Commit 77d0f5d2 authored by Matthieu Dorier's avatar Matthieu Dorier

added SubRunTest

parent e2ae0a2f
......@@ -10,7 +10,7 @@
namespace hepnos {
Event::Event()
: m_impl(std::make_unique<Impl>(nullptr, 0, "", 0)) {}
: m_impl(std::make_unique<Impl>(nullptr, 0, "", InvalidEventNumber)) {}
Event::Event(DataStore* ds, uint8_t level, const std::string& container, const EventNumber& rn)
: m_impl(std::make_unique<Impl>(ds, level, container, rn)) { }
......
......@@ -19,7 +19,11 @@ target_link_libraries(RunSetTest cppunit hepnos hepnos-service)
add_executable(RunTest RunTest.cpp HEPnOSTestMain.cpp)
target_link_libraries(RunTest cppunit hepnos hepnos-service)
add_executable(SubRunTest SubRunTest.cpp HEPnOSTestMain.cpp)
target_link_libraries(SubRunTest cppunit hepnos hepnos-service)
add_test(NAME DataStoreTest COMMAND run-test.sh ./DataStoreTest)
add_test(NAME DataSetTest COMMAND run-test.sh ./DataSetTest)
add_test(NAME RunSetTest COMMAND run-test.sh ./RunSetTest)
add_test(NAME RunTest COMMAND run-test.sh ./RunTest)
add_test(NAME SubRunTest COMMAND run-test.sh ./SubRunTest)
#include "SubRunTest.hpp"
#include "CppUnitAdditionalMacros.hpp"
CPPUNIT_TEST_SUITE_REGISTRATION( SubRunTest );
using namespace hepnos;
void SubRunTest::setUp() {}
void SubRunTest::tearDown() {}
void SubRunTest::testFillDataStore() {
auto mds = datastore->createDataSet("matthieu");
CPPUNIT_ASSERT(mds.valid());
Run r1 = mds.createRun(42);
CPPUNIT_ASSERT(r1.valid());
SubRun sr1 = r1.createSubRun(3);
}
void SubRunTest::testCreateEvents() {
DataSet mds = (*datastore)["matthieu"];
CPPUNIT_ASSERT(mds.valid());
Run r1 = mds(42);
CPPUNIT_ASSERT(r1.valid());
SubRun sr1 = r1(3);
CPPUNIT_ASSERT(sr1.valid());
Event e10 = sr1.createEvent(10);
CPPUNIT_ASSERT(e10.valid());
CPPUNIT_ASSERT(10 == e10.number());
Event e23 = sr1.createEvent(23);
CPPUNIT_ASSERT(e23.valid());
CPPUNIT_ASSERT(23 == e23.number());
Event e13 = sr1.createEvent(13);
CPPUNIT_ASSERT(e13.valid());
CPPUNIT_ASSERT(13 == e13.number());
Event e38 = sr1.createEvent(38);
CPPUNIT_ASSERT(e38.valid());
CPPUNIT_ASSERT(38 == e38.number());
}
void SubRunTest::testParenthesisOperator() {
DataSet mds = (*datastore)["matthieu"];
CPPUNIT_ASSERT(mds.valid());
Run r1 = mds(42);
CPPUNIT_ASSERT(r1.valid());
SubRun sr1 = r1(3);
CPPUNIT_ASSERT(sr1.valid());
// check access to non-existing SubRun
Event e0 = sr1(12);
CPPUNIT_ASSERT(!e0.valid());
CPPUNIT_ASSERT(e0.number() == InvalidEventNumber);
// check access to existing SubRun
Event e13 = sr1(13);
CPPUNIT_ASSERT(e13.valid());
CPPUNIT_ASSERT(13 == e13.number());
}
void SubRunTest::testFind() {
DataSet mds = (*datastore)["matthieu"];
CPPUNIT_ASSERT(mds.valid());
Run r1 = mds(42);
CPPUNIT_ASSERT(r1.valid());
SubRun sr1 = r1(3);
CPPUNIT_ASSERT(sr1.valid());
// test calling find for a SubRun that does not exist
{
auto it = sr1.find(12);
CPPUNIT_ASSERT(it == sr1.end());
CPPUNIT_ASSERT(!(it->valid()));
}
// test calling find for a SubRun that exists
{
auto it = sr1.find(13);
CPPUNIT_ASSERT(it != sr1.end());
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(13 == it->number());
// test iteration
++it;
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(23 == it->number());
}
}
void SubRunTest::testBeginEnd() {
DataSet mds = (*datastore)["matthieu"];
CPPUNIT_ASSERT(mds.valid());
Run r1 = mds(42);
CPPUNIT_ASSERT(r1.valid());
SubRun sr1 = r1(3);
CPPUNIT_ASSERT(sr1.valid());
std::vector<EventNumber> numbers = {10, 13, 23, 38};
auto it = sr1.begin();
for(int i=0; i < numbers.size(); i++, it++) {
CPPUNIT_ASSERT_EQUAL(numbers[i], it->number());
}
CPPUNIT_ASSERT(it == sr1.end());
}
void SubRunTest::testLowerUpperBounds() {
DataSet mds = (*datastore)["matthieu"];
CPPUNIT_ASSERT(mds.valid());
Run r1 = mds(42);
CPPUNIT_ASSERT(r1.valid());
SubRun sr1 = r1(3);
CPPUNIT_ASSERT(sr1.valid());
{
auto it = sr1.lower_bound(13);
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(it->number() == 13);
}
{
auto it = sr1.lower_bound(14);
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(it->number() == 23);
}
{
auto it = sr1.lower_bound(12);
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(it->number() == 13);
}
{
auto it = sr1.lower_bound(40);
CPPUNIT_ASSERT(!(it->valid()));
CPPUNIT_ASSERT(it == sr1.end());
}
{
auto it = sr1.upper_bound(13);
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(it->number() == 23);
}
{
auto it = sr1.upper_bound(14);
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(it->number() == 23);
}
{
auto it = sr1.upper_bound(12);
CPPUNIT_ASSERT(it->valid());
CPPUNIT_ASSERT(it->number() == 13);
}
{
auto it = sr1.upper_bound(38);
CPPUNIT_ASSERT(!(it->valid()));
CPPUNIT_ASSERT(it == sr1.end());
}
}
#ifndef __HEPNOS_TEST_SUBRUN_H
#define __HEPNOS_TEST_SUBRUN_H
#include <cppunit/extensions/HelperMacros.h>
#include <hepnos.hpp>
extern hepnos::DataStore* datastore;
class SubRunTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( SubRunTest );
CPPUNIT_TEST( testFillDataStore );
CPPUNIT_TEST( testCreateEvents );
CPPUNIT_TEST( testParenthesisOperator );
CPPUNIT_TEST( testFind );
CPPUNIT_TEST( testBeginEnd );
CPPUNIT_TEST( testLowerUpperBounds );
CPPUNIT_TEST_SUITE_END();
public:
void setUp();
void tearDown();
void testFillDataStore();
void testCreateEvents();
void testParenthesisOperator();
void testFind();
void testBeginEnd();
void testLowerUpperBounds();
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment