-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathFileSystem.tt
More file actions
125 lines (94 loc) · 2.68 KB
/
FileSystem.tt
File metadata and controls
125 lines (94 loc) · 2.68 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
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
#include <cxxtest/TestSuite.h>
#include "AccessManagerImpl.hh"
#include "BlobFsMarshaller.hh"
#include "file.hh"
#include "FileSystem.hh"
#include "FsMarshallerMock.hh"
#include "RootDirMarshallerImpl.hh"
#include "SystemClock.hh"
#include <sys/stat.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
class FileSystemTest : public CxxTest::TestSuite {
private:
fs::path tmpDir;
FsMarshaller *marshaller;
AccessManager *accessManager;
RootDir *rootDir;
Clock *clock;
RootDirMarshaller *rootDirMarshaller;
// TODO Remove
// RootUidMarshaller *rootUidMarshaller;
FileSystem *fs;
File *file1;
File *file2;
public:
void setUp() {
char name[] = "testXXXXXX";
if (! mkdtemp(name))
throw IoError(errno, "Couldn't create temporary directory");
tmpDir = fs::path(fs::current_path() / name);
rootDirMarshaller = new RootDirMarshallerImpl(tmpDir / "foo");
marshaller = new FsMarshallerMock();
accessManager = new AccessManagerImpl();
rootDir = new RootDir(*marshaller, *rootDirMarshaller);
clock = new SystemClock();
fs = new FileSystem(*marshaller, *accessManager, *rootDir, *clock);
file1 = new File(*marshaller, *rootDir, "foo");
file2 = new File(*marshaller, *rootDir, "bar");
rootDir->getAttr().setMode(S_IWOTH|S_IXOTH);
rootDir->addChild(*file1);
rootDir->addChild(*file2);
}
void tearDown() {
delete file1;
delete file2;
delete fs;
delete rootDirMarshaller;
delete rootDir;
delete accessManager;
delete marshaller;
fs::remove_all(tmpDir);
}
void testFindNodeForRootDir() {
TS_ASSERT_EQUALS(rootDir, fs->findNode("/"));
}
void testFindNodeForExistingFile() {
TS_ASSERT_EQUALS(file1, fs->findNode("/foo"));
TS_ASSERT_EQUALS(file2, fs->findNode("/bar"));
}
void testFindNodeForNonExistingFile() {
TS_ASSERT_EQUALS((Node *) 0, fs->findNode("/doesnt_exist"));
}
void testUtimensTvNull() {
fs->utimens("/foo", NULL);
time_t now = time(NULL);
struct stat stbuf;
fs->getAttr("/foo", &stbuf);
TS_ASSERT_EQUALS(stbuf.st_atime, now);
TS_ASSERT_EQUALS(stbuf.st_mtime, now);
}
void testUtimensATimeSkipMTimeNow() {
struct timespec tv[2];
tv[0].tv_nsec = UTIME_OMIT;
tv[1].tv_nsec = UTIME_NOW;
fs->utimens("/foo", tv);
time_t now = time(NULL);
struct stat stbuf;
fs->getAttr("/foo", &stbuf);
TS_ASSERT_DIFFERS(now, stbuf.st_atime);
TS_ASSERT_EQUALS(now, stbuf.st_mtime);
}
void testUtimensATimeValMTimeNow() {
struct timespec tv[2];
tv[0].tv_sec = 123;
tv[1].tv_nsec = UTIME_NOW;
fs->utimens("/foo", tv);
time_t now = time(NULL);
struct stat stbuf;
fs->getAttr("/foo", &stbuf);
TS_ASSERT_EQUALS(123, stbuf.st_atime);
TS_ASSERT_EQUALS(now, stbuf.st_mtime);
}
};