finish ex02
This commit is contained in:
parent
47f3c11851
commit
36a2871a3d
@ -64,8 +64,6 @@ void AForm::execute(const Bureaucrat &exec) const
|
||||
throw NotSignedException();
|
||||
if (exec.getGrade() > this->_to_execute)
|
||||
throw GradeTooLowException();
|
||||
|
||||
std::cout << exec.getName() << " executed " << this->_name << std::endl;
|
||||
}
|
||||
|
||||
const std::string& AForm::getName() const
|
||||
@ -107,5 +105,5 @@ const char* AForm::GradeTooHighException::what() const throw()
|
||||
|
||||
const char* AForm::NotSignedException::what() const throw()
|
||||
{
|
||||
return "grade is to high";
|
||||
return "form not signed";
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include "Bureaucrat.hpp"
|
||||
#include <iostream>
|
||||
#include <exception>
|
||||
#include <ostream>
|
||||
#include <string>
|
||||
|
||||
@ -78,13 +79,9 @@ void Bureaucrat::executeForm(AForm const & form) const
|
||||
form.execute(*this);
|
||||
std::cout << this->_name << " executed " << form.getName() << std::endl;
|
||||
}
|
||||
catch Form::GradeTooLowException
|
||||
catch (std::exception& e)
|
||||
{
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,13 +5,13 @@
|
||||
#include <iostream>
|
||||
|
||||
PresidentialPardonForm::PresidentialPardonForm():
|
||||
AForm("PresidentialPardonForm", 45, 72, "")
|
||||
AForm("PresidentialPardonForm", 5, 25, "")
|
||||
{
|
||||
|
||||
std::cout << "PresidentialPardonForm()" << std::endl;
|
||||
}
|
||||
|
||||
PresidentialPardonForm::PresidentialPardonForm(const std::string& target):
|
||||
AForm("PresidentialPardonForm", 45, 72, target)
|
||||
AForm("PresidentialPardonForm", 5, 25, target)
|
||||
{
|
||||
std::cout << "PresidentialPardonForm(" << target << ")" << std::endl;
|
||||
}
|
||||
@ -22,6 +22,11 @@ PresidentialPardonForm::PresidentialPardonForm(const PresidentialPardonForm& src
|
||||
std::cout << "PresidentialPardonForm(PresidentialPardonForm)" << std::endl;
|
||||
}
|
||||
|
||||
PresidentialPardonForm::~PresidentialPardonForm()
|
||||
{
|
||||
std::cout << "PresidentialPardonForm()" << std::endl;
|
||||
}
|
||||
|
||||
PresidentialPardonForm& PresidentialPardonForm::operator=(const PresidentialPardonForm& src)
|
||||
{
|
||||
if (this != & src)
|
||||
@ -31,12 +36,6 @@ PresidentialPardonForm& PresidentialPardonForm::operator=(const PresidentialPard
|
||||
|
||||
void PresidentialPardonForm::execute(const Bureaucrat &exec) const
|
||||
{
|
||||
static bool ok(false);
|
||||
std::cout << "Bzit bzit" << std::endl;
|
||||
if (ok)
|
||||
std::cout << this->_target << " be robotomized" << std::endl;
|
||||
else
|
||||
std::cout << this->_target << " robotomized failed" << std::endl;
|
||||
ok = !ok;
|
||||
AForm::execute(exec);
|
||||
std::cout << this->_target << " has been pardoned by Zaphod Beeblebrox" << std::endl;
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
RobotomyRequestForm::RobotomyRequestForm():
|
||||
AForm("RobotomyRequestForm", 45, 72, "")
|
||||
{
|
||||
|
||||
std::cout << "RobotomyRequestForm()" << std::endl;
|
||||
}
|
||||
|
||||
RobotomyRequestForm::RobotomyRequestForm(const std::string& target):
|
||||
@ -22,6 +22,11 @@ RobotomyRequestForm::RobotomyRequestForm(const RobotomyRequestForm& src):
|
||||
std::cout << "RobotomyRequestForm(RobotomyRequestForm)" << std::endl;
|
||||
}
|
||||
|
||||
RobotomyRequestForm::~RobotomyRequestForm()
|
||||
{
|
||||
std::cout << "~RobotomyRequestForm()" << std::endl;
|
||||
}
|
||||
|
||||
RobotomyRequestForm& RobotomyRequestForm::operator=(const RobotomyRequestForm& src)
|
||||
{
|
||||
if (this != & src)
|
||||
@ -32,11 +37,13 @@ RobotomyRequestForm& RobotomyRequestForm::operator=(const RobotomyRequestForm& s
|
||||
void RobotomyRequestForm::execute(const Bureaucrat &exec) const
|
||||
{
|
||||
static bool ok(false);
|
||||
|
||||
AForm::execute(exec);
|
||||
|
||||
std::cout << "Bzit bzit" << std::endl;
|
||||
if (ok)
|
||||
std::cout << this->_target << " be robotomized" << std::endl;
|
||||
else
|
||||
std::cout << this->_target << " robotomized failed" << std::endl;
|
||||
ok = !ok;
|
||||
AForm::execute(exec);
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ ShrubberyCreationForm::ShrubberyCreationForm():
|
||||
}
|
||||
|
||||
ShrubberyCreationForm::ShrubberyCreationForm(const std::string& target):
|
||||
AForm("", 137, 145, target)
|
||||
AForm("ShrubberyCreationForm", 137, 145, target)
|
||||
{
|
||||
std::cout << "ShrubberyCreationForm(" << ", " << target << ")" << std::endl;
|
||||
std::cout << "ShrubberyCreationForm(" << target << ")" << std::endl;
|
||||
}
|
||||
|
||||
ShrubberyCreationForm::ShrubberyCreationForm(const ShrubberyCreationForm& src):
|
||||
@ -57,6 +57,7 @@ void ShrubberyCreationForm::execute(const Bureaucrat &exec) const
|
||||
" _ - | | -_\n"
|
||||
" // \\\\\n"
|
||||
;
|
||||
AForm::execute(exec);
|
||||
|
||||
std::ofstream file((this->_target + "_shruberry").c_str());
|
||||
|
||||
@ -67,5 +68,4 @@ void ShrubberyCreationForm::execute(const Bureaucrat &exec) const
|
||||
}
|
||||
file << asciiTrees;
|
||||
|
||||
AForm::execute(exec);
|
||||
}
|
||||
|
@ -1,4 +1,7 @@
|
||||
#include "Bureaucrat.hpp"
|
||||
#include "RobotomyRequestForm.hpp"
|
||||
#include "ShrubberyCreationForm.hpp"
|
||||
#include "PresidentialPardonForm.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
@ -95,68 +98,28 @@ int main() {
|
||||
|
||||
std::cout << "------------- Form TEST-----------" << std::endl;
|
||||
|
||||
std::cout << "Constructor too high sign grade" << std::endl;
|
||||
{
|
||||
try {
|
||||
Form("form", 42, 0);
|
||||
} catch (std::exception &e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Constructor too low sign grade" << std::endl;
|
||||
{
|
||||
try {
|
||||
Form("form", 42, 151);
|
||||
} catch (std::exception &e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Constructor too high exec grade" << std::endl;
|
||||
{
|
||||
try {
|
||||
Form("form", 0, 42);
|
||||
} catch (std::exception &e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Constructor too low exec grade" << std::endl;
|
||||
{
|
||||
try {
|
||||
Form("form", 151, 42);
|
||||
} catch (std::exception &e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "print" << std::endl;
|
||||
{
|
||||
Form form("form", 42, 42);
|
||||
RobotomyRequestForm form("moi");
|
||||
std::cout << form;
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "------------- Form Sign TEST-----------" << std::endl;
|
||||
std::cout << "------------- RobotomyRequestForm Sign TEST-----------" << std::endl;
|
||||
|
||||
std::cout << "Bureaucrat sign a Form" << std::endl;
|
||||
std::cout << "Bureaucrat sign a RobotomyRequestForm" << std::endl;
|
||||
{
|
||||
Form form("form", 42, 42);
|
||||
RobotomyRequestForm form("form");
|
||||
Bureaucrat crat("crat", 42);
|
||||
|
||||
crat.signForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Too low Bureaucrat sign a Form" << std::endl;
|
||||
std::cout << "Too low Bureaucrat sign a RobotomyRequestForm" << std::endl;
|
||||
{
|
||||
Form form("form", 42, 1);
|
||||
Bureaucrat crat("crat", 42);
|
||||
RobotomyRequestForm form("form");
|
||||
Bureaucrat crat("crat", 150);
|
||||
try {
|
||||
crat.signForm(form);
|
||||
} catch (std::exception &e) {
|
||||
@ -165,22 +128,210 @@ int main() {
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "High Bureaucrat sign a low Form" << std::endl;
|
||||
std::cout << "High Bureaucrat sign a low RobotomyRequestForm" << std::endl;
|
||||
{
|
||||
Form form("form", 42, 150);
|
||||
RobotomyRequestForm form("form");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.signForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Form already sign" << std::endl;
|
||||
std::cout << "RobotomyRequestForm already sign" << std::endl;
|
||||
{
|
||||
Form form("form", 42, 150);
|
||||
RobotomyRequestForm form("form");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.signForm(form);
|
||||
crat.signForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "------------- RobotomyRequestForm TEST-----------" << std::endl;
|
||||
|
||||
std::cout << "Bureaucrat sign a RobotomyRequestForm" << std::endl;
|
||||
{
|
||||
RobotomyRequestForm form("form");
|
||||
Bureaucrat crat("crat", 42);
|
||||
|
||||
crat.signForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Too low Bureaucrat sign a RobotomyRequestForm" << std::endl;
|
||||
{
|
||||
RobotomyRequestForm form("form");
|
||||
Bureaucrat crat("crat", 150);
|
||||
try {
|
||||
crat.signForm(form);
|
||||
} catch (std::exception &e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "High Bureaucrat sign a low RobotomyRequestForm" << std::endl;
|
||||
{
|
||||
RobotomyRequestForm form("form");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.signForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "RobotomyRequestForm already sign" << std::endl;
|
||||
{
|
||||
RobotomyRequestForm form("form");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.signForm(form);
|
||||
crat.signForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "RobotomyRequestForm execute not signed form" << std::endl;
|
||||
{
|
||||
RobotomyRequestForm form("form");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.executeForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
std::cout << "RobotomyRequestForm execute" << std::endl;
|
||||
{
|
||||
RobotomyRequestForm form("bozo");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.signForm(form);
|
||||
|
||||
crat.executeForm(form);
|
||||
crat.executeForm(form);
|
||||
crat.executeForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "------------- PresidentialPardonForm TEST-----------" << std::endl;
|
||||
|
||||
std::cout << "Bureaucrat sign a PresidentialPardonForm" << std::endl;
|
||||
{
|
||||
PresidentialPardonForm form("form");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.signForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Too low Bureaucrat sign a PresidentialPardonForm" << std::endl;
|
||||
{
|
||||
PresidentialPardonForm form("form");
|
||||
Bureaucrat crat("crat", 150);
|
||||
try {
|
||||
crat.signForm(form);
|
||||
} catch (std::exception &e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "High Bureaucrat sign a low PresidentialPardonForm" << std::endl;
|
||||
{
|
||||
PresidentialPardonForm form("form");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.signForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "PresidentialPardonForm already sign" << std::endl;
|
||||
{
|
||||
PresidentialPardonForm form("form");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.signForm(form);
|
||||
crat.signForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "PresidentialPardonForm not signed execute" << std::endl;
|
||||
{
|
||||
PresidentialPardonForm form("form");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.executeForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "PresidentialPardonForm execute" << std::endl;
|
||||
{
|
||||
PresidentialPardonForm form("form");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.signForm(form);
|
||||
|
||||
crat.executeForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
|
||||
std::cout << "------------- ShrubberyCreationForm TEST-----------" << std::endl;
|
||||
|
||||
std::cout << "Bureaucrat sign a ShrubberyCreationForm" << std::endl;
|
||||
{
|
||||
ShrubberyCreationForm form("form");
|
||||
Bureaucrat crat("crat", 42);
|
||||
|
||||
crat.signForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "Too low Bureaucrat sign a ShrubberyCreationForm" << std::endl;
|
||||
{
|
||||
ShrubberyCreationForm form("form");
|
||||
Bureaucrat crat("crat", 150);
|
||||
try {
|
||||
crat.signForm(form);
|
||||
} catch (std::exception &e) {
|
||||
std::cout << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "High Bureaucrat sign a low ShrubberyCreationForm" << std::endl;
|
||||
{
|
||||
ShrubberyCreationForm form("form");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.signForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "ShrubberyCreationForm already sign" << std::endl;
|
||||
{
|
||||
ShrubberyCreationForm form("form");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.signForm(form);
|
||||
crat.signForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "ShrubberyCreationForm not sign execute" << std::endl;
|
||||
{
|
||||
ShrubberyCreationForm form("form");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.executeForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
|
||||
std::cout << "ShrubberyCreationForm execute" << std::endl;
|
||||
{
|
||||
ShrubberyCreationForm form("bozo");
|
||||
Bureaucrat crat("crat", 1);
|
||||
|
||||
crat.signForm(form);
|
||||
|
||||
crat.executeForm(form);
|
||||
}
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user