Skip to content

Commit df3e93a

Browse files
committed
Add support for unit tests
1 parent 352cd1d commit df3e93a

File tree

3 files changed

+63
-1
lines changed

3 files changed

+63
-1
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,7 @@
33

44
nfsclient
55
nfsserver
6-
*.o
6+
*.o
7+
DISK
8+
9+
test

src2/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,10 @@ nfsclient: Shell.o client.o
1717

1818
clean:
1919
rm -f nfsserver nfsclient *.o DISK
20+
21+
22+
# FOR TESTING
23+
TESTOBJ := $(subst server.o,,$(OBJ)) test.cpp
24+
test: $(TESTOBJ)
25+
$(CXX) -o $@ $(TESTOBJ)
26+
rm -f DISK

src2/test.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
#include <iostream>
3+
#include <string>
4+
#include <cstdlib>
5+
#include <sys/types.h>
6+
#include <sys/socket.h>
7+
#include <netinet/in.h>
8+
#include <netdb.h>
9+
#include "FileSys.h"
10+
using namespace std;
11+
12+
#include "WrappedFileSys.h"
13+
#include "assert.h"
14+
15+
void testing()
16+
{
17+
FileInode file = FileInode();
18+
cout << "FILE 1 ID " << file.get_id() << endl;
19+
file.destroy();
20+
21+
FileInode file2 = FileInode();
22+
cout << "FILE 2 ID " << file2.get_id() << endl;
23+
file2.destroy();
24+
}
25+
26+
void unit_tests()
27+
{
28+
FileInode file1 = FileInode();
29+
short file1_id = file1.get_id();
30+
file1.destroy();
31+
32+
FileInode file2 = FileInode();
33+
short file2_id = file2.get_id();
34+
file2.destroy();
35+
36+
file1_id++;
37+
38+
assert(file1_id == file2_id);
39+
}
40+
41+
int main(int argc, char *argv[])
42+
{
43+
FileSys fs;
44+
fs.mount(1); // Giving it a bogus sock int for now
45+
46+
// testing();
47+
48+
unit_tests();
49+
50+
fs.unmount();
51+
return 0;
52+
}

0 commit comments

Comments
 (0)