// 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."); } } }