]> git.tdb.fi Git - libs/datafile.git/commitdiff
Update Collection test cases with source and base class changes
authorMikko Rasa <tdb@tdb.fi>
Tue, 4 Dec 2012 09:08:11 +0000 (11:08 +0200)
committerMikko Rasa <tdb@tdb.fi>
Tue, 4 Dec 2012 09:08:11 +0000 (11:08 +0200)
tests/collection.cpp

index bbcc6c9fce28bab325341149a1123be8acf09f03..41dc7e482543ccaa31bc3e9346addab68ddcec34 100644 (file)
@@ -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<Foo>("b").get_tag(), 2);
        EXPECT_EQUAL(ccoll->get<Bar>("c").get_tag(), 3);
        EXPECT_EQUAL(ccoll->get<Bar>("d").get_tag(), 4);
+       EXPECT_EQUAL(ccoll->get<Sub>("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<Foo>().keyword("foo").creator(&TestCollection::create_foo);
        add_type<Bar>().keyword("bar");
-       add_type<Sub>().keyword("sub").store_as<Bar>();
-       add_future<Foo>("f");
+       add_type<Sub>().keyword("sub").base<Bar>();
+       add_source(source);
 }
 
 Foo *TestCollection::create_foo(const string &)