FileTests.cpp
Go to the documentation of this file.
1 // -*- C++ -*-
12 /*
13  * $Log$
14  *
15  */
16 
17 #ifndef File_cpp
18 #define File_cpp
19 
20 #include <string.h>
21 #include <string>
22 #include <cppunit/ui/text/TestRunner.h>
23 #include <cppunit/TextOutputter.h>
24 #include <cppunit/extensions/TestFactoryRegistry.h>
25 #include <cppunit/extensions/HelperMacros.h>
26 #include <cppunit/TestAssert.h>
27 #include <coil/File.h>
28 
29 static const std::string Str01("/usr/include/coil");
30 static const std::string Str02("/usr/include/coil/");
31 static const std::string Str03("coil");
32 static const std::string Str04("/");
33 static const std::string Str05(".");
34 static const std::string Str06("..");
35 static const std::string Str07("/usr");
36 
41 namespace File
42 {
43  class FileTests
44  : public CppUnit::TestFixture
45  {
62 
63  private:
64 
65  public:
66 
71  {
72  }
73 
78  {
79  }
80 
84  virtual void setUp()
85  {
86  }
87 
91  virtual void tearDown()
92  {
93  }
94 
95  /* test case */
97  {
98  char buff[BUFSIZ];
99  strcpy(buff, Str01.c_str());
100 
101  std::string result = coil::dirname(buff);
102  std::string expected("/usr/include");
103  CPPUNIT_ASSERT_EQUAL(expected, result);
104  }
105 
107  {
108  char buff[BUFSIZ];
109  strcpy(buff, Str01.c_str());
110 
111  std::string result = coil::basename(buff);
112  std::string expected("coil");
113  CPPUNIT_ASSERT_EQUAL(expected, result);
114  }
115 
117  {
118  char buff[BUFSIZ];
119  strcpy(buff, Str02.c_str());
120 
121  std::string result = coil::dirname(buff);
122  std::string expected("/usr/include");
123  CPPUNIT_ASSERT_EQUAL(expected, result);
124  }
125 
127  {
128  char buff[BUFSIZ];
129  strcpy(buff, Str02.c_str());
130 
131  std::string result = coil::basename(buff);
132  std::string expected("coil");
133  CPPUNIT_ASSERT_EQUAL(expected, result);
134  }
135 
137  {
138  char buff[BUFSIZ];
139  strcpy(buff, Str03.c_str());
140 
141  std::string result = coil::dirname(buff);
142  std::string expected(".");
143  CPPUNIT_ASSERT_EQUAL(expected, result);
144  }
145 
147  {
148  char buff[BUFSIZ];
149  strcpy(buff, Str03.c_str());
150 
151  std::string result = coil::basename(buff);
152  std::string expected("coil");
153  CPPUNIT_ASSERT_EQUAL(expected, result);
154  }
155 
157  {
158  char buff[BUFSIZ];
159  strcpy(buff, Str04.c_str());
160 
161  std::string result = coil::dirname(buff);
162  std::string expected("/");
163  CPPUNIT_ASSERT_EQUAL(expected, result);
164  }
165 
167  {
168  char buff[BUFSIZ];
169  strcpy(buff, Str04.c_str());
170 
171  std::string result = coil::basename(buff);
172  std::string expected("/");
173  CPPUNIT_ASSERT_EQUAL(expected, result);
174  }
175 
177  {
178  char buff[BUFSIZ];
179  strcpy(buff, Str05.c_str());
180 
181  std::string result = coil::dirname(buff);
182  std::string expected(".");
183  CPPUNIT_ASSERT_EQUAL(expected, result);
184  }
185 
187  {
188  char buff[BUFSIZ];
189  strcpy(buff, Str05.c_str());
190 
191  std::string result = coil::basename(buff);
192  std::string expected(".");
193  CPPUNIT_ASSERT_EQUAL(expected, result);
194  }
195 
197  {
198  char buff[BUFSIZ];
199  strcpy(buff, Str06.c_str());
200 
201  std::string result = coil::dirname(buff);
202  std::string expected(".");
203  CPPUNIT_ASSERT_EQUAL(expected, result);
204  }
205 
207  {
208  char buff[BUFSIZ];
209  strcpy(buff, Str06.c_str());
210 
211  std::string result = coil::basename(buff);
212  std::string expected("..");
213  CPPUNIT_ASSERT_EQUAL(expected, result);
214  }
215 
217  {
218  char buff[BUFSIZ];
219  strcpy(buff, Str07.c_str());
220 
221  std::string result = coil::dirname(buff);
222  std::string expected("/");
223  CPPUNIT_ASSERT_EQUAL(expected, result);
224  }
225 
227  {
228  char buff[BUFSIZ];
229  strcpy(buff, Str07.c_str());
230 
231  std::string result = coil::basename(buff);
232  std::string expected("usr");
233  CPPUNIT_ASSERT_EQUAL(expected, result);
234  }
235 
236  };
237 }; // namespace File
238 
239 /*
240  * Register test suite
241  */
243 
244 #ifdef LOCAL_MAIN
245 int main(int argc, char* argv[])
246 {
247  CppUnit::TextUi::TestRunner runner;
248  runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
249  CppUnit::Outputter* outputter =
250  new CppUnit::TextOutputter(&runner.result(), std::cout);
251  runner.setOutputter(outputter);
252  bool retcode = runner.run();
253  return !retcode;
254 }
255 #endif // MAIN
256 #endif // File_cpp
void test_dirname_06()
Definition: FileTests.cpp:196
int main(int argc, char **argv)
static const std::string Str04("/")
CPPUNIT_TEST_SUITE(FileTests)
void test_dirname_01()
Definition: FileTests.cpp:96
void test_dirname_04()
Definition: FileTests.cpp:156
static const std::string Str03("coil")
static const std::string Str05(".")
void test_dirname_03()
Definition: FileTests.cpp:136
void test_dirname_05()
Definition: FileTests.cpp:176
CPPUNIT_TEST_SUITE_REGISTRATION(File::FileTests)
~FileTests()
Destructor.
Definition: FileTests.cpp:77
static const std::string Str07("/usr")
void test_basename_05()
Definition: FileTests.cpp:186
static const std::string Str02("/usr/include/coil/")
static const std::string Str01("/usr/include/coil")
void test_basename_03()
Definition: FileTests.cpp:146
FileTests()
Constructor.
Definition: FileTests.cpp:70
virtual void tearDown()
Test finalization.
Definition: FileTests.cpp:91
static const std::string Str06("..")
void test_basename_01()
Definition: FileTests.cpp:106
void test_basename_04()
Definition: FileTests.cpp:166
void test_dirname_07()
Definition: FileTests.cpp:216
void test_dirname_02()
Definition: FileTests.cpp:116
CPPUNIT_TEST(test_dirname_01)
const char * basename(const char *path)
Get a file name part than a file pass.
Definition: ace/coil/File.h:33
virtual void setUp()
Test initialization.
Definition: FileTests.cpp:84
void test_basename_02()
Definition: FileTests.cpp:126
void test_basename_06()
Definition: FileTests.cpp:206
void test_basename_07()
Definition: FileTests.cpp:226
const char * dirname(const char *path)
Definition: ace/coil/File.h:28


openrtm_aist
Author(s): Noriaki Ando
autogenerated on Mon Jun 10 2019 14:07:52