From 17608ed08bfee40cdc3da19d5a1a2dc77410578f Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 4 Dec 2012 11:08:11 +0200 Subject: [PATCH] Update Collection test cases with source and base class changes --- tests/collection.cpp | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/tests/collection.cpp b/tests/collection.cpp index bbcc6c9..41dc7e4 100644 --- a/tests/collection.cpp +++ b/tests/collection.cpp @@ -70,8 +70,20 @@ class Sub: public Bar { }; +class TestSource: public DataFile::CollectionSource +{ +public: + virtual bool is_loadable(const DataFile::CollectionItemTypeBase &, const std::string &) const; + virtual NameList get_names(const DataFile::CollectionItemTypeBase &) const; + virtual void load(DataFile::Collection &, const DataFile::CollectionItemTypeBase &, const std::string &) const; +}; + + class TestCollection: public DataFile::Collection { +private: + TestSource source; + public: TestCollection(); @@ -155,6 +167,7 @@ void CollectionTests::fetch() EXPECT_EQUAL(ccoll->get("b").get_tag(), 2); EXPECT_EQUAL(ccoll->get("c").get_tag(), 3); EXPECT_EQUAL(ccoll->get("d").get_tag(), 4); + EXPECT_EQUAL(ccoll->get("d").get_tag(), 4); } void CollectionTests::nonexistent() @@ -204,12 +217,31 @@ Foo::Foo() } +bool TestSource::is_loadable(const DataFile::CollectionItemTypeBase &, const string &name) const +{ + return name=="f"; +} + +DataFile::CollectionSource::NameList TestSource::get_names(const DataFile::CollectionItemTypeBase &) const +{ + NameList names; + names.push_back("f"); + return names; +} + +void TestSource::load(DataFile::Collection &coll, const DataFile::CollectionItemTypeBase &, const string &name) const +{ + if(name=="f") + coll.add("f", new Foo); +} + + TestCollection::TestCollection() { add_type().keyword("foo").creator(&TestCollection::create_foo); add_type().keyword("bar"); - add_type().keyword("sub").store_as(); - add_future("f"); + add_type().keyword("sub").base(); + add_source(source); } Foo *TestCollection::create_foo(const string &) -- 2.45.2