aboutsummaryrefslogtreecommitdiff
path: root/c++-libbu++/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'c++-libbu++/src/tests')
-rw-r--r--c++-libbu++/src/tests/clone.cpp22
-rw-r--r--c++-libbu++/src/tests/dump.cpp30
-rw-r--r--c++-libbu++/src/tests/int.cpp47
3 files changed, 99 insertions, 0 deletions
diff --git a/c++-libbu++/src/tests/clone.cpp b/c++-libbu++/src/tests/clone.cpp
new file mode 100644
index 0000000..8533376
--- /dev/null
+++ b/c++-libbu++/src/tests/clone.cpp
@@ -0,0 +1,22 @@
1#include "gats/types.h"
2
3#include <bu/sio.h>
4
5using namespace Bu;
6
7int main( int argc, char *argv[] )
8{
9 Gats::Object *pBase = Gats::Object::strToGats("{\"Thing\": 3.14159, \"bool\": true, \"list\":[\"string\",44,{\"Stuff\":{\"list\":[],\"what?\":false}}]}");
10
11 sio << *pBase << sio.nl;
12
13 Gats::Object *pNew = pBase->clone();
14 delete pBase;
15
16 sio << *pNew << sio.nl;
17
18 delete pNew;
19
20 return 0;
21}
22
diff --git a/c++-libbu++/src/tests/dump.cpp b/c++-libbu++/src/tests/dump.cpp
new file mode 100644
index 0000000..e0dcb52
--- /dev/null
+++ b/c++-libbu++/src/tests/dump.cpp
@@ -0,0 +1,30 @@
1#include <bu/sio.h>
2#include <bu/file.h>
3#include <gats/gatsstream.h>
4#include <gats/types.h>
5
6using namespace Bu;
7
8int main( int argc, char *argv[] )
9{
10 File fIn( argv[1], File::Read );
11 Gats::GatsStream gsIn( fIn );
12
13 for(;;)
14 {
15 sio << "Reading from file position: " << fIn.tell() << sio.nl;
16 Gats::Object *pObj = gsIn.readObject();
17 if( !pObj )
18 {
19 if( gsIn.hasReadBuffer() )
20 {
21 sio << "Premature end of stream detected, have "
22 << gsIn.getReadBufferSize() << "b." << sio.nl;
23 }
24 return 0;
25 }
26
27 sio << *pObj << sio.nl;
28 }
29}
30
diff --git a/c++-libbu++/src/tests/int.cpp b/c++-libbu++/src/tests/int.cpp
new file mode 100644
index 0000000..c19df9c
--- /dev/null
+++ b/c++-libbu++/src/tests/int.cpp
@@ -0,0 +1,47 @@
1#include "gats/integer.h"
2
3#include <bu/sio.h>
4#include <bu/membuf.h>
5#include <stdlib.h>
6
7using namespace Bu;
8
9void hexdump( char *dat, int iSize )
10{
11 static const char *hex="0123456789ABCDEF";
12 printf("----\n");
13 for( int j = 0; j < iSize; j += 8 )
14 {
15 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] );
17 printf("| ");
18 for( int k = j; k < iSize && k < j+8; k++ )
19 printf("%c ", (dat[k]>13&&dat[k]<127)?(dat[k]):('.') );
20 printf("\n");
21 }
22 printf("----\n");
23}
24
25int main( int argc, char *argv[] )
26{
27 for( int j = 1; j < argc; j++ )
28 {
29 int64_t i = strtoll( argv[j], NULL, 10 );
30 MemBuf mb;
31 Gats::Integer::writePackedInt( mb, i );
32 hexdump( mb.getString().getStr(), mb.getString().getSize() );
33 }
34/*
35 sio << "Before: " << i << sio.nl;
36 Gats::Integer::writePackedInt( mb, i );
37 mb.write("aaa", 3 );
38 mb.setPos( 0 );
39 Gats::Integer::readPackedInt( mb, i );
40 sio << "After: " << i << sio.nl;
41 char buf[4];
42 buf[mb.read( buf, 3 )] = '\0';
43 sio << "Extra: \"" << buf << "\"" << sio.nl;
44*/
45 return 0;
46}
47