aboutsummaryrefslogtreecommitdiff
path: root/test/engines/wintermute/path_utils.h
blob: 26f3404396c493fc506e21701876ad7b45c97bba (plain)
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#include <cxxtest/TestSuite.h>
#include "engines/wintermute/utils/path_util.h"
/**
 * Test suite for the functions in engines/wintermute/utils/path_util.h
 *
 * NOTE: This is not a prescription;
 *       this was not written by the original engine author;
 *       this was not written by the engine porter.
 *
 * It might, however, help to spot variations in behavior that are introduced by modifications
 */

class PathUtilTestSuite : public CxxTest::TestSuite {
	public:
	const Common::String unixPath;
	const Common::String unixCapPath;
	const Common::String windowsPath;
	const Common::String windowsCapPath;
	const Common::String emptyString;
	const Common::String dualExtPath;
	const Common::String manyExtPath;
	const Common::String mixedSlashesPath1;
	const Common::String mixedSlashesPath2;
	const Common::String unixRelativePath;
	const Common::String windowsRelativePath;
	const Common::String unixDirPath;
	const Common::String windowsDirPath;
	PathUtilTestSuite () :
		unixPath("/some/file.ext"),
		unixCapPath("/SOME/FILE.EXT"),
		windowsPath("C:\\some\\file.ext"),
		windowsCapPath("C:\\SOME\\FILE.EXT"),
		emptyString(""),
		dualExtPath("/some/file.tar.gz"),
		manyExtPath("/some/file.tar.bz2.gz.zip"),
		mixedSlashesPath1("C:\\this/IS_REALLY\\weird.exe"),
		mixedSlashesPath2("/pretty\\weird/indeed.txt"),
		unixRelativePath("some/file.ext"),
		windowsRelativePath("some\\file.ext"),
		unixDirPath("/some/dir/"),
		windowsDirPath("C:\\some\\dir\\")
	{}
	void test_getdirectoryname() {
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getDirectoryName(unixPath),
				Common::String("/some/")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getDirectoryName(unixCapPath),
				Common::String("/SOME/")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getDirectoryName(windowsPath),
				Common::String("C:\\some\\")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getDirectoryName(windowsCapPath),
				Common::String("C:\\SOME\\")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getDirectoryName(emptyString),
				Common::String("")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getDirectoryName(unixDirPath),
				Common::String("/some/dir/")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getDirectoryName(windowsDirPath),
				Common::String("C:\\some\\dir\\")
				);
	}

	void test_getfilename() {
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileName(unixPath),
				Common::String("file.ext")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileName(unixCapPath),
				Common::String("FILE.EXT")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileName(windowsPath),
				Common::String("file.ext")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileName(windowsCapPath),
				Common::String("FILE.EXT")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileName(emptyString),
				Common::String("")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileName(unixRelativePath),
				Common::String("file.ext")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileName(windowsRelativePath),
				Common::String("file.ext")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileName(windowsDirPath),
				Common::String("")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileName(unixDirPath),
				Common::String("")
				);
	}

	void test_getextension() {
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getExtension(windowsPath),
				Common::String("ext")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getExtension(windowsCapPath),
				Common::String("EXT")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getExtension(emptyString),
				Common::String("")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getExtension(dualExtPath),
				Common::String("gz")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getExtension(manyExtPath),
				Common::String("zip")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getExtension(unixRelativePath),
				Common::String("ext")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getExtension(windowsRelativePath),
				Common::String("ext")
				);
	}

	void test_getfilenamewithoutextension() {
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileNameWithoutExtension(windowsPath),
				Common::String("file")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileNameWithoutExtension(windowsCapPath),
				Common::String("FILE")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileNameWithoutExtension(emptyString),
				Common::String("")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileNameWithoutExtension(dualExtPath),
				Common::String("file.tar")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileNameWithoutExtension(manyExtPath),
				Common::String("file.tar.bz2.gz")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileNameWithoutExtension(unixRelativePath),
				Common::String("file")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getFileNameWithoutExtension(windowsRelativePath),
				Common::String("file")
				);
	}

	void test_combine_identity() {
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getDirectoryName(windowsPath) +
				Wintermute::PathUtil::getFileNameWithoutExtension(windowsPath) +
				"." +
				Wintermute::PathUtil::getExtension(windowsPath),
				windowsPath
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getDirectoryName(windowsCapPath) +
				Wintermute::PathUtil::getFileNameWithoutExtension(windowsCapPath) +
				"." +
				Wintermute::PathUtil::getExtension(windowsCapPath),
				windowsCapPath
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getDirectoryName(unixCapPath) +
				Wintermute::PathUtil::getFileNameWithoutExtension(unixCapPath) +
				"." +
				Wintermute::PathUtil::getExtension(unixCapPath),
				unixCapPath
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::getDirectoryName(manyExtPath) +
				Wintermute::PathUtil::getFileNameWithoutExtension(manyExtPath) +
				"." +
				Wintermute::PathUtil::getExtension(manyExtPath),
				manyExtPath
				);
	}

	void test_normalize() {
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::normalizeFileName(windowsCapPath),
				Common::String("c:/some/file.ext")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::normalizeFileName(windowsPath),
				Common::String("c:/some/file.ext")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::normalizeFileName(mixedSlashesPath1),
				Common::String("c:/this/is_really/weird.exe")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::normalizeFileName(mixedSlashesPath2),
				Common::String("/pretty/weird/indeed.txt")
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::normalizeFileName(emptyString),
				emptyString
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::normalizeFileName(unixRelativePath),
				unixRelativePath
				);
		TS_ASSERT_EQUALS(
				Wintermute::PathUtil::normalizeFileName(windowsRelativePath),
				unixRelativePath // NOT windows
				);
	}
};