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/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 +- 11 files changed, 966 insertions(+), 960 deletions(-) (limited to 'src/unit') 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