source: filezilla/trunk/fuentes/tests/localpathtest.cpp @ 130

Last change on this file since 130 was 130, checked in by jrpelegrina, 3 years ago

First release to xenial

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