diff options
Diffstat (limited to '')
-rw-r--r-- | src/unit/archive.unit | 352 |
1 files changed, 176 insertions, 176 deletions
diff --git a/src/unit/archive.unit b/src/unit/archive.unit index 359f380..d0427a5 100644 --- a/src/unit/archive.unit +++ b/src/unit/archive.unit | |||
@@ -14,183 +14,183 @@ using namespace Bu; | |||
14 | 14 | ||
15 | suite Archive | 15 | suite Archive |
16 | { | 16 | { |
17 | test primitives | 17 | test primitives |
18 | { | 18 | { |
19 | MemBuf mb; | 19 | MemBuf mb; |
20 | { | 20 | { |
21 | Archive ar( mb, Archive::save ); | 21 | Archive ar( mb, Archive::save ); |
22 | ar << (int8_t)1; | 22 | ar << (int8_t)1; |
23 | ar << (uint8_t)2; | 23 | ar << (uint8_t)2; |
24 | ar << (int16_t)3; | 24 | ar << (int16_t)3; |
25 | ar << (uint16_t)4; | 25 | ar << (uint16_t)4; |
26 | ar << (int32_t)5; | 26 | ar << (int32_t)5; |
27 | ar << (uint32_t)6; | 27 | ar << (uint32_t)6; |
28 | ar << (int64_t)7; | 28 | ar << (int64_t)7; |
29 | ar << (uint64_t)8; | 29 | ar << (uint64_t)8; |
30 | ar << (char)9; | 30 | ar << (char)9; |
31 | ar << (unsigned char)10; | 31 | ar << (unsigned char)10; |
32 | ar << (short)11; | 32 | ar << (short)11; |
33 | ar << (unsigned short)12; | 33 | ar << (unsigned short)12; |
34 | ar << (int)13; | 34 | ar << (int)13; |
35 | ar << (unsigned int)14; | 35 | ar << (unsigned int)14; |
36 | ar << (long)15; | 36 | ar << (long)15; |
37 | ar << (unsigned long)16; | 37 | ar << (unsigned long)16; |
38 | ar << (long long)17; | 38 | ar << (long long)17; |
39 | ar << (unsigned long long)18; | 39 | ar << (unsigned long long)18; |
40 | ar.close(); | 40 | ar.close(); |
41 | } | 41 | } |
42 | mb.setPos( 0 ); | 42 | mb.setPos( 0 ); |
43 | { | 43 | { |
44 | Archive ar( mb, Archive::load ); | 44 | Archive ar( mb, Archive::load ); |
45 | int8_t p1; | 45 | int8_t p1; |
46 | uint8_t p2; | 46 | uint8_t p2; |
47 | int16_t p3; | 47 | int16_t p3; |
48 | uint16_t p4; | 48 | uint16_t p4; |
49 | int32_t p5; | 49 | int32_t p5; |
50 | uint32_t p6; | 50 | uint32_t p6; |
51 | int64_t p7; | 51 | int64_t p7; |
52 | uint64_t p8; | 52 | uint64_t p8; |
53 | char p9; | 53 | char p9; |
54 | unsigned char p10; | 54 | unsigned char p10; |
55 | short p11; | 55 | short p11; |
56 | unsigned short p12; | 56 | unsigned short p12; |
57 | int p13; | 57 | int p13; |
58 | unsigned int p14; | 58 | unsigned int p14; |
59 | long p15; | 59 | long p15; |
60 | unsigned long p16; | 60 | unsigned long p16; |
61 | long long p17; | 61 | long long p17; |
62 | unsigned long long p18; | 62 | unsigned long long p18; |
63 | ar >> p1; | 63 | ar >> p1; |
64 | ar >> p2; | 64 | ar >> p2; |
65 | ar >> p3; | 65 | ar >> p3; |
66 | ar >> p4; | 66 | ar >> p4; |
67 | ar >> p5; | 67 | ar >> p5; |
68 | ar >> p6; | 68 | ar >> p6; |
69 | ar >> p7; | 69 | ar >> p7; |
70 | ar >> p8; | 70 | ar >> p8; |
71 | ar >> p9; | 71 | ar >> p9; |
72 | ar >> p10; | 72 | ar >> p10; |
73 | ar >> p11; | 73 | ar >> p11; |
74 | ar >> p12; | 74 | ar >> p12; |
75 | ar >> p13; | 75 | ar >> p13; |
76 | ar >> p14; | 76 | ar >> p14; |
77 | ar >> p15; | 77 | ar >> p15; |
78 | ar >> p16; | 78 | ar >> p16; |
79 | ar >> p17; | 79 | ar >> p17; |
80 | ar >> p18; | 80 | ar >> p18; |
81 | unitTest( p1 == 1 ); | 81 | unitTest( p1 == 1 ); |
82 | unitTest( p2 == 2 ); | 82 | unitTest( p2 == 2 ); |
83 | unitTest( p3 == 3 ); | 83 | unitTest( p3 == 3 ); |
84 | unitTest( p4 == 4 ); | 84 | unitTest( p4 == 4 ); |
85 | unitTest( p5 == 5 ); | 85 | unitTest( p5 == 5 ); |
86 | unitTest( p6 == 6 ); | 86 | unitTest( p6 == 6 ); |
87 | unitTest( p7 == 7 ); | 87 | unitTest( p7 == 7 ); |
88 | unitTest( p8 == 8 ); | 88 | unitTest( p8 == 8 ); |
89 | unitTest( p9 == 9 ); | 89 | unitTest( p9 == 9 ); |
90 | unitTest( p10 == 10 ); | 90 | unitTest( p10 == 10 ); |
91 | unitTest( p11 == 11 ); | 91 | unitTest( p11 == 11 ); |
92 | unitTest( p12 == 12 ); | 92 | unitTest( p12 == 12 ); |
93 | unitTest( p13 == 13 ); | 93 | unitTest( p13 == 13 ); |
94 | unitTest( p14 == 14 ); | 94 | unitTest( p14 == 14 ); |
95 | unitTest( p15 == 15 ); | 95 | unitTest( p15 == 15 ); |
96 | unitTest( p16 == 16 ); | 96 | unitTest( p16 == 16 ); |
97 | unitTest( p17 == 17 ); | 97 | unitTest( p17 == 17 ); |
98 | unitTest( p18 == 18 ); | 98 | unitTest( p18 == 18 ); |
99 | ar.close(); | 99 | ar.close(); |
100 | } | 100 | } |
101 | } | 101 | } |
102 | 102 | ||
103 | test containers1 | 103 | test containers1 |
104 | { | 104 | { |
105 | MemBuf mb; | 105 | MemBuf mb; |
106 | { | 106 | { |
107 | Archive ar( mb, Archive::save ); | 107 | Archive ar( mb, Archive::save ); |
108 | String sStr("This is a test string."); | 108 | String sStr("This is a test string."); |
109 | List<int> lList; | 109 | List<int> lList; |
110 | lList.append( 10 ); | 110 | lList.append( 10 ); |
111 | lList.append( 20 ); | 111 | lList.append( 20 ); |
112 | lList.append( 30 ); | 112 | lList.append( 30 ); |
113 | lList.append( 40 ); | 113 | lList.append( 40 ); |
114 | ar << sStr; | 114 | ar << sStr; |
115 | ar << lList; | 115 | ar << lList; |
116 | ar.close(); | 116 | ar.close(); |
117 | } | 117 | } |
118 | mb.setPos( 0 ); | 118 | mb.setPos( 0 ); |
119 | { | 119 | { |
120 | Archive ar( mb, Archive::load ); | 120 | Archive ar( mb, Archive::load ); |
121 | String sStr; | 121 | String sStr; |
122 | List<int> lList; | 122 | List<int> lList; |
123 | ar >> sStr; | 123 | ar >> sStr; |
124 | ar >> lList; | 124 | ar >> lList; |
125 | unitTest( sStr == "This is a test string." ); | 125 | unitTest( sStr == "This is a test string." ); |
126 | unitTest( lList.getSize() == 4 ); | 126 | unitTest( lList.getSize() == 4 ); |
127 | List<int>::iterator i = lList.begin(); | 127 | List<int>::iterator i = lList.begin(); |
128 | unitTest( *i == 10 ); i++; | 128 | unitTest( *i == 10 ); i++; |
129 | unitTest( *i == 20 ); i++; | 129 | unitTest( *i == 20 ); i++; |
130 | unitTest( *i == 30 ); i++; | 130 | unitTest( *i == 30 ); i++; |
131 | unitTest( *i == 40 ); | 131 | unitTest( *i == 40 ); |
132 | ar.close(); | 132 | ar.close(); |
133 | } | 133 | } |
134 | } | 134 | } |
135 | 135 | ||
136 | test containers2 | 136 | test containers2 |
137 | { | 137 | { |
138 | MemBuf mb; | 138 | MemBuf mb; |
139 | { | 139 | { |
140 | Archive ar( mb, Archive::save ); | 140 | Archive ar( mb, Archive::save ); |
141 | String sStr("This is a test string."); | 141 | String sStr("This is a test string."); |
142 | Array<int> lArray; | 142 | Array<int> lArray; |
143 | lArray.append( 10 ); | 143 | lArray.append( 10 ); |
144 | lArray.append( 20 ); | 144 | lArray.append( 20 ); |
145 | lArray.append( 30 ); | 145 | lArray.append( 30 ); |
146 | lArray.append( 40 ); | 146 | lArray.append( 40 ); |
147 | ar << sStr; | 147 | ar << sStr; |
148 | ar << lArray; | 148 | ar << lArray; |
149 | ar.close(); | 149 | ar.close(); |
150 | } | 150 | } |
151 | mb.setPos( 0 ); | 151 | mb.setPos( 0 ); |
152 | { | 152 | { |
153 | Archive ar( mb, Archive::load ); | 153 | Archive ar( mb, Archive::load ); |
154 | String sStr; | 154 | String sStr; |
155 | Array<int> lArray; | 155 | Array<int> lArray; |
156 | ar >> sStr; | 156 | ar >> sStr; |
157 | ar >> lArray; | 157 | ar >> lArray; |
158 | unitTest( sStr == "This is a test string." ); | 158 | unitTest( sStr == "This is a test string." ); |
159 | unitTest( lArray.getSize() == 4 ); | 159 | unitTest( lArray.getSize() == 4 ); |
160 | Array<int>::iterator i = lArray.begin(); | 160 | Array<int>::iterator i = lArray.begin(); |
161 | unitTest( *i == 10 ); i++; | 161 | unitTest( *i == 10 ); i++; |
162 | unitTest( *i == 20 ); i++; | 162 | unitTest( *i == 20 ); i++; |
163 | unitTest( *i == 30 ); i++; | 163 | unitTest( *i == 30 ); i++; |
164 | unitTest( *i == 40 ); | 164 | unitTest( *i == 40 ); |
165 | ar.close(); | 165 | ar.close(); |
166 | } | 166 | } |
167 | } | 167 | } |
168 | 168 | ||
169 | test containers3 | 169 | test containers3 |
170 | { | 170 | { |
171 | MemBuf mb; | 171 | MemBuf mb; |
172 | { | 172 | { |
173 | Archive ar( mb, Archive::save ); | 173 | Archive ar( mb, Archive::save ); |
174 | Array<String> lArray; | 174 | Array<String> lArray; |
175 | lArray.append( "10" ); | 175 | lArray.append( "10" ); |
176 | lArray.append( "20" ); | 176 | lArray.append( "20" ); |
177 | lArray.append( "30" ); | 177 | lArray.append( "30" ); |
178 | lArray.append( "40" ); | 178 | lArray.append( "40" ); |
179 | ar << lArray; | 179 | ar << lArray; |
180 | ar.close(); | 180 | ar.close(); |
181 | } | 181 | } |
182 | mb.setPos( 0 ); | 182 | mb.setPos( 0 ); |
183 | { | 183 | { |
184 | Archive ar( mb, Archive::load ); | 184 | Archive ar( mb, Archive::load ); |
185 | Array<String> lArray; | 185 | Array<String> lArray; |
186 | ar >> lArray; | 186 | ar >> lArray; |
187 | unitTest( lArray.getSize() == 4 ); | 187 | unitTest( lArray.getSize() == 4 ); |
188 | Array<String>::iterator i = lArray.begin(); | 188 | Array<String>::iterator i = lArray.begin(); |
189 | unitTest( *i == "10" ); i++; | 189 | unitTest( *i == "10" ); i++; |
190 | unitTest( *i == "20" ); i++; | 190 | unitTest( *i == "20" ); i++; |
191 | unitTest( *i == "30" ); i++; | 191 | unitTest( *i == "30" ); i++; |
192 | unitTest( *i == "40" ); | 192 | unitTest( *i == "40" ); |
193 | ar.close(); | 193 | ar.close(); |
194 | } | 194 | } |
195 | } | 195 | } |
196 | } | 196 | } |