diff --git a/alib2/src/std/itos.cpp b/alib2/src/std/itos.cpp new file mode 100644 index 0000000000000000000000000000000000000000..66423b21812b9fca3b5a623ad9755f242c7ac0d8 --- /dev/null +++ b/alib2/src/std/itos.cpp @@ -0,0 +1,11 @@ +#include "itos.h" + +namespace std { + +string itos(int integer, int) { + stringstream ss; + ss << integer; + return ss.str(); +} + +} diff --git a/alib2/src/std/itos.h b/alib2/src/std/itos.h new file mode 100644 index 0000000000000000000000000000000000000000..219df670d0d0f69f8b0216b52c52d47f05df6179 --- /dev/null +++ b/alib2/src/std/itos.h @@ -0,0 +1,13 @@ +#ifndef ITOS_H_ +#define ITOS_H_ + +#include <sstream> +#include <string> + +namespace std { + +string itos(int integer, int base = 10); + +} /* namespace std */ + +#endif /* ITOS_H_ */ diff --git a/alib2/test-src/std/TypeInfoTest.cpp b/alib2/test-src/std/TypeInfoTest.cpp new file mode 100644 index 0000000000000000000000000000000000000000..79d72e95f5bc85e52179361f0bc8d9ec247dcdff --- /dev/null +++ b/alib2/test-src/std/TypeInfoTest.cpp @@ -0,0 +1,66 @@ +#include "TypeInfoTest.h" +#include <string> +#include <iostream> + +#define CPPUNIT_EXCLUSIVE_OR(x, y) CPPUNIT_ASSERT((!(x) && (y)) || ((x) && !(y))) + +CPPUNIT_TEST_SUITE_REGISTRATION( TypeInfoTest ); + +void TypeInfoTest::setUp() { +} + +void TypeInfoTest::tearDown() { +} + +void TypeInfoTest::testTypeInfo() { + Child1 c1; + Child2 c2; + + Child1& c1r = c1; + Child2& c2r = c2; + + Base& c1br = c1r; + Base& c2br = c2r; + + Child1* c1p = &c1; + Child2* c2p = &c2; + + Base* c1bp = c1p; + Base* c2bp = c2p; + + const std::type_info& c1Type = typeid(c1); + const std::type_info& c2Type = typeid(c2); + + const std::type_info& c1rType = typeid(c1r); + const std::type_info& c2rType = typeid(c2r); + + const std::type_info& c1brType = typeid(c1br); + const std::type_info& c2brType = typeid(c2br); + + const std::type_info& c1pType = typeid(c1p); + const std::type_info& c2pType = typeid(c2p); + + const std::type_info& c1bpType = typeid(c1bp); + const std::type_info& c2bpType = typeid(c2bp); + +/* std::cout << c1Type.name() << " " << c2Type.name() << std::endl; + std::cout << c1rType.name() << " " << c2rType.name() << std::endl; + std::cout << c1brType.name() << " " << c2brType.name() << std::endl; + std::cout << c1pType.name() << " " << c2pType.name() << std::endl; + std::cout << c1bpType.name() << " " << c2bpType.name() << std::endl;*/ + + CPPUNIT_EXCLUSIVE_OR(c1Type.before (c2Type ), c2Type.before (c1Type )); + CPPUNIT_EXCLUSIVE_OR(c1rType.before (c2rType ), c2rType.before (c1rType )); + CPPUNIT_EXCLUSIVE_OR(c1brType.before(c2brType), c2brType.before(c1brType)); + CPPUNIT_EXCLUSIVE_OR(c1pType.before (c2pType ), c2pType.before (c1pType )); + CPPUNIT_ASSERT(c1bpType == c2bpType); + + CPPUNIT_ASSERT(c1Type == c1rType); + CPPUNIT_ASSERT(c1Type == c1brType); + CPPUNIT_ASSERT(c1Type != c1pType); + CPPUNIT_ASSERT(c1Type != c1bpType); + CPPUNIT_ASSERT(c2Type == c2rType); + CPPUNIT_ASSERT(c2Type == c2brType); + CPPUNIT_ASSERT(c2Type != c2pType); + CPPUNIT_ASSERT(c2Type != c2bpType); +} diff --git a/alib2/test-src/std/TypeInfoTest.h b/alib2/test-src/std/TypeInfoTest.h new file mode 100644 index 0000000000000000000000000000000000000000..1a2d4cb0e13afeb5b76262b3f348df3b072988fa --- /dev/null +++ b/alib2/test-src/std/TypeInfoTest.h @@ -0,0 +1,30 @@ +#ifndef TYPE_INFO_TEST_H_ +#define TYPE_INFO_TEST_H_ + +#include <cppunit/extensions/HelperMacros.h> + +class TypeInfoTest : public CppUnit::TestFixture +{ + CPPUNIT_TEST_SUITE( TypeInfoTest ); + CPPUNIT_TEST( testTypeInfo ); + CPPUNIT_TEST_SUITE_END(); + + class Base { + public: + virtual ~Base() {} + }; + + class Child1 : public Base { + }; + + class Child2 : public Base { + }; + +public: + void setUp(); + void tearDown(); + + void testTypeInfo(); +}; + +#endif // TYPE_INFO_TEST_H_