summaryrefslogtreecommitdiff
path: root/src/unit/archive.unit
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-11-12 17:05:30 +0000
committerMike Buland <eichlan@xagasoft.com>2009-11-12 17:05:30 +0000
commit509d136e9adb60c56369565b9545e613cac3678e (patch)
treef118d676edeae2d5e17f48b32b180d4761b60520 /src/unit/archive.unit
parent3166bd631a093f42ea44a4b0f4d914cf51518bd4 (diff)
downloadlibbu++-509d136e9adb60c56369565b9545e613cac3678e.tar.gz
libbu++-509d136e9adb60c56369565b9545e613cac3678e.tar.bz2
libbu++-509d136e9adb60c56369565b9545e613cac3678e.tar.xz
libbu++-509d136e9adb60c56369565b9545e613cac3678e.zip
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.
Diffstat (limited to 'src/unit/archive.unit')
-rw-r--r--src/unit/archive.unit89
1 files changed, 77 insertions, 12 deletions
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 @@
7 */ 7 */
8 8
9#include "bu/membuf.h" 9#include "bu/membuf.h"
10#include "bu/array.h"
11#include "bu/archive.h"
12
13using namespace Bu;
10 14
11{=Init} 15{=Init}
12 16
13{%testPrimitives} 17{%testPrimitives}
14{ 18{
15 Bu::MemBuf mb; 19 MemBuf mb;
16 { 20 {
17 Bu::Archive ar( mb, Bu::Archive::save ); 21 Archive ar( mb, Archive::save );
18 ar << (int8_t)1; 22 ar << (int8_t)1;
19 ar << (uint8_t)2; 23 ar << (uint8_t)2;
20 ar << (int16_t)3; 24 ar << (int16_t)3;
@@ -37,7 +41,7 @@
37 } 41 }
38 mb.setPos( 0 ); 42 mb.setPos( 0 );
39 { 43 {
40 Bu::Archive ar( mb, Bu::Archive::load ); 44 Archive ar( mb, Archive::load );
41 int8_t p1; 45 int8_t p1;
42 uint8_t p2; 46 uint8_t p2;
43 int16_t p3; 47 int16_t p3;
@@ -96,13 +100,13 @@
96 } 100 }
97} 101}
98 102
99{%testContainers} 103{%testContainers1}
100{ 104{
101 Bu::MemBuf mb; 105 MemBuf mb;
102 { 106 {
103 Bu::Archive ar( mb, Bu::Archive::save ); 107 Archive ar( mb, Archive::save );
104 Bu::FString sStr("This is a test string."); 108 FString sStr("This is a test string.");
105 Bu::List<int> lList; 109 List<int> lList;
106 lList.append( 10 ); 110 lList.append( 10 );
107 lList.append( 20 ); 111 lList.append( 20 );
108 lList.append( 30 ); 112 lList.append( 30 );
@@ -113,14 +117,47 @@
113 } 117 }
114 mb.setPos( 0 ); 118 mb.setPos( 0 );
115 { 119 {
116 Bu::Archive ar( mb, Bu::Archive::load ); 120 Archive ar( mb, Archive::load );
117 Bu::FString sStr; 121 FString sStr;
118 Bu::List<int> lList; 122 List<int> lList;
119 ar >> sStr; 123 ar >> sStr;
120 ar >> lList; 124 ar >> lList;
121 unitTest( sStr == "This is a test string." ); 125 unitTest( sStr == "This is a test string." );
122 unitTest( lList.getSize() == 4 ); 126 unitTest( lList.getSize() == 4 );
123 Bu::List<int>::iterator i = lList.begin(); 127 List<int>::iterator i = lList.begin();
128 unitTest( *i == 10 ); i++;
129 unitTest( *i == 20 ); i++;
130 unitTest( *i == 30 ); i++;
131 unitTest( *i == 40 );
132 ar.close();
133 }
134}
135
136{%testContainers2}
137{
138 MemBuf mb;
139 {
140 Archive ar( mb, Archive::save );
141 FString sStr("This is a test string.");
142 Array<int> lArray;
143 lArray.append( 10 );
144 lArray.append( 20 );
145 lArray.append( 30 );
146 lArray.append( 40 );
147 ar << sStr;
148 ar << lArray;
149 ar.close();
150 }
151 mb.setPos( 0 );
152 {
153 Archive ar( mb, Archive::load );
154 FString sStr;
155 Array<int> lArray;
156 ar >> sStr;
157 ar >> lArray;
158 unitTest( sStr == "This is a test string." );
159 unitTest( lArray.getSize() == 4 );
160 Array<int>::iterator i = lArray.begin();
124 unitTest( *i == 10 ); i++; 161 unitTest( *i == 10 ); i++;
125 unitTest( *i == 20 ); i++; 162 unitTest( *i == 20 ); i++;
126 unitTest( *i == 30 ); i++; 163 unitTest( *i == 30 ); i++;
@@ -128,3 +165,31 @@
128 ar.close(); 165 ar.close();
129 } 166 }
130} 167}
168
169{%testContainers3}
170{
171 MemBuf mb;
172 {
173 Archive ar( mb, Archive::save );
174 Array<FString> lArray;
175 lArray.append( "10" );
176 lArray.append( "20" );
177 lArray.append( "30" );
178 lArray.append( "40" );
179 ar << lArray;
180 ar.close();
181 }
182 mb.setPos( 0 );
183 {
184 Archive ar( mb, Archive::load );
185 Array<FString> lArray;
186 ar >> lArray;
187 unitTest( lArray.getSize() == 4 );
188 Array<FString>::iterator i = lArray.begin();
189 unitTest( *i == "10" ); i++;
190 unitTest( *i == "20" ); i++;
191 unitTest( *i == "30" ); i++;
192 unitTest( *i == "40" );
193 ar.close();
194 }
195}