diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-01-07 15:59:57 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-01-07 15:59:57 +0000 |
commit | 45e065bc4fc93731ea9a0543462bc7cf9e6084d7 (patch) | |
tree | a9e8279fe00b9b01dc2393f59dc7f41b5e416b2a /src/unit/taf.cpp | |
parent | d96fe229e79f9b1947cbd24ff52d6bf7bb9bf80d (diff) | |
download | libbu++-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/taf.cpp')
-rw-r--r-- | src/unit/taf.cpp | 133 |
1 files changed, 0 insertions, 133 deletions
diff --git a/src/unit/taf.cpp b/src/unit/taf.cpp deleted file mode 100644 index e4b3ccc..0000000 --- a/src/unit/taf.cpp +++ /dev/null | |||
@@ -1,133 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libbu++ library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
8 | #include "bu/unitsuite.h" | ||
9 | #include "bu/file.h" | ||
10 | #include "bu/tafreader.h" | ||
11 | #include "bu/tafwriter.h" | ||
12 | #include "bu/membuf.h" | ||
13 | |||
14 | #include <string.h> | ||
15 | #include <unistd.h> | ||
16 | |||
17 | class Unit : public Bu::UnitSuite | ||
18 | { | ||
19 | public: | ||
20 | Unit() | ||
21 | { | ||
22 | setName("taf"); | ||
23 | addTest( Unit::read1 ); | ||
24 | addTest( Unit::encode1 ); | ||
25 | addTest( Unit::emptyStr1 ); | ||
26 | addTest( Unit::incomplete1 ); | ||
27 | } | ||
28 | |||
29 | virtual ~Unit() | ||
30 | { | ||
31 | } | ||
32 | |||
33 | void read1() | ||
34 | { | ||
35 | #define FN_TMP ("/tmp/tmpXXXXXXXX") | ||
36 | Bu::FString sFnTmp(FN_TMP); | ||
37 | Bu::File fOut = Bu::File::tempFile( sFnTmp ); | ||
38 | const char *data = | ||
39 | "{test: name=\"Bob\"}" | ||
40 | ; | ||
41 | fOut.write(data,strlen(data)); | ||
42 | fOut.close(); | ||
43 | |||
44 | Bu::File fIn(sFnTmp.getStr(), Bu::File::Read ); | ||
45 | Bu::TafReader tr(fIn); | ||
46 | |||
47 | Bu::TafGroup *tn = tr.readGroup(); | ||
48 | unitTest( !strcmp("Bob", tn->getProperty("name").getStr()) ); | ||
49 | delete tn; | ||
50 | |||
51 | unlink(sFnTmp.getStr()); | ||
52 | #undef FN_TMP | ||
53 | } | ||
54 | |||
55 | void encode1() | ||
56 | { | ||
57 | Bu::MemBuf mb; | ||
58 | Bu::TafWriter tw( mb ); | ||
59 | |||
60 | Bu::TafGroup g("Test data"); | ||
61 | Bu::FString sData( 256 ); | ||
62 | for( int j = 0; j < 256; j++ ) | ||
63 | sData[j] = (unsigned char)j; | ||
64 | g.addChild( new Bu::TafProperty("Encoded", sData) ); | ||
65 | tw.writeGroup( &g ); | ||
66 | |||
67 | static const char *cmpdata = "{\"Test data\":\n \"Encoded\"=\"" | ||
68 | "\\x00\\x01\\x02\\x03\\x04\\x05\\x06\\x07" | ||
69 | "\\x08\\x09\\x0A\\x0B\\x0C\\x0D\\x0E\\x0F" | ||
70 | "\\x10\\x11\\x12\\x13\\x14\\x15\\x16\\x17" | ||
71 | "\\x18\\x19\\x1A\\x1B\\x1C\\x1D\\x1E\\x1F" | ||
72 | " !\\\"#$%&'()*+,-./0123456789:;<=>?@ABCD" | ||
73 | "EFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghi" | ||
74 | "jklmnopqrstuvwxyz{|}~\\x7F" | ||
75 | "\\x80\\x81\\x82\\x83\\x84\\x85\\x86\\x87" | ||
76 | "\\x88\\x89\\x8A\\x8B\\x8C\\x8D\\x8E\\x8F" | ||
77 | "\\x90\\x91\\x92\\x93\\x94\\x95\\x96\\x97" | ||
78 | "\\x98\\x99\\x9A\\x9B\\x9C\\x9D\\x9E\\x9F" | ||
79 | "\\xA0\\xA1\\xA2\\xA3\\xA4\\xA5\\xA6\\xA7" | ||
80 | "\\xA8\\xA9\\xAA\\xAB\\xAC\\xAD\\xAE\\xAF" | ||
81 | "\\xB0\\xB1\\xB2\\xB3\\xB4\\xB5\\xB6\\xB7" | ||
82 | "\\xB8\\xB9\\xBA\\xBB\\xBC\\xBD\\xBE\\xBF" | ||
83 | "\\xC0\\xC1\\xC2\\xC3\\xC4\\xC5\\xC6\\xC7" | ||
84 | "\\xC8\\xC9\\xCA\\xCB\\xCC\\xCD\\xCE\\xCF" | ||
85 | "\\xD0\\xD1\\xD2\\xD3\\xD4\\xD5\\xD6\\xD7" | ||
86 | "\\xD8\\xD9\\xDA\\xDB\\xDC\\xDD\\xDE\\xDF" | ||
87 | "\\xE0\\xE1\\xE2\\xE3\\xE4\\xE5\\xE6\\xE7" | ||
88 | "\\xE8\\xE9\\xEA\\xEB\\xEC\\xED\\xEE\\xEF" | ||
89 | "\\xF0\\xF1\\xF2\\xF3\\xF4\\xF5\\xF6\\xF7" | ||
90 | "\\xF8\\xF9\\xFA\\xFB\\xFC\\xFD\\xFE\\xFF\"\n}\n"; | ||
91 | unitTest( mb.getString() == cmpdata ); | ||
92 | mb.setPos( 0 ); | ||
93 | Bu::TafReader tr( mb ); | ||
94 | Bu::TafGroup *rg = tr.readGroup(); | ||
95 | unitTest( rg->getProperty("Encoded") == sData ); | ||
96 | delete rg; | ||
97 | } | ||
98 | |||
99 | void emptyStr1() | ||
100 | { | ||
101 | Bu::MemBuf mb; | ||
102 | Bu::TafWriter tw( mb ); | ||
103 | |||
104 | Bu::TafGroup g("Test Group"); | ||
105 | Bu::FString sVal; | ||
106 | g.addChild( new Bu::TafProperty("Lame", sVal) ); | ||
107 | tw.writeGroup( &g ); | ||
108 | |||
109 | unitTest( | ||
110 | mb.getString() == "{\"Test Group\":\n \"Lame\"=\"\"\n}\n" ); | ||
111 | } | ||
112 | |||
113 | void incomplete1() | ||
114 | { | ||
115 | try | ||
116 | { | ||
117 | Bu::MemBuf mb("{Lame: \"Hello=\""); | ||
118 | Bu::TafReader tr( mb ); | ||
119 | delete tr.readGroup(); | ||
120 | unitFailed("Should have thrown an exception, didn't."); | ||
121 | } | ||
122 | catch( Bu::TafException &e ) | ||
123 | { | ||
124 | // Woot | ||
125 | } | ||
126 | } | ||
127 | }; | ||
128 | |||
129 | int main( int argc, char *argv[] ) | ||
130 | { | ||
131 | return Unit().run( argc, argv ); | ||
132 | } | ||
133 | |||