From 306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 15 May 2010 07:44:10 +0000 Subject: mkunit.sh was a little dumb, it didn't handle a number of things correctly. I've written a new program that basically does the same thing, only it's much more clever, and does many more of the translations and conversions better, including the #line directives. Also, I dropped nids, we don't need it anymore. But now I'm ready to write some serious tests for myriad. --- src/buffer.cpp | 3 +- src/cachestorenids.cpp | 9 - src/cachestorenids.h | 158 -------------- src/nids.cpp | 275 ------------------------ src/nids.h | 121 ----------- src/nidsstream.cpp | 237 --------------------- src/nidsstream.h | 59 ------ src/tests/nids.cpp | 57 ----- src/tools/mkunit.cpp | 547 +++++++++++++++++++++++++++++++++++++++++++++++ src/tools/nidstool.cpp | 248 ---------------------- src/unit/archive.unit | 337 ++++++++++++++--------------- src/unit/array.unit | 121 +++++------ src/unit/file.unit | 123 +++++------ src/unit/fstring.unit | 550 ++++++++++++++++++++++++------------------------ src/unit/hash.unit | 113 +++++----- src/unit/list.unit | 206 +++++++++--------- src/unit/membuf.unit | 61 +++--- src/unit/queuebuf.unit | 148 ++++++------- src/unit/substream.unit | 74 +++---- src/unit/taf.unit | 180 ++++++++-------- src/unit/xml.unit | 13 +- 21 files changed, 1515 insertions(+), 2125 deletions(-) delete mode 100644 src/cachestorenids.cpp delete mode 100644 src/cachestorenids.h delete mode 100644 src/nids.cpp delete mode 100644 src/nids.h delete mode 100644 src/nidsstream.cpp delete mode 100644 src/nidsstream.h delete mode 100644 src/tests/nids.cpp create mode 100644 src/tools/mkunit.cpp delete mode 100644 src/tools/nidstool.cpp (limited to 'src') diff --git a/src/buffer.cpp b/src/buffer.cpp index 654fa13..fa27116 100644 --- a/src/buffer.cpp +++ b/src/buffer.cpp @@ -34,7 +34,8 @@ void Bu::Buffer::start() size_t Bu::Buffer::stop() { - return 0; + iReadBufFill = iReadPos = iWriteBufFill = iWritePos = 0; + return sSoFar; } void Bu::Buffer::fillReadBuf() diff --git a/src/cachestorenids.cpp b/src/cachestorenids.cpp deleted file mode 100644 index 85e9cba..0000000 --- a/src/cachestorenids.cpp +++ /dev/null @@ -1,9 +0,0 @@ -/* - * 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 "bu/cachestorenids.h" - diff --git a/src/cachestorenids.h b/src/cachestorenids.h deleted file mode 100644 index 293f521..0000000 --- a/src/cachestorenids.h +++ /dev/null @@ -1,158 +0,0 @@ -/* - * 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. - */ - -#ifndef BU_CACHE_STORE_NIDS_H -#define BU_CACHE_STORE_NIDS_H - -#include "bu/fstring.h" -#include "bu/stream.h" -#include "bu/nids.h" -#include "bu/nidsstream.h" -#include "bu/cachestore.h" - -#include "bu/file.h" -#include "bu/archive.h" - -namespace Bu -{ - template - keytype __cacheGetKey( const obtype *pObj ); - - template - obtype *__cacheStoreNidsAlloc( const keytype &key ) - { - return new obtype(); - } - - template - void __cacheStoreNidsStore( Bu::Stream &s, obtype &rObj, - const keytype & ) - { - Bu::Archive ar( s, Bu::Archive::save ); - ar << rObj; - } - - template - obtype *__cacheStoreNidsLoad( Bu::Stream &s, const keytype &key ) - { - obtype *pObj = __cacheStoreNidsAlloc( key ); - Bu::Archive ar( s, Bu::Archive::load ); - ar >> (*pObj); - return pObj; - } - - template - class CacheStoreNids : public CacheStore - { - public: - CacheStoreNids( Bu::Stream &sArch, - int iBlockSize=1024, int iPreAllocate=1 ) : - nStore( sArch ) - { - try - { - nStore.initialize(); - NidsStream ns = nStore.openStream( 0 ); - Bu::Archive ar( ns, Bu::Archive::load ); - ar >> hId; - } - catch( Bu::NidsException &e ) - { - nStore.initialize( iBlockSize, iPreAllocate ); - int iStream = nStore.createStream(); - if( iStream != 0 ) - throw Bu::ExceptionBase("That's...horrible...id = %d.\n\n", iStream ); - NidsStream ns = nStore.openStream( 0 ); - Bu::Archive ar( ns, Bu::Archive::save ); - ar << hId; - } - } - - virtual ~CacheStoreNids() - { - NidsStream ns = nStore.openStream( 0 ); - Bu::Archive ar( ns, Bu::Archive::save ); - ar << hId; - } - - virtual obtype *load( const keytype &key ) - { - int iStream = hId.get( key ); - NidsStream ns = nStore.openStream( iStream ); - obtype *pOb = __cacheStoreNidsLoad( ns, key ); - return pOb; - } - - virtual void unload( obtype *pObj, const keytype &key ) - { - delete pObj; - } - - virtual keytype create( obtype *pSrc ) - { - keytype key = __cacheGetKey( pSrc ); - int iStream = nStore.createStream(); - hId.insert( key, iStream ); - NidsStream ns = nStore.openStream( iStream ); - __cacheStoreNidsStore( ns, *pSrc, key ); - return key; - } - - virtual void sync() - { - NidsStream ns = nStore.openStream( 0 ); - Bu::Archive ar( ns, Bu::Archive::save ); - ar << hId; - } - - virtual void sync( obtype *pSrc, const keytype &key ) - { - int iStream = hId.get( key ); - NidsStream ns = nStore.openStream( iStream ); - __cacheStoreNidsStore( ns, *pSrc, key ); - } - - virtual void destroy( obtype *pObj, const keytype &key ) - { - int iStream = hId.get( key ); - nStore.deleteStream( iStream ); - hId.erase( key ); - delete pObj; - sync(); - } - - virtual void destroy( const keytype &key ) - { - int iStream = hId.get( key ); - nStore.deleteStream( iStream ); - hId.erase( key ); - sync(); - } - - virtual bool has( const keytype &key ) - { - return hId.has( key ); - } - - virtual Bu::List getKeys() - { - return hId.getKeys(); - } - - virtual int getSize() - { - return hId.getSize(); - } - - private: - Nids nStore; - typedef Bu::Hash NidHash; - NidHash hId; - }; -}; - -#endif diff --git a/src/nids.cpp b/src/nids.cpp deleted file mode 100644 index 6628f14..0000000 --- a/src/nids.cpp +++ /dev/null @@ -1,275 +0,0 @@ -/* - * 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 "bu/nids.h" -#include "bu/stream.h" -#include "bu/nidsstream.h" -#include - -#define NIDS_MAGIC_CODE ((unsigned char *)"\xFF\xC3\x99\xBD") - -namespace Bu -{ - subExceptionDef( NidsException ) -} - -Bu::Nids::Nids( Bu::Stream &sStore ) : - sStore( sStore ), - iBlockSize( 0 ), - iBlocks( 0 ), - iBlockStart( -1 ), - iUsed( 0 ) -{ -} - -Bu::Nids::~Nids() -{ - updateHeader(); -} - -void Bu::Nids::sync() -{ - updateHeader(); - - // Later, also flush all caches. -} - -void Bu::Nids::initialize() -{ - unsigned char buf[4]; - if( sStore.read( buf, 4 ) < 4 ) - throw NidsException("Input stream appears to be empty."); - if( memcmp( buf, NIDS_MAGIC_CODE, 4 ) ) - { - throw NidsException( - "Stream does not appear to be a valid NIDS format."); - } - sStore.read( buf, 2 ); - if( buf[0] != 0 ) - throw NidsException( - "We can only handle version 0 for now."); - if( buf[1] != 4 ) - throw NidsException( - "We can only handle 4-byte words at the moment."); - sStore.read( &iBlockSize, 4 ); - sStore.read( &iBlocks, 4 ); - sStore.read( &iUsed, 4 ); // number of used blocks... - sStore.seek( 7 ); // skip reserved space. - iBlockStart = sStore.tell(); - - //printf("%d blocks, %db each, %db block offset\n", - // iBlocks, iBlockSize, iBlockStart ); - - bsBlockUsed.setSize( iBlocks, true ); - Block bTmp; - for( int j = 0; j < iBlocks; j++ ) - { - sStore.seek( iBlockStart+iBlockSize*j ); - sStore.read( &bTmp, sizeof(bTmp) ); - if( bTmp.uFirstBlock != blockUnused ) - bsBlockUsed.setBit( j ); - } -} - -void Bu::Nids::initialize( int iBlockSize, int iPreAllocate ) -{ - char cBuf = 0; - int iBuf = 0; - - // Magic number - sStore.write( NIDS_MAGIC_CODE, 4 ); - - // Version (0) - sStore.write( &cBuf, 1 ); - - // Bytes per int - cBuf = 4; - sStore.write( &cBuf, 1 ); - - // The size of each block and the number of blocks we're pre-allocating - sStore.write( &iBlockSize, 4 ); - sStore.write( &iPreAllocate, 4 ); - - // The number of used blocks - sStore.write( &iBuf, 4 ); - - // Reserved space - sStore.write( "\x00\x00\x00\x00\x00\x00\x00", 7 ); - - this->iBlockSize = iBlockSize; - this->iBlocks = iPreAllocate; - this->iBlockStart = sStore.tell(); - //printf("iBlockStart = %d\n", this->iBlockStart ); - bsBlockUsed.setSize( iPreAllocate, true ); - - //printf("%d blocks, %db each, %db block offset\n", - // iBlocks, iBlockSize, iBlockStart ); - - Block *block = (Block *)new char[iBlockSize]; - memset( block, 0, iBlockSize ); - block->uFirstBlock = block->uNextBlock /*=block->uPrevBlock*/ = blockUnused; - for( int j = 0; j < iPreAllocate; j++ ) - { - sStore.write( block, iBlockSize ); - } - delete[] (char *)block; -} - -void Bu::Nids::updateHeader() -{ - if( !sStore.canWrite() ) - return; - sStore.setPos( 10 ); // Skip the magic number, version, bpi, block size - sStore.write( &iBlocks, 4 ); - sStore.write( &iUsed, 4 ); -} - -void Bu::Nids::initBlock( uint32_t uPos, uint32_t uFirstBlock, - /*uint32_t uPrevBlock,*/ bool bNew ) -{ - Block b = { uPos, blockUnused, /*uPrevBlock, 0,*/ 0, { } }; - if( uFirstBlock != blockUnused ) - b.uFirstBlock = uFirstBlock; - bsBlockUsed.setBit( uPos ); - sStore.setPos( iBlockStart+(iBlockSize*uPos) ); - sStore.write( &b, sizeof(Block) ); - if( bNew ) - { - // It's a new one, at the end, write some zeros. - int iSize = iBlockSize-sizeof(Block); - char *buf = new char[iSize]; - memset( buf, 0, iSize ); - sStore.write( buf, iSize ); - delete[] buf; - } - iUsed++; -} - -uint32_t Bu::Nids::createBlock( uint32_t uFirstBlock, /*uint32_t uPrevBlock,*/ - int /*iPreAllocate*/ ) -{ - for( int j = 0; j < iBlocks; j++ ) - { - if( !bsBlockUsed.getBit( j ) ) - { - initBlock( j, uFirstBlock/*, uPrevBlock*/ ); - return j; - } - } - // Oh, we don't have any blocks left...allocate a new one. - iBlocks++; - bsBlockUsed.setSize( iBlocks, false ); - initBlock( iBlocks-1, uFirstBlock/*, uPrevBlock*/, true ); - return iBlocks-1; -} - -int Bu::Nids::createStream( int iPreAllocate ) -{ - return createBlock( blockUnused, /*blockUnused,*/ iPreAllocate ); -} - -void Bu::Nids::deleteStream( int /*iID*/ ) -{ -} - -Bu::NidsStream Bu::Nids::openStream( int iID ) -{ - if( iBlockStart < 0 ) - { - initialize(); - } - return NidsStream( *this, iID ); -} - -int Bu::Nids::getBlockSize() -{ - return iBlockSize; -} - -int Bu::Nids::getNumBlocks() -{ - return iBlocks; -} - -int Bu::Nids::getNumUsedBlocks() -{ - return iUsed; -} - -int Bu::Nids::getBlockStart() -{ - return iBlockStart; -} - -int Bu::Nids::getBlockOverhead() -{ - return sizeof(Block); -} - -/* -void Bu::Nids::extendStream( int iID, int iBlockCount ) -{ -}*/ - -void Bu::Nids::getBlock( uint32_t uIndex, Bu::Nids::Block *pBlock ) -{ - sStore.setPos( iBlockStart + (iBlockSize*uIndex) ); - sStore.read( pBlock, iBlockSize ); -} - -void Bu::Nids::setBlock( uint32_t uIndex, Bu::Nids::Block *pBlock ) -{ - sStore.setPos( iBlockStart + (iBlockSize*uIndex) ); - sStore.write( pBlock, iBlockSize ); -} - -void Bu::Nids::updateStreamSize( uint32_t uIndex, uint32_t uSize ) -{ - if( !sStore.canWrite() ) - return; - sStore.setPos( iBlockStart + (iBlockSize*uIndex)+4*2 ); - sStore.write( &uSize, 4 ); -} - -uint32_t Bu::Nids::getNextBlock( uint32_t uIndex, - struct Bu::Nids::Block *pBlock, bool bCreate ) -{ - uint32_t uNew; - if( pBlock->uNextBlock == blockUnused ) - { - if( bCreate ) - { - uNew = createBlock( pBlock->uFirstBlock, uIndex ); - sStore.setPos( iBlockStart + (iBlockSize*uIndex)+1*4 ); - sStore.write( &uNew, 4 ); - getBlock( uNew, pBlock ); - //printf("Allocated new block (%u) for stream %u.\n", - // uNew, pBlock->uFirstBlock ); - } - else - { - throw Bu::NidsException("Reached end of stream."); - } - } - else - { - uNew = pBlock->uNextBlock; - getBlock( pBlock->uNextBlock, pBlock ); - } - return uNew; -} - -Bu::Nids::Block *Bu::Nids::newBlock() -{ - return (Block *)new char[iBlockSize]; -} - -void Bu::Nids::deleteBlock( Block *pBlock ) -{ - delete[] (char *)pBlock; -} - diff --git a/src/nids.h b/src/nids.h deleted file mode 100644 index 0976e67..0000000 --- a/src/nids.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - * 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. - */ - -#ifndef BU_NIDS_H -#define BU_NIDS_H - -#include -#include "bu/bitstring.h" -#include "bu/exceptionbase.h" - -namespace Bu -{ - class Stream; - class NidsStream; - - subExceptionDecl( NidsException ) - - /** - * Numerically Indexed Data Streams. This is a working name so I can - * actually get some code written instead of agonizing over the name. - * - * This is a system for creating streams that contain other streams in - * a flexible block-allocated system. - */ - class Nids - { - friend class NidsStream; - public: - Nids( Bu::Stream &sStore ); - virtual ~Nids(); - - /** - * Initialize this object based on the data already in the assosiated - * stream. This will be called automatically for you if you forget, - * but if you want to pre-initialize for some reason, just call this - * once before you actually start doing anything with your Nids. - */ - void initialize(); - - /** - * Create a new Nids system in the assosiated stream. This should be - * used carefully, it will destroy all data already within the stream. - * More options will probably be added soon. - */ - void initialize( int iBlockSize, int iPreAllocate=1 ); - - /** - * Create a new stream within the Nids system. The ID of the new stream - * is returned. - */ - int createStream( int iPreAllocate=1 ); - - /** - * Delete a stream that's already within the Nids. - */ - void deleteStream( int iID ); - - /** - * Return a new Stream object assosiated with the given stream ID. - */ - NidsStream openStream( int iID ); - - int getBlockSize(); - int getNumBlocks(); - int getNumUsedBlocks(); - int getBlockStart(); - int getBlockOverhead(); - - /** - * Syncronize the header data, etc. with the storage stream. It's not - * a bad idea to call this periodically. - */ - void sync(); - - private: - typedef struct Block - { - uint32_t uFirstBlock; - uint32_t uNextBlock; - // uint32_t uPrevBlock; - uint32_t uBytesUsed; - // uint32_t uReserved; - unsigned char pData[0]; - } Block; - - enum - { - blockUnused = 0xFFFFFFFFUL - }; - - void initBlock( uint32_t uPos, uint32_t uFirstBlock, - /*uint32_t uPrevBlock,*/ bool bNew=false ); - uint32_t createBlock( uint32_t uFirstBlock, /*uint32_t uPrevBlock,*/ - int iPreAllocate=1 ); - void getBlock( uint32_t uIndex, Block *pBlock ); - void setBlock( uint32_t uIndex, Block *pBlock ); - void updateStreamSize( uint32_t uIndex, uint32_t uSize ); - uint32_t getNextBlock( uint32_t uIndex, Block *pBlock, - bool bCreate=true); - - void updateHeader(); - - // Block allocation routines - Block *newBlock(); - void deleteBlock( Block *pBlock ); - - private: - Bu::Stream &sStore; - int iBlockSize; - int iBlocks; - int iBlockStart; - int iUsed; - Bu::BitString bsBlockUsed; - }; -}; - -#endif diff --git a/src/nidsstream.cpp b/src/nidsstream.cpp deleted file mode 100644 index 65c8962..0000000 --- a/src/nidsstream.cpp +++ /dev/null @@ -1,237 +0,0 @@ -/* - * 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 "bu/nidsstream.h" - -#include - -Bu::NidsStream::NidsStream( Nids &rNids, uint32_t uStream ) : - rNids( rNids ), - uStream( uStream ), - pCurBlock( NULL ), - uCurBlock( uStream ), - uSize( 0 ), - uBlockSize( rNids.iBlockSize-sizeof(Nids::Block) ), - uPos( 0 ) -{ - //printf("NidsStream::allocated\n"); - pCurBlock = rNids.newBlock(); - rNids.getBlock( uStream, pCurBlock ); - uSize = pCurBlock->uBytesUsed; -} - -/* -Bu::NidsStream::NidsStream( const Bu::NidsStream &rSrc ) : - Stream( rSrc ), - rNids( rSrc.rNids ), - uStream( rSrc.uStream ), - pCurBlock( NULL ), - uCurBlock( uStream ), - uSize( 0 ), - uBlockSize( rSrc.uBlockSize ), - iUsable( uBlockSize-sizeof(Nids::Block) ), - uPos( 0 ) -{ - printf("NidsStream::copied\n"); - pCurBlock = rNids.newBlock(); - rNids.getBlock( uStream, pCurBlock ); -}*/ - -Bu::NidsStream::~NidsStream() -{ - //printf("Destroying stream?\n"); - rNids.updateStreamSize( uStream, uSize ); - rNids.deleteBlock( pCurBlock ); -} - -void Bu::NidsStream::close() -{ -} - -size_t Bu::NidsStream::read( void *pBuf, size_t nBytes ) -{ - if( nBytes == 0 ) - return 0; - if( nBytes + uPos > uSize ) - nBytes = uSize - uPos; - if( (uPos%uBlockSize)+nBytes < uBlockSize ) - { - size_t iRead = nBytes; - if( iRead > pCurBlock->uBytesUsed-(uPos%uBlockSize) ) - iRead = pCurBlock->uBytesUsed-(uPos%uBlockSize); - memcpy( pBuf, pCurBlock->pData+(uPos%uBlockSize), iRead ); - //printf("read buffill: %ub, %u-%u/%u -> %d-%d/%d (a:%u)", - // iRead, uPos, uPos+iRead-1, uSize, 0, iRead-1, nBytes, uCurBlock ); - uPos += iRead; - //printf(" -- %u\n", uPos%uBlockSize ); - //printf("ra: block %u = %ub:%u (%ub total)\n", - // uCurBlock, uPos, nBytes, uSize ); - - // This can't happen, if we're right on a boundery, it goes to the - // other case - //if( uPos%uBlockSize == 0 ) - // uCurBlock = rNids.getNextBlock( uCurBlock, pCurBlock, false ); - return iRead; - } - else - { - size_t nTotal = 0; - for(;;) - { - uint32_t iRead = nBytes; - if( iRead > uBlockSize-(uPos%uBlockSize) ) - iRead = uBlockSize-(uPos%uBlockSize); - if( iRead > pCurBlock->uBytesUsed-(uPos%uBlockSize) ) - iRead = pCurBlock->uBytesUsed-(uPos%uBlockSize); - memcpy( ((char *)pBuf)+nTotal, - pCurBlock->pData+(uPos%uBlockSize), iRead ); - //printf(" read buffill: %ub, %u-%u/%u -> %d-%d/%d (b:%u)\n", - // iRead, uPos, uPos+iRead-1, uSize, - // nTotal, nTotal+nBytes-1, nBytes, uCurBlock ); - uPos += iRead; - nBytes -= iRead; - nTotal += iRead; - //printf("rb: block %u = %ub:%u (%ub total)\n", - // uCurBlock, uPos, iRead, uSize ); - if( uPos%uBlockSize == 0 ) - uCurBlock = rNids.getNextBlock( uCurBlock, pCurBlock, false ); - if( nBytes == 0 || uPos >= uSize ) - return nTotal; - } - } - return 0; -} - -size_t Bu::NidsStream::write( const void *pBuf, size_t nBytes ) -{ - if( nBytes == 0 ) - return 0; -/* if( pCurBlock->uBytesUsed >= uBlockSize ) - { - // We're at the end of our current block, allocate another before we do - // anything. - uCurBlock = rNids.getNextBlock( uCurBlock, pCurBlock ); - } */ - if( (uPos%uBlockSize)+nBytes < uBlockSize ) - { - //printf("wa: %u:%u:%u:%u -> ", uPos, uPos%uBlockSize, uSize, pCurBlock->uBytesUsed ); - memcpy( pCurBlock->pData+(uPos%uBlockSize), pBuf, nBytes ); - //printf("write buffill: %ub, %u-%u/%u -> %d-%d/%d (a:%u:%u)\n", - // nBytes, 0, nBytes-1, nBytes, - // uPos, uPos+nBytes-1, uSize, uCurBlock, - // pCurBlock->uBytesUsed ); - if( (uPos%uBlockSize)+nBytes > pCurBlock->uBytesUsed ) - pCurBlock->uBytesUsed = (uPos%uBlockSize)+nBytes; - rNids.setBlock( uCurBlock, pCurBlock ); - uPos += nBytes; - if( uPos > uSize ) - uSize = uPos; - //printf("block %u = %ub (%ub total) %d:%u\n", - // uCurBlock, pCurBlock->uBytesUsed, uSize, nBytes, uPos ); - return nBytes; - } - else - { - size_t nTotal = 0; - for(;;) - { - uint32_t uNow = uBlockSize-(uPos%uBlockSize); - //printf("uNow: %u (%u-(%u%%%u)) %d req\n", uNow, uBlockSize, uPos, uBlockSize, nBytes ); - if( nBytes < uNow ) - uNow = nBytes; - memcpy( pCurBlock->pData+(uPos%uBlockSize), - &((char *)pBuf)[nTotal], uNow ); - //printf("write buffill: %ub, %u-%u/%u -> %d-%d/%d (b:%u:%u)\n", - // uNow, nTotal, nTotal+uNow-1, nBytes, - // uPos, uPos+uNow-1, uSize, uCurBlock, pCurBlock->uBytesUsed ); - if( (uPos%uBlockSize)+uNow > pCurBlock->uBytesUsed ) - pCurBlock->uBytesUsed = (uPos%uBlockSize)+uNow; - rNids.setBlock( uCurBlock, pCurBlock ); - uPos += uNow; - if( uPos > uSize ) - uSize = uPos; - nTotal += uNow; - nBytes -= uNow; - //printf("wb: block %u = %ub (%ub total)\n", - // uCurBlock, pCurBlock->uBytesUsed, uSize ); - //if( pCurBlock->uBytesUsed == uBlockSize ) - if( uPos%uBlockSize == 0 ) - uCurBlock = rNids.getNextBlock( uCurBlock, pCurBlock ); - if( nBytes == 0 ) - return nTotal; - } - } -} - -long Bu::NidsStream::tell() -{ - return uPos; -} - -void Bu::NidsStream::seek( long offset ) -{ - uPos += offset; -} - -void Bu::NidsStream::setPos( long pos ) -{ - uPos = pos; -} - -void Bu::NidsStream::setPosEnd( long pos ) -{ - uPos = uSize-pos-1; -} - -bool Bu::NidsStream::isEos() -{ - return true; -} - -bool Bu::NidsStream::isOpen() -{ - return true; -} - -void Bu::NidsStream::flush() -{ -} - -bool Bu::NidsStream::canRead() -{ - return true; -} - -bool Bu::NidsStream::canWrite() -{ - return true; -} - -bool Bu::NidsStream::isReadable() -{ - return true; -} - -bool Bu::NidsStream::isWritable() -{ - return true; -} - -bool Bu::NidsStream::isSeekable() -{ - return true; -} - -bool Bu::NidsStream::isBlocking() -{ - return true; -} - -void Bu::NidsStream::setBlocking( bool /*bBlocking*/ ) -{ -} - diff --git a/src/nidsstream.h b/src/nidsstream.h deleted file mode 100644 index c8c8ce0..0000000 --- a/src/nidsstream.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - * 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. - */ - -#ifndef BU_NIDS_STREAM_H -#define BU_NIDS_STREAM_H - -#include "bu/stream.h" -#include "bu/nids.h" - -namespace Bu -{ - class NidsStream : public Bu::Stream - { - friend class Nids; - private: - /** - * These can only be created by the Nids class. - */ - NidsStream( Nids &rNids, uint32_t uStream ); - - public: -// NidsStream( const NidsStream &rSrc ); - virtual ~NidsStream(); - - virtual void close(); - virtual size_t read( void *pBuf, size_t nBytes ); - virtual size_t write( const void *pBuf, size_t nBytes ); - using Stream::write; - virtual long tell(); - virtual void seek( long offset ); - virtual void setPos( long pos ); - virtual void setPosEnd( long pos ); - virtual bool isEos(); - virtual bool isOpen(); - virtual void flush(); - virtual bool canRead(); - virtual bool canWrite(); - virtual bool isReadable(); - virtual bool isWritable(); - virtual bool isSeekable(); - virtual bool isBlocking(); - virtual void setBlocking( bool bBlocking=true ); - - private: - Nids &rNids; - uint32_t uStream; - Nids::Block *pCurBlock; - uint32_t uCurBlock; - uint32_t uSize; - uint32_t uBlockSize; - uint32_t uPos; - }; -}; - -#endif diff --git a/src/tests/nids.cpp b/src/tests/nids.cpp deleted file mode 100644 index 22bf450..0000000 --- a/src/tests/nids.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 "bu/file.h" -#include "bu/nids.h" -#include "bu/nidsstream.h" - -int main( int argc, char *argv[] ) -{ - if( argc < 3 ) - { - printf("usage: %s [r|w] \n\n", argv[0] ); - return 1; - } - - if( argv[1][0] == 'w' ) - { - Bu::File fOut( argv[2], - Bu::File::ReadWrite|Bu::File::Create|Bu::File::Truncate ); - Bu::Nids n( fOut ); - - n.initialize( 32, 1 ); -/* Bu::NidsStream s = n.openStream( n.createStream() ); - - Bu::FString sBuf( 350 ); - memset( sBuf.getStr(), 'a', 350 ); - s.write( sBuf );*/ - } - else if( argv[1][0] == 'r' ) - { - Bu::File fOut( argv[2], Bu::File::Read ); - Bu::Nids n( fOut ); - n.initialize(); -/* - Bu::NidsStream s = n.openStream( 0 ); - char buf[75]; - for( int j = 0; j < 3; j++ ) - { - int iRead = s.read( buf, 75 ); - fwrite( buf, 1, iRead, stdout ); - printf("\n(read %d chars)\n", iRead ); - } - printf("Position: %ld\n", s.tell() ); - */ - } - else - { - printf("r or w, those are your choices.\n"); - } - - return 0; -} - diff --git a/src/tools/mkunit.cpp b/src/tools/mkunit.cpp new file mode 100644 index 0000000..43fab38 --- /dev/null +++ b/src/tools/mkunit.cpp @@ -0,0 +1,547 @@ +#include +#include +#include +#include +#include +#include + +using namespace Bu; + +class Test +{ +public: + Test() : + bExpectPass( true ) + { + } + + Bu::FString sName; + bool bExpectPass; +}; +typedef Bu::List TestList; + +class Suite +{ +public: + Bu::FString sName; + TestList lTest; +}; +//typedef Bu::List SuiteList; + +enum TokType +{ + tokFluff, + tokSuite, + tokTest, + tokChar, + tokBlock, + tokEof +}; + +Bu::Formatter &operator<<( Bu::Formatter &f, TokType t ) +{ + switch( t ) + { + case tokFluff: return f << "tokFluff"; + case tokSuite: return f << "tokSuite"; + case tokTest: return f << "tokTest"; + case tokChar: return f << "tokChar"; + case tokBlock: return f << "tokBlock"; + case tokEof: return f << "tokEof"; + } + + return f; +} + +Bu::Formatter &operator<<( Bu::Formatter &f, const Test &t ) +{ + return f << "{" << t.sName << ", bExpectPass=" << t.bExpectPass << "}"; +} + +Bu::Formatter &operator<<( Bu::Formatter &f, const Suite &s ) +{ + return f << "Suite[" << s.sName << "] = " << s.lTest << f.nl; +} + +class Parser +{ +public: + Parser( const Bu::FString &sFile ) : + fIn( sFile, File::Read ), + bIn( fIn ), + cBuf( 0 ), + bAvail( false ), + eMode( mRoot ), + iLine( 1 ), + iChar( 0 ), + iDepth( 0 ) + { + } + + char nextChar() + { + if( bAvail ) + return cBuf; + + if( bIn.read( &cBuf, 1 ) < 1 ) + throw Bu::ExceptionBase("End of stream"); + bAvail = true; + + if( cBuf == '\n' ) + { + iLine++; + iChar = 0; + } + else + iChar++; + + return cBuf; + } + + TokType nextToken( Variant &v, Bu::FString &sWsOut, int &iLineStart, + int &iCharStart ) + { + Bu::FString sTok, sWs; + + char buf; + try + { + buf = nextChar(); + } + catch(...) + { + return tokEof; + } + + for(;;) + { + if( buf == ' ' || buf == '\t' || buf == '\n' || buf == '\r' ) + { + sWs += buf; + bAvail = false; + } + else + break; + + try + { + buf = nextChar(); + } + catch(...) + { + sWsOut = sWs; + return tokEof; + } + } + + sWsOut = sWs; + + iLineStart = iLine; + iCharStart = iChar; + bool bInStr = false; + bool bDblStr; + + for(;;) + { + switch( eMode ) + { + case mRoot: + if( buf == ' ' || buf == '\t' || buf == '\n' + || buf == '\r' ) + { + if( sTok == "suite" ) + return tokSuite; + else + { + v = sTok; + return tokFluff; + } + } + else if( buf == '(' || buf == ')' || buf == '{' + || buf == '}' || buf == ';' ) + { + if( sTok.getSize() == 0 ) + { + bAvail = false; + v = buf; + return tokChar; + } + else + { + v = sTok; + return tokFluff; + } + } + else + { + sTok += buf; + bAvail = false; + } + break; + + case mSuite: + if( buf == ' ' || buf == '\t' || buf == '\n' + || buf == '\r' ) + { + if( sTok == "test" ) + return tokTest; + else + { + v = sTok; + return tokFluff; + } + } + else if( buf == '(' || buf == ')' + || buf == '}' || buf == ';' ) + { + if( sTok.getSize() == 0 ) + { + bAvail = false; + v = buf; + return tokChar; + } + else + { + v = sTok; + return tokFluff; + } + } + else if( buf == '{' ) + { + if( sTok.getSize() > 0 ) + { + v = sTok; + return tokFluff; + } + else + { + sTok += buf; + bAvail = false; + eMode = mBlock; + iDepth = 1; + } + } + else + { + sTok += buf; + bAvail = false; + } + break; + + case mBlock: + if( bInStr ) + { + if( buf == '\\' ) + { + sTok += buf; + bAvail = false; + sTok += nextChar(); + bAvail = false; + } + else if( bDblStr == true && buf == '\"' ) + { + sTok += buf; + bAvail = false; + bInStr = false; + } + else if( bDblStr == false && buf == '\'' ) + { + sTok += buf; + bAvail = false; + bInStr = false; + } + else + { + sTok += buf; + bAvail = false; + } + } + else + { + if( buf == '\"' ) + { + bInStr = true; + bDblStr = true; + sTok += buf; + bAvail = false; + } + else if( buf == '\'' ) + { + bInStr = true; + bDblStr = false; + sTok += buf; + bAvail = false; + } + else if( buf == '}' ) + { + sTok += buf; + bAvail = false; + iDepth--; + if( iDepth == 0 ) + { + v = sTok; + eMode = mSuite; + return tokBlock; + } + } + else if( buf == '{' ) + { + sTok += buf; + bAvail = false; + iDepth++; + } + else + { + sTok += buf; + bAvail = false; + } + } + break; + } + + buf = nextChar(); + } + } + + void firstPass() + { + Variant v; + Bu::FString sWs; + int iL, iC; + for(;;) + { + TokType t = nextToken( v, sWs, iL, iC ); + if( t == tokEof ) + return; + switch( eMode ) + { + case mRoot: + if( t == tokSuite ) + { + if( nextToken( v, sWs, iL, iC ) != tokFluff ) + throw Bu::ExceptionBase("%d:%d: Expected string " + "following suite.", iL, iC ); + s.sName = v.get(); + if( nextToken( v, sWs, iL, iC ) != tokChar || + v.get() != '{' ) + throw Bu::ExceptionBase("%d:%d: Expected {, got " + "'%s'", iL, iC, v.toString().getStr() ); + eMode = mSuite; + } + break; + + case mSuite: + switch( t ) + { + case tokFluff: + break; + + case tokBlock: + break; + + case tokTest: + { + if( nextToken( v, sWs, iL, iC ) != tokFluff ) + throw Bu::ExceptionBase("%d:%d: Expected " + "string following test.", iL, iC ); + Test t; + t.sName = v.get(); + if( nextToken( v, sWs, iL, iC ) != tokBlock ) + throw Bu::ExceptionBase("%d:%d: Expected " + "{...} block.", + iL, iC ); + s.lTest.append( t ); + } + break; + + case tokChar: + if( v.get() == '}' ) + { + eMode = mRoot; + } + else + { + } + break; + + default: + sio << iL << ":" << iC << ": Unexpected " + << t << " found." << sio.nl; + return; + break; + } + break; + + default: + sio << "???" << sio.nl; + break; + } + } + } + + void secondPass( const Bu::FString &sOut ) + { + File fOut( sOut, File::WriteNew ); + Formatter f( fOut ); + fIn.setPos( 0 ); + bIn.stop(); + bIn.start(); + bAvail = false; + eMode = mRoot; + iLine = 1; + iChar = 0; + bool bHasIncluded = false; + + Bu::FString sWs; + Variant v; + int iL, iC; + for(;;) + { + TokType t = nextToken( v, sWs, iL, iC ); + switch( eMode ) + { + case mRoot: + if( t == tokSuite ) + { + fOut.write( sWs ); + if( nextToken( v, sWs, iL, iC ) != tokFluff ) + throw Bu::ExceptionBase("%d:%d: Expected string " + "following suite.", iL, iC ); + s.sName = v.get(); + if( nextToken( v, sWs, iL, iC ) != tokChar || + v.get() != '{' ) + throw Bu::ExceptionBase("%d:%d: Expected {", + iL, iC ); + eMode = mSuite; + + if( bHasIncluded == false ) + { + fOut.write("#include \n"); + bHasIncluded = true; + } + + Bu::FString sClass = "_UnitSuite_" + s.sName; + f << "class " << sClass + << " : public Bu::UnitSuite" << f.nl + << "{" << f.nl << "public:" << f.nl + << "\t" << sClass << "()" << f.nl + << "\t{" << f.nl + << "\t\tsetName(\"" << s.sName << "\");" << f.nl; + for( TestList::iterator i = s.lTest.begin(); i; i++ ) + { + f << "\t\tadd( static_cast(" + "&" << sClass << "::" << (*i).sName << "), \"" + << (*i).sName << "\", Bu::UnitSuite::" + "expectPass );" << f.nl; + } + f << "\t}" << f.nl << f.nl + << "\tvirtual ~" << sClass << "() { }" << f.nl + << f.nl; + } + else if( t == tokEof ) + { + Bu::FString sClass = "_UnitSuite_" + s.sName; + f << sWs << f.nl << "int main( int argc, char *argv[] )" + << f.nl << "{" << f.nl << "\treturn " << sClass + << "().run( argc, argv );" << f.nl << "}" << f.nl; + } + else + { + fOut.write( sWs ); + f << v; + } + break; + + case mSuite: + switch( t ) + { + case tokFluff: + fOut.write( sWs ); + fOut.write( v.get() ); + break; + + case tokTest: + { + fOut.write( sWs ); + if( nextToken( v, sWs, iL, iC ) != tokFluff ) + throw Bu::ExceptionBase("%d:%d: Expected " + "string following test.", iL, iC ); + Test t; + t.sName = v.get(); + if( nextToken( v, sWs, iL, iC ) != tokBlock ) + throw Bu::ExceptionBase("%d:%d: Expected " + "{...} block.", + iL, iC ); + + f << "\tvoid " << t.sName << "()" + << f.nl << "#line " << iL + << " \"" << sOut << "\"" << f.nl + << v << f.nl; + } + break; + + case tokChar: + if( v.get() == '}' ) + { + f << "};" << f.nl << f.nl; + eMode = mRoot; + } + else + { + char buf = v.get(); + fOut.write( sWs ); + fOut.write( &buf, 1 ); + } + break; + + case tokBlock: + fOut.write( sWs ); + f << f.nl << "#line " << iL << " \"" << sOut + << "\"" << f.nl; + fOut.write( v.get() ); + + break; + + default: + sio << iL << ":" << iC << ": Unexpected " + << t << " found." << sio.nl; + return; + break; + } + break; + + default: + sio << "???" << sio.nl; + break; + } + if( t == tokEof ) + return; + } + } + +private: + File fIn; + Buffer bIn; + char cBuf; + bool bAvail; + enum Mode + { + mRoot, + mSuite, + mBlock + }; + Mode eMode; + int iLine, iChar; + int iDepth; + Suite s; +}; + +int main( int argc, char *argv[] ) +{ + Parser p( argv[1] ); + + p.firstPass(); + + p.secondPass( argv[2] ); +} + diff --git a/src/tools/nidstool.cpp b/src/tools/nidstool.cpp deleted file mode 100644 index 41179f9..0000000 --- a/src/tools/nidstool.cpp +++ /dev/null @@ -1,248 +0,0 @@ -/* - * 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 "bu/file.h" -#include "bu/nids.h" -#include "bu/nidsstream.h" -#include "bu/paramproc.h" - -#include - -typedef struct Block -{ - uint32_t uFirstBlock; - uint32_t uNextBlock; - uint32_t uBytesUsed; -} Block; - -class Param : public Bu::ParamProc -{ -public: - Param( int argc, char *argv[] ) - { - addHelpBanner("nidstool - Do stuff with nids files.\n\n"); - addParam("info", 'i', mkproc(Param::procInfo), - "Print some info about the file."); - addParam("dump", 'd', mkproc(Param::procDump), - "Dump a stream to a file."); - addParam("analyze", 'a', mkproc(Param::procAnalyze), - "Analyze a nids file."); - addParam("copy", 'c', mkproc(Param::procCopy), - "Copy a nids file, changing settings."); - addParam("help", 'h', mkproc(Bu::ParamProc::help), "This help."); - process( argc, argv ); - } - - virtual ~Param() - { - } - - void printInfo( Bu::Nids &n ) - { - printf("File info:\n"); - printf(" Header overhead: %db\n", n.getBlockStart() ); - printf(" Block size: %db\n", n.getBlockSize() ); - printf(" Block count: %d\n", n.getNumBlocks() ); - printf(" Blocks used: %d (%d%%)\n", n.getNumUsedBlocks(), - n.getNumUsedBlocks()*100/n.getNumBlocks() ); - printf(" Block overhead: %db\n", n.getBlockOverhead() ); - printf(" Block storage: %db (%d%%)\n", - n.getBlockSize()-n.getBlockOverhead(), - (n.getBlockSize()-n.getBlockOverhead())*100/n.getBlockSize() ); - } - - int procInfo( int argc, char *argv[] ) - { - if( argc < 1 ) - { - printf("You must provide a file name.\n"); - exit( 1 ); - } - - Bu::File fIn( argv[0], Bu::File::Read ); - Bu::Nids n( fIn ); - n.initialize(); - - printInfo( n ); - - if( argc >= 2 ) - { - uint32_t uStream = strtoul( argv[1], NULL, 0 ); - uint32_t uBlock = uStream; - - Block b; - - for(;;) - { - fIn.setPos( n.getBlockStart()+n.getBlockSize()*uBlock ); - fIn.read( &b, sizeof(Block) ); - printf("Stream %u: block %u, next %u, %ub used.\n", - uStream, uBlock, b.uNextBlock, b.uBytesUsed - ); - if( b.uNextBlock == 0xFFFFFFFFUL ) - break; - uBlock = b.uNextBlock; - } - printf("Stream End.\n"); - - return 2; - } - - return 1; - } - - int procDump( int argc, char *argv[] ) - { - if( argc < 3 ) - { - printf("You must provide a nids file, a stream id, and an output " - "file.\n"); - exit( 1 ); - } - - Bu::File fIn( argv[0], Bu::File::Read ); - Bu::Nids n( fIn ); - n.initialize(); - - int iStream = strtol( argv[1], NULL, 0 ); - Bu::NidsStream sIn = n.openStream( iStream ); - - Bu::File fOut( argv[2], Bu::File::Write|Bu::File::Create ); - int iTotal = 0; - char buf[100]; - for(;;) - { - int iRead = sIn.read( buf, 100 ); - iTotal += fOut.write( buf, iRead ); - if( iRead < 100 ) - break; - } - - printf("Wrote %db from stream %d in %s to %s.\n", - iTotal, iStream, argv[0], argv[2] ); - return 3; - } - - int procAnalyze( int argc, char *argv[] ) - { - if( argc < 1 ) - { - printf("You must provide a file name.\n"); - exit( 1 ); - } - - Bu::File fIn( argv[0], Bu::File::Read ); - Bu::Nids n( fIn ); - n.initialize(); - - printInfo( n ); - - int iStreamCnt = 0; - int iStreamTotal = 0; - int iOneBlock = 0; - uint32_t iLargest = 0; - uint32_t iSmallest = 0; - int iWaste = 0; - int iUsable = n.getBlockSize()-n.getBlockOverhead(); - Block b; - for( int j = 0; j < n.getNumBlocks(); j++ ) - { - fIn.setPos( n.getBlockStart()+n.getBlockSize()*j ); - fIn.read( &b, sizeof(Block) ); - if( b.uFirstBlock != (uint32_t)j ) - continue; - - iStreamCnt++; - iStreamTotal += b.uBytesUsed; - - if( b.uNextBlock == 0xFFFFFFFFUL ) - { - iOneBlock++; - iWaste += iUsable - b.uBytesUsed; - } - else - { - iWaste += iUsable - (b.uBytesUsed%iUsable); - } - - if( j == 0 ) - { - iSmallest = iLargest = b.uBytesUsed; - } - else - { - if( iLargest < b.uBytesUsed ) - iLargest = b.uBytesUsed; - if( iSmallest > b.uBytesUsed ) - iSmallest = b.uBytesUsed; - } - } - printf("Steam analysis:\n"); - printf(" Stream count: %d\n", iStreamCnt ); - printf(" Stream size: %db/%db/%db (min/avr/max)\n", - iSmallest, iStreamTotal/iStreamCnt, iLargest ); - printf(" One-block streams: %d (%d%%)\n", - iOneBlock, iOneBlock*100/iStreamCnt ); - printf(" Total wasted space: %db (%d%%)\n", - iWaste, iWaste*100/iStreamTotal ); - printf(" Avr blocks-per-stream: %f%%\n", - (float)n.getNumBlocks()/(float)iStreamCnt ); - - return 1; - } - - int procCopy( int argc, char *argv[] ) - { - if( argc < 3 ) - { - printf("You must provide source stream, blocksize, destination.\n"); - exit( 1 ); - } - - Bu::File fIn( argv[0], Bu::File::Read ); - Bu::Nids nIn( fIn ); - nIn.initialize(); - - Bu::File fOut( argv[2], Bu::File::Read|Bu::File::Write|Bu::File::Create| - Bu::File::Truncate ); - Bu::Nids nOut( fOut ); - nOut.initialize( strtol( argv[1], 0, NULL ) ); - - Block b; - for( int j = 0; j < nIn.getNumBlocks(); j++ ) - { - fIn.setPos( nIn.getBlockStart()+nIn.getBlockSize()*j ); - fIn.read( &b, sizeof(Block) ); - if( b.uFirstBlock != (uint32_t)j ) - continue; - - Bu::NidsStream sIn = nIn.openStream( j ); - int iNew = nOut.createStream(); - Bu::NidsStream sOut = nOut.openStream( iNew ); - - char buf[1024]; - for(;;) - { - int iRead = sIn.read( buf, 1024 ); - sOut.write( buf, iRead ); - if( iRead < 1024 ) - break; - } - } - - return 3; - } -}; - - -int main( int argc, char *argv[] ) -{ - Param p( argc, argv ); - - return 0; -} - diff --git a/src/unit/archive.unit b/src/unit/archive.unit index a0ae3ef..a7f2640 100644 --- a/src/unit/archive.unit +++ b/src/unit/archive.unit @@ -12,184 +12,185 @@ using namespace Bu; -{=Init} - -{%testPrimitives} +suite Archive { - MemBuf mb; - { - Archive ar( mb, Archive::save ); - ar << (int8_t)1; - ar << (uint8_t)2; - ar << (int16_t)3; - ar << (uint16_t)4; - ar << (int32_t)5; - ar << (uint32_t)6; - ar << (int64_t)7; - ar << (uint64_t)8; - ar << (char)9; - ar << (unsigned char)10; - ar << (short)11; - ar << (unsigned short)12; - ar << (int)13; - ar << (unsigned int)14; - ar << (long)15; - ar << (unsigned long)16; - ar << (long long)17; - ar << (unsigned long long)18; - ar.close(); - } - mb.setPos( 0 ); + test primitives { - Archive ar( mb, Archive::load ); - int8_t p1; - uint8_t p2; - int16_t p3; - uint16_t p4; - int32_t p5; - uint32_t p6; - int64_t p7; - uint64_t p8; - char p9; - unsigned char p10; - short p11; - unsigned short p12; - int p13; - unsigned int p14; - long p15; - unsigned long p16; - long long p17; - unsigned long long p18; - ar >> p1; - ar >> p2; - ar >> p3; - ar >> p4; - ar >> p5; - ar >> p6; - ar >> p7; - ar >> p8; - ar >> p9; - ar >> p10; - ar >> p11; - ar >> p12; - ar >> p13; - ar >> p14; - ar >> p15; - ar >> p16; - ar >> p17; - ar >> p18; - unitTest( p1 == 1 ); - unitTest( p2 == 2 ); - unitTest( p3 == 3 ); - unitTest( p4 == 4 ); - unitTest( p5 == 5 ); - unitTest( p6 == 6 ); - unitTest( p7 == 7 ); - unitTest( p8 == 8 ); - unitTest( p9 == 9 ); - unitTest( p10 == 10 ); - unitTest( p11 == 11 ); - unitTest( p12 == 12 ); - unitTest( p13 == 13 ); - unitTest( p14 == 14 ); - unitTest( p15 == 15 ); - unitTest( p16 == 16 ); - unitTest( p17 == 17 ); - unitTest( p18 == 18 ); - ar.close(); + MemBuf mb; + { + Archive ar( mb, Archive::save ); + ar << (int8_t)1; + ar << (uint8_t)2; + ar << (int16_t)3; + ar << (uint16_t)4; + ar << (int32_t)5; + ar << (uint32_t)6; + ar << (int64_t)7; + ar << (uint64_t)8; + ar << (char)9; + ar << (unsigned char)10; + ar << (short)11; + ar << (unsigned short)12; + ar << (int)13; + ar << (unsigned int)14; + ar << (long)15; + ar << (unsigned long)16; + ar << (long long)17; + ar << (unsigned long long)18; + ar.close(); + } + mb.setPos( 0 ); + { + Archive ar( mb, Archive::load ); + int8_t p1; + uint8_t p2; + int16_t p3; + uint16_t p4; + int32_t p5; + uint32_t p6; + int64_t p7; + uint64_t p8; + char p9; + unsigned char p10; + short p11; + unsigned short p12; + int p13; + unsigned int p14; + long p15; + unsigned long p16; + long long p17; + unsigned long long p18; + ar >> p1; + ar >> p2; + ar >> p3; + ar >> p4; + ar >> p5; + ar >> p6; + ar >> p7; + ar >> p8; + ar >> p9; + ar >> p10; + ar >> p11; + ar >> p12; + ar >> p13; + ar >> p14; + ar >> p15; + ar >> p16; + ar >> p17; + ar >> p18; + unitTest( p1 == 1 ); + unitTest( p2 == 2 ); + unitTest( p3 == 3 ); + unitTest( p4 == 4 ); + unitTest( p5 == 5 ); + unitTest( p6 == 6 ); + unitTest( p7 == 7 ); + unitTest( p8 == 8 ); + unitTest( p9 == 9 ); + unitTest( p10 == 10 ); + unitTest( p11 == 11 ); + unitTest( p12 == 12 ); + unitTest( p13 == 13 ); + unitTest( p14 == 14 ); + unitTest( p15 == 15 ); + unitTest( p16 == 16 ); + unitTest( p17 == 17 ); + unitTest( p18 == 18 ); + ar.close(); + } } -} -{%testContainers1} -{ - MemBuf mb; - { - Archive ar( mb, Archive::save ); - FString sStr("This is a test string."); - List lList; - lList.append( 10 ); - lList.append( 20 ); - lList.append( 30 ); - lList.append( 40 ); - ar << sStr; - ar << lList; - ar.close(); - } - mb.setPos( 0 ); + test containers1 { - Archive ar( mb, Archive::load ); - FString sStr; - List lList; - ar >> sStr; - ar >> lList; - unitTest( sStr == "This is a test string." ); - unitTest( lList.getSize() == 4 ); - List::iterator i = lList.begin(); - unitTest( *i == 10 ); i++; - unitTest( *i == 20 ); i++; - unitTest( *i == 30 ); i++; - unitTest( *i == 40 ); - ar.close(); + MemBuf mb; + { + Archive ar( mb, Archive::save ); + FString sStr("This is a test string."); + List lList; + lList.append( 10 ); + lList.append( 20 ); + lList.append( 30 ); + lList.append( 40 ); + ar << sStr; + ar << lList; + ar.close(); + } + mb.setPos( 0 ); + { + Archive ar( mb, Archive::load ); + FString sStr; + List lList; + ar >> sStr; + ar >> lList; + unitTest( sStr == "This is a test string." ); + unitTest( lList.getSize() == 4 ); + List::iterator i = lList.begin(); + unitTest( *i == 10 ); i++; + unitTest( *i == 20 ); i++; + unitTest( *i == 30 ); i++; + unitTest( *i == 40 ); + ar.close(); + } } -} -{%testContainers2} -{ - MemBuf mb; - { - Archive ar( mb, Archive::save ); - FString sStr("This is a test string."); - Array lArray; - lArray.append( 10 ); - lArray.append( 20 ); - lArray.append( 30 ); - lArray.append( 40 ); - ar << sStr; - ar << lArray; - ar.close(); - } - mb.setPos( 0 ); + test containers2 { - Archive ar( mb, Archive::load ); - FString sStr; - Array lArray; - ar >> sStr; - ar >> lArray; - unitTest( sStr == "This is a test string." ); - unitTest( lArray.getSize() == 4 ); - Array::iterator i = lArray.begin(); - unitTest( *i == 10 ); i++; - unitTest( *i == 20 ); i++; - unitTest( *i == 30 ); i++; - unitTest( *i == 40 ); - ar.close(); + MemBuf mb; + { + Archive ar( mb, Archive::save ); + FString sStr("This is a test string."); + Array lArray; + lArray.append( 10 ); + lArray.append( 20 ); + lArray.append( 30 ); + lArray.append( 40 ); + ar << sStr; + ar << lArray; + ar.close(); + } + mb.setPos( 0 ); + { + Archive ar( mb, Archive::load ); + FString sStr; + Array lArray; + ar >> sStr; + ar >> lArray; + unitTest( sStr == "This is a test string." ); + unitTest( lArray.getSize() == 4 ); + Array::iterator i = lArray.begin(); + unitTest( *i == 10 ); i++; + unitTest( *i == 20 ); i++; + unitTest( *i == 30 ); i++; + unitTest( *i == 40 ); + ar.close(); + } } -} -{%testContainers3} -{ - MemBuf mb; - { - Archive ar( mb, Archive::save ); - Array lArray; - lArray.append( "10" ); - lArray.append( "20" ); - lArray.append( "30" ); - lArray.append( "40" ); - ar << lArray; - ar.close(); - } - mb.setPos( 0 ); + test containers3 { - Archive ar( mb, Archive::load ); - Array lArray; - ar >> lArray; - unitTest( lArray.getSize() == 4 ); - Array::iterator i = lArray.begin(); - unitTest( *i == "10" ); i++; - unitTest( *i == "20" ); i++; - unitTest( *i == "30" ); i++; - unitTest( *i == "40" ); - ar.close(); + MemBuf mb; + { + Archive ar( mb, Archive::save ); + Array lArray; + lArray.append( "10" ); + lArray.append( "20" ); + lArray.append( "30" ); + lArray.append( "40" ); + ar << lArray; + ar.close(); + } + mb.setPos( 0 ); + { + Archive ar( mb, Archive::load ); + Array lArray; + ar >> lArray; + unitTest( lArray.getSize() == 4 ); + Array::iterator i = lArray.begin(); + unitTest( *i == "10" ); i++; + unitTest( *i == "20" ); i++; + unitTest( *i == "30" ); i++; + unitTest( *i == "40" ); + ar.close(); + } } } diff --git a/src/unit/array.unit b/src/unit/array.unit index ad249ef..1493033 100644 --- a/src/unit/array.unit +++ b/src/unit/array.unit @@ -9,76 +9,77 @@ #include "bu/hash.h" #include "bu/array.h" -{=Init} - -{%general} +suite Array { - Bu::Array ai; + test general + { + Bu::Array ai; - ai.append( 5 ); - ai.append( 10 ); - unitTest( ai.getSize() == 2 ); - unitTest( ai.getCapacity() == 10 ); - unitTest( ai[0] == 5 ); - unitTest( ai[1] == 10 ); -} + ai.append( 5 ); + ai.append( 10 ); + unitTest( ai.getSize() == 2 ); + unitTest( ai.getCapacity() == 10 ); + unitTest( ai[0] == 5 ); + unitTest( ai[1] == 10 ); + } -{%iterate1} -{ - Bu::Array ai; - for( int j = 0; j < 10; j++ ) - ai.append( j ); + test iterate1 + { + Bu::Array ai; + for( int j = 0; j < 10; j++ ) + ai.append( j ); - int j = 0; - for( Bu::Array::iterator i = ai.begin(); i != ai.end(); i++ ) - unitTest( (*i) == j++ ); - unitTest( j == 10 ); - - const Bu::Array &ci = ai; - j = 0; - for( Bu::Array::const_iterator i = ci.begin(); i; i++ ) - unitTest( (*i) == j++ ); - unitTest( j == 10 ); -} + int j = 0; + for( Bu::Array::iterator i = ai.begin(); i != ai.end(); i++ ) + unitTest( (*i) == j++ ); + unitTest( j == 10 ); + + const Bu::Array &ci = ai; + j = 0; + for( Bu::Array::const_iterator i = ci.begin(); i; i++ ) + unitTest( (*i) == j++ ); + unitTest( j == 10 ); + } -{%iterate2} -{ - Bu::Array ai; - for( Bu::Array::iterator i = ai.begin(); i != ai.end(); i++ ) - unitFailed("Empty lists shouldn't be iterated through."); - for( Bu::Array::iterator i = ai.begin(); i; i++ ) - unitFailed("Empty lists shouldn't be iterated through."); -} + test iterate2 + { + Bu::Array ai; + for( Bu::Array::iterator i = ai.begin(); i != ai.end(); i++ ) + unitFailed("Empty lists shouldn't be iterated through."); + for( Bu::Array::iterator i = ai.begin(); i; i++ ) + unitFailed("Empty lists shouldn't be iterated through."); + } -{%copy} -{ - typedef Bu::Hash StrHash; - typedef Bu::Array StrHashArray; + test copy + { + typedef Bu::Hash StrHash; + typedef Bu::Array StrHashArray; - StrHash h1; - h1["Hi"] = "Yo"; - h1["Bye"] = "Later"; + StrHash h1; + h1["Hi"] = "Yo"; + h1["Bye"] = "Later"; - StrHash h2; - h2["Test"] = "Bloop"; - h2["Foo"] = "ooF"; + StrHash h2; + h2["Test"] = "Bloop"; + h2["Foo"] = "ooF"; - StrHashArray a1; - a1.append( h1 ); - a1.append( h2 ); + StrHashArray a1; + a1.append( h1 ); + a1.append( h2 ); - StrHashArray a2(a1); + StrHashArray a2(a1); - unitTest( a2[0].get("Hi") == "Yo" ); - unitTest( a2[0].get("Bye") == "Later" ); - unitTest( a2[1].get("Test") == "Bloop" ); - unitTest( a2[1].get("Foo") == "ooF" ); + unitTest( a2[0].get("Hi") == "Yo" ); + unitTest( a2[0].get("Bye") == "Later" ); + unitTest( a2[1].get("Test") == "Bloop" ); + unitTest( a2[1].get("Foo") == "ooF" ); - StrHashArray a3; - a3 = a1; - - unitTest( a3[0].get("Hi") == "Yo" ); - unitTest( a3[0].get("Bye") == "Later" ); - unitTest( a3[1].get("Test") == "Bloop" ); - unitTest( a3[1].get("Foo") == "ooF" ); + StrHashArray a3; + a3 = a1; + + unitTest( a3[0].get("Hi") == "Yo" ); + unitTest( a3[0].get("Bye") == "Later" ); + unitTest( a3[1].get("Test") == "Bloop" ); + unitTest( a3[1].get("Foo") == "ooF" ); + } } diff --git a/src/unit/file.unit b/src/unit/file.unit index 11c82fb..f8cf7c1 100644 --- a/src/unit/file.unit +++ b/src/unit/file.unit @@ -12,84 +12,85 @@ #include #include -{=Init} - -{%writeFull} +suite File { - Bu::File sf("testfile1", Bu::File::WriteNew ); - for( int c = 0; c < 256; c++ ) + test writeFull { - unsigned char ch = (unsigned char)c; - sf.write( &ch, 1 ); - unitTest( sf.tell() == c+1 ); + Bu::File sf("testfile1", Bu::File::WriteNew ); + for( int c = 0; c < 256; c++ ) + { + unsigned char ch = (unsigned char)c; + sf.write( &ch, 1 ); + unitTest( sf.tell() == c+1 ); + } + //unitTest( sf.canRead() == false ); + //unitTest( sf.canWrite() == true ); + //unitTest( sf.canSeek() == true ); + sf.close(); + struct stat sdat; + stat("testfile1", &sdat ); + unitTest( sdat.st_size == 256 ); } - //unitTest( sf.canRead() == false ); - //unitTest( sf.canWrite() == true ); - //unitTest( sf.canSeek() == true ); - sf.close(); - struct stat sdat; - stat("testfile1", &sdat ); - unitTest( sdat.st_size == 256 ); -} -{%readBlocks} -{ - Bu::File sf("testfile1", Bu::File::Read ); - unsigned char buf[50]; - size_t total = 0; - for(;;) + test readBlocks { - size_t s = sf.read( buf, 50 ); - for( size_t c = 0; c < s; c++ ) + Bu::File sf("testfile1", Bu::File::Read ); + unsigned char buf[50]; + size_t total = 0; + for(;;) { - unitTest( buf[c] == (unsigned char)(c+total) ); - } - total += s; - if( s < 50 ) - { - unitTest( total == 256 ); - unitTest( sf.isEos() == true ); - break; + size_t s = sf.read( buf, 50 ); + for( size_t c = 0; c < s; c++ ) + { + unitTest( buf[c] == (unsigned char)(c+total) ); + } + total += s; + if( s < 50 ) + { + unitTest( total == 256 ); + unitTest( sf.isEos() == true ); + break; + } } + sf.close(); } - sf.close(); -} -{%readError1} -{ - try + test readError1 { - Bu::File sf("doesn'texist", Bu::File::Read ); - unitFailed("No exception thrown"); - } - catch( Bu::FileException &e ) - { - return; + try + { + Bu::File sf("doesn'texist", Bu::File::Read ); + unitFailed("No exception thrown"); + } + catch( Bu::FileException &e ) + { + return; + } } -} -{%readError2} -{ - Bu::File sf("testfile1", Bu::File::Read ); - char buf[256]; - int r = sf.read( buf, 256 ); - unitTest( r == 256 ); - // You have to read past the end to set the EOS flag. - unitTest( sf.isEos() == false ); - try + test readError2 { - if( sf.read( buf, 5 ) > 0 ) + Bu::File sf("testfile1", Bu::File::Read ); + char buf[256]; + int r = sf.read( buf, 256 ); + unitTest( r == 256 ); + // You have to read past the end to set the EOS flag. + unitTest( sf.isEos() == false ); + try { - unitFailed("Non-zero read result"); + if( sf.read( buf, 5 ) > 0 ) + { + unitFailed("Non-zero read result"); + } + else + { + sf.close(); + } } - else + catch( Bu::FileException &e ) { sf.close(); + return; } } - catch( Bu::FileException &e ) - { - sf.close(); - return; - } } diff --git a/src/unit/fstring.unit b/src/unit/fstring.unit index 8aaae93..00b6eed 100644 --- a/src/unit/fstring.unit +++ b/src/unit/fstring.unit @@ -10,333 +10,333 @@ #include -{=Init} - -{%compare1} +suite FString { - Bu::FString b("Bob"); - unitTest( !(b == "Bobo") ); - unitTest( b == "Bob" ); -} + test compare1 + { + Bu::FString b("Bob"); + unitTest( !(b == "Bobo") ); + unitTest( b == "Bob" ); + } -{%compare2} -{ - Bu::FString b("Bobo"); - unitTest( !(b == "Bob") ); - unitTest( b == "Bobo" ); -} + test compare2 + { + Bu::FString b("Bobo"); + unitTest( !(b == "Bob") ); + unitTest( b == "Bobo" ); + } -{%appendSingle} -{ - Bu::FString b; - for( char l = 'a'; l < 'g'; l++ ) - b += l; - unitTest( b == "abcdef" ); - unitTest( strcmp( b.getStr(), "abcdef" ) == 0 ); -} + test appendSingle + { + Bu::FString b; + for( char l = 'a'; l < 'g'; l++ ) + b += l; + unitTest( b == "abcdef" ); + unitTest( strcmp( b.getStr(), "abcdef" ) == 0 ); + } -{%shared1} -{ - Bu::FString a("Hey there"); - Bu::FString b( a ); - unitTest( a.getConstStr() == b.getConstStr() ); - b += " guy"; - unitTest( a.getConstStr() != b.getConstStr() ); - a = b; - unitTest( a.getConstStr() == b.getConstStr() ); -} + test shared1 + { + Bu::FString a("Hey there"); + Bu::FString b( a ); + unitTest( a.getConstStr() == b.getConstStr() ); + b += " guy"; + unitTest( a.getConstStr() != b.getConstStr() ); + a = b; + unitTest( a.getConstStr() == b.getConstStr() ); + } -{%insert} -{ - Bu::FString a("abcd"); - a.insert( 2, "-!-", 3 ); - unitTest( a == "ab-!-cd" ); - - a.insert( 0, "!!", 2 ); - unitTest( a == "!!ab-!-cd" ); - - a.insert( -10, "789", 3 ); - unitTest( a == "789!!ab-!-cd" ); - - a.insert( 12, "89", 2 ); - unitTest( a == "789!!ab-!-cd89" ); - - a.insert( 1203, "12", 2 ); - unitTest( a == "789!!ab-!-cd8912" ); -} + test insert + { + Bu::FString a("abcd"); + a.insert( 2, "-!-", 3 ); + unitTest( a == "ab-!-cd" ); + + a.insert( 0, "!!", 2 ); + unitTest( a == "!!ab-!-cd" ); + + a.insert( -10, "789", 3 ); + unitTest( a == "789!!ab-!-cd" ); + + a.insert( 12, "89", 2 ); + unitTest( a == "789!!ab-!-cd89" ); + + a.insert( 1203, "12", 2 ); + unitTest( a == "789!!ab-!-cd8912" ); + } -{%remove} -{ - Bu::FString a("abHEYcd"); - a.remove( 2, 3 ); - unitTest( a == "abcd" ); - a.remove( 2, 5 ); - unitTest( a == "ab" ); - a += "cdefghijklmnop"; - a.remove( 5, 1 ); - unitTest( a == "abcdeghijklmnop" ); -} + test remove + { + Bu::FString a("abHEYcd"); + a.remove( 2, 3 ); + unitTest( a == "abcd" ); + a.remove( 2, 5 ); + unitTest( a == "ab" ); + a += "cdefghijklmnop"; + a.remove( 5, 1 ); + unitTest( a == "abcdeghijklmnop" ); + } -{%add1} -{ - Bu::FString a("hi there"); - Bu::FString b(", yeah!"); - Bu::FString c = a + b; + test add1 + { + Bu::FString a("hi there"); + Bu::FString b(", yeah!"); + Bu::FString c = a + b; - unitTest( c == "hi there, yeah!" ); -} + unitTest( c == "hi there, yeah!" ); + } -{%add2} -{ - Bu::FString a("hi there"); - Bu::FString c = a + ", yeah!"; + test add2 + { + Bu::FString a("hi there"); + Bu::FString c = a + ", yeah!"; - unitTest( c == "hi there, yeah!" ); -} + unitTest( c == "hi there, yeah!" ); + } -{%add3} -{ - Bu::FString a("hi there"); - Bu::FString b(", yeah!"); - Bu::FString c = a + ", Mr. Man" + b; + test add3 + { + Bu::FString a("hi there"); + Bu::FString b(", yeah!"); + Bu::FString c = a + ", Mr. Man" + b; - unitTest( c == "hi there, Mr. Man, yeah!" ); -} + unitTest( c == "hi there, Mr. Man, yeah!" ); + } -{%add4} -{ - Bu::FString b(", yeah!"); - Bu::FString c = "hi there" + b; + test add4 + { + Bu::FString b(", yeah!"); + Bu::FString c = "hi there" + b; - unitTest( c == "hi there, yeah!" ); -} + unitTest( c == "hi there, yeah!" ); + } -{%add5} -{ - Bu::FString b; - Bu::FString c = "sup?"; - b += "hey, " + c; - - unitTest( b == "hey, sup?" ); -} + test add5 + { + Bu::FString b; + Bu::FString c = "sup?"; + b += "hey, " + c; + + unitTest( b == "hey, sup?" ); + } -{%add6} -{ - Bu::FString a("Hello"); - char b[256] = {"Dude"}; - Bu::FString c = a + "/" + b; + test add6 + { + Bu::FString a("Hello"); + char b[256] = {"Dude"}; + Bu::FString c = a + "/" + b; - unitTest( c == "Hello/Dude" ); -} + unitTest( c == "Hello/Dude" ); + } -{%add7} -{ - const Bu::FString a("hello "); - Bu::FString b(" how "); - unitTest( a == "hello " ); - unitTest( a + "dude" == "hello dude" ); - unitTest( a + "dude" + b + "are you?" == "hello dude how are you?" ); -} + test add7 + { + const Bu::FString a("hello "); + Bu::FString b(" how "); + unitTest( a == "hello " ); + unitTest( a + "dude" == "hello dude" ); + unitTest( a + "dude" + b + "are you?" == "hello dude how are you?" ); + } -{%subStr1} -{ - Bu::FString a("abcdefghijklmnop"); - Bu::FString::iterator i = a.find('f'); - unitTest( a.getSubStr( i, Bu::FString::iterator() ) == "fghijklmnop" ); - Bu::FString::iterator j = i.find('l'); - unitTest( a.getSubStr( i, j ) == "fghijk" ); -} + test subStr1 + { + Bu::FString a("abcdefghijklmnop"); + Bu::FString::iterator i = a.find('f'); + unitTest( a.getSubStr( i, Bu::FString::iterator() ) == "fghijklmnop" ); + Bu::FString::iterator j = i.find('l'); + unitTest( a.getSubStr( i, j ) == "fghijk" ); + } -{%compareSub1} -{ - Bu::FString a("just a string."); - unitTest( a.compareSub("a ", 5, 2) == true ); - unitTest( a.compareSub("string.aoeu", 7, 11 ) == false ); - unitTest( a.compareSub("string.aoeu", 7, 3 ) == true ); -} + test compareSub1 + { + Bu::FString a("just a string."); + unitTest( a.compareSub("a ", 5, 2) == true ); + unitTest( a.compareSub("string.aoeu", 7, 11 ) == false ); + unitTest( a.compareSub("string.aoeu", 7, 3 ) == true ); + } -{%compareSub2} -{ - Bu::FString a("just a string."); - unitTest( a.compareSub(Bu::FString("a "), 5, 2) == true ); - unitTest( a.compareSub(Bu::FString("string.aoeu"), 7, 11 ) == false ); - unitTest( a.compareSub(Bu::FString("string.aoeu"), 7, 3 ) == true ); -} + test compareSub2 + { + Bu::FString a("just a string."); + unitTest( a.compareSub(Bu::FString("a "), 5, 2) == true ); + unitTest( a.compareSub(Bu::FString("string.aoeu"), 7, 11 ) == false ); + unitTest( a.compareSub(Bu::FString("string.aoeu"), 7, 3 ) == true ); + } -{%iterator1} -{ - Bu::FString a("This is a test."); - Bu::FString b; - for( Bu::FString::iterator i = a.begin(); i; i++ ) + test iterator1 { - b += *i; + Bu::FString a("This is a test."); + Bu::FString b; + for( Bu::FString::iterator i = a.begin(); i; i++ ) + { + b += *i; + } + unitTest( a == b ); } - unitTest( a == b ); -} -{%iterator2} -{ - Bu::FString a("This is a test."); - Bu::FString b("--This is a test."); - Bu::FString::iterator ai = a.begin(); - Bu::FString::iterator bi = b.begin(); - unitTest( ai.compare( bi ) == false ); - unitTest( bi.compare( ai ) == false ); - bi++; bi++; - unitTest( ai.compare( bi ) == true ); - unitTest( bi.compare( ai ) == true ); -} + test iterator2 + { + Bu::FString a("This is a test."); + Bu::FString b("--This is a test."); + Bu::FString::iterator ai = a.begin(); + Bu::FString::iterator bi = b.begin(); + unitTest( ai.compare( bi ) == false ); + unitTest( bi.compare( ai ) == false ); + bi++; bi++; + unitTest( ai.compare( bi ) == true ); + unitTest( bi.compare( ai ) == true ); + } -{%iterator3} -{ - Bu::FString a("1234honour"); - Bu::FString b("--1234ueje"); - Bu::FString::iterator ai = a.begin(); - Bu::FString::iterator bi = b.begin(); - unitTest( ai.compare( bi, 4 ) == false ); - unitTest( bi.compare( ai, 4 ) == false ); - bi++; bi++; - unitTest( ai.compare( bi, 4 ) == true ); - unitTest( bi.compare( ai, 4 ) == true ); - unitTest( ai.compare( bi, 5 ) == false ); - unitTest( bi.compare( ai, 5 ) == false ); + test iterator3 + { + Bu::FString a("1234honour"); + Bu::FString b("--1234ueje"); + Bu::FString::iterator ai = a.begin(); + Bu::FString::iterator bi = b.begin(); + unitTest( ai.compare( bi, 4 ) == false ); + unitTest( bi.compare( ai, 4 ) == false ); + bi++; bi++; + unitTest( ai.compare( bi, 4 ) == true ); + unitTest( bi.compare( ai, 4 ) == true ); + unitTest( ai.compare( bi, 5 ) == false ); + unitTest( bi.compare( ai, 5 ) == false ); -} + } -{%iterator4} -{ - Bu::FString a("1234aoeu"); - Bu::FString::iterator ai = a.begin(); - unitTest( ai.compare("1234") == false ); - unitTest( ai.compare("1234aoeu") == true ); - unitTest( ai.compare("1234aoeuee") == false ); -} + test iterator4 + { + Bu::FString a("1234aoeu"); + Bu::FString::iterator ai = a.begin(); + unitTest( ai.compare("1234") == false ); + unitTest( ai.compare("1234aoeu") == true ); + unitTest( ai.compare("1234aoeuee") == false ); + } -{%iterator5} -{ - Bu::FString a("1234aoeu"); - Bu::FString::iterator ai = a.begin(); - unitTest( ai.compare("1234", 4) == true ); - unitTest( ai.compare("1234aoeu", 8) == true ); - unitTest( ai.compare("1234aoeuee", 10) == false ); -} + test iterator5 + { + Bu::FString a("1234aoeu"); + Bu::FString::iterator ai = a.begin(); + unitTest( ai.compare("1234", 4) == true ); + unitTest( ai.compare("1234aoeu", 8) == true ); + unitTest( ai.compare("1234aoeuee", 10) == false ); + } -{%iterator6} -{ - Bu::FString a("just ->this part"); - Bu::FString b; - Bu::FString::iterator s = a.begin(); - for(; s; s++ ) + test iterator6 { - if( *s == '>' ) + Bu::FString a("just ->this part"); + Bu::FString b; + Bu::FString::iterator s = a.begin(); + for(; s; s++ ) { - s++; - b.set( s ); - break; + if( *s == '>' ) + { + s++; + b.set( s ); + break; + } } - } - unitTest( b == "this part" ); + unitTest( b == "this part" ); - b.append( s ); + b.append( s ); - Bu::FString c; - c.set( b.begin() ); + Bu::FString c; + c.set( b.begin() ); - // This is here because the comparison operator used to cause flattening. - unitTest( b == "this partthis part" ); - unitTest( c == b ); -} + // This is here because the comparison operator used to cause flattening. + unitTest( b == "this partthis part" ); + unitTest( c == b ); + } -{%iterator7} -{ - Bu::FString a("just [this] part"); - Bu::FString b; - Bu::FString::iterator s = a.begin(); - for(; s; s++ ) + test iterator7 { - if( *s == '[' ) + Bu::FString a("just [this] part"); + Bu::FString b; + Bu::FString::iterator s = a.begin(); + for(; s; s++ ) { - s++; - break; + if( *s == '[' ) + { + s++; + break; + } } - } - Bu::FString::iterator e = s; - for(; e; e++ ) - { - if( *e == ']' ) + Bu::FString::iterator e = s; + for(; e; e++ ) { - b.set( s, e ); - break; + if( *e == ']' ) + { + b.set( s, e ); + break; + } } - } - unitTest( b == "this" ); + unitTest( b == "this" ); - b.append( s, e ); + b.append( s, e ); - for( Bu::FString::iterator i = b.begin(); i;) - { - Bu::FString::iterator k = i; - k++; - if( !k ) + for( Bu::FString::iterator i = b.begin(); i;) { - b.append( b.begin(), i ); - break; + Bu::FString::iterator k = i; + k++; + if( !k ) + { + b.append( b.begin(), i ); + break; + } + i = k; } - i = k; - } - Bu::FString l; - l.set( b.begin() ); - unitTest( l == "thisthisthisthi" ); - for( Bu::FString::iterator i = b.begin(); i;) - { - Bu::FString::iterator k = i; - k++; - if( !k ) + Bu::FString l; + l.set( b.begin() ); + unitTest( l == "thisthisthisthi" ); + for( Bu::FString::iterator i = b.begin(); i;) { - b.append( b.begin(), i ); - break; + Bu::FString::iterator k = i; + k++; + if( !k ) + { + b.append( b.begin(), i ); + break; + } + i = k; } - i = k; + l.set( b.begin() ); + unitTest( l == "thisthisthisthithisthisthisth" ); } - l.set( b.begin() ); - unitTest( l == "thisthisthisthithisthisthisth" ); -} -{%isSet1} -{ - Bu::FString bob; + test isSet1 + { + Bu::FString bob; - unitTest( bob.isSet() == false ); - bob = "something"; - unitTest( bob.isSet() == true ); - bob = ""; - unitTest( bob.isSet() == false ); -} + unitTest( bob.isSet() == false ); + bob = "something"; + unitTest( bob.isSet() == true ); + bob = ""; + unitTest( bob.isSet() == false ); + } -{%swap1} -{ - Bu::FString a, b; - a = "Goodbye"; - b = "Hello"; - Bu::swap( a, b ); - unitTest( a == "Hello" ); - unitTest( b == "Goodbye" ); -} + test swap1 + { + Bu::FString a, b; + a = "Goodbye"; + b = "Hello"; + Bu::swap( a, b ); + unitTest( a == "Hello" ); + unitTest( b == "Goodbye" ); + } -{%swap2} -{ - Bu::FString a, b; - a = "Goodbye"; - b = "Hello"; - std::swap( a, b ); - unitTest( a == "Hello" ); - unitTest( b == "Goodbye" ); -} + test swap2 + { + Bu::FString a, b; + a = "Goodbye"; + b = "Hello"; + std::swap( a, b ); + unitTest( a == "Hello" ); + unitTest( b == "Goodbye" ); + } -{%replace1} -{ - Bu::FString a; - a = "This is a test."; - unitTest( a.replace("i", "ooo") == "Thooos ooos a test." ); + test replace1 + { + Bu::FString a; + a = "This is a test."; + unitTest( a.replace("i", "ooo") == "Thooos ooos a test." ); + } } - diff --git a/src/unit/hash.unit b/src/unit/hash.unit index c0a10e3..e3d7e42 100644 --- a/src/unit/hash.unit +++ b/src/unit/hash.unit @@ -15,72 +15,73 @@ typedef Bu::Hash StrIntHash; typedef Bu::Hash StrStrHash; typedef Bu::Hash IntStrHash; -{=Init} - -{%probe1} +suite Hash { - StrIntHash h; - char buf[20]; - for(int i=1;i<10000;i++) + test probe1 { - sprintf(buf,"%d",i); - Bu::FString sTmp(buf); - h[sTmp] = i; - unitTest( h.has(sTmp) ); + StrIntHash h; + char buf[20]; + for(int i=1;i<10000;i++) + { + sprintf(buf,"%d",i); + Bu::FString sTmp(buf); + h[sTmp] = i; + unitTest( h.has(sTmp) ); + } } -} - -{%insert1} -{ - StrIntHash h; - h["Hi"] = 42; - unitTest( h["Hi"] == 42 ); -} -{%insert2} -{ - StrStrHash h; - h["Hi"] = "Yo"; - h["Bye"] = "Later"; - unitTest( h["Hi"].getValue() == "Yo" ); + test insert1 + { + StrIntHash h; + h["Hi"] = 42; + unitTest( h["Hi"] == 42 ); + } - StrStrHash h2(h); - unitTest( h2["Hi"].getValue() == "Yo" ); - unitTest( h2["Bye"].getValue() == "Later" ); + test insert2 + { + StrStrHash h; + h["Hi"] = "Yo"; + h["Bye"] = "Later"; + unitTest( h["Hi"].getValue() == "Yo" ); - StrStrHash h3; - h3 = h; - unitTest( h3["Hi"].getValue() == "Yo" ); - unitTest( h3["Bye"].getValue() == "Later" ); -} + StrStrHash h2(h); + unitTest( h2["Hi"].getValue() == "Yo" ); + unitTest( h2["Bye"].getValue() == "Later" ); -{%insert3} -{ - IntStrHash h; + StrStrHash h3; + h3 = h; + unitTest( h3["Hi"].getValue() == "Yo" ); + unitTest( h3["Bye"].getValue() == "Later" ); + } - for( unsigned int i=1; i<50; i++ ) + test insert3 { - h[i] = "testing"; - unitTest( h.getSize() == i ); - } -} + IntStrHash h; -{%erase1} -{ - StrIntHash h; - h.insert("Number 1", 1 ); - h.insert("Number 2", 2 ); - h.insert("Number 3", 3 ); - h.erase("Number 2"); - h.get("Number 3"); - try { - h.get("Number 2"); - unitFailed("h.get(\"Number 2\") should have thrown an exception."); - } catch( Bu::HashException &e ) { } + for( unsigned int i=1; i<50; i++ ) + { + h[i] = "testing"; + unitTest( h.getSize() == i ); + } + } -/* printf("\n"); - for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ ) + test erase1 { - printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); - } */ + StrIntHash h; + h.insert("Number 1", 1 ); + h.insert("Number 2", 2 ); + h.insert("Number 3", 3 ); + h.erase("Number 2"); + h.get("Number 3"); + try { + h.get("Number 2"); + unitFailed("h.get(\"Number 2\") should have thrown an exception."); + } catch( Bu::HashException &e ) { } + + /* printf("\n"); + for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ ) + { + printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); + } */ + } } diff --git a/src/unit/list.unit b/src/unit/list.unit index 0dd9f40..66e45b2 100644 --- a/src/unit/list.unit +++ b/src/unit/list.unit @@ -11,138 +11,138 @@ typedef Bu::List IntList; -{=Init} - -{%append} +suite List { - IntList lst; - for( int j = 0; j < 50; j++ ) - { - lst.append( j ); - } - int j = 0; - for( IntList::iterator i = lst.begin(); i; i++, j++ ) + test append { - unitTest( *i == j ); + IntList lst; + for( int j = 0; j < 50; j++ ) + { + lst.append( j ); + } + int j = 0; + for( IntList::iterator i = lst.begin(); i; i++, j++ ) + { + unitTest( *i == j ); + } } -} -{%prepend} -{ - IntList lst; - for( int j = 0; j < 50; j++ ) + test prepend { - lst.prepend( j ); + IntList lst; + for( int j = 0; j < 50; j++ ) + { + lst.prepend( j ); + } + int j = 49; + for( IntList::iterator i = lst.begin(); i; i++, j-- ) + { + unitTest( *i == j ); + } } - int j = 49; - for( IntList::iterator i = lst.begin(); i; i++, j-- ) - { - unitTest( *i == j ); - } -} -{%copy} -{ - IntList lst; - int j; - for( j = 0; j < 50; j++ ) + test copy { - lst.append( j ); + IntList lst; + int j; + for( j = 0; j < 50; j++ ) + { + lst.append( j ); + } + IntList lst2 = lst; + + j = 0; + for( IntList::iterator i = lst2.begin(); i; i++, j++ ) + { + unitTest( *i == j ); + } + lst2.clear(); + lst2 = lst; + + j = 0; + for( IntList::iterator i = lst2.begin(); i; i++, j++ ) + { + unitTest( *i == j ); + } } - IntList lst2 = lst; - j = 0; - for( IntList::iterator i = lst2.begin(); i; i++, j++ ) + test sort1 { - unitTest( *i == j ); - } - lst2.clear(); - lst2 = lst; + IntList lst; - j = 0; - for( IntList::iterator i = lst2.begin(); i; i++, j++ ) - { - unitTest( *i == j ); - } -} - -{%sort1} -{ - IntList lst; + lst.insertSorted( 5 ); + lst.insertSorted( 1 ); + lst.insertSorted( 10 ); + lst.insertSorted( 3 ); - lst.insertSorted( 5 ); - lst.insertSorted( 1 ); - lst.insertSorted( 10 ); - lst.insertSorted( 3 ); - - unitTest( lst == IntList(1).append(3).append(5).append(10) ); -} + unitTest( lst == IntList(1).append(3).append(5).append(10) ); + } -{%sort2} -{ - IntList lst; + test sort2 + { + IntList lst; - lst.insertSorted >( 5 ); - lst.insertSorted >( 1 ); - lst.insertSorted >( 10 ); - lst.insertSorted >( 3 ); + lst.insertSorted >( 5 ); + lst.insertSorted >( 1 ); + lst.insertSorted >( 10 ); + lst.insertSorted >( 3 ); - unitTest( lst == IntList(10).append(5).append(3).append(1) ); -} + unitTest( lst == IntList(10).append(5).append(3).append(1) ); + } -{%sort3} -{ - IntList lst; - Bu::__basicGTCmp cmp; + test sort3 + { + IntList lst; + Bu::__basicGTCmp cmp; - lst.insertSorted( cmp, 5 ); - lst.insertSorted( cmp, 1 ); - lst.insertSorted( cmp, 10 ); - lst.insertSorted( cmp, 3 ); + lst.insertSorted( cmp, 5 ); + lst.insertSorted( cmp, 1 ); + lst.insertSorted( cmp, 10 ); + lst.insertSorted( cmp, 3 ); - unitTest( lst == IntList(10).append(5).append(3).append(1) ); -} + unitTest( lst == IntList(10).append(5).append(3).append(1) ); + } -{%sort4} -{ - IntList lst; + test sort4 + { + IntList lst; - lst.append( 5 ); - lst.append( 1 ); - lst.append( 10 ); - lst.append( 3 ); + lst.append( 5 ); + lst.append( 1 ); + lst.append( 10 ); + lst.append( 3 ); - lst.sort(); + lst.sort(); - unitTest( lst == IntList(1).append(3).append(5).append(10) ); -} + unitTest( lst == IntList(1).append(3).append(5).append(10) ); + } -{%sort5} -{ - IntList lst; + test sort5 + { + IntList lst; - lst.append( 5 ); - lst.append( 1 ); - lst.append( 10 ); - lst.append( 3 ); + lst.append( 5 ); + lst.append( 1 ); + lst.append( 10 ); + lst.append( 3 ); - lst.sort >(); + lst.sort >(); - unitTest( lst == IntList(10).append(5).append(3).append(1) ); -} + unitTest( lst == IntList(10).append(5).append(3).append(1) ); + } -{%sort6} -{ - IntList lst; + test sort6 + { + IntList lst; - lst.append( 5 ); - lst.append( 1 ); - lst.append( 10 ); - lst.append( 3 ); + lst.append( 5 ); + lst.append( 1 ); + lst.append( 10 ); + lst.append( 3 ); - Bu::__basicGTCmp x; - lst.sort( x ); + Bu::__basicGTCmp x; + lst.sort( x ); - unitTest( lst == IntList(10).append(5).append(3).append(1) ); + unitTest( lst == IntList(10).append(5).append(3).append(1) ); + } } - diff --git a/src/unit/membuf.unit b/src/unit/membuf.unit index 883b7f8..1da3b90 100644 --- a/src/unit/membuf.unit +++ b/src/unit/membuf.unit @@ -8,38 +8,39 @@ #include "bu/membuf.h" -{=Init} - -{%testWriteRead01} +suite MemBuf { - Bu::MemBuf mb; - unitTest( mb.write("ab", 2 ) == 2 ); - unitTest( mb.write("cde", 3 ) == 3 ); - unitTest( mb.write("FG", 2 ) == 2 ); + test testWriteRead01 + { + Bu::MemBuf mb; + unitTest( mb.write("ab", 2 ) == 2 ); + unitTest( mb.write("cde", 3 ) == 3 ); + unitTest( mb.write("FG", 2 ) == 2 ); - mb.setPos( 0 ); + mb.setPos( 0 ); - char buf[8]; - buf[7] = '\0'; - unitTest( mb.read( buf, 7 ) == 7 ); - unitTest( !strncmp( buf, "abcdeFG", 7 ) ); - unitTest( mb.read( buf, 7 ) == 0 ); - mb.seek( -3 ); - unitTest( mb.read( buf, 7 ) == 3 ); - unitTest( !strncmp( buf, "eFG", 3 ) ); -} + char buf[8]; + buf[7] = '\0'; + unitTest( mb.read( buf, 7 ) == 7 ); + unitTest( !strncmp( buf, "abcdeFG", 7 ) ); + unitTest( mb.read( buf, 7 ) == 0 ); + mb.seek( -3 ); + unitTest( mb.read( buf, 7 ) == 3 ); + unitTest( !strncmp( buf, "eFG", 3 ) ); + } -{%testOverwrite1} -{ - Bu::MemBuf mb; - unitTest( mb.write("0123456789") == 10 ); - mb.setPos( 4 ); - unitTest( mb.write("-5-") == 3 ); - mb.setPos( 9 ); - mb.write("Hey!!!"); - unitTest( mb.tell() == 15 ); - char buf[50]; - mb.setPos( 0 ); - buf[mb.read( buf, 50 )] = '\0'; - unitTest( !strcmp( buf, "0123-5-78Hey!!!" ) ); + test testOverwrite1 + { + Bu::MemBuf mb; + unitTest( mb.write("0123456789") == 10 ); + mb.setPos( 4 ); + unitTest( mb.write("-5-") == 3 ); + mb.setPos( 9 ); + mb.write("Hey!!!"); + unitTest( mb.tell() == 15 ); + char buf[50]; + mb.setPos( 0 ); + buf[mb.read( buf, 50 )] = '\0'; + unitTest( !strcmp( buf, "0123-5-78Hey!!!" ) ); + } } diff --git a/src/unit/queuebuf.unit b/src/unit/queuebuf.unit index 9ae7d36..29ba858 100644 --- a/src/unit/queuebuf.unit +++ b/src/unit/queuebuf.unit @@ -14,91 +14,91 @@ #define RNDCHR ((char)(((double)random()/(double)RAND_MAX)*256.0)) -{=Init} - -{%testBasic01} +suite QueueBuf { - Bu::QueueBuf qb; - unitTest( qb.write("ab", 2 ) == 2 ); - unitTest( qb.write("cde", 3 ) == 3 ); - unitTest( qb.write("FG", 2 ) == 2 ); + test testBasic01 + { + Bu::QueueBuf qb; + unitTest( qb.write("ab", 2 ) == 2 ); + unitTest( qb.write("cde", 3 ) == 3 ); + unitTest( qb.write("FG", 2 ) == 2 ); - char buf[8]; - buf[7] = '\0'; - unitTest( qb.read( buf, 7 ) == 7 ); - unitTest( !strncmp( buf, "abcdeFG", 7 ) ); - unitTest( qb.read( buf, 7 ) == 0 ); -} + char buf[8]; + buf[7] = '\0'; + unitTest( qb.read( buf, 7 ) == 7 ); + unitTest( !strncmp( buf, "abcdeFG", 7 ) ); + unitTest( qb.read( buf, 7 ) == 0 ); + } -void QBUF_RANDSTR( Bu::FString &fill, unsigned int iSize ) -{ - char c; - for( unsigned int i=0; i #include -{=Init} - -{%read1} +suite Taf { + test read1 + { #define FN_TMP ("/tmp/tmpXXXXXXXX") - Bu::FString sFnTmp(FN_TMP); - Bu::File fOut = Bu::File::tempFile( sFnTmp ); - const char *data = -"{test: name=\"Bob\"}" -; - fOut.write(data,strlen(data)); - fOut.close(); + Bu::FString sFnTmp(FN_TMP); + Bu::File fOut = Bu::File::tempFile( sFnTmp ); + const char *data = + "{test: name=\"Bob\"}" + ; + fOut.write(data,strlen(data)); + fOut.close(); - Bu::File fIn(sFnTmp.getStr(), Bu::File::Read ); - Bu::TafReader tr(fIn); - - Bu::TafGroup *tn = tr.readGroup(); - unitTest( !strcmp("Bob", tn->getProperty("name").getStr()) ); - delete tn; + Bu::File fIn(sFnTmp.getStr(), Bu::File::Read ); + Bu::TafReader tr(fIn); + + Bu::TafGroup *tn = tr.readGroup(); + unitTest( !strcmp("Bob", tn->getProperty("name").getStr()) ); + delete tn; - unlink(sFnTmp.getStr()); + unlink(sFnTmp.getStr()); #undef FN_TMP -} + } -{%encode1} -{ - Bu::MemBuf mb; - Bu::TafWriter tw( mb ); - - Bu::TafGroup g("Test data"); - Bu::FString sData( 256 ); - for( int j = 0; j < 256; j++ ) - sData[j] = (unsigned char)j; - g.addChild( new Bu::TafProperty("Encoded", sData) ); - tw.writeGroup( &g ); + test encode1 + { + Bu::MemBuf mb; + Bu::TafWriter tw( mb ); + + Bu::TafGroup g("Test data"); + Bu::FString sData( 256 ); + for( int j = 0; j < 256; j++ ) + sData[j] = (unsigned char)j; + g.addChild( new Bu::TafProperty("Encoded", sData) ); + tw.writeGroup( &g ); - static const char *cmpdata = "{\"Test data\":\n \"Encoded\"=\"" - "\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07" - "\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F" - "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17" - "\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F" - " !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCD" - "EFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghi" - "jklmnopqrstuvwxyz{|}~\\x7F" - "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87" - "\\x88\\x89\\x8A\\x8B\\x8C\\x8D\\x8E\\x8F" - "\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97" - "\\x98\\x99\\x9A\\x9B\\x9C\\x9D\\x9E\\x9F" - "\\xA0\\xA1\\xA2\\xA3\\xA4\\xA5\\xA6\\xA7" - "\\xA8\\xA9\\xAA\\xAB\\xAC\\xAD\\xAE\\xAF" - "\\xB0\\xB1\\xB2\\xB3\\xB4\\xB5\\xB6\\xB7" - "\\xB8\\xB9\\xBA\\xBB\\xBC\\xBD\\xBE\\xBF" - "\\xC0\\xC1\\xC2\\xC3\\xC4\\xC5\\xC6\\xC7" - "\\xC8\\xC9\\xCA\\xCB\\xCC\\xCD\\xCE\\xCF" - "\\xD0\\xD1\\xD2\\xD3\\xD4\\xD5\\xD6\\xD7" - "\\xD8\\xD9\\xDA\\xDB\\xDC\\xDD\\xDE\\xDF" - "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7" - "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF" - "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\xF6\\xF7" - "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF\"\n}\n"; - unitTest( mb.getString() == cmpdata ); - mb.setPos( 0 ); - Bu::TafReader tr( mb ); - Bu::TafGroup *rg = tr.readGroup(); - unitTest( rg->getProperty("Encoded") == sData ); - delete rg; -} + static const char *cmpdata = "{\"Test data\":\n \"Encoded\"=\"" + "\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07" + "\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F" + "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17" + "\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F" + " !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCD" + "EFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghi" + "jklmnopqrstuvwxyz{|}~\\x7F" + "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87" + "\\x88\\x89\\x8A\\x8B\\x8C\\x8D\\x8E\\x8F" + "\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97" + "\\x98\\x99\\x9A\\x9B\\x9C\\x9D\\x9E\\x9F" + "\\xA0\\xA1\\xA2\\xA3\\xA4\\xA5\\xA6\\xA7" + "\\xA8\\xA9\\xAA\\xAB\\xAC\\xAD\\xAE\\xAF" + "\\xB0\\xB1\\xB2\\xB3\\xB4\\xB5\\xB6\\xB7" + "\\xB8\\xB9\\xBA\\xBB\\xBC\\xBD\\xBE\\xBF" + "\\xC0\\xC1\\xC2\\xC3\\xC4\\xC5\\xC6\\xC7" + "\\xC8\\xC9\\xCA\\xCB\\xCC\\xCD\\xCE\\xCF" + "\\xD0\\xD1\\xD2\\xD3\\xD4\\xD5\\xD6\\xD7" + "\\xD8\\xD9\\xDA\\xDB\\xDC\\xDD\\xDE\\xDF" + "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7" + "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF" + "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\xF6\\xF7" + "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF\"\n}\n"; + unitTest( mb.getString() == cmpdata ); + mb.setPos( 0 ); + Bu::TafReader tr( mb ); + Bu::TafGroup *rg = tr.readGroup(); + unitTest( rg->getProperty("Encoded") == sData ); + delete rg; + } -{%emptyStr1} -{ - Bu::MemBuf mb; - Bu::TafWriter tw( mb ); + test emptyStr1 + { + Bu::MemBuf mb; + Bu::TafWriter tw( mb ); - Bu::TafGroup g("Test Group"); - Bu::FString sVal; - g.addChild( new Bu::TafProperty("Lame", sVal) ); - tw.writeGroup( &g ); + Bu::TafGroup g("Test Group"); + Bu::FString sVal; + g.addChild( new Bu::TafProperty("Lame", sVal) ); + tw.writeGroup( &g ); - unitTest( - mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" ); -} + unitTest( + mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" ); + } -{%incomplete1} -{ - try + test incomplete1 { - Bu::MemBuf mb("{Lame: \"Hello=\""); - Bu::TafReader tr( mb ); - delete tr.readGroup(); - unitFailed("Should have thrown an exception, didn't."); + try + { + Bu::MemBuf mb("{Lame: \"Hello=\""); + Bu::TafReader tr( mb ); + delete tr.readGroup(); + unitFailed("Should have thrown an exception, didn't."); + } + catch( Bu::TafException &e ) + { + // Woot + } } - catch( Bu::TafException &e ) + + test bypath1 { - // Woot + Bu::MemBuf mb("{outer: \"Hello=\" {inner: {final: test=hi} } }"); + Bu::TafReader tr( mb ); + const Bu::TafGroup *g = tr.readGroup(); + unitTest( g->getChildByPath("inner/final")->getProperty("test") == "hi" ); + unitTest( g->getByPath("inner/final/test") == "hi" ); } } - -{%bypath1} -{ - Bu::MemBuf mb("{outer: \"Hello=\" {inner: {final: test=hi} } }"); - Bu::TafReader tr( mb ); - const Bu::TafGroup *g = tr.readGroup(); - unitTest( g->getChildByPath("inner/final")->getProperty("test") == "hi" ); - unitTest( g->getByPath("inner/final/test") == "hi" ); -} - diff --git a/src/unit/xml.unit b/src/unit/xml.unit index 1398237..67216f0 100644 --- a/src/unit/xml.unit +++ b/src/unit/xml.unit @@ -10,11 +10,12 @@ #include "bu/xmlreader.h" #include "bu/membuf.h" -{=Init} - -{%declaration} +suite Xml { - Bu::FString sXml(" "); - Bu::MemBuf buf( sXml ); - Bu::XmlReader xr( buf ); + test declaration + { + Bu::FString sXml(" "); + Bu::MemBuf buf( sXml ); + Bu::XmlReader xr( buf ); + } } -- cgit v1.2.3