aboutsummaryrefslogtreecommitdiff
path: root/src/unit/archive.unit
blob: ecc589bb57f8d772eea9e55db9a03a4bf306f145 (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
// 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"

{=Init}

{%testPrimitives}
{
	Bu::MemBuf mb;
	{
		Bu::Archive ar( mb, Bu::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 );
	{
		Bu::Archive ar( mb, Bu::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();
	}
}

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