DataStoreTest.cpp 1.91 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include "DataStoreTest.hpp"
#include "CppUnitAdditionalMacros.hpp"

CPPUNIT_TEST_SUITE_REGISTRATION( DataStoreTest );

using namespace hepnos;

void DataStoreTest::setUp() {}

void DataStoreTest::tearDown() {}

void DataStoreTest::testFillDataStore() {
    // erroneous dataset creations
    // "/" is forbidden in the name, will throw an exception
    CPPUNIT_ASSERT_THROW(
16
            datastore->root().createDataSet("ds0/AAA"),
17 18 19
            hepnos::Exception);
    // "%" is forbidden in the name, will throw an exception
    CPPUNIT_ASSERT_THROW(
20
            datastore->root().createDataSet("ds0%RRS"),
21 22
            hepnos::Exception);
    // correct dataset creation
23
    DataSet ds1 = datastore->root().createDataSet("ds1");
24 25 26 27
    // assert the characteristics of the created dataset
    CPPUNIT_ASSERT(ds1.valid());
    CPPUNIT_ASSERT_EQUAL_STR("ds1", ds1.name());
    CPPUNIT_ASSERT_EQUAL_STR("", ds1.container());
28
    CPPUNIT_ASSERT_EQUAL_STR("/ds1", ds1.fullname());
29
    // assert invalid dataset when it does not exist
30
    CPPUNIT_ASSERT_THROW(datastore->root()["invalid"], hepnos::Exception);
31 32 33 34 35 36 37 38
    // assert comparison with a default-constructed dataset
    DataSet ds0;
    CPPUNIT_ASSERT(ds0 != ds1);
    CPPUNIT_ASSERT(!(ds0 == ds1));
    // assert that ds1.next() is not valid
    DataSet ds2 = ds1.next();
    CPPUNIT_ASSERT(!ds2.valid());
    // create more datasets
39 40
    DataSet ds3 = datastore->root().createDataSet("ds3");
    ds2 = datastore->root().createDataSet("ds2");
41 42 43 44 45 46 47
    // assert that these are valid
    CPPUNIT_ASSERT(ds2.valid());
    CPPUNIT_ASSERT(ds3.valid());
    // assert that ds1.next() == ds2 and ds2.next() == ds3
    CPPUNIT_ASSERT(ds2 == ds1.next());
    CPPUNIT_ASSERT(ds3 == ds2.next());
    // create more datasets for future tests
48 49
    DataSet ds4 = datastore->root().createDataSet("dsB");
    DataSet ds5 = datastore->root().createDataSet("dsD");
50 51 52 53
    CPPUNIT_ASSERT(ds4.valid());
    CPPUNIT_ASSERT(ds5.valid());
}