doil/utils/omniidl_be/tests/unitTest/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 IDLC = @IDLC@
72 IDLFLAGS = @IDL_FLAGS@
73 LIBS = @LIBS@
74 
75 open_rtm_dir = [dollar](top_builddir)/../../../../..
76 target_srcdir = [dollar](top_builddir)/..
77 
78 AM_CPPFLAGS = -I.
79 AM_CPPFLAGS += -I[dollar](includedir)
80 AM_CPPFLAGS += -I[dollar](target_srcdir)
81 AM_CPPFLAGS += -I[dollar](open_rtm_dir)
82 AM_CPPFLAGS += -I[dollar](open_rtm_dir)/rtc/corba/idl
83 
84 AM_LDFLAGS = -L.
85 AM_LDFLAGS += -L[dollar](open_rtm_dir)/coil/lib
86 
87 IDL_SOURCES = [dollar](open_rtm_dir)/rtc/corba/idl/SDOPackage.idl
88 IDL_SOURCES += [dollar](open_rtm_dir)/rtc/corba/idl/RTC.idl
89 IDL_SOURCES += [dollar](open_rtm_dir)/rtc/corba/idl/OpenRTM.idl
90 
91 noinst_PROGRAMS = [class_name]Tests
92 
93 [class_name]Tests_SOURCES = ../TestRunner.cpp
94 [class_name]Tests_SOURCES += [class_name]Tests.cpp
95 [class_name]Tests_SOURCES += [dollar](IDL_SOURCES:.idl=Stub.cpp)
96 [class_name]Tests_SOURCES += [dollar](open_rtm_dir)/doil/ORBManager.cpp
97 [class_name]Tests_SOURCES += [dollar](open_rtm_dir)/doil/corba/CORBAManager.cpp
98 
99 [class_name]Tests_LDFLAGS = -L[dollar](libdir)
100 
101 [class_name]Tests_LDADD = -lomniORB4
102 [class_name]Tests_LDADD += -lomnithread
103 [class_name]Tests_LDADD += -lomniDynamic4
104 [class_name]Tests_LDADD += -lcoil
105 #[class_name]Tests_LDADD += -lcppunit
106 [class_name]Tests_LDADD += [dollar](target_srcdir)/[class_name].o
107 [class_name]Tests_LDADD += [dollar](target_srcdir)/RTCTypeConversion.o
108 [class_name]Tests_LDADD += [dollar](target_srcdir)/SDOPackageTypeConversion.o
109 
110 # all
111 all: do-test
112 
113 # do tests
114 do-test:
115  ./[class_name]Tests
116 
117 # clean-up
118 clean-local:
119  rm -f \\
120  *.o *.Po *.gch *.la \\
121  *Skel.cpp *Skel.h *Stub.cpp *Stub.h \\
122  *~ *core \\
123  Makefile.old \\
124  *.cc *.hh *.i *.a *.c *.inl
125 
126 """
127 
128 test_cpp = """// -*- C++ -*-
129 /*!
130  * @file [class_name]Tests.cpp
131  * @brief [class_name] test class
132  * @date [dollar]Date[dollar]
133 
134  * @author Noriaki Ando <n-ando@aist.go.jp>
135  *
136  * [dollar]Id[dollar]
137 
138  *
139  */
140 
141 /*
142  * [dollar]Log[dollar]
143 
144  *
145  */
146 
147 #ifndef [class_name]_cpp
148 #define [class_name]_cpp
149 
150 #include <iostream>
151 #include <cppunit/ui/text/TestRunner.h>
152 #include <cppunit/extensions/HelperMacros.h>
153 #include <cppunit/TestAssert.h>
154 #include <doil/ImplBase.h>
155 
156 /*!
157  * @class [class_name] Local Implementation class.
158  * @brief [class_name] test.
159  */
160 
161 /*!
162  * @class [class_name]Tests class
163  * @brief [class_name] test
164  */
165 namespace [class_name]
166 
167 {
168  class [class_name]Tests
169  : public CppUnit::TestFixture
170  {
171  CPPUNIT_TEST_SUITE([class_name]Tests);
172  CPPUNIT_TEST(test_case0);
173  CPPUNIT_TEST_SUITE_END();
174 
175  private:
176 
177  public:
178 
179  /*!
180  * @brief Constructor
181  */
182  [class_name]Tests()
183  {
184  }
185 
186  /*!
187  * @brief Destructor
188  */
189  ~[class_name]Tests()
190  {
191  }
192 
193  /*!
194  * @brief Test initialization
195  */
196  virtual void setUp()
197  {
198  }
199 
200  /*!
201  * @brief Test finalization
202  */
203  virtual void tearDown()
204  {
205  }
206 
207  /* test case */
208  void test_case0()
209  {
210  CPPUNIT_FAIL("Automatic failue.");
211  }
212  };
213 }; // namespace [class_name]
214 
215 
216 /*
217  * Register test suite
218  */
219 CPPUNIT_TEST_SUITE_REGISTRATION([class_name]::[class_name]Tests);
220 
221 #ifdef LOCAL_MAIN
222 int main(int argc, char* argv[])
223 {
224  CppUnit::TextUi::TestRunner runner;
225  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
226  CppUnit::Outputter* outputter =
227  new CppUnit::TextOutputter(&runner.result(), std::cout);
228  runner.setOutputter(outputter);
229  bool retcode = runner.run();
230  return !retcode;
231 }
232 #endif // MAIN
233 #endif // [class_name]_cpp
234 """
235 
236 
237 class test_dict:
238  def __init__(self, classname):
239  self.data = {}
240  self.data["dollar"] = "$"
241  self.data["class_name"] = classname
242  self.data["makefile"] = classname + "/Makefile.am"
243  self.data["testcpp"] = classname + "/" + classname + "Tests.cpp"
244  return
245  def get_dict(self):
246  return self.data
247 
248 
249 class test_gen:
250  def __init__(self, data):
251  self.data = data
252  return
253 
254  def gen(self, fname, temp_txt, data):
255  f = file(fname, "w")
256  t = yat.Template(temp_txt)
257  #t.parse(temp_txt)
258  text=t.generate(data)
259  f.write(text)
260  f.close()
261  print "\"", fname, "\"" " was generated."
262  return
263 
264  def gen_all(self):
265  self.write_makefile()
266  self.write_testcpp()
267  return
268 
269  def write_makefile(self):
270  self.gen(self.data["makefile"], makefile_am, self.data)
271  return
272 
273  def write_testcpp(self):
274  self.gen(self.data["testcpp"], test_cpp, self.data)
275  return
276 
277 
278 if len(sys.argv) < 2:
279  sys.exit(1)
280 
281 class_name = sys.argv[1]
282 try:
283  os.mkdir(class_name, 0755)
284 except:
285  print "Directory \"" + class_name + "\" already exists."
286  sys.exit(1)
287 
288 data = test_dict(class_name)
289 gen = test_gen(data.get_dict())
290 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 Mon Jun 10 2019 14:07:56