diff options
Diffstat (limited to 'src/libs/kdtools/kdgenericfactory.cpp')
-rw-r--r-- | src/libs/kdtools/kdgenericfactory.cpp | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/src/libs/kdtools/kdgenericfactory.cpp b/src/libs/kdtools/kdgenericfactory.cpp index 9352f83cd..df419c1f4 100644 --- a/src/libs/kdtools/kdgenericfactory.cpp +++ b/src/libs/kdtools/kdgenericfactory.cpp @@ -153,98 +153,3 @@ type T, identified by \a name. When a product is registered via this method, it will be created by calling create(). */ - -#ifdef KDTOOLSCORE_UNITTESTS - -#include <KDUnitTest/test.h> - -#include <QStringList> -#include <QMap> - -class Fruit -{ -public: - virtual ~Fruit() {} -}; - -class Apple : public Fruit -{ -}; - -class Pear : public Fruit -{ -}; - -std::ostream& operator<<( std::ostream& stream, const QStringList& list ) -{ - stream << "QStringList("; - for( QStringList::const_iterator it = list.begin(); it != list.end(); ++it ) - { - stream << " " << it->toLocal8Bit().data(); - if( it + 1 != list.end() ) - stream << ","; - } - stream << " )"; - return stream; -} - -class KDGenericFactoryTest : public KDUnitTest::Test { -public: - KDGenericFactoryTest() : Test( "KDGenericFactory" ) {} - void run() { - doRun<QHash>(); - doRun<QMap>(); - } - - template <template <typename U, typename V> class T_Map> - void doRun(); -}; - -KDAB_EXPORT_UNITTEST( KDGenericFactoryTest, "kdcoretools" ) - -template <template <typename U, typename V> class T_Map> -void KDGenericFactoryTest::doRun() { - - { - KDGenericFactory< Fruit, QString, T_Map > fruitPlantation; - assertEqual( fruitPlantation.productCount(), 0U ); - assertEqual( fruitPlantation.availableProducts(), QStringList() ); - - fruitPlantation.template registerProduct< Apple >( QLatin1String( "Apple" ) ); - assertEqual( fruitPlantation.productCount(), 1U ); - assertEqual( fruitPlantation.availableProducts(), QStringList( QLatin1String( "Apple" ) ) ); - - fruitPlantation.template registerProduct< Pear >( QLatin1String( "Pear" ) ); - assertEqual( fruitPlantation.productCount(), 2U ); - - Fruit* fruit = 0; - fruit = fruitPlantation.create( QLatin1String( "Apple" ) ); - assertNotNull( fruit ); - assertNotNull( dynamic_cast< Apple* >( fruit ) ); - - fruit = fruitPlantation.create( QLatin1String( "Pear" ) ); - assertNotNull( fruit ); - assertNotNull( dynamic_cast< Pear* >( fruit ) ); - - fruit = fruitPlantation.create( QLatin1String( "Cherry" ) ); - assertNull( fruit ); - - fruitPlantation.unregisterProduct( QLatin1String( "Apple" ) ); - assertEqual( fruitPlantation.productCount(), 1U ); - assertEqual( fruitPlantation.availableProducts(), QStringList( QLatin1String( "Pear" ) ) ); - fruit = fruitPlantation.create( QLatin1String( "Apple" ) ); - assertNull( fruit ); - - fruit = fruitPlantation.create( QLatin1String( "Pear" ) ); - assertNotNull( fruit ); - assertNotNull( dynamic_cast< Pear* >( fruit ) ); - - - fruitPlantation.unregisterProduct( QLatin1String( "Pear" ) ); - assertEqual( fruitPlantation.productCount(), 0U ); - fruit = fruitPlantation.create( QLatin1String( "Pear" ) ); - assertNull( fruit ); - } - -} -#endif // KDTOOLSCORE_UNITTESTS |