aboutsummaryrefslogtreecommitdiff
path: root/src/tests/sharedcore.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-08-13 16:14:53 +0000
committerMike Buland <eichlan@xagasoft.com>2009-08-13 16:14:53 +0000
commit3d5c548d630f8b6c86a250e1b7358824557ef01f (patch)
tree01bc0a81c7a9ae27209ca26e6ea5e0f09fb32dc5 /src/tests/sharedcore.cpp
parent8e08c85cd77d7306fb3feaef8544778408c9d858 (diff)
downloadlibbu++-3d5c548d630f8b6c86a250e1b7358824557ef01f.tar.gz
libbu++-3d5c548d630f8b6c86a250e1b7358824557ef01f.tar.bz2
libbu++-3d5c548d630f8b6c86a250e1b7358824557ef01f.tar.xz
libbu++-3d5c548d630f8b6c86a250e1b7358824557ef01f.zip
Ok, shared core looks good, and I added a unit test for Bu::List to check a few
basics. It works, so now I'm going to apply SharedCore to Bu::List and see how bad it is. Also, I got rid of all the warnings and things that showed up during compilation, they were all silly anyway. Finally, mkunit.sh is much cooler. Hard to believe it's a shell script, it now also adds proper #line directives to the cpp output so if there is an error or warning g++ will give you the right line number in your .unit file, not the resultant cpp file.
Diffstat (limited to '')
-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