registry_via_id_test.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // test registry_via_id
4 //
5 // ======================================================================
6 
8 #include "cetlib_except/exception.h"
9 
10 #include <cstdlib>
11 #include <string>
12 #include <vector>
13 
15 
16 void
17 ensure(int which, bool claim)
18 {
19  if (not claim)
20  std::exit(which);
21 }
22 
23 struct Int {
24  int i;
25  Int(int i = 0) : i(i) {}
26  float
27  id() const
28  {
29  return i;
30  }
31  bool
32  operator==(int other) const
33  {
34  return i == other;
35  }
36 };
37 
38 int
40 {
41  Int i;
42 
44  ensure(1, reg::empty());
45  ensure(2, reg::size() == 0);
46 
47  reg::put(1);
48  reg::put(2);
49  reg::put(3);
50  ensure(3, reg::size() == 3);
51  reg::put(4);
52  reg::put(5);
53  reg::put(6);
54  reg::put(7);
55  reg::put(8);
56  reg::put(9);
57  reg::put(0);
58 
59  ensure(11, !reg::empty());
60  ensure(12, reg::size() == 10);
61  ensure(13, reg::get(7.0F) == 7);
62  ensure(14, reg::get(5.0F) == 5);
63  ensure(15, reg::get(2.0F, i) && i == 2);
64  ensure(16, !reg::get(3.14F, i) && i == 2);
65 
66  try {
67  reg::get(10.0F);
68  ensure(21, false);
69  }
70  catch (cet::exception const& e) {
71  ensure(22, e.category() == "cet::registry_via_id");
72  std::string s = e.explain_self();
73  ensure(23, s.find("not found in registry") != std::string::npos);
74  }
75  catch (...) {
76  ensure(24, false);
77  }
78 
79  reg::collection_type x{{25.0, 25}, {36.0, 36}, {49.0, 49}};
80  reg::put(x);
81  reg::put(x.cbegin(), x.cend());
82  std::vector<reg::mapped_type> v{64, 81, 100};
83  reg::put(v.cbegin(), v.cend());
84 
85  return 0;
86 
87 } // main()
std::string string
Definition: nybbler.cc:12
float id() const
const double e
bool operator==(int other) const
std::map< K const, V > collection_type
static collection_type const & get() noexcept
void ensure(int which, bool claim)
static size_type size()
static detail::must_have_id< K, V >::type put(V const &value)
Int(int i=0)
int main()
list x
Definition: train.py:276
cet::registry_via_id< success_t, val > reg
static QCString * s
Definition: config.cpp:1042
cet::coded_exception< error, detail::translate > exception
Definition: exception.h:33