#include "AForm.hpp" #include "Intern.hpp" #include "Bureaucrat.hpp" #include "RobotomyRequestForm.hpp" #include "ShrubberyCreationForm.hpp" #include "PresidentialPardonForm.hpp" #include #include int main() { std::cout << "-------------Bureaucrat TEST-----------" << std::endl; std::cout << "Constructor too high grade" << std::endl; { try { Bureaucrat crat("crat", 0); } catch (std::exception &e) { std::cout << e.what() << std::endl; } } std::cout << std::endl; std::cout << "Constructor too low grade" << std::endl; { try { Bureaucrat crat("crat", 151); } catch (std::exception &e) { std::cout << e.what() << std::endl; } } std::cout << std::endl; std::cout << "increment too high" << std::endl; { Bureaucrat crat("crat", 1); try { crat.increment(); } catch (std::exception &e) { std::cout << e.what() << std::endl; } } std::cout << std::endl; std::cout << "decrement too low" << std::endl; { Bureaucrat crat("crat", 150); try { crat.decrement(); } catch (std::exception &e) { std::cout << e.what() << std::endl; } } std::cout << std::endl; std::cout << "setgrade too low" << std::endl; { Bureaucrat crat("crat", 42); try { crat.setGrade(151); } catch (std::exception &e) { std::cout << e.what() << std::endl; } } std::cout << std::endl; std::cout << "setgrade too high" << std::endl; { Bureaucrat crat("crat", 42); try { crat.setGrade(0); } catch (std::exception &e) { std::cout << e.what() << std::endl; } } std::cout << std::endl; std::cout << "increment normal" << std::endl; { Bureaucrat crat("crat", 42); std::cout << "default grade: " << crat.getGrade() << std::endl; crat.increment(); std::cout << "after increment grade: " << crat.getGrade() << std::endl; } std::cout << std::endl; std::cout << "decrement normal" << std::endl; { Bureaucrat crat("crat", 42); std::cout << "default grade: " << crat.getGrade() << std::endl; crat.decrement(); std::cout << "after decrement grade: " << crat.getGrade() << std::endl; } std::cout << std::endl; std::cout << "print" << std::endl; { Bureaucrat crat("crat", 42); std::cout << crat; } std::cout << std::endl; std::cout << "------------- Form TEST-----------" << std::endl; std::cout << "print" << std::endl; { RobotomyRequestForm form("moi"); std::cout << form; } std::cout << std::endl; std::cout << "------------- RobotomyRequestForm Sign 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 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; std::cout << "------------- Intern TEST-----------" << std::endl; std::cout << "Intern" << std::endl; { Intern intern; static const std::string forms[] = { "robotomy request", "presidential pardon", "shrubbery creation", "bozo" }; for (int i = 0; i != 4; ++i) { AForm* form = intern.makeForm(forms[i], "bozoman"); if (form != NULL) delete form; } } std::cout << std::endl; }