void create(const string str_tmpl_file = "") { // if we are trying to create a single reference file, overwrite the global // test list if ( str_tmpl_file.length() ) { tests_c.clear(); tests_c.push_back( test_s(str_tmpl_file) ); } cout << "\nCreating " << tests_c.size() << " reference tests...\n" << endl; for (unsigned int n=0; n < tests_c.size(); n++) { test_s & r_test = tests_c[n]; templ.Set_Template_File( r_test.str_file ); const string str_out_file = get_reference_file( r_test.str_file ); ofstream out_stream; out_stream.open(str_out_file.c_str(), std::ios::out); const string str_reference_output = templ.Process(); out_stream.write(str_reference_output.c_str(), str_reference_output.length()); out_stream.close(); cout << r_test.str_file << endl; } }
void spatial_test() { enum { MIN_OBJS = 150, MAX_OBJS = 170, }; glDisable(GL_TEXTURE_2D); for(int i=objs.size()-1; i>=0; i--) { test_t* obj = objs[i]; glColor3ub(0xff,0,0); if(obj->is_visible()) { if(!world()->is_visible(*obj)) std::cerr << *obj << " thinks it is visible but it isn't" << std::endl; else if(!obj->drawn) std::cerr << *obj << " thinks it is visible but wasn't drawn" << std::endl; else glColor3ub(0,0xff,0); } else { if(world()->is_visible(*obj)) std::cerr << *obj << " thinks it is invisible but it is" << std::endl; else if(obj->drawn) std::cerr << *obj << " is invisible but was drawn" << std::endl; else glColor3ub(0,0,0xff); } obj->drawn = false; caret(obj->get_pos(),obj->SZ,obj->rx,obj->ry,obj->rz); if(!obj->tick()) { objs.erase(objs.begin()+i); delete obj; } } glEnable(GL_TEXTURE_2D); if(!objs.size() < MIN_OBJS) { const size_t n = MIN_OBJS+(rand()%(MAX_OBJS-MIN_OBJS)); while(objs.size()<n) { objs.push_back(new test_t()); } } }
void test(const tests_t & tests_c, const string str_test_name) { cout << str_test_name << " "; for (unsigned int n=0; n < tests_c.size(); n++) { const test_s & t = tests_c[n]; string str_template_output = ""; try { templ.Set_Template_File( t.str_file ); str_template_output = templ.Process(); } catch (tmpl::syntax_ex & ex) { if ( t.str_error_to_catch == ex.what() ) { cout << "."; continue; } else // NOT the type of error we expect, rethrow { throw ex; } } // if there is an error to catch - we didn't catch it if ( t.str_error_to_catch.length() ) { throw( string("Uncaught error: '") + t.str_error_to_catch + "'" ); } const string str_ref_file_path = get_reference_file( t.str_file ); std::ifstream in_stream; in_stream.open(str_ref_file_path.c_str()); if( !in_stream.is_open() ) { throw(string("Could not open reference test file '") + str_ref_file_path + "'. All tests aborted"); } std::stringstream oss; oss << in_stream.rdbuf(); string str_reference_output = oss.str(); in_stream.close(); const bool b_match = (str_template_output == str_reference_output); if (b_match == true) { cout << "."; } else { cout << " FAIL: '" << t.str_file << "'" << endl; cout << "Output left in 'fail.txt'" << endl; ofstream out_stream; out_stream.open("fail.txt", std::ios::out); out_stream.write(str_template_output.c_str(), str_template_output.length()); out_stream.close(); #ifdef WIN cout << "\nPress any key to QUIT"; _getch(); #endif exit(1); } } cout <<" Pass" << endl; }