Increased Tuple capacity to 20 parameters; introduced TypeListType; added TypeListTest.cpp/.h

This commit is contained in:
Aleksandar Fabijanic
2007-02-21 00:23:09 +00:00
parent 421ada46a8
commit 605736b626
8 changed files with 2240 additions and 242 deletions

View File

@@ -1,7 +1,7 @@
//
// TuplesTest.cpp
//
// $Id: //poco/1.3/Foundation/testsuite/src/TuplesTest.cpp#2 $
// $Id: //poco/1.3/Foundation/testsuite/src/TuplesTest.cpp#1 $
//
// Copyright (c) 2006, Applied Informatics Software Engineering GmbH.
// and Contributors.
@@ -39,12 +39,29 @@
using Poco::TypeList;
using Poco::NullTypeList;
using Poco::TypeListType;
using Poco::TypeGetter;
using Poco::TypeLocator;
using Poco::TypeAppender;
using Poco::TypeEraser;
using Poco::TypeOneEraser;
using Poco::TypeAllEraser;
using Poco::TypeDuplicateEraser;
using Poco::TypeOneReplacer;
using Poco::TypeAllReplacer;
using Poco::Tuple;
using Poco::Void;
using Poco::Int8;
using Poco::UInt8;
using Poco::Int16;
using Poco::UInt16;
using Poco::Int32;
using Poco::UInt32;
using Poco::Int8;
using Poco::UInt8;
using Poco::Int16;
using Poco::UInt16;
using Poco::Int32;
using Poco::UInt32;
TuplesTest::TuplesTest(const std::string& name): CppUnit::TestCase(name)
@@ -57,7 +74,7 @@ TuplesTest::~TuplesTest()
}
void TuplesTest::testSimpleTuple()
void TuplesTest::testTuple1()
{
Tuple<int> t;
assert (t.length == 1);
@@ -87,7 +104,109 @@ void TuplesTest::testSimpleTuple()
}
void TuplesTest::testTupleSize5()
void TuplesTest::testTuple2()
{
Tuple<int, Void> dummy1;
assert (dummy1.length == 2);
dummy1.set<0>(-1);
assert (dummy1.get<0>() == -1);
//test partial init
Tuple<int, Void> dummy11(0);
Tuple<Void, int> dummy2;
dummy2.set<1>(-1);
assert (dummy2.get<1>() == -1);
Tuple<Void, int> dummy3;
dummy3.set<1>(-1);
assert (dummy3.get<1>() == -1);
Tuple<std::string, int> aTuple;
aTuple.set<0>("str");
aTuple.set<1>(1);
assert (aTuple.get<0>() == "str");
assert (aTuple.get<1>() == 1);
Tuple<std::string, int> aTuple2(aTuple);
assert (aTuple == aTuple2);
aTuple2.set<1>(99);
assert (aTuple != aTuple2);
aTuple2.set<1>(100000);
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple3()
{
Tuple<int, Void, Void> dummy1;
assert (dummy1.length == 3);
dummy1.set<0>(-1);
assert (dummy1.get<0>() == -1);
//test partial init
Tuple<int, Void, Void> dummy11(0);
Tuple<Void, int, Void> dummy2;
dummy2.set<1>(-1);
assert (dummy2.get<1>() == -1);
Tuple<Void, Void, int> dummy3;
dummy3.set<2>(-1);
assert (dummy3.get<2>() == -1);
Tuple<std::string, int, bool> aTuple;
aTuple.set<0>("str");
aTuple.set<1>(1);
aTuple.set<2>(true);
assert (aTuple.get<0>() == "str");
assert (aTuple.get<1>() == 1);
assert (aTuple.get<2>());
Tuple<std::string, int, bool> aTuple2(aTuple);
assert (aTuple == aTuple2);
aTuple2.set<2>(false);
assert (aTuple != aTuple2);
aTuple2.set<1>(100000);
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple4()
{
Tuple<int, Void, Void, Void> dummy1;
assert (dummy1.length == 4);
dummy1.set<0>(-1);
assert (dummy1.get<0>() == -1);
//test partial init
Tuple<int, Void, Void, Void> dummy11(0);
Tuple<Void, int, Void, Void> dummy2;
dummy2.set<1>(-1);
assert (dummy2.get<1>() == -1);
Tuple<Void, Void, Void, int> dummy3;
dummy3.set<3>(-1);
assert (dummy3.get<3>() == -1);
Tuple<std::string, int, bool, float> aTuple;
aTuple.set<0>("str");
aTuple.set<1>(1);
aTuple.set<2>(true);
aTuple.set<3>(3.14f);
assert (aTuple.get<0>() == "str");
assert (aTuple.get<1>() == 1);
assert (aTuple.get<2>());
assert (aTuple.get<3>() >= 3.13f && aTuple.get<3>() <= 3.15f);
Tuple<std::string, int, bool, float> aTuple2(aTuple);
assert (aTuple == aTuple2);
aTuple2.set<2>(false);
assert (aTuple != aTuple2);
aTuple2.set<1>(100000);
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple5()
{
Tuple<int, Void, Void, Void, Void> dummy1;
assert (dummy1.length == 5);
@@ -125,11 +244,229 @@ void TuplesTest::testTupleSize5()
}
void TuplesTest::testTupleSize10()
void TuplesTest::testTuple6()
{
Tuple<std::string, int, bool, float, char, long, double, short, std::string, int> aTuple;
Tuple<std::string, int, bool, float, char, long> aTuple;
assert (aTuple.length == 6);
Tuple<std::string, int, bool, float, char, long>
aTuple2("1", 1, true, 3.14f, 'c', 999);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple7()
{
Tuple<std::string, int, bool, float, char, long, double> aTuple;
assert (aTuple.length == 7);
Tuple<std::string, int, bool, float, char, long, double>
aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple8()
{
Tuple<std::string, int, bool, float, char, long, double, short> aTuple;
assert (aTuple.length == 8);
Tuple<std::string, int, bool, float, char, long, double, short>
aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple9()
{
Tuple<std::string, int, bool, float, char, long, double, short, std::string> aTuple;
assert (aTuple.length == 9);
Tuple<std::string, int, bool, float, char, long, double, short, std::string>
aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2");
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple10()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int> TupleType;
TupleType aTuple;
assert (aTuple.length == 10);
Tuple<std::string, int, bool, float, char, long, double, short, std::string, int> aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple11()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string> TupleType;
TupleType aTuple;
assert (aTuple.length == 11);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1");
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple12()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int> TupleType;
TupleType aTuple;
assert (aTuple.length == 12);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple13()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool> TupleType;
TupleType aTuple;
assert (aTuple.length == 13);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple14()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float> TupleType;
TupleType aTuple;
assert (aTuple.length == 14);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple15()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float, char> TupleType;
TupleType aTuple;
assert (aTuple.length == 15);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f, 'c');
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple16()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float, char, long> TupleType;
TupleType aTuple;
assert (aTuple.length == 16);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f, 'c', 999);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple17()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float, char, long, double> TupleType;
TupleType aTuple;
assert (aTuple.length == 17);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f, 'c', 999, 33.14);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple18()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float, char, long, double, short> TupleType;
TupleType aTuple;
assert (aTuple.length == 18);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f, 'c', 999, 33.14, 32700);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple19()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float, char, long, double, short, std::string> TupleType;
TupleType aTuple;
assert (aTuple.length == 19);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2");
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
aTuple2.get<1>()++;
assert (aTuple < aTuple2);
}
void TuplesTest::testTuple20()
{
typedef Tuple<std::string, int, bool, float, char, long, double, short, std::string, int,
std::string, int, bool, float, char, long, double, short, std::string, int> TupleType;
TupleType aTuple;
assert (aTuple.length == 20);
TupleType aTuple2("1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2, "1", 1, true, 3.14f, 'c', 999, 33.14, 32700, "2", 2);
assert (aTuple != aTuple2);
aTuple = aTuple2;
assert (aTuple == aTuple2);
@@ -145,114 +482,7 @@ void TuplesTest::testMemOverhead()
assert (sz == 4 || sz == 8); //depending on architecture and alignment
Tuple<long> notSoSmall(0);
sz = sizeof(notSoSmall);
assert (sz == 8);
}
void TuplesTest::testTypeList()
{
typedef TYPELIST_15(Poco::Int8,
Poco::UInt8,
Poco::Int16,
Poco::UInt16,
Poco::Int32,
Poco::UInt32,
float,
double,
Poco::Int8,
Poco::UInt8,
Poco::Int16,
Poco::UInt16,
Poco::Int32,
Poco::UInt32,
float) Type15;
TypeLocator<Type15, Poco::Int8> pos0; pos0;
TypeLocator<Type15, Poco::UInt8> pos1; pos1;
TypeLocator<Type15, Poco::Int16> pos2; pos2;
TypeLocator<Type15, Poco::UInt16> pos3; pos3;
TypeLocator<Type15, Poco::Int32> pos4; pos4;
TypeLocator<Type15, Poco::UInt32> pos5; pos5;
TypeLocator<Type15, float> pos6; pos6;
TypeLocator<Type15, double> pos7; pos7;
TypeLocator<Type15, Poco::Int8> pos8; pos8;
TypeLocator<Type15, std::string> posUnknown; posUnknown;
assert (pos0.value == 0);
assert (pos1.value == 1);
assert (pos2.value == 2);
assert (pos3.value == 3);
assert (pos4.value == 4);
assert (pos5.value == 5);
assert (pos6.value == 6);
assert (pos7.value == 7);
assert (pos8.value == 0);
assert (posUnknown.value == -1);
assert (typeid(TypeGetter<0, Type15>::HeadType) == typeid(Poco::Int8));
assert (typeid(TypeGetter<0, Type15>::ConstHeadType) == typeid(const Poco::Int8));
assert (typeid(TypeGetter<1, Type15>::HeadType) == typeid(Poco::UInt8));
assert (typeid(TypeGetter<1, Type15>::ConstHeadType) == typeid(const Poco::UInt8));
assert (typeid(TypeGetter<2, Type15>::HeadType) == typeid(Poco::Int16));
assert (typeid(TypeGetter<2, Type15>::ConstHeadType) == typeid(const Poco::Int16));
assert (typeid(TypeGetter<3, Type15>::HeadType) == typeid(Poco::UInt16));
assert (typeid(TypeGetter<3, Type15>::ConstHeadType) == typeid(const Poco::UInt16));
assert (typeid(TypeGetter<4, Type15>::HeadType) == typeid(Poco::Int32));
assert (typeid(TypeGetter<4, Type15>::ConstHeadType) == typeid(const Poco::Int32));
assert (typeid(TypeGetter<5, Type15>::HeadType) == typeid(Poco::UInt32));
assert (typeid(TypeGetter<5, Type15>::ConstHeadType) == typeid(const Poco::UInt32));
assert (typeid(TypeGetter<6, Type15>::HeadType) == typeid(float));
assert (typeid(TypeGetter<6, Type15>::ConstHeadType) == typeid(const float));
assert (typeid(TypeGetter<7, Type15>::HeadType) == typeid(double));
assert (typeid(TypeGetter<7, Type15>::ConstHeadType) == typeid(const double));
assert (typeid(TypeGetter<8, Type15>::HeadType) == typeid(Poco::Int8));
assert (typeid(TypeGetter<8, Type15>::ConstHeadType) == typeid(const Poco::Int8));
assert (typeid(TypeGetter<9, Type15>::HeadType) == typeid(Poco::UInt8));
assert (typeid(TypeGetter<9, Type15>::ConstHeadType) == typeid(const Poco::UInt8));
assert (typeid(TypeGetter<10, Type15>::HeadType) == typeid(Poco::Int16));
assert (typeid(TypeGetter<10, Type15>::ConstHeadType) == typeid(const Poco::Int16));
assert (typeid(TypeGetter<11, Type15>::HeadType) == typeid(Poco::UInt16));
assert (typeid(TypeGetter<11, Type15>::ConstHeadType) == typeid(const Poco::UInt16));
assert (typeid(TypeGetter<12, Type15>::HeadType) == typeid(Poco::Int32));
assert (typeid(TypeGetter<12, Type15>::ConstHeadType) == typeid(const Poco::Int32));
assert (typeid(TypeGetter<13, Type15>::HeadType) == typeid(Poco::UInt32));
assert (typeid(TypeGetter<13, Type15>::ConstHeadType) == typeid(const Poco::UInt32));
assert (typeid(TypeGetter<14, Type15>::HeadType) == typeid(float));
assert (typeid(TypeGetter<14, Type15>::ConstHeadType) == typeid(const float));
typedef TYPELIST_1(Poco::Int8) Type1;
assert (1 == Type1::length);
typedef TYPELIST_2(Poco::Int16, Poco::Int32) Type2;
assert (2 == Type2::length);
typedef TypeAppender<Type1, Type2>::HeadType Type3;
assert (3 == Type3::length);
assert (typeid(TypeGetter<0, Type3>::HeadType) == typeid(Poco::Int8));
assert (typeid(TypeGetter<1, Type3>::HeadType) == typeid(Poco::Int16));
assert (typeid(TypeGetter<2, Type3>::HeadType) == typeid(Poco::Int32));
TypeLocator<Type3, Poco::Int8> posNo1; posNo1;
TypeLocator<Type3, Poco::Int16> posNo2; posNo2;
TypeLocator<Type3, Poco::Int32> posNo3; posNo3;
assert (posNo1.value == 0);
assert (posNo2.value == 1);
assert (posNo3.value == 2);
typedef TypeEraser<Type3, Poco::Int8>::HeadType TypeEraser1;
assert (2 == TypeEraser1::length);
assert (typeid(TypeGetter<0, TypeEraser1>::HeadType) == typeid(Poco::Int16));
assert (typeid(TypeGetter<1, TypeEraser1>::HeadType) == typeid(Poco::Int32));
typedef TypeEraser<Type3, Poco::Int16>::HeadType TypeEraser2;
assert (2 == TypeEraser2::length);
assert (typeid(TypeGetter<0, TypeEraser2>::HeadType) == typeid(Poco::Int8));
assert (typeid(TypeGetter<1, TypeEraser2>::HeadType) == typeid(Poco::Int32));
typedef TypeEraser<Type3, Poco::Int32>::HeadType TypeEraser3;
assert (2 == TypeEraser3::length);
assert (typeid(TypeGetter<0, TypeEraser3>::HeadType) == typeid(Poco::Int8));
assert (typeid(TypeGetter<1, TypeEraser3>::HeadType) == typeid(Poco::Int16));
assert (sz == 8 || sz == 16); //depending on architecture and alignment
}
@@ -270,12 +500,27 @@ CppUnit::Test* TuplesTest::suite()
{
CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TuplesTest");
CppUnit_addTest(pSuite, TuplesTest, testSimpleTuple);
CppUnit_addTest(pSuite, TuplesTest, testTupleSize5);
CppUnit_addTest(pSuite, TuplesTest, testTupleSize10);
CppUnit_addTest(pSuite, TuplesTest, testTuple1);
CppUnit_addTest(pSuite, TuplesTest, testTuple2);
CppUnit_addTest(pSuite, TuplesTest, testTuple3);
CppUnit_addTest(pSuite, TuplesTest, testTuple4);
CppUnit_addTest(pSuite, TuplesTest, testTuple5);
CppUnit_addTest(pSuite, TuplesTest, testTuple6);
CppUnit_addTest(pSuite, TuplesTest, testTuple7);
CppUnit_addTest(pSuite, TuplesTest, testTuple8);
CppUnit_addTest(pSuite, TuplesTest, testTuple9);
CppUnit_addTest(pSuite, TuplesTest, testTuple10);
CppUnit_addTest(pSuite, TuplesTest, testTuple11);
CppUnit_addTest(pSuite, TuplesTest, testTuple12);
CppUnit_addTest(pSuite, TuplesTest, testTuple13);
CppUnit_addTest(pSuite, TuplesTest, testTuple14);
CppUnit_addTest(pSuite, TuplesTest, testTuple15);
CppUnit_addTest(pSuite, TuplesTest, testTuple16);
CppUnit_addTest(pSuite, TuplesTest, testTuple17);
CppUnit_addTest(pSuite, TuplesTest, testTuple18);
CppUnit_addTest(pSuite, TuplesTest, testTuple19);
CppUnit_addTest(pSuite, TuplesTest, testTuple20);
CppUnit_addTest(pSuite, TuplesTest, testMemOverhead);
CppUnit_addTest(pSuite, TuplesTest, testTypeList);
return pSuite;
}