#include #include #include "Bureaucrat.hpp" #include "Form.hpp" #include "colors.h" #define EXCEPTION BOLD BACKGROUND1 " Exception: " RESET " " #define INFO ITALIC BOLD UNDERLINE GREEN "Info: " #define PRINT BOLD BACKGROUND3 " Print: " RESET " " #define END_SCOPE ITALIC BOLD UNDERLINE RED "End of scope" RESET #define END_SCOPE_EXCEPTION \ ITALIC BOLD UNDERLINE RED "End of scope with exception" RESET int main(void) { try { std::cout << INFO << "Creating Bureaucrat with name 'jan' and grade 3" << RESET << std::endl; Bureaucrat jan("Jan", 41); std::cout << std::endl; std::cout << INFO << "Printing Bureaucrat..." << RESET << std::endl; std::cout << PRINT << jan << std::endl; std::cout << std::endl; std::cout << INFO << "Creating a Form with name 'Form1', sign grade 40, and " "execute grade 30" << RESET << std::endl; Form form1("Form1", 40, 30); std::cout << std::endl; std::cout << INFO << "Printing Form..." << RESET << std::endl; std::cout << PRINT << form1 << std::endl; std::cout << std::endl; std::cout << INFO << "Jan tries to sign Form1..." << RESET << std::endl; jan.signForm(form1); std::cout << std::endl; std::cout << INFO << "Printing Form after signing..." << RESET << std::endl; std::cout << PRINT << form1 << std::endl; std::cout << std::endl; std::cout << INFO << "Incrementing Jan's grade..." << RESET << std::endl; ++jan; std::cout << std::endl; std::cout << INFO << "Printing Bureaucrat after incrementing..." << RESET << std::endl; std::cout << PRINT << jan << std::endl; std::cout << std::endl; std::cout << INFO << "Jan tries to sign Form1 again..." << RESET << std::endl; jan.signForm(form1); std::cout << std::endl; std::cout << INFO << "Printing Form after second signing attempt..." << RESET << std::endl; std::cout << PRINT << form1 << std::endl; std::cout << std::endl; std::cout << INFO << "Jan tries to sign Form1 again" << RESET << std::endl; jan.signForm(form1); std::cout << std::endl; std::cout << INFO << "Destructing..." << RESET << std::endl; std::cout << END_SCOPE << std::endl; } catch (std::exception &e) { std::cerr << EXCEPTION << e.what() << std::endl; std::cout << END_SCOPE_EXCEPTION << std::endl; } std::cout << std::endl; std::cout << INFO << "Testing Exceptions..." << RESET << std::endl; std::cout << std::endl; try { std::cout << INFO << "Creating Bureaucrat with name 'Invalid' and grade 0" << RESET << std::endl; Bureaucrat invalid("Invalid", 0); std::cout << END_SCOPE << std::endl; } catch (std::exception &e) { std::cerr << EXCEPTION << e.what() << std::endl; std::cout << END_SCOPE_EXCEPTION << std::endl; } std::cout << std::endl; try { std::cout << INFO << "Creating Bureaucrat with name 'Invalid' and grade 151" << RESET << std::endl; Bureaucrat invalid("Invalid", 151); std::cout << END_SCOPE << std::endl; } catch (std::exception &e) { std::cerr << EXCEPTION << e.what() << std::endl; std::cout << END_SCOPE_EXCEPTION << std::endl; } std::cout << std::endl; try { std::cout << INFO << "Creating Form with name 'InvalidForm', sign grade 0, and " "execute grade 30" << RESET << std::endl; Form invalidForm("InvalidForm", 0, 30); std::cout << END_SCOPE << std::endl; } catch (std::exception &e) { std::cerr << EXCEPTION << e.what() << std::endl; std::cout << END_SCOPE_EXCEPTION << std::endl; } std::cout << std::endl; try { std::cout << INFO << "Creating Form with name 'InvalidForm', sign grade 40, " "and execute grade 151" << RESET << std::endl; Form invalidForm("InvalidForm", 40, 151); std::cout << END_SCOPE << std::endl; } catch (std::exception &e) { std::cerr << EXCEPTION << e.what() << std::endl; std::cout << END_SCOPE_EXCEPTION << std::endl; } std::cout << std::endl; std::cout << INFO << "Testing signing with Bureaucrat with grade too low using " "Form::beSigned()" << RESET << std::endl; try { std::cout << INFO << "Creating Bureaucrat with name 'Peter' and grade 50" << RESET << std::endl; Bureaucrat peter("Peter", 50); std::cout << std::endl; std::cout << INFO << "Creating Form with name 'Form2', sign grade 40, and " "execute grade 30" << RESET << std::endl; Form form2("Form2", 40, 30); std::cout << std::endl; std::cout << INFO << "Peter tries to sign Form2..." << RESET << std::endl; form2.beSigned(peter); std::cout << END_SCOPE << std::endl; } catch (std::exception &e) { std::cerr << EXCEPTION << e.what() << std::endl; std::cout << END_SCOPE_EXCEPTION << std::endl; } std::cout << END_SCOPE << std::endl; }