-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.cpp
62 lines (48 loc) · 1.09 KB
/
test.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
#include <assert.h>
#include <cstring>
#include <fstream>
#include <unistd.h>
#include "inner.h"
#include "outer.h"
void testOuter() {
const char* s = "blah";
example::Outer a(3.14159, 11, s);
ofstream out("test.bin");
a.write(out);
out.close();
example::Outer b;
ifstream in("test.bin");
b.read(in);
in.close();
unlink("test.bin");
// assertions
assert((a.getFA() - 3.14159) < 0.000001);
assert((b.getFA() - 3.14159) < 0.000001);
auto innera = a.getInner();
auto innerb = b.getInner();
assert(innera.getF1() == 11);
assert(innerb.getF1() == 11);
assert(!strcmp(innera.getF2(), s));
assert(!strcmp(innerb.getF2(), s));
}
void testInner() {
const char* s = "blah";
example::Inner a(11, s);
ofstream out("test.bin");
a.write(out);
out.close();
example::Inner b;
ifstream in("test.bin");
b.read(in);
in.close();
unlink("test.bin");
// assertions
assert(a.getF1() == 11);
assert(b.getF1() == 11);
assert(!strcmp(a.getF2(), s));
assert(!strcmp(b.getF2(), s));
}
int main(int argc, const char* argv[]) {
testOuter();
testInner();
}