From a153962ffe93e70f2419efeab904b515c99c2eda Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 7 Jun 2008 07:00:09 +0000 Subject: Fixed the bugs in the archive system. Both the List container and FString had inconsistancies when archiving compared to their STL counterparts, they are now compatible on every system I can imagine. Also, List now uses a long instead of an int for sizing, and the other containers should as well. I'll check on that later. That means that the files will all be larger on a 64 bit system, but such is life. The same thing happens when you use STL classes. There may be other inconsistancies down the road, we'll see. --- src/archive.cpp | 5 +++-- src/archive.h | 12 ++++++------ src/list.h | 4 ++-- src/unit/archive.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++-------- 4 files changed, 53 insertions(+), 18 deletions(-) diff --git a/src/archive.cpp b/src/archive.cpp index accdeb1..90211fe 100644 --- a/src/archive.cpp +++ b/src/archive.cpp @@ -473,7 +473,8 @@ Bu::Archive &Bu::operator>>(Bu::Archive &ar, class Bu::Archival *p ) Bu::Archive &Bu::operator<<( Bu::Archive &ar, std::string &s ) { - ar << (uint32_t)s.length(); + // This should be defined as long anyway, this is just insurance + ar << (long)s.length(); ar.write( s.c_str(), s.length() ); return ar; @@ -481,7 +482,7 @@ Bu::Archive &Bu::operator<<( Bu::Archive &ar, std::string &s ) Bu::Archive &Bu::operator>>( Bu::Archive &ar, std::string &s ) { - uint32_t l; + long l; ar >> l; char *tmp = new char[l+1]; tmp[l] = '\0'; diff --git a/src/archive.h b/src/archive.h index 95c8c0c..1d57724 100644 --- a/src/archive.h +++ b/src/archive.h @@ -256,10 +256,10 @@ namespace Bu Archive &operator>>( Archive &ar, Hash &h ) { h.clear(); - uint32_t nSize; + long nSize; ar >> nSize; - for( uint32_t j = 0; j < nSize; j++ ) + for( long j = 0; j < nSize; j++ ) { key k; value v; ar >> k >> v; @@ -285,10 +285,10 @@ namespace Bu Archive &operator>>( Archive &ar, List &h ) { h.clear(); - uint32_t nSize; + long nSize; ar >> nSize; - for( uint32_t j = 0; j < nSize; j++ ) + for( long j = 0; j < nSize; j++ ) { value v; ar >> v; @@ -314,10 +314,10 @@ namespace Bu Archive &operator>>( Archive &ar, Set &h ) { h.clear(); - uint32_t nSize; + long nSize; ar >> nSize; - for( uint32_t j = 0; j < nSize; j++ ) + for( long j = 0; j < nSize; j++ ) { value v; ar >> v; diff --git a/src/list.h b/src/list.h index ed28e15..2a40013 100644 --- a/src/list.h +++ b/src/list.h @@ -535,7 +535,7 @@ namespace Bu * Get the current size of the list. *@returns (int) The current size of the list. */ - int getSize() const + long getSize() const { return nSize; } @@ -586,7 +586,7 @@ namespace Bu Link *pLast; linkalloc la; valuealloc va; - int nSize; + long nSize; cmpfunc cmp; }; } diff --git a/src/unit/archive.cpp b/src/unit/archive.cpp index 531ece1..8e71f4b 100644 --- a/src/unit/archive.cpp +++ b/src/unit/archive.cpp @@ -15,6 +15,7 @@ public: { setName("Archive"); addTest( Unit::testPrimitives ); + addTest( Unit::testContainers ); } virtual ~Unit() @@ -42,8 +43,8 @@ public: ar << (unsigned int)14; ar << (long)15; ar << (unsigned long)16; - //ar << (long long)17; - //ar << (unsigned long long)18; + ar << (long long)17; + ar << (unsigned long long)18; ar.close(); } mb.setPos( 0 ); @@ -65,8 +66,8 @@ public: unsigned int p14; long p15; unsigned long p16; - //long long p17; - //unsigned long long p18; + long long p17; + unsigned long long p18; ar >> p1; ar >> p2; ar >> p3; @@ -83,8 +84,8 @@ public: ar >> p14; ar >> p15; ar >> p16; - //ar >> p17; - //ar >> p18; + ar >> p17; + ar >> p18; unitTest( p1 == 1 ); unitTest( p2 == 2 ); unitTest( p3 == 3 ); @@ -101,8 +102,41 @@ public: unitTest( p14 == 14 ); unitTest( p15 == 15 ); unitTest( p16 == 16 ); - //unitTest( p17 == 17 ); - //unitTest( p18 == 18 ); + unitTest( p17 == 17 ); + unitTest( p18 == 18 ); + ar.close(); + } + } + + void testContainers() + { + Bu::MemBuf mb; + { + Bu::Archive ar( mb, Bu::Archive::save ); + Bu::FString sStr("This is a test string."); + Bu::List lList; + lList.append( 10 ); + lList.append( 20 ); + lList.append( 30 ); + lList.append( 40 ); + ar << sStr; + ar << lList; + ar.close(); + } + mb.setPos( 0 ); + { + Bu::Archive ar( mb, Bu::Archive::load ); + Bu::FString sStr; + Bu::List lList; + ar >> sStr; + ar >> lList; + unitTest( sStr == "This is a test string." ); + unitTest( lList.getSize() == 4 ); + Bu::List::iterator i = lList.begin(); + unitTest( *i == 10 ); i++; + unitTest( *i == 20 ); i++; + unitTest( *i == 30 ); i++; + unitTest( *i == 40 ); ar.close(); } } -- cgit v1.2.3