From ec05778d5718a7912e506764d443a78d6a6179e3 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Mon, 5 Nov 2012 22:41:51 +0000 Subject: Converted tabs to spaces with tabconv. --- src/unit/archive.unit | 352 +++++++-------- src/unit/array.unit | 174 +++---- src/unit/base64.unit | 24 +- src/unit/blowfish.unit | 44 +- src/unit/buffer.unit | 22 +- src/unit/file.unit | 160 +++---- src/unit/hash.unit | 378 ++++++++-------- src/unit/list.unit | 264 +++++------ src/unit/md5.unit | 124 ++--- src/unit/membuf.unit | 60 +-- src/unit/myriad.unit | 678 ++++++++++++++-------------- src/unit/queuebuf.unit | 154 +++---- src/unit/sha1.unit | 112 ++--- src/unit/string.unit | 1148 +++++++++++++++++++++++------------------------ src/unit/substream.unit | 72 +-- src/unit/taf.unit | 94 ++-- src/unit/variant.unit | 70 +-- src/unit/xml.unit | 12 +- 18 files changed, 1971 insertions(+), 1971 deletions(-) (limited to 'src/unit') diff --git a/src/unit/archive.unit b/src/unit/archive.unit index 359f380..d0427a5 100644 --- a/src/unit/archive.unit +++ b/src/unit/archive.unit @@ -14,183 +14,183 @@ 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 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 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 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(); - } - } + 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(); + } + } } diff --git a/src/unit/array.unit b/src/unit/array.unit index 6e985d8..ca85b4d 100644 --- a/src/unit/array.unit +++ b/src/unit/array.unit @@ -14,91 +14,91 @@ using Bu::sio; suite Array { - 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 ); - } - - 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 ); - } - - 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."); - } - - test copy - { - typedef Bu::Hash StrHash; - typedef Bu::Array StrHashArray; - - StrHash h1; - h1["Hi"] = "Yo"; - h1["Bye"] = "Later"; - - StrHash h2; - h2["Test"] = "Bloop"; - h2["Foo"] = "ooF"; - - StrHashArray a1; - a1.append( h1 ); - a1.append( h2 ); - - 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" ); - - 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" ); - } - - test insert - { - Bu::Array aInts; - aInts.insert( aInts.end(), 4 ); - aInts.insert( aInts.begin(), 1 ); - aInts.insert( aInts.end(), 5 ); - aInts.insert( aInts.begin()+1, 3 ); - aInts.insert( aInts.begin()+1, 2 ); - aInts.insert( aInts.begin(), 0 ); - - for( int j = 0; j < 6; j++ ) - { - unitTest( aInts[j] == j ); - } - } + 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 ); + } + + 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 ); + } + + 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."); + } + + test copy + { + typedef Bu::Hash StrHash; + typedef Bu::Array StrHashArray; + + StrHash h1; + h1["Hi"] = "Yo"; + h1["Bye"] = "Later"; + + StrHash h2; + h2["Test"] = "Bloop"; + h2["Foo"] = "ooF"; + + StrHashArray a1; + a1.append( h1 ); + a1.append( h2 ); + + 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" ); + + 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" ); + } + + test insert + { + Bu::Array aInts; + aInts.insert( aInts.end(), 4 ); + aInts.insert( aInts.begin(), 1 ); + aInts.insert( aInts.end(), 5 ); + aInts.insert( aInts.begin()+1, 3 ); + aInts.insert( aInts.begin()+1, 2 ); + aInts.insert( aInts.begin(), 0 ); + + for( int j = 0; j < 6; j++ ) + { + unitTest( aInts[j] == j ); + } + } } diff --git a/src/unit/base64.unit b/src/unit/base64.unit index 5266b48..bd5bc97 100644 --- a/src/unit/base64.unit +++ b/src/unit/base64.unit @@ -11,18 +11,18 @@ suite MemBuf { - test decode01 - { - unitTest( Bu::decodeStr("RnVu") == "Fun" ); - unitTest( Bu::decodeStr("V2hhdA==") == "What" ); - unitTest( Bu::decodeStr("SGVsbG8=") == "Hello" ); - } + test decode01 + { + unitTest( Bu::decodeStr("RnVu") == "Fun" ); + unitTest( Bu::decodeStr("V2hhdA==") == "What" ); + unitTest( Bu::decodeStr("SGVsbG8=") == "Hello" ); + } - test encode01 - { - unitTest( Bu::decodeStr("R n V u") == "Fun" ); - unitTest( Bu::decodeStr("V2\n\n\thh dA==") == "What" ); - unitTest( Bu::decodeStr("\n\n\t\t SGV\r\ns\tbG8\n=") == "Hello" ); - } + test encode01 + { + unitTest( Bu::decodeStr("R n V u") == "Fun" ); + unitTest( Bu::decodeStr("V2\n\n\thh dA==") == "What" ); + unitTest( Bu::decodeStr("\n\n\t\t SGV\r\ns\tbG8\n=") == "Hello" ); + } } diff --git a/src/unit/blowfish.unit b/src/unit/blowfish.unit index abab63d..1b4ca18 100644 --- a/src/unit/blowfish.unit +++ b/src/unit/blowfish.unit @@ -50,29 +50,29 @@ static const char *testdat[34][3] ={ suite Blowfish { - test standard - { - for( int j = 0; j < 34; j++ ) - { - Bu::MemBuf mb; - Bu::BlowfishEcb bf( mb ); - bf.setPassword( Bu::decodeStr( testdat[j][0] ) ); - bf.write( Bu::decodeStr( testdat[j][1] ) ); - unitTest( - mb.getString() == Bu::decodeStr( testdat[j][2] ) - ); + test standard + { + for( int j = 0; j < 34; j++ ) + { + Bu::MemBuf mb; + Bu::BlowfishEcb bf( mb ); + bf.setPassword( Bu::decodeStr( testdat[j][0] ) ); + bf.write( Bu::decodeStr( testdat[j][1] ) ); + unitTest( + mb.getString() == Bu::decodeStr( testdat[j][2] ) + ); - mb.setPos( 0 ); - Bu::BlowfishEcb bf2( mb ); - bf2.setPassword( Bu::decodeStr( testdat[j][0] ) ); - char buf[8]; - bf2.read( buf, 8 ); + mb.setPos( 0 ); + Bu::BlowfishEcb bf2( mb ); + bf2.setPassword( Bu::decodeStr( testdat[j][0] ) ); + char buf[8]; + bf2.read( buf, 8 ); - unitTest( - Bu::String(testdat[j][1]) == - Bu::encodeStr(Bu::String(buf,8),true) - ); - } - } + unitTest( + Bu::String(testdat[j][1]) == + Bu::encodeStr(Bu::String(buf,8),true) + ); + } + } } diff --git a/src/unit/buffer.unit b/src/unit/buffer.unit index 8bfdc3d..8613c5b 100644 --- a/src/unit/buffer.unit +++ b/src/unit/buffer.unit @@ -12,16 +12,16 @@ suite Buffer { - test emptyFile - { - Bu::String sTmp("empty-XXXXXX"); - Bu::File fEmpty = tempFile(sTmp); - Bu::Buffer buf( fEmpty ); + test emptyFile + { + Bu::String sTmp("empty-XXXXXX"); + Bu::File fEmpty = tempFile(sTmp); + Bu::Buffer buf( fEmpty ); - unitTest( buf.isEos() == false ); - Bu::String sLine = buf.readLine(); - unitTest( sLine == "" ); - unitTest( fEmpty.isEos() == true ); - unitTest( buf.isEos() == true ); - } + unitTest( buf.isEos() == false ); + Bu::String sLine = buf.readLine(); + unitTest( sLine == "" ); + unitTest( fEmpty.isEos() == true ); + unitTest( buf.isEos() == true ); + } } diff --git a/src/unit/file.unit b/src/unit/file.unit index 7140d03..c0358ac 100644 --- a/src/unit/file.unit +++ b/src/unit/file.unit @@ -14,87 +14,87 @@ suite File { - test writeFull - { - 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 ); - } + test writeFull + { + 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 ); + } - test readBlocks - { - Bu::File sf("testfile1", Bu::File::Read ); - unsigned char buf[50]; - size_t total = 0; - for(;;) - { - 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() == false ); - unitTest( sf.read( buf, 1 ) == 0 ); - unitTest( sf.isEos() == true ); - // EOS is only set when an attempt to read past the end of - // the stream is made, not when a short block is returned. - break; - } - } - sf.close(); - } + test readBlocks + { + Bu::File sf("testfile1", Bu::File::Read ); + unsigned char buf[50]; + size_t total = 0; + for(;;) + { + 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() == false ); + unitTest( sf.read( buf, 1 ) == 0 ); + unitTest( sf.isEos() == true ); + // EOS is only set when an attempt to read past the end of + // the stream is made, not when a short block is returned. + break; + } + } + sf.close(); + } - test readError1 - { - try - { - Bu::File sf("doesn'texist", Bu::File::Read ); - unitFailed("No exception thrown"); - } - catch( Bu::FileException &e ) - { - return; - } - } + test readError1 + { + try + { + Bu::File sf("doesn'texist", Bu::File::Read ); + unitFailed("No exception thrown"); + } + catch( Bu::FileException &e ) + { + return; + } + } - test 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 - { - if( sf.read( buf, 5 ) > 0 ) - { - unitFailed("Non-zero read result"); - } - else - { - sf.close(); - } - } - catch( Bu::FileException &e ) - { - sf.close(); - return; - } - } + test 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 + { + if( sf.read( buf, 5 ) > 0 ) + { + unitFailed("Non-zero read result"); + } + else + { + sf.close(); + } + } + catch( Bu::FileException &e ) + { + sf.close(); + return; + } + } } diff --git a/src/unit/hash.unit b/src/unit/hash.unit index 3abc6a5..e30c62b 100644 --- a/src/unit/hash.unit +++ b/src/unit/hash.unit @@ -19,193 +19,193 @@ typedef Bu::Hash IntStrHash; suite Hash { - test probe1 - { - StrIntHash h; - char buf[20]; - for(int i=1;i<10000;i++) - { - sprintf(buf,"%d",i); - Bu::String sTmp(buf); - h[sTmp] = i; - unitTest( h.has(sTmp) ); - } - } - - test insert1 - { - StrIntHash h; - h["Hi"] = 42; - unitTest( h["Hi"] == 42 ); - } - - test insert2 - { - StrStrHash h; - h["Hi"] = "Yo"; - h["Bye"] = "Later"; - unitTest( h["Hi"].getValue() == "Yo" ); - - StrStrHash h2(h); - unitTest( h2["Hi"].getValue() == "Yo" ); - unitTest( h2["Bye"].getValue() == "Later" ); - - StrStrHash h3; - h3 = h; - unitTest( h3["Hi"].getValue() == "Yo" ); - unitTest( h3["Bye"].getValue() == "Later" ); - } - - test insert3 - { - IntStrHash h; - - for( unsigned int i=1; i<50; i++ ) - { - h[i] = "testing"; - unitTest( h.getSize() == i ); - } - } - - test 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 ) { } - - /* printf("\n"); - for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ ) - { - printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); - } */ - } - - test copy - { - StrIntHash h; - h.insert("hello", 55 ); - h.insert("goodbye", -1812 ); - - StrIntHash h2 = h; - unitTest( h2.isCoreShared( h ) ); - - StrIntHash h3 = h.clone(); - unitTest( !h3.isCoreShared( h ) ); - } - - test reHashSpecial - { - IntStrHash hTest; - - setStepCount( 1000000 ); - for( int i=0; i<1000000; ++i ) - { - char buf[40]; snprintf(buf,40,"num%d",i); - incProgress(); - - if( ((double)random()/(double)RAND_MAX)<.01 ) - { - //printf("ERASE: %d (%s)\n",i%64,buf); - hTest.erase(i%64); - } - else - { - hTest[i%64]=buf; - } - - /*printf("(%d) size: %u fill: %u cap:%u\n", - i, - hTest.getSize(), - hTest.getFill(), - hTest.getCapacity() - );*/ - } - } - - test stress - { - srandom(time(NULL)); - - IntStrHash hTest; - IntStrHash hReUse; - setStepCount( 100000 ); - - for( int i=0; i<100000; ++i ) - { - char buf[40]; snprintf(buf,40,"num%d",i); - hTest[i] = buf; - incProgress(); - - - if( ((double)random()/(double)RAND_MAX)<.01 ) - { - Bu::List lKeys = hReUse.getKeys(); - Bu::List::const_iterator it = lKeys.begin(); - int iIdx = (int)(((double)random()/(double)RAND_MAX) - *lKeys.getSize()); - for( int l=0; it; ++it, ++l ) - { - if( l==iIdx ) - { - int iVal = *it; - hReUse.erase( *it ); - char buf[40]; snprintf(buf,40,"num%d",iVal); - hTest[i] = buf; - //printf("re-use: %s\n",buf); - } - } - } - - /*printf("(%s) size: %u fill: %u cap:%u\n", - buf, - hTest.getSize(), - hTest.getFill(), - hTest.getCapacity() - );*/ - - if( ((double)random()/(double)RAND_MAX)<.3 ) - { - Bu::List lKeys = hTest.getKeys(); - int iIdx = (int)(((double)random()/(double)RAND_MAX) - *lKeys.getSize()); - Bu::List::const_iterator it = lKeys.begin(); - for( int k=0; it; ++it, ++k ) - { - if( k == iIdx ) - { - hReUse.insert(*it,"yo"); - hTest.erase( *it ); - } - } - } - - if( hTest.getSize() > 100 ) - { - int iK = (int)(((double)random()/(double)RAND_MAX)*50)+10; - for( int j=0; j lKeys = hTest.getKeys(); - int iIdx = (int)(((double)random()/(double)RAND_MAX) - *lKeys.getSize()); - Bu::List::const_iterator it = lKeys.begin(); - for( int k=0; it; ++it, ++k ) - { - if( k == iIdx ) - { - hReUse.insert(*it,"yo"); - hTest.erase( *it ); - break; - } - } - } - } - } - } + test probe1 + { + StrIntHash h; + char buf[20]; + for(int i=1;i<10000;i++) + { + sprintf(buf,"%d",i); + Bu::String sTmp(buf); + h[sTmp] = i; + unitTest( h.has(sTmp) ); + } + } + + test insert1 + { + StrIntHash h; + h["Hi"] = 42; + unitTest( h["Hi"] == 42 ); + } + + test insert2 + { + StrStrHash h; + h["Hi"] = "Yo"; + h["Bye"] = "Later"; + unitTest( h["Hi"].getValue() == "Yo" ); + + StrStrHash h2(h); + unitTest( h2["Hi"].getValue() == "Yo" ); + unitTest( h2["Bye"].getValue() == "Later" ); + + StrStrHash h3; + h3 = h; + unitTest( h3["Hi"].getValue() == "Yo" ); + unitTest( h3["Bye"].getValue() == "Later" ); + } + + test insert3 + { + IntStrHash h; + + for( unsigned int i=1; i<50; i++ ) + { + h[i] = "testing"; + unitTest( h.getSize() == i ); + } + } + + test 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 ) { } + + /* printf("\n"); + for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ ) + { + printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); + } */ + } + + test copy + { + StrIntHash h; + h.insert("hello", 55 ); + h.insert("goodbye", -1812 ); + + StrIntHash h2 = h; + unitTest( h2.isCoreShared( h ) ); + + StrIntHash h3 = h.clone(); + unitTest( !h3.isCoreShared( h ) ); + } + + test reHashSpecial + { + IntStrHash hTest; + + setStepCount( 1000000 ); + for( int i=0; i<1000000; ++i ) + { + char buf[40]; snprintf(buf,40,"num%d",i); + incProgress(); + + if( ((double)random()/(double)RAND_MAX)<.01 ) + { + //printf("ERASE: %d (%s)\n",i%64,buf); + hTest.erase(i%64); + } + else + { + hTest[i%64]=buf; + } + + /*printf("(%d) size: %u fill: %u cap:%u\n", + i, + hTest.getSize(), + hTest.getFill(), + hTest.getCapacity() + );*/ + } + } + + test stress + { + srandom(time(NULL)); + + IntStrHash hTest; + IntStrHash hReUse; + setStepCount( 100000 ); + + for( int i=0; i<100000; ++i ) + { + char buf[40]; snprintf(buf,40,"num%d",i); + hTest[i] = buf; + incProgress(); + + + if( ((double)random()/(double)RAND_MAX)<.01 ) + { + Bu::List lKeys = hReUse.getKeys(); + Bu::List::const_iterator it = lKeys.begin(); + int iIdx = (int)(((double)random()/(double)RAND_MAX) + *lKeys.getSize()); + for( int l=0; it; ++it, ++l ) + { + if( l==iIdx ) + { + int iVal = *it; + hReUse.erase( *it ); + char buf[40]; snprintf(buf,40,"num%d",iVal); + hTest[i] = buf; + //printf("re-use: %s\n",buf); + } + } + } + + /*printf("(%s) size: %u fill: %u cap:%u\n", + buf, + hTest.getSize(), + hTest.getFill(), + hTest.getCapacity() + );*/ + + if( ((double)random()/(double)RAND_MAX)<.3 ) + { + Bu::List lKeys = hTest.getKeys(); + int iIdx = (int)(((double)random()/(double)RAND_MAX) + *lKeys.getSize()); + Bu::List::const_iterator it = lKeys.begin(); + for( int k=0; it; ++it, ++k ) + { + if( k == iIdx ) + { + hReUse.insert(*it,"yo"); + hTest.erase( *it ); + } + } + } + + if( hTest.getSize() > 100 ) + { + int iK = (int)(((double)random()/(double)RAND_MAX)*50)+10; + for( int j=0; j lKeys = hTest.getKeys(); + int iIdx = (int)(((double)random()/(double)RAND_MAX) + *lKeys.getSize()); + Bu::List::const_iterator it = lKeys.begin(); + for( int k=0; it; ++it, ++k ) + { + if( k == iIdx ) + { + hReUse.insert(*it,"yo"); + hTest.erase( *it ); + break; + } + } + } + } + } + } } diff --git a/src/unit/list.unit b/src/unit/list.unit index ec92fd5..0b60e43 100644 --- a/src/unit/list.unit +++ b/src/unit/list.unit @@ -13,136 +13,136 @@ typedef Bu::List IntList; suite List { - test append - { - 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 ); - } - } - - test prepend - { - 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 ); - } - } - - test copy - { - 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 ); - } - } - - test sort1 - { - IntList lst; - - lst.insertSorted( 5 ); - lst.insertSorted( 1 ); - lst.insertSorted( 10 ); - lst.insertSorted( 3 ); - - unitTest( lst == IntList(1).append(3).append(5).append(10) ); - } - - test sort2 - { - IntList lst; - - lst.insertSorted >( 5 ); - lst.insertSorted >( 1 ); - lst.insertSorted >( 10 ); - lst.insertSorted >( 3 ); - - unitTest( lst == IntList(10).append(5).append(3).append(1) ); - } - - test sort3 - { - IntList lst; - Bu::__basicGTCmp cmp; - - 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) ); - } - - test sort4 - { - IntList lst; - - lst.append( 5 ); - lst.append( 1 ); - lst.append( 10 ); - lst.append( 3 ); - - lst.sort(); - - unitTest( lst == IntList(1).append(3).append(5).append(10) ); - } - - test sort5 - { - IntList lst; - - lst.append( 5 ); - lst.append( 1 ); - lst.append( 10 ); - lst.append( 3 ); - - lst.sort >(); - - unitTest( lst == IntList(10).append(5).append(3).append(1) ); - } - - test sort6 - { - IntList lst; - - lst.append( 5 ); - lst.append( 1 ); - lst.append( 10 ); - lst.append( 3 ); - - Bu::__basicGTCmp x; - lst.sort( x ); - - unitTest( lst == IntList(10).append(5).append(3).append(1) ); - } + test append + { + 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 ); + } + } + + test prepend + { + 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 ); + } + } + + test copy + { + 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 ); + } + } + + test sort1 + { + IntList lst; + + lst.insertSorted( 5 ); + lst.insertSorted( 1 ); + lst.insertSorted( 10 ); + lst.insertSorted( 3 ); + + unitTest( lst == IntList(1).append(3).append(5).append(10) ); + } + + test sort2 + { + IntList lst; + + lst.insertSorted >( 5 ); + lst.insertSorted >( 1 ); + lst.insertSorted >( 10 ); + lst.insertSorted >( 3 ); + + unitTest( lst == IntList(10).append(5).append(3).append(1) ); + } + + test sort3 + { + IntList lst; + Bu::__basicGTCmp cmp; + + 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) ); + } + + test sort4 + { + IntList lst; + + lst.append( 5 ); + lst.append( 1 ); + lst.append( 10 ); + lst.append( 3 ); + + lst.sort(); + + unitTest( lst == IntList(1).append(3).append(5).append(10) ); + } + + test sort5 + { + IntList lst; + + lst.append( 5 ); + lst.append( 1 ); + lst.append( 10 ); + lst.append( 3 ); + + lst.sort >(); + + unitTest( lst == IntList(10).append(5).append(3).append(1) ); + } + + test sort6 + { + IntList lst; + + lst.append( 5 ); + lst.append( 1 ); + lst.append( 10 ); + lst.append( 3 ); + + Bu::__basicGTCmp x; + lst.sort( x ); + + unitTest( lst == IntList(10).append(5).append(3).append(1) ); + } } diff --git a/src/unit/md5.unit b/src/unit/md5.unit index 248aaaf..aaba113 100644 --- a/src/unit/md5.unit +++ b/src/unit/md5.unit @@ -12,71 +12,71 @@ suite Md5 { - test basics - { + test basics + { #define tryStr( a, b ) \ - { Bu::Md5 m; m.addData(a); unitTest( m.getHexResult() == b ); } (void)0 - tryStr("", "d41d8cd98f00b204e9800998ecf8427e"); - tryStr("a", "0cc175b9c0f1b6a831c399e269772661"); - tryStr("abc", "900150983cd24fb0d6963f7d28e17f72"); - tryStr("message digest", "f96b697d7cb7938d525a2f31aaf161d0"); - tryStr("abcdefghijklmnopqrstuvwxyz", - "c3fcd3d76192e4007dfb496cca67e13b"); - tryStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", - "d174ab98d277d9f5a5611c2c9f419d9f"); - tryStr("12345678901234567890123456789012345" - "678901234567890123456789012345678901234567890", - "57edf4a22be3c955ac49da2e2107b67a"); - } + { Bu::Md5 m; m.addData(a); unitTest( m.getHexResult() == b ); } (void)0 + tryStr("", "d41d8cd98f00b204e9800998ecf8427e"); + tryStr("a", "0cc175b9c0f1b6a831c399e269772661"); + tryStr("abc", "900150983cd24fb0d6963f7d28e17f72"); + tryStr("message digest", "f96b697d7cb7938d525a2f31aaf161d0"); + tryStr("abcdefghijklmnopqrstuvwxyz", + "c3fcd3d76192e4007dfb496cca67e13b"); + tryStr("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "d174ab98d277d9f5a5611c2c9f419d9f"); + tryStr("12345678901234567890123456789012345" + "678901234567890123456789012345678901234567890", + "57edf4a22be3c955ac49da2e2107b67a"); + } - test twoChunks - { - Bu::Md5 m; - m.addData("12345678901234567890123456789012345"); - m.addData("678901234567890123456789012345678901234567890"); - unitTest( m.getHexResult() == "57edf4a22be3c955ac49da2e2107b67a" ); - } + test twoChunks + { + Bu::Md5 m; + m.addData("12345678901234567890123456789012345"); + m.addData("678901234567890123456789012345678901234567890"); + unitTest( m.getHexResult() == "57edf4a22be3c955ac49da2e2107b67a" ); + } - test biggerBlocks - { - const char *sums[33] = { - "75fcf199abe516903321095a588b938d", - "e26a863c96d6bdba6601175aedaae108", - "2b207fdcb222078d3ebfeb8d5e7c9315", - "b08683aaa465add72cc2b43ae42f4f70", - "638bb73963b2d925771c3579ccb5e879", - "c727bd4b48a88e3df5924a2604de0790", - "f33d21203c80490f7342e5853c5550eb", - "db449faca66a177aae59b1e36a19d053", - "c800d429afb5f5c820f75c2c94e2e2bb", - "43b79c70b9a6a11e823ffbfa0f45a4db", - "0177ffc483cf598ae3966b3a5ae00c8c", - "1a68fdf4b17a3820d48d101e9355a818" - }; + test biggerBlocks + { + const char *sums[33] = { + "75fcf199abe516903321095a588b938d", + "e26a863c96d6bdba6601175aedaae108", + "2b207fdcb222078d3ebfeb8d5e7c9315", + "b08683aaa465add72cc2b43ae42f4f70", + "638bb73963b2d925771c3579ccb5e879", + "c727bd4b48a88e3df5924a2604de0790", + "f33d21203c80490f7342e5853c5550eb", + "db449faca66a177aae59b1e36a19d053", + "c800d429afb5f5c820f75c2c94e2e2bb", + "43b79c70b9a6a11e823ffbfa0f45a4db", + "0177ffc483cf598ae3966b3a5ae00c8c", + "1a68fdf4b17a3820d48d101e9355a818" + }; - char block[128]; - for( int i = 0; i < 128; i++ ) - block[i] = i*2; + char block[128]; + for( int i = 0; i < 128; i++ ) + block[i] = i*2; - const char **curSum = sums; - for( int j = 1; j < 4096; j*=2 ) - { - /* - Bu::File fOut("temp", Bu::File::WriteNew ); - for( int b = 0; b < j; b++ ) - { - fOut.write( block, 128 ); - } - fOut.close(); - system("md5sum -b temp"); - */ - Bu::Md5 m; - for( int b = 0; b < j; b++ ) - { - m.addData( block, 128 ); - } - unitTest( m.getHexResult() == *curSum ); - curSum++; - } - } + const char **curSum = sums; + for( int j = 1; j < 4096; j*=2 ) + { + /* + Bu::File fOut("temp", Bu::File::WriteNew ); + for( int b = 0; b < j; b++ ) + { + fOut.write( block, 128 ); + } + fOut.close(); + system("md5sum -b temp"); + */ + Bu::Md5 m; + for( int b = 0; b < j; b++ ) + { + m.addData( block, 128 ); + } + unitTest( m.getHexResult() == *curSum ); + curSum++; + } + } } diff --git a/src/unit/membuf.unit b/src/unit/membuf.unit index 37ea77e..e5ee073 100644 --- a/src/unit/membuf.unit +++ b/src/unit/membuf.unit @@ -10,37 +10,37 @@ suite MemBuf { - test testWriteRead01 - { - 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 ) ); + } - 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!!!" ) ); - } + 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/myriad.unit b/src/unit/myriad.unit index 8c96f79..4960f38 100644 --- a/src/unit/myriad.unit +++ b/src/unit/myriad.unit @@ -26,360 +26,360 @@ class VerifyObject friend Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const VerifyObject &vo ); friend Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, VerifyObject &vo ); public: - VerifyObject( int iUnits ) : - iUnits( iUnits ), - iBytesWritten( 0 ) - { - } + VerifyObject( int iUnits ) : + iUnits( iUnits ), + iBytesWritten( 0 ) + { + } - virtual ~VerifyObject() - { - } + virtual ~VerifyObject() + { + } - int getBytesWritten() - { - return iBytesWritten; - } + int getBytesWritten() + { + return iBytesWritten; + } private: - int iUnits; - mutable int iBytesWritten; + int iUnits; + mutable int iBytesWritten; }; Bu::ArchiveBase &operator<<( Bu::ArchiveBase &ar, const VerifyObject &vo ) { - Md5 sum; - ar << vo.iUnits; - vo.iBytesWritten = 4; - sum.addData( &vo.iUnits, 4 ); - for( int j = 0; j < vo.iUnits; j++ ) - { - int iRand = random()%128; -// ar << iRand; - Bu::String sDat( iRand ); - for( int j = 0; j < iRand; j++ ) - sDat[j] = (char)((uint8_t)(random()%256)); - ar << sDat; - sum.addData( &iRand, 4 ); - sum.addData( sDat.getStr(), iRand ); - vo.iBytesWritten += 4 + iRand; - } - Bu::String sRes = sum.getResult(); - ar << sRes; - vo.iBytesWritten += 4 + sRes.getSize(); - return ar; + Md5 sum; + ar << vo.iUnits; + vo.iBytesWritten = 4; + sum.addData( &vo.iUnits, 4 ); + for( int j = 0; j < vo.iUnits; j++ ) + { + int iRand = random()%128; +// ar << iRand; + Bu::String sDat( iRand ); + for( int j = 0; j < iRand; j++ ) + sDat[j] = (char)((uint8_t)(random()%256)); + ar << sDat; + sum.addData( &iRand, 4 ); + sum.addData( sDat.getStr(), iRand ); + vo.iBytesWritten += 4 + iRand; + } + Bu::String sRes = sum.getResult(); + ar << sRes; + vo.iBytesWritten += 4 + sRes.getSize(); + return ar; } Bu::ArchiveBase &operator>>( Bu::ArchiveBase &ar, VerifyObject &vo ) { - Md5 sum; - ar >> vo.iUnits; - sum.addData( &vo.iUnits, 4 ); - for( int j = 0; j < vo.iUnits; j++ ) - { - int iRand; -// ar >> iRand; - Bu::String sStr; - ar >> sStr; - iRand = sStr.getSize(); - sum.addData( &iRand, 4 ); - sum.addData( sStr.getStr(), iRand ); - } - Bu::String sSum; - ar >> sSum; - unitTest( sSum == sum.getResult() ); - int iTooMuch; - try - { - ar >> iTooMuch; - unitFailed("should have thrown an exception."); - } - catch( Bu::ExceptionBase &e ) - { - } - return ar; + Md5 sum; + ar >> vo.iUnits; + sum.addData( &vo.iUnits, 4 ); + for( int j = 0; j < vo.iUnits; j++ ) + { + int iRand; +// ar >> iRand; + Bu::String sStr; + ar >> sStr; + iRand = sStr.getSize(); + sum.addData( &iRand, 4 ); + sum.addData( sStr.getStr(), iRand ); + } + Bu::String sSum; + ar >> sSum; + unitTest( sSum == sum.getResult() ); + int iTooMuch; + try + { + ar >> iTooMuch; + unitFailed("should have thrown an exception."); + } + catch( Bu::ExceptionBase &e ) + { + } + return ar; } suite Myriad { - test setSize - { - String sFileName("myriad-XXXXXXX"); - - File fMyriad = tempFile( sFileName ); - Myriad m( fMyriad, 32 ); - - MyriadStream ms = m.openStream( m.createStream() ); - ms.setSize( 150 ); - ms.setPos( 145 ); - char stuff[10]; - unitTest( ms.read( stuff, 10 ) == 5 ); - - ms.setSize( 12 ); - unitTest( ms.read( stuff, 10 ) == 0 ); - unitTest( ms.write( "hello", 5 ) == 5 ); - unitTest( ms.tell() == 17 ); - - ms.setSize( 500 ); - unitTest( ms.tell() == 17 ); - } - - void addBlock( Stream &s, bool bAppend=true ) - { - if( bAppend ) - s.setPosEnd( 0 ); - int iSize = (random()%1016)+8; - s.write( &iSize, 4 ); - char *buf = new char[iSize-8]; - for( int j = 0; j < iSize-8; j++ ) - { - buf[j] = (j+iSize)%256; - } - if( random()%2 == 0 ) - { - s.write( buf, iSize-8 ); - } - else - { - for( int j = 0; j < iSize-8; ) - { - int iAmnt = (random()%8)+1; - if( iAmnt+j > iSize-8 ) - iAmnt = iSize-8-j; - iAmnt = s.write( buf+j, iAmnt ); - j += iAmnt; - } - } - delete[] buf; - iSize = ~iSize; - s.write( &iSize, 4 ); - } - - void verifyBlock( Stream &s ) - { - int iSize, iInv; - if( s.read( &iSize, 4 ) == 0 ) - return; - if( iSize < 8 || iSize > 1024 ) - throw ExceptionBase("Read bad data, %d", iSize ); - char *buf = new char[iSize-8]; - if( s.read( buf, iSize-8 ) < (size_t)iSize-8 ) - { - delete[] buf; - throw ExceptionBase("Block failed verify (insuffient block data)."); - } - for( int j = 0; j < iSize-8; j++ ) - { - if( buf[j] != (char)((j+iSize)%256) ) - { - char b = buf[j]; - delete[] buf; - throw ExceptionBase("Block failed computed data verify " - "(%02X==%02X).", b, (char)((j+iSize)%256) ); - } - } - delete[] buf; - if( s.read( &iInv, 4 ) < 4 ) - throw ExceptionBase("Block failed verify (insufficient data)."); - if( iInv != ~iSize ) - throw ExceptionBase("Block failed inversion verify."); - } - - void verifyStream( Stream &s ) - { - s.setPos( 0 ); - while( !s.isEos() ) - verifyBlock( s ); - } - - test stressGrow - { - String sFileName("myriad-XXXXXXX"); - - File fMyriad = tempFile( sFileName ); - Myriad m( fMyriad ); - m.initialize( 64 ); - - Array aStreams; - for( int j = 0; j < 5; j++ ) - { - aStreams.append( m.createStream() ); - } - - srandom( 512 ); - - for( int j = 0; j < 2500; j++ ) - { - switch( random()%5 ) - { - case 0: - aStreams.append( m.createStream() ); - break; - - case 1: - if( aStreams.getSize() > 0 ) - { - int iStream = random()%aStreams.getSize(); - { - MyriadStream ms = m.openStream( aStreams[iStream] ); - verifyStream( ms ); - } - m.deleteStream( aStreams[iStream] ); - Array::iterator i = aStreams.begin(); - for( int k = 0; k < iStream; k++ ) - i++; - aStreams.erase( i ); - } - break; - - default: - if( aStreams.getSize() == 0 ) - { - aStreams.append( m.createStream() ); - } - { - int iStream = random()%aStreams.getSize(); - MyriadStream ms = m.openStream( aStreams[iStream] ); - addBlock( ms ); - verifyStream( ms ); - } - break; - } - } - - for( Array::iterator i = aStreams.begin(); i; i++ ) - { - MyriadStream ms = m.openStream( *i ); - verifyStream( ms ); - } - } - - test stressTruncate - { - String sFileName("myriad-XXXXXXX"); - - File fMyriad = tempFile( sFileName ); - Myriad m( fMyriad ); - m.initialize( 128 ); - - Array aStream; - - for( int j = 0; j < 5; j++ ) - { - aStream.append( m.createStream() ); - } - - srandom( 1024 ); - - char b; - for( int iter = 0; iter < 2500; iter++ ) - { - for( Array::iterator i = aStream.begin(); i; i++ ) - { - MyriadStream ms = m.openStream( *i ); - addBlock( ms, false ); - ms.setSize( ms.tell() ); - unitTest( ms.read( &b, 1 ) == 0 ); - ms.setPos( 0 ); - verifyBlock( ms ); - unitTest( ms.read( &b, 1 ) == 0 ); - } - } - } - - test stressTruncate2 - { - String sFileName("myriad-XXXXXXX"); - - Array aStream; - - setStepCount( 5*2500 + 5 ); - - { - File fMyriad = tempFile( sFileName ); - Myriad m( fMyriad, 128 ); - - for( int j = 0; j < 5; j++ ) - { - aStream.append( m.createStream() ); - incProgress(); - } - } - - srandom( 1024 ); - - char b; - for( int iter = 0; iter < 2500; iter++ ) - { - File fMyriad( sFileName, File::ReadWrite ); - Myriad m( fMyriad ); - for( Array::iterator i = aStream.begin(); i; i++ ) - { - MyriadStream ms = m.openStream( *i ); - addBlock( ms, false ); - ms.setSize( ms.tell() ); - unitTest( ms.read( &b, 1 ) == 0 ); - ms.setPos( 0 ); - verifyBlock( ms ); - unitTest( ms.read( &b, 1 ) == 0 ); - incProgress(); - } - } - } - - test stressArchive - { - String sFileName("myriad-XXXXXX"); - Array aStream; - - srandom( 2096 ); - - setStepCount( 15*250 + 15 ); - - { - File fMyriad = tempFile( sFileName ); - Myriad m( fMyriad, 1024 ); - - for( int j = 0; j < 15; j++ ) - { - int iStream = m.createStream(); - aStream.append( iStream ); - VerifyObject vo( random()%1024 ); - { - MyriadStream ms = m.openStream( iStream ); - Archive ar( ms, Archive::save ); - ar << vo; - unitTest( ms.tell() == vo.getBytesWritten() ); - ms.setSize( ms.tell() ); - } - unitTest( m.getStreamSize( iStream ) == vo.getBytesWritten() ); - incProgress(); - } - } - - for( int iter = 0; iter < 250; iter++ ) - { - File fMyriad( sFileName, File::ReadWrite ); - Myriad m( fMyriad ); - for( Array::iterator i = aStream.begin(); i; i++ ) - { - VerifyObject vo( random()%1024 ); - { - MyriadStream ms = m.openStream( *i ); - Archive ar( ms, Archive::load ); - ar >> vo; - } - { - MyriadStream ms = m.openStream( *i ); - Archive ar( ms, Archive::save ); - ar << vo; - unitTest( ms.tell() == vo.getBytesWritten() ); - ms.setSize( ms.tell() ); - } - unitTest( m.getStreamSize( *i ) == vo.getBytesWritten() ); - incProgress(); - } - } - } + test setSize + { + String sFileName("myriad-XXXXXXX"); + + File fMyriad = tempFile( sFileName ); + Myriad m( fMyriad, 32 ); + + MyriadStream ms = m.openStream( m.createStream() ); + ms.setSize( 150 ); + ms.setPos( 145 ); + char stuff[10]; + unitTest( ms.read( stuff, 10 ) == 5 ); + + ms.setSize( 12 ); + unitTest( ms.read( stuff, 10 ) == 0 ); + unitTest( ms.write( "hello", 5 ) == 5 ); + unitTest( ms.tell() == 17 ); + + ms.setSize( 500 ); + unitTest( ms.tell() == 17 ); + } + + void addBlock( Stream &s, bool bAppend=true ) + { + if( bAppend ) + s.setPosEnd( 0 ); + int iSize = (random()%1016)+8; + s.write( &iSize, 4 ); + char *buf = new char[iSize-8]; + for( int j = 0; j < iSize-8; j++ ) + { + buf[j] = (j+iSize)%256; + } + if( random()%2 == 0 ) + { + s.write( buf, iSize-8 ); + } + else + { + for( int j = 0; j < iSize-8; ) + { + int iAmnt = (random()%8)+1; + if( iAmnt+j > iSize-8 ) + iAmnt = iSize-8-j; + iAmnt = s.write( buf+j, iAmnt ); + j += iAmnt; + } + } + delete[] buf; + iSize = ~iSize; + s.write( &iSize, 4 ); + } + + void verifyBlock( Stream &s ) + { + int iSize, iInv; + if( s.read( &iSize, 4 ) == 0 ) + return; + if( iSize < 8 || iSize > 1024 ) + throw ExceptionBase("Read bad data, %d", iSize ); + char *buf = new char[iSize-8]; + if( s.read( buf, iSize-8 ) < (size_t)iSize-8 ) + { + delete[] buf; + throw ExceptionBase("Block failed verify (insuffient block data)."); + } + for( int j = 0; j < iSize-8; j++ ) + { + if( buf[j] != (char)((j+iSize)%256) ) + { + char b = buf[j]; + delete[] buf; + throw ExceptionBase("Block failed computed data verify " + "(%02X==%02X).", b, (char)((j+iSize)%256) ); + } + } + delete[] buf; + if( s.read( &iInv, 4 ) < 4 ) + throw ExceptionBase("Block failed verify (insufficient data)."); + if( iInv != ~iSize ) + throw ExceptionBase("Block failed inversion verify."); + } + + void verifyStream( Stream &s ) + { + s.setPos( 0 ); + while( !s.isEos() ) + verifyBlock( s ); + } + + test stressGrow + { + String sFileName("myriad-XXXXXXX"); + + File fMyriad = tempFile( sFileName ); + Myriad m( fMyriad ); + m.initialize( 64 ); + + Array aStreams; + for( int j = 0; j < 5; j++ ) + { + aStreams.append( m.createStream() ); + } + + srandom( 512 ); + + for( int j = 0; j < 2500; j++ ) + { + switch( random()%5 ) + { + case 0: + aStreams.append( m.createStream() ); + break; + + case 1: + if( aStreams.getSize() > 0 ) + { + int iStream = random()%aStreams.getSize(); + { + MyriadStream ms = m.openStream( aStreams[iStream] ); + verifyStream( ms ); + } + m.deleteStream( aStreams[iStream] ); + Array::iterator i = aStreams.begin(); + for( int k = 0; k < iStream; k++ ) + i++; + aStreams.erase( i ); + } + break; + + default: + if( aStreams.getSize() == 0 ) + { + aStreams.append( m.createStream() ); + } + { + int iStream = random()%aStreams.getSize(); + MyriadStream ms = m.openStream( aStreams[iStream] ); + addBlock( ms ); + verifyStream( ms ); + } + break; + } + } + + for( Array::iterator i = aStreams.begin(); i; i++ ) + { + MyriadStream ms = m.openStream( *i ); + verifyStream( ms ); + } + } + + test stressTruncate + { + String sFileName("myriad-XXXXXXX"); + + File fMyriad = tempFile( sFileName ); + Myriad m( fMyriad ); + m.initialize( 128 ); + + Array aStream; + + for( int j = 0; j < 5; j++ ) + { + aStream.append( m.createStream() ); + } + + srandom( 1024 ); + + char b; + for( int iter = 0; iter < 2500; iter++ ) + { + for( Array::iterator i = aStream.begin(); i; i++ ) + { + MyriadStream ms = m.openStream( *i ); + addBlock( ms, false ); + ms.setSize( ms.tell() ); + unitTest( ms.read( &b, 1 ) == 0 ); + ms.setPos( 0 ); + verifyBlock( ms ); + unitTest( ms.read( &b, 1 ) == 0 ); + } + } + } + + test stressTruncate2 + { + String sFileName("myriad-XXXXXXX"); + + Array aStream; + + setStepCount( 5*2500 + 5 ); + + { + File fMyriad = tempFile( sFileName ); + Myriad m( fMyriad, 128 ); + + for( int j = 0; j < 5; j++ ) + { + aStream.append( m.createStream() ); + incProgress(); + } + } + + srandom( 1024 ); + + char b; + for( int iter = 0; iter < 2500; iter++ ) + { + File fMyriad( sFileName, File::ReadWrite ); + Myriad m( fMyriad ); + for( Array::iterator i = aStream.begin(); i; i++ ) + { + MyriadStream ms = m.openStream( *i ); + addBlock( ms, false ); + ms.setSize( ms.tell() ); + unitTest( ms.read( &b, 1 ) == 0 ); + ms.setPos( 0 ); + verifyBlock( ms ); + unitTest( ms.read( &b, 1 ) == 0 ); + incProgress(); + } + } + } + + test stressArchive + { + String sFileName("myriad-XXXXXX"); + Array aStream; + + srandom( 2096 ); + + setStepCount( 15*250 + 15 ); + + { + File fMyriad = tempFile( sFileName ); + Myriad m( fMyriad, 1024 ); + + for( int j = 0; j < 15; j++ ) + { + int iStream = m.createStream(); + aStream.append( iStream ); + VerifyObject vo( random()%1024 ); + { + MyriadStream ms = m.openStream( iStream ); + Archive ar( ms, Archive::save ); + ar << vo; + unitTest( ms.tell() == vo.getBytesWritten() ); + ms.setSize( ms.tell() ); + } + unitTest( m.getStreamSize( iStream ) == vo.getBytesWritten() ); + incProgress(); + } + } + + for( int iter = 0; iter < 250; iter++ ) + { + File fMyriad( sFileName, File::ReadWrite ); + Myriad m( fMyriad ); + for( Array::iterator i = aStream.begin(); i; i++ ) + { + VerifyObject vo( random()%1024 ); + { + MyriadStream ms = m.openStream( *i ); + Archive ar( ms, Archive::load ); + ar >> vo; + } + { + MyriadStream ms = m.openStream( *i ); + Archive ar( ms, Archive::save ); + ar << vo; + unitTest( ms.tell() == vo.getBytesWritten() ); + ms.setSize( ms.tell() ); + } + unitTest( m.getStreamSize( *i ) == vo.getBytesWritten() ); + incProgress(); + } + } + } } diff --git a/src/unit/queuebuf.unit b/src/unit/queuebuf.unit index 553d9fc..bc55a04 100644 --- a/src/unit/queuebuf.unit +++ b/src/unit/queuebuf.unit @@ -16,89 +16,89 @@ suite QueueBuf { - test testBasic01 - { - 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::String &fill, unsigned int iSize ) - { - char c; - for( unsigned int i=0; ithis part"); - Bu::String b; - Bu::String::iterator s = a.begin(); - for(; s; s++ ) - { - if( *s == '>' ) - { - s++; - b.set( s ); - break; - } - } - unitTest( b == "this part" ); - - b.append( s ); - - Bu::String c; - c.set( b.begin() ); - - // This is here because the comparison operator used to cause flattening. - unitTest( b == "this partthis part" ); - unitTest( c == b ); - } - - test iteratorAppend2 - { - Bu::String a("just [this] part"); - Bu::String b; - Bu::String::iterator s = a.begin(); - for(; s; s++ ) - { - if( *s == '[' ) - { - s++; - break; - } - } - Bu::String::iterator e = s; - for(; e; e++ ) - { - if( *e == ']' ) - { - b.set( s, e ); - break; - } - } - unitTest( b == "this" ); - - b.append( s, e ); - - for( Bu::String::iterator i = b.begin(); i;) - { - Bu::String::iterator k = i; - k++; - if( !k ) - { - b.append( b.begin(), i ); - break; - } - i = k; - } - Bu::String l; - l.set( b.begin() ); - unitTest( l == "thisthisthisthi" ); - for( Bu::String::iterator i = b.begin(); i;) - { - Bu::String::iterator k = i; - k++; - if( !k ) - { - b.append( b.begin(), i ); - break; - } - i = k; - } - l.set( b.begin() ); - unitTest( l == "thisthisthisthithisthisthisth" ); - } - - test isSet1 - { - Bu::String bob; - - unitTest( bob.isSet() == false ); - bob = "something"; - unitTest( bob.isSet() == true ); - bob = ""; - unitTest( bob.isSet() == false ); - } - - test swap1 - { - Bu::String a, b; - a = "Goodbye"; - b = "Hello"; - Bu::swap( a, b ); - unitTest( a == "Hello" ); - unitTest( b == "Goodbye" ); - } - - test swap2 - { - Bu::String a, b; - a = "Goodbye"; - b = "Hello"; - std::swap( a, b ); - unitTest( a == "Hello" ); - unitTest( b == "Goodbye" ); - } - - test replace1 - { - Bu::String a; - a = "This is a test."; - unitTest( a.replace("i", "ooo") == "Thooos ooos a test." ); - } - - test replace2 - { - Bu::String a; - a = "aaaboostuffb"; - unitTest( a.replace("boo", "/") == "aaa/stuffb" ); - } - - test coreDerefBug1 - { - Bu::String a, b; - a = "bob"; - a.setSize( 0 ); - b = a; - b.getStr(); - } - - test padding1 - { - Bu::String a; - a.append('a'); - a.append('b'); - a.append('c'); - a.append("hello"); - a.clear(); - } - - test padding2 - { - Bu::String src("It's all sorts of things"); - Bu::String::const_iterator i = src.find('a'); - Bu::String::const_iterator j = src.find('f'); - Bu::String a, b; - a.append( i ); - i += 2; - a.append( i, j ); - a.append('a'); - a.append('b'); - a.append('c'); - a.append("hello"); - a.append( src ); - b = a; - a.clear(); - } - - test append - { - // This is the byte sequence that caused += to die - // 03 F0 9C A4 F5 8A C8 CA 0E - uint8_t b; - Bu::String m1; - b = 0x03; m1 += (char)b; - b = 0xF0; m1 += (char)b; - b = 0x9C; m1 += (char)b; - b = 0xA4; m1 += (char)b; - b = 0xF5; m1 += (char)b; - b = 0x8A; m1 += (char)b; - b = 0xC8; m1 += (char)b; - b = 0xCA; m1 += (char)b; - b = 0x0E; m1 += (char)b; - - Bu::String m2; - b = 0x03; m2.append( (const char *)&b, 1 ); - b = 0xF0; m2.append( (const char *)&b, 1 ); - b = 0x9C; m2.append( (const char *)&b, 1 ); - b = 0xA4; m2.append( (const char *)&b, 1 ); - b = 0xF5; m2.append( (const char *)&b, 1 ); - b = 0x8A; m2.append( (const char *)&b, 1 ); - b = 0xC8; m2.append( (const char *)&b, 1 ); - b = 0xCA; m2.append( (const char *)&b, 1 ); - b = 0x0E; m2.append( (const char *)&b, 1 ); - - unitTest( m1 == m2 ); - unitTest( m1 == "\x03\xF0\x9C\xA4\xF5\x8A\xC8\xCA\x0E" ); - } - - test toUpper1 - { - Bu::String s1("HeLlO ThErE, HoW ArE YoU DoInG?"); - unitTest( s1.toUpper() == "HELLO THERE, HOW ARE YOU DOING?" ); - unitTest( s1 == "HeLlO ThErE, HoW ArE YoU DoInG?" ); - } - - test toLower1 - { - Bu::String s1("HeLlO ThErE, HoW ArE YoU DoInG?"); - unitTest( s1.toLower() == "hello there, how are you doing?" ); - unitTest( s1 == "HeLlO ThErE, HoW ArE YoU DoInG?" ); - } - - test trimWhitespace1 - { - unitTest( Bu::String("Hello there").trimWhitespace() - == "Hello there" ); - unitTest( Bu::String(" \t\r\r\nHello there").trimWhitespace() - == "Hello there" ); - unitTest( Bu::String("Hello there \r\n\n\t\t ").trimWhitespace() - == "Hello there" ); - unitTest( Bu::String(" \tHello there\r\n \t").trimWhitespace() - == "Hello there" ); - unitTest( Bu::String(" \t\t\r\n").trimWhitespace() == "" ); - unitTest( Bu::String().trimWhitespace() == "" ); - unitTest( Bu::String(" \tHello \t\t\r\nthere\r\n \t").trimWhitespace() - == "Hello \t\t\r\nthere" ); - } - - test format1 - { - unitTest( (Bu::String)Bu::String("%1").arg( 12, Bu::Fmt().width(3) ) == " 12" ); - unitTest( (Bu::String)Bu::String("%1 %2").arg("IQ").arg(4, Bu::Fmt().plus()) == "IQ +4" ); - unitTest( (Bu::String)Bu::String("%1%2").arg("IQ").arg(4, Bu::Fmt().plus()) == "IQ+4" ); - unitTest( (Bu::String)Bu::String("Sup #%1-Guy!").arg( 1 ) == "Sup #1-Guy!" ); - } - - test format2 - { - unitTest( Bu::String("0x%{1}00").arg( 75, Bu::Fmt::hex() ).end() == "0x4B00" ); - } + test compare1 + { + Bu::String b("Bob"); + unitTest( !(b == "Bobo") ); + unitTest( b == "Bob" ); + } + + test compare2 + { + Bu::String b("Bobo"); + unitTest( !(b == "Bob") ); + unitTest( b == "Bobo" ); + } + + test appendSingle + { + Bu::String b; + for( char l = 'a'; l < 'g'; l++ ) + b += l; + unitTest( b == "abcdef" ); + unitTest( strcmp( b.getStr(), "abcdef" ) == 0 ); + } + + test shared1 + { + Bu::String a("Hey there"); + Bu::String b( a ); + unitTest( a.getConstStr() == b.getConstStr() ); + b += " guy"; + unitTest( a.getConstStr() != b.getConstStr() ); + a = b; + unitTest( a.getConstStr() == b.getConstStr() ); + } + + test insert + { + Bu::String 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 remove + { + Bu::String 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 add1 + { + Bu::String a("hi there"); + Bu::String b(", yeah!"); + Bu::String c = a + b; + + unitTest( c == "hi there, yeah!" ); + } + + test add2 + { + Bu::String a("hi there"); + Bu::String c = a + ", yeah!"; + + unitTest( c == "hi there, yeah!" ); + } + + test add3 + { + Bu::String a("hi there"); + Bu::String b(", yeah!"); + Bu::String c = a + ", Mr. Man" + b; + + unitTest( c == "hi there, Mr. Man, yeah!" ); + } + + test add4 + { + Bu::String b(", yeah!"); + Bu::String c = "hi there" + b; + + unitTest( c == "hi there, yeah!" ); + } + + test add5 + { + Bu::String b; + Bu::String c = "sup?"; + b += "hey, " + c; + + unitTest( b == "hey, sup?" ); + } + + test add6 + { + Bu::String a("Hello"); + char b[256] = {"Dude"}; + Bu::String c = a + "/" + b; + + unitTest( c == "Hello/Dude" ); + } + + test add7 + { + const Bu::String a("hello "); + Bu::String b(" how "); + unitTest( a == "hello " ); + unitTest( a + "dude" == "hello dude" ); + unitTest( a + "dude" + b + "are you?" == "hello dude how are you?" ); + } + + test subStr1 + { + Bu::String a("abcdefghijklmnop"); + Bu::String::iterator i = a.find('f'); + unitTest( a.getSubStr( i, Bu::String::iterator() ) == "fghijklmnop" ); + Bu::String::iterator j = i.find('l'); + unitTest( a.getSubStr( i, j ) == "fghijk" ); + } + + test compareSub1 + { + Bu::String 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 compareSub2 + { + Bu::String a("just a string."); + unitTest( a.compareSub(Bu::String("a "), 5, 2) == true ); + unitTest( a.compareSub(Bu::String("string.aoeu"), 7, 11 ) == false ); + unitTest( a.compareSub(Bu::String("string.aoeu"), 7, 3 ) == true ); + } + + test iterator1 + { + Bu::String a("This is a test."); + Bu::String b; + for( Bu::String::iterator i = a.begin(); i; i++ ) + { + b += *i; + } + unitTest( a == b ); + } + + test iteratorCompare1 + { + Bu::String a("This is a test."); + Bu::String b("--This is a test."); + Bu::String::iterator ai = a.begin(); + Bu::String::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 ); + b += "hi"; + unitTest( ai.compare( bi ) == false ); + unitTest( bi.compare( ai ) == false ); + } + + test iteratorCompare2 + { + Bu::String a("1234honour"); + Bu::String b("--1234ueje"); + Bu::String::iterator ai = a.begin(); + Bu::String::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 ); + + a = "fell"; + b = "-felloo"; + ai = a.begin(); + bi = b.begin()+1; + unitTest( ai.compare( bi, 4 ) == true ); + ai++; + bi++; + unitTest( ai.compare( bi, 4 ) == false ); + } + + test iteratorCompare3 + { + Bu::String a("1234aoeu"); + Bu::String::iterator ai = a.begin(); + unitTest( ai.compare("1234") == false ); + unitTest( ai.compare("1234aoeu") == true ); + unitTest( ai.compare("1234aoeuee") == false ); + ai += 4; + unitTest( ai.compare("aoeu") == true ); + unitTest( ai.compare("aoeubo") == false ); + unitTest( ai.compare("aoe") == false ); + unitTest( ai.compare("wrong") == false ); + unitTest( ai.compare("boeu") == false ); + } + + test iteratorCompare4 + { + Bu::String a("1234aoeu"); + Bu::String::iterator ai = a.begin(); + unitTest( ai.compare("1234", 4) == true ); + unitTest( ai.compare("1234aoeu", 8) == true ); + unitTest( ai.compare("1234aoeuee", 10) == false ); + } + + test iteratorCompare5 + { + Bu::String a("1234aoeu"); + Bu::String b("34ao"); + Bu::String::iterator ai = a.begin(); + unitTest( ai.compare( b ) == false ); + ai += 2; + unitTest( ai.compare( b ) == false ); + b = "oeu"; + ai += 3; + unitTest( ai.compare( b ) == true ); + b += "boo"; + unitTest( ai.compare( b ) == false ); + } + + test iteratorCompare6 + { + Bu::String a("1234aoeu"); + Bu::String::iterator ai = a.begin(); + unitTest( ai.compare( Bu::String("1234"), 4) == true ); + unitTest( ai.compare( Bu::String("1234aoeu"), 8) == true ); + unitTest( ai.compare( Bu::String("1234aoeuee"), 10) == false ); + } + + test const_iteratorCompare1 + { + Bu::String a("This is a test."); + Bu::String b("--This is a test."); + Bu::String::const_iterator ai = a.begin(); + Bu::String::const_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 ); + b += "hi"; + unitTest( ai.compare( bi ) == false ); + unitTest( bi.compare( ai ) == false ); + } + + test const_iteratorCompare2 + { + Bu::String a("1234honour"); + Bu::String b("--1234ueje"); + Bu::String::const_iterator ai = a.begin(); + Bu::String::const_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 ); + + a = "fell"; + b = "-felloo"; + ai = a.begin(); + bi = b.begin()+1; + unitTest( ai.compare( bi, 4 ) == true ); + ai++; + bi++; + unitTest( ai.compare( bi, 4 ) == false ); + } + + test const_iteratorCompare3 + { + Bu::String a("1234aoeu"); + Bu::String::const_iterator ai = a.begin(); + unitTest( ai.compare("1234") == false ); + unitTest( ai.compare("1234aoeu") == true ); + unitTest( ai.compare("1234aoeuee") == false ); + ai += 4; + unitTest( ai.compare("aoeu") == true ); + unitTest( ai.compare("aoeubo") == false ); + unitTest( ai.compare("aoe") == false ); + unitTest( ai.compare("wrong") == false ); + unitTest( ai.compare("boeu") == false ); + } + + test const_iteratorCompare4 + { + Bu::String a("1234aoeu"); + Bu::String::const_iterator ai = a.begin(); + unitTest( ai.compare("1234", 4) == true ); + unitTest( ai.compare("1234aoeu", 8) == true ); + unitTest( ai.compare("1234aoeuee", 10) == false ); + } + + test const_iteratorCompare5 + { + Bu::String a("1234aoeu"); + Bu::String b("34ao"); + Bu::String::const_iterator ai = a.begin(); + unitTest( ai.compare( b ) == false ); + ai += 2; + unitTest( ai.compare( b ) == false ); + b = "oeu"; + ai += 3; + unitTest( ai.compare( b ) == true ); + b += "boo"; + unitTest( ai.compare( b ) == false ); + } + + test const_iteratorCompare6 + { + Bu::String a("1234aoeu"); + Bu::String::const_iterator ai = a.begin(); + unitTest( ai.compare( Bu::String("1234"), 4) == true ); + unitTest( ai.compare( Bu::String("1234aoeu"), 8) == true ); + unitTest( ai.compare( Bu::String("1234aoeuee"), 10) == false ); + } + + test iteratorAppend1 + { + Bu::String a("just ->this part"); + Bu::String b; + Bu::String::iterator s = a.begin(); + for(; s; s++ ) + { + if( *s == '>' ) + { + s++; + b.set( s ); + break; + } + } + unitTest( b == "this part" ); + + b.append( s ); + + Bu::String c; + c.set( b.begin() ); + + // This is here because the comparison operator used to cause flattening. + unitTest( b == "this partthis part" ); + unitTest( c == b ); + } + + test iteratorAppend2 + { + Bu::String a("just [this] part"); + Bu::String b; + Bu::String::iterator s = a.begin(); + for(; s; s++ ) + { + if( *s == '[' ) + { + s++; + break; + } + } + Bu::String::iterator e = s; + for(; e; e++ ) + { + if( *e == ']' ) + { + b.set( s, e ); + break; + } + } + unitTest( b == "this" ); + + b.append( s, e ); + + for( Bu::String::iterator i = b.begin(); i;) + { + Bu::String::iterator k = i; + k++; + if( !k ) + { + b.append( b.begin(), i ); + break; + } + i = k; + } + Bu::String l; + l.set( b.begin() ); + unitTest( l == "thisthisthisthi" ); + for( Bu::String::iterator i = b.begin(); i;) + { + Bu::String::iterator k = i; + k++; + if( !k ) + { + b.append( b.begin(), i ); + break; + } + i = k; + } + l.set( b.begin() ); + unitTest( l == "thisthisthisthithisthisthisth" ); + } + + test isSet1 + { + Bu::String bob; + + unitTest( bob.isSet() == false ); + bob = "something"; + unitTest( bob.isSet() == true ); + bob = ""; + unitTest( bob.isSet() == false ); + } + + test swap1 + { + Bu::String a, b; + a = "Goodbye"; + b = "Hello"; + Bu::swap( a, b ); + unitTest( a == "Hello" ); + unitTest( b == "Goodbye" ); + } + + test swap2 + { + Bu::String a, b; + a = "Goodbye"; + b = "Hello"; + std::swap( a, b ); + unitTest( a == "Hello" ); + unitTest( b == "Goodbye" ); + } + + test replace1 + { + Bu::String a; + a = "This is a test."; + unitTest( a.replace("i", "ooo") == "Thooos ooos a test." ); + } + + test replace2 + { + Bu::String a; + a = "aaaboostuffb"; + unitTest( a.replace("boo", "/") == "aaa/stuffb" ); + } + + test coreDerefBug1 + { + Bu::String a, b; + a = "bob"; + a.setSize( 0 ); + b = a; + b.getStr(); + } + + test padding1 + { + Bu::String a; + a.append('a'); + a.append('b'); + a.append('c'); + a.append("hello"); + a.clear(); + } + + test padding2 + { + Bu::String src("It's all sorts of things"); + Bu::String::const_iterator i = src.find('a'); + Bu::String::const_iterator j = src.find('f'); + Bu::String a, b; + a.append( i ); + i += 2; + a.append( i, j ); + a.append('a'); + a.append('b'); + a.append('c'); + a.append("hello"); + a.append( src ); + b = a; + a.clear(); + } + + test append + { + // This is the byte sequence that caused += to die + // 03 F0 9C A4 F5 8A C8 CA 0E + uint8_t b; + Bu::String m1; + b = 0x03; m1 += (char)b; + b = 0xF0; m1 += (char)b; + b = 0x9C; m1 += (char)b; + b = 0xA4; m1 += (char)b; + b = 0xF5; m1 += (char)b; + b = 0x8A; m1 += (char)b; + b = 0xC8; m1 += (char)b; + b = 0xCA; m1 += (char)b; + b = 0x0E; m1 += (char)b; + + Bu::String m2; + b = 0x03; m2.append( (const char *)&b, 1 ); + b = 0xF0; m2.append( (const char *)&b, 1 ); + b = 0x9C; m2.append( (const char *)&b, 1 ); + b = 0xA4; m2.append( (const char *)&b, 1 ); + b = 0xF5; m2.append( (const char *)&b, 1 ); + b = 0x8A; m2.append( (const char *)&b, 1 ); + b = 0xC8; m2.append( (const char *)&b, 1 ); + b = 0xCA; m2.append( (const char *)&b, 1 ); + b = 0x0E; m2.append( (const char *)&b, 1 ); + + unitTest( m1 == m2 ); + unitTest( m1 == "\x03\xF0\x9C\xA4\xF5\x8A\xC8\xCA\x0E" ); + } + + test toUpper1 + { + Bu::String s1("HeLlO ThErE, HoW ArE YoU DoInG?"); + unitTest( s1.toUpper() == "HELLO THERE, HOW ARE YOU DOING?" ); + unitTest( s1 == "HeLlO ThErE, HoW ArE YoU DoInG?" ); + } + + test toLower1 + { + Bu::String s1("HeLlO ThErE, HoW ArE YoU DoInG?"); + unitTest( s1.toLower() == "hello there, how are you doing?" ); + unitTest( s1 == "HeLlO ThErE, HoW ArE YoU DoInG?" ); + } + + test trimWhitespace1 + { + unitTest( Bu::String("Hello there").trimWhitespace() + == "Hello there" ); + unitTest( Bu::String(" \t\r\r\nHello there").trimWhitespace() + == "Hello there" ); + unitTest( Bu::String("Hello there \r\n\n\t\t ").trimWhitespace() + == "Hello there" ); + unitTest( Bu::String(" \tHello there\r\n \t").trimWhitespace() + == "Hello there" ); + unitTest( Bu::String(" \t\t\r\n").trimWhitespace() == "" ); + unitTest( Bu::String().trimWhitespace() == "" ); + unitTest( Bu::String(" \tHello \t\t\r\nthere\r\n \t").trimWhitespace() + == "Hello \t\t\r\nthere" ); + } + + test format1 + { + unitTest( (Bu::String)Bu::String("%1").arg( 12, Bu::Fmt().width(3) ) == " 12" ); + unitTest( (Bu::String)Bu::String("%1 %2").arg("IQ").arg(4, Bu::Fmt().plus()) == "IQ +4" ); + unitTest( (Bu::String)Bu::String("%1%2").arg("IQ").arg(4, Bu::Fmt().plus()) == "IQ+4" ); + unitTest( (Bu::String)Bu::String("Sup #%1-Guy!").arg( 1 ) == "Sup #1-Guy!" ); + } + + test format2 + { + unitTest( Bu::String("0x%{1}00").arg( 75, Bu::Fmt::hex() ).end() == "0x4B00" ); + } } // 03F09CA4F58AC8CA0E80F0D9D409D0A60700A192270004BC3A99E91D0001034F544603362E35013103313130019CA4F58AC8CA0E0002830800002C4200008AC200EBF7D9D4090127BB010000E3 // diff --git a/src/unit/substream.unit b/src/unit/substream.unit index c66238d..b0d1407 100644 --- a/src/unit/substream.unit +++ b/src/unit/substream.unit @@ -11,42 +11,42 @@ suite SubStream { - test testRead01 - { - Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz"); - mb.seek( 4 ); - Bu::SubStream ss( mb, 10 ); - unitTest( ss.readLine() == "efghijklmn" ); - } + test testRead01 + { + Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz"); + mb.seek( 4 ); + Bu::SubStream ss( mb, 10 ); + unitTest( ss.readLine() == "efghijklmn" ); + } - test testRead02 - { - Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz"); - mb.seek( 4 ); - Bu::SubStream ss( mb, 10 ); - char buf[8]; - size_t iRead = ss.read( buf, 8 ); - unitTest( iRead == 8 ); - unitTest( strncmp( buf, "efghijkl", 8 ) == 0 ); - unitTest( !ss.isEos() ); - iRead = ss.read( buf, 8 ); - unitTest( iRead == 2 ); - unitTest( strncmp( buf, "mn", 2 ) == 0 ); - unitTest( ss.isEos() ); - } + test testRead02 + { + Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz"); + mb.seek( 4 ); + Bu::SubStream ss( mb, 10 ); + char buf[8]; + size_t iRead = ss.read( buf, 8 ); + unitTest( iRead == 8 ); + unitTest( strncmp( buf, "efghijkl", 8 ) == 0 ); + unitTest( !ss.isEos() ); + iRead = ss.read( buf, 8 ); + unitTest( iRead == 2 ); + unitTest( strncmp( buf, "mn", 2 ) == 0 ); + unitTest( ss.isEos() ); + } - test testRead03 - { - Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz"); - mb.seek( 20 ); - Bu::SubStream ss( mb, 10 ); - char buf[8]; - size_t iRead = ss.read( buf, 8 ); - unitTest( iRead == 6 ); - unitTest( strncmp( buf, "uvwxyz", 6 ) == 0 ); - unitTest( ss.isEos() ); - iRead = ss.read( buf, 8 ); - unitTest( iRead == 0 ); - unitTest( ss.isEos() ); - } + test testRead03 + { + Bu::MemBuf mb("abcdefghijklmnopqrstuvwxyz"); + mb.seek( 20 ); + Bu::SubStream ss( mb, 10 ); + char buf[8]; + size_t iRead = ss.read( buf, 8 ); + unitTest( iRead == 6 ); + unitTest( strncmp( buf, "uvwxyz", 6 ) == 0 ); + unitTest( ss.isEos() ); + iRead = ss.read( buf, 8 ); + unitTest( iRead == 0 ); + unitTest( ss.isEos() ); + } } diff --git a/src/unit/taf.unit b/src/unit/taf.unit index 12e93c2..47605ee 100644 --- a/src/unit/taf.unit +++ b/src/unit/taf.unit @@ -15,64 +15,64 @@ suite Taf { - test read1 - { + test read1 + { #define FN_TMP ("/tmp/tmpXXXXXXXX") - Bu::String sFnTmp(FN_TMP); - Bu::File fOut = Bu::File::tempFile( sFnTmp ); - const char *data = - "{test: name=\"Bob\"}" - ; - fOut.write(data,strlen(data)); - fOut.close(); + Bu::String 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 - } + } - test encode1 - { - Bu::MemBuf mb; - Bu::TafWriter tw( mb ); - - Bu::TafGroup g("Test data"); - Bu::String 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::String 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\"=\"" + 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"; + "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 ); diff --git a/src/unit/variant.unit b/src/unit/variant.unit index 684bea1..68c7be5 100644 --- a/src/unit/variant.unit +++ b/src/unit/variant.unit @@ -16,46 +16,46 @@ using namespace Bu; Bu::String mkastring() { - Bu::String a = "s"; - a += "tu"; - a += "f"; - a += "f"; - return a; + Bu::String a = "s"; + a += "tu"; + a += "f"; + a += "f"; + return a; } suite Variant { - test construction - { - Bu::Variant v( 55 ); - v.get(); + test construction + { + Bu::Variant v( 55 ); + v.get(); - Bu::Variant v2( v ); - v2.get(); - } + Bu::Variant v2( v ); + v2.get(); + } - test formatting - { - Bu::Variant v("hello"); - Bu::MemBuf mb; - Bu::Formatter f( mb ); - f << v; - unitTest( mb.getString() == v.get() ); - } + test formatting + { + Bu::Variant v("hello"); + Bu::MemBuf mb; + Bu::Formatter f( mb ); + f << v; + unitTest( mb.getString() == v.get() ); + } - test stringForamtting - { - Bu::String s1; - s1 = "hello"; - int32_t i1, i2; - i1 = 32; - i2 = 0; - Bu::String out = Bu::String("%1-%2-%3-%4.odp"). - arg( s1.getStr() ). - arg( mkastring().getStr() ). - arg( i1, Fmt(2).fill('0') ). - arg( i2, Fmt(2).fill('0') ); - // sio << sio.nl << out << sio.nl; - unitTest( out == "hello-stuff-32-00.odp" ); - } + test stringForamtting + { + Bu::String s1; + s1 = "hello"; + int32_t i1, i2; + i1 = 32; + i2 = 0; + Bu::String out = Bu::String("%1-%2-%3-%4.odp"). + arg( s1.getStr() ). + arg( mkastring().getStr() ). + arg( i1, Fmt(2).fill('0') ). + arg( i2, Fmt(2).fill('0') ); + // sio << sio.nl << out << sio.nl; + unitTest( out == "hello-stuff-32-00.odp" ); + } } diff --git a/src/unit/xml.unit b/src/unit/xml.unit index 0db21c1..57e1c1c 100644 --- a/src/unit/xml.unit +++ b/src/unit/xml.unit @@ -12,10 +12,10 @@ suite Xml { - test declaration - { - Bu::String sXml(" "); - Bu::MemBuf buf( sXml ); - Bu::XmlReader xr( buf ); - } + test declaration + { + Bu::String sXml(" "); + Bu::MemBuf buf( sXml ); + Bu::XmlReader xr( buf ); + } } -- cgit v1.2.3