*** empty log message ***
git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@60 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
parent
ca9fff7cf4
commit
a0aa6b269f
13 changed files with 2054 additions and 0 deletions
87
tools/RegressionTest/AbstractFactoryTest.h
Normal file
87
tools/RegressionTest/AbstractFactoryTest.h
Normal file
|
@ -0,0 +1,87 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <memory>
|
||||
#include <typeinfo>
|
||||
#include <loki/AbstractFactory.h>
|
||||
#include "UnitTest.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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<TYPELIST_3(Soldier, Monster, SuperMonster)> AbstractEnemyFactory;
|
||||
|
||||
typedef Loki::ConcreteFactory<AbstractEnemyFactory, Loki::OpNewFactoryUnit,
|
||||
TYPELIST_3(SillySoldier, SillyMonster, SillySuperMonster)> EasyLevelEnemyFactory;
|
||||
|
||||
typedef Loki::ConcreteFactory<AbstractEnemyFactory, Loki::OpNewFactoryUnit,
|
||||
TYPELIST_3(BadSoldier, BadMonster, BadSuperMonster)> 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<AbstractEnemyFactory> easyFactory(new EasyLevelEnemyFactory);
|
||||
std::auto_ptr<AbstractEnemyFactory> hardFactory(new HardLevelEnemyFactory);
|
||||
|
||||
Soldier *s;
|
||||
|
||||
s = easyFactory->Create<Soldier>();
|
||||
|
||||
r=typeid(*s)==typeid(SillySoldier);
|
||||
|
||||
delete s;
|
||||
|
||||
#ifndef __BORLANDC__
|
||||
|
||||
s = hardFactory->Create<Soldier>(); //BCB bug!!! - always creates SillySoldier
|
||||
|
||||
r=r && typeid(*s)==typeid(BadSoldier);
|
||||
|
||||
delete s;
|
||||
|
||||
#endif
|
||||
|
||||
testAssert("AbstractFactory",r,result);
|
||||
|
||||
std::cout << '\n';
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
358
tools/RegressionTest/AssocVectorTest.h
Normal file
358
tools/RegressionTest/AssocVectorTest.h
Normal file
|
@ -0,0 +1,358 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <loki/AssocVector.h>
|
||||
#include "UnitTest.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// AssocVectorTest
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// STL compatible allocator
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class T> class TestAllocator : public std::allocator<T>
|
||||
{
|
||||
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 std::size_t size_type;
|
||||
typedef std::ptrdiff_t difference_type;
|
||||
|
||||
template <class U>
|
||||
struct rebind { typedef TestAllocator<U> other; };
|
||||
|
||||
TestAllocator() {}
|
||||
TestAllocator(const TestAllocator&) {}
|
||||
template <class U>
|
||||
TestAllocator(const TestAllocator<U>&) {}
|
||||
~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<pointer>(::operator new(n * sizeof(T)));
|
||||
}
|
||||
|
||||
void deallocate(pointer p, size_type size) {
|
||||
::operator delete(p);
|
||||
}
|
||||
|
||||
size_type max_size() const {
|
||||
return static_cast<size_type>(-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<const char*, const char*, bool> {
|
||||
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<int>
|
||||
{
|
||||
bool operator()(int x, int y) const {
|
||||
++int_test_count;
|
||||
return x < y;
|
||||
}
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// is_sorted
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template<class Vect>
|
||||
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 (!(Vect::key_compare()(previous, current))) return false;
|
||||
previous = current;
|
||||
++it;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
typedef Loki::AssocVector<int, int, std::less<int>, TestAllocator<std::pair<int, int> > > test_vect1_t;
|
||||
typedef Loki::AssocVector<const char*, int, str_less, TestAllocator<std::pair<const char*, int> > > test_vect2_t;
|
||||
typedef Loki::AssocVector<std::string, std::string> test_vect3_t;
|
||||
typedef Loki::AssocVector<AVTestClass, AVTestClass, std::less<AVTestClass>, TestAllocator<std::pair<AVTestClass, AVTestClass> > > test_vect4_t;
|
||||
typedef Loki::AssocVector<int, const char*> test_vect5_t;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void check_insert1(test_vect1_t& v)
|
||||
{
|
||||
std::srand(10);
|
||||
for (unsigned i = 0; i < 100; ++i) {
|
||||
int x = std::rand();
|
||||
v.insert(std::make_pair(x, x));
|
||||
assert(is_sorted(v));
|
||||
}
|
||||
assert(v.size() == 100);
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// check_swap
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
template <class Vect>
|
||||
void check_swap(Vect& v1, Vect& v2)
|
||||
{
|
||||
unsigned size1 = v1.size();
|
||||
unsigned 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);
|
||||
unsigned 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<test_vect1_t::value_type>());
|
||||
//assert(vec99.size() == 0); //- here ir cries
|
||||
|
||||
test_vect1_t::key_compare comp = test_vect1_t::key_compare();
|
||||
test_vect1_t vec14(comp, TestAllocator<test_vect1_t::value_type>());
|
||||
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<test_vect1_t::value_type>());
|
||||
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<test_vect2_t::iterator, bool> aux = vec21.insert(std::make_pair("xyz", 99));
|
||||
assert(aux.first);
|
||||
it = vec21.find("xyz");
|
||||
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;
|
||||
std::srand(111);
|
||||
// a stress test
|
||||
for (unsigned i = 0; i < 2 * 1000; ++i) {
|
||||
char buffer[16];
|
||||
std::sprintf(buffer, "string%d", std::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();
|
||||
int 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';
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
147
tools/RegressionTest/FactoryTest.h
Normal file
147
tools/RegressionTest/FactoryTest.h
Normal file
|
@ -0,0 +1,147 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <loki/Factory.h>
|
||||
#include "UnitTest.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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<Shape, int> 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<Shape> 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';
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
109
tools/RegressionTest/FunctorTest.h
Normal file
109
tools/RegressionTest/FunctorTest.h
Normal file
|
@ -0,0 +1,109 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <loki/Functor.h>
|
||||
#include "UnitTest.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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<void,TYPELIST_1(bool &)> function(testFunction);
|
||||
Functor<void,TYPELIST_1(bool &)> functor(testFunctor);
|
||||
Functor<void,TYPELIST_1(bool &)> classFunctor(&testClass,&TestClass::member);
|
||||
Functor<void,TYPELIST_1(bool &)> functorCopy(function);
|
||||
Functor<void,NullType> bindFunctor(BindFirst(function,testResult));
|
||||
Functor<void> 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;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
bool FunctorTest::testResult;
|
||||
|
||||
#endif
|
77
tools/RegressionTest/LokiTest.h
Normal file
77
tools/RegressionTest/LokiTest.h
Normal file
|
@ -0,0 +1,77 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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 LOKITEST_H
|
||||
#define LOKITEST_H
|
||||
|
||||
#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"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// LokiTest
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class LokiTest
|
||||
{
|
||||
public:
|
||||
LokiTest()
|
||||
{
|
||||
addTests();
|
||||
}
|
||||
|
||||
int result()
|
||||
{
|
||||
return unitTest.run("Unit Test",tests);
|
||||
}
|
||||
|
||||
private:
|
||||
void addTests()
|
||||
{
|
||||
tests.add(typelistTest);
|
||||
// tests.add(typeManipTest);
|
||||
// tests.add(typeTraitsTest);
|
||||
// tests.add(smallObjectTest);
|
||||
// tests.add(singletonTest);
|
||||
// tests.add(smartPtrTest);
|
||||
// tests.add(factoryTest);
|
||||
// tests.add(abstractFactoryTest);
|
||||
// tests.add(assocVectorTest);
|
||||
// tests.add(functorTest);
|
||||
}
|
||||
|
||||
private:
|
||||
UnitTest unitTest;
|
||||
TestSuite tests;
|
||||
|
||||
TypelistTest typelistTest;
|
||||
// TypeManipTest typeManipTest;
|
||||
// TypeTraitsTest typeTraitsTest;
|
||||
// SmallObjectTest smallObjectTest;
|
||||
// SingletonTest singletonTest;
|
||||
// SmartPtrTest smartPtrTest;
|
||||
// FactoryTest factoryTest;
|
||||
// AbstractFactoryTest abstractFactoryTest;
|
||||
// AssocVectorTest assocVectorTest;
|
||||
// FunctorTest functorTest;
|
||||
};
|
||||
|
||||
#endif
|
157
tools/RegressionTest/SingletonTest.h
Normal file
157
tools/RegressionTest/SingletonTest.h
Normal file
|
@ -0,0 +1,157 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <cassert>
|
||||
#include <loki/Singleton.h>
|
||||
#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<int N>
|
||||
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<MyClass<0> > t0;
|
||||
|
||||
typedef SingletonHolder<MyClass<1>, CreateUsingNew, DefaultLifetime, SingleThreaded> t1;
|
||||
typedef SingletonHolder<MyClass<2>, CreateUsingNew, PhoenixSingleton, SingleThreaded> t2;
|
||||
typedef SingletonHolder<MyClass<3>, CreateUsingNew, SingletonWithLongevity, SingleThreaded> t3;
|
||||
typedef SingletonHolder<MyClass<4>, CreateUsingNew, NoDestroy, SingleThreaded> t4;
|
||||
|
||||
typedef SingletonHolder<MyClass<9>, CreateUsingMalloc, DefaultLifetime, SingleThreaded> t9;
|
||||
typedef SingletonHolder<MyClass<10>, CreateUsingMalloc, PhoenixSingleton, SingleThreaded> t10;
|
||||
typedef SingletonHolder<MyClass<11>, CreateUsingMalloc, SingletonWithLongevity, SingleThreaded> t11;
|
||||
typedef SingletonHolder<MyClass<12>, CreateUsingMalloc, NoDestroy, SingleThreaded> t12;
|
||||
|
||||
typedef SingletonHolder<MyClass<17>, CreateStatic, DefaultLifetime, SingleThreaded> t17;
|
||||
typedef SingletonHolder<MyClass<18>, CreateStatic, PhoenixSingleton, SingleThreaded> t18;
|
||||
typedef SingletonHolder<MyClass<19>, CreateStatic, SingletonWithLongevity, SingleThreaded> t19;
|
||||
typedef SingletonHolder<MyClass<20>, CreateStatic, NoDestroy, SingleThreaded> t20;
|
||||
|
||||
#if !__INTEL_COMPILER && !__GNUC__
|
||||
|
||||
typedef SingletonHolder<MyClass<5>, CreateUsingNew, DefaultLifetime, ClassLevelLockable> t5;
|
||||
typedef SingletonHolder<MyClass<6>, CreateUsingNew, PhoenixSingleton, ClassLevelLockable> t6;
|
||||
typedef SingletonHolder<MyClass<7>, CreateUsingNew, SingletonWithLongevity, ClassLevelLockable> t7;
|
||||
typedef SingletonHolder<MyClass<8>, CreateUsingNew, NoDestroy, ClassLevelLockable> t8;
|
||||
|
||||
typedef SingletonHolder<MyClass<13>, CreateUsingMalloc, DefaultLifetime, ClassLevelLockable> t13;
|
||||
typedef SingletonHolder<MyClass<14>, CreateUsingMalloc, PhoenixSingleton, ClassLevelLockable> t14;
|
||||
typedef SingletonHolder<MyClass<15>, CreateUsingMalloc, SingletonWithLongevity, ClassLevelLockable> t15;
|
||||
typedef SingletonHolder<MyClass<16>, CreateUsingMalloc, NoDestroy, ClassLevelLockable> t16;
|
||||
|
||||
typedef SingletonHolder<MyClass<21>, CreateStatic, DefaultLifetime, ClassLevelLockable> t21;
|
||||
typedef SingletonHolder<MyClass<22>, CreateStatic, PhoenixSingleton, ClassLevelLockable> t22;
|
||||
typedef SingletonHolder<MyClass<23>, CreateStatic, SingletonWithLongevity, ClassLevelLockable> t23;
|
||||
typedef SingletonHolder<MyClass<24>, 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 !__INTEL_COMPILER && !__GNUC__
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
#endif
|
164
tools/RegressionTest/SmallObjectTest.h
Normal file
164
tools/RegressionTest/SmallObjectTest.h
Normal file
|
@ -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 SMALLOBJECTTEST_H
|
||||
#define SMALLOBJECTTEST_H
|
||||
|
||||
#include <cstdlib>
|
||||
#include <loki/SmallObj.h>
|
||||
#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<char*>(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<Base*> 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)
|
||||
{
|
||||
int pos = std::rand() % vec.size();
|
||||
|
||||
delete vec[pos];
|
||||
|
||||
vec[pos] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
while (!vec.empty())
|
||||
{
|
||||
delete vec.back();
|
||||
|
||||
vec.pop_back();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
290
tools/RegressionTest/SmartPtrTest.h
Normal file
290
tools/RegressionTest/SmartPtrTest.h
Normal file
|
@ -0,0 +1,290 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <loki/SmartPtr.h>
|
||||
#include "UnitTest.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// SmartPtrTest
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TestClass
|
||||
{
|
||||
public:
|
||||
TestClass() : references(1)
|
||||
{
|
||||
++instances;
|
||||
}
|
||||
|
||||
~TestClass()
|
||||
{
|
||||
--instances;
|
||||
}
|
||||
|
||||
void AddRef()
|
||||
{
|
||||
++references;
|
||||
}
|
||||
|
||||
void Release()
|
||||
{
|
||||
--references;
|
||||
|
||||
if (references <= 0)
|
||||
delete 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<TestClass> p = new TestClass; }
|
||||
|
||||
bool test1=TestClass::instances == 0;
|
||||
|
||||
{ p0 p = new TestClass(); }
|
||||
{ p1 p = new TestClass(); }
|
||||
// { p2 p = new TestClass(); }
|
||||
{ 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<TestClass, DeepCopy, DisallowConversion, AssertCheck, DefaultSPStorage> p0;
|
||||
typedef SmartPtr<TestClass, RefCounted, DisallowConversion, AssertCheck, DefaultSPStorage> p1;
|
||||
//typedef SmartPtr<TestClass, RefCountedMT, DisallowConversion, AssertCheck, DefaultSPStorage> p2;
|
||||
typedef SmartPtr<TestClass, COMRefCounted, DisallowConversion, AssertCheck, DefaultSPStorage> p3;
|
||||
typedef SmartPtr<TestClass, RefLinked, DisallowConversion, AssertCheck, DefaultSPStorage> p4;
|
||||
typedef SmartPtr<TestClass, DestructiveCopy, DisallowConversion, AssertCheck, DefaultSPStorage> p5;
|
||||
typedef SmartPtr<TestClass, NoCopy, DisallowConversion, AssertCheck, DefaultSPStorage> p6;
|
||||
typedef SmartPtr<TestClass, NoCopy, DisallowConversion, AssertCheck, DefaultSPStorage> p7;
|
||||
|
||||
typedef SmartPtr<TestClass, DeepCopy, AllowConversion, AssertCheck, DefaultSPStorage> p8;
|
||||
typedef SmartPtr<TestClass, RefCounted, AllowConversion, AssertCheck, DefaultSPStorage> p9;
|
||||
//typedef SmartPtr<TestClass, RefCountedMT, AllowConversion, AssertCheck, DefaultSPStorage> p10;
|
||||
typedef SmartPtr<TestClass, COMRefCounted, AllowConversion, AssertCheck, DefaultSPStorage> p11;
|
||||
typedef SmartPtr<TestClass, RefLinked, AllowConversion, AssertCheck, DefaultSPStorage> p12;
|
||||
typedef SmartPtr<TestClass, DestructiveCopy, AllowConversion, AssertCheck, DefaultSPStorage> p13;
|
||||
typedef SmartPtr<TestClass, NoCopy, AllowConversion, AssertCheck, DefaultSPStorage> p14;
|
||||
typedef SmartPtr<TestClass, NoCopy, AllowConversion, AssertCheck, DefaultSPStorage> p15;
|
||||
|
||||
typedef SmartPtr<TestClass, DeepCopy, DisallowConversion, AssertCheckStrict, DefaultSPStorage> p16;
|
||||
typedef SmartPtr<TestClass, RefCounted, DisallowConversion, AssertCheckStrict, DefaultSPStorage> p17;
|
||||
//typedef SmartPtr<TestClass, RefCountedMT, DisallowConversion, AssertCheckStrict, DefaultSPStorage> p18;
|
||||
typedef SmartPtr<TestClass, COMRefCounted, DisallowConversion, AssertCheckStrict, DefaultSPStorage> p19;
|
||||
typedef SmartPtr<TestClass, RefLinked, DisallowConversion, AssertCheckStrict, DefaultSPStorage> p20;
|
||||
typedef SmartPtr<TestClass, DestructiveCopy, DisallowConversion, AssertCheckStrict, DefaultSPStorage> p21;
|
||||
typedef SmartPtr<TestClass, NoCopy, DisallowConversion, AssertCheckStrict, DefaultSPStorage> p22;
|
||||
typedef SmartPtr<TestClass, NoCopy, DisallowConversion, AssertCheckStrict, DefaultSPStorage> p23;
|
||||
|
||||
typedef SmartPtr<TestClass, DeepCopy, AllowConversion, AssertCheckStrict, DefaultSPStorage> p24;
|
||||
typedef SmartPtr<TestClass, RefCounted, AllowConversion, AssertCheckStrict, DefaultSPStorage> p25;
|
||||
//typedef SmartPtr<TestClass, RefCountedMT, AllowConversion, AssertCheckStrict, DefaultSPStorage> p26;
|
||||
typedef SmartPtr<TestClass, COMRefCounted, AllowConversion, AssertCheckStrict, DefaultSPStorage> p27;
|
||||
typedef SmartPtr<TestClass, RefLinked, AllowConversion, AssertCheckStrict, DefaultSPStorage> p28;
|
||||
typedef SmartPtr<TestClass, DestructiveCopy, AllowConversion, AssertCheckStrict, DefaultSPStorage> p29;
|
||||
typedef SmartPtr<TestClass, NoCopy, AllowConversion, AssertCheckStrict, DefaultSPStorage> p30;
|
||||
typedef SmartPtr<TestClass, NoCopy, AllowConversion, AssertCheckStrict, DefaultSPStorage> p31;
|
||||
|
||||
typedef SmartPtr<TestClass, DeepCopy, AllowConversion, RejectNullStatic, DefaultSPStorage> p40;
|
||||
typedef SmartPtr<TestClass, RefCounted, AllowConversion, RejectNullStatic, DefaultSPStorage> p41;
|
||||
//typedef SmartPtr<TestClass, RefCountedMT, AllowConversion, RejectNullStatic, DefaultSPStorage> p42;
|
||||
typedef SmartPtr<TestClass, COMRefCounted, AllowConversion, RejectNullStatic, DefaultSPStorage> p43;
|
||||
typedef SmartPtr<TestClass, RefLinked, AllowConversion, RejectNullStatic, DefaultSPStorage> p44;
|
||||
typedef SmartPtr<TestClass, DestructiveCopy, AllowConversion, RejectNullStatic, DefaultSPStorage> p45;
|
||||
typedef SmartPtr<TestClass, NoCopy, AllowConversion, RejectNullStatic, DefaultSPStorage> p46;
|
||||
typedef SmartPtr<TestClass, NoCopy, AllowConversion, RejectNullStatic, DefaultSPStorage> p47;
|
||||
|
||||
typedef SmartPtr<TestClass, DeepCopy, DisallowConversion, RejectNullStatic, DefaultSPStorage> p48;
|
||||
typedef SmartPtr<TestClass, RefCounted, DisallowConversion, RejectNullStatic, DefaultSPStorage> p49;
|
||||
//typedef SmartPtr<TestClass, RefCountedMT, DisallowConversion, RejectNullStatic, DefaultSPStorage> p50;
|
||||
typedef SmartPtr<TestClass, COMRefCounted, DisallowConversion, RejectNullStatic, DefaultSPStorage> p51;
|
||||
typedef SmartPtr<TestClass, RefLinked, DisallowConversion, RejectNullStatic, DefaultSPStorage> p52;
|
||||
typedef SmartPtr<TestClass, DestructiveCopy, DisallowConversion, RejectNullStatic, DefaultSPStorage> p53;
|
||||
typedef SmartPtr<TestClass, NoCopy, DisallowConversion, RejectNullStatic,DefaultSPStorage> p54;
|
||||
typedef SmartPtr<TestClass, NoCopy, DisallowConversion, RejectNullStatic,DefaultSPStorage> p55;
|
||||
|
||||
typedef SmartPtr<TestClass, DeepCopy, AllowConversion, RejectNull, DefaultSPStorage> p56;
|
||||
typedef SmartPtr<TestClass, RefCounted, AllowConversion, RejectNull, DefaultSPStorage> p57;
|
||||
//typedef SmartPtr<TestClass, RefCountedMT, AllowConversion, RejectNull, DefaultSPStorage> p58;
|
||||
typedef SmartPtr<TestClass, COMRefCounted, AllowConversion, RejectNull, DefaultSPStorage> p59;
|
||||
typedef SmartPtr<TestClass, RefLinked, AllowConversion, RejectNull, DefaultSPStorage> p60;
|
||||
typedef SmartPtr<TestClass, DestructiveCopy, AllowConversion, RejectNull, DefaultSPStorage> p61;
|
||||
typedef SmartPtr<TestClass, NoCopy, AllowConversion, RejectNull, DefaultSPStorage> p62;
|
||||
typedef SmartPtr<TestClass, NoCopy, AllowConversion, RejectNull, DefaultSPStorage> p63;
|
||||
|
||||
typedef SmartPtr<TestClass, DeepCopy, DisallowConversion, RejectNull, DefaultSPStorage> p64;
|
||||
typedef SmartPtr<TestClass, RefCounted, DisallowConversion, RejectNull, DefaultSPStorage> p65;
|
||||
//typedef SmartPtr<TestClass, RefCountedMT, DisallowConversion, RejectNull, DefaultSPStorage> p66;
|
||||
typedef SmartPtr<TestClass, COMRefCounted, DisallowConversion, RejectNull, DefaultSPStorage> p67;
|
||||
typedef SmartPtr<TestClass, RefLinked, DisallowConversion, RejectNull, DefaultSPStorage> p68;
|
||||
typedef SmartPtr<TestClass, DestructiveCopy, DisallowConversion, RejectNull, DefaultSPStorage> p69;
|
||||
typedef SmartPtr<TestClass, NoCopy, DisallowConversion, RejectNull, DefaultSPStorage> p70;
|
||||
typedef SmartPtr<TestClass, NoCopy, DisallowConversion, RejectNull, DefaultSPStorage> p71;
|
||||
|
||||
typedef SmartPtr<TestClass, DeepCopy, AllowConversion, RejectNullStrict, DefaultSPStorage> p72;
|
||||
typedef SmartPtr<TestClass, RefCounted, AllowConversion, RejectNullStrict, DefaultSPStorage> p73;
|
||||
//typedef SmartPtr<TestClass, RefCountedMT, AllowConversion, RejectNullStrict, DefaultSPStorage> p74;
|
||||
typedef SmartPtr<TestClass, COMRefCounted, AllowConversion, RejectNullStrict, DefaultSPStorage> p75;
|
||||
typedef SmartPtr<TestClass, RefLinked, AllowConversion, RejectNullStrict, DefaultSPStorage> p76;
|
||||
typedef SmartPtr<TestClass, DestructiveCopy, AllowConversion, RejectNullStrict, DefaultSPStorage> p77;
|
||||
typedef SmartPtr<TestClass, NoCopy, AllowConversion, RejectNullStrict, DefaultSPStorage> p78;
|
||||
typedef SmartPtr<TestClass, NoCopy, AllowConversion, RejectNullStrict, DefaultSPStorage> p79;
|
||||
|
||||
typedef SmartPtr<TestClass, DeepCopy, DisallowConversion, RejectNullStrict, DefaultSPStorage> p80;
|
||||
typedef SmartPtr<TestClass, RefCounted, DisallowConversion, RejectNullStrict, DefaultSPStorage> p81;
|
||||
//typedef SmartPtr<TestClass, RefCountedMT, DisallowConversion, RejectNullStrict, DefaultSPStorage> p82;
|
||||
typedef SmartPtr<TestClass, COMRefCounted, DisallowConversion, RejectNullStrict, DefaultSPStorage> p83;
|
||||
typedef SmartPtr<TestClass, RefLinked, DisallowConversion, RejectNullStrict, DefaultSPStorage> p84;
|
||||
typedef SmartPtr<TestClass, DestructiveCopy, DisallowConversion, RejectNullStrict, DefaultSPStorage> p85;
|
||||
typedef SmartPtr<TestClass, NoCopy, DisallowConversion, RejectNullStrict, DefaultSPStorage> p86;
|
||||
typedef SmartPtr<TestClass, NoCopy, DisallowConversion, RejectNullStrict, DefaultSPStorage> p87;
|
||||
|
||||
typedef SmartPtr<TestClass, DeepCopy, AllowConversion, NoCheck, DefaultSPStorage> p88;
|
||||
typedef SmartPtr<TestClass, RefCounted, AllowConversion, NoCheck, DefaultSPStorage> p89;
|
||||
//typedef SmartPtr<TestClass, RefCountedMT, AllowConversion, NoCheck, DefaultSPStorage> p90;
|
||||
typedef SmartPtr<TestClass, COMRefCounted, AllowConversion, NoCheck, DefaultSPStorage> p91;
|
||||
typedef SmartPtr<TestClass, RefLinked, AllowConversion, NoCheck, DefaultSPStorage> p92;
|
||||
typedef SmartPtr<TestClass, DestructiveCopy, AllowConversion, NoCheck, DefaultSPStorage> p93;
|
||||
typedef SmartPtr<TestClass, NoCopy, AllowConversion, NoCheck, DefaultSPStorage> p94;
|
||||
typedef SmartPtr<TestClass, NoCopy, AllowConversion, NoCheck, DefaultSPStorage> p95;
|
||||
|
||||
typedef SmartPtr<TestClass, DeepCopy, DisallowConversion, NoCheck, DefaultSPStorage> p96;
|
||||
typedef SmartPtr<TestClass, RefCounted, DisallowConversion, NoCheck, DefaultSPStorage> p97;
|
||||
//typedef SmartPtr<TestClass, RefCountedMT, DisallowConversion, NoCheck, DefaultSPStorage> p98;
|
||||
typedef SmartPtr<TestClass, COMRefCounted, DisallowConversion, NoCheck, DefaultSPStorage> p99;
|
||||
typedef SmartPtr<TestClass, RefLinked, DisallowConversion, NoCheck, DefaultSPStorage> p100;
|
||||
typedef SmartPtr<TestClass, DestructiveCopy, DisallowConversion, NoCheck, DefaultSPStorage> p101;
|
||||
typedef SmartPtr<TestClass, NoCopy, DisallowConversion, NoCheck, DefaultSPStorage> p102;
|
||||
typedef SmartPtr<TestClass, NoCopy, DisallowConversion, NoCheck, DefaultSPStorage> p103;
|
||||
};
|
||||
|
||||
#endif
|
32
tools/RegressionTest/Test.cpp
Normal file
32
tools/RegressionTest/Test.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifdef __INTEL_COMPILER
|
||||
# pragma warning(disable: 111 193 304 383 444 488 981 1418)
|
||||
#endif
|
||||
|
||||
#include "LokiTest.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
LokiTest test;
|
||||
|
||||
const int result=test.result();
|
||||
|
||||
#if __BORLANDC__ || __GNUC__
|
||||
while(true); // Stop console window from closing if run from IDE.
|
||||
#endif
|
||||
|
||||
return result;
|
||||
}
|
119
tools/RegressionTest/TypeManipTest.h
Normal file
119
tools/RegressionTest/TypeManipTest.h
Normal file
|
@ -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 <Loki/TypeManip.h>
|
||||
#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<Type2Type<char>::OriginalType,char>::value;
|
||||
|
||||
testAssert("Type2Type",r,result);
|
||||
|
||||
r=SameType<Select<true,char,int>::Result,char>::value &&
|
||||
SameType<Select<false,char,int>::Result,int>::value;
|
||||
|
||||
testAssert("Select",r,result);
|
||||
|
||||
r=Conversion<char,int>::exists &&
|
||||
Conversion<char,int>::exists2Way &&
|
||||
!Conversion<char,int>::sameType &&
|
||||
Conversion<char,char>::exists &&
|
||||
Conversion<char,char>::exists2Way &&
|
||||
Conversion<char,char>::sameType &&
|
||||
Conversion<void,void>::exists &&
|
||||
!Conversion<void,char>::exists &&
|
||||
Conversion<char,void>::exists &&
|
||||
Conversion<Derived2,Base>::exists &&
|
||||
Conversion<Derived1,Base>::exists &&
|
||||
Conversion<Base,Base>::exists &&
|
||||
!Conversion<Base,Derived2>::exists &&
|
||||
!Conversion<Base,Derived1>::exists &&
|
||||
Conversion<Derived2 *,Base *>::exists &&
|
||||
Conversion<Derived1 *,Base *>::exists &&
|
||||
!Conversion<Base *,Derived2 *>::exists &&
|
||||
!Conversion<Base *,Derived1 *>::exists &&
|
||||
Conversion<Base *,void *>::exists &&
|
||||
!Conversion<void *,Base *>::exists;
|
||||
|
||||
testAssert("Conversion",r,result);
|
||||
|
||||
r=SuperSubclass<Base,Derived1>::value &&
|
||||
SuperSubclass<Base,Derived2>::value &&
|
||||
SuperSubclass<Base,Base>::value &&
|
||||
!SuperSubclass<Derived1,Base>::value &&
|
||||
!SuperSubclass<Derived2,Base>::value &&
|
||||
!SuperSubclass<void,Base>::value;
|
||||
|
||||
testAssert("SuperSubclass",r,result);
|
||||
|
||||
r=SuperSubclassStrict<Base,Derived1>::value &&
|
||||
SuperSubclassStrict<Base,Derived2>::value &&
|
||||
!SuperSubclassStrict<Base,Base>::value &&
|
||||
!SuperSubclassStrict<Derived1,Base>::value &&
|
||||
!SuperSubclassStrict<Derived2,Base>::value &&
|
||||
!SuperSubclassStrict<void,Base>::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; };
|
||||
};
|
||||
|
||||
#endif
|
116
tools/RegressionTest/TypeTraitsTest.h
Normal file
116
tools/RegressionTest/TypeTraitsTest.h
Normal file
|
@ -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 <Loki/TypeTraits.h>
|
||||
#include "UnitTest.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// TypeTraitsTest
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class TypeTraitsTest : public Test
|
||||
{
|
||||
public:
|
||||
TypeTraitsTest() : Test("TypeTraits.h") {}
|
||||
|
||||
virtual void execute(TestResult &result)
|
||||
{
|
||||
printName(result);
|
||||
|
||||
using namespace Loki;
|
||||
|
||||
bool r;
|
||||
|
||||
r=TypeTraits<int *>::isPointer &&
|
||||
!TypeTraits<int>::isPointer &&
|
||||
SameType<TypeTraits<int *>::PointeeType,int>::value &&
|
||||
SameType<TypeTraits<int>::PointeeType,NullType>::value &&
|
||||
|
||||
TypeTraits<int &>::isReference &&
|
||||
!TypeTraits<int>::isReference &&
|
||||
SameType<TypeTraits<int &>::ReferredType,int>::value &&
|
||||
SameType<TypeTraits<int>::ReferredType,int>::value &&
|
||||
|
||||
TypeTraits<int Test::*>::isMemberPointer &&
|
||||
!TypeTraits<int>::isMemberPointer &&
|
||||
|
||||
TypeTraits<unsigned int>::isStdUnsignedInt &&
|
||||
!TypeTraits<int>::isStdUnsignedInt &&
|
||||
|
||||
TypeTraits<int>::isStdSignedInt &&
|
||||
!TypeTraits<unsigned int>::isStdSignedInt &&
|
||||
|
||||
TypeTraits<int>::isStdIntegral &&
|
||||
!TypeTraits<double>::isStdIntegral &&
|
||||
|
||||
TypeTraits<double>::isStdFloat &&
|
||||
!TypeTraits<int>::isStdFloat &&
|
||||
|
||||
TypeTraits<int>::isStdArith &&
|
||||
!TypeTraits<void>::isStdArith &&
|
||||
|
||||
TypeTraits<void>::isStdFundamental &&
|
||||
!TypeTraits<Test>::isStdFundamental &&
|
||||
|
||||
TypeTraits<unsigned int>::isUnsignedInt &&
|
||||
!TypeTraits<int>::isUnsignedInt &&
|
||||
|
||||
TypeTraits<int>::isSignedInt &&
|
||||
!TypeTraits<unsigned int>::isSignedInt &&
|
||||
|
||||
TypeTraits<int>::isIntegral &&
|
||||
!TypeTraits<double>::isIntegral &&
|
||||
|
||||
TypeTraits<double>::isFloat &&
|
||||
!TypeTraits<int>::isFloat &&
|
||||
|
||||
TypeTraits<char>::isArith &&
|
||||
TypeTraits<int>::isArith &&
|
||||
TypeTraits<double>::isArith &&
|
||||
!TypeTraits<void>::isArith &&
|
||||
|
||||
TypeTraits<void>::isFundamental &&
|
||||
!TypeTraits<Test>::isFundamental &&
|
||||
|
||||
#ifndef __BORLANDC__
|
||||
|
||||
TypeTraits<const int>::isConst &&
|
||||
!TypeTraits<int>::isConst &&
|
||||
SameType<TypeTraits<const int>::NonConstType,int>::value &&
|
||||
SameType<TypeTraits<int>::NonConstType,int>::value &&
|
||||
|
||||
TypeTraits<volatile int>::isVolatile &&
|
||||
!TypeTraits<int>::isVolatile &&
|
||||
SameType<TypeTraits<volatile int>::NonVolatileType,int>::value &&
|
||||
SameType<TypeTraits<int>::NonVolatileType,int>::value &&
|
||||
|
||||
SameType<TypeTraits<const volatile int>::UnqualifiedType,int>::value &&
|
||||
|
||||
#endif
|
||||
|
||||
SameType<TypeTraits<char>::ParameterType,char>::value &&
|
||||
SameType<TypeTraits<int>::ParameterType,int>::value &&
|
||||
SameType<TypeTraits<double>::ParameterType,double>::value &&
|
||||
SameType<TypeTraits<Test>::ParameterType,Test &>::value;
|
||||
|
||||
testAssert("TypeTraits",r,result);
|
||||
|
||||
std::cout << '\n';
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
190
tools/RegressionTest/TypelistTest.h
Normal file
190
tools/RegressionTest/TypelistTest.h
Normal file
|
@ -0,0 +1,190 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <Loki/Typelist.h>
|
||||
#include "UnitTest.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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<NullType>::value==0 &&
|
||||
Length<CharList>::value==1 &&
|
||||
Length<CharIntDoubleList>::value==3;
|
||||
|
||||
testAssert("Length",r,result);
|
||||
|
||||
r=SameType<TypeAt<CharList,0>::Result,char>::value &&
|
||||
SameType<TypeAt<CharIntDoubleList,2>::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<TypeAtNonStrict<NullType,0>::Result,NullType>::value &&
|
||||
SameType<TypeAtNonStrict<CharList,0>::Result,char>::value &&
|
||||
SameType<TypeAtNonStrict<CharIntDoubleList,2>::Result,double>::value &&
|
||||
SameType<TypeAtNonStrict<CharIntDoubleList,3>::Result,NullType>::value &&
|
||||
SameType<TypeAtNonStrict<CharList,1,long>::Result,long>::value;
|
||||
|
||||
testAssert("TypeAtNonStrict",r,result);
|
||||
|
||||
#else
|
||||
|
||||
testAssert("TypeAtNonStrict",false,result,false);
|
||||
|
||||
#endif
|
||||
|
||||
r=IndexOf<NullType,char>::value==-1 &&
|
||||
IndexOf<CharList,char>::value==0 &&
|
||||
IndexOf<CharIntDoubleList,double>::value==2 &&
|
||||
IndexOf<CharIntDoubleList,long>::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<Append<NullType,NullType>::Result,NullType>::value &&
|
||||
SameType<Append<NullType,char>::Result,TYPELIST_1(char)>::value &&
|
||||
SameType<Append<NullType,CharList>::Result,CharList>::value &&
|
||||
SameType<Append<CharList,NullType>::Result,CharList>::value &&
|
||||
SameType<Append<CharList,int>::Result,TYPELIST_2(char,int)>::value &&
|
||||
SameType<Append<CharList,CharIntDoubleList>::Result,TYPELIST_4(char,char,int,double)>::value;
|
||||
|
||||
testAssert("Append",r,result);
|
||||
|
||||
r=SameType<Erase<NullType,char>::Result,NullType>::value &&
|
||||
SameType<Erase<CharList,char>::Result,NullType>::value &&
|
||||
SameType<Erase<CharList,long>::Result,CharList>::value &&
|
||||
SameType<Erase<CharIntDoubleList,int>::Result,TYPELIST_2(char,double)>::value &&
|
||||
SameType<Erase<CharIntDoubleList,double>::Result,TYPELIST_2(char,int)>::value;
|
||||
|
||||
testAssert("Erase",r,result);
|
||||
|
||||
r=SameType<EraseAll<NullType,char>::Result,NullType>::value &&
|
||||
SameType<EraseAll<CharList,char>::Result,NullType>::value &&
|
||||
SameType<EraseAll<CharList,long>::Result,CharList>::value &&
|
||||
SameType<EraseAll<CharIntDoubleList,int>::Result,TYPELIST_2(char,double)>::value &&
|
||||
SameType<EraseAll<CharIntDoubleList,double>::Result,TYPELIST_2(char,int)>::value &&
|
||||
SameType<EraseAll<CharIntDoubleCharList,char>::Result,TYPELIST_2(int,double)>::value &&
|
||||
SameType<EraseAll<CharIntDoubleCharList,int>::Result,TYPELIST_3(char,double,char)>::value &&
|
||||
SameType<EraseAll<CharIntDoubleCharList,double>::Result,TYPELIST_3(char,int,char)>::value;
|
||||
|
||||
testAssert("EraseAll",r,result);
|
||||
|
||||
r=SameType<NoDuplicates<NullType>::Result,NullType>::value &&
|
||||
SameType<NoDuplicates<CharList>::Result,CharList>::value &&
|
||||
SameType<NoDuplicates<CharIntDoubleList>::Result,CharIntDoubleList>::value &&
|
||||
SameType<NoDuplicates<CharIntDoubleCharList>::Result,CharIntDoubleList>::value;
|
||||
|
||||
testAssert("NoDuplicates",r,result);
|
||||
|
||||
r=SameType<Replace<NullType,char,long>::Result,NullType>::value &&
|
||||
SameType<Replace<CharList,char,long>::Result,TYPELIST_1(long)>::value &&
|
||||
SameType<Replace<CharList,int,long>::Result,CharList>::value &&
|
||||
SameType<Replace<CharIntDoubleList,char,long>::Result,TYPELIST_3(long,int,double)>::value &&
|
||||
SameType<Replace<CharIntDoubleList,long,char[16]>::Result,CharIntDoubleList>::value &&
|
||||
SameType<Replace<CharIntDoubleCharList,char,long>::Result,TYPELIST_4(long,int,double,char)>::value;
|
||||
|
||||
testAssert("Replace",r,result);
|
||||
|
||||
r=SameType<ReplaceAll<NullType,char,long>::Result,NullType>::value &&
|
||||
SameType<ReplaceAll<CharList,char,long>::Result,TYPELIST_1(long)>::value &&
|
||||
SameType<ReplaceAll<CharList,int,long>::Result,CharList>::value &&
|
||||
SameType<ReplaceAll<CharIntDoubleList,char,long>::Result,TYPELIST_3(long,int,double)>::value &&
|
||||
SameType<ReplaceAll<CharIntDoubleList,long,char[16]>::Result,CharIntDoubleList>::value &&
|
||||
SameType<ReplaceAll<CharIntDoubleCharList,char,long>::Result,TYPELIST_4(long,int,double,long)>::value;
|
||||
|
||||
testAssert("ReplaceAll",r,result);
|
||||
|
||||
r=SameType<Reverse<NullType>::Result,NullType>::value &&
|
||||
SameType<Reverse<CharList>::Result,CharList>::value &&
|
||||
SameType<Reverse<CharIntDoubleList>::Result,TYPELIST_3(double,int,char)>::value;
|
||||
|
||||
testAssert("Reverse",r,result);
|
||||
|
||||
r=SameType<MostDerived<NullType,Base>::Result,Base>::value &&
|
||||
SameType<MostDerived<BaseDerived1Derived2List,Base>::Result,Derived2>::value &&
|
||||
SameType<MostDerived<BaseDerived1Derived2List,Derived1>::Result,Derived2>::value &&
|
||||
SameType<MostDerived<BaseDerived1Derived2List,Derived2>::Result,Derived2>::value &&
|
||||
SameType<MostDerived<Derived2Derived1BaseList,Base>::Result,Derived2>::value &&
|
||||
SameType<MostDerived<Derived2Derived1BaseList,Derived1>::Result,Derived2>::value &&
|
||||
SameType<MostDerived<Derived2Derived1BaseList,Derived2>::Result,Derived2>::value;
|
||||
|
||||
testAssert("MostDerived",r,result);
|
||||
|
||||
r=SameType<DerivedToFront<NullType>::Result,NullType>::value &&
|
||||
SameType<DerivedToFront<CharList>::Result,CharList>::value &&
|
||||
SameType<DerivedToFront<CharIntDoubleList>::Result,CharIntDoubleList>::value &&
|
||||
SameType<DerivedToFront<CharIntDoubleCharList>::Result,CharIntDoubleCharList>::value &&
|
||||
SameType<DerivedToFront<BaseDerived1Derived2List>::Result,Derived2Derived1BaseList>::value &&
|
||||
SameType<DerivedToFront<Derived2Derived1BaseList>::Result,Derived2Derived1BaseList>::value &&
|
||||
SameType<DerivedToFront<BaseDerived1BaseDerived2List>::Result,TYPELIST_4(Derived2,Derived1,Base,Base)>::value &&
|
||||
SameType<DerivedToFront<Derived1BaseDerived1Derived2List>::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; };
|
||||
};
|
||||
|
||||
#endif
|
208
tools/RegressionTest/UnitTest.h
Normal file
208
tools/RegressionTest/UnitTest.h
Normal file
|
@ -0,0 +1,208 @@
|
|||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// SameType
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#if _MSC_VER && !__INTEL_COMPILER && !__MWERKS__
|
||||
|
||||
// Rani Sharoni's SameType
|
||||
|
||||
template<class T1,class T2>
|
||||
struct SameType
|
||||
{
|
||||
private:
|
||||
template<class>
|
||||
struct In
|
||||
{ enum { value = false }; };
|
||||
|
||||
template<>
|
||||
struct In<T1>
|
||||
{ enum { value = true }; };
|
||||
|
||||
public:
|
||||
enum { value = In<T2>::value };
|
||||
};
|
||||
|
||||
#else
|
||||
|
||||
template<class T1,class T2>
|
||||
struct SameType
|
||||
{
|
||||
static const bool value=false;
|
||||
};
|
||||
|
||||
template<class T>
|
||||
struct SameType<T,T>
|
||||
{
|
||||
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
|
||||
{
|
||||
public:
|
||||
explicit Test(const std::string &n) : name(n) {}
|
||||
|
||||
virtual void execute(TestResult &) =0;
|
||||
|
||||
protected:
|
||||
~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;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// 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
|
||||
{
|
||||
std::cout << title << std::string(Test::offset-title.length(),' ') << "Result\n";
|
||||
std::cout << std::string(76,'-') << '\n';
|
||||
|
||||
TestResult testResult;
|
||||
|
||||
tests.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
|
Loading…
Add table
Reference in a new issue