From 1b797548dff7e2475826ba29a71c3f496008988f Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 14 Aug 2010 07:12:29 +0000 Subject: libgats gets it's own repo. The rest of the history is in my misc repo. --- src/unit/basic.unit | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 src/unit/basic.unit (limited to 'src/unit') diff --git a/src/unit/basic.unit b/src/unit/basic.unit new file mode 100644 index 0000000..9389c70 --- /dev/null +++ b/src/unit/basic.unit @@ -0,0 +1,122 @@ +// vim: syntax=cpp +/* + * Copyright (C) 2007-2010 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "gats/dictionary.h" +#include "gats/integer.h" +#include "gats/float.h" +#include "gats/list.h" +#include "gats/boolean.h" +#include "gats/string.h" + +#include "bu/membuf.h" +#include "bu/list.h" +#include "bu/sio.h" + +#include + +using namespace Bu; + +suite Basic +{ + test integer + { + Bu::List lInts; + Bu::MemBuf mb; + + int64_t i = 1; + for( int x = 0; x < 256; x++ ) + { + lInts.append( i ); + Gats::Integer( i ).write( mb ); + i = -(i<<1)-i; + } + + mb.setPos( 0 ); + + for( Bu::List::iterator j = lInts.begin(); j; j++ ) + { + Gats::Object *pObj = Gats::Object::read( mb ); + if( pObj->getType() != Gats::typeInteger ) + unitFailed("Bad type read."); + + if( dynamic_cast(pObj)->getValue() != *j ) + unitFailed("Bad number."); + } + } + + test string + { + Bu::List lStrs; + Bu::MemBuf mb; + + lStrs.append( Bu::FString() ); + Gats::String("").write( mb ); + + { + int iMax = 0; + for( int j = 1; j <= (1<<16); j=j<<1 ) + iMax += j; + setStepCount( iMax ); + } + for( int j = 1; j <= (1<<16); j=j<<1 ) + { + Bu::FString s( j ); + for( int x = 0; x < j; x++ ) + { + s[x] = (unsigned char)(random()%256); + } + incProgress( j ); + Gats::String( s ).write( mb ); + lStrs.append( s ); + } + + mb.setPos( 0 ); + + for( Bu::List::iterator i = lStrs.begin(); i; i++ ) + { + Gats::Object *pObj = Gats::Object::read( mb ); + if( pObj->getType() != Gats::typeString ) + unitFailed("Bad type read."); + + if( *dynamic_cast(pObj) != *i ) + unitFailed("Bad string."); + } + } + + test boolean + { + Bu::List lBs; + Bu::MemBuf mb; + + for( int j = 0; j < 1024; j++ ) + { + if( random()%2 == 0 ) + { + lBs.append( true ); + Gats::Boolean( true ).write( mb ); + } + else + { + lBs.append( false ); + Gats::Boolean( false ).write( mb ); + } + } + + mb.setPos( 0 ); + + for( Bu::List::iterator i = lBs.begin(); i; i++ ) + { + Gats::Object *pObj = Gats::Object::read( mb ); + if( pObj->getType() != Gats::typeBoolean ) + unitFailed("Bad type read."); + + if( dynamic_cast(pObj)->getValue() != *i ) + unitFailed("Bad string."); + } + } +} -- cgit v1.2.3