diff options
Diffstat (limited to 'c++-libbu++/src/tests')
-rw-r--r-- | c++-libbu++/src/tests/clone.cpp | 21 | ||||
-rw-r--r-- | c++-libbu++/src/tests/dump.cpp | 41 | ||||
-rw-r--r-- | c++-libbu++/src/tests/int.cpp | 65 |
3 files changed, 74 insertions, 53 deletions
diff --git a/c++-libbu++/src/tests/clone.cpp b/c++-libbu++/src/tests/clone.cpp index 8533376..bfb7b27 100644 --- a/c++-libbu++/src/tests/clone.cpp +++ b/c++-libbu++/src/tests/clone.cpp | |||
@@ -1,3 +1,10 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libgats library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
1 | #include "gats/types.h" | 8 | #include "gats/types.h" |
2 | 9 | ||
3 | #include <bu/sio.h> | 10 | #include <bu/sio.h> |
@@ -6,17 +13,17 @@ using namespace Bu; | |||
6 | 13 | ||
7 | int main( int argc, char *argv[] ) | 14 | int main( int argc, char *argv[] ) |
8 | { | 15 | { |
9 | Gats::Object *pBase = Gats::Object::strToGats("{\"Thing\": 3.14159, \"bool\": true, \"list\":[\"string\",44,{\"Stuff\":{\"list\":[],\"what?\":false}}]}"); | 16 | Gats::Object *pBase = Gats::Object::strToGats("{\"Thing\": 3.14159, \"bool\": true, \"list\":[\"string\",44,{\"Stuff\":{\"list\":[],\"what?\":false}}]}"); |
10 | 17 | ||
11 | sio << *pBase << sio.nl; | 18 | sio << *pBase << sio.nl; |
12 | 19 | ||
13 | Gats::Object *pNew = pBase->clone(); | 20 | Gats::Object *pNew = pBase->clone(); |
14 | delete pBase; | 21 | delete pBase; |
15 | 22 | ||
16 | sio << *pNew << sio.nl; | 23 | sio << *pNew << sio.nl; |
17 | 24 | ||
18 | delete pNew; | 25 | delete pNew; |
19 | 26 | ||
20 | return 0; | 27 | return 0; |
21 | } | 28 | } |
22 | 29 | ||
diff --git a/c++-libbu++/src/tests/dump.cpp b/c++-libbu++/src/tests/dump.cpp index e0dcb52..f1950b2 100644 --- a/c++-libbu++/src/tests/dump.cpp +++ b/c++-libbu++/src/tests/dump.cpp | |||
@@ -1,3 +1,10 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libgats library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
1 | #include <bu/sio.h> | 8 | #include <bu/sio.h> |
2 | #include <bu/file.h> | 9 | #include <bu/file.h> |
3 | #include <gats/gatsstream.h> | 10 | #include <gats/gatsstream.h> |
@@ -7,24 +14,24 @@ using namespace Bu; | |||
7 | 14 | ||
8 | int main( int argc, char *argv[] ) | 15 | int main( int argc, char *argv[] ) |
9 | { | 16 | { |
10 | File fIn( argv[1], File::Read ); | 17 | File fIn( argv[1], File::Read ); |
11 | Gats::GatsStream gsIn( fIn ); | 18 | Gats::GatsStream gsIn( fIn ); |
12 | 19 | ||
13 | for(;;) | 20 | for(;;) |
14 | { | 21 | { |
15 | sio << "Reading from file position: " << fIn.tell() << sio.nl; | 22 | sio << "Reading from file position: " << fIn.tell() << sio.nl; |
16 | Gats::Object *pObj = gsIn.readObject(); | 23 | Gats::Object *pObj = gsIn.readObject(); |
17 | if( !pObj ) | 24 | if( !pObj ) |
18 | { | 25 | { |
19 | if( gsIn.hasReadBuffer() ) | 26 | if( gsIn.hasReadBuffer() ) |
20 | { | 27 | { |
21 | sio << "Premature end of stream detected, have " | 28 | sio << "Premature end of stream detected, have " |
22 | << gsIn.getReadBufferSize() << "b." << sio.nl; | 29 | << gsIn.getReadBufferSize() << "b." << sio.nl; |
23 | } | 30 | } |
24 | return 0; | 31 | return 0; |
25 | } | 32 | } |
26 | 33 | ||
27 | sio << *pObj << sio.nl; | 34 | sio << *pObj << sio.nl; |
28 | } | 35 | } |
29 | } | 36 | } |
30 | 37 | ||
diff --git a/c++-libbu++/src/tests/int.cpp b/c++-libbu++/src/tests/int.cpp index c19df9c..25ef831 100644 --- a/c++-libbu++/src/tests/int.cpp +++ b/c++-libbu++/src/tests/int.cpp | |||
@@ -1,3 +1,10 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2007-2012 Xagasoft, All rights reserved. | ||
3 | * | ||
4 | * This file is part of the libgats library and is released under the | ||
5 | * terms of the license contained in the file LICENSE. | ||
6 | */ | ||
7 | |||
1 | #include "gats/integer.h" | 8 | #include "gats/integer.h" |
2 | 9 | ||
3 | #include <bu/sio.h> | 10 | #include <bu/sio.h> |
@@ -8,40 +15,40 @@ using namespace Bu; | |||
8 | 15 | ||
9 | void hexdump( char *dat, int iSize ) | 16 | void hexdump( char *dat, int iSize ) |
10 | { | 17 | { |
11 | static const char *hex="0123456789ABCDEF"; | 18 | static const char *hex="0123456789ABCDEF"; |
12 | printf("----\n"); | 19 | printf("----\n"); |
13 | for( int j = 0; j < iSize; j += 8 ) | 20 | for( int j = 0; j < iSize; j += 8 ) |
14 | { | 21 | { |
15 | for( int k = j; /*k < iSize &&*/ k < j+8; k++ ) | 22 | for( int k = j; /*k < iSize &&*/ k < j+8; k++ ) |
16 | printf((k<iSize)?"%c%c ":" ", hex[(dat[k]>>4)&0x0F], hex[dat[k]&0x0F] ); | 23 | printf((k<iSize)?"%c%c ":" ", hex[(dat[k]>>4)&0x0F], hex[dat[k]&0x0F] ); |
17 | printf("| "); | 24 | printf("| "); |
18 | for( int k = j; k < iSize && k < j+8; k++ ) | 25 | for( int k = j; k < iSize && k < j+8; k++ ) |
19 | printf("%c ", (dat[k]>13&&dat[k]<127)?(dat[k]):('.') ); | 26 | printf("%c ", (dat[k]>13&&dat[k]<127)?(dat[k]):('.') ); |
20 | printf("\n"); | 27 | printf("\n"); |
21 | } | 28 | } |
22 | printf("----\n"); | 29 | printf("----\n"); |
23 | } | 30 | } |
24 | 31 | ||
25 | int main( int argc, char *argv[] ) | 32 | int main( int argc, char *argv[] ) |
26 | { | 33 | { |
27 | for( int j = 1; j < argc; j++ ) | 34 | for( int j = 1; j < argc; j++ ) |
28 | { | 35 | { |
29 | int64_t i = strtoll( argv[j], NULL, 10 ); | 36 | int64_t i = strtoll( argv[j], NULL, 10 ); |
30 | MemBuf mb; | 37 | MemBuf mb; |
31 | Gats::Integer::writePackedInt( mb, i ); | 38 | Gats::Integer::writePackedInt( mb, i ); |
32 | hexdump( mb.getString().getStr(), mb.getString().getSize() ); | 39 | hexdump( mb.getString().getStr(), mb.getString().getSize() ); |
33 | } | 40 | } |
34 | /* | 41 | /* |
35 | sio << "Before: " << i << sio.nl; | 42 | sio << "Before: " << i << sio.nl; |
36 | Gats::Integer::writePackedInt( mb, i ); | 43 | Gats::Integer::writePackedInt( mb, i ); |
37 | mb.write("aaa", 3 ); | 44 | mb.write("aaa", 3 ); |
38 | mb.setPos( 0 ); | 45 | mb.setPos( 0 ); |
39 | Gats::Integer::readPackedInt( mb, i ); | 46 | Gats::Integer::readPackedInt( mb, i ); |
40 | sio << "After: " << i << sio.nl; | 47 | sio << "After: " << i << sio.nl; |
41 | char buf[4]; | 48 | char buf[4]; |
42 | buf[mb.read( buf, 3 )] = '\0'; | 49 | buf[mb.read( buf, 3 )] = '\0'; |
43 | sio << "Extra: \"" << buf << "\"" << sio.nl; | 50 | sio << "Extra: \"" << buf << "\"" << sio.nl; |
44 | */ | 51 | */ |
45 | return 0; | 52 | return 0; |
46 | } | 53 | } |
47 | 54 | ||