*operation* void gen_selftest(ofstream & user_calls,int selftest_flag,int trace_flag) *wrapper* Parsed_obj *prefix* (@ char * full_type_name = new char[MAXNAMLEN]; char * prec_type_name = new char[MAXNAMLEN]; assert( (full_type_name != NULL) && (prec_type_name != NULL) ); obj_type->get_full_type_names(full_type_name,prec_type_name); user_calls << " // parse it in\n"; if (trace_flag) user_calls << " cout << \"Parsing in object in: \" << dem_in << \". \\n\";\n"; user_calls << " " << full_type_name << " *" << obj->get_val() << " = new " << full_type_name << "();\n"; user_calls << " " << obj->get_val() << " = ( " << full_type_name << " * ) " << obj->get_val() << " -> g_parse( dem_in );\n"; user_calls << " if ( " << obj->get_val() << " == NULL ) {\n"; user_calls << " cerr << \"Parser error.\" << endl;\n"; user_calls << " exit(1);\n"; user_calls << " }\n"; user_calls << "\n"; if (selftest_flag == 0) return; user_calls << " //----------------------------------------\n"; user_calls << " // Drawing an object\n"; user_calls << " //----------------------------------------\n"; user_calls << " cout << \"Drawing the parsed object:\\n\";\n"; user_calls << " " << obj->get_val() << " -> g_draw();\n"; user_calls << " cout << \"\\nEnd of drawing.\\n\" << endl;\n"; user_calls << "\n"; user_calls << " //----------------------------------------\n"; user_calls << " // Copying an object\n"; user_calls << " //----------------------------------------\n"; user_calls << " cout << \"Copying the object.\\n\";\n"; user_calls << " " << full_type_name << " *" << obj->get_val() << "_copied = ( " << full_type_name << " * ) " << obj->get_val() << " -> g_copy();\n"; user_calls << " cout << endl;\n"; user_calls << "\n"; user_calls << " //----------------------------------------\n"; user_calls << " // Displaying the copied object as a tree\n"; user_calls << " //----------------------------------------\n"; user_calls << " cout << \"Displaying the copied object as a tree:\\n\";\n"; user_calls << " " << obj->get_val() << "_copied -> g_displayAsTree();\n"; user_calls << " cout << \"\\nEnd of display.\\n\" << endl;\n"; user_calls << "\n"; user_calls << " //----------------------------------------\n"; user_calls << " // Comparing two objects\n"; user_calls << " //----------------------------------------\n"; user_calls << " cout << \"Comparing the two objects:\\n\";\n"; user_calls << " if ( " << obj->get_val() << " -> g_equal( " << obj->get_val() << "_copied ) == 1 )\n"; user_calls << " cout << \"copied and original object are equal\\n\" << endl;\n"; user_calls << " else\n"; user_calls << " cout << \"copied and original object are NOT equal\\n\" << endl;\n"; user_calls << "\n"; user_calls << " //----------------------------------------\n"; user_calls << " // Printing an object\n"; user_calls << " //----------------------------------------\n"; user_calls << " cout << \"Pretty printing the parsed object:\\n\";\n"; user_calls << " ofstream outFile( \"demeter-output\" );\n"; user_calls << " cout << " << obj->get_val() << " << endl;\n"; user_calls << " " << obj->get_val() << " -> g_print( outFile );\n"; user_calls << " outFile.close();\n"; user_calls << " cout << \"\\nEnd of printing.\\n\" << endl;\n"; user_calls << "\n"; user_calls << " //----------------------------------------\n"; user_calls << " // Selftest of generic parser/printer\n"; user_calls << " //----------------------------------------\n"; user_calls << " cout << \"Selftest of generic parser/printer:\\n\";\n"; user_calls << " " << full_type_name << " *" << obj->get_val() << "_printed = new " << full_type_name << "();\n"; user_calls << " " << obj->get_val() << "_printed = ( " << full_type_name <<" *)" << obj->get_val() << "_printed->g_parse( \"demeter-output\" );\n"; user_calls << " if( " << obj->get_val() << "->g_equal( " << obj->get_val() << "_printed ) == 1 ) {\n"; user_calls << " cout << \"g_parse and g_parse( g_print( g_parse ) ) are equal.\\n\"\n"; user_calls << " << \"Selftest passed.\\n\";\n"; user_calls << " } else {\n"; user_calls << " cout << \"g_parse and g_parse( g_print( g_parse ) ) are NOT equal.\\n\"\n"; user_calls << " << \"Selftest failed.\\n\";\n"; user_calls << " }\n"; user_calls << " cout << endl;\n"; user_calls << "\n"; @)