diff --git a/test/RegressionTest/AbstractFactoryTest.h b/test/RegressionTest/AbstractFactoryTest.h new file mode 100755 index 0000000..4fae51a --- /dev/null +++ b/test/RegressionTest/AbstractFactoryTest.h @@ -0,0 +1,86 @@ +/////////////////////////////////////////////////////////////////////////////// +// Unit Test for Loki +// +// Copyright Terje Slettebų and Pavel Vozenilek 2002. +// +// Permission to use, copy, modify, and distribute this software for any +// purpose is hereby granted without fee, provided that this copyright and +// permissions notice appear in all copies and derivatives. +// +// This software is provided "as is" without express or implied warranty. +// +// Last update: September 16, 2002 +/////////////////////////////////////////////////////////////////////////////// + +#ifndef ABSTRACTFACTORYTEST_H +#define ABSTRACTFACTORYTEST_H + +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////////// +// AbstractFactoryTest +/////////////////////////////////////////////////////////////////////////////// + +class Soldier { public: virtual ~Soldier() {} }; +class Monster { public: virtual ~Monster() {} }; +class SuperMonster { public: virtual ~SuperMonster() {} }; + +class SillySoldier : public Soldier {}; +class SillyMonster : public Monster {}; +class SillySuperMonster : public SuperMonster {}; + +class BadSoldier : public Soldier {}; +class BadMonster : public Monster {}; +class BadSuperMonster : public SuperMonster {}; + +typedef Loki::AbstractFactory AbstractEnemyFactory; + +typedef Loki::ConcreteFactory EasyLevelEnemyFactory; + +typedef Loki::ConcreteFactory HardLevelEnemyFactory; + +class AbstractFactoryTest : public Test +{ +public: + AbstractFactoryTest() : Test("AbstractFactory.h") {} + + virtual void execute(TestResult &result) + { + printName(result); + + using namespace Loki; + + bool r; + + std::auto_ptr easyFactory(new EasyLevelEnemyFactory); + std::auto_ptr hardFactory(new HardLevelEnemyFactory); + + Soldier *s; + + s = easyFactory->Create(); + + r= !!(typeid(*s)==typeid(SillySoldier)); //SGB !! eliminates bool-to-int performance warning + + delete s; + +#ifndef __BORLANDC__ + + s = hardFactory->Create(); //BCB bug!!! - always creates SillySoldier + + r=r && typeid(*s)==typeid(BadSoldier); + + delete s; + +#endif + + testAssert("AbstractFactory",r,result); + + std::cout << '\n'; + } +} abstractFactoryTest; + +#endif diff --git a/test/RegressionTest/AssocVectorTest.h b/test/RegressionTest/AssocVectorTest.h new file mode 100755 index 0000000..bb87488 --- /dev/null +++ b/test/RegressionTest/AssocVectorTest.h @@ -0,0 +1,374 @@ +/////////////////////////////////////////////////////////////////////////////// +// Unit Test for Loki +// +// Copyright Terje Slettebų and Pavel Vozenilek 2002. +// +// Permission to use, copy, modify, and distribute this software for any +// purpose is hereby granted without fee, provided that this copyright and +// permissions notice appear in all copies and derivatives. +// +// This software is provided "as is" without express or implied warranty. +// +// Last update: September 16, 2002 +/////////////////////////////////////////////////////////////////////////////// + +#ifndef ASSOCVECTORTEST_H +#define ASSOCVECTORTEST_H + +#include +#include +#include +#include "UnitTest.h" + +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) + #define C_Namespace +#else + #define C_Namespace std +#endif + +/////////////////////////////////////////////////////////////////////////////// +// AssocVectorTest +/////////////////////////////////////////////////////////////////////////////// + +/////////////////////////////////////////////////////////////////////////////// +// STL compatible allocator +/////////////////////////////////////////////////////////////////////////////// + +template class TestAllocator : public std::allocator +{ +public: + typedef T value_type; + typedef value_type* pointer; + typedef const value_type* const_pointer; + typedef value_type& reference; + typedef const value_type& const_reference; + typedef C_Namespace::size_t size_type; + typedef C_Namespace::ptrdiff_t difference_type; + + template + struct rebind { typedef TestAllocator other; }; + + TestAllocator() {} + TestAllocator(const TestAllocator&) {} + +#if !(defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__)) + + template + TestAllocator(const TestAllocator&) {} + +#endif + + ~TestAllocator() {} + + pointer address(reference x) const { return &x; } + const_pointer address(const_reference x) const { + return x; + } + + pointer allocate(size_type n, const_pointer = 0) { + return static_cast(::operator new(n * sizeof(T))); + } + + void deallocate(pointer p, size_type size) { + ::operator delete(p); + } + + size_type max_size() const { + return static_cast(-1) / sizeof(T); + } + + void construct(pointer p, const value_type& x) { + new(p) value_type(x); + } + void destroy(pointer p) { +#ifndef _USE_OLD_RW_STL // ?? failed to compile when RogueWave is enabled !?! + p->~value_type(); +#endif + } + +private: + void operator=(const TestAllocator&); +}; + +/////////////////////////////////////////////////////////////////////////////// +// AVTestClass +/////////////////////////////////////////////////////////////////////////////// + +class AVTestClass +{ +public: + AVTestClass(int value) : value_(value) {} + AVTestClass(const AVTestClass& other) : value_(other.value_) {} + AVTestClass& operator=(const AVTestClass& other) { + value_ = other.value_; + return *this; + } + + int value_; +}; + +bool operator<(const AVTestClass& lhs, const AVTestClass& rhs) +{ + return lhs.value_ < rhs.value_; +} + +/////////////////////////////////////////////////////////////////////////////// +// str_less +/////////////////////////////////////////////////////////////////////////////// + +struct str_less : public std::binary_function { + bool operator()(const char* x, const char* y) const { + return strcmp(x, y) < 0; + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// int_less +/////////////////////////////////////////////////////////////////////////////// + +unsigned int_test_count = 0; // to verify usage +struct int_less : public std::less +{ + bool operator()(int x, int y) const { + ++int_test_count; + return x < y; + } +}; + +/////////////////////////////////////////////////////////////////////////////// +// is_sorted +/////////////////////////////////////////////////////////////////////////////// + +template +bool is_sorted(const Vect& v) { + if (v.size() < 2) return true; + typename Vect::const_iterator it = v.begin(); + typename Vect::key_type previous = it->first; + ++it; + while (it != v.end()) { + typename Vect::key_type current = it->first; + if (!v.key_comp()(previous, current)) return false; + previous = current; + ++it; + } + return true; +} + +/////////////////////////////////////////////////////////////////////////////// + +typedef Loki::AssocVector, TestAllocator > > test_vect1_t; +typedef Loki::AssocVector > > test_vect2_t; +typedef Loki::AssocVector test_vect3_t; +typedef Loki::AssocVector, TestAllocator > > test_vect4_t; +typedef Loki::AssocVector test_vect5_t; + +/////////////////////////////////////////////////////////////////////////////// + +void check_insert1(test_vect1_t& v) +{ + C_Namespace::srand(10); + for (unsigned i = 0; i < 100; ++i) { + int x = C_Namespace::rand(); + v.insert(std::make_pair(x, x)); + assert(is_sorted(v)); + } + assert(v.size() == 100); +} + +/////////////////////////////////////////////////////////////////////////////// +// check_swap +/////////////////////////////////////////////////////////////////////////////// + +template +void check_swap(Vect& v1, Vect& v2) +{ + size_t size1 = v1.size(); + size_t size2 = v2.size(); + v1.swap(v2); + assert(v1.size() == size2); + assert(v2.size() == size1); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_vect1 +/////////////////////////////////////////////////////////////////////////////// + +void test_vect1() +{ + test_vect1_t vec11; + assert(vec11.size() == 0); + + check_insert1(vec11); + size_t size1 = vec11.size(); + assert(size1); + + test_vect1_t vec12(vec11.begin(), vec11.end()); + assert(vec12.size() == vec11.size()); + assert(vec11.size() == size1); + + test_vect1_t vec13; + vec13 = vec11; + assert(vec13.size() == vec11.size()); + assert(vec11.size() == size1); + + // this doesn't compile on Borland C++ 6.0 !?! + //test_vect1_t vec99(test_vect1_t::key_compare(), TestAllocator()); + //assert(vec99.size() == 0); //- here ir cries + + test_vect1_t::key_compare comp = test_vect1_t::key_compare(); + test_vect1_t vec14(comp, TestAllocator()); + assert(vec14.size() == 0); + + check_swap(vec11, vec14); + assert(vec14.size() == size1); + assert(vec11.size() == 0); + + // this compiles, unlike object on stack + test_vect1_t* vec15 = new test_vect1_t(test_vect1_t::key_compare(), TestAllocator()); + assert(vec15->size() == 0); + check_insert1(*vec15); + delete vec15; + + // different comparator test - doesn't work for Loki + //comp = int_less(); + //test_vect1_t vec16(comp); + //assert(vec16.size() == 0); + //assert(int_test_count == 0); + //check_insert1(vec16); + //assert(int_test_count != 0); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_vect2 +/////////////////////////////////////////////////////////////////////////////// + +void test_vect2() +{ + test_vect2_t vec21; + vec21.insert(std::make_pair("abc", 1)); + vec21.insert(std::make_pair("xyz", 3)); + vec21.insert(std::make_pair("def", 2)); + assert(vec21.size() == 3); + assert(is_sorted(vec21)); + + test_vect2_t::iterator it = vec21.find("xyz"); + assert(it != vec21.end()); + assert(it->second == 3); + + std::pair aux = vec21.insert(std::make_pair("xyz", 99)); + assert(!aux.second); + assert(aux.first->first == "xyz"); + assert(aux.first->second == 3); + + it = vec21.find("xyz"); + assert(it != vec21.end()); + assert(it->second == 3); + + vec21.erase(it); + assert(vec21.size() == 2); + it = vec21.find("xyz"); + assert(it == vec21.end()); + vec21.erase("xyz"); + vec21.erase("abc"); + assert(vec21.size() == 1); + + vec21.clear(); + assert(vec21.size() == 0); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_vect3 +/////////////////////////////////////////////////////////////////////////////// + +void test_vect3() +{ + // To use string, you need: + // 1) enable _STLP_USE_NEWALLOC in include\stl\_site_config.h + // 2) either disable use of any dynamic RTL (menu Project | Options | Linker) + // 3) or recompile STLPort DLL. + // This all is related to bug in STLPort allocator. + test_vect3_t vec31; + C_Namespace::srand(111); + // a stress test + for (unsigned i = 0; i < 2 * 1000; ++i) { + char buffer[17]; + C_Namespace::sprintf(buffer, "string%d", C_Namespace::rand()); + std::string s(buffer); + vec31.insert(std::make_pair(s, s)); + } +} + +/////////////////////////////////////////////////////////////////////////////// +// test_vect4 +/////////////////////////////////////////////////////////////////////////////// + +void test_vect4() +{ + test_vect4_t vec41; + for (int i = 0; i < 100; ++i) { + vec41.insert(std::make_pair(AVTestClass(i), AVTestClass(i))); + } + assert(vec41.size() == 100); + + vec41.insert(std::make_pair(AVTestClass(300), AVTestClass(300))); + vec41.insert(std::make_pair(AVTestClass(200), AVTestClass(200))); + assert(vec41.size() == 102); + + test_vect4_t::iterator it = vec41.find(AVTestClass(22)); + assert(it != vec41.end()); + assert(it->second.value_ == 22); + + test_vect4_t vec42; + vec42.swap(vec41); + assert(vec41.size() == 0); + assert(vec42.size() == 102); + + vec42.erase(vec42.begin(), vec42.end()); + assert(vec42.size() == 0); +} + +/////////////////////////////////////////////////////////////////////////////// +// test_vect5 +/////////////////////////////////////////////////////////////////////////////// + +void test_vect5() +{ + test_vect5_t vec51; + vec51.insert(test_vect5_t::value_type(3, "XXX")); + vec51.insert(std::make_pair(1, "X")); + vec51.insert(std::make_pair(2, "XX")); + + test_vect5_t::const_iterator it = vec51.begin(); + std::string::size_type count=1; + + while (it != vec51.end()) { + assert(std::string(it->second).length()==count); + + ++count; + + it++; // intentionally + } +} + +class AssocVectorTest : public Test +{ +public: + AssocVectorTest() : Test("AssocVector.h") {} + + virtual void execute(TestResult &result) + { + printName(result); + + test_vect1(); + test_vect2(); + test_vect3(); + test_vect4(); + test_vect5(); + + testAssert("AssocVector",true,result), + + std::cout << '\n'; + } +} assocVectorTest; + +#endif diff --git a/test/RegressionTest/DataGeneratorsTest.h b/test/RegressionTest/DataGeneratorsTest.h new file mode 100755 index 0000000..b0e8451 --- /dev/null +++ b/test/RegressionTest/DataGeneratorsTest.h @@ -0,0 +1,62 @@ +//DataGeneratorsTest.h + + +#ifndef DATAGENERATORSTEST_H +#define DATAGENERATORSTEST_H + +#include +#include + +struct DataGeneratorsTest : public Test + { + DataGeneratorsTest() : Test("DataGeneratorsTest.h") + {} + virtual void execute(TestResult& result) + { + this->printName(result); + + using namespace Loki; + using namespace Loki::TL; + + bool b; + typedef MakeTypelist<>::Result null_tl; + typedef MakeTypelist::Result char_types; + std::size_t n = Length::value; + + std::vector names; + names.reserve(n); + //Some fascist decided that all temporaries should be const. + //The following line of code stupidity is a direct result of the half-baked idea + iterate_types(std::back_inserter(names)); + b = names.size() == n; + testAssert("iterate_types - Check Length", b, result); + + std::vector sizes; + sizes.reserve(n); + typedef MakeTypelist::Result some_types; + iterate_types(std::back_inserter(sizes)); + size_t apriori_size[] = {sizeof(char), sizeof(short), sizeof(int), sizeof(double)}; + b = true; + for(std::size_t i=0; i(sizes); + b = sizes.size() == 0; + testAssert("iterate_types - Degenerate Case 1 - Null List", b, result); + + sizes.resize(0); + iterate_types(sizes); + b = sizes.size() == 0; + testAssert("iterate_types - Degenerate Case 2 - NullType", b, result); + } + } datageneratorsTest; + +#endif //DATAGENERATORSTEST_H diff --git a/test/RegressionTest/FactoryParmTest.h b/test/RegressionTest/FactoryParmTest.h new file mode 100755 index 0000000..52c6667 --- /dev/null +++ b/test/RegressionTest/FactoryParmTest.h @@ -0,0 +1,434 @@ +/////////////////////////////////////////////////////////////////////////////// +// Unit Test for Loki +// +// Copyright (C) 2002 Terje Slettebų +// Copyright (C) 2002 Pavel Vozenilek +// Copyright (C) 2005 Peter Kümmel + +// Permission to use, copy, modify, and distribute this software for any +// purpose is hereby granted without fee, provided that this copyright and +// permissions notice appear in all copies and derivatives. +// +// This software is provided "as is" without express or implied warranty. +// +/////////////////////////////////////////////////////////////////////////////// + +// $Header$ + +#ifndef FACTORYPARMTEST_H +#define FACTORYPARMTEST_H + + +#ifdef ENABLE_NEW_FACTORY_CODE + +#include + +using Loki::Factory; +using Loki::SingletonHolder; + +/////////////////////////////////////////////////////////////////////////////// +// FactoryPArmTest +/////////////////////////////////////////////////////////////////////////////// + +namespace FactoryTestParmPrivate +{ + class AbstractProduct + { + }; + + class Product : public AbstractProduct + { + public: + Product() + {} + Product(int) + {} + Product(int, int) + {} + Product(int, int, int) + {} + Product(int, int, int, int) + {} + Product(int, int, int, int, int) + {} + Product(int, int, int, int, int, + int) + {} + Product(int, int, int, int, int, + int, int) + {} + Product(int, int, int, int, int, + int, int, int) + {} + Product(int, int, int, int, int, + int, int, int, int) + {} + Product(int, int, int, int, int, + int, int, int, int, int) + {} + Product(int, int, int, int, int, + int, int, int, int, int, + int) + {} + Product(int, int, int, int, int, + int, int, int, int, int, + int, int) + {} + Product(int, int, int, int, int, + int, int, int, int, int, + int, int, int) + {} + Product(int, int, int, int, int, + int, int, int, int, int, + int, int, int, int) + {} + Product(int, int, int, int, int, + int, int, int, int, int, + int, int, int, int, int) + {} + + }; + + + template< class T> + class CreatorClass + { + public: + CreatorClass() + { + } + T* create0() + { + return new T; + } + T* create1( int) + { + return new T(1); + } + T* create2( int, int) + { + return new T(1,2); + } + T* create3( int, int, int) + { + return new T(1,2,3); + } + T* create4( int, int, int, int) + { + return new T(1,2,3,4); + } + T* create5( int, int, int, int, int) + { + return new T(1,2,3,4,5); + } + T* create6( int, int, int, int, int, + int) + { + return new T(1,2,3,4,5,6); + } + T* create7( int, int, int, int, int, + int, int) + { + return new T(1,2,3,4,5,6,7); + } + T* create8( int, int, int, int, int, + int, int, int) + { + return new T(1,2,3,4,5,6,7,8); + } + T* create9( int, int, int, int, int, + int, int, int, int) + { + return new T(1,2,3,4,5,6,7,8,9); + } + T* create10(int, int, int, int, int, + int, int, int, int, int) + { + return new T(1,2,3,4,5,6,7,8,9,10); + } + T* create11(int, int, int, int, int, + int, int, int, int, int, + int) + { + return new T(1,2,3,4,5,6,7,8,9,10,11); + } + T* create12(int, int, int, int, int, + int, int, int, int, int, + int, int) + { + return new T(1,2,3,4,5,6,7,8,9,10,11,12); + } + T* create13(int, int, int, int, int, + int, int, int, int, int, + int, int, int) + { + return new T(1,2,3,4,5,6,7,8,9,10,11,12,13); + } + T* create14(int, int, int, int, int, + int, int, int, int, int, + int, int, int, int) + { + return new T(1,2,3,4,5,6,7,8,9,10,11,12,13,14); + } + T* create15(int, int, int, int, int, + int, int, int, int, int, + int, int, int, int, int) + { + return new T(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15); + } + }; + + typedef + SingletonHolder< + Factory< AbstractProduct, int > + >Factory0; + + typedef + SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_1( int ) > + >Factory1; + + typedef SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_2( int, int ) > + >Factory2; + + typedef + SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_3( int, int, int ) > + >Factory3; + + typedef + SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_4( int, int, int, int ) > + >Factory4; + + typedef + SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_5( int, int, int, int, int ) > + >Factory5; + + typedef + SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_6( int, int, int, int, int, + int ) > + >Factory6; + + typedef + SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_7( int, int, int, int, int, + int, int ) > + >Factory7; + + typedef + SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_8( int, int, int, int, int, + int, int, int ) > + >Factory8; + + + typedef + SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_9( int, int, int, int, int, + int, int, int, int ) > + >Factory9; + + typedef + SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_10( int, int, int, int, int, + int, int, int, int, int ) > + >Factory10; + + typedef + SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_11( int, int, int, int, int, + int, int, int, int, int, + int ) > + >Factory11; + + typedef + SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_12( int, int, int, int, int, + int, int, int, int, int, + int, int ) > + >Factory12; + + typedef + SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_13( int, int, int, int, int, + int, int, int, int, int, + int, int, int ) > + >Factory13; + + typedef + SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_14( int, int, int, int, int, + int, int, int, int, int, + int, int, int, int ) > + >Factory14; + + typedef + SingletonHolder< + Factory< AbstractProduct, int, TYPELIST_15( int, int, int, int, int, + int, int, int, int, int, + int, int, int, int, int ) > + >Factory15; + + + CreatorClass creaClass; + + bool registerAll(){ + + bool const o0 = Factory0::Instance().Register( 1, &creaClass, &CreatorClass::create0 ); + bool const o1 = Factory1::Instance().Register( 1, &creaClass, &CreatorClass::create1 ); + bool const o2 = Factory2::Instance().Register( 1, &creaClass, &CreatorClass::create2 ); + bool const o3 = Factory3::Instance().Register( 1, &creaClass, &CreatorClass::create3 ); + bool const o4 = Factory4::Instance().Register( 1, &creaClass, &CreatorClass::create4 ); + bool const o5 = Factory5::Instance().Register( 1, &creaClass, &CreatorClass::create5 ); + bool const o6 = Factory6::Instance().Register( 1, &creaClass, &CreatorClass::create6 ); + bool const o7 = Factory7::Instance().Register( 1, &creaClass, &CreatorClass::create7 ); + bool const o8 = Factory8::Instance().Register( 1, &creaClass, &CreatorClass::create8 ); + bool const o9 = Factory9::Instance().Register( 1, &creaClass, &CreatorClass::create9 ); + bool const o10 = Factory10::Instance().Register( 1, &creaClass, &CreatorClass::create10 ); + bool const o11 = Factory11::Instance().Register( 1, &creaClass, &CreatorClass::create11 ); + bool const o12 = Factory12::Instance().Register( 1, &creaClass, &CreatorClass::create12 ); + bool const o13 = Factory13::Instance().Register( 1, &creaClass, &CreatorClass::create13 ); + bool const o14 = Factory14::Instance().Register( 1, &creaClass, &CreatorClass::create14 ); + bool const o15 = Factory15::Instance().Register( 1, &creaClass, &CreatorClass::create15 ); + + return o0 && o1 && o2 && o3 && o4 && o5 && o6 && o7 && o8 && o9 && o10 && o11 && o12 && o13 && o14 && o15; + } + + bool testFactoryParm() + { + bool reg = registerAll(); + + AbstractProduct* p; + + p = Factory0::Instance().CreateObject(1); + delete p; + bool test0=p!=NULL; + + p = Factory1::Instance().CreateObject(1,64); + delete p; + bool test1=p!=NULL; + + p = Factory2::Instance().CreateObject(1,64,64); + delete p; + bool test2=p!=NULL; + + p = Factory3::Instance().CreateObject(1,64,64,64); + delete p; + bool test3=p!=NULL; + + p = Factory4::Instance().CreateObject(1,64,64,64,64); + delete p; + bool test4=p!=NULL; + + p = Factory5::Instance().CreateObject(1,64,64,64,64,64); + delete p; + bool test5=p!=NULL; + + p = Factory6::Instance().CreateObject(1, 64,64,64,64,64, + 64); + delete p; + bool test6=p!=NULL; + + p = Factory7::Instance().CreateObject(1, 64,64,64,64,64, + 64,64); + delete p; + bool test7=p!=NULL; + + p = Factory8::Instance().CreateObject(1, 64,64,64,64,64, + 64,64,64); + delete p; + bool test8=p!=NULL; + + p = Factory9::Instance().CreateObject(1, 64,64,64,64,64, + 64,64,64,64); + delete p; + bool test9=p!=NULL; + + p = Factory10::Instance().CreateObject(1, 64,64,64,64,64, + 64,64,64,64,64); + delete p; + bool test10=p!=NULL; + + p = Factory11::Instance().CreateObject(1, 64,64,64,64,64, + 64,64,64,64,64, + 64); + delete p; + bool test11=p!=NULL; + + p = Factory12::Instance().CreateObject(1, 64,64,64,64,64, + 64,64,64,64,64, + 64,64); + delete p; + bool test12=p!=NULL; + + p = Factory13::Instance().CreateObject(1, 64,64,64,64,64, + 64,64,64,64,64, + 64,64,64); + delete p; + bool test13=p!=NULL; + + p = Factory14::Instance().CreateObject(1, 64,64,64,64,64, + 64,64,64,64,64, + 64,64,64,64); + delete p; + bool test14=p!=NULL; + + p = Factory15::Instance().CreateObject(1, 64,64,64,64,64, + 64,64,64,64,64, + 64,64,64,64,64); + delete p; + bool test15=p!=NULL; + + return reg && test0 && + test1 && test2 && test3 && test4 && test5 && + test6 && test7 && test8 && test9 && test10 && + test11 && test12 && test13 && test14 && test15; + } + + +} + +class FactoryParmTest : public Test +{ +public: + FactoryParmTest() : Test("FactoryParm.h") {} + + virtual void execute(TestResult &result) + { + printName(result); + + bool test1=FactoryTestParmPrivate::testFactoryParm(); + + bool r=test1; + + testAssert("FactoryParm",r,result); + + std::cout << '\n'; + } + +} factoryParmTest; + + +#endif + +#endif + + +// $Log$ +// Revision 1.4 2005/09/24 15:25:20 syntheticpp +// ove RegressionTest +// +// Revision 1.6 2005/07/31 15:06:22 syntheticpp +// invert new factory code macro logic to be ReferenceTest more compatible with noncc code +// +// Revision 1.5 2005/07/28 14:59:17 syntheticpp +// remove unreferenced parameter warning +// +// Revision 1.4 2005/07/28 14:26:10 syntheticpp +// add cvs Header/Log +// + diff --git a/test/RegressionTest/FactoryTest.h b/test/RegressionTest/FactoryTest.h new file mode 100755 index 0000000..5e3d804 --- /dev/null +++ b/test/RegressionTest/FactoryTest.h @@ -0,0 +1,146 @@ +/////////////////////////////////////////////////////////////////////////////// +// Unit Test for Loki +// +// Copyright Terje Slettebų and Pavel Vozenilek 2002. +// +// Permission to use, copy, modify, and distribute this software for any +// purpose is hereby granted without fee, provided that this copyright and +// permissions notice appear in all copies and derivatives. +// +// This software is provided "as is" without express or implied warranty. +// +// Last update: September 16, 2002 +/////////////////////////////////////////////////////////////////////////////// + +#ifndef FACTORYTEST_H +#define FACTORYTEST_H + +#include + +/////////////////////////////////////////////////////////////////////////////// +// FactoryTest +/////////////////////////////////////////////////////////////////////////////// + +namespace FactoryTestPrivate +{ + class Shape + { + public: + virtual ~Shape() = 0; + }; + + inline Shape::~Shape() {} + + class Polygon : public Shape + { + }; + + class Line : public Shape + { + }; + + class Circle : public Shape + { + }; + + Polygon *createPolygon() { return new Polygon; } + Line *createLine() { return new Line; } + Circle *createCircle() { return new Circle; } + + Polygon *clonePolygon(Polygon *) { return new Polygon; } + Line *cloneLine(Line *) { return new Line; } + Circle *cloneCircle(Circle *) { return new Circle; } + + typedef Loki::Factory FactoryType; + + bool testFactory() + { + FactoryType factory; + + factory.Register(1, (Shape * (*)()) createPolygon); + factory.Register(2, (Shape * (*)()) createCircle); + factory.Register(3, (Shape * (*)()) createLine); + + Shape *s; + + s = factory.CreateObject(1); + delete s; + bool test1=s!=NULL; + + s = factory.CreateObject(2); + delete s; + bool test2=s!=NULL; + + s = factory.CreateObject(3); + delete s; + bool test3=s!=NULL; + + bool test4=true; + +// try +// { +// factory.CreateObject(4); +// +// test4=false; +// } +// catch (std::exception&) +// { +// } + + return test1 && test2 && test3 && test4; + } + + typedef Loki::CloneFactory CloneFactoryType; + + bool testCloneFactory() + { + CloneFactoryType factory; + + factory.Register(Loki::TypeInfo(typeid(Polygon)), (Shape * (*)(const Shape *)) clonePolygon); + factory.Register(Loki::TypeInfo(typeid(Circle)), (Shape * (*)(const Shape *)) cloneCircle); + factory.Register(Loki::TypeInfo(typeid(Line)), (Shape * (*)(const Shape *)) cloneLine); + + Polygon p; + Circle c; + Line l; + + Shape *s; + + s = factory.CreateObject(&p); + delete s; + bool test1=s!=NULL; + + s = factory.CreateObject(&c); + delete s; + bool test2=s!=NULL; + + s = factory.CreateObject(&l); + delete s; + bool test3=s!=NULL; + + return test1 && test2 && test3; + } +} + +class FactoryTest : public Test +{ +public: + FactoryTest() : Test("Factory.h") {} + + virtual void execute(TestResult &result) + { + printName(result); + + bool test1=FactoryTestPrivate::testFactory(); + + bool test2=FactoryTestPrivate::testCloneFactory(); + + bool r=test1 && test2; + + testAssert("Factory",r,result); + + std::cout << '\n'; + } +} factoryTest; + +#endif diff --git a/test/RegressionTest/FunctorTest.h b/test/RegressionTest/FunctorTest.h new file mode 100755 index 0000000..720d890 --- /dev/null +++ b/test/RegressionTest/FunctorTest.h @@ -0,0 +1,112 @@ +/////////////////////////////////////////////////////////////////////////////// +// Unit Test for Loki +// +// Copyright Terje Slettebų and Pavel Vozenilek 2002. +// +// Permission to use, copy, modify, and distribute this software for any +// purpose is hereby granted without fee, provided that this copyright and +// permissions notice appear in all copies and derivatives. +// +// This software is provided "as is" without express or implied warranty. +// +// Last update: September 16, 2002 +/////////////////////////////////////////////////////////////////////////////// + +#ifndef FUNCTORTEST_H +#define FUNCTORTEST_H + +#include + +/////////////////////////////////////////////////////////////////////////////// +// FunctorTest +/////////////////////////////////////////////////////////////////////////////// + +class FunctorTest : public Test +{ +public: + FunctorTest() : Test("Functor.h") {} + + virtual void execute(TestResult &result) + { + printName(result); + + using namespace Loki; + + bool r; + + TestFunctor testFunctor; + TestClass testClass; + + Functor function(testFunction); + Functor functor(testFunctor); + Functor classFunctor(&testClass,&TestClass::member); + Functor functorCopy(function); + Functor bindFunctor(BindFirst(function,testResult)); + Functor chainFunctor(Chain(bindFunctor,bindFunctor)); + + testResult=false; + function(testResult); + bool functionResult=testResult; + + testResult=false; + functor(testResult); + bool functorResult=testResult; + + testResult=false; + classFunctor(testResult); + bool classFunctorResult=testResult; + + testResult=false; + functorCopy(testResult); + bool functorCopyResult=testResult; + + testResult=false; + bindFunctor(); + bool bindFunctorResult=testResult; + + testResult=false; + chainFunctor(); + bool chainFunctorResult=testResult; + + r=functionResult && functorResult && classFunctorResult && functorCopyResult && bindFunctorResult && + chainFunctorResult; + + testAssert("Functor",r,result); + + std::cout << '\n'; + } + +private: + static bool testResult; + + static void testFunction(bool &result) + { + result=true; + } + + class TestFunctor + { + public: + void operator()(bool &result) + { + result=true; + } + }; + + class TestClass + { + public: + void member(bool &result) + { + result=true; + } + }; +} functorTest; + +bool FunctorTest::testResult; + +#ifndef SMALLOBJ_CPP +# define SMALLOBJ_CPP +# include "../../SmallObj.cpp" +#endif +#endif diff --git a/test/RegressionTest/MSVCUnitTest.sln b/test/RegressionTest/MSVCUnitTest.sln new file mode 100755 index 0000000..70bd2ce --- /dev/null +++ b/test/RegressionTest/MSVCUnitTest.sln @@ -0,0 +1,21 @@ +Microsoft Visual Studio Solution File, Format Version 7.00 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTest", "MSVCUnitTest.vcproj", "{79729949-F144-4098-BFE9-B6320E6AC3F6}" +EndProject +Global + GlobalSection(SolutionConfiguration) = preSolution + ConfigName.0 = Debug + ConfigName.1 = Release + EndGlobalSection + GlobalSection(ProjectDependencies) = postSolution + EndGlobalSection + GlobalSection(ProjectConfiguration) = postSolution + {79729949-F144-4098-BFE9-B6320E6AC3F6}.Debug.ActiveCfg = Debug|Win32 + {79729949-F144-4098-BFE9-B6320E6AC3F6}.Debug.Build.0 = Debug|Win32 + {79729949-F144-4098-BFE9-B6320E6AC3F6}.Release.ActiveCfg = Release|Win32 + {79729949-F144-4098-BFE9-B6320E6AC3F6}.Release.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + EndGlobalSection + GlobalSection(ExtensibilityAddIns) = postSolution + EndGlobalSection +EndGlobal diff --git a/test/RegressionTest/MSVCUnitTest.vcproj b/test/RegressionTest/MSVCUnitTest.vcproj new file mode 100755 index 0000000..be10da2 --- /dev/null +++ b/test/RegressionTest/MSVCUnitTest.vcproj @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/RegressionTest/Makefile.mingw b/test/RegressionTest/Makefile.mingw new file mode 100755 index 0000000..866cbae --- /dev/null +++ b/test/RegressionTest/Makefile.mingw @@ -0,0 +1,30 @@ + + +CPP = g++ +CC = gcc +OBJ = tmp\Test.o +LINKOBJ = tmp\Test.o +CXXINCS = -I./../../include -I./../../include/loki +BIN = main-mingw.exe +CXXFLAGS = $(CXXINCS) -W0 -O2 +RM = rm -f +CHK_DIR_EXISTS= if not exist +MKDIR = mkdir + +.PHONY: all all-before all-after clean clean-custom + +all: all-before check_tmp main-mingw.exe all-after + + +clean: clean-custom + ${RM} $(OBJ) $(BIN) + +$(BIN): $(OBJ) + $(CPP) $(LINKOBJ) -o main-mingw.exe $(LIBS) + +check_tmp: + @$(CHK_DIR_EXISTS) "tmp\" $(MKDIR) "tmp" + +tmp\Test.o: Test.cpp + $(CPP) -c Test.cpp -o tmp\Test.o $(CXXFLAGS) + diff --git a/test/RegressionTest/RegressionTest.dev b/test/RegressionTest/RegressionTest.dev new file mode 100755 index 0000000..577d75d --- /dev/null +++ b/test/RegressionTest/RegressionTest.dev @@ -0,0 +1,399 @@ +[Project] +FileName=RegressionTest.dev +Name=RegressionTest +UnitCount=34 +Type=1 +Ver=1 +ObjFiles= +Includes=.;..\..\include;..\..\include\loki +Libs= +PrivateResource= +ResourceIncludes= +MakeIncludes= +Compiler= +CppCompiler=-Wall -pedantic_@@_ +Linker= +IsCpp=1 +Icon= +ExeOutput= +ObjectOutput= +OverrideOutput=0 +OverrideOutputName=RegressionTest.exe +HostApplication= +Folders=loki,src +CommandLine= +UseCustomMakefile=0 +CustomMakefile=Makefile.loki +IncludeVersionInfo=0 +SupportXPThemes=0 +CompilerSet=0 +CompilerSettings=0000000000000001000000 + +[VersionInfo] +Major=0 +Minor=1 +Release=1 +Build=1 +LanguageID=1033 +CharsetID=1252 +CompanyName= +FileVersion= +FileDescription=Developed using the Dev-C++ IDE +InternalName= +LegalCopyright= +LegalTrademarks= +OriginalFilename= +ProductName= +ProductVersion= +AutoIncBuildNr=0 + +[Unit1] +FileName=Test.cpp +CompileCpp=1 +Folder=src +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit2] +FileName=AbstractFactoryTest.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit3] +FileName=AssocVectorTest.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit5] +FileName=FactoryParmTest.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit6] +FileName=FactoryTest.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit7] +FileName=FunctorTest.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit8] +FileName=SingletonTest.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit9] +FileName=SmallObjectTest.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit10] +FileName=SmartPtrTest.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit11] +FileName=TypelistTest.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit12] +FileName=TypeManipTest.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit13] +FileName=TypeTraitsTest.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit14] +FileName=UnitTest.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit15] +FileName=..\..\include\loki\Visitor.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit16] +FileName=..\..\include\loki\AssocVector.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit17] +FileName=..\..\include\loki\DataGenerators.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit18] +FileName=..\..\include\loki\EmptyType.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit19] +FileName=..\..\include\loki\Factory.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit20] +FileName=..\..\include\loki\Functor.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit21] +FileName=..\..\include\loki\HierarchyGenerators.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit22] +FileName=..\..\include\loki\LokiTypeInfo.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit23] +FileName=..\..\include\loki\MultiMethods.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit24] +FileName=..\..\include\loki\NullType.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit25] +FileName=..\..\include\loki\Singleton.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit26] +FileName=..\..\include\loki\SmallObj.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit27] +FileName=..\..\include\loki\SmartPtr.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit28] +FileName=..\..\include\loki\static_check.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit29] +FileName=..\..\include\loki\Threads.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit30] +FileName=..\..\include\loki\Tuple.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit31] +FileName=..\..\include\loki\Typelist.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit32] +FileName=..\..\include\loki\TypeManip.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit33] +FileName=..\..\include\loki\TypeTraits.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit34] +FileName=..\..\include\loki\AbstractFactory.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit35] +FileName=..\..\include\loki\AbstractFactory.h +CompileCpp=1 +Folder=loki +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + +[Unit4] +FileName=DataGeneratorsTest.h +CompileCpp=1 +Folder= +Compile=1 +Link=1 +Priority=1000 +OverrideBuildCmd=0 +BuildCmd= + diff --git a/test/RegressionTest/SingletonTest.h b/test/RegressionTest/SingletonTest.h new file mode 100755 index 0000000..0bf56e2 --- /dev/null +++ b/test/RegressionTest/SingletonTest.h @@ -0,0 +1,164 @@ +/////////////////////////////////////////////////////////////////////////////// +// Unit Test for Loki +// +// Copyright Terje Slettebų and Pavel Vozenilek 2002. +// +// Permission to use, copy, modify, and distribute this software for any +// purpose is hereby granted without fee, provided that this copyright and +// permissions notice appear in all copies and derivatives. +// +// This software is provided "as is" without express or implied warranty. +// +// Last update: September 16, 2002 +/////////////////////////////////////////////////////////////////////////////// + +#ifndef SINGLETONTEST_H +#define SINGLETONTEST_H + +#include +#include +#include "UnitTest.h" + +#define MAKE_TEST(name)\ + if(singletonTest && name::Instance().a != 99)\ + singletonTest=false;\ + ++name::Instance().a;\ + if(singletonTest && name::Instance().a != 100)\ + singletonTest=false; + +/////////////////////////////////////////////////////////////////////////////// +// SingletonTest +/////////////////////////////////////////////////////////////////////////////// + +template +class MyClass +{ +public: + MyClass() : a(99), wasDestroyed(false) {} + + virtual ~MyClass() + { + assert(!wasDestroyed); + + wasDestroyed = true; + } + +public: + int a; + bool wasDestroyed; +}; + +inline unsigned GetLongevity(MyClass<3> *) { return 6; } +inline unsigned GetLongevity(MyClass<7> *) { return 5; } +inline unsigned GetLongevity(MyClass<11> *) { return 4; } +inline unsigned GetLongevity(MyClass<15> *) { return 1; } +inline unsigned GetLongevity(MyClass<19> *) { return 2; } +inline unsigned GetLongevity(MyClass<23> *) { return 3; } + +namespace +{ + using namespace Loki; + + typedef SingletonHolder > t0; + + typedef SingletonHolder, CreateUsingNew, DefaultLifetime, SingleThreaded> t1; + typedef SingletonHolder, CreateUsingNew, PhoenixSingleton, SingleThreaded> t2; + typedef SingletonHolder, CreateUsingNew, SingletonWithLongevity, SingleThreaded> t3; + typedef SingletonHolder, CreateUsingNew, NoDestroy, SingleThreaded> t4; + + typedef SingletonHolder, CreateUsingMalloc, DefaultLifetime, SingleThreaded> t9; + typedef SingletonHolder, CreateUsingMalloc, PhoenixSingleton, SingleThreaded> t10; + typedef SingletonHolder, CreateUsingMalloc, SingletonWithLongevity, SingleThreaded> t11; + typedef SingletonHolder, CreateUsingMalloc, NoDestroy, SingleThreaded> t12; + + typedef SingletonHolder, CreateStatic, DefaultLifetime, SingleThreaded> t17; + typedef SingletonHolder, CreateStatic, PhoenixSingleton, SingleThreaded> t18; + typedef SingletonHolder, CreateStatic, SingletonWithLongevity, SingleThreaded> t19; + typedef SingletonHolder, CreateStatic, NoDestroy, SingleThreaded> t20; + +#if defined(_WINDOWS_) || defined(_WINDOWS_H) + + typedef SingletonHolder, CreateUsingNew, DefaultLifetime, ClassLevelLockable> t5; + typedef SingletonHolder, CreateUsingNew, PhoenixSingleton, ClassLevelLockable> t6; + typedef SingletonHolder, CreateUsingNew, SingletonWithLongevity, ClassLevelLockable> t7; + typedef SingletonHolder, CreateUsingNew, NoDestroy, ClassLevelLockable> t8; + + typedef SingletonHolder, CreateUsingMalloc, DefaultLifetime, ClassLevelLockable> t13; + typedef SingletonHolder, CreateUsingMalloc, PhoenixSingleton, ClassLevelLockable> t14; + typedef SingletonHolder, CreateUsingMalloc, SingletonWithLongevity, ClassLevelLockable> t15; + typedef SingletonHolder, CreateUsingMalloc, NoDestroy, ClassLevelLockable> t16; + + typedef SingletonHolder, CreateStatic, DefaultLifetime, ClassLevelLockable> t21; + typedef SingletonHolder, CreateStatic, PhoenixSingleton, ClassLevelLockable> t22; + typedef SingletonHolder, CreateStatic, SingletonWithLongevity, ClassLevelLockable> t23; + typedef SingletonHolder, CreateStatic, NoDestroy, ClassLevelLockable> t24; + +#endif +} + +class SingletonTest : public Test +{ +public: + SingletonTest() : Test("Singleton.h") {} + + virtual void execute(TestResult &result) + { + printName(result); + + using namespace Loki; + + singletonTest=true; + + MAKE_TEST(t0) + + MAKE_TEST(t1) + MAKE_TEST(t2) + MAKE_TEST(t3) + MAKE_TEST(t4) + + MAKE_TEST(t9) + MAKE_TEST(t10) + MAKE_TEST(t11) + MAKE_TEST(t12) + + MAKE_TEST(t17) + MAKE_TEST(t18) + MAKE_TEST(t19) + MAKE_TEST(t20) + + +#if defined(_WINDOWS_) || defined(_WINDOWS_H) + + MAKE_TEST(t5) + MAKE_TEST(t6) + MAKE_TEST(t7) + MAKE_TEST(t8) + + MAKE_TEST(t13) + MAKE_TEST(t14) + MAKE_TEST(t15) + MAKE_TEST(t16) + + MAKE_TEST(t21) + MAKE_TEST(t22) + MAKE_TEST(t23) + MAKE_TEST(t24) + +#endif + + testAssert("Singleton",singletonTest,result); + + std::cout << '\n'; + } + +private: + bool singletonTest; +} singletonTest; + +#ifdef LOKI_NONCC +#include "../../include/noncc/loki/Singleton.cpp" +#else +#include "../../src/Singleton.cpp" +#endif + +#endif diff --git a/test/RegressionTest/SmallObjectTest.h b/test/RegressionTest/SmallObjectTest.h new file mode 100755 index 0000000..4e21477 --- /dev/null +++ b/test/RegressionTest/SmallObjectTest.h @@ -0,0 +1,175 @@ +/////////////////////////////////////////////////////////////////////////////// +// Unit Test for Loki +// +// Copyright Terje Slettebų and Pavel Vozenilek 2002. +// +// Permission to use, copy, modify, and distribute this software for any +// purpose is hereby granted without fee, provided that this copyright and +// permissions notice appear in all copies and derivatives. +// +// This software is provided "as is" without express or implied warranty. +// +// Last update: September 16, 2002 +/////////////////////////////////////////////////////////////////////////////// + +#ifndef SMALLOBJECTTEST_H +#define SMALLOBJECTTEST_H + +#include +#include +#include "UnitTest.h" + +/////////////////////////////////////////////////////////////////////////////// +// SmallObjectTest +/////////////////////////////////////////////////////////////////////////////// + +class SmallObjectTest : public Test +{ +public: + SmallObjectTest() : Test("SmallObject.h") {} + + virtual void execute(TestResult &result) + { + printName(result); + + using namespace Loki; + + bool r; + + SmallClass* a = new SmallClass; + delete a; + + bool smallTest1=a!=NULL; + + a = new SmallClass2; + delete a; + + bool smallTest2=a!=NULL; + + BigClass* b = new BigClass; + delete b; + + bool bigTest1=b!=NULL; + + b = new BigClass2; + delete b; + + bool bigTest2=b!=NULL; + + char* buff = static_cast(Loki::SmallObject<>::operator new(10)); + Loki::SmallObject<>::operator delete(buff, 10); + + bool test=buff!=NULL; + +// stress_test(); + + r=smallTest1 && smallTest2 && bigTest1 && bigTest2 && test; + + testAssert("SmallObject",r,result); + + std::cout << '\n'; + } + +private: + class SmallClass : public Loki::SmallObject<> + { + int a; + }; + + class SmallClass2 : public SmallClass + { + int b; + }; + + class BigClass : public Loki::SmallObject<> + { + char a[200]; + }; + + class BigClass2 : public BigClass + { + int b; + }; + + class Base + { + public: + virtual ~Base() {} + }; + + class A : public Base, public Loki::SmallObject<> + { + int a[1]; + }; + + class B : public Base, public Loki::SmallObject<> + { + int a[2]; + }; + + class C : public Base, public Loki::SmallObject<> + { + int a[3]; + }; + + class D : public Base, public Loki::SmallObject<> + { + int a[4]; + }; + + static void stress_test() + { + std::vector vec; + + vec.reserve(20 * 1024); + + std::srand(1231); + + for (int i = 0; i < 10; ++i) + { + for (int j = 0; j < 2 * 1024; ++j) + { + Base* p; + + switch (std::rand() % 4) + { + case 0: p = new A; break; + case 1: p = new B; break; + case 2: p = new C; break; + case 3: p = new D; break; + } + + vec.push_back(p); + } + + for (int j = 0; j < 1024; ++j) + { + size_t pos = std::rand() % vec.size(); + + delete vec[pos]; + + vec[pos] = 0; + } + } + + while (!vec.empty()) + { + delete vec.back(); + + vec.pop_back(); + } + } +} smallObjectTest; + +#ifndef SMALLOBJ_CPP +# define SMALLOBJ_CPP +# ifdef LOKI_NONCC +# include "../../include/noncc/loki/SmallObj.cpp" +# else +# include "../../src/SmallObj.cpp" +# endif +#endif + + + +#endif diff --git a/test/RegressionTest/SmartPtrTest.h b/test/RegressionTest/SmartPtrTest.h new file mode 100755 index 0000000..ab89a71 --- /dev/null +++ b/test/RegressionTest/SmartPtrTest.h @@ -0,0 +1,309 @@ +/////////////////////////////////////////////////////////////////////////////// +// Unit Test for Loki +// +// Copyright Terje Slettebų and Pavel Vozenilek 2002. +// +// Permission to use, copy, modify, and distribute this software for any +// purpose is hereby granted without fee, provided that this copyright and +// permissions notice appear in all copies and derivatives. +// +// This software is provided "as is" without express or implied warranty. +// +// Last update: September 16, 2002 +/////////////////////////////////////////////////////////////////////////////// + +#ifndef SMARTPTRTEST_H +#define SMARTPTRTEST_H + +#include "UnitTest.h" +#include + +using namespace Loki; + +/////////////////////////////////////////////////////////////////////////////// +// SmartPtrTest +/////////////////////////////////////////////////////////////////////////////// + +class TestClass +{ +public: + TestClass() : references(1) + { + ++instances; + } + + ~TestClass() + { + --instances; + } + + void AddRef() + { + ++references; + } + + void Release() + { + --references; + + if (references <= 0) + delete this; + } + + TestClass* Clone() + { + return new TestClass(*this); + } + +public: + static int instances; + + int references; +}; + +int TestClass::instances = 0; + +class SmartPtrTest : public Test +{ +public: + SmartPtrTest() : Test("SmartPtr.h") {} + + virtual void execute(TestResult &result) + { + printName(result); + + using namespace Loki; + + { SmartPtr p = new TestClass; } + + bool test1=TestClass::instances == 0; + + { p0 p(new TestClass); } + { p1 p(new TestClass); } + { p2 p(new TestClass); p2 pp(p); } + { p3 p(new TestClass); } + { p4 p(new TestClass); } + { p5 p(new TestClass); } + { p6 p(new TestClass); } + { p7 p(new TestClass); } + { p8 p(new TestClass); } + { p9 p(new TestClass); } + { p10 p(new TestClass); } + { p11 p(new TestClass); } + { p12 p(new TestClass); } + { p13 p(new TestClass); } + { p14 p(new TestClass); } + { p15 p(new TestClass); } + { p16 p(new TestClass); } + { p17 p(new TestClass); } + { p18 p(new TestClass); } + { p19 p(new TestClass); } + { p20 p(new TestClass); } + { p21 p(new TestClass); } + { p22 p(new TestClass); } + { p23 p(new TestClass); } + { p24 p(new TestClass); } + { p25 p(new TestClass); } + { p26 p(new TestClass); } + { p27 p(new TestClass); } + { p28 p(new TestClass); } + { p29 p(new TestClass); } + { p30 p(new TestClass); } + { p31 p(new TestClass); } + { p40 p(new TestClass); } + { p41 p(new TestClass); } + { p42 p(new TestClass); } + { p43 p(new TestClass); } + { p44 p(new TestClass); } + { p45 p(new TestClass); } + { p46 p(new TestClass); } + { p47 p(new TestClass); } + { p48 p(new TestClass); } + { p49 p(new TestClass); } + { p50 p(new TestClass); } + { p51 p(new TestClass); } + { p52 p(new TestClass); } + { p53 p(new TestClass); } + { p54 p(new TestClass); } + { p55 p(new TestClass); } + { p56 p(new TestClass); } + { p57 p(new TestClass); } + { p58 p(new TestClass); } + { p59 p(new TestClass); } + { p60 p(new TestClass); } + { p61 p(new TestClass); } + { p62 p(new TestClass); } + { p63 p(new TestClass); } + { p64 p(new TestClass); } + { p65 p(new TestClass); } + { p66 p(new TestClass); } + { p67 p(new TestClass); } + { p68 p(new TestClass); } + { p69 p(new TestClass); } + { p70 p(new TestClass); } + { p71 p(new TestClass); } + { p72 p(new TestClass); } + { p73 p(new TestClass); } + { p74 p(new TestClass); } + { p75 p(new TestClass); } + { p76 p(new TestClass); } + { p77 p(new TestClass); } + { p78 p(new TestClass); } + { p79 p(new TestClass); } + { p80 p(new TestClass); } + { p81 p(new TestClass); } + { p82 p(new TestClass); } + { p83 p(new TestClass); } + { p84 p(new TestClass); } + { p85 p(new TestClass); } + { p86 p(new TestClass); } + { p87 p(new TestClass); } + { p88 p(new TestClass); } + { p89 p(new TestClass); } + { p90 p(new TestClass); } + { p91 p(new TestClass); } + { p92 p(new TestClass); } + { p93 p(new TestClass); } + { p94 p(new TestClass); } + { p95 p(new TestClass); } + { p96 p(new TestClass); } + { p97 p(new TestClass); } + { p98 p(new TestClass); } + { p99 p(new TestClass); } + { p100 p(new TestClass); } + { p101 p(new TestClass); } + { p102 p(new TestClass); } + { p103 p(new TestClass); } + + bool test2=TestClass::instances==0; + + bool r=test1 && test2; + + testAssert("SmartPtr",r,result); + + std::cout << '\n'; + } + +private: + typedef SmartPtr p0; + typedef SmartPtr p1; + typedef SmartPtr::RefCountedMT, + DisallowConversion, AssertCheck, DefaultSPStorage> p2; + typedef SmartPtr p3; + typedef SmartPtr p4; + typedef SmartPtr p5; + typedef SmartPtr p6; + typedef SmartPtr p7; + + typedef SmartPtr p8; + typedef SmartPtr p9; + typedef SmartPtr::RefCountedMT, + AllowConversion, AssertCheck, DefaultSPStorage> p10; + typedef SmartPtr p11; + typedef SmartPtr p12; + typedef SmartPtr p13; + typedef SmartPtr p14; + typedef SmartPtr p15; + + typedef SmartPtr p16; + typedef SmartPtr p17; + typedef SmartPtr::RefCountedMT, + DisallowConversion, AssertCheckStrict, DefaultSPStorage> p18; + typedef SmartPtr p19; + typedef SmartPtr p20; + typedef SmartPtr p21; + typedef SmartPtr p22; + typedef SmartPtr p23; + + typedef SmartPtr p24; + typedef SmartPtr p25; + typedef SmartPtr::RefCountedMT, + AllowConversion, AssertCheckStrict, DefaultSPStorage> p26; + typedef SmartPtr p27; + typedef SmartPtr p28; + typedef SmartPtr p29; + typedef SmartPtr p30; + typedef SmartPtr p31; + + typedef SmartPtr p40; + typedef SmartPtr p41; + typedef SmartPtr::RefCountedMT, + AllowConversion, RejectNullStatic, DefaultSPStorage> p42; + typedef SmartPtr p43; + typedef SmartPtr p44; + typedef SmartPtr p45; + typedef SmartPtr p46; + typedef SmartPtr p47; + + typedef SmartPtr p48; + typedef SmartPtr p49; + typedef SmartPtr::RefCountedMT, + DisallowConversion, RejectNullStatic, DefaultSPStorage> p50; + typedef SmartPtr p51; + typedef SmartPtr p52; + typedef SmartPtr p53; + typedef SmartPtr p54; + typedef SmartPtr p55; + + typedef SmartPtr p56; + typedef SmartPtr p57; + typedef SmartPtr::RefCountedMT, + AllowConversion, RejectNull, DefaultSPStorage> p58; + typedef SmartPtr p59; + typedef SmartPtr p60; + typedef SmartPtr p61; + typedef SmartPtr p62; + typedef SmartPtr p63; + + typedef SmartPtr p64; + typedef SmartPtr p65; + typedef SmartPtr::RefCountedMT, + DisallowConversion, RejectNull, DefaultSPStorage> p66; + typedef SmartPtr p67; + typedef SmartPtr p68; + typedef SmartPtr p69; + typedef SmartPtr p70; + typedef SmartPtr p71; + + typedef SmartPtr p72; + typedef SmartPtr p73; + typedef SmartPtr::RefCountedMT, + AllowConversion, RejectNullStrict, DefaultSPStorage> p74; + typedef SmartPtr p75; + typedef SmartPtr p76; + typedef SmartPtr p77; + typedef SmartPtr p78; + typedef SmartPtr p79; + + typedef SmartPtr p80; + typedef SmartPtr p81; + typedef SmartPtr::RefCountedMT, + DisallowConversion, RejectNullStrict, DefaultSPStorage> p82; + typedef SmartPtr p83; + typedef SmartPtr p84; + typedef SmartPtr p85; + typedef SmartPtr p86; + typedef SmartPtr p87; + + typedef SmartPtr p88; + typedef SmartPtr p89; + typedef SmartPtr::RefCountedMT, + AllowConversion, NoCheck, DefaultSPStorage> p90; + typedef SmartPtr p91; + typedef SmartPtr p92; + typedef SmartPtr p93; + typedef SmartPtr p94; + typedef SmartPtr p95; + + typedef SmartPtr p96; + typedef SmartPtr p97; + typedef SmartPtr::RefCountedMT, + DisallowConversion, NoCheck, DefaultSPStorage> p98; + typedef SmartPtr p99; + typedef SmartPtr p100; + typedef SmartPtr p101; + typedef SmartPtr p102; + typedef SmartPtr p103; +} smartPtrTest; + +#endif diff --git a/test/RegressionTest/Test.cpp b/test/RegressionTest/Test.cpp new file mode 100755 index 0000000..a0bf695 --- /dev/null +++ b/test/RegressionTest/Test.cpp @@ -0,0 +1,127 @@ +/////////////////////////////////////////////////////////////////////////////// +// Unit Test for Loki +// +// Copyright Terje Slettebų and Pavel Vozenilek 2002. +// +// Permission to use, copy, modify, and distribute this software for any +// purpose is hereby granted without fee, provided that this copyright and +// permissions notice appear in all copies and derivatives. +// +// This software is provided "as is" without express or implied warranty. +// +/////////////////////////////////////////////////////////////////////////////// + +// $Header$ + +#ifdef __INTEL_COMPILER +# pragma warning(disable: 111 193 304 383 444 488 981 1418) +#elif defined(_MSC_VER) && !defined(__MWERKS__) +# pragma warning(disable: 4018 4097 4100 4213 4290 4512 4514 4700 4702 4710 4786 4800) +#endif + +//#define CLASS_LEVEL_THREADING +//#define OBJECT_LEVEL_THREADING + +// Some platforms might have difficulty with this +// Need to ifdef around those cases. +// TODO SGB + +#include "UnitTest.h" + +// static variable defintion, do not remove + +Test::tests_type Test::tests; + +// Merely comment out any of the following headers to +// prevent thier execution during the test. +// +// A pluggable-factory-like method is used to +// auto-register the test, so all that is needed +// is the header inclusion to execute the correspond +// unit test. + +#include "TypelistTest.h" +#include "TypeManipTest.h" +#include "TypeTraitsTest.h" +#include "TypeTraitsTest2.h" +#include "SmallObjectTest.h" +#include "SingletonTest.h" +#include "SmartPtrTest.h" +#include "FactoryTest.h" +#include "FactoryParmTest.h" +#include "AbstractFactoryTest.h" +#include "AssocVectorTest.h" +#include "FunctorTest.h" +#include "DataGeneratorsTest.h" + +/* + * AP - All Pass + * FC - Fails to Compile + * ? - Unknown/Not Tested/Not Recorded + * + * TypelistTest TypeManipTest TypeTraitsTest SmallObjectTest SingletonTest + * gcc 2.95.3 ? ? ? ? ? + * gcc 3.2 AP AP AP AP P (Only SingleThreaded) + * MSVC 6.0 P AP FC FC AP + * MSVC 7.0 AP Conversion FC AP P (Only SingleThreaded) ? + * Intel 5.0 AP AP AP FC FC + * Intel 6.0 AP AP AP FC P (Only SingleThreaded) + * Intel 7.0 AP AP AP FC P (Only SingleThreaded) + * BCC 5.5 ? ? ? ? ? + * BCC 5.6 ? ? ? ? ? + * CW 6.0 ? ? ? ? ? + * + * SmartPtrTest FactoryTest AbstractFactoryTest AssocVectorTest FunctorTest + * gcc 2.95.3 ? ? ? ? ? + * gcc 3.2 AP AP AP AP AP + * MSVC 6.0 FC AP FC FC FC + * MSVC 7.0 FC AP AP FC AP + * Intel 5.0 FC FC FC FC FC + * Intel 6.0 FC AP AP FC FC + * Intel 7.0 FC AP AP FC FC + * BCC 5.5 ? ? ? ? ? + * CW 6.0 ? ? ? ? ? + * + * DataGeneratorsTest + * gcc 2.95.3 ? + * gcc 3.2 AP + * MSVC 6.0 FC + * MSVC 7.0 AP + * Intel 5.0 FC + * Intel 6.0 AP + * Intel 7.0 AP + * BCC 5.5 ? + * BCC 5.6 ? + * CW 6.0 ? + + */ + +int main() +{ + +int result = Test::run("Loki Unit Test"); + +#if defined(__BORLANDC__) || defined(__GNUC__) || defined(_MSC_VER) + system("pause"); // Stop console window from closing if run from IDE. +#endif + +return result; +} + + +// $Log$ +// Revision 1.4 2005/09/24 15:25:20 syntheticpp +// ove RegressionTest +// +// Revision 1.17 2005/09/15 17:51:48 syntheticpp +// add new TypeTraits test from Kalle Rutanen +// +// Revision 1.16 2005/08/10 18:13:13 syntheticpp +// change default to single threading +// +// Revision 1.15 2005/07/31 14:00:48 syntheticpp +// make object level threading possible +// +// Revision 1.14 2005/07/28 14:26:10 syntheticpp +// add cvs Header/Log +// diff --git a/test/RegressionTest/TypeManipTest.h b/test/RegressionTest/TypeManipTest.h new file mode 100755 index 0000000..8ca764c --- /dev/null +++ b/test/RegressionTest/TypeManipTest.h @@ -0,0 +1,119 @@ +/////////////////////////////////////////////////////////////////////////////// +// Unit Test for Loki +// +// Copyright Terje Slettebų and Pavel Vozenilek 2002. +// +// Permission to use, copy, modify, and distribute this software for any +// purpose is hereby granted without fee, provided that this copyright and +// permissions notice appear in all copies and derivatives. +// +// This software is provided "as is" without express or implied warranty. +// +// Last update: September 16, 2002 +/////////////////////////////////////////////////////////////////////////////// + +#ifndef TYPEMANIPTEST_H +#define TYPEMANIPTEST_H + +#include +#include "UnitTest.h" + +/////////////////////////////////////////////////////////////////////////////// +// TypeManipTest +/////////////////////////////////////////////////////////////////////////////// + +class TypeManipTest : public Test +{ +public: + TypeManipTest() : Test("TypeManip.h") {} + + virtual void execute(TestResult &result) + { + printName(result); + + using namespace Loki; + + bool r; + + r=Int2Type<1>::value==1; + + testAssert("Int2Type",r,result); + + r=SameType::OriginalType,char>::value; + + testAssert("Type2Type",r,result); + + r=SameType::Result,char>::value && + SameType::Result,int>::value; + + testAssert("Select",r,result); + + r=Conversion::exists && + Conversion::exists2Way && + !Conversion::sameType && + Conversion::exists && + Conversion::exists2Way && + Conversion::sameType && + Conversion::exists && + !Conversion::exists && + !Conversion::exists && + Conversion::exists && + Conversion::exists && + Conversion::exists && + !Conversion::exists && + !Conversion::exists && + Conversion::exists && + Conversion::exists && + !Conversion::exists && + !Conversion::exists && + Conversion::exists && + !Conversion::exists; + + testAssert("Conversion",r,result); + + r=SuperSubclass::value && + SuperSubclass::value && + SuperSubclass::value && + !SuperSubclass::value && + !SuperSubclass::value && + !SuperSubclass::value; + + testAssert("SuperSubclass",r,result); + + r=SuperSubclassStrict::value && + SuperSubclassStrict::value && + !SuperSubclassStrict::value && + !SuperSubclassStrict::value && + !SuperSubclassStrict::value && + !SuperSubclassStrict::value; + + testAssert("SuperSubclassStrict",r,result); + + r=SUPERSUBCLASS(Base,Derived1) && + SUPERSUBCLASS(Base,Derived2) && + SUPERSUBCLASS(Base,Base) && + !SUPERSUBCLASS(Derived1,Base) && + !SUPERSUBCLASS(Derived2,Base) && + !SUPERSUBCLASS(void,Base); + + testAssert("SUPERSUBCLASS",r,result); + + r=SUPERSUBCLASS_STRICT(Base,Derived1) && + SUPERSUBCLASS_STRICT(Base,Derived2) && + !SUPERSUBCLASS_STRICT(Base,Base) && + !SUPERSUBCLASS_STRICT(Derived1,Base) && + !SUPERSUBCLASS_STRICT(Derived2,Base) && + !SUPERSUBCLASS_STRICT(void,Base); + + testAssert("SUPERSUBCLASS_STRICT",r,result); + + std::cout << '\n'; + } + +private: + struct Base { char c; }; + struct Derived1 : Base { char c; }; + struct Derived2 : Derived1 { char c; }; +} typeManipTest; + +#endif diff --git a/test/RegressionTest/TypeTraitsTest.h b/test/RegressionTest/TypeTraitsTest.h new file mode 100755 index 0000000..6c17fe6 --- /dev/null +++ b/test/RegressionTest/TypeTraitsTest.h @@ -0,0 +1,116 @@ +/////////////////////////////////////////////////////////////////////////////// +// Unit Test for Loki +// +// Copyright Terje Slettebų and Pavel Vozenilek 2002. +// +// Permission to use, copy, modify, and distribute this software for any +// purpose is hereby granted without fee, provided that this copyright and +// permissions notice appear in all copies and derivatives. +// +// This software is provided "as is" without express or implied warranty. +// +// Last update: September 16, 2002 +/////////////////////////////////////////////////////////////////////////////// + +#ifndef TYPETRAITSTEST_H +#define TYPETRAITSTEST_H + +#include + +/////////////////////////////////////////////////////////////////////////////// +// TypeTraitsTest +/////////////////////////////////////////////////////////////////////////////// + +class TypeTraitsTest : public Test +{ +public: + TypeTraitsTest() : Test("TypeTraits.h") {} + + virtual void execute(TestResult &result) + { + printName(result); + + using namespace Loki; + + bool r; + + r=TypeTraits::isPointer && + !TypeTraits::isPointer && + SameType::PointeeType,int>::value && + SameType::PointeeType,NullType>::value && + + TypeTraits::isReference && + !TypeTraits::isReference && + SameType::ReferredType,int>::value && + SameType::ReferredType,int>::value && + + TypeTraits::isMemberPointer && + !TypeTraits::isMemberPointer && + + TypeTraits::isStdUnsignedInt && + !TypeTraits::isStdUnsignedInt && + + TypeTraits::isStdSignedInt && + !TypeTraits::isStdSignedInt && + + TypeTraits::isStdIntegral && + !TypeTraits::isStdIntegral && + + TypeTraits::isStdFloat && + !TypeTraits::isStdFloat && + + TypeTraits::isStdArith && + !TypeTraits::isStdArith && + + TypeTraits::isStdFundamental && + !TypeTraits::isStdFundamental && + + TypeTraits::isUnsignedInt && + !TypeTraits::isUnsignedInt && + + TypeTraits::isSignedInt && + !TypeTraits::isSignedInt && + + TypeTraits::isIntegral && + !TypeTraits::isIntegral && + + TypeTraits::isFloat && + !TypeTraits::isFloat && + + TypeTraits::isArith && + TypeTraits::isArith && + TypeTraits::isArith && + !TypeTraits::isArith && + + TypeTraits::isFundamental && + !TypeTraits::isFundamental && + +#ifndef __BORLANDC__ + + TypeTraits::isConst && + !TypeTraits::isConst && + SameType::NonConstType,int>::value && + SameType::NonConstType,int>::value && + + TypeTraits::isVolatile && + !TypeTraits::isVolatile && + SameType::NonVolatileType,int>::value && + SameType::NonVolatileType,int>::value && + + SameType::UnqualifiedType,int>::value && + +#endif + + SameType::ParameterType,char>::value && + SameType::ParameterType,int>::value && + SameType::ParameterType,double>::value && + SameType::ParameterType,Test &>::value && + SameType::ParameterType,const Test &>::value; + + testAssert("TypeTraits",r,result); + + std::cout << '\n'; + } +} typeTraitsTest; + +#endif diff --git a/test/RegressionTest/TypeTraitsTest2.h b/test/RegressionTest/TypeTraitsTest2.h new file mode 100755 index 0000000..527b410 --- /dev/null +++ b/test/RegressionTest/TypeTraitsTest2.h @@ -0,0 +1,546 @@ +// Loki TypeTraits test program +// Kalle Rutanen +// 9.9.2005 +// +// Some type sets +// -------------- +// +// [] for optional +// ^ for repetition +// T for any type +// +// The set of normal pointers: +// +// G = T* [const] [volatile] [&] +// +// The set of member variable pointers: +// +// H = T A::* [const] [volatile] [&] +// +// The set of function pointers: +// +// F = T (* [const] [volatile] [&])([P1, P2, ---, Pn] + [...]]) +// +// The set of member function pointers: +// +// I = T (A::* [const] [volatile] [&])([P1, P2, ---, Pn] [...]]) [const] [volatile] +// +// Repetition +// ---------- +// +// With pointers, we have an infinite number of possibilities. We can have +// for example the type +// "const int* volatile*** const volatile**const*volatile*volatile" +// Naturally we can't test for every possible situation. In this case +// we shall only test the first level of this repetition and rely on induction. +// +// Reference & +// ----------- +// +// A problem is how the reference should affect the type, in particular: +// +// Is "T*&" a pointer ? +// Is "T const&" const? +// Is "int&" integral? +// etc.. +// +// The philosophy for solving these situations is: +// "a type is what it does". By this philosophy, +// all of the questions above are answered affirmitively. +// +// Dealing with the number of possibilities +// ---------------------------------------- +// +// For every test, types are separated into groups: types +// in the same groups behave the same kind with respect to the tested +// property. Thus we have to test only one of types in group. +// +// The number of tests is important to keep low for two reasons: +// First, the test program can come up too long, and as such contain +// errors itself. Second, compilers have limitations, which quite certainly +// raise internal errors during compilations due to a extensive use of the +// precompiler. +// +// Types that should not be forgotten +// ---------------------------------- +// +// bool, char, wchar_t +// signed char, signed short, signed int, signed long +// unsigned char, unsigned short, unsigned int, unsigned long +// T* (normal pointers) +// T (*)() (non-parametric function pointers) +// T (*)(int, float) (n-parametric function pointers) +// T (*)(int, float, ...) (variable-parametric function pointers) +// T A::* (member variable pointers) +// T A::(*)() (non-parametric member function pointers) +// T A::(*)(int, float) (n-parametric member function pointers) +// T A::(*)(int, float, ...) (variable-parametric member function pointers) +// T A::(*)() const volatile +// (non-parametric cv-qualified member function pointers) +// T A::(*)(int, float) const volatile +// (n-parametric cv-qualified member function pointers) +// T A::(*)(int, float, ...) const volatile +// (variable-parametric cv-qualified member function pointers) +// T() (non-parametric functions) +// T(int, float) (n-parametric functions) +// T(int, float, ...) (variable-parametric functions) +// +// All types listed above with cv-qualifiers +// References to every type listed above. +// void +// +// IMPORTANT: +// 1) char != signed char && char != unsigned char +// 2) cv-qualifiers in the end of a member function does not +// affect the cv-qualifiers of the pointer type. However, they +// do affect the overall type. (void (A::*)f() const != void (A::*)f()) +// 3) The ellipsis "..." does not correspond to any explicit parameter list +// such as () or (int, float) +// 4) You can have a reference to a function, for example: +// int (&)(int, float) + +#ifndef TYPETRAITSTEST2_H +#define TYPETRAITSTEST2_H + +#include +#include +#include + +#define ENABLE_ADDITIONAL_TYPETRAITS + + +#include + +// Macros for testing isX variables + +#define TEST_CONDITION(cond, answer) \ + testCondition(cond, answer, #cond); + +#define TEST_CONDITION_HELP(type, cond, answer) \ + TEST_CONDITION(Loki::TypeTraits::cond, answer) + +#define PASS(type) \ + TEST_CONDITION_HELP(type, CONDITION, true) + +#define FAIL(type) \ + TEST_CONDITION_HELP(type, CONDITION, false) + +// Macros for testing xType types + +#define TEST_TYPE_HELP2(type, rightType, cond) \ + { \ + const std::type_info& info = typeid(Loki::TypeTraits::cond); \ + bool testResult = Loki::IsSameType::cond>::value; \ + testType(testResult, #cond, #type, info.name(), #rightType); \ + } + +// This macro is needed as an intermediate step to print CONDITION right +// Could be a bug... +#define TEST_TYPE_HELP(type, rightType, cond) \ + TEST_TYPE_HELP2(type, rightType, cond) + +#define TEST_TYPE(type, rightType) \ + TEST_TYPE_HELP(type, rightType, CONDITION) + +/////////////////////////////////////////////////////////////////////////////// +// TypeTraitsTest2 +/////////////////////////////////////////////////////////////////////////////// + +class TypeTraitsTest2: public Test +{ +public: + TypeTraitsTest2() + : Test("TypeTraits.h"), + testedConditions_(0), + erroneousConditions_(0) + { + } + + virtual void execute(TestResult &result); + +private: + class A{}; + + void testCount(bool result); + void testType(bool result, std::string conditionText, + std::string typeText, + std::string deducedTypeText, + std::string rightTypeText); + void testCondition(bool result, bool answer, std::string text); + + void testIntegral(); + void testFloat(); + void testConst(); + void testVolatile(); + void testPointer(); + void testReference(); + void testMemberPointer(); + void testFunctionPointer(); + void testMemberFunctionPointer(); + void testFunction(); + + void testParameterType(); + void testReferredType(); + void testPointeeType(); + + unsigned int testedConditions_; + unsigned int erroneousConditions_; + +} typeTraitsTest2; + +inline void TypeTraitsTest2::execute(TestResult &result) +{ + printName(result); + + testIntegral(); + testFloat(); + testConst(); + testVolatile(); + testPointer(); + testReference(); + testMemberPointer(); + testFunctionPointer(); + testMemberFunctionPointer(); + testFunction(); + testParameterType(); + testReferredType(); + testPointeeType(); + + bool r = erroneousConditions_ == 0; + + std::cout << "Tested " << testedConditions_ + << " conditions of which " << erroneousConditions_ + << " were erroneous" << std::endl; + + testAssert("TypeTraits2",r,result); + + std::cout << std::endl; +} + +inline void TypeTraitsTest2::testCount(bool result) +{ + if (!result) + { + ++erroneousConditions_; + } + + ++testedConditions_; +} + +inline void TypeTraitsTest2::testType(bool result, std::string conditionText, + std::string typeText, + std::string deducedTypeText, + std::string rightTypeText) +{ + testCount(result); + + if (!result) + { + std::cout << "TypeTraits<" << typeText << ">::" + << conditionText << " -> " << deducedTypeText << std::endl; + std::cout << " Expected " << rightTypeText << std::endl; + } +} + +inline void TypeTraitsTest2::testCondition(bool result, bool answer, std::string text) +{ + testCount(result == answer); + + if (result != answer) + { + std::cout << text << " == " << result << std::endl; + } +} + +inline void TypeTraitsTest2::testIntegral() +{ +#undef CONDITION +#define CONDITION isIntegral + + PASS(bool); + PASS(char); + PASS(wchar_t); + + PASS(signed char); + PASS(signed short int); + PASS(signed long int); + + PASS(unsigned char); + PASS(unsigned short int); + PASS(unsigned long int); + + PASS(unsigned long int const volatile); + PASS(unsigned long int const volatile&); + + FAIL(float); + FAIL(A); + FAIL(int*); + FAIL(int A::*); + FAIL(int(*)()); + FAIL(int(*)(int, float, ...)); + FAIL(int (A::*)()); + FAIL(int (A::*)(int, float, ...)); +} + +inline void TypeTraitsTest2::testFloat() +{ +#undef CONDITION +#define CONDITION isFloat + + PASS(float); + PASS(double); + PASS(long double); + + PASS(long double const volatile); + PASS(long double const volatile&); + + FAIL(int); + FAIL(void); + FAIL(A); + FAIL(float*); + FAIL(float A::*); + FAIL(float(*)()); + FAIL(float(*)(int, float, ...)); + FAIL(float (A::*)()); + FAIL(float (A::*)(int, float, ...)); +} + +inline void TypeTraitsTest2::testConst() +{ +#undef CONDITION +#define CONDITION isConst + + PASS(const volatile int); + PASS(int* const volatile); + PASS(int (* const volatile)()); + PASS(int (* const volatile)(int, float, ...)); + PASS(int A::* const volatile); + PASS(int (A::* const volatile)()); + PASS(int (A::* const volatile)(int, float, ...)); + PASS(const volatile int&); + + FAIL(void); + FAIL(int); + FAIL(A); + FAIL(const int*); + FAIL(const int A::*); + FAIL(const int(*)()); + FAIL(const int(*)(int, float, ...)); + FAIL(const int (A::*)() const); + FAIL(const int (A::*)(int, float, ...) const); +} + +inline void TypeTraitsTest2::testVolatile() +{ +#undef CONDITION +#define CONDITION isVolatile + + PASS(const volatile int); + PASS(int* const volatile); + PASS(int (* const volatile)()); + PASS(int (* const volatile)(int, float, ...)); + PASS(int A::* const volatile); + PASS(int (A::* const volatile)()); + PASS(int (A::* const volatile)(int, float, ...)); + PASS(const volatile int&); + + FAIL(void); + FAIL(int); + FAIL(A); + FAIL(volatile int*); + FAIL(volatile int A::*); + FAIL(volatile int(*)()); + FAIL(volatile int (A::*)() volatile); + FAIL(volatile int(*)(int, float, ...)); + FAIL(volatile int (A::*)(int, float, ...) volatile); + FAIL(volatile int(*)(int, float)); + FAIL(volatile int (A::*)(int, float) volatile); +} + +inline void TypeTraitsTest2::testReference() +{ +#undef CONDITION +#define CONDITION isReference + + PASS(const volatile int&); + PASS(void (*const volatile&)(int, float)); + PASS(void (&)(int, float)); + PASS(void (*const volatile&)(int, float, ...)); + PASS(void (&)()); + PASS(void (&)(int, float, ...)); + + FAIL(int); + FAIL(void); +} + +inline void TypeTraitsTest2::testPointer() +{ +#undef CONDITION +#define CONDITION isPointer + + PASS(int* const volatile); + PASS(void (* const volatile)()); + PASS(void (* const volatile)(int, float)); + PASS(void (* const volatile)(int, float, ...)); + + + PASS(void (A::* const volatile)() const volatile); + PASS(void (A::* const volatile)(int, float) const volatile); + PASS(void (A::* const volatile)(int, float, ...) const volatile); + PASS(int A::* const volatile); + + + PASS(const volatile int** const volatile ** const * const volatile); + PASS(int* const volatile&); + + FAIL(int); + FAIL(int&); + FAIL(void); +} + +inline void TypeTraitsTest2::testMemberPointer() +{ +#undef CONDITION +#define CONDITION isMemberPointer + + PASS(int A::* const volatile); + PASS(const volatile int A::* const volatile); + + + // Pointer to member functions + PASS(int (A::* )() const); + PASS(int (A::* const volatile)() const volatile); + PASS(int (A::* const volatile)(int, float) const volatile); + PASS(int (A::* const volatile&)(int, float) const volatile); + PASS(int (A::* const volatile)(int, float, ...) const volatile); + PASS(int (A::* const volatile&)(int, float, ...) const volatile); + + + FAIL(int); + FAIL(void); + FAIL(void*); + FAIL(void(*)()); +} + +inline void TypeTraitsTest2::testFunctionPointer() +{ +#ifdef ENABLE_ADDITIONAL_TYPETRAITS +#undef CONDITION +#define CONDITION isFunctionPointer + + PASS(void (*)()); + FAIL(void (A::* const volatile)()); + FAIL(void (A::* const volatile)() const); + FAIL(void (A::* const volatile)() volatile); + FAIL(void (A::* const volatile)() const volatile); + FAIL(void (A::* const volatile&)() const volatile); + PASS(void (* const volatile)()); + PASS(void (* const volatile&)()); + + PASS(void (* const volatile&)(int, float)); + FAIL(void (A::* const volatile&)(int, float) const volatile); + + PASS(void (* const volatile&)(int, float, ...)); + FAIL(void (A::* const volatile&)(int, float, ...) const volatile); + + FAIL(void); + FAIL(void*); + FAIL(int A::*); + +#endif +} + +inline void TypeTraitsTest2::testMemberFunctionPointer() +{ +#ifdef ENABLE_ADDITIONAL_TYPETRAITS +#undef CONDITION +#define CONDITION isMemberFunctionPointer + + PASS(void (A::* const volatile)()); + PASS(void (A::* const volatile)() const); + PASS(void (A::* const volatile)() volatile); + PASS(void (A::* const volatile)() const volatile); + PASS(void (A::* const volatile&)() const volatile); + FAIL(void (* const volatile)()); + FAIL(void (* const volatile&)()); + + FAIL(void (* const volatile&)(int, float)); + PASS(void (A::* const volatile&)(int, float) const volatile); + + FAIL(void (* const volatile&)(int, float, ...)); + PASS(void (A::* const volatile&)(int, float, ...) const volatile); + + FAIL(void); + FAIL(void*); + FAIL(int A::*); +#endif +} + +inline void TypeTraitsTest2::testFunction() +{ +#ifdef ENABLE_ADDITIONAL_TYPETRAITS +#undef CONDITION +#define CONDITION isFunction + + PASS(void()); + PASS(void(int, float, ...)); + PASS(void(&)(int, float, ...)); + PASS(void(int, float)); + PASS(void(&)()); + PASS(void(&)(int, float)); + PASS(int(&)(int, float)); +#endif +} + +inline void TypeTraitsTest2::testParameterType() +{ +#undef CONDITION +#define CONDITION ParameterType + + TEST_TYPE(int, int); + TEST_TYPE(const volatile int, const volatile int); + TEST_TYPE(const volatile int&, const volatile int&); + TEST_TYPE(void, Loki::NullType); + TEST_TYPE(void*, void*); + TEST_TYPE(void* const volatile, void* const volatile); + TEST_TYPE(void* const volatile&, void* const volatile&); + TEST_TYPE(const volatile A, const volatile A&); + TEST_TYPE(A&, A&); + + TEST_TYPE(A, const A&); +} + +inline void TypeTraitsTest2::testReferredType() +{ +#undef CONDITION +#define CONDITION ReferredType + + TEST_TYPE(const volatile int&, const volatile int); + TEST_TYPE(void* const volatile&, void* const volatile); + TEST_TYPE(void (&)(), void()); + TEST_TYPE(void (&)(int, float, ...), void(int, float, ...)); + TEST_TYPE(int (*)(), int (*)()); + TEST_TYPE(int (*&)(int, float, ...), int (*)(int, float, ...)); + TEST_TYPE(int (A::*&)() const volatile, int (A::*)() const volatile); + TEST_TYPE(int (A::*&)(int, float, ...) const volatile, int (A::*)(int, float, ...) const volatile); +} + +inline void TypeTraitsTest2::testPointeeType() +{ +#undef CONDITION +#define CONDITION PointeeType + + TEST_TYPE(void, Loki::NullType); + TEST_TYPE(void*, void); + TEST_TYPE(const volatile int*, const volatile int); + + TEST_TYPE( + const volatile int* const volatile&, + const volatile int); + + TEST_TYPE(void(*)(int, float), void(int, float)); + TEST_TYPE(void(int, float), Loki::NullType); + TEST_TYPE(void(*&)(int, float), void(int, float)); +} + +#endif diff --git a/test/RegressionTest/TypelistTest.h b/test/RegressionTest/TypelistTest.h new file mode 100755 index 0000000..6087d29 --- /dev/null +++ b/test/RegressionTest/TypelistTest.h @@ -0,0 +1,188 @@ +/////////////////////////////////////////////////////////////////////////////// +// Unit Test for Loki +// +// Copyright Terje Slettebų and Pavel Vozenilek 2002. +// +// Permission to use, copy, modify, and distribute this software for any +// purpose is hereby granted without fee, provided that this copyright and +// permissions notice appear in all copies and derivatives. +// +// This software is provided "as is" without express or implied warranty. +// +// Last update: September 16, 2002 +/////////////////////////////////////////////////////////////////////////////// + +#ifndef TYPELISTTEST_H +#define TYPELISTTEST_H + +#include + +/////////////////////////////////////////////////////////////////////////////// +// TypelistTest +/////////////////////////////////////////////////////////////////////////////// + +class TypelistTest : public Test +{ +public: + TypelistTest() : Test("Typelist.h") {} + + virtual void execute(TestResult &result) + { + printName(result); + + using namespace Loki; + using namespace Loki::TL; + + typedef TYPELIST_1(char) CharList; + typedef TYPELIST_3(char,int,double) CharIntDoubleList; + typedef TYPELIST_4(char,int,double,char) CharIntDoubleCharList; + typedef TYPELIST_3(Base,Derived1,Derived2) BaseDerived1Derived2List; + typedef TYPELIST_3(Derived2,Derived1,Base) Derived2Derived1BaseList; + typedef TYPELIST_4(Base,Derived1,Base,Derived2) BaseDerived1BaseDerived2List; + typedef TYPELIST_4(Derived1,Base,Derived1,Derived2) Derived1BaseDerived1Derived2List; + + bool r; + + r=Length::value==0 && + Length::value==1 && + Length::value==3; + + testAssert("Length",r,result); + + r=SameType::Result,char>::value && + SameType::Result,double>::value; + + testAssert("TypeAt",r,result); + + #if !(_MSC_VER && !__INTEL_COMPILER && !__MWERKS__ && _MSC_VER < 1300) + + // TypeAtNonStrict works like TypeAt on MSVC 6.0 + + r=SameType::Result,NullType>::value && + SameType::Result,char>::value && + SameType::Result,double>::value && + SameType::Result,NullType>::value && + SameType::Result,long>::value; + + testAssert("TypeAtNonStrict",r,result); + + #else + + testAssert("TypeAtNonStrict",false,result,false); + + #endif + + r=IndexOf::value==-1 && + IndexOf::value==0 && + IndexOf::value==2 && + IndexOf::value==-1; + + testAssert("IndexOf",r,result); + + #if !(_MSC_VER && !__INTEL_COMPILER && !__MWERKS__ && _MSC_VER < 1300) + + // Append, Erase, EraseAll, NoDuplicates, Replace, ReplaceAll, Reverse, + // MostDerived and DerivedToFront doesn't work on MSVC 6.0 + + r=SameType::Result,NullType>::value && + SameType::Result,TYPELIST_1(char)>::value && + SameType::Result,CharList>::value && + SameType::Result,CharList>::value && + SameType::Result,TYPELIST_2(char,int)>::value && + SameType::Result,TYPELIST_4(char,char,int,double)>::value; + + testAssert("Append",r,result); + + r=SameType::Result,NullType>::value && + SameType::Result,NullType>::value && + SameType::Result,CharList>::value && + SameType::Result,TYPELIST_2(char,double)>::value && + SameType::Result,TYPELIST_2(char,int)>::value; + + testAssert("Erase",r,result); + + r=SameType::Result,NullType>::value && + SameType::Result,NullType>::value && + SameType::Result,CharList>::value && + SameType::Result,TYPELIST_2(char,double)>::value && + SameType::Result,TYPELIST_2(char,int)>::value && + SameType::Result,TYPELIST_2(int,double)>::value && + SameType::Result,TYPELIST_3(char,double,char)>::value && + SameType::Result,TYPELIST_3(char,int,char)>::value; + + testAssert("EraseAll",r,result); + + r=SameType::Result,NullType>::value && + SameType::Result,CharList>::value && + SameType::Result,CharIntDoubleList>::value && + SameType::Result,CharIntDoubleList>::value; + + testAssert("NoDuplicates",r,result); + + r=SameType::Result,NullType>::value && + SameType::Result,TYPELIST_1(long)>::value && + SameType::Result,CharList>::value && + SameType::Result,TYPELIST_3(long,int,double)>::value && + SameType::Result,CharIntDoubleList>::value && + SameType::Result,TYPELIST_4(long,int,double,char)>::value; + + testAssert("Replace",r,result); + + r=SameType::Result,NullType>::value && + SameType::Result,TYPELIST_1(long)>::value && + SameType::Result,CharList>::value && + SameType::Result,TYPELIST_3(long,int,double)>::value && + SameType::Result,CharIntDoubleList>::value && + SameType::Result,TYPELIST_4(long,int,double,long)>::value; + + testAssert("ReplaceAll",r,result); + + r=SameType::Result,NullType>::value && + SameType::Result,CharList>::value && + SameType::Result,TYPELIST_3(double,int,char)>::value; + + testAssert("Reverse",r,result); + + r=SameType::Result,Base>::value && + SameType::Result,Derived2>::value && + SameType::Result,Derived2>::value && + SameType::Result,Derived2>::value && + SameType::Result,Derived2>::value && + SameType::Result,Derived2>::value && + SameType::Result,Derived2>::value; + + testAssert("MostDerived",r,result); + + r=SameType::Result,NullType>::value && + SameType::Result,CharList>::value && + SameType::Result,CharIntDoubleList>::value && + SameType::Result,CharIntDoubleCharList>::value && + SameType::Result,Derived2Derived1BaseList>::value && + SameType::Result,Derived2Derived1BaseList>::value && + SameType::Result,TYPELIST_4(Derived2,Derived1,Base,Base)>::value && + SameType::Result,TYPELIST_4(Derived2,Derived1,Derived1,Base)>::value; + + testAssert("DerivedToFront",r,result); + + #else + + testAssert("Append",false,result,false); + testAssert("Erase",false,result,false); + testAssert("EraseAll",false,result,false); + testAssert("NoDuplicates",false,result,false); + testAssert("Replace",false,result,false); + testAssert("Reverse",false,result,false); + testAssert("MostDerived",false,result,false); + testAssert("DerivedToFront",false,result,false); + + #endif + + std::cout << '\n'; + } + +private: + struct Base { char c; }; + struct Derived1 : Base { char c; }; + struct Derived2 : Derived1 { char c; }; +} typelistTest; +#endif diff --git a/test/RegressionTest/UnitTest.h b/test/RegressionTest/UnitTest.h new file mode 100755 index 0000000..72deb5e --- /dev/null +++ b/test/RegressionTest/UnitTest.h @@ -0,0 +1,184 @@ +/////////////////////////////////////////////////////////////////////////////// +// Unit Test framework +// +// Copyright Terje Slettebų and Pavel Vozenilek 2002. +// +// Permission to use, copy, modify, and distribute this software for any +// purpose is hereby granted without fee, provided that this copyright and +// permissions notice appear in all copies and derivatives. +// +// This software is provided "as is" without express or implied warranty. +// +// Last update: September 16, 2002 +/////////////////////////////////////////////////////////////////////////////// + +#ifndef UNITTEST_H +#define UNITTEST_H + +#include +#include +#include +#include +#include + +/////////////////////////////////////////////////////////////////////////////// +// SameType +/////////////////////////////////////////////////////////////////////////////// + +#if defined(_MSC_VER) && !defined(__INTEL_COMPILER) && !defined(__MWERKS__) + +// Rani Sharoni's SameType +// +// Non-conforming workaround for MSVC + +template +struct SameType +{ +private: + template + struct In + { enum { value = false }; }; + + template<> + struct In + { enum { value = true }; }; + +public: + enum { value = In::value }; +}; + +#else + +template +struct SameType +{ + static const bool value=false; +}; + +template +struct SameType +{ + static const bool value=true; +}; + +#endif + +/////////////////////////////////////////////////////////////////////////////// +// TestResult +/////////////////////////////////////////////////////////////////////////////// + +class TestResult +{ +public: + TestResult() : pos(0),passed(0),failed(0),notSupported(0) {} + + int pos; + int passed; + int failed; + int notSupported; +}; + + +/////////////////////////////////////////////////////////////////////////////// +// Test +/////////////////////////////////////////////////////////////////////////////// + +class Test +{ +typedef std::vector tests_type; +static tests_type tests; + +public: + explicit Test(const std::string &n) : name(n) + { + Test::tests.push_back(this); + } + + virtual void execute(TestResult &) =0; + +protected: + virtual ~Test() {} + + void printName(const TestResult &result) const + { + if(name.length()!=0) + std::cout << std::string(result.pos,' ') << name << '\n'; + } + + void testAssert(const std::string &s,bool assertion,TestResult &result,bool supported =true, + const std::string &failStr =emptyStr()) + { + std::string str=std::string(result.pos+2,' ')+s; + + str+=std::string(offset-str.length(),' '); + + if(supported) + { + if(assertion) + { + std::cout << str << "Passed\n"; + + ++result.passed; + } + else + { + std::cout << str << (failStr==emptyStr() ? std::string("Failed") : "Failed - "+failStr) << '\n'; + + ++result.failed; + } + } + else + { + std::cout << str << "Not Supported\n"; + + ++result.notSupported; + } + } + + static std::string emptyStr() + { + return std::string(); + } + +public: + enum { offset=63 }; + +protected: + const std::string name; + +public: + static int run(const std::string &title) + { + std::cout << title << std::string(Test::offset-title.length(),' ') << "Result\n"; + std::cout << std::string(76,'-') << '\n'; + + TestResult testResult; + + tests_type::iterator it; + tests_type::const_iterator itEnd = Test::tests.end(); + for(it=Test::tests.begin(); it!=itEnd; ++it) + { + Test* test = *it; + test->execute(testResult); + } + + std::cout << std::string(76,'-') << '\n'; + + const int total=testResult.passed+testResult.failed; + const int totalAll=total+testResult.notSupported; + + if(total!=0) + std::cout << "Total - " << testResult.passed << '/' << total << (total==1 ? " test, " : " tests, ") + << testResult.passed*100/total << "% Passed\n"; + + if(testResult.notSupported!=0) + std::cout << "Not Supported - " << testResult.notSupported << '/' << totalAll << ", " + << testResult.notSupported*100/totalAll << "%\n"; + + return testResult.failed; + } + +}; + + +#endif diff --git a/test/RegressionTest/make.msvc.bat b/test/RegressionTest/make.msvc.bat new file mode 100755 index 0000000..6fd242e --- /dev/null +++ b/test/RegressionTest/make.msvc.bat @@ -0,0 +1,5 @@ +if not exist tmp\ mkdir tmp + +cl -c -Zm200 -O2 -MT -EHsc -GR -W0 -wd4710 -I"." -I"..\..\include" -I"..\..\include\loki" -Fotmp\ Test.cpp + +link /NOLOGO /SUBSYSTEM:CONSOLE /incremental:no /OUT:"main-msvc.exe" tmp\Test.obj