From: stephan b. <sg...@us...> - 2004-12-26 05:03:23
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7975/test Modified Files: FactoryTest.cpp FactoryTest.h Makefile.toc s11nTest.cpp Log Message: mass commit: sharing code between FactoryTest and s11nTest. Index: s11nTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/s11nTest.cpp,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- s11nTest.cpp 26 Dec 2004 02:25:30 -0000 1.1 +++ s11nTest.cpp 26 Dec 2004 05:02:59 -0000 1.2 @@ -1,6 +1,7 @@ #include <pclasses/s11n/s11n.h> #include <pclasses/s11n/s11n_node.h> +#include <pclasses/s11n/io/s11n_io.h> #include <pclasses/s11n/s11n_debuggering_macros.h> #include <pclasses/s11n/list.h> #include <pclasses/s11n/map.h> @@ -11,55 +12,49 @@ #include <list> #include <map> -#define NODE_TYPE ::P::s11n::s11n_node +#include "FactoryTest.h" + #define SERIALIZE(Node,SType,SObj) ::P::s11n::serialize< NODE_TYPE >( Node, SObj ) #define DESERIALIZE(Node,SType) ::P::s11n::deserialize< NODE_TYPE, SType >( Node ) -#define TRAITS ::P::s11n::node_traits< NODE_TYPE > -struct TheBase -{ +typedef ::P::s11n::io::data_node_serializer<NODE_TYPE> SerializerBase; - virtual ~TheBase() {} - virtual std::string classname() const = 0; - virtual bool serialize( NODE_TYPE & dest ) const - { - TRAITS::class_name( dest, this->classname() ); - return true; - } - virtual bool deserialize( const NODE_TYPE & dest ) - { - CERR << "Deserializing " << TRAITS::class_name( dest ) << "\n"; - return true; - } +#define FACTORYTEST_NO_REGISTER -}; +// struct TheBase +// { -struct AType : public TheBase -{ - AType() - { - CERR << "AType()\n"; - } - virtual ~AType() - { - CERR << "~AType()\n"; - } +// virtual ~TheBase() {} +// virtual std::string classname() const = 0; - virtual std::string classname() const { return "AType"; } +// }; -}; +// struct AType : public TheBase +// { +// AType() +// { +// CERR << "AType()\n"; +// } +// virtual ~AType() +// { +// CERR << "~AType()\n"; +// } -struct BType : public AType -{ - BType() - { - CERR << "BType()\n"; - } - virtual ~BType() - { - CERR << "~BType()\n"; - } - virtual std::string classname() const { return "BType"; } -}; +// virtual std::string classname() const { return "AType"; } + +// }; + +// struct BType : public AType +// { +// BType() +// { +// CERR << "BType()\n"; +// } +// virtual ~BType() +// { +// CERR << "~BType()\n"; +// } +// virtual std::string classname() const { return "BType"; } +// }; struct TheBase_s11n @@ -91,23 +86,51 @@ #define PS11N_TYPE_NAME "BType" #include <pclasses/s11n/reg_serializable_traits.h> +bool test_load( const std::string & fn ) +{ + typedef std::auto_ptr<NODE_TYPE> NAP; + NAP n = NAP( P::s11n::io::load_node<NODE_TYPE>( fn ) ); + assert( n.get() && "Failed loading node from file :(" ); + if( n.get() ) + { + typedef std::auto_ptr<SerializerBase> SAP; + std::string serclass = "expat"; + SAP ser = SAP( ::P::Plugin::pluginManager<SerializerBase>().create( serclass ) ); + assert( ser.get() && "Could not load serializer :(" ); + return ser->serialize( *(n.get()), std::cout ); + } + return false; +} /// i wish i could make this a P::App... int main( int argc, char ** argv ) { CERR << "P::s11n tests...\n"; - typedef std::auto_ptr<TheBase> BAP; - BAP b1 = BAP( new BType ); + + if( 2 == argc ) + { + return test_load( argv[1] ) ? 0 : 1; + } + + typedef std::auto_ptr<TheBase> TAP; + TAP b1 = TAP( new BType ); NODE_TYPE node; assert( SERIALIZE(node,TheBase,b1.get() ) ); CERR << "Serialize Workie!\n"; - BAP b2 = BAP( DESERIALIZE(node,TheBase) ); + 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!\n"; + CERR << "Deser workie: " << b2->classname()<<"\n"; + typedef std::auto_ptr<SerializerBase> SAP; + std::string serclass = "expat"; + SAP ser = SAP( ::P::Plugin::pluginManager<SerializerBase>().create( serclass ) ); + assert( ser.get() && "Could not load serializer :(" ); + CERR << "Loaded serializer '"<<serclass<<"'. :)\n"; + - TRAITS::clear(node); + NODETR::clear(node); using ::P::Util::LexT; typedef std::list<LexT> ListT; @@ -128,12 +151,14 @@ CERR << "Containers...\n"; assert( ::P::s11n::serialize(node,list) ); + assert( ser->serialize( node, std::cout ) ); list.clear(); worked = ::P::s11n::deserialize( node, list ); assert( worked && "deser list failed :(" ); node.clear(); assert( ::P::s11n::serialize(node,map) ); + assert( ser->serialize( node, std::cout ) ); map.clear(); worked = ::P::s11n::deserialize( node, map ); assert( worked && "deser map failed :(" ); Index: FactoryTest.cpp =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/FactoryTest.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- FactoryTest.cpp 25 Dec 2004 01:57:09 -0000 1.6 +++ FactoryTest.cpp 26 Dec 2004 05:02:59 -0000 1.7 @@ -64,8 +64,8 @@ } #endif - LOAD("DefaultDocumentType"); - LOAD("CType"); + LOAD("CType"); // should load ./CType.so + LOAD("DefaultDocumentType"); // should return a (C*) LOAD("TheBase"); LOAD("AType"); LOAD("BType"); Index: Makefile.toc =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/Makefile.toc,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- Makefile.toc 26 Dec 2004 02:25:49 -0000 1.6 +++ Makefile.toc 26 Dec 2004 05:02:59 -0000 1.7 @@ -40,7 +40,7 @@ PtrTest_bin_OBJECTS = PtrTest.o PtrTest_bin_LDADD = $(LIBPSYSTEM_CLIENT_LDADD) - s11nTest_bin_OBJECTS = s11nTest.o $(LIBPS11N_CLIENT_LDADD) + s11nTest_bin_OBJECTS = s11nTest.o $(LIBPS11N_CLIENT_LDADD) $(LIBPSYSTEM_CLIENT_LDADD) include $(TOC_MAKESDIR)/BIN_PROGRAMS.make endif Index: FactoryTest.h =================================================================== RCS file: /cvsroot/pclasses/pclasses2/test/FactoryTest.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- FactoryTest.h 25 Dec 2004 01:57:09 -0000 1.2 +++ FactoryTest.h 26 Dec 2004 05:02:59 -0000 1.3 @@ -10,14 +10,29 @@ #endif #include <pclasses/Factory.h> +#include <pclasses/s11n/s11n.h> - +#define NODE_TYPE ::P::s11n::s11n_node +#define NODETR ::P::s11n::node_traits< NODE_TYPE > struct TheBase { virtual ~TheBase() {} virtual std::string classname() const = 0; + + virtual bool serialize( NODE_TYPE & dest ) const + { + NODETR::class_name( dest, this->classname() ); + CERR << "Serializing " << NODETR::class_name( dest ) << "...\n"; + return true; + } + virtual bool deserialize( const NODE_TYPE & dest ) + { + CERR << "Deserializing " << NODETR::class_name( dest ) << "...\n"; + return true; + } + }; struct AType : public TheBase @@ -36,13 +51,6 @@ }; - -#define PFACREG_TYPE AType -#define PFACREG_TYPE_INTERFACE TheBase -// #define PFACREG_TYPE_IS_ABSTRACT // define to install a null factory for AType -#define PFACREG_TYPE_NAME "AType" -#include <pclasses/FactoryReg.h> - struct BType : public AType { BType() @@ -55,10 +63,21 @@ } virtual std::string classname() const { return "BType"; } }; -#define PFACREG_TYPE BType -#define PFACREG_TYPE_INTERFACE TheBase -#define PFACREG_TYPE_NAME "BType" -#include <pclasses/FactoryReg.h> + + +#ifndef PCLASSES_S11N_INCLUDED +// avoid duplicate registrations... +# define PFACREG_TYPE AType +# define PFACREG_TYPE_INTERFACE TheBase +// #define PFACREG_TYPE_IS_ABSTRACT // define to install a null factory for AType +# define PFACREG_TYPE_NAME "AType" +# include <pclasses/FactoryReg.h> + +# define PFACREG_TYPE BType +# define PFACREG_TYPE_INTERFACE TheBase +# define PFACREG_TYPE_NAME "BType" +# include <pclasses/FactoryReg.h> +#endif // PCLASSES_S11N_INCLUDED #endif // ptest_FACTORYTEST_HPP_INCLUDED |