Commit 1e4c689f authored by Matthieu Dorier's avatar Matthieu Dorier
Browse files

added tests against exceptions

parent de4a7bc4
......@@ -342,10 +342,16 @@ EventSet DataSet::events(int target) const {
if(!valid()) {
throw Exception("Calling DataSet member function on an invalid DataSet");
}
auto numTargets = m_impl->m_datastore->numTargets(ItemType::EVENT);
if(target >= (int)numTargets) {
throw Exception(std::string("Invalid target number ")
+std::to_string(target)
+" for EventSet (>= "
+std::to_string(numTargets)+")");
}
if(target >= 0)
return EventSet(std::make_shared<EventSetImpl>(*m_impl, target));
else {
auto numTargets = m_impl->m_datastore->numTargets(ItemType::EVENT);
return EventSet(std::make_shared<EventSetImpl>(*m_impl, 0, numTargets));
}
}
......
......@@ -58,6 +58,13 @@ void EventSetTest::testFillDataStore() {
onevent.createRun(1).createSubRun(3).createEvent(76);
}
void EventSetTest::testInvalid() {
auto root = datastore->root();
DataSet mds = root["matthieu"];
CPPUNIT_ASSERT_THROW(mds.events(datastore->numTargets(ItemType::EVENT)+1), Exception);
CPPUNIT_ASSERT_THROW(mds.events(datastore->numTargets(ItemType::EVENT)+1), Exception);
}
void EventSetTest::testBeginEnd() {
auto root = datastore->root();
DataSet mds = root["matthieu"];
......
......@@ -10,6 +10,7 @@ class EventSetTest : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE( EventSetTest );
CPPUNIT_TEST( testFillDataStore );
CPPUNIT_TEST( testInvalid );
CPPUNIT_TEST( testBeginEnd );
CPPUNIT_TEST_SUITE_END();
......@@ -19,6 +20,7 @@ class EventSetTest : public CppUnit::TestFixture
void tearDown();
void testFillDataStore();
void testInvalid();
void testBeginEnd();
};
......
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