Debian Codegraph @

tests/test_pseudoIO.cc

raw
1 #include <sstream>
2 #include "UnitTest++.h"
3
4 #include "geners/pseudoIO.hh"
5 #include "geners/StringArchive.hh"
6 #include "geners/Record.hh"
7 #include "geners/Reference.hh"
8
9 using namespace gs;
10
11 struct Dummy
12 {
13 inline Dummy() : i_(7) {}
14
15 inline bool operator==(const Dummy& r) const {return i_ == r.i_;}
16 inline bool operator!=(const Dummy& r) const {return i_ != r.i_;}
17
18 private:
19 int i_;
20 };
21
22 gs_enable_pseudo_io(Dummy)
23
24 namespace {
25 TEST(pseudoIO)
26 {
27 StringArchive ar;
28
29 Dummy d;
30 ar << Record(d, "dummy", "haha");
31
32 const Dummy cd;
33 ar << Record(cd, "dummy2", "haha");
34
35 const volatile Dummy cvd;
36 ar << Record(cvd, "dummy3", "haha");
37
38 volatile Dummy vd;
39 ar << Record(vd, "dummy4", "haha");
40
41 Reference<Dummy> ref(ar, "dummy", "haha");
42 CHECK(ref.unique());
43
44 Reference<Dummy> ref2(ar, "dummy4", "haha");
45 CHECK(ref2.unique());
46
47 Dummy d1;
48 ref.restore(0, &d1);
49 CHECK(d == d1);
50
51 CHECK(d == *ref2.get(0));
52 CHECK(d == *ref.getShared(0));
53 }
54 }