From 4b9289cfb260f4bcecaf23a810584ef6ef8e8501 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 30 Mar 2011 22:33:41 +0000 Subject: Ok, string stuff is working much, much better, a load of new unit tests have been added, and I deleted a whole slew of stupid old tests that I don't need. --- src/tests/archive.cpp | 27 ----- src/tests/archive2.cpp | 102 ------------------ src/tests/atom.cpp | 32 ------ src/tests/buffer.cpp | 45 -------- src/tests/cache.cpp | 260 ---------------------------------------------- src/tests/conduit.cpp | 56 ---------- src/tests/console.cpp | 43 -------- src/tests/cryptpass.cpp | 25 ----- src/tests/csv.cpp | 50 --------- src/tests/daysinmonth.cpp | 23 ---- src/tests/fastcgi.cpp | 90 ---------------- src/tests/formula.cpp | 56 ---------- src/tests/fstratsptr.cpp | 53 ---------- src/tests/fstrstd.cpp | 16 --- src/tests/hash.cpp | 31 ------ src/tests/hash2.cpp | 35 ------- src/tests/heap.cpp | 120 --------------------- src/tests/itoheap.cpp | 70 ------------- src/tests/itoqueue1.cpp | 115 -------------------- src/tests/itoqueue2.cpp | 87 ---------------- src/tests/itoserver.cpp | 80 -------------- src/tests/list.cpp | 77 -------------- src/tests/list2.cpp | 26 ----- src/tests/listsort.cpp | 79 -------------- src/tests/logger.cpp | 37 ------- src/tests/md5.cpp | 34 ------ src/tests/minicron.cpp | 63 ----------- src/tests/mmparse.cpp | 22 ---- src/tests/multiserver.cpp | 76 -------------- src/tests/procs.cpp | 37 ------- src/tests/queuebuf.cpp | 66 ------------ src/tests/regex.cpp | 38 ------- src/tests/ringbuffer.cpp | 38 ------- src/tests/rot13.cpp | 91 ---------------- src/tests/serverticks.cpp | 69 ------------ src/tests/sha1.cpp | 39 ------- src/tests/sharedcore.cpp | 98 ----------------- src/tests/signals.cpp | 131 ----------------------- src/tests/size.cpp | 20 ---- src/tests/socketblock.cpp | 56 ---------- src/tests/socketbreak.cpp | 35 ------- src/tests/speed.cpp | 58 ----------- src/tests/stdstream.cpp | 39 ------- src/tests/streamstack.cpp | 100 ------------------ src/tests/string.cpp | 154 --------------------------- src/tests/stringspeed.cpp | 122 ---------------------- src/tests/tcpsocket.cpp | 73 ------------- src/tests/telnetsrv.cpp | 92 ---------------- src/tests/tracer.cpp | 36 ------- src/tests/udpsocket.cpp | 86 --------------- src/tests/url.cpp | 42 -------- src/tests/variant.cpp | 52 ---------- 52 files changed, 3402 deletions(-) delete mode 100644 src/tests/archive.cpp delete mode 100644 src/tests/archive2.cpp delete mode 100644 src/tests/atom.cpp delete mode 100644 src/tests/buffer.cpp delete mode 100644 src/tests/cache.cpp delete mode 100644 src/tests/conduit.cpp delete mode 100644 src/tests/console.cpp delete mode 100644 src/tests/cryptpass.cpp delete mode 100644 src/tests/csv.cpp delete mode 100644 src/tests/daysinmonth.cpp delete mode 100644 src/tests/fastcgi.cpp delete mode 100644 src/tests/formula.cpp delete mode 100644 src/tests/fstratsptr.cpp delete mode 100644 src/tests/fstrstd.cpp delete mode 100644 src/tests/hash.cpp delete mode 100644 src/tests/hash2.cpp delete mode 100644 src/tests/heap.cpp delete mode 100644 src/tests/itoheap.cpp delete mode 100644 src/tests/itoqueue1.cpp delete mode 100644 src/tests/itoqueue2.cpp delete mode 100644 src/tests/itoserver.cpp delete mode 100644 src/tests/list.cpp delete mode 100644 src/tests/list2.cpp delete mode 100644 src/tests/listsort.cpp delete mode 100644 src/tests/logger.cpp delete mode 100644 src/tests/md5.cpp delete mode 100644 src/tests/minicron.cpp delete mode 100644 src/tests/mmparse.cpp delete mode 100644 src/tests/multiserver.cpp delete mode 100644 src/tests/procs.cpp delete mode 100644 src/tests/queuebuf.cpp delete mode 100644 src/tests/regex.cpp delete mode 100644 src/tests/ringbuffer.cpp delete mode 100644 src/tests/rot13.cpp delete mode 100644 src/tests/serverticks.cpp delete mode 100644 src/tests/sha1.cpp delete mode 100644 src/tests/sharedcore.cpp delete mode 100644 src/tests/signals.cpp delete mode 100644 src/tests/size.cpp delete mode 100644 src/tests/socketblock.cpp delete mode 100644 src/tests/socketbreak.cpp delete mode 100644 src/tests/speed.cpp delete mode 100644 src/tests/stdstream.cpp delete mode 100644 src/tests/streamstack.cpp delete mode 100644 src/tests/string.cpp delete mode 100644 src/tests/stringspeed.cpp delete mode 100644 src/tests/tcpsocket.cpp delete mode 100644 src/tests/telnetsrv.cpp delete mode 100644 src/tests/tracer.cpp delete mode 100644 src/tests/udpsocket.cpp delete mode 100644 src/tests/url.cpp delete mode 100644 src/tests/variant.cpp (limited to 'src/tests') diff --git a/src/tests/archive.cpp b/src/tests/archive.cpp deleted file mode 100644 index c905007..0000000 --- a/src/tests/archive.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/archive.h" -#include "bu/file.h" -#include "bu/string.h" - -using namespace Bu; - -int main() -{ - File f("test.dat", File::WriteNew ); - Archive ar( f, Archive::save ); - - Bu::String s("Hello there"); - ar << s; - - ar.setProp("hi", 45 ); - printf("Hi: %d", ar.getProp("hi") ); - - return 0; -} - diff --git a/src/tests/archive2.cpp b/src/tests/archive2.cpp deleted file mode 100644 index e8d3360..0000000 --- a/src/tests/archive2.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/archive.h" -#include "bu/archival.h" -#include "bu/file.h" - -int giId = 0; - -class A : public Bu::Archival -{ -public: - A() : - iId( giId++ ) - { - } - - virtual ~A() - { - } - - virtual void archive( Bu::ArchiveBase &ar ) - { - ar && iId; - } - - int iId; -}; - -class B : public Bu::Archival -{ -public: - B() : - iId( giId++ ), - a1( new A ), - a2( new A ) - { - } - - virtual ~B() - { - delete a1; - delete a2; - } - - virtual void archive( Bu::ArchiveBase &ar ) - { - //ar && iId && a1 && a2; - ar << iId << a1 << a2; - } - - int iId; - A *a1, *a2; -}; - -class C : public Bu::Archival -{ -public: - C() : - iId( giId++ ), - a( new A ), - b( new B ) - { - } - - virtual ~C() - { - delete a; - delete b; - } - - virtual void archive( Bu::ArchiveBase &ar ) - { - //ar && iId && a && b; - ar << iId; - ar << a << b; - } - - int iId; - A *a; - B *b; -}; - -void write() -{ - C *c = new C; - - Bu::File f( "test.archive", Bu::File::Write ); - Bu::Archive ar( f, Bu::Archive::save ); - ar << c; -} - -int main() -{ - write(); - -} - diff --git a/src/tests/atom.cpp b/src/tests/atom.cpp deleted file mode 100644 index 7808282..0000000 --- a/src/tests/atom.cpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/atom.h" -#include -#include - -typedef struct bob -{ - int a, b; -} bob; -int main() -{ - Bu::Atom aInt; - Bu::Atom aStr; - Bu::Atom aBob; - - aBob = bob(); - aBob->a = 5; - - aStr.set("Hey there, dude"); - aInt.set( 55 ); - int me = aInt; - aInt = 12; - printf("%d, %d\n", aInt.get(), me ); - printf("%s\n", aStr.get() ); -} - diff --git a/src/tests/buffer.cpp b/src/tests/buffer.cpp deleted file mode 100644 index f3f6f41..0000000 --- a/src/tests/buffer.cpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/membuf.h" -#include "bu/buffer.h" -#include "bu/file.h" - -using namespace Bu; - -int main( int argc, char *argv[] ) -{ - argc--,argv++; - if( argc == 0 ) - { - MemBuf mOut; - Buffer bOut( mOut, 10 ); - - for( int j = 0; j < 4; j++ ) - bOut.write("hi ", 3 ); - - printf("Preflush: \"%s\"\n", mOut.getString().getStr() ); - bOut.flush(); - - printf("Final: \"%s\"\n", mOut.getString().getStr() ); - } - else - { - File fIn( *argv, File::Read ); - Buffer bIn( fIn, 10 ); - - char buf[5]; - for( int j = 0; j < 5; j++ ) - { - buf[bIn.read( buf, 4 )] = '\0'; - printf("Four chars: \"%s\"\n", buf ); - } - } - - return 0; -} - diff --git a/src/tests/cache.cpp b/src/tests/cache.cpp deleted file mode 100644 index e9dbd86..0000000 --- a/src/tests/cache.cpp +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -#include -#include -#include -#include -#include - -#include "bu/cache.h" -#include "bu/file.h" -#include "bu/string.h" -#include "bu/cachecalc.h" - -class Bob -{ -public: - Bob() - { - TRACE(); - } - - Bob( int i ) : - iInt( i ) - { - TRACE( i ); - } - - virtual ~Bob() - { - TRACE(); - } - - void setInt( int i ) - { - TRACE( i ); - iInt = i; - } - - long getKey() const - { - TRACE( i ); - return iInt; - } - - int getInt() - { - return iInt; - } - - int iInt; -}; - -namespace Bu { - template<> - void __tracer_format( Bob* const &c ) - { - printf("%08X=%d", (uint32_t)c, c->getInt() ); - } -} - -class BobStore : public Bu::CacheStore -{ -public: - BobStore() : - cLastId( 0 ) - { - TRACE(); - if( access( "bobcache/last", R_OK|W_OK ) ) - { - mkdir("bobcache", 0755 ); - Bu::File f("bobcache/last", Bu::File::Write|Bu::File::Create ); - f.write("0", 1); - printf("Initializing cache: %s\n", strerror( errno ) ); - } - else - { - cLastId = readNum("bobcache/last"); - } - } - - ~BobStore() - { - TRACE(); - writeNum("bobcache/last", cLastId ); - } - - long readNum( const Bu::String &sFile ) - { - TRACE( sFile ); - Bu::File f( sFile, Bu::File::Read ); - char buf[80]; - buf[f.read( buf, 80 )] = '\0'; - return strtol( buf, NULL, 0 ); - } - - void writeNum( const Bu::String &sFile, long num ) - { - TRACE( sFile, num ); - Bu::File f( sFile, - Bu::File::Write|Bu::File::Create|Bu::File::Truncate - ); - f.write( Bu::String("%1").arg( num ) ); - } - - virtual void sync( Bob *, const long & ) - { - } - - virtual void sync() - { - } - - virtual bool has( const long & ) - { - return true; - } - - virtual Bob *load( const long &key ) - { - TRACE( key ); - Bu::String sDest = Bu::String("bobcache/%1").arg( key ); - return new Bob( readNum( sDest ) ); - } - - virtual void unload( Bob *pObj, const long &key ) - { - TRACE( pObj, key ); - Bu::String sDest = Bu::String("bobcache/%1").arg( key ); - writeNum( sDest, pObj->getInt() ); - delete pObj; - } - - virtual long create( Bob *rSrc ) - { - TRACE( rSrc ); - long id = ++cLastId; - Bu::String sDest = Bu::String("bobcache/%1").arg( id ); - writeNum( sDest, rSrc->getInt() ); - return id; - } - - virtual void destroy( Bob *pObj, const long &key ) - { - TRACE( pObj, key ); - Bu::String sDest = Bu::String("bobcache/%1").arg( key ); - if( !access( sDest.getStr(), F_OK ) ) - unlink( sDest.getStr() ); - delete pObj; - } - - virtual void destroy( const long &key ) - { - TRACE( pObj, key ); - Bu::String sDest = Bu::String("bobcache/%1").arg( key ); - if( !access( sDest.getStr(), F_OK ) ) - unlink( sDest.getStr() ); - } - -private: - long cLastId; -}; - -class BobCalc : public Bu::CacheCalc -{ -public: - BobCalc() - { - } - - virtual ~BobCalc() - { - } - - virtual void onLoad( Bob *, const long & ) - { - } - - virtual void onUnload( Bob *, const long & ) - { - } - - virtual void onDestroy( Bob *, const long & ) - { - } - - virtual void onDestroy( const long & ) - { - } - - virtual bool shouldSync( Bob *, const long &, time_t ) - { - return false; - } - -private: - -}; - -int main( int argc, char *argv[] ) -{ - TRACE( argc, argv ); - typedef Bu::Cache BobCache; - typedef BobCache::Ptr BobPtr; - - if( argc < 3 ) - { - printf("Try: %s [crudl] []\n\n", argv[0] ); - return 0; - } - - BobCache cBob( new BobCalc(), new BobStore() ); - switch( argv[1][0] ) - { - case 'c': - { - BobCache::Ptr pBob = cBob.insert( - new Bob( strtol( argv[2], NULL, 0 ) ) - ); - printf("Key = %ld\n", pBob.getKey() ); - } - return 0; - - case 'r': - { - BobCache::Ptr pBob = cBob.get( strtol( argv[2], NULL, 0 ) ); - printf("Value = %d\n", pBob->getInt() ); - } - return 0; - - case 'u': - { - BobCache::Ptr pBob = cBob.get( strtol( argv[2], NULL, 0 ) ); - pBob->setInt( strtol( argv[3], NULL, 0 ) ); - } - return 0; - - case 'd': - { - cBob.erase( strtol( argv[2], NULL, 0 ) ); - } - return 0; - - case 'l': - { - BobCache::Ptr pBob = cBob.getLazy( strtol( argv[2], NULL, 0 ) ); - printf("isBound: %s\n", pBob.isBound()?"yes":"no"); - printf("Value = %d\n", pBob->getInt() ); - printf("isBound: %s\n", pBob.isBound()?"yes":"no"); - } - return 0; - } - -} - diff --git a/src/tests/conduit.cpp b/src/tests/conduit.cpp deleted file mode 100644 index d8d9e03..0000000 --- a/src/tests/conduit.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "bu/conduit.h" -#include "bu/sio.h" -#include "bu/ito.h" - -using namespace Bu; - -class Reader : public Bu::Ito -{ -public: - Reader( Bu::Conduit &rCond ) : - rCond( rCond ) - { - } - - virtual ~Reader() - { - } - -protected: - virtual void run() - { - while( rCond.isOpen() ) - { - char buf[1025]; - - sio << "Reading..." << sio.flush; - Bu::size iRead = rCond.read( buf, 1024 ); - buf[iRead] = '\0'; - sio << "got " << iRead << " >" << buf << "<" << sio.nl; - } - - sio << "Conduit closed, exting thread." << sio.nl; - } - -private: - Bu::Conduit &rCond; -}; - -int main() -{ - Conduit c; - Reader r( c ); - r.start(); - - sleep( 3 ); - c.write("Hi there", 8 ); - sleep( 3 ); - c.write("Goodbye, soon.", 14 ); - sleep( 3 ); - c.write("...NOW!", 9 ); - c.close(); - sleep( 3 ); - - return 0; -} - diff --git a/src/tests/console.cpp b/src/tests/console.cpp deleted file mode 100644 index 670ff5b..0000000 --- a/src/tests/console.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -using namespace Bu; - -#include -using namespace std; - -typedef struct Counter -{ - Counter() : i( 0 ) - { - } - - int get() - { - i++; - return i-1; - } - - int i; -} Counter; - -template -void runtest( a &out ) -{ - Counter c; - out << c.get() << ", " << c.get() << ", " << c.get() << ", " << c.get() << ", " << c.get() << "\n"; -} - -int main() -{ - runtest( cout ); - runtest( sio ); - - return 0; -} - diff --git a/src/tests/cryptpass.cpp b/src/tests/cryptpass.cpp deleted file mode 100644 index d272344..0000000 --- a/src/tests/cryptpass.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/crypt.h" -#include "bu/sio.h" - -using namespace Bu; - -int main( int argc, char *argv[] ) -{ - if( argc == 1 ) - sio << "Syntax: " << argv[0] << " [salt]" << sio.nl - << sio.nl; - else if( argc == 2 ) - sio << "Crypt1: >> " << cryptPass( argv[1] ) << " <<" << sio.nl; - else - sio << "Crypt2: >> " << cryptPass( argv[1], argv[2] ) << " <<" << sio.nl; - - return 0; -} - diff --git a/src/tests/csv.cpp b/src/tests/csv.cpp deleted file mode 100644 index 850fda8..0000000 --- a/src/tests/csv.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/optparser.h" -#include "bu/file.h" -#include "bu/newline.h" -#include "bu/csvreader.h" -#include "bu/buffer.h" -#include "bu/sio.h" - -using namespace Bu; - -class Options : public OptParser -{ -public: - Options( int argc, char *argv[] ) - { - addOption( slot( this, &Options::onRead ), 'r', "read", - "Read and display a csv file." ); - - addHelpOption(); - - parse( argc, argv ); - } - - int onRead( StrArray aArgs ) - { - File fIn( aArgs[1], File::Read ); - NewLine nlIn( fIn ); - Buffer bIn( nlIn ); - CsvReader rCsv( bIn ); - while( !fIn.isEos() ) - { - sio << rCsv.readLine() << sio.nl; - } - sio << sio.nl; - return 1; - } -}; - -int main( int argc, char *argv[] ) -{ - Options opts( argc, argv ); - return 0; -} - diff --git a/src/tests/daysinmonth.cpp b/src/tests/daysinmonth.cpp deleted file mode 100644 index 1e78eb3..0000000 --- a/src/tests/daysinmonth.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/sio.h" -#include "bu/util.h" - -using namespace Bu; - -int main() -{ - for( int j = 0; j < 12; j++ ) - { - sio << "2012-" << j << " = " - << getDaysInMonth( j, 2012 ) << sio.nl; - } - - return 0; -} - diff --git a/src/tests/fastcgi.cpp b/src/tests/fastcgi.cpp deleted file mode 100644 index 7447a6f..0000000 --- a/src/tests/fastcgi.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/fastcgi.h" - -#include - -class Cgi : public Bu::FastCgi -{ -public: - Cgi() : - Bu::FastCgi::FastCgi() - { - } - - Cgi( int iPort ) : - Bu::FastCgi::FastCgi( iPort ) - { - } - - virtual ~Cgi() - { - } - - virtual int onRequest( const StrHash &hParams, - const Bu::String &sStdIn, Bu::Stream &sStdOut, - Bu::Stream &/*sStdErr*/ ) - { - Bu::String sOut("Content-Type: text/html\r\n\r\n"); - sOut += "

