]> git.tdb.fi Git - libs/datafile.git/commitdiff
Add some new test cases for Collection
authorMikko Rasa <tdb@tdb.fi>
Wed, 5 Dec 2012 16:57:28 +0000 (18:57 +0200)
committerMikko Rasa <tdb@tdb.fi>
Wed, 5 Dec 2012 16:57:28 +0000 (18:57 +0200)
Failures will be fixed a bit later.

tests/collection.cpp

index 41dc7e482543ccaa31bc3e9346addab68ddcec34..38af5d0e58eef9364aaf5e8557f5045de625d746 100644 (file)
@@ -23,13 +23,16 @@ public:
 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();
 };
 
@@ -69,6 +72,9 @@ class Bar: public Base
 class Sub: public Bar
 { };
 
+class Bus: public Bar
+{ };
+
 
 class TestSource: public DataFile::CollectionSource
 {
@@ -96,13 +102,16 @@ CollectionTests::CollectionTests()
 {
        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;
@@ -119,7 +128,8 @@ void CollectionTests::load()
                "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, "-");
@@ -135,6 +145,13 @@ void CollectionTests::contains()
        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;
@@ -152,6 +169,17 @@ void CollectionTests::names()
        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>();
@@ -189,6 +217,14 @@ void CollectionTests::create()
        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;
@@ -241,6 +277,7 @@ TestCollection::TestCollection()
        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);
 }