From 3d5c548d630f8b6c86a250e1b7358824557ef01f Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 13 Aug 2009 16:14:53 +0000 Subject: 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. --- src/tests/sharedcore.cpp | 82 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/tests/sharedcore.cpp (limited to 'src/tests') 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 @@ +#include "bu/sharedcore.h" +#include "bu/sio.h" + +using namespace Bu; + +struct ShintCore +{ + int val; +}; +class Shint : public Bu::SharedCore +{ +public: + Shint() + { + data->val = 0; + } + + Shint( int val ) + { + data->val = val; + } + + int getVal() + { + return data->val; + } + + void setValBad( int val ) + { + data->val = val; + } + + void setVal( int val ) + { + _hardCopy(); + data->val = val; + } + + bool operator==( const Shint &rhs ) + { + if( data == rhs.data ) + { + sio << "Same pointer (" << Fmt::ptr() << data << ")" << sio.nl; + return true; + } + if( data->val == rhs.data->val ) + { + sio << "Same value " << data->val << " (" + << Fmt::ptr() << data << " vs " + << Fmt::ptr() << rhs.data << ")" + << sio.nl; + return true; + } + sio << "Different" << sio.nl; + return false; + } +}; + +#define line( x ) sio << __FILE__ ": " << __LINE__ << ": " << #x << sio.nl; x + +int main() +{ + line( Shint a; ) + line( Shint b( 5 ); ) + + line( a == b; ) + + line( b = a; ) + line( a == b; ) + + line( b.setValBad( 12 ); ) + sio << a.getVal() << " != " << b.getVal() << sio.nl; + line( a == b; ) + + line( a.setVal( 3 ); ) + sio << a.getVal() << " != " << b.getVal() << sio.nl; + line( a == b; ) + + line( a.setVal( b.getVal() ); ) + line( a == b; ) +} + -- cgit v1.2.3