test_DuneToolManager.cxx
Go to the documentation of this file.
1 // test_DuneToolManager.cxx
2 
3 //#include "AXService/DuneToolManager.h"
6 
7 #include <string>
8 #include <iostream>
9 #include <fstream>
10 
11 using std::string;
12 using std::cout;
13 using std::endl;
14 using std::ofstream;
15 
16 #undef NDEBUG
17 #include <cassert>
18 
19 int test_DuneToolManager(bool useExistingFcl =false) {
20  const string myname = "test_DuneToolManager: ";
21  cout << myname << "Starting test" << endl;
22 #ifdef NDEBUG
23  cout << myname << "NDEBUG must be off." << endl;
24  abort();
25 #endif
26  string line = "-----------------------------";
27  string scfg;
28 
29  cout << myname << line << endl;
30  string fclfile = "test_DuneToolManager.fcl";
31  if ( ! useExistingFcl ) {
32  cout << myname << "Creating top-level FCL." << endl;
33  ofstream fout(fclfile.c_str());
34  fout << "tools: {" << endl;
35  fout << " mytool1: {" << endl;
36  fout << " tool_type: TestTool" << endl;
37  fout << " Label: \"Tool 1\"" << endl;
38  fout << " }" << endl;
39  fout << " mytool2: {" << endl;
40  fout << " tool_type: TestTool" << endl;
41  fout << " Label: \"Tool 2\"" << endl;
42  fout << " }" << endl;
43  fout << "}" << endl;
44  fout.close();
45  } else {
46  cout << myname << "Using existing top-level FCL." << endl;
47  }
48 
49  cout << line << endl;
50  cout << myname << "Retrieve tool manager." << endl;
52  assert( ptm != nullptr );
53  assert( DuneToolManager::fclFilename() == fclfile );
54  DuneToolManager& dtm = *ptm;
55 
56  cout << myname << line << endl;
57  cout << myname << "Display tools." << endl;
58  dtm.print();
59 
60  cout << myname << line << endl;
61  cout << myname << "Check tool list." << endl;
62  assert( dtm.toolNames().size() > 0 );
63 
64  cout << myname << line << endl;
65  cout << myname << "Fetch a private tool." << endl;
66  auto ptp1 = ptm->getPrivate<TestTool>("mytool1");
67  assert( ptp1 != nullptr );
68  assert( ptp1->label() == "Tool 1" );
69 
70  cout << myname << line << endl;
71  cout << myname << "Fetch a private tool." << endl;
72  auto ptp2 = ptm->getPrivate<TestTool>("mytool1");
73  assert( ptp2 != nullptr );
74  assert( ptp2 != ptp1 );
75  assert( ptp2->label() == "Tool 1" );
76 
77  cout << myname << line << endl;
78  cout << myname << "Fetch a shared tool." << endl;
79  auto pts1 = ptm->getShared<TestTool>("mytool1");
80  assert( pts1 != nullptr );
81  assert( pts1 != ptp1.get() );
82  assert( pts1->label() == "Tool 1" );
83 
84  cout << myname << line << endl;
85  cout << myname << "Fetch shared tool again." << endl;
86  auto pts2 = ptm->getShared<TestTool>("mytool1");
87  assert( pts2 != nullptr );
88  assert( pts2 == pts1 );
89  assert( pts2->label() == "Tool 1" );
90 
91  cout << myname << line << endl;
92  cout << myname << "Fetch another shared tool." << endl;
93  auto pts3 = ptm->getShared<TestTool>("mytool2");
94  assert( pts3 != nullptr );
95  assert( pts3 != pts2 );
96  assert( pts3->label() == "Tool 2" );
97 
98  cout << myname << line << endl;
99  cout << myname << "Fetch a private tool with config." << endl;
100  string scfgTool = "{ tool_type:TestTool Label:\"Tool C\" }";
101  cout << myname << "Config: " << scfgTool << endl;
102  auto ptpc = ptm->getPrivate<TestTool>(scfgTool);
103  assert( ptpc != nullptr );
104  assert( ptpc != ptp1 );
105  assert( ptpc->label() == "Tool C" );
106 
107  cout << myname << line << endl;
108  cout << myname << "Done." << endl;
109  return 0;
110 }
111 
112 int main() {
113  int rstat = test_DuneToolManager();
114  return rstat;
115 }
const std::vector< std::string > & toolNames() const
std::string string
Definition: nybbler.cc:12
void print() const
int test_DuneToolManager(bool useExistingFcl=false)
static std::string fclFilename(std::string setName="", int dbg=1)
std::unique_ptr< T > getPrivate(std::string name)
void line(double t, double *p, double &x, double &y, double &z)
int main()
static DuneToolManager * instance(std::string fclname="", int dbg=1)
T * getShared(std::string name)
QTextStream & endl(QTextStream &s)