/*! @file @id $Id: serialization_test.cxx 31 2009-04-28 07:36:07Z $ */ // 1 2 3 4 5 6 7 8 // 45678901234567890123456789012345678901234567890123456789012345678901234567890 #include #include #include #include #include class A: public xml::Serialize { public: int _int; unsigned _unsigned; bool operator<(const A& o) const { return _int _map; protected: void initXmlMembers() { className("C"); persist(_map, "map"); } }; class C2: public C { public: xml::Set _set; protected: void initXmlMembers() { C::initXmlMembers(); className("C2"); persist(_set, "set"); } }; class D: public xml::Serialize { public: xml::Vector _vector; protected: void initXmlMembers() { className("D"); persist(_vector, "vector"); } }; class ContainerSerializationTest: public CppUnit::TestFixture { public: void checkContainers() { // instanciate all container to find template compilation errors xml::Deque c1; xml::List c2; xml::Map c3; xml::MultiMap c4; xml::MultiSet c5; //xml::PriorityQueue c6; //xml::Queue c7; xml::Set c8; //xml::Stack c9; xml::Vector c10; // no test std::string file("\n" "\t\n" "\t\t\n" "\t\t\t\n" "\t\t\t\t\n" "\t\t\t\t\t-13\n" "\t\t\t\t\t13\n" "\t\t\t\t\n" "\t\t\t\t\n" "\t\t\t\t\t1234567890\n" "\t\t\t\t\t123\n" "\t\t\t\t\t1.234\n" "\t\t\t\t\n" "\t\t\t\t\n" "\t\t\t\t\t-1\n" "\t\t\t\t\t2\n" "\t\t\t\t\n" "\t\t\t\t\n" "\t\t\t\t\t451236789\n" "\t\t\t\t\t43\n" "\t\t\t\t\t15.34\n" "\t\t\t\t\n" "\t\t\t\n" "\t\t\t\n" "\t\t\t\tHello\n" "\t\t\t\tWorld\n" "\t\t\t\n" "\t\t\n" "\t\t\n" "\t\t\t\n" "\t\t\t\n" "\t\t\n" "\t\n" ""); std::stringstream ss(file); D d; CPPUNIT_ASSERT_EQUAL(std::string("\n" "\t\n" "\t\t\n" "\t\t\t\n" "\t\t\t\t\n" "\t\t\t\t\t\n" "\t\t\t\t\t\n" "\t\t\t\t\n" "\t\t\t\t\n" "\t\t\t\t\t\n" "\t\t\t\t\t\n" "\t\t\t\t\t\n" "\t\t\t\t\n" "\t\t\t\n" "\t\t\t\n" "\t\t\t\t\n" "\t\t\t\n" "\t\t\n" "\t\n" ""), d.schema()); CPPUNIT_ASSERT_NO_THROW(d.loadXml(ss)); std::stringstream ss2; CPPUNIT_ASSERT_NO_THROW(d.saveXml(ss2)); CPPUNIT_ASSERT_EQUAL(file, ss2.str()); } CPPUNIT_TEST_SUITE(ContainerSerializationTest); CPPUNIT_TEST(checkContainers); CPPUNIT_TEST_SUITE_END(); }; CPPUNIT_TEST_SUITE_REGISTRATION(ContainerSerializationTest); int main() try { CppUnit::TextUi::TestRunner runner; runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest()); return runner.run() ? 0 : 1; } catch (std::exception& e) { std::cerr<<"***Exception: "<