1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
|
#include <cppunit/extensions/HelperMacros.h>
#include "../src/include/local_path.h"
/*
* This testsuite asserts the correctness of the CLocalPathTest class.
*/
class CLocalPathTest final : public CppUnit::TestFixture
{
CPPUNIT_TEST_SUITE(CLocalPathTest);
CPPUNIT_TEST(testSetPath);
CPPUNIT_TEST(testChangePath);
CPPUNIT_TEST(testHasParent);
#ifdef FZ_WINDOWS
CPPUNIT_TEST(testHasLogicalParent);
#endif
CPPUNIT_TEST(testAddSegment);
CPPUNIT_TEST_SUITE_END();
public:
void setUp() {}
void tearDown() {}
void testSetPath();
void testChangePath();
void testHasParent();
#ifdef FZ_WINDOWS
void testHasLogicalParent();
#endif
void testAddSegment();
protected:
};
CPPUNIT_TEST_SUITE_REGISTRATION(CLocalPathTest);
void CLocalPathTest::testSetPath()
{
#ifdef FZ_WINDOWS
CPPUNIT_ASSERT(CLocalPath(L"\\").GetPath() == L"\\");
CPPUNIT_ASSERT(CLocalPath(L"C:").GetPath() == L"C:\\");
CPPUNIT_ASSERT(CLocalPath(L"C:\\").GetPath() == L"C:\\");
CPPUNIT_ASSERT(CLocalPath(L"C:\\.").GetPath() == L"C:\\");
CPPUNIT_ASSERT(CLocalPath(L"C:\\.\\").GetPath() == L"C:\\");
CPPUNIT_ASSERT(CLocalPath(L"C:\\.").GetPath() == L"C:\\");
CPPUNIT_ASSERT(CLocalPath(L"C:\\..").GetPath() == L"C:\\");
CPPUNIT_ASSERT(CLocalPath(L"C:\\..\\").GetPath() == L"C:\\");
CPPUNIT_ASSERT(CLocalPath(L"C:\\foo").GetPath() == L"C:\\foo\\");
CPPUNIT_ASSERT(CLocalPath(L"C:\\..\\foo\\").GetPath() == L"C:\\foo\\");
CPPUNIT_ASSERT(CLocalPath(L"C:\\foo\\..\\bar").GetPath() == L"C:\\bar\\");
CPPUNIT_ASSERT(CLocalPath(L"\\\\foo").GetPath() == L"\\\\foo\\");
CPPUNIT_ASSERT(CLocalPath(L"\\\\foo\\").GetPath() == L"\\\\foo\\");
CPPUNIT_ASSERT(CLocalPath(L"\\\\foo/").GetPath() == L"\\\\foo\\");
CPPUNIT_ASSERT(CLocalPath(L"\\\\foo/..").GetPath() == L"\\\\foo\\");
CPPUNIT_ASSERT(CLocalPath(L"\\\\foo\\.").GetPath() == L"\\\\foo\\");
CPPUNIT_ASSERT(CLocalPath(L"\\\\foo\\.\\").GetPath() == L"\\\\foo\\");
CPPUNIT_ASSERT(CLocalPath(L"\\\\foo\\bar\\").GetPath() == L"\\\\foo\\bar\\");
CPPUNIT_ASSERT(CLocalPath(L"\\\\foo\\bar\\.\\..").GetPath() == L"\\\\foo\\");
#else
CPPUNIT_ASSERT(CLocalPath(L"/").GetPath() == L"/");
CPPUNIT_ASSERT(CLocalPath(L"/foo").GetPath() == L"/foo/");
CPPUNIT_ASSERT(CLocalPath(L"//foo//").GetPath() == L"/foo/");
CPPUNIT_ASSERT(CLocalPath(L"/foo/../foo").GetPath() == L"/foo/");
CPPUNIT_ASSERT(CLocalPath(L"/foo/..").GetPath() == L"/");
CPPUNIT_ASSERT(CLocalPath(L"/..").GetPath() == L"/");
CPPUNIT_ASSERT(CLocalPath(L"/foo/.").GetPath() == L"/foo/");
CPPUNIT_ASSERT(CLocalPath(L"/foo/./").GetPath() == L"/foo/");
CPPUNIT_ASSERT(CLocalPath(L"/foo/bar/").GetPath() == L"/foo/bar/");
CPPUNIT_ASSERT(CLocalPath(L"/foo/bar/./..").GetPath() == L"/foo/");
#endif
}
void CLocalPathTest::testChangePath()
{
#ifdef FZ_WINDOWS
CLocalPath p1(L"C:\\");
CPPUNIT_ASSERT(p1.ChangePath(L"\\") && p1.GetPath() == L"\\");
CPPUNIT_ASSERT(p1.ChangePath(L"C:") && p1.GetPath() == L"C:\\");
CPPUNIT_ASSERT(p1.ChangePath(L"C:\\.") && p1.GetPath() == L"C:\\");
CPPUNIT_ASSERT(p1.ChangePath(L"C:\\..") && p1.GetPath() == L"C:\\");
CPPUNIT_ASSERT(p1.ChangePath(L"foo") && p1.GetPath() == L"C:\\foo\\");
CPPUNIT_ASSERT(p1.ChangePath(L"..") && p1.GetPath() == L"C:\\");
CPPUNIT_ASSERT(p1.ChangePath(L"..") && p1.GetPath() == L"C:\\");
CPPUNIT_ASSERT(p1.ChangePath(L"C:\\foo") && p1.GetPath() == L"C:\\foo\\");
CPPUNIT_ASSERT(p1.ChangePath(L".") && p1.GetPath() == L"C:\\foo\\");
CPPUNIT_ASSERT(p1.ChangePath(L"..\\bar") && p1.GetPath() == L"C:\\bar\\");
CLocalPath p2;
CPPUNIT_ASSERT(p2.ChangePath(L"\\\\foo") && p2.GetPath() == L"\\\\foo\\");
CPPUNIT_ASSERT(p2.ChangePath(L".") && p2.GetPath() == L"\\\\foo\\");
CPPUNIT_ASSERT(p2.ChangePath(L"..") && p2.GetPath() == L"\\\\foo\\");
CPPUNIT_ASSERT(p2.ChangePath(L"..\\bar\\.\\baz\\..") && p2.GetPath() == L"\\\\foo\\bar\\");
#else
#endif
}
void CLocalPathTest::testHasParent()
{
#ifdef FZ_WINDOWS
CPPUNIT_ASSERT(!CLocalPath(L"\\").HasParent());
CPPUNIT_ASSERT(!CLocalPath(L"C:\\").HasParent());
CPPUNIT_ASSERT(CLocalPath(L"C:\\foo").HasParent());
CPPUNIT_ASSERT(CLocalPath(L"c:\\foo\\bar\\").HasParent());
CPPUNIT_ASSERT(!CLocalPath(L"\\\\foo").HasParent());
CPPUNIT_ASSERT(CLocalPath(L"\\\\foo\\bar").HasParent());
#else
CPPUNIT_ASSERT(!CLocalPath(L"/").HasParent());
CPPUNIT_ASSERT(CLocalPath(L"/foo").HasParent());
CPPUNIT_ASSERT(CLocalPath(L"/foo/bar").HasParent());
#endif
}
#ifdef FZ_WINDOWS
void CLocalPathTest::testHasLogicalParent()
{
CPPUNIT_ASSERT(!CLocalPath(L"\\").HasLogicalParent());
CPPUNIT_ASSERT(CLocalPath(L"C:\\").HasLogicalParent()); // This one's only difference
CPPUNIT_ASSERT(CLocalPath(L"C:\\foo").HasLogicalParent());
CPPUNIT_ASSERT(CLocalPath(L"c:\\foo\\bar\\").HasLogicalParent());
CPPUNIT_ASSERT(!CLocalPath(L"\\\\foo").HasLogicalParent());
CPPUNIT_ASSERT(CLocalPath(L"\\\\foo\\bar").HasLogicalParent());
}
#endif
void CLocalPathTest::testAddSegment()
{
#ifdef FZ_WINDOWS
CLocalPath a(L"c:\\foo");
#else
CLocalPath a(L"/foo");
#endif
CLocalPath b(a);
a.AddSegment(L"");
CPPUNIT_ASSERT(a == b);
CPPUNIT_ASSERT(a.GetPath() == b.GetPath());
}
|