test_dlopen.cxx
Go to the documentation of this file.
2 
6 #include "WireCellUtil/Testing.h"
7 
8 #include <dlfcn.h>
9 
10 #include <iostream>
11 using namespace std;
12 using namespace WireCell;
13 
14 int main()
15 {
17  Plugin* gen_plug = pm.add("WireCellGen");
18  Assert(gen_plug);
19 
20 
21  typedef NamedFactoryRegistry<IWireParameters> IWPFactoryRegistry;
22  IWPFactoryRegistry* iwp1 = &Singleton< IWPFactoryRegistry >::Instance();
23  IWPFactoryRegistry* iwp2 = &Singleton< IWPFactoryRegistry >::Instance();
24  Assert(iwp1);
25  Assert(iwp2);
26  Assert(iwp1 == iwp2);
27 
28  cerr << "Looking up WireParams factory in NFR: " << iwp1 << endl;
29  auto inst1 = iwp1->lookup_factory("WireParams");
30  auto inst2 = iwp1->lookup_factory("WireParams");
31 
32  Assert(inst1);
33  Assert(inst2);
34  Assert(inst1 == inst2);
35 
36  cerr << "Looking up WireParams factory \n";
37  auto factory = Factory::lookup_factory<IWireParameters>("WireParams");
38  Assert(factory);
39 
40  cerr << "Looking up WireParams:\n";
41  auto wp1 = Factory::lookup<IWireParameters>("WireParams");
42  Assert(wp1);
43  cerr << "Looking up WireParams, again:\n";
44  auto wp2 = Factory::lookup<IWireParameters>("WireParams");
45  Assert(wp2);
46  cerr << "Looking up undefined WireParams\n";
47  auto wp3 = Factory::lookup<IWireParameters>("WireParams","MyWireParameters");
48  Assert(wp3);
49 
50  Assert(wp2 == wp1);
51  Assert(wp3 != wp1);
52 
53  return 0;
54 }
55 
56 
const std::string instance
STL namespace.
#define Assert
Definition: Testing.h:7
Definition: Main.h:22
Plugin * add(const std::string &plugin_name, const std::string &libname="")
Add a plugin. If libname is not given, try to derive it.
int main()
Definition: test_dlopen.cxx:14
QTextStream & endl(QTextStream &s)