2 #include <gtest/gtest.h>
\r
6 // Expects that C:\Temp exists for creating temporary testing files.
\r
9 // paths::normalize() with rel path returns drive letter? how to test?
\r
10 // paths::GetLongPath() - how to test?
\r
11 // paths::GetPairComparability() tests
\r
12 // paths::IsShortcut() how to test so that test data is in SVN?
\r
13 // ExpandShortcut() how to test so that test data is in SVN?
\r
14 // paths::EnsurePathExist() tests
\r
19 // The fixture for testing paths functions.
\r
20 class PathTest : public testing::Test
\r
23 // You can remove any or all of the following functions if its body
\r
28 // You can do set-up work for each test here.
\r
33 // You can do clean-up work that doesn't throw exceptions here.
\r
36 // If the constructor and destructor are not enough for setting up
\r
37 // and cleaning up each test, you can define the following methods:
\r
39 virtual void SetUp()
\r
41 // Code here will be called immediately after the constructor (right
\r
42 // before each test).
\r
45 virtual void TearDown()
\r
47 // Code here will be called immediately after each test (right
\r
48 // before the destructor).
\r
51 // Objects declared here can be used by all tests in the test case for Foo.
\r
54 //*************************
\r
55 // paths::EndsWithSlash()
\r
56 //*************************
\r
58 TEST_F(PathTest, EndsWithSlash_rootfolders)
\r
60 const TCHAR path[] = _T("c:");
\r
61 const TCHAR path2[] = _T("c:\\");
\r
62 EXPECT_FALSE(paths::EndsWithSlash(path));
\r
63 EXPECT_TRUE(paths::EndsWithSlash(path2));
\r
66 TEST_F(PathTest, EndsWithSlash_shortfolders)
\r
68 const TCHAR path[] = _T("c:\\path");
\r
69 const TCHAR path2[] = _T("c:\\path\\");
\r
70 EXPECT_FALSE(paths::EndsWithSlash(path));
\r
71 EXPECT_TRUE(paths::EndsWithSlash(path2));
\r
74 TEST_F(PathTest, EndsWithSlash_relfolders)
\r
76 const TCHAR path[] = _T("\\path");
\r
77 const TCHAR path2[] = _T("\\path\\");
\r
78 EXPECT_FALSE(paths::EndsWithSlash(path));
\r
79 EXPECT_TRUE(paths::EndsWithSlash(path2));
\r
82 //*************************
\r
83 // paths::DoesPathExist()
\r
84 //*************************
\r
86 TEST_F(PathTest, Exists_specialfolders)
\r
88 const TCHAR path[] = _T(".");
\r
89 const TCHAR path2[] = _T("..");
\r
90 EXPECT_EQ(paths::IS_EXISTING_DIR, paths::DoesPathExist(path));
\r
91 EXPECT_EQ(paths::IS_EXISTING_DIR, paths::DoesPathExist(path2));
\r
93 TEST_F(PathTest, Exists_files)
\r
95 TCHAR path[_MAX_PATH];
\r
96 const TCHAR path2[] = _T("notfound.txt");
\r
97 GetModuleFileName(NULL, path, sizeof(path));
\r
98 EXPECT_EQ(paths::IS_EXISTING_FILE, paths::DoesPathExist(path));
\r
99 EXPECT_EQ(paths::DOES_NOT_EXIST, paths::DoesPathExist(path2));
\r
101 TEST_F(PathTest, Exists_relfolder)
\r
103 const TCHAR path[] = _T("..\\");
\r
104 const TCHAR path2[] = _T("..\\Paths");
\r
105 EXPECT_EQ(paths::IS_EXISTING_DIR, paths::DoesPathExist(path));
\r
106 EXPECT_EQ(paths::IS_EXISTING_DIR, paths::DoesPathExist(path2));
\r
108 TEST_F(PathTest, Exists_relfiles)
\r
110 const TCHAR path[] = _T(".\\..\\Paths\\paths_test.cpp");
\r
111 const TCHAR path2[] = _T("..\\Paths\\paths_test.cpp");
\r
112 EXPECT_EQ(paths::IS_EXISTING_FILE, paths::DoesPathExist(path));
\r
113 EXPECT_EQ(paths::IS_EXISTING_FILE, paths::DoesPathExist(path2));
\r
115 TEST_F(PathTest, Exists_absfolders)
\r
117 const TCHAR path[] = _T("C:");
\r
118 const TCHAR path2[] = _T("C:\\");
\r
119 EXPECT_EQ(paths::IS_EXISTING_DIR, paths::DoesPathExist(path));
\r
120 EXPECT_EQ(paths::IS_EXISTING_DIR, paths::DoesPathExist(path2));
\r
122 TEST_F(PathTest, Exists_absfolders2)
\r
124 const TCHAR path[] = _T("C:\\windows");
\r
125 const TCHAR path2[] = _T("C:\\windows\\");
\r
126 const TCHAR path3[] = _T("C:\\gack");
\r
127 const TCHAR path4[] = _T("C:\\gack\\");
\r
128 EXPECT_EQ(paths::IS_EXISTING_DIR, paths::DoesPathExist(path));
\r
129 EXPECT_EQ(paths::IS_EXISTING_DIR, paths::DoesPathExist(path2));
\r
130 EXPECT_EQ(paths::DOES_NOT_EXIST, paths::DoesPathExist(path3));
\r
131 EXPECT_EQ(paths::DOES_NOT_EXIST, paths::DoesPathExist(path4));
\r
133 TEST_F(PathTest, Exists_absfiles)
\r
135 const TCHAR path1[] = _T("C:\\windows\\notepad.exe");
\r
136 const TCHAR path2[] = _T("C:\\windows\\gack.txt");
\r
137 EXPECT_EQ(paths::IS_EXISTING_FILE, paths::DoesPathExist(path1));
\r
138 EXPECT_EQ(paths::DOES_NOT_EXIST, paths::DoesPathExist(path2));
\r
141 //*************************
\r
142 // paths::FindFileName()
\r
143 //*************************
\r
145 TEST_F(PathTest, FindName_absfiles)
\r
147 TCHAR path[] = _T("c:\\abc.txt");
\r
148 EXPECT_EQ(path + 3, paths::FindFileName(path));
\r
151 TEST_F(PathTest, FindName_absfiles2)
\r
153 TCHAR path[] = _T("c:\\temp\\abc.txt");
\r
154 EXPECT_EQ(path + 8, paths::FindFileName(path));
\r
157 //*************************
\r
158 // paths::normalize()
\r
159 //*************************
\r
161 TEST_F(PathTest, Normalize_abspath)
\r
163 String path = _T("c:\\abc.txt");
\r
164 String path_orig = path;
\r
165 paths::normalize(path);
\r
166 EXPECT_EQ(path_orig, path);
\r
168 TEST_F(PathTest, Normalize_abspath2)
\r
170 String path = _T("c:\\temp\\abc.txt");
\r
171 String path_orig = path;
\r
172 paths::normalize(path);
\r
173 EXPECT_EQ(path_orig, path);
\r
175 TEST_F(PathTest, Normalize_abspath3)
\r
177 TCHAR curdir[_MAX_PATH];
\r
178 GetCurrentDirectory(sizeof(curdir), curdir);
\r
179 String path(curdir, 2);
\r
180 String path_orig = curdir;
\r
181 paths::normalize(path);
\r
182 EXPECT_EQ(path_orig, path);
\r
185 TEST_F(PathTest, Normalize_abspath4)
\r
187 String path = _T("c:\\");
\r
188 String path_orig = path;
\r
189 paths::normalize(path);
\r
190 EXPECT_EQ(path_orig, path);
\r
192 TEST_F(PathTest, Normalize_abspath5)
\r
194 String path = _T("c:\\Temp\\");
\r
195 String path_orig = _T("c:\\Temp");
\r
196 paths::normalize(path);
\r
197 EXPECT_EQ(path_orig, path);
\r
200 //*************************
\r
201 // paths::CreateIfNeeded()
\r
202 //*************************
\r
204 TEST_F(PathTest, Create_abspath1)
\r
206 EXPECT_TRUE(paths::CreateIfNeeded(_T("c:\\Temp")));
\r
208 TEST_F(PathTest, Create_abspath2)
\r
210 EXPECT_TRUE(paths::CreateIfNeeded(_T("c:\\Temp\\wm_test")));
\r
211 EXPECT_EQ(0, _taccess(_T("c:\\Temp\\wm_test"), 0));
\r
213 TEST_F(PathTest, Create_abspath3)
\r
215 EXPECT_TRUE(paths::CreateIfNeeded(_T("c:\\Temp\\wm_test")));
\r
216 EXPECT_EQ(0, _taccess(_T("c:\\Temp\\wm_test"), 0));
\r
217 EXPECT_EQ(0, _trmdir(_T("c:\\Temp\\wm_test")));
\r
218 EXPECT_NE(0, _taccess(_T("c:\\Temp\\wm_test"), 0));
\r
220 TEST_F(PathTest, Create_abspath4)
\r
222 EXPECT_TRUE(paths::CreateIfNeeded(_T("c:\\Temp\\wm_test\\abc\\dce")));
\r
223 EXPECT_EQ(0, _taccess(_T("c:\\Temp\\wm_test\\abc\\dce"), 0));
\r
225 TEST_F(PathTest, Create_abspath5)
\r
227 EXPECT_TRUE(paths::CreateIfNeeded(_T("c:\\Temp\\wm_test\\abc\\dce")));
\r
228 EXPECT_EQ(0, _taccess(_T("c:\\Temp\\wm_test\\abc\\dce"), 0));
\r
229 EXPECT_EQ(0, _trmdir(_T("c:\\Temp\\wm_test\\abc\\dce")));
\r
230 EXPECT_NE(0, _taccess(_T("c:\\Temp\\wm_test\\abc\\dce"), 0));
\r
231 EXPECT_EQ(0, _trmdir(_T("c:\\Temp\\wm_test\\abc")));
\r
232 EXPECT_NE(0, _taccess(_T("c:\\Temp\\wm_test\\abc"), 0));
\r
233 EXPECT_EQ(0, _trmdir(_T("c:\\Temp\\wm_test")));
\r
234 EXPECT_NE(0, _taccess(_T("c:\\Temp\\wm_test"), 0));
\r
237 //*********************
\r
238 // paths::ConcatPath()
\r
239 //*********************
\r
241 TEST_F(PathTest, Concat_abspath1)
\r
243 EXPECT_EQ(_T("c:\\Temp\\wm_test"), paths::ConcatPath(_T("c:\\Temp"), _T("wm_test")));
\r
245 TEST_F(PathTest, Concat_abspath2)
\r
247 EXPECT_EQ(_T("c:\\Temp\\wm_test"), paths::ConcatPath(_T("c:\\Temp\\"), _T("wm_test")));
\r
249 TEST_F(PathTest, Concat_abspath3)
\r
251 EXPECT_EQ(_T("c:\\Temp\\wm_test"), paths::ConcatPath(_T("c:\\Temp"), _T("\\wm_test")));
\r
253 TEST_F(PathTest, Concat_abspath4)
\r
255 EXPECT_EQ(_T("c:\\Temp\\wm_test"), paths::ConcatPath(_T("c:\\Temp\\"), _T("\\wm_test")));
\r
257 TEST_F(PathTest, Concat_relpath1)
\r
259 EXPECT_EQ(_T("\\Temp\\wm_test"), paths::ConcatPath(_T("\\Temp"), _T("wm_test")));
\r
261 TEST_F(PathTest, Concat_relpath2)
\r
263 EXPECT_EQ(_T("\\Temp\\wm_test"), paths::ConcatPath(_T("\\Temp\\"), _T("wm_test")));
\r
265 TEST_F(PathTest, Concat_relpath3)
\r
267 EXPECT_EQ(_T("\\Temp\\wm_test"), paths::ConcatPath(_T("\\Temp"), _T("\\wm_test")));
\r
269 TEST_F(PathTest, Concat_relpath4)
\r
271 EXPECT_EQ(_T("\\Temp\\wm_test"), paths::ConcatPath(_T("\\Temp\\"), _T("\\wm_test")));
\r
273 TEST_F(PathTest, Concat_missingFilename1)
\r
275 EXPECT_EQ(_T("c:\\Temp"), paths::ConcatPath(_T("c:\\Temp"), _T("")));
\r
277 TEST_F(PathTest, Concat_missingFilename2)
\r
279 EXPECT_EQ(_T("\\Temp\\"), paths::ConcatPath(_T("\\Temp\\"), _T("")));
\r
282 //*************************
\r
283 // paths::GetParentPath()
\r
284 //*************************
\r
286 TEST_F(PathTest, Parent_abspath1)
\r
288 EXPECT_EQ(_T("c:\\Temp"), paths::GetParentPath(_T("c:\\Temp\\wm_test")));
\r
290 TEST_F(PathTest, Parent_abspath2)
\r
292 EXPECT_EQ(_T("c:\\Temp\\abc"), paths::GetParentPath(_T("c:\\Temp\\abc\\wm_test")));
\r
296 // paths::GetParentPath(_T("c:\\Temp")) "returns c:"
\r
297 TEST_F(PathTest, Parent_abspath3)
\r
299 EXPECT_EQ(_T("c:\\"), paths::GetParentPath(_T("c:\\Temp")));
\r
303 // paths::GetParentPath(_T("c:\\Temp\\")) "returns c:"
\r
304 TEST_F(PathTest, Parent_abspath4)
\r
306 EXPECT_EQ(_T("c:\\"), paths::GetParentPath(_T("c:\\Temp\\")));
\r
308 TEST_F(PathTest, Parent_relpath1)
\r
310 EXPECT_EQ(_T("\\temp"), paths::GetParentPath(_T("\\temp\\abc")));
\r
312 TEST_F(PathTest, Parent_relpath2)
\r
314 EXPECT_EQ(_T("\\temp\\abc"), paths::GetParentPath(_T("\\temp\\abc\\cde")));
\r
317 //*************************
\r
318 // paths::GetLastSubdir()
\r
319 //*************************
\r
321 TEST_F(PathTest, LastSubdir_abspath1)
\r
323 EXPECT_EQ(_T("\\abc"), paths::GetLastSubdir(_T("c:\\temp\\abc")));
\r
327 // paths::GetLastSubdir(_T("c:\\temp")) returns "c:\\temp"
\r
328 TEST_F(PathTest, LastSubdir_abspath2)
\r
330 EXPECT_EQ(_T("\\temp"), paths::GetLastSubdir(_T("c:\\temp")));
\r
334 // paths::GetLastSubdir(_T("c:\\temp")) returns "c:\\temp"
\r
335 TEST_F(PathTest, LastSubdir_abspath3)
\r
337 EXPECT_EQ(_T("\\temp"), paths::GetLastSubdir(_T("c:\\temp\\")));
\r
339 TEST_F(PathTest, LastSubdir_relpath1)
\r
341 EXPECT_EQ(_T("\\temp"), paths::GetLastSubdir(_T("abc\\temp\\")));
\r
343 TEST_F(PathTest, LastSubdir_relpath2)
\r
345 EXPECT_EQ(_T("\\dce"), paths::GetLastSubdir(_T("abc\\temp\\dce")));
\r
348 //*************************
\r
349 // paths::IsPathAbsolute()
\r
350 //*************************
\r
352 TEST_F(PathTest, IsAbsolute_abspath1)
\r
354 EXPECT_TRUE(paths::IsPathAbsolute(_T("c:\\abc")));
\r
356 TEST_F(PathTest, IsAbsolute_abspath2)
\r
358 EXPECT_TRUE(paths::IsPathAbsolute(_T("c:\\abc\\")));
\r
360 TEST_F(PathTest, IsAbsolute_abspath3)
\r
362 EXPECT_TRUE(paths::IsPathAbsolute(_T("c:\\abc\\cde")));
\r
364 TEST_F(PathTest, IsAbsolute_abspath4)
\r
366 EXPECT_TRUE(paths::IsPathAbsolute(_T("c:\\abc\\cde\\")));
\r
368 TEST_F(PathTest, IsAbsolute_abspath5)
\r
370 EXPECT_TRUE(paths::IsPathAbsolute(_T("c:\\")));
\r
372 TEST_F(PathTest, IsAbsolute_relpath1)
\r
374 EXPECT_FALSE(paths::IsPathAbsolute(_T("\\cde")));
\r
376 TEST_F(PathTest, IsAbsolute_relpath2)
\r
378 EXPECT_FALSE(paths::IsPathAbsolute(_T("\\cde\\")));
\r
380 TEST_F(PathTest, IsAbsolute_relpath3)
\r
382 EXPECT_FALSE(paths::IsPathAbsolute(_T("\\cde\\abd")));
\r
384 TEST_F(PathTest, IsAbsolute_relpath4)
\r
386 EXPECT_FALSE(paths::IsPathAbsolute(_T("\\cde\\abd\\")));
\r
388 TEST_F(PathTest, IsAbsolute_relpath5)
\r
390 EXPECT_FALSE(paths::IsPathAbsolute(_T("cde\\abd")));
\r
393 TEST_F(PathTest, IsAbsolute_relpath6)
\r
395 EXPECT_FALSE(paths::IsPathAbsolute(_T("cde\\abd")));
\r