no message

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@67 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
magmaikh 2002-10-13 04:40:12 +00:00
parent 34baf93ed8
commit 44d1bc8ebf
21 changed files with 336 additions and 97 deletions

View file

@ -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<class II, class P1>
@ -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 <typename> class UnitFunc
//template <class> class UnitFunc
template<typename Types, class UnitFunc, typename II>
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
////////////////////////////////////////////////////////////////////////////////

View file

@ -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<U*>(pObj->DoClone());
assert(typeid(*pClone) == typeid(*pObj));
//MSVC7: warning C4541: 'typeid' used on polymorphic type 'Loki::FunctorImpl<R,TList,ThreadingModel>' 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_

View file

@ -73,7 +73,7 @@ namespace Loki
typedef typename In<flag>::Result Result;
};
/*
////////////////////////////////////////////////////////////////////////////////
// class template SameType
// Return true iff two given types are the same
@ -98,6 +98,7 @@ namespace Loki
public:
enum { value = In<U>::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<B, D>::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 <class T, class U>
struct SuperSubclass
{
enum { value = (::Loki::Conversion<const volatile U*, const volatile T*>::exists &&
!::Loki::Conversion<const volatile T*, const volatile void*>::sameType) };
};
////////////////////////////////////////////////////////////////////////////////
// class template SuperSubclassStrict
// Invocation: SuperSubclassStrict<B, D>::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<class T,class U>
struct SuperSubclassStrict
{
enum { value = (::Loki::Conversion<const volatile U*, const volatile T*>::exists &&
!::Loki::Conversion<const volatile T*, const volatile void*>::sameType &&
!::Loki::Conversion<const volatile T*, const volatile U*>::sameType) };
};
#define SUPERSUBCLASS(T, U) \
(::Loki::Conversion<const volatile U*, const volatile T*>::exists && \
!::Loki::Conversion<const volatile T*, const volatile void*>::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_

View file

@ -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_

View file

@ -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<typename Types, template <typename> class UnitFunc, typename II>
template<typename Types, template <class> class UnitFunc, typename II>
void iterate_types(II ii)
{
Loki::TL::IterateTypes<Types, UnitFunc> 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

View file

@ -18,7 +18,6 @@
#include <memory>
#include <typeinfo>
#include <loki/AbstractFactory.h>
#include "UnitTest.h"
///////////////////////////////////////////////////////////////////////////////
// AbstractFactoryTest
@ -64,7 +63,7 @@ public:
s = easyFactory->Create<Soldier>();
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

View file

@ -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<test_vect2_t::iterator, bool> 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

View file

@ -6,14 +6,6 @@
#include <typeinfo>
#include <Loki/DataGenerators.h>
#include "UnitTest.h"
template<typename T>
T& remove_const(const T& t)
{
return const_cast<T&>(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<char_types, name_from_type>(remove_const(std::back_inserter(names)));
iterate_types<char_types, nameof_type>(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<some_types, sizeof_type>(remove_const(std::back_inserter(sizes)));
iterate_types<some_types, sizeof_type>(std::back_inserter(sizes));
size_t apriori_size[] = {sizeof(char), sizeof(short), sizeof(int), sizeof(double)};
b = true;
for(int i=0; i<n; ++i)
@ -65,6 +57,6 @@ struct DataGeneratorsTest : public Test
b = sizes.size() == 0;
testAssert("iterate_types - Degenerate Case 2 - NullType", b, result);
}
};
} datageneratorsTest;
#endif //DATAGENERATORSTEST_H

View file

@ -16,7 +16,6 @@
#define FACTORYTEST_H
#include <loki/Factory.h>
#include "UnitTest.h"
///////////////////////////////////////////////////////////////////////////////
// FactoryTest
@ -142,6 +141,6 @@ public:
std::cout << '\n';
}
};
} factoryTest;
#endif

View file

@ -16,7 +16,6 @@
#define FUNCTORTEST_H
#include <loki/Functor.h>
#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

View file

@ -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

View file

@ -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

View file

@ -0,0 +1,121 @@
<?xml version="1.0" encoding = "Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="7.00"
Name="UnitTest"
ProjectGUID="{79729949-F144-4098-BFE9-B6320E6AC3F6}"
Keyword="Win32Proj">
<Platforms>
<Platform
Name="Win32"/>
</Platforms>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="Debug"
IntermediateDirectory="Debug"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
MinimalRebuild="TRUE"
BasicRuntimeChecks="3"
RuntimeLibrary="5"
BufferSecurityCheck="TRUE"
TreatWChar_tAsBuiltInType="TRUE"
ForceConformanceInForLoopScope="TRUE"
RuntimeTypeInfo="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="4"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/UnitTest.exe"
LinkIncremental="2"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile="$(OutDir)/UnitTest.pdb"
SubSystem="1"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="Release"
IntermediateDirectory="Release"
ConfigurationType="1"
CharacterSet="2">
<Tool
Name="VCCLCompilerTool"
Optimization="2"
InlineFunctionExpansion="1"
OmitFramePointers="TRUE"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
StringPooling="TRUE"
RuntimeLibrary="4"
EnableFunctionLevelLinking="TRUE"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="TRUE"
DebugInformationFormat="3"/>
<Tool
Name="VCCustomBuildTool"/>
<Tool
Name="VCLinkerTool"
OutputFile="$(OutDir)/UnitTest.exe"
LinkIncremental="1"
GenerateDebugInformation="TRUE"
SubSystem="1"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"/>
<Tool
Name="VCMIDLTool"/>
<Tool
Name="VCPostBuildEventTool"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
</Configuration>
</Configurations>
<Files>
<File
RelativePath="LokiTest.h">
</File>
<File
RelativePath="Test.cpp">
</File>
<File
RelativePath="..\..\MSVC\1300\TypeTraits.h">
</File>
<File
RelativePath="UnitTest.h">
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View file

@ -76,7 +76,7 @@ namespace
typedef SingletonHolder<MyClass<19>, CreateStatic, SingletonWithLongevity, SingleThreaded> t19;
typedef SingletonHolder<MyClass<20>, CreateStatic, NoDestroy, SingleThreaded> t20;
#if !__INTEL_COMPILER && !__GNUC__
#if !__INTEL_COMPILER && !__GNUC__ && !_MSC_VER
typedef SingletonHolder<MyClass<5>, CreateUsingNew, DefaultLifetime, ClassLevelLockable> t5;
typedef SingletonHolder<MyClass<6>, 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

View file

@ -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

View file

@ -285,6 +285,6 @@ private:
typedef SmartPtr<TestClass, DestructiveCopy, DisallowConversion, NoCheck, DefaultSPStorage> p101;
typedef SmartPtr<TestClass, NoCopy, DisallowConversion, NoCheck, DefaultSPStorage> p102;
typedef SmartPtr<TestClass, NoCopy, DisallowConversion, NoCheck, DefaultSPStorage> p103;
};
} smartPtrTest;
#endif

View file

@ -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;

View file

@ -114,6 +114,6 @@ private:
struct Base { char c; };
struct Derived1 : Base { char c; };
struct Derived2 : Derived1 { char c; };
};
} typeManipTest;
#endif

View file

@ -16,7 +16,6 @@
#define TYPETRAITSTEST_H
#include <Loki/TypeTraits.h>
#include "UnitTest.h"
///////////////////////////////////////////////////////////////////////////////
// TypeTraitsTest
@ -111,6 +110,6 @@ public:
std::cout << '\n';
}
};
} typeTraitsTest;
#endif

View file

@ -16,7 +16,6 @@
#define TYPELISTTEST_H
#include <Loki/Typelist.h>
#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

View file

@ -19,6 +19,7 @@
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
///////////////////////////////////////////////////////////////////////////////
// SameType
@ -28,6 +29,8 @@
// Rani Sharoni's SameType
//This is non-standard code, you are not allowed to
// specialize a nested template
template<class T1,class T2>
struct SameType
{
@ -75,14 +78,21 @@ public:
int notSupported;
};
///////////////////////////////////////////////////////////////////////////////
// Test
///////////////////////////////////////////////////////////////////////////////
class Test
{
typedef std::vector<Test*> 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;
@ -135,58 +145,22 @@ public:
protected:
const std::string name;
};
///////////////////////////////////////////////////////////////////////////////
// TestSuite
///////////////////////////////////////////////////////////////////////////////
class TestSuite : public Test
{
private:
typedef std::vector<Test *> 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';
@ -203,6 +177,8 @@ public:
return testResult.failed;
}
};
#endif