diff options
| author | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 16:25:22 +0000 |
|---|---|---|
| committer | Mike Buland <eichlan@xagasoft.com> | 2012-11-09 16:25:22 +0000 |
| commit | 74dd68ad611d15abf16a65c36a7cfd3f4492930a (patch) | |
| tree | 843fed9ba6bb03253a01314afc3b1dfbb2dfd26c /src/unit | |
| parent | d9b407475ae3ebe434b29d9eabdd7d4416e17881 (diff) | |
| download | libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.gz libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.bz2 libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.tar.xz libgats-74dd68ad611d15abf16a65c36a7cfd3f4492930a.zip | |
Made the repo less libbu++-centric.
Diffstat (limited to 'src/unit')
| -rw-r--r-- | src/unit/basic.unit | 191 | ||||
| -rw-r--r-- | src/unit/float.unit | 84 | ||||
| -rw-r--r-- | src/unit/io.unit | 128 |
3 files changed, 0 insertions, 403 deletions
diff --git a/src/unit/basic.unit b/src/unit/basic.unit deleted file mode 100644 index 2c2c31a..0000000 --- a/src/unit/basic.unit +++ /dev/null | |||
| @@ -1,191 +0,0 @@ | |||
| 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/null.h" | ||
| 16 | #include "gats/gatsstream.h" | ||
| 17 | |||
| 18 | #include "bu/membuf.h" | ||
| 19 | #include "bu/list.h" | ||
| 20 | #include "bu/sio.h" | ||
| 21 | |||
| 22 | #include <stdlib.h> | ||
| 23 | #include <math.h> | ||
| 24 | |||
| 25 | using namespace Bu; | ||
| 26 | |||
| 27 | suite Basic | ||
| 28 | { | ||
| 29 | test integer | ||
| 30 | { | ||
| 31 | Bu::List<int64_t> lInts; | ||
| 32 | Bu::MemBuf mb; | ||
| 33 | |||
| 34 | int64_t i = 1; | ||
| 35 | for( int x = 0; x < 256; x++ ) | ||
| 36 | { | ||
| 37 | lInts.append( i ); | ||
| 38 | Gats::Integer( i ).write( mb ); | ||
| 39 | i = -(i<<1)-i; | ||
| 40 | } | ||
| 41 | |||
| 42 | mb.setPos( 0 ); | ||
| 43 | |||
| 44 | for( Bu::List<int64_t>::iterator j = lInts.begin(); j; j++ ) | ||
| 45 | { | ||
| 46 | Gats::Object *pObj = Gats::Object::read( mb ); | ||
| 47 | if( pObj->getType() != Gats::typeInteger ) | ||
| 48 | unitFailed("Bad type read."); | ||
| 49 | |||
| 50 | if( dynamic_cast<Gats::Integer *>(pObj)->getValue() != *j ) | ||
| 51 | unitFailed("Bad number."); | ||
| 52 | } | ||
| 53 | } | ||
| 54 | |||
| 55 | test string | ||
| 56 | { | ||
| 57 | Bu::List<Bu::String> lStrs; | ||
| 58 | Bu::MemBuf mb; | ||
| 59 | |||
| 60 | lStrs.append( Bu::String() ); | ||
| 61 | Gats::String("").write( mb ); | ||
| 62 | |||
| 63 | { | ||
| 64 | int iMax = 0; | ||
| 65 | for( int j = 1; j <= (1<<16); j=j<<1 ) | ||
| 66 | iMax += j; | ||
| 67 | setStepCount( iMax ); | ||
| 68 | } | ||
| 69 | for( int j = 1; j <= (1<<16); j=j<<1 ) | ||
| 70 | { | ||
| 71 | Bu::String s( j ); | ||
| 72 | for( int x = 0; x < j; x++ ) | ||
| 73 | { | ||
| 74 | s[x] = (unsigned char)(random()%256); | ||
| 75 | } | ||
| 76 | incProgress( j ); | ||
| 77 | Gats::String( s ).write( mb ); | ||
| 78 | lStrs.append( s ); | ||
| 79 | } | ||
| 80 | |||
| 81 | mb.setPos( 0 ); | ||
| 82 | |||
| 83 | for( Bu::List<Bu::String>::iterator i = lStrs.begin(); i; i++ ) | ||
| 84 | { | ||
| 85 | Gats::Object *pObj = Gats::Object::read( mb ); | ||
| 86 | if( pObj->getType() != Gats::typeString ) | ||
| 87 | unitFailed("Bad type read."); | ||
| 88 | |||
| 89 | if( *dynamic_cast<Gats::String *>(pObj) != *i ) | ||
| 90 | unitFailed("Bad string."); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | test boolean | ||
| 95 | { | ||
| 96 | Bu::List<bool> lBs; | ||
| 97 | Bu::MemBuf mb; | ||
| 98 | |||
| 99 | for( int j = 0; j < 1024; j++ ) | ||
| 100 | { | ||
| 101 | if( random()%2 == 0 ) | ||
| 102 | { | ||
| 103 | lBs.append( true ); | ||
| 104 | Gats::Boolean( true ).write( mb ); | ||
| 105 | } | ||
| 106 | else | ||
| 107 | { | ||
| 108 | lBs.append( false ); | ||
| 109 | Gats::Boolean( false ).write( mb ); | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | mb.setPos( 0 ); | ||
| 114 | |||
| 115 | for( Bu::List<bool>::iterator i = lBs.begin(); i; i++ ) | ||
| 116 | { | ||
| 117 | Gats::Object *pObj = Gats::Object::read( mb ); | ||
| 118 | if( pObj->getType() != Gats::typeBoolean ) | ||
| 119 | unitFailed("Bad type read."); | ||
| 120 | |||
| 121 | if( dynamic_cast<Gats::Boolean *>(pObj)->getValue() != *i ) | ||
| 122 | unitFailed("Bad string."); | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | test floats | ||
| 127 | { | ||
| 128 | Bu::MemBuf mb; | ||
| 129 | |||
| 130 | Gats::Float( M_PI ).write( mb ); | ||
| 131 | |||
| 132 | mb.setPos( 0 ); | ||
| 133 | |||
| 134 | Gats::Object *pObj = Gats::Object::read( mb ); | ||
| 135 | unitTest( pObj != NULL ); | ||
| 136 | unitTest( pObj->getType() == Gats::typeFloat ); | ||
| 137 | Gats::Float *pFlt = dynamic_cast<Gats::Float *>(pObj); | ||
| 138 | // sio << "old = " << M_PI << ", new = " << pFlt->getValue() << sio.nl; | ||
| 139 | unitTest( pFlt->getValue() == M_PI ); | ||
| 140 | |||
| 141 | delete pObj; | ||
| 142 | } | ||
| 143 | |||
| 144 | test dictionary | ||
| 145 | { | ||
| 146 | MemBuf mb; | ||
| 147 | |||
| 148 | { | ||
| 149 | Gats::Dictionary dict; | ||
| 150 | dict.insert("bool", new Gats::Boolean(true) ); | ||
| 151 | dict.insert("int", 33403055 ); | ||
| 152 | dict.insert("str", "Hey there" ); | ||
| 153 | dict.write( mb ); | ||
| 154 | } | ||
| 155 | |||
| 156 | mb.setPos( 0 ); | ||
| 157 | |||
| 158 | { | ||
| 159 | Gats::Object *pRead = Gats::Object::read( mb ); | ||
| 160 | unitTest( pRead != NULL ); | ||
| 161 | Gats::Dictionary *pDict = dynamic_cast<Gats::Dictionary *>(pRead); | ||
| 162 | unitTest( pDict != NULL ); | ||
| 163 | |||
| 164 | unitTest( pDict->getBool("bool") == true ); | ||
| 165 | unitTest( pDict->getInt("int") == 33403055 ); | ||
| 166 | unitTest( pDict->getStr("str") == "Hey there" ); | ||
| 167 | unitTest( pDict->getSize() == 3 ); | ||
| 168 | |||
| 169 | delete pDict; | ||
| 170 | } | ||
| 171 | } | ||
| 172 | |||
| 173 | test null | ||
| 174 | { | ||
| 175 | MemBuf mb; | ||
| 176 | { | ||
| 177 | Gats::Null n; | ||
| 178 | Gats::GatsStream gs( mb ); | ||
| 179 | gs.writeObject( &n ); | ||
| 180 | } | ||
| 181 | |||
| 182 | mb.setPos( 0 ); | ||
| 183 | |||
| 184 | { | ||
| 185 | Gats::GatsStream gs( mb ); | ||
| 186 | Gats::Object *pObj = gs.readObject(); | ||
| 187 | unitTest( pObj->getType() == Gats::typeNull ); | ||
| 188 | delete pObj; | ||
| 189 | } | ||
| 190 | } | ||
| 191 | } | ||
diff --git a/src/unit/float.unit b/src/unit/float.unit deleted file mode 100644 index b1eb063..0000000 --- a/src/unit/float.unit +++ /dev/null | |||
| @@ -1,84 +0,0 @@ | |||
| 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/float.h" | ||
| 11 | #include "gats/string.h" | ||
| 12 | |||
| 13 | #include "bu/membuf.h" | ||
| 14 | #include "bu/list.h" | ||
| 15 | #include "bu/sio.h" | ||
| 16 | |||
| 17 | #include <stdlib.h> | ||
| 18 | #include <math.h> | ||
| 19 | |||
| 20 | using namespace Bu; | ||
| 21 | |||
| 22 | suite Basic | ||
| 23 | { | ||
| 24 | void rw( double dVal ) | ||
| 25 | { | ||
| 26 | Bu::MemBuf mb; | ||
| 27 | |||
| 28 | Gats::Float( dVal ).write( mb ); | ||
| 29 | |||
| 30 | mb.setPos( 0 ); | ||
| 31 | |||
| 32 | Gats::Object *pObj = Gats::Object::read( mb ); | ||
| 33 | unitTest( pObj != NULL ); | ||
| 34 | unitTest( pObj->getType() == Gats::typeFloat ); | ||
| 35 | Gats::Float *pFlt = dynamic_cast<Gats::Float *>(pObj); | ||
| 36 | Bu::String sHex; | ||
| 37 | for( Bu::String::iterator i = mb.getString().begin(); i; i++ ) | ||
| 38 | { | ||
| 39 | sHex += "0123456789abcdef"[(((uint8_t)*i)>>4)&0x0f]; | ||
| 40 | sHex += "0123456789abcdef"[(*i)&0x0f]; | ||
| 41 | sHex += ' '; | ||
| 42 | } | ||
| 43 | printf("In: %a\nOut: %a\nRaw: %s\n", dVal, pFlt->getValue(), sHex.getStr() ); | ||
| 44 | if( isnan( dVal ) ) | ||
| 45 | unitTest( isnan(pFlt->getValue()) == isnan(dVal) ); | ||
| 46 | else | ||
| 47 | unitTest( pFlt->getValue() == dVal ); | ||
| 48 | unitTest( signbit(pFlt->getValue()) == signbit(dVal) ); | ||
| 49 | |||
| 50 | delete pObj; | ||
| 51 | } | ||
| 52 | |||
| 53 | test positive | ||
| 54 | { | ||
| 55 | rw( 8485738457.0 ); | ||
| 56 | rw( 63723.0 ); | ||
| 57 | rw( 0.000000000000001928173 ); | ||
| 58 | rw( 1.0 ); | ||
| 59 | rw( 0.0 ); | ||
| 60 | rw( M_PI ); | ||
| 61 | } | ||
| 62 | |||
| 63 | test negitave | ||
| 64 | { | ||
| 65 | rw( -8485738457.0 ); | ||
| 66 | rw( -63723.0 ); | ||
| 67 | rw( -0.000000000000001928173 ); | ||
| 68 | rw( -1.0 ); | ||
| 69 | rw( -0.0 ); | ||
| 70 | rw( -M_PI ); | ||
| 71 | } | ||
| 72 | |||
| 73 | test inf | ||
| 74 | { | ||
| 75 | rw( INFINITY ); | ||
| 76 | rw( -INFINITY ); | ||
| 77 | } | ||
| 78 | |||
| 79 | test nan | ||
| 80 | { | ||
| 81 | rw( NAN ); | ||
| 82 | rw( -NAN ); | ||
| 83 | } | ||
| 84 | } | ||
diff --git a/src/unit/io.unit b/src/unit/io.unit deleted file mode 100644 index 1a9747f..0000000 --- a/src/unit/io.unit +++ /dev/null | |||
| @@ -1,128 +0,0 @@ | |||
| 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::String 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::String 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 | |||
| 95 | test biggerSpacers | ||
| 96 | { | ||
| 97 | Bu::String sTmpFileName("temp-XXXXXXXXX"); | ||
| 98 | Bu::File fIo = tempFile( sTmpFileName ); | ||
| 99 | |||
| 100 | { | ||
| 101 | Gats::GatsStream sGats( fIo ); | ||
| 102 | Gats::Integer i( -157 ); | ||
| 103 | sGats.writeObject( &i ); | ||
| 104 | fIo.write( "\x00\x00\x00\x00\x00\x00\x00\x00\x00", 9 ); | ||
| 105 | Gats::String s("negative one hundred and fifty seven"); | ||
| 106 | sGats.writeObject( &s ); | ||
| 107 | } | ||
| 108 | |||
| 109 | fIo.setPos( 0 ); | ||
| 110 | |||
| 111 | { | ||
| 112 | Gats::GatsStream sGats( fIo ); | ||
| 113 | Gats::Object *pObj1 = sGats.readObject(); | ||
| 114 | unitTest( pObj1 != NULL ); | ||
| 115 | unitTest( pObj1->getType() == Gats::typeInteger ); | ||
| 116 | unitTest( dynamic_cast<Gats::Integer *>(pObj1)->getValue() == -157 ); | ||
| 117 | |||
| 118 | Gats::Object *pObj2 = sGats.readObject(); | ||
| 119 | unitTest( pObj2 != NULL ); | ||
| 120 | unitTest( pObj2->getType() == Gats::typeString ); | ||
| 121 | unitTest( *dynamic_cast<Gats::String *>(pObj2) == | ||
| 122 | "negative one hundred and fifty seven" ); | ||
| 123 | |||
| 124 | delete pObj1; | ||
| 125 | delete pObj2; | ||
| 126 | } | ||
| 127 | } | ||
| 128 | } | ||
