forked from hrydgard/ppsspp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestVFS.cpp
94 lines (81 loc) · 2.58 KB
/
TestVFS.cpp
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
#include <thread>
#include <vector>
#include "Common/Log.h"
#include "Common/File/VFS/ZipFileReader.h"
#include "UnitTest.h"
static bool CheckContainsDir(const std::vector<File::FileInfo> &listing, const char *name) {
for (auto &file : listing) {
if (file.name == name && file.isDirectory) {
return true;
}
}
return false;
}
static bool CheckContainsFile(const std::vector<File::FileInfo> &listing, const char *name) {
for (auto &file : listing) {
if (file.name == name && !file.isDirectory) {
return true;
}
}
return false;
}
// ziptest.zip file structure:
//
// ziptest/
// data/
// a/
// in_a.txt
// b/
// in_b.txt
// argh.txt
// big.txt
// lang/
// en_us.txt
// sv_se.txt
// langregion.txt
// in_root.txt
// TODO: Also test the filter.
bool TestZipFile() {
// First, check things relative to root, with an empty internal path.
Path zipPath = Path("../source_assets/ziptest.zip");
if (!File::Exists(zipPath)) {
zipPath = Path("source_assets/ziptest.zip");
}
ZipFileReader *dir = ZipFileReader::Create(zipPath, "", true);
EXPECT_TRUE(dir != nullptr);
std::vector<File::FileInfo> listing;
EXPECT_TRUE(dir->GetFileListing("", &listing, nullptr));
EXPECT_EQ_INT(listing.size(), 2);
EXPECT_TRUE(CheckContainsDir(listing, "ziptest"));
EXPECT_TRUE(CheckContainsFile(listing, "in_root.txt"));
EXPECT_FALSE(dir->GetFileListing("ziptestwrong", &listing, nullptr));
// Next, do a file listing in a directory, but keep the root.
EXPECT_TRUE(dir->GetFileListing("ziptest", &listing, nullptr));
EXPECT_EQ_INT(listing.size(), 3);
EXPECT_TRUE(CheckContainsDir(listing, "data"));
EXPECT_TRUE(CheckContainsDir(listing, "lang"));
EXPECT_TRUE(CheckContainsFile(listing, "langregion.txt"));
delete dir;
// Next, we'll destroy the reader and create a new one based in a subdirectory.
dir = ZipFileReader::Create(zipPath, "ziptest/data", true);
EXPECT_TRUE(dir != nullptr);
EXPECT_TRUE(dir->GetFileListing("", &listing, nullptr));
EXPECT_EQ_INT(listing.size(), 4);
EXPECT_TRUE(CheckContainsDir(listing, "a"));
EXPECT_TRUE(CheckContainsDir(listing, "b"));
EXPECT_TRUE(CheckContainsFile(listing, "argh.txt"));
EXPECT_TRUE(CheckContainsFile(listing, "big.txt"));
EXPECT_TRUE(dir->GetFileListing("a", &listing, nullptr));
EXPECT_TRUE(CheckContainsFile(listing, "in_a.txt"));
EXPECT_EQ_INT(listing.size(), 1);
EXPECT_TRUE(dir->GetFileListing("b", &listing, nullptr));
EXPECT_TRUE(CheckContainsFile(listing, "in_b.txt"));
EXPECT_EQ_INT(listing.size(), 1);
delete dir;
return true;
}
bool TestVFS() {
if (!TestZipFile())
return false;
return true;
}