registry_test.cc
Go to the documentation of this file.
1 // ======================================================================
2 //
3 // test registry
4 //
5 // ======================================================================
6 
7 #include "cetlib/registry.h"
8 #include "cetlib_except/exception.h"
9 
10 #include <cstdlib>
11 #include <string>
12 
13 using cet::registry;
14 
15 void
16 ensure(int which, bool claim)
17 {
18  if (not claim)
19  std::exit(which);
20 }
21 
22 int
24 {
25  int i;
26 
28  ensure(1, reg::empty());
29  ensure(2, reg::size() == 0);
30 
31  reg::put("one", 1);
32  reg::put("two", 2);
33  reg::put("three", 3);
34  ensure(3, reg::size() == 3);
35  reg::put("four", 4);
36  reg::put("five", 5);
37  reg::put("six", 6);
38  reg::put("seven", 7);
39  reg::put("eight", 8);
40  reg::put("nine", 9);
41  reg::put("zero", 0);
42 
43  ensure(11, !reg::empty());
44  ensure(12, reg::size() == 10);
45  ensure(13, reg::get("seven") == 7);
46  ensure(14, reg::get("five") == 5);
47  ensure(15, !reg::get("bleen", i));
48  ensure(16, reg::get("two", i) && i == 2);
49 
50  try {
51  reg::get("ten");
52  ensure(21, false);
53  }
54  catch (cet::exception const& e) {
55  ensure(22, e.category() == "cet::registry");
56  std::string s = e.explain_self();
57  ensure(23, s.find("not found in registry") != std::string::npos);
58  }
59  catch (...) {
60  ensure(24, false);
61  }
62 
63  return reg::get("zero");
64 
65 } // main()
int main()
std::string string
Definition: nybbler.cc:12
void ensure(int which, bool claim)
const double e
static collection_type const & get() noexcept
static size_type size()
static detail::must_have_id< K, V >::type put(V const &value)
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