Environment:

    "; - for( StrHash::const_iterator i = hParams.begin(); i; i++ ) - { - sOut += "
  • " + i.getKey() + " = " + - i.getValue() + "
  • "; - } - sOut += "
"; - char buf[2048]; - sOut += "

Cwd:

  • "; - sOut += getcwd( buf, 2048 ); - sOut += "
"; - sOut += "

Stdin:

"; - sOut += Bu::String("%1 bytes
").arg( sStdIn.getSize() );
-		Bu::String sL, sR;
-		for( Bu::String::const_iterator i = sStdIn.begin();
-			i; i++ )
-		{
-			sL += Bu::String("%1").arg(
-					(unsigned int)((unsigned char)*i), Bu::Fmt::hex().width(2).fill('0') );
-			if( *i < 27 )
-				sR += ". ";
-			else
-				sR += Bu::String("&#%1; ").arg(
-					(unsigned int)((unsigned char)*i) );
-			if( sL.getSize()/3 == 8 )
-			{
-				sOut += sL + " | " + sR + "\n";
-				sL = sR = "";
-			}
-		}
-		if( sL != "" )
-		{
-			while( sL.getSize()/3 < 8 )
-				sL += "   ";
-			sOut += sL + " | " + sR + "\n";
-		}
-		sOut += "

