testFileName.cc
Go to the documentation of this file.
1 
11 // header for unit test testFileName
12 
13 #include <string>
14 #include <boost/filesystem/path.hpp>
15 #include <boost/version.hpp>
16 #include <cppunit/extensions/HelperMacros.h>
17 #include <tst/Verify.h>
18 #include <utl/FileName.h>
19 
20 namespace fs = boost::filesystem;
21 using namespace utl;
22 using namespace tst;
23 using std::string;
24 
25 
29 class testFileName : public CppUnit::TestFixture {
30 
31  CPPUNIT_TEST_SUITE(testFileName);
32  CPPUNIT_TEST(testBareFilePath);
33  CPPUNIT_TEST(testBareFileName);
34  CPPUNIT_TEST(testFileExtension);
35  CPPUNIT_TEST(testAppend);
36  CPPUNIT_TEST_SUITE_END();
37 
38 public:
39  void
41  {
42 #if BOOST_FILESYSTEM_VERSION < 3
43  if (fs::path::default_name_check_writable())
44  fs::path::default_name_check(fs::portable_posix_name);
45 #endif
46  }
47 
48  void tearDown() { }
49 
50  void
52  {
53  string n1("/a/b.q/c.ext");
54  CPPUNIT_ASSERT(BareFilePath(n1).string() == "/a/b.q/c");
55  string n2("/b.q/c.ext");
56  CPPUNIT_ASSERT(BareFilePath(n2).string() == "/b.q/c");
57  string n3("c.ext");
58  CPPUNIT_ASSERT(BareFilePath(n3).string() == "c");
59  string n4("c");
60  CPPUNIT_ASSERT(BareFilePath(n4).string() == "c");
61  string n5("/b.q/c");
62  CPPUNIT_ASSERT(BareFilePath(n5).string() == "/b.q/c");
63  string n6("/b.q/.ext");
64  CPPUNIT_ASSERT(BareFilePath(n6).string() == "/b.q");
65  string n7("a.q/c.ext");
66  CPPUNIT_ASSERT(BareFilePath(n7).string() == "a.q/c");
67  string n8("a.q/c");
68  CPPUNIT_ASSERT(BareFilePath(n8).string() == "a.q/c");
69  }
70 
71  void
73  {
74  string n1("/a/b.q/c.ext");
75  CPPUNIT_ASSERT(BareFileName(n1) == "c");
76  string n2("/b.q/c.ext");
77  CPPUNIT_ASSERT(BareFileName(n2) == "c");
78  string n3("c.ext");
79  CPPUNIT_ASSERT(BareFileName(n3) == "c");
80  string n4("c");
81  CPPUNIT_ASSERT(BareFileName(n4) == "c");
82  string n5("/b.q/c");
83  CPPUNIT_ASSERT(BareFileName(n5) == "c");
84  string n6("/b.q/.ext");
85  CPPUNIT_ASSERT(BareFileName(n6) == "");
86  string n7("a.q/c.ext");
87  CPPUNIT_ASSERT(BareFileName(n7) == "c");
88  string n8("a.q/c");
89  CPPUNIT_ASSERT(BareFileName(n8) == "c");
90  }
91 
92  void
94  {
95  string n1("/a/b.q/c.ext");
96  CPPUNIT_ASSERT(FileExtension(n1) == ".ext");
97  string n2("/b.q/c.ext");
98  CPPUNIT_ASSERT(FileExtension(n2) == ".ext");
99  string n3("c.ext");
100  CPPUNIT_ASSERT(FileExtension(n3) == ".ext");
101  string n4("c");
102  CPPUNIT_ASSERT(FileExtension(n4) == "");
103  string n5("/b.q/c");
104  CPPUNIT_ASSERT(FileExtension(n5) == "");
105  string n6("/b.q/.ext");
106  CPPUNIT_ASSERT(FileExtension(n6) == ".ext");
107  string n7("a.q/c.ext");
108  CPPUNIT_ASSERT(FileExtension(n7) == ".ext");
109  string n8("a.q/c");
110  CPPUNIT_ASSERT(FileExtension(n8) == "");
111  }
112 
113  void
115  {
116  fs::path p1("/a/b.q/c");
117 
118  std::cout << "============= " << (p1+".ext").string() << std::endl;
119 
120  CPPUNIT_ASSERT((p1+".ext").string() == "/a/b.q/c.ext");
121 //#warning test disabled since it makes no sense
122  //fs::path p2("/a/b.q/");
123  //CPPUNIT_ASSERT(Verify<Equal>((p2+".ext").string(), string("/a/b.q.ext")));
124  fs::path p3("");
125  CPPUNIT_ASSERT((p3+".ext").string() == ".ext");
126  }
127 
128 };
129 
130 
132 
133 
134 // Configure (x)emacs for this file ...
135 // Local Variables:
136 // mode:c++
137 // compile-command: "make -C .. -k testFileSystem && ../testFileSystem"
138 // End:
void testAppend()
void testBareFileName()
Definition: testFileName.cc:72
std::string BareFileName(const fs::path &thePath)
Definition: FileName.cc:46
fs::path BareFilePath(const fs::path &thePath)
Definition: FileName.cc:33
CPPUNIT_TEST_SUITE_REGISTRATION(testAiresShowerFile)
void testBareFilePath()
Definition: testFileName.cc:51
void testFileExtension()
Definition: testFileName.cc:93
void tearDown()
Definition: testFileName.cc:48
std::string FileExtension(const fs::path &thePath)
Definition: FileName.cc:58

, generated on Tue Sep 26 2023.