Skip to content
Snippets Groups Projects
Commit 715b5ee8 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

std tests, base implementation of itos

parent aed00fee
No related branches found
No related tags found
No related merge requests found
#include "itos.h"
namespace std {
string itos(int integer, int) {
stringstream ss;
ss << integer;
return ss.str();
}
}
#ifndef ITOS_H_
#define ITOS_H_
#include <sstream>
#include <string>
namespace std {
string itos(int integer, int base = 10);
} /* namespace std */
#endif /* ITOS_H_ */
#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);
}
#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_
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment