-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgitlstree_test.cc
More file actions
64 lines (56 loc) · 1.82 KB
/
gitlstree_test.cc
File metadata and controls
64 lines (56 loc) · 1.82 KB
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
#include <assert.h>
#include <sys/stat.h>
#include <iostream>
#include <memory>
#include <string>
#define FUSE_USE_VERSION 32
#include "get_current_dir.h"
#include "gitlstree.h"
using std::cout;
using std::endl;
using std::string;
using std::unique_ptr;
void TryReadFileTest(directory_container::DirectoryContainer* fs,
const string& name) {
// Try reading a file.
cout << "Try reading: " << name << endl;
gitlstree::FileElement* fe;
;
assert((fe = dynamic_cast<gitlstree::FileElement*>(fs->mutable_get(name))) !=
nullptr);
constexpr size_t size = 4096;
char buf[size];
size_t read_size;
fe->Open();
assert((read_size = fe->Read(buf, size, 0)) > 0);
assert(read_size <= size);
string f(buf, read_size);
cout << f << endl;
}
void ScenarioTest() {
auto fs = std::make_unique<directory_container::DirectoryContainer>();
auto git = gitlstree::GitTree::NewGitTree(
GetCurrentDir() + "/out/fetch_test_repo/gitlstreefs", "HEAD", "",
GetCurrentDir() + "/out/gitlstree_test_cache/", fs.get());
fs->dump();
assert(fs->get("/dummytestdirectory/README") != nullptr);
assert(fs->get("/dummytestdirectory") != nullptr);
assert(fs->is_directory("/dummytestdirectory"));
assert(!fs->is_directory("/dummytestdirectory/README"));
// root directory.
assert(fs->get("/") != nullptr);
struct stat st;
assert(fs->Getattr("/", &st) == 0);
assert(st.st_nlink == 2);
assert(st.st_mode == (S_IFDIR | 0755));
assert(fs->Getattr("/dummytestdirectory", &st) == 0);
assert(fs->Getattr("/dummytestdirectory/", &st) == -ENOENT);
assert(fs->Getattr("/dummytestdirectory/README", &st) == 0);
TryReadFileTest(fs.get(), "/dummytestdirectory/README");
}
int main(int argc, char** argv) {
int iter = argv[1] ? atoi(argv[1]) : 1;
for (int i = 0; i < iter; ++i) {
ScenarioTest();
}
}