aboutsummaryrefslogtreecommitdiff
path: root/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/sharedcore.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/src/tests/sharedcore.cpp b/src/tests/sharedcore.cpp
new file mode 100644
index 0000000..bdfde4c
--- /dev/null
+++ b/src/tests/sharedcore.cpp
@@ -0,0 +1,82 @@
1#include "bu/sharedcore.h"
2#include "bu/sio.h"
3
4using namespace Bu;
5
6struct ShintCore
7{
8 int val;
9};
10class Shint : public Bu::SharedCore<struct ShintCore>
11{
12public:
13 Shint()
14 {
15 data->val = 0;
16 }
17
18 Shint( int val )
19 {
20 data->val = val;
21 }
22
23 int getVal()
24 {
25 return data->val;
26 }
27
28 void setValBad( int val )
29 {
30 data->val = val;
31 }
32
33 void setVal( int val )
34 {
35 _hardCopy();
36 data->val = val;
37 }
38
39 bool operator==( const Shint &rhs )
40 {
41 if( data == rhs.data )
42 {
43 sio << "Same pointer (" << Fmt::ptr() << data << ")" << sio.nl;
44 return true;
45 }
46 if( data->val == rhs.data->val )
47 {
48 sio << "Same value " << data->val << " ("
49 << Fmt::ptr() << data << " vs "
50 << Fmt::ptr() << rhs.data << ")"
51 << sio.nl;
52 return true;
53 }
54 sio << "Different" << sio.nl;
55 return false;
56 }
57};
58
59#define line( x ) sio << __FILE__ ": " << __LINE__ << ": " << #x << sio.nl; x
60
61int main()
62{
63 line( Shint a; )
64 line( Shint b( 5 ); )
65
66 line( a == b; )
67
68 line( b = a; )
69 line( a == b; )
70
71 line( b.setValBad( 12 ); )
72 sio << a.getVal() << " != " << b.getVal() << sio.nl;
73 line( a == b; )
74
75 line( a.setVal( 3 ); )
76 sio << a.getVal() << " != " << b.getVal() << sio.nl;
77 line( a == b; )
78
79 line( a.setVal( b.getVal() ); )
80 line( a == b; )
81}
82