From 62038f6100d131b760a2ac090933b7b998419bc9 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 5 Dec 2012 18:57:28 +0200 Subject: [PATCH] Add some new test cases for Collection Failures will be fixed a bit later. --- tests/collection.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/tests/collection.cpp b/tests/collection.cpp index 41dc7e4..38af5d0 100644 --- a/tests/collection.cpp +++ b/tests/collection.cpp @@ -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(); add(&CollectionTests::type_mismatch, "Type mismatch").expect_throw(); add(&CollectionTests::create, "Create object"); + add(&CollectionTests::list_future, "List future objects"); add(&CollectionTests::name_collision, "Name collision").expect_throw(); 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("c")); } +void CollectionTests::contains_base() +{ + const TestCollection *ccoll = collection; + EXPECT(ccoll->contains("d")); + EXPECT(ccoll->contains("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 nm = ccoll->get_names(); + EXPECT_EQUAL(nm.size(), 3); + set 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 nm = collection->get_names(); @@ -189,6 +217,14 @@ void CollectionTests::create() EXPECT(Foo::get_create_count()>foo_count); } +void CollectionTests::list_future() +{ + list nm = collection->get_list(); + EXPECT_EQUAL(nm.size(), 3); + set nm_set(nm.begin(), nm.end()); + EXPECT_EQUAL(nm_set.size(), nm.size()); +} + void CollectionTests::name_collision() { RefPtr a = new Foo; @@ -241,6 +277,7 @@ TestCollection::TestCollection() add_type().keyword("foo").creator(&TestCollection::create_foo); add_type().keyword("bar"); add_type().keyword("sub").base(); + add_type().keyword("bus").base(); add_source(source); } -- 2.45.2