-
Notifications
You must be signed in to change notification settings - Fork 2
/
directory_container_test.cc
65 lines (55 loc) · 1.63 KB
/
directory_container_test.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
62
63
64
65
#include "directory_container.h"
#include "basename.h"
#include <assert.h>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <vector>
using std::cout;
using std::endl;
using std::function;
using std::map;
using std::pair;
using std::string;
using std::unique_ptr;
using std::unordered_map;
using std::vector;
// Concrete class.
class GitFile : public directory_container::File {
public:
GitFile() {}
virtual ~GitFile() {}
virtual int Getattr(struct stat* stbuf) override { return 0; }
virtual ssize_t Read(char* buf, size_t size, off_t offset) override {
return -EINVAL;
}
virtual int Open() override { return -EINVAL; };
virtual int Release() override { return -EINVAL; };
};
int main() {
directory_container::DirectoryContainer d;
d.add("/this/dir", std::make_unique<GitFile>());
d.add("/the", std::make_unique<GitFile>());
d.add("/a", std::make_unique<GitFile>());
d.add("/hoge/bbb", std::make_unique<GitFile>());
d.add("/hoge/ccc", std::make_unique<GitFile>());
d.add("/foo/bbbdir/ccc", std::make_unique<GitFile>());
d.add("/hoge/bbbdir/ccc", std::make_unique<GitFile>());
d.dump();
assert(d.is_directory("/this"));
assert(d.is_directory("/hoge"));
assert(d.is_directory("/"));
assert(!d.is_directory("/hog"));
assert(!d.is_directory("/a"));
assert(!d.is_directory("/hoge/ccc"));
assert(d.get("/hoge/ccc"));
int count_hoge = 0;
d.for_each("/hoge", [&count_hoge](const string& name,
const directory_container::File* f) {
cout << "under hoge: " << name << endl;
count_hoge++;
});
assert(count_hoge == 3);
}