#include #include #include #include #include #include #include #include #include "common.h" #include "OrderedMapTest.h" #include "VectorMapTest.h" // That's how it should work, if we had a working compiler. /* template struct PairTestBase { typedef SimpleValueStrategy KeyStrategy; typedef SimpleValueStrategy ValueStrategy; typedef PairEntryStrategy EntryStrategy; template struct MyMap : public VectorMap > { }; template struct Strategy : public TestStrategy { }; }; typedef typename PairTestBase::Strategy IntIntTestStrategy; // ... */ // ugly work-around: template struct PairTestBase { typedef SimpleValueStrategy KeyStrategy; typedef SimpleValueStrategy ValueStrategy; typedef PairEntryStrategy EntryStrategy; template struct MyMap : public VectorMap > { }; }; #define DECLARE_TEST_STRATEGY(Key, Value, Map, Strategy, ClassName) \ template struct Map : PairTestBase::MyMap {};\ template \ struct Strategy \ : public TestStrategy::EntryStrategy, \ CS> { \ static const char *kClassName; \ }; \ template const char *Strategy::kClassName = ClassName; DECLARE_TEST_STRATEGY(int, int, IntIntMap, IntIntTestStrategy, "VectorMap") DECLARE_TEST_STRATEGY(int, string, IntStringMap, IntStringTestStrategy, "VectorMap") DECLARE_TEST_STRATEGY(string, int, StringIntMap, StringIntTestStrategy, "VectorMap") DECLARE_TEST_STRATEGY(string, string, StringStringMap, StringStringTestStrategy, "VectorMap") // TestStrategy for the ImplicitKey entry strategy // string_hash (from the Dragon Book: a slightly modified hashpjw()) static inline int string_hash(const char *name) { uint32 h = 0; for (; *name; name++) { if (uint32 g = h & 0xf0000000) h ^= g >> 24; h = (h << 4) + *name; } return (int)h; } struct ImplicitKeyTestGetKey { int operator()(string value) const { return string_hash(value.c_str()); } }; template struct ImplicitKeyTestMap : public VectorMap > { }; typedef ImplicitKeyStrategy, SimpleValueStrategy, ImplicitKeyTestGetKey> ImplicitKeyTestEntryStrategy; template struct ImplicitKeyTestStrategy : public TestStrategy< ImplicitKeyTestMap, ImplicitKeyTestEntryStrategy, CompareStrategy> { static const char *kClassName; }; template const char *ImplicitKeyTestStrategy::kClassName = "VectorMap"; // constructor VectorMapTest::VectorMapTest(std::string name) : BTestCase(name) { } // Suite CppUnit::Test* VectorMapTest::Suite() { CppUnit::TestSuite *suite = new CppUnit::TestSuite("VectorMap"); suite->addTest(OrderedMapTest::Suite()); suite->addTest(OrderedMapTest::Suite()); suite->addTest(OrderedMapTest::Suite()); suite->addTest(OrderedMapTest::Suite()); suite->addTest(OrderedMapTest::Suite()); return suite; }