diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-08-19 06:28:17 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-08-19 06:28:17 +0000 |
commit | 11b5a91c5884d496744911f261ed6c2b053b9940 (patch) | |
tree | 61ed65f187e0719f141d80d4e1e648aeff311024 /src/unit | |
parent | 9dc8cc535ef5fc4ea78f967fe285fe4424ff4458 (diff) | |
download | libgats-11b5a91c5884d496744911f261ed6c2b053b9940.tar.gz libgats-11b5a91c5884d496744911f261ed6c2b053b9940.tar.bz2 libgats-11b5a91c5884d496744911f261ed6c2b053b9940.tar.xz libgats-11b5a91c5884d496744911f261ed6c2b053b9940.zip |
Wow, it pretty much all works. the float format is a little funny, I treat it
as a string, with a string header and then string data that is then turned into
a float. It's pretty much how it's going to work, unless I come up with
something revolutionary.
Diffstat (limited to 'src/unit')
-rw-r--r-- | src/unit/basic.unit | 19 | ||||
-rw-r--r-- | src/unit/io.unit | 127 |
2 files changed, 146 insertions, 0 deletions
diff --git a/src/unit/basic.unit b/src/unit/basic.unit index 744d679..d0309ee 100644 --- a/src/unit/basic.unit +++ b/src/unit/basic.unit | |||
@@ -18,6 +18,7 @@ | |||
18 | #include "bu/sio.h" | 18 | #include "bu/sio.h" |
19 | 19 | ||
20 | #include <stdlib.h> | 20 | #include <stdlib.h> |
21 | #include <math.h> | ||
21 | 22 | ||
22 | using namespace Bu; | 23 | using namespace Bu; |
23 | 24 | ||
@@ -120,6 +121,24 @@ suite Basic | |||
120 | } | 121 | } |
121 | } | 122 | } |
122 | 123 | ||
124 | test floats | ||
125 | { | ||
126 | Bu::MemBuf mb; | ||
127 | |||
128 | Gats::Float( M_PI ).write( mb ); | ||
129 | |||
130 | mb.setPos( 0 ); | ||
131 | |||
132 | Gats::Object *pObj = Gats::Object::read( mb ); | ||
133 | unitTest( pObj != NULL ); | ||
134 | unitTest( pObj->getType() == Gats::typeFloat ); | ||
135 | Gats::Float *pFlt = dynamic_cast<Gats::Float *>(pObj); | ||
136 | sio << "old = " << M_PI << ", new = " << pFlt->getValue() << sio.nl; | ||
137 | unitTest( pFlt->getValue() == M_PI ); | ||
138 | |||
139 | delete pObj; | ||
140 | } | ||
141 | |||
123 | test dictionary | 142 | test dictionary |
124 | { | 143 | { |
125 | MemBuf mb; | 144 | MemBuf mb; |
diff --git a/src/unit/io.unit b/src/unit/io.unit new file mode 100644 index 0000000..3e9c82c --- /dev/null +++ b/src/unit/io.unit | |||
@@ -0,0 +1,127 @@ | |||
1 | // vim: syntax=cpp | ||
2 | /* | ||
3 | * Copyright (C) 2007-2010 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 "gats/dictionary.h" | ||
10 | #include "gats/integer.h" | ||
11 | #include "gats/float.h" | ||
12 | #include "gats/list.h" | ||
13 | #include "gats/boolean.h" | ||
14 | #include "gats/string.h" | ||
15 | #include "gats/gatsstream.h" | ||
16 | |||
17 | #include "bu/membuf.h" | ||
18 | #include "bu/list.h" | ||
19 | #include "bu/sio.h" | ||
20 | |||
21 | #include <stdlib.h> | ||
22 | |||
23 | using namespace Bu; | ||
24 | |||
25 | suite Basic | ||
26 | { | ||
27 | test basic | ||
28 | { | ||
29 | Bu::FString sTmpFileName("temp-XXXXXXXXX"); | ||
30 | Bu::File fIo = tempFile( sTmpFileName ); | ||
31 | |||
32 | { | ||
33 | Gats::Dictionary dTest; | ||
34 | dTest.insert("age", 27 ); | ||
35 | dTest.insert("firstName", "Mike"); | ||
36 | dTest.insert("lastName", "Buland"); | ||
37 | dTest.insert("awake", true ); | ||
38 | |||
39 | Gats::GatsStream sGats( fIo ); | ||
40 | sGats.writeObject( &dTest ); | ||
41 | } | ||
42 | |||
43 | fIo.setPos( 0 ); | ||
44 | |||
45 | { | ||
46 | Gats::GatsStream sGats( fIo ); | ||
47 | Gats::Object *pObj = sGats.readObject(); | ||
48 | unitTest( pObj != NULL ); | ||
49 | unitTest( pObj->getType() == Gats::typeDictionary ); | ||
50 | Gats::Dictionary *pDic = dynamic_cast<Gats::Dictionary *>(pObj); | ||
51 | unitTest( pDic->getSize() == 4 ); | ||
52 | unitTest( pDic->getInt("age") == 27 ); | ||
53 | unitTest( pDic->getStr("firstName") == "Mike" ); | ||
54 | unitTest( pDic->getStr("lastName") == "Buland" ); | ||
55 | unitTest( pDic->getBool("awake") == true ); | ||
56 | |||
57 | delete pDic; | ||
58 | } | ||
59 | } | ||
60 | |||
61 | test spacers | ||
62 | { | ||
63 | Bu::FString sTmpFileName("temp-XXXXXXXXX"); | ||
64 | Bu::File fIo = tempFile( sTmpFileName ); | ||
65 | |||
66 | { | ||
67 | Gats::GatsStream sGats( fIo ); | ||
68 | Gats::Integer i( -157 ); | ||
69 | sGats.writeObject( &i ); | ||
70 | fIo.write( "\x00\x00\x00", 3 ); | ||
71 | Gats::String s("negative one hundred and fifty seven"); | ||
72 | sGats.writeObject( &s ); | ||
73 | } | ||
74 | |||
75 | fIo.setPos( 0 ); | ||
76 | |||
77 | { | ||
78 | Gats::GatsStream sGats( fIo ); | ||
79 | Gats::Object *pObj1 = sGats.readObject(); | ||
80 | unitTest( pObj1 != NULL ); | ||
81 | unitTest( pObj1->getType() == Gats::typeInteger ); | ||
82 | unitTest( dynamic_cast<Gats::Integer *>(pObj1)->getValue() == -157 ); | ||
83 | |||
84 | Gats::Object *pObj2 = sGats.readObject(); | ||
85 | unitTest( pObj2 != NULL ); | ||
86 | unitTest( pObj2->getType() == Gats::typeString ); | ||
87 | unitTest( *dynamic_cast<Gats::String *>(pObj2) == | ||
88 | "negative one hundred and fifty seven" ); | ||
89 | |||
90 | delete pObj1; | ||
91 | delete pObj2; | ||
92 | } | ||
93 | } | ||
94 | test biggerSpacers | ||
95 | { | ||
96 | Bu::FString sTmpFileName("temp-XXXXXXXXX"); | ||
97 | Bu::File fIo = tempFile( sTmpFileName ); | ||
98 | |||
99 | { | ||
100 | Gats::GatsStream sGats( fIo ); | ||
101 | Gats::Integer i( -157 ); | ||
102 | sGats.writeObject( &i ); | ||
103 | fIo.write( "\x00\x00\x00\x00\x00\x00\x00\x00\x00", 9 ); | ||
104 | Gats::String s("negative one hundred and fifty seven"); | ||
105 | sGats.writeObject( &s ); | ||
106 | } | ||
107 | |||
108 | fIo.setPos( 0 ); | ||
109 | |||
110 | { | ||
111 | Gats::GatsStream sGats( fIo ); | ||
112 | Gats::Object *pObj1 = sGats.readObject(); | ||
113 | unitTest( pObj1 != NULL ); | ||
114 | unitTest( pObj1->getType() == Gats::typeInteger ); | ||
115 | unitTest( dynamic_cast<Gats::Integer *>(pObj1)->getValue() == -157 ); | ||
116 | |||
117 | Gats::Object *pObj2 = sGats.readObject(); | ||
118 | unitTest( pObj2 != NULL ); | ||
119 | unitTest( pObj2->getType() == Gats::typeString ); | ||
120 | unitTest( *dynamic_cast<Gats::String *>(pObj2) == | ||
121 | "negative one hundred and fifty seven" ); | ||
122 | |||
123 | delete pObj1; | ||
124 | delete pObj2; | ||
125 | } | ||
126 | } | ||
127 | } | ||