aboutsummaryrefslogtreecommitdiff
path: root/src/unit/archive.unit
blob: 266784f5e5d95f9ea050cad0c07369acc7b345b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
// vim: syntax=cpp
/*
 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
 *
 * This file is part of the libbu++ library and is released under the
 * terms of the license contained in the file LICENSE.
 */

#include "bu/membuf.h"
#include "bu/array.h"
#include "bu/archive.h"

using namespace Bu;

{=Init}

{%testPrimitives}
{
	MemBuf mb;
	{
		Archive ar( mb, Archive::save );
		ar << (int8_t)1;
		ar << (uint8_t)2;
		ar << (int16_t)3;
		ar << (uint16_t)4;
		ar << (int32_t)5;
		ar << (uint32_t)6;
		ar << (int64_t)7;
		ar << (uint64_t)8;
		ar << (char)9;
		ar << (unsigned char)10;
		ar << (short)11;
		ar << (unsigned short)12;
		ar << (int)13;
		ar << (unsigned int)14;
		ar << (long)15;
		ar << (unsigned long)16;
		ar << (long long)17;
		ar << (unsigned long long)18;
		ar.close();
	}
	mb.setPos( 0 );
	{
		Archive ar( mb, Archive::load );
		int8_t p1;
		uint8_t p2;
		int16_t p3;
		uint16_t p4;
		int32_t p5;
		uint32_t p6;
		int64_t p7;
		uint64_t p8;
		char p9;
		unsigned char p10;
		short p11;
		unsigned short p12;
		int p13;
		unsigned int p14;
		long p15;
		unsigned long p16;
		long long p17;
		unsigned long long p18;
		ar >> p1;
		ar >> p2;
		ar >> p3;
		ar >> p4;
		ar >> p5;
		ar >> p6;
		ar >> p7;
		ar >> p8;
		ar >> p9;
		ar >> p10;
		ar >> p11;
		ar >> p12;
		ar >> p13;
		ar >> p14;
		ar >> p15;
		ar >> p16;
		ar >> p17;
		ar >> p18;
		unitTest( p1 == 1 );
		unitTest( p2 == 2 );
		unitTest( p3 == 3 );
		unitTest( p4 == 4 );
		unitTest( p5 == 5 );
		unitTest( p6 == 6 );
		unitTest( p7 == 7 );
		unitTest( p8 == 8 );
		unitTest( p9 == 9 );
		unitTest( p10 == 10 );
		unitTest( p11 == 11 );
		unitTest( p12 == 12 );
		unitTest( p13 == 13 );
		unitTest( p14 == 14 );
		unitTest( p15 == 15 );
		unitTest( p16 == 16 );
		unitTest( p17 == 17 );
		unitTest( p18 == 18 );
		ar.close();
	}
}

{%testContainers1}
{
	MemBuf mb;
	{
		Archive ar( mb, Archive::save );
		FString sStr("This is a test string.");
		List<int> lList;
		lList.append( 10 );
		lList.append( 20 );
		lList.append( 30 );
		lList.append( 40 );
		ar << sStr;
		ar << lList;
		ar.close();
	}
	mb.setPos( 0 );
	{
		Archive ar( mb, Archive::load );
		FString sStr;
		List<int> lList;
		ar >> sStr;
		ar >> lList;
		unitTest( sStr == "This is a test string." );
		unitTest( lList.getSize() == 4 );
		List<int>::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<int> 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<int> lArray;
		ar >> sStr;
		ar >> lArray;
		unitTest( sStr == "This is a test string." );
		unitTest( lArray.getSize() == 4 );
		Array<int>::iterator i = lArray.begin();
		unitTest( *i == 10 ); i++;
		unitTest( *i == 20 ); i++;
		unitTest( *i == 30 ); i++;
		unitTest( *i == 40 );
		ar.close();
	}
}

{%testContainers3}
{
	MemBuf mb;
	{
		Archive ar( mb, Archive::save );
		Array<FString> 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<FString> lArray;
		ar >> lArray;
		unitTest( lArray.getSize() == 4 );
		Array<FString>::iterator i = lArray.begin();
		unitTest( *i == "10" ); i++;
		unitTest( *i == "20" ); i++;
		unitTest( *i == "30" ); i++;
		unitTest( *i == "40" );
		ar.close();
	}
}