// ObjStream_t.cpp #include #include #include #include #include "ObjStreamTest.hpp" #include "ObjTableTest.hpp" using std::cout; using std::cerr; using std::endl; using std::string; using std::istringstream; using std::ostringstream; //********************************************************************** int main( ) { string component = "ObjStream"; string ok_prefix = component + " (I): "; string error_prefix = component + " test (E): "; cout << ok_prefix << "---------- Testing component " + component + ". ----------" << endl; // Make sure assert is enabled. bool assert_flag = false; assert ( ( assert_flag = true, assert_flag ) ); if ( ! assert_flag ) { cerr << "Assert is disabled" << endl; return 1; } //******************************************************************** cout << ok_prefix << "Create output stream." << endl; string expect("Begin\n"); ostringstream strm; int i1 = 1; Page page1(1,11.1,true,"This is page 1."); { TestStream tstrm(strm); assert( ! tstrm.in_enabled() ); assert( tstrm.out_enabled() ); assert( tstrm.out_state() == 0 ); { tstrm.write_object("page001", page1); expect += "\nPage page001 {\n"; expect += " int number = 1\n"; expect += " double length = 11.1\n"; expect += " bool start = 1\n"; expect += " string text = \"This is page 1.\"\n"; expect += " bare_pointer prev = 0\n"; expect += " share_pointer first = 0\n"; #ifdef ObjData_supports_lists expect += " int_list refs = \n"; expect += " double_list lens = \n"; expect += " bool_list isrefs = \n"; expect += " string_list paras = \n"; expect += " bare_ptr_list figs = \n"; expect += " share_ptr_list tabs = \n"; #endif expect += "}\n"; cout << "Expect: -" << expect << "-" << endl; cout << "Data: -" << strm.str() << "-" << endl; assert( strm.str() == expect ); } } expect += "\nEnd"; cout << "Data: -" << strm.str() << "-" << endl; assert( strm.str() == expect ); //******************************************************************** cout << ok_prefix << "Create input stream." << endl; { string data(expect); istringstream strm(data); TestStream tstrm(strm); assert( ObjTable::get_object_count() == 0 ); tstrm.read_data(); assert( ObjTable::get_object_count() == 1 ); Ptr ptr; ObjTable::get_object("page001",ptr); cout << *ptr << endl; assert( *ptr == page1 ); assert( tstrm.in_enabled() ); assert( ! tstrm.out_enabled() ); assert( tstrm.in_state() == 0 ); assert( ! tstrm.eof() ); { } } //******************************************************************** cout << ok_prefix << "------------- All tests passed. -------------" << endl; return 0; //******************************************************************** }