From 509d136e9adb60c56369565b9545e613cac3678e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 12 Nov 2009 17:05:30 +0000 Subject: I've started my campaign to clean up all of the header files in libbu++ as far as includes go. This required a little bit of reworking as far as archive goes, but I've been planning on changing it aronud for a bit anyway. The final result here is that you may need to add some more includes in your own code, libbu++ doesn't include as many random things you didn't ask for anymore, most of these seem to be bu/hash.h, unistd.h, and time.h. Also, any Archive functions and operators should use ArchiveBase when they can instead of Archive, archivebase.h is a much lighterweight include that will be used everywhere in core that it can be, there are a few classes that actually want a specific archiver to be used, they will use it (such as the nids storage class). So far, except for adding header files, nothing has changed in functionality, and no other code changes should be required, although the above mentioned archive changeover is reccomended. --- src/unit/archive.unit | 89 ++++++++++++++++++++++++++++++++++++++++++++------- src/unit/file.unit | 2 +- src/unit/fstring.unit | 21 ++++++++++++ src/unit/list.unit | 80 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 179 insertions(+), 13 deletions(-) (limited to 'src/unit') diff --git a/src/unit/archive.unit b/src/unit/archive.unit index ecc589b..266784f 100644 --- a/src/unit/archive.unit +++ b/src/unit/archive.unit @@ -7,14 +7,18 @@ */ #include "bu/membuf.h" +#include "bu/array.h" +#include "bu/archive.h" + +using namespace Bu; {=Init} {%testPrimitives} { - Bu::MemBuf mb; + MemBuf mb; { - Bu::Archive ar( mb, Bu::Archive::save ); + Archive ar( mb, Archive::save ); ar << (int8_t)1; ar << (uint8_t)2; ar << (int16_t)3; @@ -37,7 +41,7 @@ } mb.setPos( 0 ); { - Bu::Archive ar( mb, Bu::Archive::load ); + Archive ar( mb, Archive::load ); int8_t p1; uint8_t p2; int16_t p3; @@ -96,13 +100,13 @@ } } -{%testContainers} +{%testContainers1} { - Bu::MemBuf mb; + MemBuf mb; { - Bu::Archive ar( mb, Bu::Archive::save ); - Bu::FString sStr("This is a test string."); - Bu::List lList; + Archive ar( mb, Archive::save ); + FString sStr("This is a test string."); + List lList; lList.append( 10 ); lList.append( 20 ); lList.append( 30 ); @@ -113,14 +117,47 @@ } mb.setPos( 0 ); { - Bu::Archive ar( mb, Bu::Archive::load ); - Bu::FString sStr; - Bu::List lList; + Archive ar( mb, Archive::load ); + FString sStr; + List lList; ar >> sStr; ar >> lList; unitTest( sStr == "This is a test string." ); unitTest( lList.getSize() == 4 ); - Bu::List::iterator i = lList.begin(); + 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 ); + { + 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++; @@ -128,3 +165,31 @@ 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 ); + { + 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/file.unit b/src/unit/file.unit index 911d8f6..e0d2005 100644 --- a/src/unit/file.unit +++ b/src/unit/file.unit @@ -16,7 +16,7 @@ {%writeFull} { - Bu::File sf("testfile1", Bu::File::Write ); + Bu::File sf("testfile1", Bu::File::WriteNew ); for( int c = 0; c < 256; c++ ) { unsigned char ch = (unsigned char)c; diff --git a/src/unit/fstring.unit b/src/unit/fstring.unit index 3e4456d..d218a07 100644 --- a/src/unit/fstring.unit +++ b/src/unit/fstring.unit @@ -312,3 +312,24 @@ bob = ""; unitTest( bob.isSet() == false ); } + +{%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" ); +} + diff --git a/src/unit/list.unit b/src/unit/list.unit index 9da0342..9f66f54 100644 --- a/src/unit/list.unit +++ b/src/unit/list.unit @@ -66,3 +66,83 @@ typedef Bu::List IntList; } } +{%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) ); +} + +{%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) ); +} + +{%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) ); +} + +{%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) ); +} + +{%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) ); +} + +{%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) ); +} + -- cgit v1.2.3