/* * TestASTInspector.cpp * * Created on: Dec 18, 2012 * Author: att */ #include "TestASTInspector.h" TestASTInspector::TestASTInspector() { // TODO Auto-generated constructor stub } TestASTInspector::~TestASTInspector() { // TODO Auto-generated destructor stub } std::string TestASTInspector::test_inspecting_basic_expression() { std::string test_report = ""; BasicExpression * be = build_basic_expression("+", SenchaObject(9), SenchaObject(122)); be->accept(&inspector); std::string assert_report = "Report:\n" + inspector.get_report(); muu_assert("ASTInspector didn\'t write any report", inspector.get_report() != ""); muu_assert("Some of nodes were missed in visit", inspector.how_many_visits() == 3); muu_assert("Some of nodes were missed in visit", inspector.how_many_occurences_of("BasicExpression") == 1); muu_assert("Some of nodes were missed in visit", inspector.how_many_occurences_of("ConstantExpression") == 2); delete be; inspector.forget_everything(); return test_report; } std::string TestASTInspector::test_inspecting_simple_AST() { std::string test_report = ""; auto left = build_basic_expression("-", SenchaObject(88), SenchaObject(-19)); auto right = build_basic_expression("*", SenchaObject(9), SenchaObject(12)); BasicExpression * be = build_simple_AST("+", left, right); be->accept(&inspector); std::string assert_report = "Report:\n" + inspector.get_report(); muu_assert("ASTInspector didn\'t write any report", inspector.get_report() != ""); muu_assert("Some of nodes were missed in visit", inspector.how_many_visits() == 7); muu_assert("Some of nodes were missed in visit", inspector.how_many_occurences_of("BasicExpression") == 3); muu_assert("Some of nodes were missed in visit", inspector.how_many_occurences_of("ConstantExpression") == 4); delete be; inspector.forget_everything(); return test_report; } std::string TestASTInspector::all_tests() { std::string test_report = ""; mu_run_test(test_inspecting_basic_expression); mu_run_test(test_inspecting_simple_AST); return test_report; } BasicExpression * TestASTInspector::build_basic_expression(std::string oper, SenchaObject arg1, SenchaObject arg2) { BasicExpression * be = new BasicExpression(NULL); be->set_operator(oper); be->set_left_operand(new ConstantExpression(be, arg1)); be->set_right_operand(new ConstantExpression(be, arg2)); return be; } BasicExpression * TestASTInspector::build_simple_AST(std::string oper, BasicExpression * left, BasicExpression * right) { BasicExpression * be = new BasicExpression(NULL); be->set_operator(oper); be->set_left_operand(left); be->set_right_operand(right); return be; }