Classes | Functions
registry_via_id_test.cc File Reference
#include "cetlib/registry_via_id.h"
#include "cetlib_except/exception.h"
#include <cstdlib>
#include <string>
#include <vector>

Go to the source code of this file.

Classes

struct  Int
 

Functions

void ensure (int which, bool claim)
 
int main ()
 

Function Documentation

void ensure ( int  which,
bool  claim 
)

Definition at line 17 of file registry_via_id_test.cc.

18 {
19  if (not claim)
20  std::exit(which);
21 }
int main ( void  )

Definition at line 39 of file registry_via_id_test.cc.

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
const double e
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)
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