setuptest.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # @file setuptest.py
00004 # @brief CppUnit test environment setup script
00005 # @date $Date: 2008-02-29 04:50:54 $
00006 # @author Norkai Ando <n-ando@aist.go.jp>
00007 #
00008 # Copyright (C) 2006
00009 #     Noriaki Ando
00010 #     Task-intelligence Research Group,
00011 #     Intelligent Systems Research Institute,
00012 #     National Institute of
00013 #         Advanced Industrial Science and Technology (AIST), Japan
00014 #     All rights reserved.
00015 #
00016 # $Id: setuptest.py 775 2008-07-28 16:14:45Z n-ando $
00017 #
00018 # [usage]
00019 # setuptest.py [class_name]
00020 #
00021 # 1. make test class file and Makefile.am
00022 # > setuptest.py
00023 # " Hoge/Makefile.am " was generated.
00024 # " Hoge/HogeTests.cpp " was generated.
00025 #
00026 # 2. add Makefile entry into the configure.ac
00027 # > vi configure.ac
00028 #------------------------------------------------------------
00029 # AC_OUTPUT([Makefile
00030 #            _test_dir_/Hoge/Makefile <- add this entry
00031 #           ])
00032 #------------------------------------------------------------
00033 # 2.5 add dubsir entry to parent dir's Makefile.am
00034 #
00035 # 3. autoreconf and configure again
00036 # autoreconf generate Makefile.in
00037 # configure generate Makefile
00038 #
00039 # 4. buid test
00040 # > cd  _test_dir_/Hoge
00041 # > make
00042 # > ./HogeTests
00043 #
00044 # done
00045 
00046 import sys
00047 import os
00048 import yat
00049 
00050 makefile_am = """# -*- Makefile -*-
00051 #------------------------------------------------------------
00052 # @file   Makefile.am
00053 # @brief  Makefile.am for [class_name] unit test
00054 # @date   [dollar]Date[dollar]
00055 
00056 # @author Noriaki Ando <n-ando@aist.go.jp>
00057 #
00058 # [dollar]Id[dollar]
00059 
00060 #
00061 #------------------------------------------------------------
00062 
00063 #
00064 # [dollar]Log[dollar]
00065 
00066 #
00067 
00068 
00069 AUTOMAKE_OPTIONS = 1.9
00070 
00071 IDLC = @IDLC@
00072 IDLFLAGS = @IDL_FLAGS@
00073 LIBS = @LIBS@
00074 
00075 open_rtm_dir = [dollar](top_builddir)/../../../../..
00076 target_srcdir = [dollar](top_builddir)/..
00077 
00078 AM_CPPFLAGS = -I.
00079 AM_CPPFLAGS += -I[dollar](includedir)
00080 AM_CPPFLAGS += -I[dollar](target_srcdir)
00081 AM_CPPFLAGS += -I[dollar](open_rtm_dir)
00082 AM_CPPFLAGS += -I[dollar](open_rtm_dir)/rtc/corba/idl
00083 
00084 AM_LDFLAGS = -L.
00085 AM_LDFLAGS += -L[dollar](open_rtm_dir)/coil/lib
00086 
00087 IDL_SOURCES = [dollar](open_rtm_dir)/rtc/corba/idl/SDOPackage.idl
00088 IDL_SOURCES += [dollar](open_rtm_dir)/rtc/corba/idl/RTC.idl
00089 IDL_SOURCES += [dollar](open_rtm_dir)/rtc/corba/idl/OpenRTM.idl
00090 
00091 noinst_PROGRAMS = [class_name]Tests
00092 
00093 [class_name]Tests_SOURCES = ../TestRunner.cpp
00094 [class_name]Tests_SOURCES += [class_name]Tests.cpp
00095 [class_name]Tests_SOURCES += [dollar](IDL_SOURCES:.idl=Stub.cpp)
00096 [class_name]Tests_SOURCES += [dollar](open_rtm_dir)/doil/ORBManager.cpp
00097 [class_name]Tests_SOURCES += [dollar](open_rtm_dir)/doil/corba/CORBAManager.cpp
00098 
00099 [class_name]Tests_LDFLAGS = -L[dollar](libdir)
00100 
00101 [class_name]Tests_LDADD   = -lomniORB4
00102 [class_name]Tests_LDADD  += -lomnithread
00103 [class_name]Tests_LDADD  += -lomniDynamic4
00104 [class_name]Tests_LDADD  += -lcoil
00105 #[class_name]Tests_LDADD  += -lcppunit
00106 [class_name]Tests_LDADD  += [dollar](target_srcdir)/[class_name].o
00107 [class_name]Tests_LDADD  += [dollar](target_srcdir)/RTCTypeConversion.o
00108 [class_name]Tests_LDADD  += [dollar](target_srcdir)/SDOPackageTypeConversion.o
00109 
00110 # all
00111 all: do-test
00112 
00113 # do tests
00114 do-test:
00115         ./[class_name]Tests
00116 
00117 # clean-up
00118 clean-local:
00119         rm -f                               \\
00120         *.o *.Po *.gch *.la                 \\
00121         *Skel.cpp *Skel.h *Stub.cpp *Stub.h \\
00122         *~ *core                            \\
00123         Makefile.old                        \\
00124         *.cc *.hh *.i *.a *.c *.inl
00125 
00126 """
00127 
00128 test_cpp = """// -*- C++ -*-
00129 /*!
00130  * @file   [class_name]Tests.cpp
00131  * @brief  [class_name] test class
00132  * @date   [dollar]Date[dollar]
00133  
00134  * @author Noriaki Ando <n-ando@aist.go.jp>
00135  *
00136  * [dollar]Id[dollar]
00137  
00138  *
00139  */
00140 
00141 /*
00142  * [dollar]Log[dollar]
00143 
00144  *
00145  */
00146 
00147 #ifndef [class_name]_cpp
00148 #define [class_name]_cpp
00149 
00150 #include <iostream>
00151 #include <cppunit/ui/text/TestRunner.h>
00152 #include <cppunit/extensions/HelperMacros.h>
00153 #include <cppunit/TestAssert.h>
00154 #include <doil/ImplBase.h>
00155 
00156 /*!
00157  * @class [class_name] Local Implementation class.
00158  * @brief [class_name] test.
00159  */
00160 
00161 /*!
00162  * @class [class_name]Tests class
00163  * @brief [class_name] test
00164  */
00165 namespace [class_name]
00166 
00167 {
00168   class [class_name]Tests
00169    : public CppUnit::TestFixture
00170   {
00171     CPPUNIT_TEST_SUITE([class_name]Tests);
00172     CPPUNIT_TEST(test_case0);
00173     CPPUNIT_TEST_SUITE_END();
00174   
00175   private:
00176   
00177   public:
00178   
00179     /*!
00180      * @brief Constructor
00181      */
00182     [class_name]Tests()
00183     {
00184     }
00185     
00186     /*!
00187      * @brief Destructor
00188      */
00189     ~[class_name]Tests()
00190     {
00191     }
00192   
00193     /*!
00194      * @brief Test initialization
00195      */
00196     virtual void setUp()
00197     {
00198     }
00199     
00200     /*!
00201      * @brief Test finalization
00202      */
00203     virtual void tearDown()
00204     { 
00205     }
00206   
00207     /* test case */
00208     void test_case0()
00209     {
00210       CPPUNIT_FAIL("Automatic failue.");
00211     }
00212   };
00213 }; // namespace [class_name]
00214 
00215 
00216 /*
00217  * Register test suite
00218  */
00219 CPPUNIT_TEST_SUITE_REGISTRATION([class_name]::[class_name]Tests);
00220 
00221 #ifdef LOCAL_MAIN
00222 int main(int argc, char* argv[])
00223 {
00224     CppUnit::TextUi::TestRunner runner;
00225     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00226     CppUnit::Outputter* outputter = 
00227       new CppUnit::TextOutputter(&runner.result(), std::cout);
00228     runner.setOutputter(outputter);
00229     bool retcode = runner.run();
00230     return !retcode;
00231 }
00232 #endif // MAIN
00233 #endif // [class_name]_cpp
00234 """
00235 
00236 
00237 class test_dict:
00238     def __init__(self, classname):
00239         self.data = {}
00240         self.data["dollar"] = "$"
00241         self.data["class_name"] = classname
00242         self.data["makefile"]   = classname + "/Makefile.am"
00243         self.data["testcpp"]    = classname + "/" + classname + "Tests.cpp"
00244         return
00245     def get_dict(self):
00246         return self.data
00247     
00248 
00249 class test_gen:
00250     def __init__(self, data):
00251         self.data = data
00252         return
00253     
00254     def gen(self, fname, temp_txt, data):
00255         f = file(fname, "w")
00256         t = yat.Template(temp_txt)
00257         #t.parse(temp_txt)
00258         text=t.generate(data)
00259         f.write(text)
00260         f.close()
00261         print "\"", fname, "\"" " was generated."
00262         return
00263 
00264     def gen_all(self):
00265         self.write_makefile()
00266         self.write_testcpp()
00267         return
00268 
00269     def write_makefile(self):
00270         self.gen(self.data["makefile"], makefile_am, self.data)
00271         return
00272 
00273     def write_testcpp(self):
00274         self.gen(self.data["testcpp"], test_cpp, self.data)
00275         return
00276 
00277 
00278 if len(sys.argv) < 2:
00279     sys.exit(1)
00280 
00281 class_name = sys.argv[1]
00282 try:
00283     os.mkdir(class_name, 0755)
00284 except:
00285     print "Directory \"" + class_name + "\" already exists."
00286     sys.exit(1)
00287 
00288 data = test_dict(class_name)
00289 gen  = test_gen(data.get_dict())
00290 gen.gen_all()


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Sat Jun 8 2019 18:49:07