Classes | Functions
test_namedfactory.cxx File Reference
#include "WireCellUtil/NamedFactory.h"
#include "WireCellUtil/Testing.h"
#include "WireCellUtil/Logging.h"
#include "WireCellUtil/Exceptions.h"

Go to the source code of this file.

Classes

class  ISomeComponent
 
class  SomeConcrete
 

Functions

int main (int argc, char *argv[])
 

Function Documentation

int main ( int  argc,
char *  argv[] 
)

Definition at line 41 of file test_namedfactory.cxx.

42 {
43  Testing::log(argv[0]);
44  // for this test we cheat since the factory isn't in a shared library.
45  make_SomeConcrete_factory();
46 
47  auto ins = WireCell::Factory::lookup<ISomeComponent>("SomeConcrete");
48  AssertMsg(ins, "Failed to lookup 'SomeConcrete' with interface 'ISomeComponent'");
49  info("Got SomeConcrete @ {:p}", (void*)ins.get());
50  info("Got bogus @ {:p}", (void*)std::shared_ptr<ISomeComponent>().get());
51  ins->chirp();
52 
53  bool caught = false;
54  try {
55  auto should_fail = WireCell::Factory::lookup<ISomeComponent>("NothingNamedThis");
56  }
57  catch (WireCell::FactoryException& e) {
58  warn(errstr(e));
59  info("^^^ Successfully failed to lookup a nonexistent component");
60  caught=true;
61  }
62  AssertMsg(caught, "Failed to throw");
63  info("Should not hear anything from this failed find_tn");
64  std::shared_ptr<ISomeComponent> ptr
65  = WireCell::Factory::find_maybe_tn<ISomeComponent>("SomeConcrete:doesnotexist");
66  AssertMsg(ptr==nullptr, "Got non null for nonexistent named component");
67  info("Success. Next, 'find' should be successful");
68  std::shared_ptr<ISomeComponent> ptr2
69  = WireCell::Factory::find_maybe_tn<ISomeComponent>("SomeConcrete");
70  debug("Got ptr2 @ {:p}", (void*)ptr2.get());
71  AssertMsg(ptr2 != nullptr, "Got null for existing component");
72 // AssertMsg(false, "Got null for existing component");
73 }
#define errstr(e)
Definition: Exceptions.h:26
const double e
void log(source_loc source, level::level_enum lvl, const char *fmt, const Args &...args)
Definition: spdlog.h:165
const void * ptr(const T *p)
Definition: format.h:3138
#define AssertMsg
Definition: Testing.h:8