diff --git a/MSVC/1300/DataGenerators.h b/MSVC/1300/DataGenerators.h index c13eba0..ebc1bb6 100644 --- a/MSVC/1300/DataGenerators.h +++ b/MSVC/1300/DataGenerators.h @@ -1,13 +1,19 @@ //////////////////////////////////////////////////////////////////////////////// // The Loki Library -// Data Generator by Shannon Barber +// Data Generator by Mr. Shannon Barber // This code DOES NOT accompany the book: // Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design // Patterns Applied". Copyright (c) 2001. Addison-Wesley. // // Code covered by the MIT License +// +// The author makes no representations about the suitability of this software +// for any purpose. It is provided "as is" without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// +// Last update: Oct 10, 2002 + +#pragma once #include "TypeList.h" //MSVC7 version @@ -95,7 +101,12 @@ namespace Loki void operator()(II ii) { genfunc_t gen; + //warning C4267: 'argument' : conversion from 'size_t' to 'const std::_Vbase', possible loss of data +#pragma warning(push) +#pragma warning(disable: 4267) + //TODOSGB *ii = gen(); +#pragma warning(pop) ++ii; } template @@ -201,7 +212,7 @@ namespace Loki //UnitFunc is really a template-template parameter, but MSVC7 // chokes on the correct defintion. Oddly enough, it works correctly // with the 'undecorated' template parameter declaraion! - //template class UnitFunc + //template class UnitFunc template void iterate_types(II ii) { @@ -215,5 +226,6 @@ namespace Loki // Change log: // Aug 17, 2002: Ported to MSVC7 by Rani Sharoni // Aug 18, 2002: Removed ctor(II), replaced with operator(II) Shannon Barber +// Oct 10, 2002: Changed II (insertion iterator) from pass-by-reference to pass-by-value //////////////////////////////////////////////////////////////////////////////// diff --git a/MSVC/1300/Functor.h b/MSVC/1300/Functor.h index c211881..ba0c991 100644 --- a/MSVC/1300/Functor.h +++ b/MSVC/1300/Functor.h @@ -13,7 +13,7 @@ // without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// -// Last update: May 19, 2002 +// Last update: Oct 10, 2002 #ifndef FUNCTOR_INC_ #define FUNCTOR_INC_ @@ -61,7 +61,10 @@ namespace Loki { if (!pObj) return 0; U* pClone = static_cast(pObj->DoClone()); - assert(typeid(*pClone) == typeid(*pObj)); + //MSVC7: warning C4541: 'typeid' used on polymorphic type 'Loki::FunctorImpl' with /GR-; unpredictable behavior may result + //I rather RTTI wasn't a requirement + //TODOSGB find another way + //assert(typeid(*pClone) == typeid(*pObj)); return pClone; } }; @@ -1342,6 +1345,7 @@ namespace Loki // Change log: // June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! // May 10, 2002: ported by Rani Sharoni to VC7 (RTM - 9466) +// Oct 10, 2002: removed rtti/polymorphic use of typeid //////////////////////////////////////////////////////////////////////////////// #endif // FUNCTOR_INC_ diff --git a/MSVC/1300/TypeManip.h b/MSVC/1300/TypeManip.h index 014ba17..873dafa 100644 --- a/MSVC/1300/TypeManip.h +++ b/MSVC/1300/TypeManip.h @@ -73,7 +73,7 @@ namespace Loki typedef typename In::Result Result; }; - +/* //////////////////////////////////////////////////////////////////////////////// // class template SameType // Return true iff two given types are the same @@ -98,6 +98,7 @@ namespace Loki public: enum { value = In::value }; }; + //*/ //////////////////////////////////////////////////////////////////////////////// // Helper types Small and Big - guarantee that sizeof(Small) < sizeof(Big) @@ -183,6 +184,38 @@ namespace Loki // Caveat: might not work if T and U are in a private inheritance hierarchy. //////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////// +// class template SuperSubclass +// Invocation: SuperSubclass::value where B and D are types. +// Returns true if B is a public base of D, or if B and D are aliases of the +// same type. +// +// Caveat: might not work if T and U are in a private inheritance hierarchy. +//////////////////////////////////////////////////////////////////////////////// + +template +struct SuperSubclass +{ + enum { value = (::Loki::Conversion::exists && + !::Loki::Conversion::sameType) }; +}; + +//////////////////////////////////////////////////////////////////////////////// +// class template SuperSubclassStrict +// Invocation: SuperSubclassStrict::value where B and D are types. +// Returns true if B is a public base of D. +// +// Caveat: might not work if T and U are in a private inheritance hierarchy. +//////////////////////////////////////////////////////////////////////////////// + +template +struct SuperSubclassStrict +{ + enum { value = (::Loki::Conversion::exists && + !::Loki::Conversion::sameType && + !::Loki::Conversion::sameType) }; +}; + #define SUPERSUBCLASS(T, U) \ (::Loki::Conversion::exists && \ !::Loki::Conversion::sameType) @@ -205,6 +238,7 @@ namespace Loki // Change log: // June 20, 2001: ported by Nick Thurn to gcc 2.95.3. Kudos, Nick!!! // May 10, 2002: ported by Rani Sharoni to VC7 (RTM - 9466) +// Oct 10, 2002: Commented SameType template (not a loki-template - yet) //////////////////////////////////////////////////////////////////////////////// #endif // TYPEMANIP_INC_ diff --git a/MSVC/1300/TypeTraits.h b/MSVC/1300/TypeTraits.h index af065bd..1d615df 100644 --- a/MSVC/1300/TypeTraits.h +++ b/MSVC/1300/TypeTraits.h @@ -15,6 +15,8 @@ // Last update: May 19, 2002 +//TODOSGB None of the parameter types are defined inside of TypeTraits, e.g. PointeeType, ReferredType, etc... + #ifndef TYPETRAITS_INC_ #define TYPETRAITS_INC_ diff --git a/Reference/DataGenerators.h b/Reference/DataGenerators.h index 402b6c0..c297363 100644 --- a/Reference/DataGenerators.h +++ b/Reference/DataGenerators.h @@ -6,8 +6,14 @@ // Patterns Applied". Copyright (c) 2001. Addison-Wesley. // // Code covered by the MIT License +// The author makes no representations about the suitability of this software +// for any purpose. It is provided "as is" without express or implied warranty. //////////////////////////////////////////////////////////////////////////////// +// Last update: Oct 10, 2002 + +#ifndef DATAGENERATORS_H +#define DATAGENERATORS_H #include "TypeList.h" //Reference version @@ -93,7 +99,7 @@ namespace Loki {} }; - template class UnitFunc, typename II> + template class UnitFunc, typename II> void iterate_types(II ii) { Loki::TL::IterateTypes it; @@ -102,6 +108,7 @@ namespace Loki }//ns TL }//ns Loki +#endif //DATAGENERATORS_H //////////////////////////////////////////////////////////////////////////////// // Change log: // 9/20/02 Named changed from GenData to IterateTypes diff --git a/tools/RegressionTest/AbstractFactoryTest.h b/tools/RegressionTest/AbstractFactoryTest.h index 930aa66..1be1f65 100644 --- a/tools/RegressionTest/AbstractFactoryTest.h +++ b/tools/RegressionTest/AbstractFactoryTest.h @@ -18,7 +18,6 @@ #include #include #include -#include "UnitTest.h" /////////////////////////////////////////////////////////////////////////////// // AbstractFactoryTest @@ -63,8 +62,8 @@ public: Soldier *s; s = easyFactory->Create(); - - r=typeid(*s)==typeid(SillySoldier); + + r= !!(typeid(*s)==typeid(SillySoldier)); //SGB !! eliminates bool-to-int performance warning delete s; @@ -82,6 +81,6 @@ public: std::cout << '\n'; } -}; +} abstractFactoryTest; #endif diff --git a/tools/RegressionTest/AssocVectorTest.h b/tools/RegressionTest/AssocVectorTest.h index 43eea62..a0d6ae6 100644 --- a/tools/RegressionTest/AssocVectorTest.h +++ b/tools/RegressionTest/AssocVectorTest.h @@ -187,7 +187,7 @@ void test_vect1() assert(vec11.size() == 0); check_insert1(vec11); - unsigned size1 = vec11.size(); + size_t size1 = vec11.size(); assert(size1); test_vect1_t vec12(vec11.begin(), vec11.end()); @@ -244,7 +244,7 @@ void test_vect2() assert(it->second == 3); std::pair aux = vec21.insert(std::make_pair("xyz", 99)); - assert(aux.first); + assert(aux.first); //TODOSGB was second meant, not first? MSVC7 dies here (more errors follow) it = vec21.find("xyz"); assert(it->second == 3); @@ -353,6 +353,6 @@ public: std::cout << '\n'; } -}; +} assocVectorTest; #endif diff --git a/tools/RegressionTest/DataGeneratorsTest.h b/tools/RegressionTest/DataGeneratorsTest.h index b19f06e..57cee7b 100644 --- a/tools/RegressionTest/DataGeneratorsTest.h +++ b/tools/RegressionTest/DataGeneratorsTest.h @@ -6,14 +6,6 @@ #include #include -#include "UnitTest.h" - -template -T& remove_const(const T& t) - { - return const_cast(t); - } - struct DataGeneratorsTest : public Test { @@ -38,7 +30,7 @@ struct DataGeneratorsTest : public Test 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(remove_const(std::back_inserter(names))); + iterate_types(std::back_inserter(names)); b = names.size() == n; testAssert("iterate_types - Check Length", b, result); @@ -48,7 +40,7 @@ struct DataGeneratorsTest : public Test short, int, double>::Result some_types; - iterate_types(remove_const(std::back_inserter(sizes))); + iterate_types(std::back_inserter(sizes)); size_t apriori_size[] = {sizeof(char), sizeof(short), sizeof(int), sizeof(double)}; b = true; for(int i=0; i -#include "UnitTest.h" /////////////////////////////////////////////////////////////////////////////// // FactoryTest @@ -142,6 +141,6 @@ public: std::cout << '\n'; } -}; +} factoryTest; #endif diff --git a/tools/RegressionTest/FunctorTest.h b/tools/RegressionTest/FunctorTest.h index 89f8c6e..3a4397c 100644 --- a/tools/RegressionTest/FunctorTest.h +++ b/tools/RegressionTest/FunctorTest.h @@ -16,7 +16,6 @@ #define FUNCTORTEST_H #include -#include "UnitTest.h" /////////////////////////////////////////////////////////////////////////////// // FunctorTest @@ -102,8 +101,12 @@ private: result=true; } }; -}; +} functorTest; bool FunctorTest::testResult; +#ifndef SMALLOBJ_CPP +# define SMALLOBJ_CPP +# include "../../SmallObj.cpp" +#endif #endif diff --git a/tools/RegressionTest/LokiTest.h b/tools/RegressionTest/LokiTest.h index c8fb5f6..7b7bb91 100644 --- a/tools/RegressionTest/LokiTest.h +++ b/tools/RegressionTest/LokiTest.h @@ -25,6 +25,7 @@ //#include "AbstractFactoryTest.h" //#include "AssocVectorTest.h" //#include "FunctorTest.h" +#include "DataGeneratorsTest.h" /////////////////////////////////////////////////////////////////////////////// // LokiTest @@ -56,6 +57,7 @@ private: // tests.add(abstractFactoryTest); // tests.add(assocVectorTest); // tests.add(functorTest); + tests.add(datageneratorTest); } private: @@ -72,6 +74,7 @@ private: // AbstractFactoryTest abstractFactoryTest; // AssocVectorTest assocVectorTest; // FunctorTest functorTest; + DataGeneratorsTest datageneratorTest; }; #endif diff --git a/tools/RegressionTest/MSVCUnitTest.sln b/tools/RegressionTest/MSVCUnitTest.sln new file mode 100644 index 0000000..70bd2ce --- /dev/null +++ b/tools/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/tools/RegressionTest/MSVCUnitTest.vcproj b/tools/RegressionTest/MSVCUnitTest.vcproj new file mode 100644 index 0000000..40531ae --- /dev/null +++ b/tools/RegressionTest/MSVCUnitTest.vcproj @@ -0,0 +1,121 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tools/RegressionTest/SingletonTest.h b/tools/RegressionTest/SingletonTest.h index 9572e39..b60d718 100644 --- a/tools/RegressionTest/SingletonTest.h +++ b/tools/RegressionTest/SingletonTest.h @@ -76,7 +76,7 @@ namespace typedef SingletonHolder, CreateStatic, SingletonWithLongevity, SingleThreaded> t19; typedef SingletonHolder, CreateStatic, NoDestroy, SingleThreaded> t20; -#if !__INTEL_COMPILER && !__GNUC__ +#if !__INTEL_COMPILER && !__GNUC__ && !_MSC_VER typedef SingletonHolder, CreateUsingNew, DefaultLifetime, ClassLevelLockable> t5; typedef SingletonHolder, CreateUsingNew, PhoenixSingleton, ClassLevelLockable> t6; @@ -126,7 +126,7 @@ public: MAKE_TEST(t19) MAKE_TEST(t20) -#if !__INTEL_COMPILER && !__GNUC__ +#if !__INTEL_COMPILER && !__GNUC__ && !_MSC_VER MAKE_TEST(t5) MAKE_TEST(t6) @@ -152,6 +152,8 @@ public: private: bool singletonTest; -}; +} singletonTest; + +#include "../../Singleton.cpp" #endif diff --git a/tools/RegressionTest/SmallObjectTest.h b/tools/RegressionTest/SmallObjectTest.h index 3f6770e..9eec393 100644 --- a/tools/RegressionTest/SmallObjectTest.h +++ b/tools/RegressionTest/SmallObjectTest.h @@ -144,7 +144,7 @@ private: for (int j = 0; j < 1024; ++j) { - int pos = std::rand() % vec.size(); + size_t pos = std::rand() % vec.size(); delete vec[pos]; @@ -159,6 +159,10 @@ private: vec.pop_back(); } } -}; +} smallObjectTest; +#ifndef SMALLOBJ_CPP +# define SMALLOBJ_CPP +# include "../../SmallObj.cpp" +#endif #endif diff --git a/tools/RegressionTest/SmartPtrTest.h b/tools/RegressionTest/SmartPtrTest.h index 84d317d..e602bfe 100644 --- a/tools/RegressionTest/SmartPtrTest.h +++ b/tools/RegressionTest/SmartPtrTest.h @@ -285,6 +285,6 @@ private: typedef SmartPtr p101; typedef SmartPtr p102; typedef SmartPtr p103; -}; +} smartPtrTest; #endif diff --git a/tools/RegressionTest/Test.cpp b/tools/RegressionTest/Test.cpp index 71f3fc9..003b3e9 100644 --- a/tools/RegressionTest/Test.cpp +++ b/tools/RegressionTest/Test.cpp @@ -9,23 +9,86 @@ // // This software is provided "as is" without express or implied warranty. // -// Last update: September 16, 2002 +// Last update: October 10, 2002 /////////////////////////////////////////////////////////////////////////////// #ifdef __INTEL_COMPILER # pragma warning(disable: 111 193 304 383 444 488 981 1418) #endif -#include "LokiTest.h" +//Some platforms might have difficulty with this +//Need to ifdef around those cases. +//TODOSGB + +#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 "SmallObjectTest.h" +#include "SingletonTest.h" +#include "SmartPtrTest.h" +#include "FactoryTest.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 #ifdef? + * MSVC 6 ? ? ? ? ? + * MSVC 7 DerivedToFront Conversion FC AP P #ifdef? + * Intel ? ? ? ? ? ? + * BCB 5.5? ? ? ? ? ? + * CW 6.0 DerivedToFront ? ? ? ? + * + * SmartPtrTest FactoryTest AbstractFactoryTest AssocVectorTest FunctorTest + * gcc 2.95.3 ? ? ? ? ? + * gcc 3.2 FC AP AP FC AP + * MSVC 6 ? ? ? ? ? + * MSVC 7 FC AP AP FC AP + * Intel ? ? ? ? ? ? + * BCB 5.5? ? ? ? ? ? + * CW 6.0 ? ? ? ? ? + * + * DataGeneratorsTest + * gcc 2.95.3 ? + * gcc 3.2 AP + * MSVC 6 ? + * MSVC 7 AP + * Intel ? ? + * BCB 5.5? ? + * CW 6.0 ? + + */ int main() { -LokiTest test; -const int result=test.result(); +int result = Test::run("Loki Unit Test"); -#if __BORLANDC__ || __GNUC__ +#if __BORLANDC__ while(true); // Stop console window from closing if run from IDE. +#elif _MSC_VER || __GNUC__ + system("pause"); #endif return result; diff --git a/tools/RegressionTest/TypeManipTest.h b/tools/RegressionTest/TypeManipTest.h index 3ae16fd..b8c5017 100644 --- a/tools/RegressionTest/TypeManipTest.h +++ b/tools/RegressionTest/TypeManipTest.h @@ -114,6 +114,6 @@ private: struct Base { char c; }; struct Derived1 : Base { char c; }; struct Derived2 : Derived1 { char c; }; -}; +} typeManipTest; #endif diff --git a/tools/RegressionTest/TypeTraitsTest.h b/tools/RegressionTest/TypeTraitsTest.h index a78496f..b10ecfd 100644 --- a/tools/RegressionTest/TypeTraitsTest.h +++ b/tools/RegressionTest/TypeTraitsTest.h @@ -16,7 +16,6 @@ #define TYPETRAITSTEST_H #include -#include "UnitTest.h" /////////////////////////////////////////////////////////////////////////////// // TypeTraitsTest @@ -111,6 +110,6 @@ public: std::cout << '\n'; } -}; +} typeTraitsTest; #endif diff --git a/tools/RegressionTest/TypelistTest.h b/tools/RegressionTest/TypelistTest.h index 67f912e..9cc8d0e 100644 --- a/tools/RegressionTest/TypelistTest.h +++ b/tools/RegressionTest/TypelistTest.h @@ -16,7 +16,6 @@ #define TYPELISTTEST_H #include -#include "UnitTest.h" /////////////////////////////////////////////////////////////////////////////// // TypelistTest @@ -185,6 +184,5 @@ private: struct Base { char c; }; struct Derived1 : Base { char c; }; struct Derived2 : Derived1 { char c; }; -}; - +} typelistTest; #endif diff --git a/tools/RegressionTest/UnitTest.h b/tools/RegressionTest/UnitTest.h index c2eb303..d442d79 100644 --- a/tools/RegressionTest/UnitTest.h +++ b/tools/RegressionTest/UnitTest.h @@ -19,6 +19,7 @@ #include #include #include +#include /////////////////////////////////////////////////////////////////////////////// // SameType @@ -28,6 +29,8 @@ // Rani Sharoni's SameType +//This is non-standard code, you are not allowed to +// specialize a nested template template struct SameType { @@ -49,13 +52,13 @@ public: template struct SameType { - static const bool value=false; + static const bool value=false; }; template struct SameType { - static const bool value=true; + static const bool value=true; }; #endif @@ -75,17 +78,24 @@ public: int notSupported; }; + /////////////////////////////////////////////////////////////////////////////// // Test /////////////////////////////////////////////////////////////////////////////// class Test { +typedef std::vector tests_type; +static tests_type tests; + public: - explicit Test(const std::string &n) : name(n) {} + explicit Test(const std::string &n) : name(n) + { + Test::tests.push_back(this); + } virtual void execute(TestResult &) =0; - + protected: ~Test() {} @@ -135,59 +145,23 @@ public: protected: const std::string name; -}; - -/////////////////////////////////////////////////////////////////////////////// -// TestSuite -/////////////////////////////////////////////////////////////////////////////// - -class TestSuite : public Test -{ -private: - typedef std::vector TestList; - + public: - explicit TestSuite(const std::string &name =emptyStr()) : Test(name) {} - - void add(Test &test) - { - tests.push_back(&test); - } - - virtual void execute(TestResult &result) - { - printName(result); - - if(name.length()!=0) - result.pos+=2; - - for(TestList::iterator i=tests.begin();i!=tests.end();++i) - (*i)->execute(result); - - if(name.length()!=0) - result.pos-=2; - } - -private: - TestList tests; -}; - -/////////////////////////////////////////////////////////////////////////////// -// UnitTest -/////////////////////////////////////////////////////////////////////////////// - -class UnitTest -{ -public: - int run(const std::string &title,TestSuite &tests) const + 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.execute(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; @@ -203,6 +177,8 @@ public: return testResult.failed; } + }; + #endif