private:
void load();
void contains();
+ void contains_base();
void contains_future();
void names();
+ void names_base();
void names_future();
void fetch();
void nonexistent();
void type_mismatch();
void create();
+ void list_future();
void name_collision();
};
class Sub: public Bar
{ };
+class Bus: public Bar
+{ };
+
class TestSource: public DataFile::CollectionSource
{
{
add(&CollectionTests::load, "Load objects");
add(&CollectionTests::contains, "Containment test");
+ add(&CollectionTests::contains_base, "Base class containment test");
add(&CollectionTests::contains_future, "Future containment test");
add(&CollectionTests::names, "List object names");
+ add(&CollectionTests::names_base, "List base class object names");
add(&CollectionTests::names_future, "List future object names");
add(&CollectionTests::fetch, "Fetch objects");
add(&CollectionTests::nonexistent, "Nonexistent object").expect_throw<key_error>();
add(&CollectionTests::type_mismatch, "Type mismatch").expect_throw<Msp::type_mismatch>();
add(&CollectionTests::create, "Create object");
+ add(&CollectionTests::list_future, "List future objects");
add(&CollectionTests::name_collision, "Name collision").expect_throw<Msp::key_error>();
collection = new TestCollection;
"foo \"a\" { tag 1; };\n"
"foo \"b\" { tag 2; };\n"
"bar \"c\" { tag 3; };\n"
- "sub \"d\" { tag 4; };\n";
+ "sub \"d\" { tag 4; };\n"
+ "bus \"e\" { tag 5; };\n";
IO::Memory mem(input, sizeof(input)-1);
DataFile::Parser parser(mem, "-");
EXPECT(!ccoll->contains<Foo>("c"));
}
+void CollectionTests::contains_base()
+{
+ const TestCollection *ccoll = collection;
+ EXPECT(ccoll->contains<Bar>("d"));
+ EXPECT(ccoll->contains<Sub>("d"));
+}
+
void CollectionTests::contains_future()
{
const TestCollection *ccoll = collection;
EXPECT_EQUAL(nm_set.count("b"), 1);
}
+void CollectionTests::names_base()
+{
+ const TestCollection *ccoll = collection;
+ list<string> nm = ccoll->get_names<Bar>();
+ EXPECT_EQUAL(nm.size(), 3);
+ set<string> nm_set(nm.begin(), nm.end());
+ EXPECT_EQUAL(nm_set.count("c"), 1);
+ EXPECT_EQUAL(nm_set.count("d"), 1);
+ EXPECT_EQUAL(nm_set.count("e"), 1);
+}
+
void CollectionTests::names_future()
{
list<string> nm = collection->get_names<Foo>();
EXPECT(Foo::get_create_count()>foo_count);
}
+void CollectionTests::list_future()
+{
+ list<Foo *> nm = collection->get_list<Foo>();
+ EXPECT_EQUAL(nm.size(), 3);
+ set<Foo *> nm_set(nm.begin(), nm.end());
+ EXPECT_EQUAL(nm_set.size(), nm.size());
+}
+
void CollectionTests::name_collision()
{
RefPtr<Foo> a = new Foo;
add_type<Foo>().keyword("foo").creator(&TestCollection::create_foo);
add_type<Bar>().keyword("bar");
add_type<Sub>().keyword("sub").base<Bar>();
+ add_type<Bus>().keyword("bus").base<Bar>();
add_source(source);
}