-
-
Notifications
You must be signed in to change notification settings - Fork 435
/
Copy pathtest_path.cc
61 lines (49 loc) · 1.8 KB
/
test_path.cc
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
/* test_path.cc - Test path functionality
part of the minizip-ng project
Copyright (C) Nathan Moinvaziri
https://github.com/zlib-ng/minizip-ng
This program is distributed under the terms of the same license as zlib.
See the accompanying LICENSE file for the full text of the license.
*/
#include "mz.h"
#include "mz_os.h"
#include <gtest/gtest.h>
struct resolve_path_param {
const char *path;
const char *expected_path;
friend std::ostream &operator<<(std::ostream &os, const resolve_path_param ¶m) {
return os << "path: " << param.path;
}
};
constexpr resolve_path_param resolve_path_tests[] = {
{ "c:\\test\\.", "c:\\test\\" },
{ "c:\\test\\.\\", "c:\\test\\" },
{ "c:\\test\\.\\.", "c:\\test\\" },
{ "c:\\test\\..", "c:\\" },
{ "c:\\test\\..\\", "c:\\" },
{ "c:\\test\\.\\..", "c:\\" },
{ "c:\\test\\.\\\\..", "c:\\" },
{ ".", "." },
{ ".\\", "" },
{ "..", "" },
{ "..\\", "" },
{ ".\\test\\123", "test\\123" },
{ ".\\..\\test\\123", "test\\123" },
{ "..\\..\\test\\123", "test\\123" },
{ "test\\.abc.txt", "test\\.abc.txt" },
{ "c:\\test\\123\\.\\abc.txt", "c:\\test\\123\\abc.txt" },
{ "c:\\test\\123\\..\\abc.txt", "c:\\test\\abc.txt" },
{ "c:\\test\\123\\..\\..\\abc.txt", "c:\\abc.txt" },
{ "c:\\test\\123\\..\\..\\..\\abc.txt", "abc.txt" },
{ "c:\\test\\123\\..\\.\\..\\abc.txt", "c:\\abc.txt" },
};
class path_resolve : public ::testing::TestWithParam<resolve_path_param> {
};
INSTANTIATE_TEST_SUITE_P(os, path_resolve, testing::ValuesIn(resolve_path_tests));
TEST_P(path_resolve, os) {
const auto ¶m = GetParam();
char output[256];
memset(output, 'z', sizeof(output));
mz_path_resolve(param.path, output, sizeof(output));
EXPECT_STREQ(output, param.expected_path);
}