FileTests.cpp
Go to the documentation of this file.
00001 // -*- C++ -*-
00012 /*
00013  * $Log$
00014  *
00015  */
00016 
00017 #ifndef File_cpp
00018 #define File_cpp
00019 
00020 #include <string.h>
00021 #include <string>
00022 #include <cppunit/ui/text/TestRunner.h>
00023 #include <cppunit/TextOutputter.h>
00024 #include <cppunit/extensions/TestFactoryRegistry.h>
00025 #include <cppunit/extensions/HelperMacros.h>
00026 #include <cppunit/TestAssert.h>
00027 #include <coil/File.h>
00028 
00029 static const std::string Str01("/usr/include/coil");
00030 static const std::string Str02("/usr/include/coil/");
00031 static const std::string Str03("coil");
00032 static const std::string Str04("/");
00033 static const std::string Str05(".");
00034 static const std::string Str06("..");
00035 static const std::string Str07("/usr");
00036 
00041 namespace File
00042 {
00043   class FileTests
00044    : public CppUnit::TestFixture
00045   {
00046     CPPUNIT_TEST_SUITE(FileTests);
00047     CPPUNIT_TEST(test_dirname_01);
00048     CPPUNIT_TEST(test_basename_01);
00049     CPPUNIT_TEST(test_dirname_02);
00050     CPPUNIT_TEST(test_basename_02);
00051     CPPUNIT_TEST(test_dirname_03);
00052     CPPUNIT_TEST(test_basename_03);
00053     CPPUNIT_TEST(test_dirname_04);
00054     CPPUNIT_TEST(test_basename_04);
00055     CPPUNIT_TEST(test_dirname_05);
00056     CPPUNIT_TEST(test_basename_05);
00057     CPPUNIT_TEST(test_dirname_06);
00058     CPPUNIT_TEST(test_basename_06);
00059     CPPUNIT_TEST(test_dirname_07);
00060     CPPUNIT_TEST(test_basename_07);
00061     CPPUNIT_TEST_SUITE_END();
00062   
00063   private:
00064 
00065   public:
00066   
00070     FileTests()
00071     {
00072     }
00073     
00077     ~FileTests()
00078     {
00079     }
00080   
00084     virtual void setUp()
00085     {
00086     }
00087     
00091     virtual void tearDown()
00092     { 
00093     }
00094   
00095     /* test case */
00096     void test_dirname_01()
00097     {
00098       char buff[BUFSIZ];
00099       strcpy(buff, Str01.c_str());
00100 
00101       std::string result = coil::dirname(buff);
00102       std::string expected("/usr/include");
00103       CPPUNIT_ASSERT_EQUAL(expected, result);
00104     }
00105 
00106     void test_basename_01()
00107     {
00108       char buff[BUFSIZ];
00109       strcpy(buff, Str01.c_str());
00110 
00111       std::string result = coil::basename(buff);
00112       std::string expected("coil");
00113       CPPUNIT_ASSERT_EQUAL(expected, result);
00114     }
00115 
00116     void test_dirname_02()
00117     {
00118       char buff[BUFSIZ];
00119       strcpy(buff, Str02.c_str());
00120 
00121       std::string result = coil::dirname(buff);
00122       std::string expected("/usr/include");
00123       CPPUNIT_ASSERT_EQUAL(expected, result);
00124     }
00125 
00126     void test_basename_02()
00127     {
00128       char buff[BUFSIZ];
00129       strcpy(buff, Str02.c_str());
00130 
00131       std::string result = coil::basename(buff);
00132       std::string expected("coil");
00133       CPPUNIT_ASSERT_EQUAL(expected, result);
00134     }
00135 
00136     void test_dirname_03()
00137     {
00138       char buff[BUFSIZ];
00139       strcpy(buff, Str03.c_str());
00140 
00141       std::string result = coil::dirname(buff);
00142       std::string expected(".");
00143       CPPUNIT_ASSERT_EQUAL(expected, result);
00144     }
00145 
00146     void test_basename_03()
00147     {
00148       char buff[BUFSIZ];
00149       strcpy(buff, Str03.c_str());
00150 
00151       std::string result = coil::basename(buff);
00152       std::string expected("coil");
00153       CPPUNIT_ASSERT_EQUAL(expected, result);
00154     }
00155 
00156     void test_dirname_04()
00157     {
00158       char buff[BUFSIZ];
00159       strcpy(buff, Str04.c_str());
00160 
00161       std::string result = coil::dirname(buff);
00162       std::string expected("/");
00163       CPPUNIT_ASSERT_EQUAL(expected, result);
00164     }
00165 
00166     void test_basename_04()
00167     {
00168       char buff[BUFSIZ];
00169       strcpy(buff, Str04.c_str());
00170 
00171       std::string result = coil::basename(buff);
00172       std::string expected("/");
00173       CPPUNIT_ASSERT_EQUAL(expected, result);
00174     }
00175 
00176     void test_dirname_05()
00177     {
00178       char buff[BUFSIZ];
00179       strcpy(buff, Str05.c_str());
00180 
00181       std::string result = coil::dirname(buff);
00182       std::string expected(".");
00183       CPPUNIT_ASSERT_EQUAL(expected, result);
00184     }
00185 
00186     void test_basename_05()
00187     {
00188       char buff[BUFSIZ];
00189       strcpy(buff, Str05.c_str());
00190 
00191       std::string result = coil::basename(buff);
00192       std::string expected(".");
00193       CPPUNIT_ASSERT_EQUAL(expected, result);
00194     }
00195 
00196     void test_dirname_06()
00197     {
00198       char buff[BUFSIZ];
00199       strcpy(buff, Str06.c_str());
00200 
00201       std::string result = coil::dirname(buff);
00202       std::string expected(".");
00203       CPPUNIT_ASSERT_EQUAL(expected, result);
00204     }
00205 
00206     void test_basename_06()
00207     {
00208       char buff[BUFSIZ];
00209       strcpy(buff, Str06.c_str());
00210 
00211       std::string result = coil::basename(buff);
00212       std::string expected("..");
00213       CPPUNIT_ASSERT_EQUAL(expected, result);
00214     }
00215 
00216     void test_dirname_07()
00217     {
00218       char buff[BUFSIZ];
00219       strcpy(buff, Str07.c_str());
00220 
00221       std::string result = coil::dirname(buff);
00222       std::string expected("/");
00223       CPPUNIT_ASSERT_EQUAL(expected, result);
00224     }
00225 
00226     void test_basename_07()
00227     {
00228       char buff[BUFSIZ];
00229       strcpy(buff, Str07.c_str());
00230 
00231       std::string result = coil::basename(buff);
00232       std::string expected("usr");
00233       CPPUNIT_ASSERT_EQUAL(expected, result);
00234     }
00235 
00236   };
00237 }; // namespace File
00238 
00239 /*
00240  * Register test suite
00241  */
00242 CPPUNIT_TEST_SUITE_REGISTRATION(File::FileTests);
00243 
00244 #ifdef LOCAL_MAIN
00245 int main(int argc, char* argv[])
00246 {
00247     CppUnit::TextUi::TestRunner runner;
00248     runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
00249     CppUnit::Outputter* outputter = 
00250       new CppUnit::TextOutputter(&runner.result(), std::cout);
00251     runner.setOutputter(outputter);
00252     bool retcode = runner.run();
00253     return !retcode;
00254 }
00255 #endif // MAIN
00256 #endif // File_cpp


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Thu Aug 27 2015 14:16:37