event_start_t.cc
Go to the documentation of this file.
1 #define BOOST_TEST_MODULE (event start test)
2 #include "boost/test/unit_test.hpp"
3 
6 
7 #include <string_view>
8 
9 namespace {
10  bool
11  invalid_event_id(art::Exception const& e, std::string const& spec)
12  {
13  std::string const expected{"The specification '" + spec +
14  "' is not a valid EventID"};
15  std::string_view const msg{e.what()};
16  return msg.find(expected) != std::string_view::npos;
17  }
18 }
19 
21 
22 BOOST_AUTO_TEST_SUITE(event_start_test)
23 
25 {
26  auto const [r, sr, e] = event_start("1:2:3");
27  BOOST_TEST(r == 1u);
28  BOOST_TEST(sr == 2u);
29  BOOST_TEST(e == 3u);
30 }
31 
32 BOOST_AUTO_TEST_CASE(well_formed_first_values)
33 {
34  using std::to_string;
35  auto const r_first = art::IDNumber<art::Level::Run>::first();
36  auto const sr_first = art::IDNumber<art::Level::SubRun>::first();
37  auto const e_first = art::IDNumber<art::Level::Event>::first();
38  auto const [r, sr, e] = event_start(
39  to_string(r_first) + ':' + to_string(sr_first) + ':' + to_string(e_first));
40  BOOST_TEST(r == r_first);
41  BOOST_TEST(sr == sr_first);
42  BOOST_TEST(e == e_first);
43 }
44 
45 BOOST_AUTO_TEST_CASE(well_formed_max_valid_values)
46 {
47  using std::to_string;
48  auto const r_max_valid = art::IDNumber<art::Level::Run>::max_valid();
49  auto const sr_max_valid = art::IDNumber<art::Level::SubRun>::max_valid();
50  auto const e_max_valid = art::IDNumber<art::Level::Event>::max_valid();
51  auto const [r, sr, e] =
52  event_start(to_string(r_max_valid) + ':' + to_string(sr_max_valid) + ':' +
53  to_string(e_max_valid));
54  BOOST_TEST(r == r_max_valid);
55  BOOST_TEST(sr == sr_max_valid);
56  BOOST_TEST(e == e_max_valid);
57 }
58 
59 BOOST_AUTO_TEST_CASE(leading_and_trailing_spaces_allowed)
60 {
61  auto const [r, sr, e] = event_start(" 1:2 : 3");
62  BOOST_TEST(r == 1u);
63  BOOST_TEST(sr == 2u);
64  BOOST_TEST(e == 3u);
65 }
66 
67 #define VERIFY_EXCEPTION_WITH_MSG(spec) \
68  BOOST_CHECK_EXCEPTION(event_start(spec), art::Exception, [](auto const& e) { \
69  return invalid_event_id(e, spec); \
70  })
71 
72 BOOST_AUTO_TEST_CASE(out_of_range_run)
73 {
74  VERIFY_EXCEPTION_WITH_MSG("-1:0:0");
76  VERIFY_EXCEPTION_WITH_MSG("4294967295:0:0");
77 }
78 
79 BOOST_AUTO_TEST_CASE(out_of_range_subrun)
80 {
81  VERIFY_EXCEPTION_WITH_MSG("1:-1:0");
82  VERIFY_EXCEPTION_WITH_MSG("1:4294967295:0");
83 }
84 
85 BOOST_AUTO_TEST_CASE(out_of_range_event)
86 {
87  VERIFY_EXCEPTION_WITH_MSG("1:0:-1");
88  VERIFY_EXCEPTION_WITH_MSG("1:0:4294967295");
89 }
90 
91 BOOST_AUTO_TEST_CASE(wrong_number_of_colons)
92 {
94  VERIFY_EXCEPTION_WITH_MSG("1:1:1:2");
95 }
96 
98 {
99  VERIFY_EXCEPTION_WITH_MSG("1: - 2:3");
101  VERIFY_EXCEPTION_WITH_MSG("1:hello billy:3");
102  VERIFY_EXCEPTION_WITH_MSG("1:2.8:3");
103 }
104 
105 BOOST_AUTO_TEST_SUITE_END()
106 
107 #undef VERIFY_EXCEPTION_WITH_MSG
void msg(const char *fmt,...)
Definition: message.cpp:107
const char expected[]
Definition: Exception_t.cc:22
std::string string
Definition: nybbler.cc:12
#define VERIFY_EXCEPTION_WITH_MSG(spec)
std::tuple< RunNumber_t, SubRunNumber_t, EventNumber_t > event_start(std::string const &str_num)
Definition: event_start.cc:72
const double e
cet::coded_exception< errors::ErrorCodes, ExceptionDetail::translate > Exception
Definition: Exception.h:66
static constexpr double sr
Definition: Units.h:166
std::string to_string(ModuleType const mt)
Definition: ModuleType.h:34
BOOST_AUTO_TEST_CASE(well_formed)