From: stephan b. <sg...@us...> - 2005-01-06 17:05:48
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18142/test Modified Files: s11nTest.cpp Log Message: Moved s11n tests into a UnitTest class. Index: s11nTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/s11nTest.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- s11nTest.cpp 31 Dec 2004 17:41:59 -0000 1.11 +++ s11nTest.cpp 6 Jan 2005 17:05:36 -0000 1.12 @@ -21,6 +21,13 @@ #include "FactoryTest.h" +#include "Test.h" +#include "pclasses/IO/IOStream.h" +#include "pclasses/System/File.h" +#include "pclasses/System/Pipe.h" +#include "pclasses/System/Process.h" +#include "pclasses/System/ProcessIO.h" + using namespace ::P::SIO; typedef std::list<std::string> TestListType; @@ -337,164 +344,139 @@ return 0; } -/// i wish i could make this a P::App... -int main( int argc, char ** argv ) -{ - using namespace ::P::SIO; - - CERR << "P::s11n tests...\n"; - - if( 0 ) - { - return parens_parser(); - } - - if( 2 == argc ) +class S11nTest: public UnitTest { +public: + + void run() throw() { - return test_load( argv[1] ) ? 0 : 1; - } + using namespace ::P::SIO; - typedef std::auto_ptr<TheBase> TAP; - TAP b1 = TAP( new BType ); - NODE_TYPE node; - assert( SERIALIZE(node,TheBase, *b1.get() ) ); // weird: i shouldn't have to deref that AP. - CERR << "Serialize Workie!\n"; + typedef std::auto_ptr<TheBase> TAP; + TAP b1 = TAP( new BType ); + NODE_TYPE node; + P_TEST( SERIALIZE(node,TheBase, *b1.get() ) ); // weird: i shouldn't have to deref that AP. + CERR << "Serialize Workie!\n"; - NODETR::class_name( node, "CType" ); // should force load of CType.so on next line... - TAP b2 = TAP( DESERIALIZE(node,TheBase) ); - assert( b2.get() && "Deserialize failed :(" ); - CERR << "Deser workie: " << b2->classname()<<"\n"; + NODETR::class_name( node, "CType" ); // This should force load of CType.so on next line... + TAP b2 = TAP( DESERIALIZE(node,TheBase) ); + P_TEST( b2.get() && "Deserialize failed :(" ); + CERR << "Deser workie: " << b2->classname()<<"\n"; - typedef std::auto_ptr<SerializerInterface> SAP; - std::string serclass = SERIALIZER_CLASS_NAME; - SAP ser = SAP( ::P::Plugin::pluginManager<SerializerInterface>().create( serclass ) ); - assert( ser.get() && "Could not load serializer :(" ); - CERR << "Loaded serializer '"<<serclass<<"'. :)\n"; + typedef std::auto_ptr<SerializerInterface> SAP; + std::string serclass = SERIALIZER_CLASS_NAME; + SAP ser = SAP( createSerializer() ); + P_TEST( ser.get() && "Could not load serializer :(" ); + CERR << "Loaded serializer '"<<serclass<<"'. :)\n"; - NODETR::clear(node); - - using ::P::Util::LexT; - TestListType list; - TestMapType map; - LexT tmpv; - LexT tmpk; - for( int i = 0; i < 10; i++ ) - { - tmpk = "item" + LexT(i).str(); - // ^^^ reminder: we do this to avoid numeric keys - // in map, because that don't work with XML-compliant Serializers. - tmpv = std::string("this is item #") + LexT(i).str(); - CERR << "Adding ["<<tmpv<<"]\n"; - list.push_back( tmpv ); - map[tmpk] = tmpv; - } - CERR << "list/map sizes == " << list.size() << " , " << map.size()<<"\n"; - - CERR << "Containers...\n"; + NODETR::clear(node); - TestMapType::const_iterator mit; - TestListType::const_iterator lit = list.begin(); - size_t at = 0; - if( 0 ) - { - while( lit != list.end() ) - { - CERR << "list["<<at++<<"] = " << (*(lit++))<<"\n"; - } - mit = map.begin(); - while( mit != map.end() ) + using ::P::Util::LexT; + TestListType list; + TestMapType map; + LexT tmpv; + LexT tmpk; + for( int i = 0; i < 10; i++ ) { - CERR << "map["<<(*mit).first<<"] = "<<(*mit).second<<"\n"; - ++mit; + tmpk = "item" + LexT(i).str(); + // ^^^ reminder: we do this to avoid numeric keys + // in map, because that don't work with XML-compliant Serializers. + tmpv = std::string("this is item #") + LexT(i).str(); + CERR << "Adding ["<<tmpv<<"]\n"; + list.push_back( tmpv ); + map[tmpk] = tmpv; } - } + CERR << "list/map sizes == " << list.size() << " , " << map.size()<<"\n"; + CERR << "Containers...\n"; + TestMapType::const_iterator mit; + TestListType::const_iterator lit = list.begin(); + size_t at = 0; - assert( serialize(node,list) ); - assert( ser->serialize( node, std::cout ) ); - list.clear(); - assert( deserialize( node, list ) && "deser list failed :(" ); + P_TEST( serialize(node,list) ); + P_TEST( ser->serialize( node, std::cout ) ); + list.clear(); + P_TEST( deserialize( node, list ) && "deser list failed :(" ); - NodeTraits::clear(node); - assert( serialize(node,map) ); - assert( ser->serialize( node, std::cout ) ); - map.clear(); - assert( deserialize( node, map ) && "deser map failed :(" ); - NodeTraits::set( node, "i_deserialized_this", "yes" ); - CERR << "Deserialized:\n"; + NodeTraits::clear(node); + P_TEST( serialize(node,map) ); + P_TEST( ser->serialize( node, std::cout ) ); + map.clear(); + P_TEST( deserialize( node, map ) && "deser map failed :(" ); + NodeTraits::set( node, "i_deserialized_this", "yes" ); + CERR << "Deserialized:\n"; - CERR << "deser list.size() == " << list.size()<<"\n"; - CERR << "map.size() == " << map.size()<<"\n"; + CERR << "deser list.size() == " << list.size()<<"\n"; + CERR << "map.size() == " << map.size()<<"\n"; + P_TEST( save( map, std::cout ) ); + // now prove it... - // now prove it... - if( 0 ) - { - lit = list.begin(); - at = 0; - while( lit != list.end() ) + + if( 1 ) { - CERR << "list["<<at++<<"] = " << (*(lit++))<<"\n"; + CERR << "Manually iterating over deserialized data...\n"; + lit = list.begin(); + at = 0; + while( lit != list.end() ) + { + CERR << "list["<<at++<<"] = " << (*(lit++))<<"\n"; + } + mit = map.begin(); + while( mit != map.end() ) + { + CERR << "map["<<(*mit).first<<"] = "<<(*mit).second<<"\n"; + ++mit; + } } - mit = map.begin(); - while( mit != map.end() ) + + + if( 0 ) { - CERR << "map["<<(*mit).first<<"] = "<<(*mit).second<<"\n"; - ++mit; + CERR << "s11nCast(list,list2)...\n"; + TestListType2 list2; + P_TEST( s11nCast( list, list2 ) && "s11nCast() failed :(" ); + // ^^^ reminder: only works when list and list2 use compatible + // proxies!!! + CERR << "casted-to list (size=="<<list2.size()<<"):\n"; + save( list2, std::cout ); + CERR << "ACHTUNG: ^^^^^ failure here is normal when the list1/list2 proxies don't match.\n"; + } + + if( 1 ) + { + CERR << "Just what we've always wanted to do: save Time...\n"; + using P::Time; + using P::Date; + using P::DateTime; + Time thetime( 12, 13, 14 ); + Date thedate( 2005, 1, 30 ); + DateTime dt( thedate, thetime ); + save( thetime, std::cout ); + save( thedate, std::cout ); + save( dt, std::cout ); } } +}; +/// i wish i could make this a P::App... +int main( int argc, char ** argv ) +{ + + CERR << "P::s11n tests...\n"; if( 0 ) { - CERR << "s11n_cast(list,list2)...\n"; - TestListType2 list2; - assert( s11n_cast( list, list2 ) && "s11n_cast() failed :(" ); - // ^^^ reminder: only works when list and list2 use compatible - // proxies!!! - CERR << "casted-to list (size=="<<list2.size()<<"):\n"; - save( list2, std::cout ); - CERR << "ACHTUNG: ^^^^^ failure here is normal when the list1/list2 proxies don't match.\n"; + return parens_parser(); } - if( 1 ) + if( 2 == argc ) { - CERR << "Time...\n"; - using P::Time; - using P::Date; - using P::DateTime; - Time thetime( 12, 13, 14 ); - Date thedate( 2005, 1, 30 ); - DateTime dt( thedate, thetime ); - save( thetime, std::cout ); - save( thedate, std::cout ); - save( dt, std::cout ); - -// CERR << "Using S11nNode-specific API...\n"; -// NODE_TYPE tmnode; -// assert( tmnode.serialize( dt ) ); -// assert( save( tmnode, std::cout ) ); - -// DateTime * pdt = tmnode.deserialize<DateTime>(); -// assert( pdt ); -// CERR << "deserialized (DateTime*) == " << *pdt<<"\n"; -// delete pdt; -// DateTime vdt; -// assert( tmnode.deserialize( vdt ) ); -// CERR << "deserialized DateTime == " << vdt<<"\n"; - + return test_load( argv[1] ) ? 0 : 1; } -// size_t S1 = 7; -// ulong S2 = 7; -// int S3 = 7; -// char S4 = '7'; -// save( S1, std::cout ); -// save( S2, std::cout ); -// save( S3, std::cout ); -// save( S4, std::cout ); - + S11nTest t1; + t1.run(); return 0; } |