coil/build/setuptest.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #
3 # @file setuptest.py
4 # @brief CppUnit test environment setup script
5 # @date $Date: 2008-02-29 04:50:54 $
6 # @author Norkai Ando <n-ando@aist.go.jp>
7 #
8 # Copyright (C) 2006
9 # Noriaki Ando
10 # Task-intelligence Research Group,
11 # Intelligent Systems Research Institute,
12 # National Institute of
13 # Advanced Industrial Science and Technology (AIST), Japan
14 # All rights reserved.
15 #
16 # $Id: setuptest.py 775 2008-07-28 16:14:45Z n-ando $
17 #
18 # [usage]
19 # setuptest.py [class_name]
20 #
21 # 1. make test class file and Makefile.am
22 # > setuptest.py
23 # " Hoge/Makefile.am " was generated.
24 # " Hoge/HogeTests.cpp " was generated.
25 #
26 # 2. add Makefile entry into the configure.ac
27 # > vi configure.ac
28 #------------------------------------------------------------
29 # AC_OUTPUT([Makefile
30 # _test_dir_/Hoge/Makefile <- add this entry
31 # ])
32 #------------------------------------------------------------
33 # 2.5 add dubsir entry to parent dir's Makefile.am
34 #
35 # 3. autoreconf and configure again
36 # autoreconf generate Makefile.in
37 # configure generate Makefile
38 #
39 # 4. buid test
40 # > cd _test_dir_/Hoge
41 # > make
42 # > ./HogeTests
43 #
44 # done
45 
46 import sys
47 import os
48 import yat
49 
50 makefile_am = """# -*- Makefile -*-
51 #------------------------------------------------------------
52 # @file Makefile.am
53 # @brief Makefile.am for [class_name] unit test
54 # @date [dollar]Date[dollar]
55 
56 # @author Noriaki Ando <n-ando@aist.go.jp>
57 #
58 # [dollar]Id[dollar]
59 
60 #
61 #------------------------------------------------------------
62 
63 #
64 # [dollar]Log[dollar]
65 
66 #
67 
68 
69 AUTOMAKE_OPTIONS = 1.9
70 
71 AM_CPPFLAGS= -I. \\
72  -I$(includedir) \\
73  -I$(top_builddir)
74 
75 AM_LDFLAGS= -L. \\
76  -L$(top_builddir)
77 
78 
79 noinst_PROGRAMS = [class_name]Tests
80 
81 [class_name]Tests_SOURCES = ../TestRunner.cpp [class_name]Tests.cpp
82 [class_name]Tests_LDFLAGS = -L$(libdir)
83 [class_name]Tests_LDADD = -lcppunit
84 
85 TEST_SRC = [dollar]([class_name]Tests_SOURCES)
86 TEST_H =
87 
88 # all
89 all: do-test
90 
91 # do tests
92 do-test:
93  ./[class_name]Tests
94 
95 # clean-up
96 clean-local:
97  rm -f *.o *.Po *.gch *.la
98  rm -f *~ *core
99  rm -f *.xml
100  rm -f Makefile.old
101  rm -f *.vcproj
102  rm -rf Release Debug
103 
104 #------------------------------------------------------------
105 # vcproj file build rules
106 #------------------------------------------------------------
107 win32_builddir = .
108 
109 vcproj: [class_name]_vc8.vcproj [class_name]_vc9.vcproj
110 
111 [class_name]_vc8.vcproj:
112  $(top_builddir)/build/vcprojtool.py vcproj \\
113  --projectname [class_name]Test \\
114  --type EXE \\
115  --vcversion "8.00" \\
116  --version $(COIL_VERSION) \\
117  --out $(win32_builddir)/[class_name]_vc8.vcproj \\
118  --yaml ../coil_test.vcproj.yaml \\
119  --source $(TEST_SRC)
120 # --header $(TEST_H)
121  qkc -sm $(win32_builddir)/[class_name]_vc8.vcproj
122 
123 [class_name]_vc9.vcproj:
124  $(top_builddir)/build/vcprojtool.py vcproj \\
125  --projectname [class_name]Test \\
126  --type EXE \\
127  --vcversion "9.00" \\
128  --version $(COIL_VERSION) \\
129  --out $(win32_builddir)/[class_name]_vc9.vcproj \\
130  --yaml ../coil_test.vcproj.yaml \\
131  --source $(TEST_SRC)
132 # --header $(TEST_H)
133  qkc -sm $(win32_builddir)/[class_name]_vc9.vcproj
134 
135 
136 """
137 
138 test_cpp = """// -*- C++ -*-
139 /*!
140  * @file [class_name]Tests.cpp
141  * @brief [class_name] test class
142  * @date [dollar]Date[dollar]
143 
144  * @author Noriaki Ando <n-ando@aist.go.jp>
145  *
146  * [dollar]Id[dollar]
147 
148  *
149  */
150 
151 /*
152  * [dollar]Log[dollar]
153 
154  *
155  */
156 
157 #ifndef [class_name]_cpp
158 #define [class_name]_cpp
159 
160 #include <cppunit/ui/text/TestRunner.h>
161 #include <cppunit/TextOutputter.h>
162 #include <cppunit/extensions/TestFactoryRegistry.h>
163 #include <cppunit/extensions/HelperMacros.h>
164 #include <cppunit/TestAssert.h>
165 
166 /*!
167  * @class [class_name]Tests class
168  * @brief [class_name] test
169  */
170 namespace [class_name]
171 
172 {
173  class [class_name]Tests
174  : public CppUnit::TestFixture
175  {
176  CPPUNIT_TEST_SUITE([class_name]Tests);
177  CPPUNIT_TEST(test_case0);
178  CPPUNIT_TEST_SUITE_END();
179 
180  private:
181 
182  public:
183 
184  /*!
185  * @brief Constructor
186  */
187  [class_name]Tests()
188  {
189  }
190 
191  /*!
192  * @brief Destructor
193  */
194  ~[class_name]Tests()
195  {
196  }
197 
198  /*!
199  * @brief Test initialization
200  */
201  virtual void setUp()
202  {
203  }
204 
205  /*!
206  * @brief Test finalization
207  */
208  virtual void tearDown()
209  {
210  }
211 
212  /* test case */
213  void test_case0()
214  {
215  }
216  };
217 }; // namespace [class_name]
218 
219 
220 /*
221  * Register test suite
222  */
223 CPPUNIT_TEST_SUITE_REGISTRATION([class_name]::[class_name]Tests);
224 
225 #ifdef LOCAL_MAIN
226 int main(int argc, char* argv[])
227 {
228  CppUnit::TextUi::TestRunner runner;
229  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
230  CppUnit::Outputter* outputter =
231  new CppUnit::TextOutputter(&runner.result(), std::cout);
232  runner.setOutputter(outputter);
233  bool retcode = runner.run();
234  return !retcode;
235 }
236 #endif // MAIN
237 #endif // [class_name]_cpp
238 """
239 
240 
241 class test_dict:
242  def __init__(self, classname):
243  self.data = {}
244  self.data["dollar"] = "$"
245  self.data["class_name"] = classname
246  self.data["makefile"] = classname + "/Makefile.am"
247  self.data["testcpp"] = classname + "/" + classname + "Tests.cpp"
248  return
249  def get_dict(self):
250  return self.data
251 
252 
253 class test_gen:
254  def __init__(self, data):
255  self.data = data
256  return
257 
258  def gen(self, fname, temp_txt, data):
259  f = file(fname, "w")
260  t = yat.Template(temp_txt)
261  #t.parse(temp_txt)
262  text=t.generate(data)
263  f.write(text)
264  f.close()
265  print "\"", fname, "\"" " was generated."
266  return
267 
268  def gen_all(self):
269  self.write_makefile()
270  self.write_testcpp()
271  return
272 
273  def write_makefile(self):
274  self.gen(self.data["makefile"], makefile_am, self.data)
275  return
276 
277  def write_testcpp(self):
278  self.gen(self.data["testcpp"], test_cpp, self.data)
279  return
280 
281 
282 if len(sys.argv) < 2:
283  sys.exit(1)
284 
285 class_name = sys.argv[1]
286 try:
287  os.mkdir(class_name, 0755)
288 except:
289  print "Directory \"" + class_name + "\" already exists."
290  sys.exit(1)
291 
292 data = test_dict(class_name)
293 gen = test_gen(data.get_dict())
294 gen.gen_all()
def gen(self, fname, temp_txt, data)
def __init__(self, data)
def __init__(self, classname)


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Jun 6 2019 19:26:00