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 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 12 deletions(-) (limited to 'src/unit/archive.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(); + } +} -- cgit v1.2.3