test_FileChannelMappingService.cxx
Go to the documentation of this file.
1 // test_FileChannelMappingService.cxx
2 
3 // David Adams
4 // February 2015
5 //
6 // Test FileChannelMappingService.
7 
8 #include "../FileChannelMappingService.h"
9 #include <string>
10 #include <iostream>
11 #include <sstream>
12 #include <fstream>
13 #include <iomanip>
14 //#include "dune/ArtSupport/ArtServiceHelper.h"
15 
16 using std::string;
17 using std::cout;
18 using std::endl;
19 using std::setw;
21 
22 #undef NDEBUG
23 #include <cassert>
24 
26  const string myname = "test_FileChannelMappingService: ";
27 #ifdef NDEBUG
28  cout << myname << "NDEBUG must be off." << endl;
29  abort();
30 #endif
31  const string line = "-----------------------------";
32 
33  cout << myname << line << endl;
34  cout << myname << "Create channel mapping service." << endl;
36  pset.put("FileName", fname);
37  FileChannelMappingService mapsvc(pset);
38 
39  cout << myname << line << endl;
40  cout << myname << "Fetch offline channels." << endl;
41  Channel maxch = 20;
42  unsigned int w = 12;
43  cout << myname << setw(w) << "online" << setw(w) << "offline" << endl;
44  for ( unsigned int chin=0; chin<maxch; ++chin ) {
45  cout << myname << setw(w) << chin << setw(w) << mapsvc.offline(chin) << endl;
46  }
47 
48  cout << myname << line << endl;
49  cout << myname << "Fetch online channels." << endl;
50  cout << myname << setw(w) << "offline" << setw(w) << "online" << endl;
51  for ( unsigned int chin=0; chin<maxch; ++chin ) {
52  cout << myname << setw(w) << chin << setw(w) << mapsvc.online(chin) << endl;
53  }
54 
55  cout << myname << line << endl;
56  cout << myname << "Check mapping failures raise exceptions." << endl;
57  Channel nch = 2048;
58  try {
59  mapsvc.offline(nch);
60  cout << myname << "ERROR: Invalid online channel did not raise exception!" << endl;
61  return 1;
62  } catch(...) {
63  cout << myname << "Invalid online channel raised exception." << endl;
64  }
65  try {
66  mapsvc.online(nch);
67  cout << myname << "ERROR: Invalid offline channel did not raise exception!" << endl;
68  return 1;
69  } catch(...) {
70  cout << myname << "Invalid offline channel raised exception." << endl;
71  }
72 
73  cout << myname << line << endl;
74  cout << myname << "Check map consistency." << endl;
75  for ( Channel chin=0; chin<nch; ++chin ) {
76  Channel choff = mapsvc.offline(chin);
77  Channel chon = mapsvc.online(choff);
78  assert( chon == chin );
79  }
80 
81  cout << myname << line << endl;
82  cout << myname << "Done." << endl;
83  return 0;
84 }
85 
86 int main(int argc, char* argv[]) {
87  test_FileChannelMappingService("rce_channel_map_dune35t.txt");
88  return 0;
89 }
std::string string
Definition: nybbler.cc:12
ChannelMappingService::Channel Channel
Q_EXPORT QTSManip setw(int w)
Definition: qtextstream.h:331
Channel online(Channel offlineChannel) const
int main(int argc, char *argv[])
void line(double t, double *p, double &x, double &y, double &z)
Channel offline(Channel onlineChannel) const
int test_FileChannelMappingService(string fname)
void put(std::string const &key)
QTextStream & endl(QTextStream &s)
ChannelMappingService::Channel Channel