aboutsummaryrefslogtreecommitdiff
path: root/src/unit/archive.unit
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-01-07 15:59:57 +0000
committerMike Buland <eichlan@xagasoft.com>2009-01-07 15:59:57 +0000
commit45e065bc4fc93731ea9a0543462bc7cf9e6084d7 (patch)
treea9e8279fe00b9b01dc2393f59dc7f41b5e416b2a /src/unit/archive.unit
parentd96fe229e79f9b1947cbd24ff52d6bf7bb9bf80d (diff)
downloadlibbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.tar.gz
libbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.tar.bz2
libbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.tar.xz
libbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.zip
Only two real changes. First, Bu::FString and Bu::FBasicString are in different
files. This won't affect any programs at all anywhere. This will just make it easier to maintain and extend later. You still want to include "bu/fstring.h" and use Bu::FString in code. The other is kinda fun. I created a special format for unit tests, they use the extension .unit now and use the mkunit.sh script to convert them to c++ code. There are some nice features here too, maintaining unit tests is much, much easier, and we can have more features without making the code any harder to use. Also, it will be easier to have the unit tests generate reports and be run from a master program and the like.
Diffstat (limited to 'src/unit/archive.unit')
-rw-r--r--src/unit/archive.unit130
1 files changed, 130 insertions, 0 deletions
diff --git a/src/unit/archive.unit b/src/unit/archive.unit
new file mode 100644
index 0000000..ecc589b
--- /dev/null
+++ b/src/unit/archive.unit
@@ -0,0 +1,130 @@
1// vim: syntax=cpp
2/*
3 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
4 *
5 * This file is part of the libbu++ library and is released under the
6 * terms of the license contained in the file LICENSE.
7 */
8
9#include "bu/membuf.h"
10
11{=Init}
12
13{%testPrimitives}
14{
15 Bu::MemBuf mb;
16 {
17 Bu::Archive ar( mb, Bu::Archive::save );
18 ar << (int8_t)1;
19 ar << (uint8_t)2;
20 ar << (int16_t)3;
21 ar << (uint16_t)4;
22 ar << (int32_t)5;
23 ar << (uint32_t)6;
24 ar << (int64_t)7;
25 ar << (uint64_t)8;
26 ar << (char)9;
27 ar << (unsigned char)10;
28 ar << (short)11;
29 ar << (unsigned short)12;
30 ar << (int)13;
31 ar << (unsigned int)14;
32 ar << (long)15;
33 ar << (unsigned long)16;
34 ar << (long long)17;
35 ar << (unsigned long long)18;
36 ar.close();
37 }
38 mb.setPos( 0 );
39 {
40 Bu::Archive ar( mb, Bu::Archive::load );
41 int8_t p1;
42 uint8_t p2;
43 int16_t p3;
44 uint16_t p4;
45 int32_t p5;
46 uint32_t p6;
47 int64_t p7;
48 uint64_t p8;
49 char p9;
50 unsigned char p10;
51 short p11;
52 unsigned short p12;
53 int p13;
54 unsigned int p14;
55 long p15;
56 unsigned long p16;
57 long long p17;
58 unsigned long long p18;
59 ar >> p1;
60 ar >> p2;
61 ar >> p3;
62 ar >> p4;
63 ar >> p5;
64 ar >> p6;
65 ar >> p7;
66 ar >> p8;
67 ar >> p9;
68 ar >> p10;
69 ar >> p11;
70 ar >> p12;
71 ar >> p13;
72 ar >> p14;
73 ar >> p15;
74 ar >> p16;
75 ar >> p17;
76 ar >> p18;
77 unitTest( p1 == 1 );
78 unitTest( p2 == 2 );
79 unitTest( p3 == 3 );
80 unitTest( p4 == 4 );
81 unitTest( p5 == 5 );
82 unitTest( p6 == 6 );
83 unitTest( p7 == 7 );
84 unitTest( p8 == 8 );
85 unitTest( p9 == 9 );
86 unitTest( p10 == 10 );
87 unitTest( p11 == 11 );
88 unitTest( p12 == 12 );
89 unitTest( p13 == 13 );
90 unitTest( p14 == 14 );
91 unitTest( p15 == 15 );
92 unitTest( p16 == 16 );
93 unitTest( p17 == 17 );
94 unitTest( p18 == 18 );
95 ar.close();
96 }
97}
98
99{%testContainers}
100{
101 Bu::MemBuf mb;
102 {
103 Bu::Archive ar( mb, Bu::Archive::save );
104 Bu::FString sStr("This is a test string.");
105 Bu::List<int> lList;
106 lList.append( 10 );
107 lList.append( 20 );
108 lList.append( 30 );
109 lList.append( 40 );
110 ar << sStr;
111 ar << lList;
112 ar.close();
113 }
114 mb.setPos( 0 );
115 {
116 Bu::Archive ar( mb, Bu::Archive::load );
117 Bu::FString sStr;
118 Bu::List<int> lList;
119 ar >> sStr;
120 ar >> lList;
121 unitTest( sStr == "This is a test string." );
122 unitTest( lList.getSize() == 4 );
123 Bu::List<int>::iterator i = lList.begin();
124 unitTest( *i == 10 ); i++;
125 unitTest( *i == 20 ); i++;
126 unitTest( *i == 30 ); i++;
127 unitTest( *i == 40 );
128 ar.close();
129 }
130}