Bridge++  Ver. 1.1.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
testManager.h
Go to the documentation of this file.
1 
14 #ifndef TESTMANAGER_INCLUDED
15 #define TESTMANAGER_INCLUDED
16 
17 #include <iostream>
18 #include <fstream>
19 #include <cmath>
20 #include <string>
21 #include <vector>
22 #include <map>
23 
24 #include "defs.h"
25 #include "communicator.h"
26 #include "commonParameters.h"
27 #include "test.h"
28 
29 #include "bridgeIO.h"
30 using Bridge::vout;
31 
32 // typedef Functor<int> Test_function;
33 typedef int (*Test_function) (void);
34 
35 // null function
36 int DoNothing();
37 
38 #if 0
39 // debug
40 void hook_preexec();
41 void hook_postexec();
42 #endif
43 
45 
64 {
65  public:
66  void interactive();
67  void batch(const std::string& arg);
68 
69  bool registerTest(const std::string& key, const Test_function func);
70 
71  static TestManager& Instance();
72 
73  static bool RegisterTest(const std::string& key, const Test_function func)
74  { return Instance().registerTest(key, func); }
75 
76  // for test result verification
77  int getCheckPrecision() const
78  { return m_precision; }
79 
80  private:
81  // singleton
82  TestManager();
83 
84  TestManager(const TestManager&); // not implemented
85  TestManager& operator=(const TestManager&); // not implemented
86 
87  ~TestManager();
88 
89  static void CreateInstance();
90 
92 
93  // bi-directional tree representation of key
94  struct Node
95  {
97  std::vector<Node *> m_next;
98  std::string m_name; // key
100 
101  Node(const std::string& name, Node *const prev = 0)
102  : m_prev(prev), m_next(), m_name(name), m_function(DoNothing) {}
104  {
105  for (size_t i = 0; i < m_next.size(); ++i) { delete m_next[i]; }
106  }
107  };
108 
109  Node *find_node(Node *p, const std::vector<std::string>& v);
110  Node *append_key(Node *p, const std::vector<std::string>& v);
111  Node *append_key(Node *p, int argc, char **argv);
112 
113  // statistics
114  struct Stat
115  {
118  std::vector<std::string> m_list_failure;
119 
120  void reset();
121  void success(const std::string& test_name);
122  void failure(const std::string& test_name);
123  };
124 
125  void stat_report() const;
126 
127  std::string find_fullpath(const Node *p, const std::string& path = "");
128 
129  void interactive_master();
130  void interactive_slave();
131 
132  void run(const Node *p);
133  void run_traversal(const Node *p);
134 
135  bool menu(const Node *p, const bool is_top = false);
136  void banner();
137 
138  void set_precision();
139 
140  // for debug
141  void traverse(const Node *p, const std::string& indent = "");
142 
143 
145 
147 
148  // for test result verification
150 
151  // for statistics report
153 };
154 #endif // TEST_MANAGER_H