aboutsummaryrefslogtreecommitdiff
path: root/src/unit
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-08-14 07:12:29 +0000
committerMike Buland <eichlan@xagasoft.com>2010-08-14 07:12:29 +0000
commit1b797548dff7e2475826ba29a71c3f496008988f (patch)
tree2a81ee2e8fa2f17fd95410aabbf44533d35a727a /src/unit
downloadlibgats-1b797548dff7e2475826ba29a71c3f496008988f.tar.gz
libgats-1b797548dff7e2475826ba29a71c3f496008988f.tar.bz2
libgats-1b797548dff7e2475826ba29a71c3f496008988f.tar.xz
libgats-1b797548dff7e2475826ba29a71c3f496008988f.zip
libgats gets it's own repo. The rest of the history is in my misc repo.
Diffstat (limited to 'src/unit')
-rw-r--r--src/unit/basic.unit122
1 files changed, 122 insertions, 0 deletions
diff --git a/src/unit/basic.unit b/src/unit/basic.unit
new file mode 100644
index 0000000..9389c70
--- /dev/null
+++ b/src/unit/basic.unit
@@ -0,0 +1,122 @@
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
16#include "bu/membuf.h"
17#include "bu/list.h"
18#include "bu/sio.h"
19
20#include <stdlib.h>
21
22using namespace Bu;
23
24suite Basic
25{
26 test integer
27 {
28 Bu::List<int64_t> lInts;
29 Bu::MemBuf mb;
30
31 int64_t i = 1;
32 for( int x = 0; x < 256; x++ )
33 {
34 lInts.append( i );
35 Gats::Integer( i ).write( mb );
36 i = -(i<<1)-i;
37 }
38
39 mb.setPos( 0 );
40
41 for( Bu::List<int64_t>::iterator j = lInts.begin(); j; j++ )
42 {
43 Gats::Object *pObj = Gats::Object::read( mb );
44 if( pObj->getType() != Gats::typeInteger )
45 unitFailed("Bad type read.");
46
47 if( dynamic_cast<Gats::Integer *>(pObj)->getValue() != *j )
48 unitFailed("Bad number.");
49 }
50 }
51
52 test string
53 {
54 Bu::List<Bu::FString> lStrs;
55 Bu::MemBuf mb;
56
57 lStrs.append( Bu::FString() );
58 Gats::String("").write( mb );
59
60 {
61 int iMax = 0;
62 for( int j = 1; j <= (1<<16); j=j<<1 )
63 iMax += j;
64 setStepCount( iMax );
65 }
66 for( int j = 1; j <= (1<<16); j=j<<1 )
67 {
68 Bu::FString s( j );
69 for( int x = 0; x < j; x++ )
70 {
71 s[x] = (unsigned char)(random()%256);
72 }
73 incProgress( j );
74 Gats::String( s ).write( mb );
75 lStrs.append( s );
76 }
77
78 mb.setPos( 0 );
79
80 for( Bu::List<Bu::FString>::iterator i = lStrs.begin(); i; i++ )
81 {
82 Gats::Object *pObj = Gats::Object::read( mb );
83 if( pObj->getType() != Gats::typeString )
84 unitFailed("Bad type read.");
85
86 if( *dynamic_cast<Gats::String *>(pObj) != *i )
87 unitFailed("Bad string.");
88 }
89 }
90
91 test boolean
92 {
93 Bu::List<bool> lBs;
94 Bu::MemBuf mb;
95
96 for( int j = 0; j < 1024; j++ )
97 {
98 if( random()%2 == 0 )
99 {
100 lBs.append( true );
101 Gats::Boolean( true ).write( mb );
102 }
103 else
104 {
105 lBs.append( false );
106 Gats::Boolean( false ).write( mb );
107 }
108 }
109
110 mb.setPos( 0 );
111
112 for( Bu::List<bool>::iterator i = lBs.begin(); i; i++ )
113 {
114 Gats::Object *pObj = Gats::Object::read( mb );
115 if( pObj->getType() != Gats::typeBoolean )
116 unitFailed("Bad type read.");
117
118 if( dynamic_cast<Gats::Boolean *>(pObj)->getValue() != *i )
119 unitFailed("Bad string.");
120 }
121 }
122}