";
-		sOut += sStdIn;
-		sOut += "
"; - sOut += "


"; - sOut += ""; - - sStdOut.write( sOut ); - - return 0; - } -}; - -int main() -{ - Cgi c( 8789 ); - - c.run(); - - return 0; -} - diff --git a/src/tests/formula.cpp b/src/tests/formula.cpp deleted file mode 100644 index a90ddaf..0000000 --- a/src/tests/formula.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/formula.h" -#include - -int main( int argc, char *argv[] ) -{ - if( argc < 2 ) - { - printf("usage: %s \n", argv[0] ); - return -1; - } - Bu::Formula uForm; - Bu::Formula dForm; - - class DblCeilFunc : public Bu::Formula::Func - { - public: - virtual double operator()( double x ) - { - return ceil( x ); - } - }; - - dForm.hFunc.insert( "ceil", new DblCeilFunc() ); - - class IntCeilFunc : public Bu::Formula::Func - { - public: - virtual uint32_t operator()( uint32_t x ) - { - return x; - } - }; - - uForm.hFunc.insert( "ceil", new IntCeilFunc() ); - - uForm.hVars.insert("x", 10 ); - dForm.hVars.insert("x", 10.00 ); - uForm.hVars.insert("y", 10 ); - dForm.hVars.insert("y", 10.00 ); - - for( int j = 1; j < argc; j++ ) - { - printf("u: %s = %u\n", argv[j], uForm.run( argv[j] ) ); - printf("d: %s = %f\n", argv[j], dForm.run( argv[j] ) ); - } - - return 0; -} - diff --git a/src/tests/fstratsptr.cpp b/src/tests/fstratsptr.cpp deleted file mode 100644 index 5053dd1..0000000 --- a/src/tests/fstratsptr.cpp +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/string.h" -#include "bu/atom.h" -#include "bu/sptr.h" - -class Person -{ -public: - Person(){}; - virtual ~Person(){}; - - Bu::Atom sFirstName; - Bu::Atom sLastName; -}; - -typedef Bu::SPtr PersonPtr; - -void Swap(PersonPtr one, PersonPtr two) -{ - PersonPtr three(new Person); - three->sFirstName = one->sFirstName; - three->sLastName = two->sLastName; - - printf( - "%s %s\n", - three->sFirstName->getStr(), - three->sLastName->getStr() ); -} - -int main() -{ -/* PersonPtr one(new Person); - PersonPtr two(new Person); - one->sFirstName = "Bob"; - one->sLastName = "Smith"; - two->sFirstName = "Fred"; - two->sLastName = "Carpenter"; - - Swap(one, two); -*/ - - Bu::Atom sOne, sTwo; - sOne = "Hello"; - sTwo = sOne; - - return 0; -} diff --git a/src/tests/fstrstd.cpp b/src/tests/fstrstd.cpp deleted file mode 100644 index b2fed8a..0000000 --- a/src/tests/fstrstd.cpp +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -#include "bu/string.h" - -int main() -{ - Bu::String s("Hey there, dude.\n"); - -// std::cout << s << 5; -} diff --git a/src/tests/hash.cpp b/src/tests/hash.cpp deleted file mode 100644 index 7cefb79..0000000 --- a/src/tests/hash.cpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/hash.h" -#include "bu/sptr.h" - -typedef struct Bob -{ - int nID; -} Bob; - -int main() -{ - Bu::Hash > lb; - for( int j = 0; j < 10; j++ ) - { - Bob *b = new Bob; - b->nID = j; - lb.insert( j, b ); - } - - for( int j = 0; j < 10; j++ ) - { - printf("%d\n", lb[j].getValue()->nID ); - } -} - diff --git a/src/tests/hash2.cpp b/src/tests/hash2.cpp deleted file mode 100644 index 55bb4c9..0000000 --- a/src/tests/hash2.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -#include - -int main() -{ - Bu::Hash hCmd; - - hCmd.insert("help", 5 ); - hCmd.insert("exit", 5 ); - hCmd.insert("getkey", 5 ); - hCmd.insert("setcrypt", 5 ); - hCmd.insert("user", 5 ); - hCmd.insert("pass", 5 ); - hCmd.erase("getkey"); - hCmd.erase("setcrypt"); - hCmd.insert("user", 5 ); - hCmd.insert("pass", 5 ); - hCmd.erase("pass"); - hCmd.erase("user"); - hCmd.insert("acl", 5 ); - hCmd.insert("owner", 5 ); - hCmd.insert("operator", 5 ); - hCmd.insert("admin", 5 ); - hCmd.insert("monitor", 5 ); - hCmd.insert("shutdown", 5 ); - - return 0; -} diff --git a/src/tests/heap.cpp b/src/tests/heap.cpp deleted file mode 100644 index 520a57f..0000000 --- a/src/tests/heap.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -#include - -#include "bu/formatter.h" -#include "bu/heap.h" -#include "bu/string.h" -#include "bu/file.h" - -typedef struct num -{ - num( int iNum, int iOrder ) : iNum( iNum ), iOrder( iOrder ) - { - } - - num( const num &src ) : iNum( src.iNum ), iOrder( src.iOrder ) - { - } - - int iNum; - int iOrder; - - bool operator<( const num &oth ) const - { - if( iNum == oth.iNum ) - return iOrder < oth.iOrder; - return iNum < oth.iNum; - } - bool operator>( const num &oth ) const - { - return iNum > oth.iNum; - } -} num; - -void printHeap( Bu::Heap &h, int j ) -{ -// return; - Bu::String sFName = Bu::String("graph-step-%1.dot").arg( j, Bu::Fmt().width(2).fill('0') ); - Bu::File fOut( sFName, Bu::File::WriteNew ); - Bu::Formatter f( fOut ); - f << "Graph step: " << j << ", total size: " << h.getSize() << f.nl; - for( Bu::Heap::iterator i = h.begin(); i; i++ ) - { - f << *i << f.nl; - } - f << f.nl; -} - -int main() -{ - /* - Bu::Heap hNum; - - for( int j = 0; j < 30; j++ ) - { - int r = rand()%10; - printf("Pushing: %d, top: ", r ); - hNum.enqueue( num( r, j ) ); - printf("%d\n", hNum.peek().iNum ); - } - - while( !hNum.isEmpty() ) - { - printf("(%d:%d) ", hNum.peek().iOrder, hNum.peek().iNum ); - hNum.dequeue(); - } - printf("\n"); -*/ - Bu::Heap hStr; - int j = 0; - - hStr.enqueue("George"); - printHeap( hStr, j++ ); - hStr.enqueue("George"); - printHeap( hStr, j++ ); - hStr.enqueue("Sam"); - printHeap( hStr, j++ ); - hStr.enqueue("Abby"); - printHeap( hStr, j++ ); - hStr.enqueue("Zorro"); - printHeap( hStr, j++ ); - hStr.enqueue("Brianna"); - printHeap( hStr, j++ ); - hStr.enqueue("Kate"); - printHeap( hStr, j++ ); - hStr.enqueue("Soggy"); - printHeap( hStr, j++ ); - - while( !hStr.isEmpty() ) - { - printf("\"%s\" ", hStr.dequeue().getStr() ); - printHeap( hStr, j++ ); - } - printf("\n"); - - Bu::List lStr; - - lStr.insertSorted("George"); - lStr.insertSorted("George"); - lStr.insertSorted("Sam"); - lStr.insertSorted("Abby"); - lStr.insertSorted("Zorro"); - lStr.insertSorted("Brianna"); - lStr.insertSorted("Kate"); - lStr.insertSorted("Soggy"); - for( Bu::List::iterator i = lStr.begin(); i; i++ ) - { - printf("\"%s\" ", (*i).getStr() ); - } - printf("\n"); - - return 0; -} - diff --git a/src/tests/itoheap.cpp b/src/tests/itoheap.cpp deleted file mode 100644 index ec06b90..0000000 --- a/src/tests/itoheap.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -#include -#include - -#include "bu/itoheap.h" -#include "bu/ito.h" - -class Consumer : public Bu::Ito -{ -public: - Consumer() - { - } - - virtual ~Consumer() - { - } - - void run() - { - for( int j = 0; j < 10; j++ ) - { - printf("Trying to read [%d].\n", j ); - - try - { - int iNum = hInt.dequeue( 0, 500000 ); - printf("Read %d\n", iNum ); - } - catch( Bu::HeapException &e ) - { - printf("Nothing yet...\n"); - } - } - } - - Bu::ItoHeap hInt; -}; - - -int main() -{ - Consumer c; - - for( int j = 0; j < 3; j++ ) - { - int iNum = rand()%10; - printf("Enqueuing %d.\n", iNum ); - c.hInt.enqueue( iNum ); - } - - printf("Sarting consumer.\n"); - c.start(); - - for( int j = 0; j < 5; j++ ) - { - sleep( 1 ); - int iNum = rand()%10; - printf("Enqueuing %d.\n", iNum ); - c.hInt.enqueue( iNum ); - } -} - diff --git a/src/tests/itoqueue1.cpp b/src/tests/itoqueue1.cpp deleted file mode 100644 index 27cb93c..0000000 --- a/src/tests/itoqueue1.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -#include "bu/ito.h" -#include "bu/itoqueue.h" -#include -#include - -class Reader : public Bu::Ito -{ -public: - Reader( Bu::ItoQueue &q, int id ) : - q( q ), - id( id ) - { - } - - void run() - { - for( int i = 0; i < 10; i++ ) - { - std::string *pStr = q.dequeue( true ); - if( pStr == NULL ) - { - printf("Null received...\n"); - } - else - { - printf("[%d] read: %s\n", id, pStr->c_str() ); - delete pStr; - } - usleep( (int)(((double)rand())/((double)RAND_MAX)*2000000.0) ); - } - } - -private: - Bu::ItoQueue &q; - int id; -}; - -class Writer : public Bu::Ito -{ -public: - Writer( Bu::ItoQueue &q, int id, const char *strbase ) : - q( q ), - strbase( strbase ), - id( id ) - { - } - - void run() - { - for( int i = 0; i < 11; i++ ) - { - usleep( (int)(((double)rand())/((double)RAND_MAX)*2000000.0) ); - q.enqueue( new std::string( strbase ) ); - printf("[%d] write: %s\n", id, strbase ); - } - } - -private: - Bu::ItoQueue &q; - const char *strbase; - int id; -}; - -int main() -{ - Writer *wr[5]; - Reader *rd[5]; - const char bob[][7]={ - {"Test 1"}, - {"Test 2"}, - {"Test 3"}, - {"Test 4"}, - {"Test 5"} - }; - - Bu::ItoQueue q; - - for( int j = 0; j < 5; j++ ) - { - wr[j] = new Writer( q, j, bob[j] ); - rd[j] = new Reader( q, j ); - } - - for( int j = 0; j < 5; j++ ) - { - rd[j]->start(); - } - - for( int j = 0; j < 5; j++ ) - { - wr[j]->start(); - } - - for( int j = 0; j < 5; j++ ) - { - rd[j]->join(); - } - - for( int j = 0; j < 5; j++ ) - { - delete wr[j]; - delete rd[j]; - } - - return 0; -} - diff --git a/src/tests/itoqueue2.cpp b/src/tests/itoqueue2.cpp deleted file mode 100644 index 10bc566..0000000 --- a/src/tests/itoqueue2.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -#include "bu/ito.h" -#include "bu/itoqueue.h" -#include -#include - -class Reader : public Bu::Ito -{ -public: - Reader( Bu::ItoQueue &q, int id ) : - q( q ), - id( id ) - { - } - - void run() - { - for( int i = 0; i < 10; i++ ) - { - std::string *pStr = q.dequeue( 0, 500000 ); - if( pStr == NULL ) - { - printf("Null received...\n"); - i--; - } - else - { - printf("[%d] read: %s\n", id, pStr->c_str() ); - delete pStr; - } - } - } - -private: - Bu::ItoQueue &q; - int id; -}; - -class Writer : public Bu::Ito -{ -public: - Writer( Bu::ItoQueue &q, int id, const char *strbase ) : - q( q ), - strbase( strbase ), - id( id ) - { - } - - void run() - { - for( int i = 0; i < 11; i++ ) - { - sleep( 2 ); - printf("[%d] write: %s\n", id, strbase ); - q.enqueue( new std::string( strbase ) ); - } - } - -private: - Bu::ItoQueue &q; - const char *strbase; - int id; -}; - -int main() -{ - printf("ETIMEDOUT: %d\n", ETIMEDOUT ); - Bu::ItoQueue q; - Writer wr( q, 0, "writer" ); - Reader rd( q, 0 ); - - rd.start(); - wr.start(); - - rd.join(); - wr.join(); - - return 0; -} - diff --git a/src/tests/itoserver.cpp b/src/tests/itoserver.cpp deleted file mode 100644 index 48ef527..0000000 --- a/src/tests/itoserver.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/itoserver.h" -#include "bu/protocol.h" -#include "bu/client.h" - -#define BU_TRACE -#include "bu/trace.h" - -class ProtocolEcho : public Bu::Protocol -{ -public: - ProtocolEcho() - { - TRACE(); - } - virtual ~ProtocolEcho() - { - TRACE(); - } - - virtual void onNewConnection( Bu::Client * ) - { - TRACE(); - // Huh... - } - - virtual void onNewData( Bu::Client *pClient ) - { - TRACE(); - char buf[1024]; - while( pClient->hasInput() ) - { - int iAmnt = pClient->read( buf, 1024 ); - pClient->write( buf, iAmnt ); - } - } -}; - -class TestServer : public Bu::ItoServer -{ -public: - TestServer() - { - TRACE(); - } - virtual ~TestServer() - { - TRACE(); - } - - virtual void onNewConnection( Bu::Client *pClient, int ) - { - TRACE(); - pClient->setProtocol( new ProtocolEcho() ); - } - - virtual void onClosedConnection( Bu::Client *pClient ) - { - TRACE(); - delete pClient->getProtocol(); - } -}; - -int main() -{ - TRACE(); - - TestServer ts; - - ts.addPort( 5555 ); - ts.start(); - ts.join(); -} - diff --git a/src/tests/list.cpp b/src/tests/list.cpp deleted file mode 100644 index aa3d32d..0000000 --- a/src/tests/list.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/list.h" -#include - -typedef struct Bob -{ - int nID; -} Bob; - -int main() -{ - Bu::List l; - - l.append( 0 ); - - for( int j = 3; j <= 21; j += 3 ) - { - l.append( j ); - l.prepend( -j ); - } - - { - Bu::List::iterator i = l.begin(); - Bu::List::iterator j = i; - int a, b; - a = *j; - printf("end: %s\n", (j != l.end())?"no":"yes"); - j--; - printf("end: %s\n", (j != l.end())?"no":"yes"); - j++; - printf("end: %s\n", (j != l.end())?"no":"yes"); - i = j; - b = *i; - printf("%d -> %d\n", a, b ); - } - - for( Bu::List::iterator i = l.begin(); i != l.end(); i++ ) - { - printf("%d ", *i ); - } - printf("\n"); - for( Bu::List::iterator i = l.begin(); i != l.end(); i++ ) - { - Bu::List::iterator j = i; j--; - l.erase( i ); - i = j; - if( i != l.end() ) - printf("!%d ", *i ); - } - - printf("\n\n"); - - Bu::List lb; - for( int j = 0; j < 10; j++ ) - { - Bob b; - b.nID = j; - lb.append( b ); - } - - const Bu::List rb = lb; - - for( Bu::List::const_iterator i = rb.begin(); i != rb.end(); i++ ) - { - //i->nID += 2; - //(*i).nID = 4; - printf("%d ", i->nID ); - } - printf("\n\n"); -} - diff --git a/src/tests/list2.cpp b/src/tests/list2.cpp deleted file mode 100644 index 567370e..0000000 --- a/src/tests/list2.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -#include - -using namespace Bu; - -int main() -{ - List lInt; - - lInt.append( 512 ); - lInt.append( 1024 ); - lInt.append( 4096 ); - lInt.append( 12 ); - lInt.erase( 12 ); - lInt.append( 12 ); - lInt.erase( 12 ); - lInt.append( 12 ); -} - diff --git a/src/tests/listsort.cpp b/src/tests/listsort.cpp deleted file mode 100644 index 4873a05..0000000 --- a/src/tests/listsort.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -#include -#include - -using namespace Bu; - -int main() -{ - /* - List il; - il.append( 5 ); - il.append( 12 ); - il.append( 0 ); - il.append( 7 ); - il.append( 3 ); - il.append( 5 ); - Bu::__basicLTCmp cmp; - il.sortI( cmp ); - */ - - String a("Soggy"), b("Sam"); - - if( a < b ) - { - sio << "Bad" << sio.nl; - } - else - { - sio << "Good" << sio.nl; - } - - typedef List StrList; - - StrList lNames; - - lNames.append("George"); - lNames.append("Sam"); - lNames.append("Abby"); - lNames.append("Zorro"); - lNames.append("Brianna"); - lNames.append("Kate"); - lNames.append("Soggy"); - - sio << "Names: " << lNames << sio.nl; - lNames.sort(); - - sio << "Names: " << lNames << sio.nl; - - StrList lNames2; - - lNames2.insertSorted("George"); - lNames2.insertSorted("Sam"); - lNames2.insertSorted("Abby"); - lNames2.insertSorted("Zorro"); - lNames2.insertSorted("Brianna"); - lNames2.insertSorted("Kate"); - lNames2.insertSorted("Soggy"); - - sio << "Names: " << lNames2 << sio.nl; - - if( lNames == lNames2 ) - { - sio << "They're the same." << sio.nl; - } - else - { - sio << "They're different." << sio.nl; - } - - return 0; -} - diff --git a/src/tests/logger.cpp b/src/tests/logger.cpp deleted file mode 100644 index e97193c..0000000 --- a/src/tests/logger.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/logger.h" -#include -#include - -class Thing -{ - public: - Thing() - { - lineLog( 2, "Want a thing?"); - } - - void go( int ) - { - lineLog( 1, "GO!!!!"); - } -}; - -int main() -{ - setLogLevel( 4 ); - setLogFormat("%L: %y-%02m-%02d %h:%02M:%02s %f:%l:%F: %t"); - lineLog( 5, "Hey, error: %s", strerror( errno ) ); - - logHexDump( 5, "This is a test of the hex-dump facility", 16, "Random stuff"); - - Thing gh; - gh.go( 6 ); -} - diff --git a/src/tests/md5.cpp b/src/tests/md5.cpp deleted file mode 100644 index a32f669..0000000 --- a/src/tests/md5.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/sio.h" -#include "bu/file.h" -#include "bu/md5.h" - -using Bu::sio; - -int main( int argc, char *argv[] ) -{ - argv++, argc--; - for(; *argv; argv++ ) - { - Bu::File fIn( *argv, Bu::File::Read ); - Bu::Md5 m; - - char buf[100000]; - for(;;) - { - int iRead = fIn.read( buf, 100000 ); - m.addData( buf, iRead ); - if( iRead < 100000 ) - break; - } - - sio << m.getHexResult() << " *" << *argv << sio.nl; - } -} - diff --git a/src/tests/minicron.cpp b/src/tests/minicron.cpp deleted file mode 100644 index aed63e2..0000000 --- a/src/tests/minicron.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/minicron.h" -#include "bu/sio.h" - -#include - -using namespace Bu; - -Bu::MiniCron mCron; - -void job0( Bu::MiniCron::Job &job ) -{ - sio << time( NULL ) << ": job0( id = " << job.getId() << ", count = " - << job.getRunCount() << ")" << sio.nl; -} - -void job1( Bu::MiniCron::Job &job ) -{ - sio << time( NULL ) << ": job1( id = " << job.getId() << ", count = " - << job.getRunCount() << ")" << sio.nl; - mCron.removeJob( 4 ); -} - -void job2( Bu::MiniCron::Job &job ) -{ - sio << time( NULL ) << ": job2( id = " << job.getId() << ", count = " - << job.getRunCount() << ")" << sio.nl; -} - -void job3( Bu::MiniCron::Job &job ) -{ - sio << time( NULL ) << ": job3( id = " << job.getId() << ", count = " - << job.getRunCount() << ")" << sio.nl; -} - -int main() -{ - mCron.addJob( - "job0", slot( &job0 ), MiniCron::TimerInterval( time(NULL)+3, 5 ) ); - mCron.addJob( - "job1", slot( &job1 ), MiniCron::TimerInterval( time(NULL)+10, 8 ) ); - mCron.addJob( - "job2", slot( &job2 ), MiniCron::TimerBasic("weekly wed 17") ); - mCron.addJob( - "job3", slot( &job3 ), MiniCron::TimerInterval( time(NULL)+1, 2 ) ); - - sio << time( NULL ) << ": Program started." << sio.nl; - - for(;;) - { - usleep( 50000 ); - mCron.poll(); - } - - return 0; -} - diff --git a/src/tests/mmparse.cpp b/src/tests/mmparse.cpp deleted file mode 100644 index c1ce862..0000000 --- a/src/tests/mmparse.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/minimacro.h" -#include "bu/string.h" - -int main() -{ - Bu::MiniMacro mm; - - mm.addVar("name", "Mike"); - mm.addVar("age", "no"); - - printf("%s\n", mm.parse("Hey there {=name:toupper():tolower()}, how are you?").getStr() ); - - return 0; -} - diff --git a/src/tests/multiserver.cpp b/src/tests/multiserver.cpp deleted file mode 100644 index 12f4681..0000000 --- a/src/tests/multiserver.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/multiserver.h" -#include "bu/protocol.h" -#include "bu/client.h" - -class ProtocolRaw : public Bu::Protocol -{ -public: - virtual void onNewConnection( Bu::Client *pClient ) - { - pClient->write("Raw echo\n"); - } - - virtual void onNewData( Bu::Client *pClient ) - { - char buf[1024]; - while( pClient->hasInput() ) - { - int iAmnt = pClient->read( buf, 1024 ); - pClient->write( buf, iAmnt ); - } - } -}; - -class ProtocolRot13 : public Bu::Protocol -{ -public: - virtual void onNewConnection( Bu::Client *pClient ) - { - pClient->write("Rot13 echo\n"); - } - - virtual void onNewData( Bu::Client *pClient ) - { - while( pClient->hasInput() ) - { - char sTmp[1024]; - int iAmnt = pClient->read( sTmp, 1024 ); - for( int j = 0; j < iAmnt; j++ ) - { - if( sTmp[j] >= 'a' && sTmp[j] <= 'z' ) - { - sTmp[j] = ((sTmp[j]-'a'+13)%26) + 'a'; - } - else if( sTmp[j] >= 'A' && sTmp[j] <= 'Z' ) - { - sTmp[j] = ((sTmp[j]-'A'+13)%26) + 'A'; - } - } - pClient->write( sTmp, iAmnt ); - } - } -}; - -int main() -{ - Bu::MultiServer msMain; - - msMain.addProtocol( Bu::genProtocol, 5550 ); - msMain.addProtocol( Bu::genProtocol, 5551 ); - msMain.setTimeout( 5, 0 ); - - for(;;) - { - msMain.scan(); - } - - return 0; -} - diff --git a/src/tests/procs.cpp b/src/tests/procs.cpp deleted file mode 100644 index 94d2cc5..0000000 --- a/src/tests/procs.cpp +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/process.h" - -#include - -int main() -{ - Bu::Process p( Bu::Process::Both, "/bin/bash", "/bin/bash", "-c", "echo Hello 1>&2; echo StdOut; sleep 1; echo Yup; echo Yup 1>&2", NULL ); - - char buf[1000]; - while( !p.isEos() ) - { - bool out, err; - p.select( out, err ); - if( out ) - { - int iSize = p.read( buf, 1000 ); - printf("::read=%d::\n", iSize ); - fwrite( buf, iSize, 1, stdout ); - } - if( err ) - { - int iSize = p.readErr( buf, 1000 ); - printf("::readErr=%d::\n", iSize ); - fwrite( buf, iSize, 1, stdout ); - } - } - - return 0; -} - diff --git a/src/tests/queuebuf.cpp b/src/tests/queuebuf.cpp deleted file mode 100644 index f872738..0000000 --- a/src/tests/queuebuf.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -#include - -using namespace Bu; - -int main() -{ - static const char *src = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789%#"; - QueueBuf qb; - - for( int j = 0; j < 8; j++ ) - { - qb.write( src, 60 ); - } - - char buf[11], bufp[11]; - while( !qb.isEos() ) - { - int iAmntPeek = qb.peek( bufp, 9 ); - int iAmntRead = qb.read( buf, 9 ); - if( iAmntPeek != iAmntRead ) - sio << "Differ: " << iAmntPeek << " vs " << iAmntRead << sio.nl; - buf[iAmntRead] = '\0'; - bufp[iAmntPeek] = '\0'; - if( memcmp( buf, bufp, iAmntPeek ) ) - { - sio << "Buffers differ" << sio.nl - << " " << buf << sio.nl - << " " << bufp << sio.nl; - } - else - sio << "Read: >>" << buf << "<<" << sio.nl; - } - - sio << sio.nl << sio.nl << sio.nl << "Seek test:" << sio.nl << sio.nl; - - for( int j = 0; j < 5; j++ ) - { - qb.write( src, 25 ); - qb.write( src+10, 25 ); - } - - char bufa[26]; - char bufb[26]; - ::memcpy( bufb, src+10, 15 ); - ::memcpy( bufb+15, src+10, 10 ); - bufb[25] = '\0'; - sio << "Comparing to '" << bufb << "'" << sio.nl; - qb.seek( 10 ); - while( !qb.isEos() ) - { - bufa[qb.read( bufa, 25 )] = '\0'; - qb.seek( 25 ); - if( memcmp( bufa, bufb, 25 ) ) - sio << "Differ?" << sio.nl; - sio << "=== '" << bufa << "' == '" << bufb << "'" << sio.nl; - } -} - diff --git a/src/tests/regex.cpp b/src/tests/regex.cpp deleted file mode 100644 index 376fbb2..0000000 --- a/src/tests/regex.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -#include - -int main( int argc, char *argv[] ) -{ - if( argc < 3 ) - { - printf("No... %s \n\n", argv[0] ); - return 0; - } - - Bu::RegEx re( argv[1] ); - - printf("Regex: %s\n", argv[1] ); - printf("Match: %s\n", argv[2] ); - - if( re.execute( argv[2] ) ) - { - for( int j = 0; j < re.getNumSubStrings(); j++ ) - { - printf("SubStr %d: %s\n", j, re.getSubString( j ).getStr() ); - } - } - else - { - printf("Regex did not match.\n"); - } - - return 0; -} - diff --git a/src/tests/ringbuffer.cpp b/src/tests/ringbuffer.cpp deleted file mode 100644 index da5126c..0000000 --- a/src/tests/ringbuffer.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/ringbuffer.h" -#include -#include -#include - -int main() -{ - Bu::RingBuffer ibuf( 10 ); - - for( int k = 0; k < 2; k++ ) - { - int j = 1; - for(; j < 7; j++ ) - { - ibuf.enqueue( j ); - } - - for(; j < 20; j++ ) - { - ibuf.enqueue( j ); - printf("- %d\n", ibuf.dequeue() ); - } - - for(;;) - { - if( ibuf.isEmpty() ) break; - printf(". %d\n", ibuf.dequeue() ); - } - } -} - diff --git a/src/tests/rot13.cpp b/src/tests/rot13.cpp deleted file mode 100644 index 1530af3..0000000 --- a/src/tests/rot13.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/protocol.h" -#include "bu/multiserver.h" -#include "bu/client.h" -#include "bu/filter.h" - -using namespace Bu; - -class Rot13Filter : public Filter -{ -public: - Rot13Filter( Stream &next ) : - Filter( next ) - { - } - - virtual ~Rot13Filter() - { - } - - virtual void start() - { - } - - virtual Bu::size stop() - { - return 0; - } - - virtual Bu::size read( void *pBuf, Bu::size nBytes ) - { - return rNext.read( pBuf, nBytes ); - } - - virtual Bu::size write( const void *pBuf, Bu::size nBytes ) - { - const char *cBuf = (const char *)pBuf; - char *buf = new char[nBytes]; - for( Bu::size j = 0; j < nBytes; j++ ) - { - if( cBuf[j] >= 'a' && cBuf[j] <= 'z' ) - buf[j] = (cBuf[j]-'a'+13)%26+'a'; - else if( cBuf[j] >= 'A' && cBuf[j] <= 'Z' ) - buf[j] = (cBuf[j]-'A'+13)%26+'A'; - else - buf[j] = cBuf[j]; - } - rNext.write( buf, nBytes ); - delete[] buf; - return nBytes; - } -}; - -class Rot13Protocol : public Protocol -{ -public: - void onNewConnection( Bu::Client *pClient ) - { - pClient->pushFilter(); - } - - void onNewData( Bu::Client *pClient ) - { - char buf[1024]; - while( pClient->hasInput() ) - { - int iAmnt = pClient->read( buf, 1024 ); - pClient->write( buf, iAmnt ); - } - } -}; - -int main() -{ - MultiServer xSrv; - - xSrv.setTimeout( 5 ); - xSrv.addProtocol( genProtocol, 9999 ); - - for(;;) - xSrv.scan(); - - return 0; -} - diff --git a/src/tests/serverticks.cpp b/src/tests/serverticks.cpp deleted file mode 100644 index 3872a16..0000000 --- a/src/tests/serverticks.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/server.h" -#include "bu/client.h" -#include "bu/protocol.h" -#include - -class TickProtocol : public Bu::Protocol -{ -public: - TickProtocol() - { - } - - virtual ~TickProtocol() - { - } - - virtual void onTick( Bu::Client *pClient ) - { - printf("tick!\n"); - pClient->write("tick!\n"); - } -}; - -class TickServer : public Bu::Server -{ -public: - TickServer() - { - } - - virtual ~TickServer() - { - } - - virtual void onNewConnection( Bu::Client *pClient, int ) - { - pClient->setProtocol( new TickProtocol() ); - } - - virtual void onClosedConnection( Bu::Client *pClient ) - { - delete pClient->getProtocol(); - } -}; - -int main( int , char *[] ) -{ - TickServer ts; - - ts.setTimeout( 1, 0 ); - ts.setAutoTick(); - ts.addPort( 5555 ); - - for(;;) - { - ts.scan(); - sleep( 1 ); - } - - return 0; -} - diff --git a/src/tests/sha1.cpp b/src/tests/sha1.cpp deleted file mode 100644 index ac795e7..0000000 --- a/src/tests/sha1.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/sio.h" -#include "bu/file.h" -#include "bu/sha1.h" - -using namespace Bu; - -int main( int argc, char *argv[] ) -{ - argv++, argc--; - for(; *argv; argv++ ) - { - Bu::File fIn( *argv, Bu::File::Read ); - Bu::Sha1 m; - - char buf[100000]; - for(;;) - { - int iRead = fIn.read( buf, 100000 ); - m.addData( buf, iRead ); - if( iRead < 100000 ) - break; - } - - Bu::String sRes = m.getResult(); - for( Bu::String::iterator i = sRes.begin(); i; i++ ) - { - sio << Fmt::hex(2,false) << (int)(unsigned char)(*i); - } - sio << " *" << *argv << sio.nl; - } -} - diff --git a/src/tests/sharedcore.cpp b/src/tests/sharedcore.cpp deleted file mode 100644 index c68f07b..0000000 --- a/src/tests/sharedcore.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/sharedcore.h" -#include "bu/sio.h" - -using namespace Bu; - -struct ShintCore -{ - int val; -}; -class Shint : public Bu::SharedCore -{ -public: - Shint() - { - core->val = 0; - } - - Shint( int val ) - { - core->val = val; - } - - int getVal() const - { - return core->val; - } - - void setValBad( int val ) - { - core->val = val; - } - - void setVal( int val ) - { - _hardCopy(); - core->val = val; - } - - bool operator==( const Shint &rhs ) - { - if( core == rhs.core ) - { - sio << "Same pointer (" << Fmt::ptr() << core << ")" << sio.nl; - return true; - } - if( core->val == rhs.core->val ) - { - sio << "Same value " << core->val << " (" - << Fmt::ptr() << core << " vs " - << Fmt::ptr() << rhs.core << ")" - << sio.nl; - return true; - } - sio << "Different" << sio.nl; - return false; - } -}; - -#define line( x ) sio << __FILE__ ": " << __LINE__ << ": " << #x << sio.nl; x - -int main() -{ - line( Shint a; ) - line( Shint b( 5 ); ) - - line( a == b; ) - - line( b = a; ) - line( a == b; ) - - line( b.setValBad( 12 ); ) - sio << a.getVal() << " != " << b.getVal() << sio.nl; - line( a == b; ) - - line( a.setVal( 3 ); ) - sio << a.getVal() << " != " << b.getVal() << sio.nl; - line( a == b; ) - - line( a.setVal( b.getVal() ); ) - line( a == b; ) - - { - Shint c( b ); - Shint d( c ); - sio << c.getVal(); - d.setVal( 43 ); - } - - sio << b.getVal(); -} - diff --git a/src/tests/signals.cpp b/src/tests/signals.cpp deleted file mode 100644 index 14bbc9c..0000000 --- a/src/tests/signals.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -#include - -using namespace Bu; - -class Thing -{ -public: - Thing() : - iState( 82731 ) - { - } - - virtual ~Thing() - { - } - - void fnc0() - { - sio << iState << ": void fnc0()" << sio.nl; - } - - void fnc1( int a ) - { - sio << iState << ": void fnc1( " << a << " )" << sio.nl; - } - - void fnc2( int a, Bu::String b ) - { - sio << iState << ": void fnc2( " << a << ", \"" << b << "\" )" << sio.nl; - } - - void fnc3( int a, Bu::String b, double c ) - { - sio << iState << ": void fnc3( " << a << ", \"" << b << "\", " << c << " )" << sio.nl; - } - - void fnc4( int a, Bu::String b, double c, char d ) - { - sio << iState << ": void fnc4( " << a << ", \"" << b << "\", " << c << ", '" << d << "' )" << sio.nl; - } - - void fnc5( int a, Bu::String b, double c, char d, long e ) - { - sio << iState << ": void fnc5( " << a << ", \"" << b << "\", " << c << ", '" << d << "', " << e << " )" << sio.nl; - } - -private: - int iState; -}; - -void pfnc0() -{ - sio << ": void pfnc0()" << sio.nl; -} - -void pfnc1( int a ) -{ - sio << ": void pfnc1( " << a << " )" << sio.nl; -} - -void pfnc2( int a, Bu::String b ) -{ - sio << ": void pfnc2( " << a << ", \"" << b << "\" )" << sio.nl; -} - -void pfnc3( int a, Bu::String b, double c ) -{ - sio << ": void pfnc3( " << a << ", \"" << b << "\", " << c << " )" << sio.nl; -} - -void pfnc4( int a, Bu::String b, double c, char d ) -{ - sio << ": void pfnc4( " << a << ", \"" << b << "\", " << c << ", '" << d << "' )" << sio.nl; -} - -void pfnc5( int a, Bu::String b, double c, char d, long e ) -{ - sio << ": void pfnc5( " << a << ", \"" << b << "\", " << c << ", '" << d << "', " << e << " )" << sio.nl; -} - -void callit( Signal0 sig ) -{ - sig(); -} - -int main() -{ - Thing t; - - Signal0 cb0( slot( &t, &Thing::fnc0 ) ); - cb0(); - cb0 = slot( &pfnc0 ); - cb0(); - - Signal1 cb1( slot( &t, &Thing::fnc1 ) ); - cb1( 5 ); - cb1 = slot( &pfnc1 ); - cb1( 5 ); - - Signal2 cb2( slot( &t, &Thing::fnc2 ) ); - cb2( 5, "Hi there" ); - cb2 = slot( &pfnc2 ); - cb2( 5, "Hi there" ); - - Signal3 cb3( slot( &t, &Thing::fnc3 ) ); - cb3( 5, "Hi there", 12.85 ); - cb3 = slot( &pfnc3 ); - cb3( 5, "Hi there", 12.85 ); - - Signal4 cb4( slot( &t, &Thing::fnc4 ) ); - cb4( 5, "Hi there", 12.85, 'z' ); - cb4 = slot( &pfnc4 ); - cb4( 5, "Hi there", 12.85, 'z' ); - - Signal5 cb5( slot( &t, &Thing::fnc5 ) ); - cb5( 5, "Hi there", 12.85, 'z', 849 ); - cb5 = slot( &pfnc5 ); - cb5( 5, "Hi there", 12.85, 'z', 849 ); - -// Signal1 cb1( slot( &t, &Thing::fnc1 ) ); -// sio << "Result: " << cb1( 5 ) << sio.nl; -} - diff --git a/src/tests/size.cpp b/src/tests/size.cpp deleted file mode 100644 index dfad16f..0000000 --- a/src/tests/size.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/hash.h" -#include "bu/string.h" - -#define pSize( t ) printf("%15s: %db\n", #t, sizeof( t ) ); - -int main() -{ - typedef Bu::Hash charcharHash; - typedef Bu::Hash strstrHash; - pSize( Bu::String ); - pSize( charcharHash ); - pSize( strstrHash ); -} diff --git a/src/tests/socketblock.cpp b/src/tests/socketblock.cpp deleted file mode 100644 index e36bb33..0000000 --- a/src/tests/socketblock.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/ito.h" -#include "bu/tcpsocket.h" -#include "bu/tcpserversocket.h" -#include -#include - -class TstServer : public Bu::Ito -{ -public: - TstServer() : - s( 55678 ) - { - } - - virtual void run() - { - Bu::TcpSocket c = s.accept( 45, 0 ); - printf("TstServer: Accetped connection.\n"); fflush( stdout ); - - sleep( 1 ); - printf("TstServer: Trying to read 10 bytes...\n"); fflush( stdout ); - - char buf[10]; - size_t nRead = c.read( buf, 10 ); - printf("TstServer: Got %d bytes...\n", nRead ); fflush( stdout ); - - printf("TstServer: Closing connection...\n"); fflush( stdout ); - c.close(); - } - - Bu::TcpServerSocket s; -}; - -int main() -{ - TstServer ts; - - ts.start(); - - printf("main: Connecting to server.\n"); fflush( stdout ); - Bu::TcpSocket s( "localhost", 55678 ); - - printf("main: Sending 4 bytes.\n"); fflush( stdout ); - s.write( "aoeu", 4 ); - - printf("main: Sleeping 10 seconds for good measure.\n"); fflush( stdout ); - sleep( 10 ); -} - diff --git a/src/tests/socketbreak.cpp b/src/tests/socketbreak.cpp deleted file mode 100644 index d58ebcf..0000000 --- a/src/tests/socketbreak.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/tcpserversocket.h" -#include "bu/tcpsocket.h" -#include - -int main() -{ - Bu::TcpServerSocket sSrv( 9987 ); - - Bu::TcpSocket sSend("localhost", 9987 ); - - Bu::TcpSocket sRecv( sSrv.accept() ); - - printf("Connected sockets.\n"); - - sleep( 1 ); - printf("Closing sRecv.\n"); - sRecv.close(); - sleep( 1 ); - - char buf[3]; - printf("About to write.\n"); - printf("write: %lld\n", sSend.write("hi", 2 ) ); - printf("About to read.\n"); - printf("read: %lld\n", sSend.read( buf, 2 ) ); - - return 0; -} - diff --git a/src/tests/speed.cpp b/src/tests/speed.cpp deleted file mode 100644 index 2fa29aa..0000000 --- a/src/tests/speed.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/string.h" -#include - -template -struct tstCopy -{ - tstCopy( const a &src ) : - src( src ) - { - } - - void operator()() - { - a tmp = src; - } - - a src; -}; - -template -double runTest( f fnc ) -{ - struct timeval tStart, tEnd; - int j = 0; - gettimeofday( &tStart, NULL ); - for(; j < 500000; j++ ) - fnc(); - gettimeofday( &tEnd, NULL ); - - return (double)(tEnd.tv_sec-tStart.tv_sec)+ - (double)(tEnd.tv_usec-tStart.tv_usec)/1000000.0; -} - -template -void fullTest( tst t ) -{ - double dTotal; - int iCount = 10; - for( int j = 0; j < iCount; j++ ) - dTotal += runTest( t ); - printf("Average time: %f\n", dTotal/iCount ); -} - -int main() -{ - Bu::String str; - for( int j = 0; j < 500; j++ ) - str.append("Hey, this is a test string. It will be reapeated many, many times. How's that?"); - fullTest( tstCopy( str ) ); -} - diff --git a/src/tests/stdstream.cpp b/src/tests/stdstream.cpp deleted file mode 100644 index 95df42e..0000000 --- a/src/tests/stdstream.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/sio.h" - -using Bu::sio; -using Bu::Fmt; - -int main() -{ - sio << "Hello there" << sio.nl; - - sio << "sizeof(Fmt) = " << sizeof(Fmt) << sio.nl; - - sio << -123 << ", " << 0 << ", " << 123 << sio.nl; - - sio << "+----------+" << sio.nl; - sio << "|" << Fmt( 10, 10, Fmt::Center ) << "Test" << "|" << sio.nl; - sio << "+----------+" << sio.nl; - sio << "|" << Fmt( 10, 10, Fmt::Left ) << 123 << "|" << sio.nl; - sio << "|" << Fmt( 10, 10, Fmt::Center ) << 123 << "|" << sio.nl; - sio << "|" << Fmt( 10, 10, Fmt::Right ) << 123 << "|" << sio.nl; - sio << "+----------+" << sio.nl; - - sio << Fmt(10,Fmt::Left) << "Hexcode:" << Fmt::ptr() << (void*)(&sio) << sio.nl; - - sio << 0.123 << sio.nl; - sio << true << " and then " << false << sio.nl; - - for( int j = 2; j <= 36; j++ ) - sio << "radix(" << j << ") = " << Fmt().radix( j ).width( 8 ).align( Fmt::Right ) << 255 << sio.nl; - - return 0; -} - diff --git a/src/tests/streamstack.cpp b/src/tests/streamstack.cpp deleted file mode 100644 index 4a0e128..0000000 --- a/src/tests/streamstack.cpp +++ /dev/null @@ -1,100 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/streamstack.h" - -#include "bu/file.h" -#include "bu/base64.h" -#include "bu/bzip2.h" - -#include "bu/sio.h" - -#include - -using namespace Bu; - -class DoStuff -{ -public: - DoStuff( Bu::Stream &rStream ) : - rStream( rStream ) - { - } - - virtual ~DoStuff() - { - } - - void write() - { - Bu::String s; - time_t tNow = time( NULL ); - s = ctime( &tNow ); - long lSize = s.getSize()-1; - rStream.write( &lSize, sizeof(long) ); - rStream.write( s.getStr(), lSize ); - } - - void read() - { - Bu::String s; - long lSize; - rStream.read( &lSize, sizeof(long) ); - s.setSize( lSize ); - rStream.read( s.getStr(), lSize ); - sio << "Read str(" << lSize << ") = '" << s << "'" << sio.nl; - } - -private: - Bu::Stream &rStream; -}; - -int main() -{ - Bu::StreamStack ss; - - DoStuff ds( ss ); - - try - { - ds.write(); - sio << "This shouldn't have worked." << sio.nl; - } - catch( Bu::ExceptionBase &e ) - { - sio << "Got exception, this is good: " << e.what() << sio.nl; - } - - ss.setStream( new Bu::File("Hello.test", Bu::File::WriteNew ) ); - - ds.write(); - - ss.pushFilter(); - - ds.write(); - - ss.pushFilter(); - - ds.write(); - - ss.clear(); - - ss.setStream( new Bu::File("Hello.test", Bu::File::Read ) ); - - ds.read(); - - ss.pushFilter(); - - ds.read(); - - ss.pushFilter(); - - ds.read(); - - return 0; -} - diff --git a/src/tests/string.cpp b/src/tests/string.cpp deleted file mode 100644 index b37460e..0000000 --- a/src/tests/string.cpp +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/hash.h" -#include "bu/string.h" -#include -#include - -#ifndef WIN32 -inline double getTime() -{ - struct timeval tv; - gettimeofday( &tv, NULL ); - return ((double)tv.tv_sec) + ((double)tv.tv_usec/1000000.0); -} -#else -#include "windows.h" -#include "winbase.h" -inline double getTime() -{ - uint32_t t = (uint32_t) GetTickCount(); - return (double) t / 1000.0; -} -#endif - -Bu::String genThing() -{ - Bu::String bob; - bob.append("ab "); - bob += "cd "; - bob += "efg"; - - printf("---bob------\n%08tX: %s\n", (ptrdiff_t)bob.getStr(), - bob.getStr() ); - return bob; -} - -void thing( Bu::String str ) -{ - printf("Hey: %s\n", str.getStr() ); -} - -void copyfunc( std::string temp ) -{ - temp += "Hi"; -} - -void copyfunc( Bu::String temp ) -{ - temp += "Hi"; -} - -void doTimings() -{ - Bu::String fs1, fs2; - std::string ss1, ss2; - double dStart, dEnd, tfs1, tfs2, tfs3, tss1, tss2, tss3; - int nChars = 50000000, nChunks=50000, nCopies=500000000, nChunkSize=1024*4; - char *buf = new char[nChunkSize]; - memset( buf, '!', nChunkSize ); - - printf("Timing Bu::String single chars...\n"); - dStart = getTime(); - for( int j = 0; j < nChars; j++ ) fs1 += (char)('a'+(j%26)); - fs1.getStr(); - dEnd = getTime(); - tfs1 = dEnd-dStart; - - printf("Timing std::string single chars...\n"); - dStart = getTime(); - for( int j = 0; j < nChars; j++ ) ss1 += (char)('a'+(j%26)); - ss1.c_str(); - dEnd = getTime(); - tss1 = dEnd-dStart; - - printf("Timing Bu::String %d char chunks...\n", nChunkSize); - dStart = getTime(); - for( int j = 0; j < nChunks; j++ ) fs2.append(buf, nChunkSize); - fs2.getStr(); - dEnd = getTime(); - tfs2 = dEnd-dStart; - - printf("Timing std::string %d char chunks...\n", nChunkSize); - dStart = getTime(); - for( int j = 0; j < nChunks; j++ ) ss2.append(buf, nChunkSize); - ss2.c_str(); - dEnd = getTime(); - tss2 = dEnd-dStart; - - fs2 = "Hello there."; - ss2 = "Hello there."; - printf("Timing Bu::String copies...\n"); - dStart = getTime(); - for( int j = 0; j < nCopies; j++ ) Bu::String stmp = fs2; - dEnd = getTime(); - tfs3 = dEnd-dStart; - - printf("Timing std::string copies...\n"); - dStart = getTime(); - for( int j = 0; j < nCopies; j++ ) std::string stpm = ss2; - dEnd = getTime(); - tss3 = dEnd-dStart; - - printf( - "Results: singles: chunks: copies:\n" - "Bu::String %15.2f/s %15.2f/s %15.2f/s\n" - "std::string %15.2f/s %15.2f/s %15.2f/s\n", - nChars/tfs1, nChunks/tfs2, nCopies/tfs3, - nChars/tss1, nChunks/tss2, nCopies/tss3 ); - - delete[] buf; -} - -#define pem printf("---------\n%08tX: %s\n%08tX: %s\n", (ptrdiff_t)str.getConstStr(), str.getConstStr(), (ptrdiff_t)str2.getConstStr(), str2.getConstStr() ); -int main( ) -{ -// Bu::String fs1; -// for( int j = 0; j < 500000; j++ ) fs1 += (char)('a'+(j%26)); -// return 0; - - Bu::String str("th"); - - str.prepend("Hello "); - str.append("ere."); - - Bu::String str2( str ); - pem; - str += " What's up?"; - pem; - str2 += " How are you?"; - pem; - str = str2; - pem; - - str2 = genThing(); - pem; - - str = str2; - pem; - - thing( str2 ); - thing("test."); - - printf("%d == %d\n", Bu::__calcHashCode( str ), Bu::__calcHashCode( str.getStr() ) ); - - doTimings(); - - return 0; -} - diff --git a/src/tests/stringspeed.cpp b/src/tests/stringspeed.cpp deleted file mode 100644 index 5636de7..0000000 --- a/src/tests/stringspeed.cpp +++ /dev/null @@ -1,122 +0,0 @@ -#include - -#include -#include - -void timeit( void (*func)(), const char *sName, int iIter ) -{ - struct timeval ts, te; - - gettimeofday( &ts, NULL ); - for( int j = 0; j < iIter; j++ ) - { - func(); - } - gettimeofday( &te, NULL ); - - double dTotal = (double)(te.tv_sec-ts.tv_sec) + (double)(te.tv_usec-ts.tv_usec)/1000000.0; - printf("%10s: %f spi (%f total)\n", sName, dTotal/iIter, dTotal ); -} - -void append1() -{ - Bu::String sTmp; - for( int c = 0; c < 5000; c++ ) - { - sTmp += (char)(c%256); - } -} - -void append2() -{ - Bu::String sTmp; - for( int c = 0; c < 5000; c++ ) - { - sTmp.append( (char)(c%256) ); - } -} - -void append3() -{ - Bu::String sTmp; - for( int c = 0; c < 5000; c++ ) - { - sTmp += "Test"; - } -} - -void append4() -{ - Bu::String sTmp; - for( int c = 0; c < 5000; c++ ) - { - sTmp.append("Test"); - } -} - -void append5() -{ - Bu::String sTmp, sAdd("Test"); - for( int c = 0; c < 5000; c++ ) - { - sTmp += sAdd; - } -} - -void append6() -{ - Bu::String sTmp, sAdd("Test"); - for( int c = 0; c < 5000; c++ ) - { - sTmp.append( sAdd ); - } -} - -void prepend1() -{ - Bu::String sTmp; - for( int c = 0; c < 5000; c++ ) - { - sTmp.prepend('c'); - } -} - -void copy1() -{ - Bu::String sSrc; - for( int c = 0; c < 1000; c++ ) - { - sSrc += (char)(c%256); - Bu::String sTmp = sSrc; - sTmp.append( '-' ); - } -} - -void copy2() -{ - Bu::String sSrc; - for( int c = 0; c < 1000; c++ ) - { - sSrc += (char)(c%256); - Bu::String sTmp = sSrc; - } -} - -void replace1() -{ - Bu::String s("Hey, this is a replacement test, what do you thing of it?"); - s.replace("e", "X").replace("a", "X").replace("what","XXX"); -} - -int main() -{ - timeit( append1, "Append1", 5000 ); - timeit( append2, "Append2", 5000 ); - timeit( append3, "Append3", 2000 ); - timeit( append4, "Append4", 2000 ); - timeit( append4, "Prepend1", 2000 ); - timeit( copy1, "Copy1", 2000 ); - timeit( copy2, "Copy2", 2000 ); - timeit( replace1, "Replace1", 10000 ); -} - diff --git a/src/tests/tcpsocket.cpp b/src/tests/tcpsocket.cpp deleted file mode 100644 index 89c015c..0000000 --- a/src/tests/tcpsocket.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -#include - -#include -#include - -using namespace Bu; - -bool isUp() -{ - try - { - TcpSocket s("xagasoft.com", 9898, 1 ); - - char buf[5]; - buf[s.read(buf, 2, 1, 0)] = '\0'; - - if( !strcmp( buf, "hi" ) ) - return true; - else - return false; - } - catch(...) - { - return false; - } -} - -int main() -{ - uint32_t uUp = 0; - uint32_t uDown = 0; - uint32_t uTotal = 0; - struct timeval tv; - - for(;;) - { - gettimeofday( &tv, NULL ); - time_t goal = ((tv.tv_sec/5)+1)*5; - tv.tv_sec = goal-tv.tv_sec; - tv.tv_usec = 0-tv.tv_usec; - if( tv.tv_usec < 0 ) - { - tv.tv_sec--; - tv.tv_usec = 1000000+tv.tv_usec; - } - select( 0, NULL, NULL, NULL, &tv ); - gettimeofday( &tv, NULL ); - if( isUp() ) - { - uUp++; - sio << "status: up "; - } - else - { - uDown++; - sio << "status: down "; - } - uTotal++; - - sio << "(up=" << (uUp*5) << "s, down=" << (uDown*5) << ") up for " - << uUp*100/uTotal << "% of " << uTotal*5 << "s" << sio.nl - << sio.flush; - } -} - diff --git a/src/tests/telnetsrv.cpp b/src/tests/telnetsrv.cpp deleted file mode 100644 index aac6b39..0000000 --- a/src/tests/telnetsrv.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/server.h" -#include "bu/protocoltelnet.h" -#include "bu/client.h" - -class MyTelnet : public Bu::ProtocolTelnet -{ -public: - MyTelnet() - { - } - - virtual ~MyTelnet() - { - } - - virtual void onNewConnection( Bu::Client *pClient ) - { - Bu::ProtocolTelnet::onNewConnection( pClient ); - - //oNAWS.remoteSet(); - oEcho.localSet(); - oSuppressGA.remoteSet( true ); - oSuppressGA.localSet( true ); - setCanonical(); - } - - virtual void onSubNAWS( uint16_t iWidth, uint16_t iHeight ) - { - printf("New dim = (%dx%d)\n", iWidth, iHeight ); - } - - virtual void gotLine( Bu::String &sLine ) - { - printf("Line: \"%s\"\n", sLine.getStr() ); - write("\n\r", 2 ); - } - -private: - -}; - -class TelServer : public Bu::Server -{ -public: - TelServer() - { - } - - virtual ~TelServer() - { - } - - virtual void onNewConnection( Bu::Client *pClient, int ) - { - printf("New connection.\n"); - - pClient->setProtocol( new MyTelnet() ); - } - - virtual void onClosedConnection( Bu::Client *pClient ) - { - printf("Lost connection.\n"); - - delete pClient->getProtocol(); - } - -private: - -}; - -int main() -{ - TelServer ts; - - ts.addPort( 4000 ); - ts.setTimeout( 0, 5000 ); - - printf("Initializing server on port: 4000\n"); - - for(;;) - { - ts.scan(); - } -} - diff --git a/src/tests/tracer.cpp b/src/tests/tracer.cpp deleted file mode 100644 index 703fa1a..0000000 --- a/src/tests/tracer.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - - -#define BU_TRACE -#include "bu/trace.h" - -void doThing3( int x, const char *bob, void *p ) -{ - TRACE( x, bob, p ); -} - -void doThing2( int x, const char *bob ) -{ - TRACE( x, bob ); -} - -void doThing( int8_t x ) -{ - TRACE( x ); -} - -int main( int argc, char *argv[] ) -{ - TRACE( argc, argv ); - doThing( 54 ); - doThing2( 128, "Hello" ); - doThing3( 266, "Goodbye", argv ); - - return 0; -} - diff --git a/src/tests/udpsocket.cpp b/src/tests/udpsocket.cpp deleted file mode 100644 index 2a74acf..0000000 --- a/src/tests/udpsocket.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/udpsocket.h" -#include "bu/sio.h" - -#include -#include -#include -#include -#include - -using namespace Bu; - -int main( int argc, char *argv[] ) -{ - sio << Fmt::hex(8) << INADDR_ANY << sio.nl << Fmt::hex(8) << inet_addr("0.0.0.0") << sio.nl; - if( argc == 1 ) - { - sio << "Options are 'l' for listening and 'b' for broadcasting." - << sio.nl; - } - else if( argv[1][0] == 'l' ) - { - sio << "Listening..." << sio.nl; - Bu::UdpSocket udp( "0.0.0.0", 6688, UdpSocket::Read|UdpSocket::Broadcast ); - - for(;;) - { - char buf[1501]; - int iRead = udp.read( buf, 1500 ); - if( iRead >= 0 ) - { - buf[iRead] = '\0'; - sio << "Read(" << iRead << "): '" << buf << "'" << sio.nl; - } - else - { - sio << "Got " << iRead << ": " << strerror( errno ) << sio.nl; - } - } - } - else if( argv[1][0] == 'L' ) - { - sio << "Listening..." << sio.nl; - Bu::UdpSocket udp( "0.0.0.0", 6688, UdpSocket::Read|UdpSocket::Broadcast ); - - for(;;) - { - char buf[1501]; - Bu::UdpSocket::addr aHost; - int iPort; - int iRead = udp.read( buf, 1500, aHost, iPort ); - if( iRead >= 0 ) - { - buf[iRead] = '\0'; - sio << "Read(" << iRead << ") from " << Bu::UdpSocket::addrToStr( aHost ) << ":" << iPort << ": '" << buf << "'" << sio.nl; - } - } - } - else if( argv[1][0] == 'b' ) - { - sio << "Broadcasting..." << sio.nl; - Bu::UdpSocket udp("255.255.255.255", 6688, - UdpSocket::Write|UdpSocket::Broadcast ); - - for(;;) - { - int iWrote = udp.write("hello", 5 ); - sio << "Wrote(" << iWrote << "): " << strerror( errno ) << sio.nl; - usleep( 250000 ); - } - } - else - { - sio << "Options are 'l' for listening and 'b' for broadcasting." - << sio.nl; - } - - return 0; -} - diff --git a/src/tests/url.cpp b/src/tests/url.cpp deleted file mode 100644 index a381cbe..0000000 --- a/src/tests/url.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include "bu/url.h" - -#include - -int main( int argc, char *argv[] ) -{ - for( argc--, argv++; argc >= 0; argc--, argv++ ) - { - printf("encodede: %s\n", Bu::Url::encode( *argv ).getStr() ); - printf("decodede: %s\n", Bu::Url::decode( *argv ).getStr() ); - Bu::Url u( *argv ); - - printf("Protocol: %s\n", u.getProtocol().getStr() ); - printf("User: %s\n", u.getUser().getStr() ); - printf("Pass: %s\n", u.getPass().getStr() ); - printf("Host: %s\n", u.getHost().getStr() ); - printf("Path: %s\n", u.getPath().getStr() ); - try - { - printf("Port: %d\n", u.getPort() ); - } catch( Bu::ExceptionBase &e ) - { - printf("Port: not set.\n"); - } - printf("Parameters:\n"); - for( Bu::Url::ParamList::const_iterator i = u.getParamBegin(); i; i++ ) - { - printf(" \"%s\" = \"%s\"\n", - (*i).sName.getStr(), (*i).sValue.getStr() - ); - } - } - - return 0; -} diff --git a/src/tests/variant.cpp b/src/tests/variant.cpp deleted file mode 100644 index 68dec4f..0000000 --- a/src/tests/variant.cpp +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2007-2011 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#include -#include -#include - -using namespace Bu; - -Variant getThing( int i ) -{ - Variant v; - switch( i ) - { - case 0: - v = 45; - break; - - case 1: - v = true; - break; - - case 2: - v = List(5).append(10).append(15); - break; - } - - return v; -} - -int main() -{ - Variant a; - Variant b; - Variant c; - - a = getThing( 0 ); - b = getThing( 1 ); - c = getThing( 2 ); - - sio << "a = " << a << " or " << (int)a << sio.nl - << "b = " << b << " or " << b.toString() << sio.nl - << "c = " << c << " or " << c.toString() << sio.nl - << sio.nl; - - return 0; -} - -- cgit v1.2.3