From: stephan b. <sg...@us...> - 2004-12-23 20:12:28
|
Update of /cvsroot/pclasses/pclasses2/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv26362 Added Files: FactoryTest.cpp Log Message: egg --- NEW FILE: FactoryTest.cpp --- #ifdef NDEBUG # // force assert() to work... # undef NDEBUG #endif #include <string> #include <cassert> #include <pclasses/Factory.h> #ifndef CERR #define CERR std::cerr << __FILE__ << ":" << std::dec << __LINE__ << " : " #endif struct AType { AType() { CERR << "AType()\n"; } virtual ~AType() { CERR << "~AType()\n"; } virtual std::string classname() { return "AType"; } }; struct BType : public AType { BType() { CERR << "BType()\n"; } virtual ~BType() { CERR << "~BType()\n"; } virtual std::string classname() { return "BType"; } }; struct CType : public BType { CType() { CERR << "CType()\n"; } virtual ~CType() { CERR << "~CType()\n"; } virtual std::string classname() { return "CType"; } }; int main( int argc, char ** argv ) { CERR << "Factory tests...\n"; typedef P::Factory<AType> FT; P::CL::registerBase<AType>( "AType" ); P::CL::registerSubtype<AType,BType>( "BType" ); P::CL::registerSubtype<AType,CType>( "CType" ); AType * a = 0; #define LOAD(CN) a = P::CL::classload<AType>( CN ); \ CERR << CN << " loaded? == " << a << "\n"; \ if( a ) CERR << "classname="<<a->classname()<<"\n"; \ delete( a ); a = 0; LOAD("AType"); LOAD("BType"); LOAD("CType"); LOAD("NoType"); return 0; } |