aboutsummaryrefslogtreecommitdiff
path: root/src/unit
diff options
context:
space:
mode:
Diffstat (limited to 'src/unit')
-rw-r--r--src/unit/archive.unit89
-rw-r--r--src/unit/file.unit2
-rw-r--r--src/unit/fstring.unit21
-rw-r--r--src/unit/list.unit80
4 files changed, 179 insertions, 13 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}
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 @@
16 16
17{%writeFull} 17{%writeFull}
18{ 18{
19 Bu::File sf("testfile1", Bu::File::Write ); 19 Bu::File sf("testfile1", Bu::File::WriteNew );
20 for( int c = 0; c < 256; c++ ) 20 for( int c = 0; c < 256; c++ )
21 { 21 {
22 unsigned char ch = (unsigned char)c; 22 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 @@
312 bob = ""; 312 bob = "";
313 unitTest( bob.isSet() == false ); 313 unitTest( bob.isSet() == false );
314} 314}
315
316{%swap1}
317{
318 Bu::FString a, b;
319 a = "Goodbye";
320 b = "Hello";
321 Bu::swap( a, b );
322 unitTest( a == "Hello" );
323 unitTest( b == "Goodbye" );
324}
325
326{%swap2}
327{
328 Bu::FString a, b;
329 a = "Goodbye";
330 b = "Hello";
331 std::swap( a, b );
332 unitTest( a == "Hello" );
333 unitTest( b == "Goodbye" );
334}
335
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<int> IntList;
66 } 66 }
67} 67}
68 68
69{%sort1}
70{
71 IntList lst;
72
73 lst.insertSorted( 5 );
74 lst.insertSorted( 1 );
75 lst.insertSorted( 10 );
76 lst.insertSorted( 3 );
77
78 unitTest( lst == IntList(1).append(3).append(5).append(10) );
79}
80
81{%sort2}
82{
83 IntList lst;
84
85 lst.insertSorted<Bu::__basicGTCmp<int> >( 5 );
86 lst.insertSorted<Bu::__basicGTCmp<int> >( 1 );
87 lst.insertSorted<Bu::__basicGTCmp<int> >( 10 );
88 lst.insertSorted<Bu::__basicGTCmp<int> >( 3 );
89
90 unitTest( lst == IntList(10).append(5).append(3).append(1) );
91}
92
93{%sort3}
94{
95 IntList lst;
96 Bu::__basicGTCmp<int> cmp;
97
98 lst.insertSorted( cmp, 5 );
99 lst.insertSorted( cmp, 1 );
100 lst.insertSorted( cmp, 10 );
101 lst.insertSorted( cmp, 3 );
102
103 unitTest( lst == IntList(10).append(5).append(3).append(1) );
104}
105
106{%sort4}
107{
108 IntList lst;
109
110 lst.append( 5 );
111 lst.append( 1 );
112 lst.append( 10 );
113 lst.append( 3 );
114
115 lst.sort();
116
117 unitTest( lst == IntList(1).append(3).append(5).append(10) );
118}
119
120{%sort5}
121{
122 IntList lst;
123
124 lst.append( 5 );
125 lst.append( 1 );
126 lst.append( 10 );
127 lst.append( 3 );
128
129 lst.sort<Bu::__basicGTCmp<int> >();
130
131 unitTest( lst == IntList(10).append(5).append(3).append(1) );
132}
133
134{%sort6}
135{
136 IntList lst;
137
138 lst.append( 5 );
139 lst.append( 1 );
140 lst.append( 10 );
141 lst.append( 3 );
142
143 Bu::__basicGTCmp<int> x;
144 lst.sort( x );
145
146 unitTest( lst == IntList(10).append(5).append(3).append(1) );
147}
148