// 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 "bu/membuf.h" #include "bu/array.h" #include "bu/archive.h" using namespace Bu; suite Archive { test primitives { 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(); } } test containers1 { MemBuf mb; { Archive ar( mb, Archive::save ); String 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 ); String 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(); } } test containers2 { MemBuf mb; { Archive ar( mb, Archive::save ); String 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 ); String 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(); } } test containers3 { 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(); } } }