source: branches/work_320/FileSystemUtilTest.cpp @ 679

Revision 678, 2.4 KB checked in by jls17, 5 years ago (diff)
  • the CombinePathSecondPathStartsWithRootDir2 test could run on all platforms
Line 
1#include "ARInsideTest.h"
2#include "FileSystemUtil.h"
3#include "FileSystemUtilTest.h"
4
5TEST(FileSystemUtil, IsDots_WithDots_Test)
6{
7        ASSERT_EQ(true, FileSystemUtil::IsDots("."));
8        ASSERT_EQ(true, FileSystemUtil::IsDots(".."));
9}
10
11TEST(FileSystemUtil, IsDots_WithoutDots_Test)
12{
13        ASSERT_EQ(false, FileSystemUtil::IsDots("testfile"));
14}
15
16TEST(FileSystemUtil, GetExecutableDirectory)
17{
18        string directory = FileSystemUtil::GetExecutableDirectory(argv_0);
19        directory = FileSystemUtil::GetRealPathName(directory);
20
21        string expectedDir = DIRECTORY_OF_TEST_BINARY;
22#ifdef WIN32
23        expectedDir = CUtil::StrReplace("/","\\", expectedDir);
24        std::transform(directory.begin(), directory.end(), directory.begin(), ::tolower);
25        std::transform(expectedDir.begin(), expectedDir.end(), expectedDir.begin(), ::tolower);
26#endif
27
28        ASSERT_STREQ(expectedDir.c_str(), directory.c_str());
29}
30
31TEST(FileSystemUtil, CombinePathSimpleWithoutSeparator)
32{
33#ifdef WIN32
34        string directory = FileSystemUtil::CombinePath("C:\\Windows", "Temp");
35        ASSERT_STREQ("C:\\Windows\\Temp", directory.c_str());
36#else
37        string directory = FileSystemUtil::CombinePath("/c/Windows", "Temp");
38        ASSERT_STREQ("/c/Windows/Temp", directory.c_str());
39#endif
40}
41
42TEST(FileSystemUtil, CombinePathSimpleWithSeparator)
43{
44#ifdef WIN32
45        string directory = FileSystemUtil::CombinePath("C:\\", "Temp");
46        ASSERT_STREQ("C:\\Temp", directory.c_str());
47#else
48        string directory = FileSystemUtil::CombinePath("/tmp/", "test_dir");
49        ASSERT_STREQ("/tmp/test_dir", directory.c_str());
50#endif
51}
52
53TEST(FileSystemUtil, CombinePathSecondPathStartsWithRootDir)
54{
55#ifdef WIN32
56        string directory = FileSystemUtil::CombinePath("C:\\Windows", "\\Temp");
57        ASSERT_STREQ("\\Temp", directory.c_str());
58#else
59        string directory = FileSystemUtil::CombinePath("/tmp/", "/test_dir");
60        ASSERT_STREQ("/test_dir", directory.c_str());
61#endif
62}
63
64TEST(FileSystemUtil, CombinePathSecondPathStartsWithRootDir2)
65{
66        string directory = FileSystemUtil::CombinePath("C:\\Windows", "/Temp");
67        ASSERT_STREQ("/Temp", directory.c_str());
68}
69
70TEST(FileSystemUtil, CombinePathWithMixedSeparators)
71{
72#ifdef WIN32
73        string directory = FileSystemUtil::CombinePath("C:/Windows/Temp", "MyDir");
74        ASSERT_STREQ("C:/Windows/Temp\\MyDir", directory.c_str());
75#else
76        string directory = FileSystemUtil::CombinePath("/tmp\\", "MyDir");
77        ASSERT_STREQ("/tmp\\/MyDir", directory.c_str());
78#endif
79}
Note: See TracBrowser for help on using the repository browser.