diff options
author | Mike Buland <eichlan@xagasoft.com> | 2007-07-03 00:28:59 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2007-07-03 00:28:59 +0000 |
commit | ac517a2b7625e0aa0862679e961c6349f859ea3b (patch) | |
tree | e3e27a6b9bd5e2be6150088495c91fc91786ad9d /src/tests | |
parent | f8d4301e9fa4f3709258505941e37fab2eadadc6 (diff) | |
parent | bd865cee5f89116c1f054cd0e5c275e97c2d0a9b (diff) | |
download | libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.gz libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.bz2 libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.tar.xz libbu++-ac517a2b7625e0aa0862679e961c6349f859ea3b.zip |
The reorg is being put in trunk, I think it's ready. Now we just get to find
out how many applications won't work anymore :)
Diffstat (limited to '')
-rw-r--r-- | src/old/tests/clistress.cpp (renamed from src/tests/clistress.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/confpair.cpp (renamed from src/tests/confpair.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/connect.cpp (renamed from src/tests/connect.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/exception.cpp (renamed from src/tests/exception.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/formula.cpp (renamed from src/tests/formula.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/hashtest.cpp (renamed from src/tests/hashtest.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/hashtest2.cpp (renamed from src/tests/hashtest2.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/httpsrv/httpconnectionmonitor.cpp (renamed from src/tests/httpsrv/httpconnectionmonitor.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/httpsrv/httpconnectionmonitor.h (renamed from src/tests/httpsrv/httpconnectionmonitor.h) | 0 | ||||
-rw-r--r-- | src/old/tests/httpsrv/main.cpp (renamed from src/tests/httpsrv/main.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/log.cpp (renamed from src/tests/log.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/md5test.cpp (renamed from src/tests/md5test.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/ordhash.cpp (renamed from src/tests/ordhash.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/param.cpp (renamed from src/tests/param.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/param.h (renamed from src/tests/param.h) | 0 | ||||
-rw-r--r-- | src/old/tests/plugin/main.cpp (renamed from src/tests/plugin/main.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/plugin/plugin.cpp (renamed from src/tests/plugin/plugin.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/plugin/plugin.h (renamed from src/tests/plugin/plugin.h) | 0 | ||||
-rw-r--r-- | src/old/tests/qsort.cpp (renamed from src/tests/qsort.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/sbuffer.cpp (renamed from src/tests/sbuffer.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/serialize.cpp (renamed from src/tests/serialize.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/serializetext.cpp (renamed from src/tests/serializetext.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/sha1.cpp (renamed from src/tests/sha1.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/sptr.cpp (renamed from src/tests/sptr.cpp) | 30 | ||||
-rw-r--r-- | src/old/tests/srvstress.cpp (renamed from src/tests/srvstress.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/strhash.cpp (renamed from src/tests/strhash.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/teltest/main.cpp (renamed from src/tests/teltest/main.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/teltest/telnetmonitor.cpp (renamed from src/tests/teltest/telnetmonitor.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/teltest/telnetmonitor.h (renamed from src/tests/teltest/telnetmonitor.h) | 0 | ||||
-rw-r--r-- | src/old/tests/xmlreadtest.cpp (renamed from src/tests/xmlreadtest.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/xmlrepltest.cpp (renamed from src/tests/xmlrepltest.cpp) | 0 | ||||
-rw-r--r-- | src/old/tests/xmlwritetest.cpp (renamed from src/tests/xmlwritetest.cpp) | 0 | ||||
-rw-r--r-- | src/tests/archive.cpp | 16 | ||||
-rw-r--r-- | src/tests/atom.cpp | 25 | ||||
-rw-r--r-- | src/tests/bzip2.cpp | 23 | ||||
-rw-r--r-- | src/tests/constsptr.cpp | 94 | ||||
-rw-r--r-- | src/tests/constsptr2.cpp | 30 | ||||
-rw-r--r-- | src/tests/fstring.cpp | 108 | ||||
-rw-r--r-- | src/tests/hash.cpp | 120 | ||||
-rw-r--r-- | src/tests/itoqueue1.cpp | 110 | ||||
-rw-r--r-- | src/tests/itoqueue2.cpp | 83 | ||||
-rw-r--r-- | src/tests/list.cpp | 53 | ||||
-rw-r--r-- | src/tests/logger.cpp | 28 | ||||
-rw-r--r-- | src/tests/ringbuffer.cpp | 29 | ||||
-rw-r--r-- | src/tests/taf.cpp | 24 |
45 files changed, 508 insertions, 265 deletions
diff --git a/src/tests/clistress.cpp b/src/old/tests/clistress.cpp index 6b0ac66..6b0ac66 100644 --- a/src/tests/clistress.cpp +++ b/src/old/tests/clistress.cpp | |||
diff --git a/src/tests/confpair.cpp b/src/old/tests/confpair.cpp index fb1b0d3..fb1b0d3 100644 --- a/src/tests/confpair.cpp +++ b/src/old/tests/confpair.cpp | |||
diff --git a/src/tests/connect.cpp b/src/old/tests/connect.cpp index a9fca64..a9fca64 100644 --- a/src/tests/connect.cpp +++ b/src/old/tests/connect.cpp | |||
diff --git a/src/tests/exception.cpp b/src/old/tests/exception.cpp index 6417692..6417692 100644 --- a/src/tests/exception.cpp +++ b/src/old/tests/exception.cpp | |||
diff --git a/src/tests/formula.cpp b/src/old/tests/formula.cpp index 976b039..976b039 100644 --- a/src/tests/formula.cpp +++ b/src/old/tests/formula.cpp | |||
diff --git a/src/tests/hashtest.cpp b/src/old/tests/hashtest.cpp index eaa84a0..eaa84a0 100644 --- a/src/tests/hashtest.cpp +++ b/src/old/tests/hashtest.cpp | |||
diff --git a/src/tests/hashtest2.cpp b/src/old/tests/hashtest2.cpp index 74700fd..74700fd 100644 --- a/src/tests/hashtest2.cpp +++ b/src/old/tests/hashtest2.cpp | |||
diff --git a/src/tests/httpsrv/httpconnectionmonitor.cpp b/src/old/tests/httpsrv/httpconnectionmonitor.cpp index 51d82f3..51d82f3 100644 --- a/src/tests/httpsrv/httpconnectionmonitor.cpp +++ b/src/old/tests/httpsrv/httpconnectionmonitor.cpp | |||
diff --git a/src/tests/httpsrv/httpconnectionmonitor.h b/src/old/tests/httpsrv/httpconnectionmonitor.h index 30c0afd..30c0afd 100644 --- a/src/tests/httpsrv/httpconnectionmonitor.h +++ b/src/old/tests/httpsrv/httpconnectionmonitor.h | |||
diff --git a/src/tests/httpsrv/main.cpp b/src/old/tests/httpsrv/main.cpp index 2f1563c..2f1563c 100644 --- a/src/tests/httpsrv/main.cpp +++ b/src/old/tests/httpsrv/main.cpp | |||
diff --git a/src/tests/log.cpp b/src/old/tests/log.cpp index d7cfa0b..d7cfa0b 100644 --- a/src/tests/log.cpp +++ b/src/old/tests/log.cpp | |||
diff --git a/src/tests/md5test.cpp b/src/old/tests/md5test.cpp index 6f832df..6f832df 100644 --- a/src/tests/md5test.cpp +++ b/src/old/tests/md5test.cpp | |||
diff --git a/src/tests/ordhash.cpp b/src/old/tests/ordhash.cpp index f1d96ec..f1d96ec 100644 --- a/src/tests/ordhash.cpp +++ b/src/old/tests/ordhash.cpp | |||
diff --git a/src/tests/param.cpp b/src/old/tests/param.cpp index a4d2824..a4d2824 100644 --- a/src/tests/param.cpp +++ b/src/old/tests/param.cpp | |||
diff --git a/src/tests/param.h b/src/old/tests/param.h index 2756b69..2756b69 100644 --- a/src/tests/param.h +++ b/src/old/tests/param.h | |||
diff --git a/src/tests/plugin/main.cpp b/src/old/tests/plugin/main.cpp index 51c8390..51c8390 100644 --- a/src/tests/plugin/main.cpp +++ b/src/old/tests/plugin/main.cpp | |||
diff --git a/src/tests/plugin/plugin.cpp b/src/old/tests/plugin/plugin.cpp index ea558fd..ea558fd 100644 --- a/src/tests/plugin/plugin.cpp +++ b/src/old/tests/plugin/plugin.cpp | |||
diff --git a/src/tests/plugin/plugin.h b/src/old/tests/plugin/plugin.h index f726867..f726867 100644 --- a/src/tests/plugin/plugin.h +++ b/src/old/tests/plugin/plugin.h | |||
diff --git a/src/tests/qsort.cpp b/src/old/tests/qsort.cpp index 28c6f03..28c6f03 100644 --- a/src/tests/qsort.cpp +++ b/src/old/tests/qsort.cpp | |||
diff --git a/src/tests/sbuffer.cpp b/src/old/tests/sbuffer.cpp index 02798cb..02798cb 100644 --- a/src/tests/sbuffer.cpp +++ b/src/old/tests/sbuffer.cpp | |||
diff --git a/src/tests/serialize.cpp b/src/old/tests/serialize.cpp index e233704..e233704 100644 --- a/src/tests/serialize.cpp +++ b/src/old/tests/serialize.cpp | |||
diff --git a/src/tests/serializetext.cpp b/src/old/tests/serializetext.cpp index f6be7d3..f6be7d3 100644 --- a/src/tests/serializetext.cpp +++ b/src/old/tests/serializetext.cpp | |||
diff --git a/src/tests/sha1.cpp b/src/old/tests/sha1.cpp index df3113c..df3113c 100644 --- a/src/tests/sha1.cpp +++ b/src/old/tests/sha1.cpp | |||
diff --git a/src/tests/sptr.cpp b/src/old/tests/sptr.cpp index 252463b..38d3675 100644 --- a/src/tests/sptr.cpp +++ b/src/old/tests/sptr.cpp | |||
@@ -9,12 +9,12 @@ public: | |||
9 | printf("Created.\n"); | 9 | printf("Created.\n"); |
10 | } | 10 | } |
11 | 11 | ||
12 | virtual ~Annoy() | 12 | ~Annoy() |
13 | { | 13 | { |
14 | printf("Destroyed.\n"); | 14 | printf("Destroyed.\n"); |
15 | } | 15 | } |
16 | 16 | ||
17 | virtual void go() | 17 | void go() |
18 | { | 18 | { |
19 | printf("%d: I'm annoying.\n", ++nCnt); | 19 | printf("%d: I'm annoying.\n", ++nCnt); |
20 | } | 20 | } |
@@ -22,22 +22,6 @@ public: | |||
22 | int nCnt; | 22 | int nCnt; |
23 | }; | 23 | }; |
24 | 24 | ||
25 | class Annoy2: public Annoy | ||
26 | { | ||
27 | public: | ||
28 | Annoy2(){}; | ||
29 | virtual ~Annoy2(){}; | ||
30 | virtual void go() | ||
31 | { | ||
32 | printf("{{I'm Annoy2!!}} "); | ||
33 | Annoy::go(); | ||
34 | } | ||
35 | virtual void go2() | ||
36 | { | ||
37 | printf("This is me, on my own...\n"); | ||
38 | } | ||
39 | }; | ||
40 | |||
41 | void beAnnoying( SPtr<Annoy> bob ) | 25 | void beAnnoying( SPtr<Annoy> bob ) |
42 | { | 26 | { |
43 | printf("bob-Count: %d\n", bob.count() ); | 27 | printf("bob-Count: %d\n", bob.count() ); |
@@ -46,7 +30,7 @@ void beAnnoying( SPtr<Annoy> bob ) | |||
46 | 30 | ||
47 | int main() | 31 | int main() |
48 | { | 32 | { |
49 | SPtr<Annoy> pt( new Annoy2 ); | 33 | SPtr<Annoy> pt( new Annoy ); |
50 | printf("Count: %d\n", pt.count() ); | 34 | printf("Count: %d\n", pt.count() ); |
51 | pt->go(); | 35 | pt->go(); |
52 | 36 | ||
@@ -63,14 +47,6 @@ int main() | |||
63 | pt3->go(); | 47 | pt3->go(); |
64 | 48 | ||
65 | beAnnoying( pt3 ); | 49 | beAnnoying( pt3 ); |
66 | |||
67 | { | ||
68 | SPtr<Annoy2> pt4( SPtrCast<Annoy2>( pt3 ) ); | ||
69 | printf("Count: %d\n", pt4.count() ); | ||
70 | |||
71 | pt4->go2(); | ||
72 | } | ||
73 | printf("Count: %d\n", pt.count() ); | ||
74 | } | 50 | } |
75 | printf("Count: %d\n", pt.count() ); | 51 | printf("Count: %d\n", pt.count() ); |
76 | } | 52 | } |
diff --git a/src/tests/srvstress.cpp b/src/old/tests/srvstress.cpp index d9a9a1c..d9a9a1c 100644 --- a/src/tests/srvstress.cpp +++ b/src/old/tests/srvstress.cpp | |||
diff --git a/src/tests/strhash.cpp b/src/old/tests/strhash.cpp index f6528ca..f6528ca 100644 --- a/src/tests/strhash.cpp +++ b/src/old/tests/strhash.cpp | |||
diff --git a/src/tests/teltest/main.cpp b/src/old/tests/teltest/main.cpp index 5d3ec26..5d3ec26 100644 --- a/src/tests/teltest/main.cpp +++ b/src/old/tests/teltest/main.cpp | |||
diff --git a/src/tests/teltest/telnetmonitor.cpp b/src/old/tests/teltest/telnetmonitor.cpp index 65954eb..65954eb 100644 --- a/src/tests/teltest/telnetmonitor.cpp +++ b/src/old/tests/teltest/telnetmonitor.cpp | |||
diff --git a/src/tests/teltest/telnetmonitor.h b/src/old/tests/teltest/telnetmonitor.h index ba5761e..ba5761e 100644 --- a/src/tests/teltest/telnetmonitor.h +++ b/src/old/tests/teltest/telnetmonitor.h | |||
diff --git a/src/tests/xmlreadtest.cpp b/src/old/tests/xmlreadtest.cpp index d061810..d061810 100644 --- a/src/tests/xmlreadtest.cpp +++ b/src/old/tests/xmlreadtest.cpp | |||
diff --git a/src/tests/xmlrepltest.cpp b/src/old/tests/xmlrepltest.cpp index 9667705..9667705 100644 --- a/src/tests/xmlrepltest.cpp +++ b/src/old/tests/xmlrepltest.cpp | |||
diff --git a/src/tests/xmlwritetest.cpp b/src/old/tests/xmlwritetest.cpp index a22d19d..a22d19d 100644 --- a/src/tests/xmlwritetest.cpp +++ b/src/old/tests/xmlwritetest.cpp | |||
diff --git a/src/tests/archive.cpp b/src/tests/archive.cpp new file mode 100644 index 0000000..2035aa6 --- /dev/null +++ b/src/tests/archive.cpp | |||
@@ -0,0 +1,16 @@ | |||
1 | #include "archive.h" | ||
2 | #include "file.h" | ||
3 | |||
4 | using namespace Bu; | ||
5 | |||
6 | int main() | ||
7 | { | ||
8 | File f("test.dat", "wb"); | ||
9 | Archive ar( f, Archive::save ); | ||
10 | |||
11 | std::string s("Hello there"); | ||
12 | ar << s; | ||
13 | |||
14 | return 0; | ||
15 | } | ||
16 | |||
diff --git a/src/tests/atom.cpp b/src/tests/atom.cpp new file mode 100644 index 0000000..2077bfd --- /dev/null +++ b/src/tests/atom.cpp | |||
@@ -0,0 +1,25 @@ | |||
1 | #include "bu/atom.h" | ||
2 | #include <stdio.h> | ||
3 | #include <stdlib.h> | ||
4 | |||
5 | typedef struct bob | ||
6 | { | ||
7 | int a, b; | ||
8 | } bob; | ||
9 | int main() | ||
10 | { | ||
11 | Bu::Atom<int> aInt; | ||
12 | Bu::Atom<char *> aStr; | ||
13 | Bu::Atom<bob> aBob; | ||
14 | |||
15 | aBob = bob(); | ||
16 | aBob->a = 5; | ||
17 | |||
18 | aStr.set("Hey there, dude"); | ||
19 | aInt.set( 55 ); | ||
20 | int me = aInt; | ||
21 | aInt = 12; | ||
22 | printf("%d, %d\n", aInt.get(), me ); | ||
23 | printf("%s\n", aStr.get() ); | ||
24 | } | ||
25 | |||
diff --git a/src/tests/bzip2.cpp b/src/tests/bzip2.cpp new file mode 100644 index 0000000..683d3d7 --- /dev/null +++ b/src/tests/bzip2.cpp | |||
@@ -0,0 +1,23 @@ | |||
1 | #include "bu/bzip2.h" | ||
2 | #include "bu/file.h" | ||
3 | |||
4 | int main( int argc, char *argv[] ) | ||
5 | { | ||
6 | char buf[1024]; | ||
7 | size_t nRead; | ||
8 | |||
9 | Bu::File f( "test.bz2", "wb" ); | ||
10 | Bu::BZip2 bz2( f ); | ||
11 | |||
12 | Bu::File fin( argv[1], "rb"); | ||
13 | |||
14 | for(;;) | ||
15 | { | ||
16 | nRead = fin.read( buf, 1024 ); | ||
17 | if( nRead > 0 ) | ||
18 | bz2.write( buf, nRead ); | ||
19 | if( fin.isEOS() ) | ||
20 | break; | ||
21 | } | ||
22 | } | ||
23 | |||
diff --git a/src/tests/constsptr.cpp b/src/tests/constsptr.cpp deleted file mode 100644 index e6f87c7..0000000 --- a/src/tests/constsptr.cpp +++ /dev/null | |||
@@ -1,94 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include "sptr.h" | ||
3 | |||
4 | template <typename T> | ||
5 | class DataBase | ||
6 | { | ||
7 | public: | ||
8 | DataBase(): | ||
9 | _bHas(false) | ||
10 | { | ||
11 | } | ||
12 | |||
13 | virtual ~DataBase() | ||
14 | { | ||
15 | clr(); | ||
16 | } | ||
17 | |||
18 | virtual bool has() const | ||
19 | { | ||
20 | return _bHas; | ||
21 | } | ||
22 | |||
23 | virtual void clr() | ||
24 | { | ||
25 | _bHas = false; | ||
26 | } | ||
27 | |||
28 | virtual void set(T d) | ||
29 | { | ||
30 | _tVal = d; | ||
31 | _bHas = true; | ||
32 | } | ||
33 | |||
34 | virtual T const &get() const | ||
35 | { | ||
36 | if(!has()) | ||
37 | throw "no data"; | ||
38 | return _tVal; | ||
39 | } | ||
40 | |||
41 | virtual T &get() | ||
42 | { | ||
43 | if(!has()) | ||
44 | throw "no data"; | ||
45 | return _tVal; | ||
46 | } | ||
47 | |||
48 | protected: | ||
49 | bool _bHas; | ||
50 | T _tVal; | ||
51 | }; | ||
52 | |||
53 | |||
54 | class Test | ||
55 | { | ||
56 | public: | ||
57 | Test(){}; | ||
58 | virtual ~Test(){}; | ||
59 | |||
60 | void set(int i) | ||
61 | { | ||
62 | _i = i; | ||
63 | } | ||
64 | |||
65 | int get() const | ||
66 | { | ||
67 | return _i; | ||
68 | } | ||
69 | |||
70 | private: | ||
71 | int _i; | ||
72 | }; | ||
73 | |||
74 | int main() | ||
75 | { | ||
76 | typedef SPtr<Test> TestPtr; | ||
77 | |||
78 | TestPtr t1(new Test); | ||
79 | t1->set(42); | ||
80 | |||
81 | printf("t1: %d.\n", t1->get()); | ||
82 | |||
83 | const TestPtr t2 = t1; | ||
84 | |||
85 | printf("t2: %d.\n", t2->get()); | ||
86 | |||
87 | typedef DataBase<const TestPtr> DBTP; | ||
88 | |||
89 | DBTP db; | ||
90 | db.set(t1); | ||
91 | |||
92 | printf("dbt1: %d.\n", db.get()->get()); | ||
93 | } | ||
94 | |||
diff --git a/src/tests/constsptr2.cpp b/src/tests/constsptr2.cpp deleted file mode 100644 index 8ccb20c..0000000 --- a/src/tests/constsptr2.cpp +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | #include "sptr.h" | ||
2 | |||
3 | void nonsptr() | ||
4 | { | ||
5 | int a = 5; | ||
6 | int b = 10; | ||
7 | const int *p = &a; | ||
8 | p = &b; | ||
9 | printf("p = %d\n", (*p) ); | ||
10 | //(*p)++; | ||
11 | } | ||
12 | |||
13 | void sptr() | ||
14 | { | ||
15 | int a = 5; | ||
16 | int b = 10; | ||
17 | const SPtr<int> p = new int(a); | ||
18 | p = new int(b); | ||
19 | printf("p = %d\n", (*p) ); | ||
20 | //(*p)++; | ||
21 | } | ||
22 | |||
23 | int main() | ||
24 | { | ||
25 | printf("Non-sptr:\n"); | ||
26 | nonsptr(); | ||
27 | printf("sptr:\n"); | ||
28 | sptr(); | ||
29 | } | ||
30 | |||
diff --git a/src/tests/fstring.cpp b/src/tests/fstring.cpp index 271738c..48dfc5f 100644 --- a/src/tests/fstring.cpp +++ b/src/tests/fstring.cpp | |||
@@ -1,9 +1,28 @@ | |||
1 | #include "hash.h" | 1 | #include "bu/hash.h" |
2 | #include "fstring.h" | 2 | #include "bu/fstring.h" |
3 | #include <sys/time.h> | ||
4 | #include <string> | ||
3 | 5 | ||
4 | FString genThing() | 6 | #ifndef WIN32 |
7 | inline double getTime() | ||
5 | { | 8 | { |
6 | FString bob; | 9 | struct timeval tv; |
10 | gettimeofday( &tv, NULL ); | ||
11 | return ((double)tv.tv_sec) + ((double)tv.tv_usec/1000000.0); | ||
12 | } | ||
13 | #else | ||
14 | #include "windows.h" | ||
15 | #include "winbase.h" | ||
16 | inline double getTime() | ||
17 | { | ||
18 | uint32_t t = (uint32_t) GetTickCount(); | ||
19 | return (double) t / 1000.0; | ||
20 | } | ||
21 | #endif | ||
22 | |||
23 | Bu::FString genThing() | ||
24 | { | ||
25 | Bu::FString bob; | ||
7 | bob.append("ab "); | 26 | bob.append("ab "); |
8 | bob += "cd "; | 27 | bob += "cd "; |
9 | bob += "efg"; | 28 | bob += "efg"; |
@@ -12,20 +31,91 @@ FString genThing() | |||
12 | return bob; | 31 | return bob; |
13 | } | 32 | } |
14 | 33 | ||
15 | void thing( FString str ) | 34 | void thing( Bu::FString str ) |
16 | { | 35 | { |
17 | printf("Hey: %s\n", str.c_str() ); | 36 | printf("Hey: %s\n", str.c_str() ); |
18 | } | 37 | } |
19 | 38 | ||
39 | void copyfunc( std::string temp ) | ||
40 | { | ||
41 | temp += "Hi"; | ||
42 | } | ||
43 | |||
44 | void copyfunc( Bu::FString temp ) | ||
45 | { | ||
46 | temp += "Hi"; | ||
47 | } | ||
48 | |||
49 | void doTimings() | ||
50 | { | ||
51 | Bu::FString fs1, fs2; | ||
52 | std::string ss1, ss2; | ||
53 | double dStart, dEnd, tfs1, tfs2, tfs3, tss1, tss2, tss3; | ||
54 | int nChars = 500000, nChunks=5000, nCopies=5000000, nChunkSize=1024*4; | ||
55 | char *buf = new char[nChunkSize]; | ||
56 | memset( buf, '!', nChunkSize ); | ||
57 | |||
58 | printf("Timing Bu::FString single chars...\n"); | ||
59 | dStart = getTime(); | ||
60 | for( int j = 0; j < nChars; j++ ) fs1 += (char)('a'+(j%26)); | ||
61 | fs1.getStr(); | ||
62 | dEnd = getTime(); | ||
63 | tfs1 = dEnd-dStart; | ||
64 | |||
65 | printf("Timing std::string single chars...\n"); | ||
66 | dStart = getTime(); | ||
67 | for( int j = 0; j < nChars; j++ ) ss1 += (char)('a'+(j%26)); | ||
68 | ss1.c_str(); | ||
69 | dEnd = getTime(); | ||
70 | tss1 = dEnd-dStart; | ||
71 | |||
72 | printf("Timing Bu::FString %d char chunks...\n", nChunkSize); | ||
73 | dStart = getTime(); | ||
74 | for( int j = 0; j < nChunks; j++ ) fs2.append(buf, nChunkSize); | ||
75 | fs2.getStr(); | ||
76 | dEnd = getTime(); | ||
77 | tfs2 = dEnd-dStart; | ||
78 | |||
79 | printf("Timing std::string %d char chunks...\n", nChunkSize); | ||
80 | dStart = getTime(); | ||
81 | for( int j = 0; j < nChunks; j++ ) ss2.append(buf, nChunkSize); | ||
82 | ss2.c_str(); | ||
83 | dEnd = getTime(); | ||
84 | tss2 = dEnd-dStart; | ||
85 | |||
86 | fs2 = "Hello there."; | ||
87 | ss2 = "Hello there."; | ||
88 | printf("Timing Bu::FString copies...\n"); | ||
89 | dStart = getTime(); | ||
90 | for( int j = 0; j < nCopies; j++ ) Bu::FString stmp = fs2; | ||
91 | dEnd = getTime(); | ||
92 | tfs3 = dEnd-dStart; | ||
93 | |||
94 | printf("Timing std::string copies...\n"); | ||
95 | dStart = getTime(); | ||
96 | for( int j = 0; j < nCopies; j++ ) std::string stpm = ss2; | ||
97 | dEnd = getTime(); | ||
98 | tss3 = dEnd-dStart; | ||
99 | |||
100 | printf( | ||
101 | "Results: singles: chunks: copies:\n" | ||
102 | "Bu::FString %10.2f/s %10.2f/s %10.2f/s\n" | ||
103 | "std::string %10.2f/s %10.2f/s %10.2f/s\n", | ||
104 | nChars/tfs1, nChunks/tfs2, nCopies/tfs3, | ||
105 | nChars/tss1, nChunks/tss2, nCopies/tss3 ); | ||
106 | |||
107 | delete[] buf; | ||
108 | } | ||
109 | |||
20 | #define pem printf("---------\n%08X: %s\n%08X: %s\n", (unsigned int)str.c_str(), str.c_str(), (unsigned int)str2.c_str(), str2.c_str() ); | 110 | #define pem printf("---------\n%08X: %s\n%08X: %s\n", (unsigned int)str.c_str(), str.c_str(), (unsigned int)str2.c_str(), str2.c_str() ); |
21 | int main( int argc, char *argv ) | 111 | int main( int argc, char *argv ) |
22 | { | 112 | { |
23 | FString str("th"); | 113 | Bu::FString str("th"); |
24 | 114 | ||
25 | str.prepend("Hello "); | 115 | str.prepend("Hello "); |
26 | str.append("ere."); | 116 | str.append("ere."); |
27 | 117 | ||
28 | FString str2( str ); | 118 | Bu::FString str2( str ); |
29 | pem; | 119 | pem; |
30 | str += " What's up?"; | 120 | str += " What's up?"; |
31 | pem; | 121 | pem; |
@@ -43,6 +133,8 @@ int main( int argc, char *argv ) | |||
43 | thing( str2 ); | 133 | thing( str2 ); |
44 | thing("test."); | 134 | thing("test."); |
45 | 135 | ||
46 | printf("%d == %d\n", __calcHashCode( str ), __calcHashCode( str.c_str() ) ); | 136 | printf("%d == %d\n", Bu::__calcHashCode( str ), Bu::__calcHashCode( str.c_str() ) ); |
137 | |||
138 | doTimings(); | ||
47 | } | 139 | } |
48 | 140 | ||
diff --git a/src/tests/hash.cpp b/src/tests/hash.cpp index 2fc6968..73cfb27 100644 --- a/src/tests/hash.cpp +++ b/src/tests/hash.cpp | |||
@@ -1,116 +1,24 @@ | |||
1 | #include "hash.h" | 1 | #include "bu/hash.h" |
2 | #include "staticstring.h" | 2 | #include "bu/sptr.h" |
3 | 3 | ||
4 | int main() | 4 | typedef struct Bob |
5 | { | 5 | { |
6 | const char *names[]={ | 6 | int nID; |
7 | "Homer the Great", | 7 | } Bob; |
8 | "And Maggie Makes Three", | ||
9 | "Bart's Comet", | ||
10 | "Homie The Clown", | ||
11 | "Bart Vs Australia", | ||
12 | "Homer vs Patty and Selma", | ||
13 | "A star is burns", | ||
14 | "Lisa's Wedding", | ||
15 | "Two Dozen and One Greyhounds", | ||
16 | "The PTA Disbands", | ||
17 | "Round Springfield", | ||
18 | "The Springfield connection", | ||
19 | "Lemon of Troy", | ||
20 | "Who Shot Mr. Burns (Pt. 1)", | ||
21 | "Who Shot Mr. Burns (pt. 2)", | ||
22 | "Radioactive Man", | ||
23 | "Home Sweet Homediddly-dum-doodly", | ||
24 | "Bart Sells His Soul", | ||
25 | "Lisa the Vegetarian", | ||
26 | "Treehouse of horror VI", | ||
27 | "King Size Homer", | ||
28 | "Mother Simpson", | ||
29 | "Sideshow Bob's Last Gleaming", | ||
30 | "The Simpson's 138th Show Spectacular", | ||
31 | "Marge Be Not Proud", | ||
32 | "Team Homer", | ||
33 | "Two Bad Neighbors", | ||
34 | "Scenes From the Class Struggle in Springfield", | ||
35 | "Bart the Fink", | ||
36 | "Lisa the Iconoclast", | ||
37 | "Homer the Smithers", | ||
38 | "The Day the Violence Died", | ||
39 | "A Fish Called Selma", | ||
40 | "Bart on the road", | ||
41 | "22 Short Films about Springfield", | ||
42 | "The Curse of the Flying Hellfish", | ||
43 | "Much Apu about Nothing", | ||
44 | "Homerpalooza", | ||
45 | "The Summer of 4 Ft 2", | ||
46 | "Treehouse of Horror VII", | ||
47 | "You Only Move Twice", | ||
48 | "The Homer They Fall", | ||
49 | "Burns Baby Burns", | ||
50 | "Bart After Dark", | ||
51 | "A Millhouse Divided", | ||
52 | "Lisas Date With Destiny", | ||
53 | "Hurricane Neddy", | ||
54 | "The Mysterious Voyage of Our Homer", | ||
55 | "The Springfield Files", | ||
56 | "The Twisted World of Marge Simpson", | ||
57 | "Mountain of Madness", | ||
58 | NULL | ||
59 | }; | ||
60 | |||
61 | Hash<const char *, int> sTest; | ||
62 | |||
63 | printf("Inserting\n-------------------\n\n"); | ||
64 | for( int j = 0; j < 33; j++ ) | ||
65 | { | ||
66 | sTest[names[j]] = j; | ||
67 | } | ||
68 | |||
69 | printf("Test1: %d, Test2: %d\n", sTest.has("Lemon of Troy"), sTest.has(std::string("Lemon of Troy").c_str() ) ); | ||
70 | |||
71 | sTest.has(std::string("Lemon of Troy").c_str() ); | ||
72 | |||
73 | printf("Getting\n-------------------\n\n"); | ||
74 | |||
75 | sTest.erase("Homer the Great"); | ||
76 | sTest["Bart's Comet"].erase(); | ||
77 | 8 | ||
78 | for( Hash<const char *, int>::iterator i = sTest.begin(); | 9 | int main() |
79 | i != sTest.end(); i++ ) | 10 | { |
80 | { | 11 | Bu::Hash<int, Bu::SPtr<const Bob> > lb; |
81 | Hash<const char *, int>::iterator j = i; | 12 | for( int j = 0; j < 10; j++ ) |
82 | printf("%d: %s\n", (*j).second, (*j).first ); | ||
83 | } | ||
84 | |||
85 | printf("Testing\n-------------------\n\n"); | ||
86 | for( int j = 0; j < 33; j++ ) | ||
87 | { | 13 | { |
88 | if( sTest.has(names[j]) ) | 14 | Bob *b = new Bob; |
89 | { | 15 | b->nID = j; |
90 | if( sTest[names[j]] != j ) | 16 | lb.insert( j, b ); |
91 | { | ||
92 | printf("'%s' should be %d, is %d\n", | ||
93 | names[j], j, | ||
94 | sTest[names[j]].value() | ||
95 | ); | ||
96 | } | ||
97 | } | ||
98 | else | ||
99 | { | ||
100 | printf("Missing element %d, '%s'\n", j, names[j] ); | ||
101 | } | ||
102 | } | 17 | } |
103 | 18 | ||
104 | printf("Clearing\n-------------------\n\n"); | 19 | for( int j = 0; j < 10; j++ ) |
105 | |||
106 | sTest.clear(); | ||
107 | |||
108 | for( Hash<const char *, int>::iterator i = sTest.begin(); | ||
109 | i != sTest.end(); i++ ) | ||
110 | { | 20 | { |
111 | Hash<const char *, int>::iterator j = i; | 21 | printf("%d\n", lb[j].value()->nID ); |
112 | printf("%d: %s\n", (*j).second, (*j).first ); | ||
113 | } | 22 | } |
114 | |||
115 | } | 23 | } |
116 | 24 | ||
diff --git a/src/tests/itoqueue1.cpp b/src/tests/itoqueue1.cpp new file mode 100644 index 0000000..f73f4d3 --- /dev/null +++ b/src/tests/itoqueue1.cpp | |||
@@ -0,0 +1,110 @@ | |||
1 | #include <string> | ||
2 | #include "bu/ito.h" | ||
3 | #include "bu/itoqueue.h" | ||
4 | |||
5 | class Reader : public Bu::Ito | ||
6 | { | ||
7 | public: | ||
8 | Reader( Bu::ItoQueue<std::string *> &q, int id ) : | ||
9 | q( q ), | ||
10 | id( id ) | ||
11 | { | ||
12 | } | ||
13 | |||
14 | void *run() | ||
15 | { | ||
16 | for( int i = 0; i < 10; i++ ) | ||
17 | { | ||
18 | std::string *pStr = q.dequeue( true ); | ||
19 | if( pStr == NULL ) | ||
20 | { | ||
21 | printf("Null received...\n"); | ||
22 | } | ||
23 | else | ||
24 | { | ||
25 | printf("[%d] read: %s\n", id, pStr->c_str() ); | ||
26 | delete pStr; | ||
27 | } | ||
28 | usleep( (int)(((double)rand())/((double)RAND_MAX)*2000000.0) ); | ||
29 | } | ||
30 | |||
31 | return NULL; | ||
32 | } | ||
33 | |||
34 | private: | ||
35 | Bu::ItoQueue<std::string *> &q; | ||
36 | int id; | ||
37 | }; | ||
38 | |||
39 | class Writer : public Bu::Ito | ||
40 | { | ||
41 | public: | ||
42 | Writer( Bu::ItoQueue<std::string *> &q, int id, const char *strbase ) : | ||
43 | q( q ), | ||
44 | strbase( strbase ), | ||
45 | id( id ) | ||
46 | { | ||
47 | } | ||
48 | |||
49 | void *run() | ||
50 | { | ||
51 | for( int i = 0; i < 11; i++ ) | ||
52 | { | ||
53 | usleep( (int)(((double)rand())/((double)RAND_MAX)*2000000.0) ); | ||
54 | q.enqueue( new std::string( strbase ) ); | ||
55 | printf("[%d] write: %s\n", id, strbase ); | ||
56 | } | ||
57 | |||
58 | return NULL; | ||
59 | } | ||
60 | |||
61 | private: | ||
62 | Bu::ItoQueue<std::string *> &q; | ||
63 | const char *strbase; | ||
64 | int id; | ||
65 | }; | ||
66 | |||
67 | int main() | ||
68 | { | ||
69 | Writer *wr[5]; | ||
70 | Reader *rd[5]; | ||
71 | const char bob[][7]={ | ||
72 | {"Test 1"}, | ||
73 | {"Test 2"}, | ||
74 | {"Test 3"}, | ||
75 | {"Test 4"}, | ||
76 | {"Test 5"} | ||
77 | }; | ||
78 | |||
79 | Bu::ItoQueue<std::string *> q; | ||
80 | |||
81 | for( int j = 0; j < 5; j++ ) | ||
82 | { | ||
83 | wr[j] = new Writer( q, j, bob[j] ); | ||
84 | rd[j] = new Reader( q, j ); | ||
85 | } | ||
86 | |||
87 | for( int j = 0; j < 5; j++ ) | ||
88 | { | ||
89 | rd[j]->start(); | ||
90 | } | ||
91 | |||
92 | for( int j = 0; j < 5; j++ ) | ||
93 | { | ||
94 | wr[j]->start(); | ||
95 | } | ||
96 | |||
97 | for( int j = 0; j < 5; j++ ) | ||
98 | { | ||
99 | rd[j]->join(); | ||
100 | } | ||
101 | |||
102 | for( int j = 0; j < 5; j++ ) | ||
103 | { | ||
104 | delete wr[j]; | ||
105 | delete rd[j]; | ||
106 | } | ||
107 | |||
108 | return 0; | ||
109 | } | ||
110 | |||
diff --git a/src/tests/itoqueue2.cpp b/src/tests/itoqueue2.cpp new file mode 100644 index 0000000..f4b5e19 --- /dev/null +++ b/src/tests/itoqueue2.cpp | |||
@@ -0,0 +1,83 @@ | |||
1 | #include <string> | ||
2 | #include "bu/ito.h" | ||
3 | #include "bu/itoqueue.h" | ||
4 | #include <errno.h> | ||
5 | |||
6 | class Reader : public Bu::Ito | ||
7 | { | ||
8 | public: | ||
9 | Reader( Bu::ItoQueue<std::string *> &q, int id ) : | ||
10 | q( q ), | ||
11 | id( id ) | ||
12 | { | ||
13 | } | ||
14 | |||
15 | void *run() | ||
16 | { | ||
17 | for( int i = 0; i < 10; i++ ) | ||
18 | { | ||
19 | std::string *pStr = q.dequeue( 0, 500000 ); | ||
20 | if( pStr == NULL ) | ||
21 | { | ||
22 | printf("Null received...\n"); | ||
23 | i--; | ||
24 | } | ||
25 | else | ||
26 | { | ||
27 | printf("[%d] read: %s\n", id, pStr->c_str() ); | ||
28 | delete pStr; | ||
29 | } | ||
30 | } | ||
31 | |||
32 | return NULL; | ||
33 | } | ||
34 | |||
35 | private: | ||
36 | Bu::ItoQueue<std::string *> &q; | ||
37 | int id; | ||
38 | }; | ||
39 | |||
40 | class Writer : public Bu::Ito | ||
41 | { | ||
42 | public: | ||
43 | Writer( Bu::ItoQueue<std::string *> &q, int id, const char *strbase ) : | ||
44 | q( q ), | ||
45 | strbase( strbase ), | ||
46 | id( id ) | ||
47 | { | ||
48 | } | ||
49 | |||
50 | void *run() | ||
51 | { | ||
52 | for( int i = 0; i < 11; i++ ) | ||
53 | { | ||
54 | sleep( 2 ); | ||
55 | printf("[%d] write: %s\n", id, strbase ); | ||
56 | q.enqueue( new std::string( strbase ) ); | ||
57 | } | ||
58 | |||
59 | return NULL; | ||
60 | } | ||
61 | |||
62 | private: | ||
63 | Bu::ItoQueue<std::string *> &q; | ||
64 | const char *strbase; | ||
65 | int id; | ||
66 | }; | ||
67 | |||
68 | int main() | ||
69 | { | ||
70 | printf("ETIMEDOUT: %d\n", ETIMEDOUT ); | ||
71 | Bu::ItoQueue<std::string *> q; | ||
72 | Writer wr( q, 0, "writer" ); | ||
73 | Reader rd( q, 0 ); | ||
74 | |||
75 | rd.start(); | ||
76 | wr.start(); | ||
77 | |||
78 | rd.join(); | ||
79 | wr.join(); | ||
80 | |||
81 | return 0; | ||
82 | } | ||
83 | |||
diff --git a/src/tests/list.cpp b/src/tests/list.cpp new file mode 100644 index 0000000..12807a5 --- /dev/null +++ b/src/tests/list.cpp | |||
@@ -0,0 +1,53 @@ | |||
1 | #include "bu/list.h" | ||
2 | #include <list> | ||
3 | |||
4 | typedef struct Bob | ||
5 | { | ||
6 | int nID; | ||
7 | } Bob; | ||
8 | |||
9 | int main() | ||
10 | { | ||
11 | Bu::List<int> l; | ||
12 | |||
13 | l.append( 0 ); | ||
14 | |||
15 | for( int j = 3; j <= 21; j += 3 ) | ||
16 | { | ||
17 | l.append( j ); | ||
18 | l.prepend( -j ); | ||
19 | } | ||
20 | |||
21 | for( Bu::List<int>::iterator i = l.begin(); i != l.end(); i++ ) | ||
22 | { | ||
23 | printf("%d ", *i ); | ||
24 | } | ||
25 | printf("\n"); | ||
26 | for( Bu::List<int>::iterator i = l.begin(); i != l.end(); i++ ) | ||
27 | { | ||
28 | l.erase( i ); | ||
29 | if( i != l.end() ) | ||
30 | printf("%d ", *i ); | ||
31 | } | ||
32 | |||
33 | printf("\n\n"); | ||
34 | |||
35 | Bu::List<Bob> lb; | ||
36 | for( int j = 0; j < 10; j++ ) | ||
37 | { | ||
38 | Bob b; | ||
39 | b.nID = j; | ||
40 | lb.append( b ); | ||
41 | } | ||
42 | |||
43 | const Bu::List<Bob> rb = lb; | ||
44 | |||
45 | for( Bu::List<Bob>::const_iterator i = rb.begin(); i != rb.end(); i++ ) | ||
46 | { | ||
47 | //i->nID += 2; | ||
48 | //(*i).nID = 4; | ||
49 | printf("%d ", i->nID ); | ||
50 | } | ||
51 | printf("\n\n"); | ||
52 | } | ||
53 | |||
diff --git a/src/tests/logger.cpp b/src/tests/logger.cpp new file mode 100644 index 0000000..290f479 --- /dev/null +++ b/src/tests/logger.cpp | |||
@@ -0,0 +1,28 @@ | |||
1 | #include "bu/logger.h" | ||
2 | #include <errno.h> | ||
3 | #include <stdlib.h> | ||
4 | |||
5 | class Thing | ||
6 | { | ||
7 | public: | ||
8 | Thing() | ||
9 | { | ||
10 | lineLog( 2, "Want a thing?"); | ||
11 | } | ||
12 | |||
13 | void go( int i ) | ||
14 | { | ||
15 | lineLog( 1, "GO!!!!"); | ||
16 | } | ||
17 | }; | ||
18 | |||
19 | int main() | ||
20 | { | ||
21 | setLogLevel( 4 ); | ||
22 | setLogFormat("%L: %y-%02m-%02d %h:%02M:%02s %f:%l:%F: %t"); | ||
23 | lineLog( 5, "Hey, error: %s", strerror( errno ) ); | ||
24 | |||
25 | Thing gh; | ||
26 | gh.go( 6); | ||
27 | } | ||
28 | |||
diff --git a/src/tests/ringbuffer.cpp b/src/tests/ringbuffer.cpp new file mode 100644 index 0000000..259ec1f --- /dev/null +++ b/src/tests/ringbuffer.cpp | |||
@@ -0,0 +1,29 @@ | |||
1 | #include "bu/ringbuffer.h" | ||
2 | #include <stdlib.h> | ||
3 | |||
4 | int main() | ||
5 | { | ||
6 | Bu::RingBuffer<uint32_t> ibuf( 10 ); | ||
7 | |||
8 | for( int k = 0; k < 2; k++ ) | ||
9 | { | ||
10 | int j = 1; | ||
11 | for(; j < 7; j++ ) | ||
12 | { | ||
13 | ibuf.enqueue( j ); | ||
14 | } | ||
15 | |||
16 | for(; j < 20; j++ ) | ||
17 | { | ||
18 | ibuf.enqueue( j ); | ||
19 | printf("- %d\n", ibuf.dequeue() ); | ||
20 | } | ||
21 | |||
22 | for(;;) | ||
23 | { | ||
24 | if( ibuf.isEmpty() ) break; | ||
25 | printf(". %d\n", ibuf.dequeue() ); | ||
26 | } | ||
27 | } | ||
28 | } | ||
29 | |||
diff --git a/src/tests/taf.cpp b/src/tests/taf.cpp new file mode 100644 index 0000000..e3da120 --- /dev/null +++ b/src/tests/taf.cpp | |||
@@ -0,0 +1,24 @@ | |||
1 | #include "bu/tafreader.h" | ||
2 | #include "bu/tafwriter.h" | ||
3 | #include "bu/file.h" | ||
4 | |||
5 | int main() | ||
6 | { | ||
7 | Bu::File f("test.taf", "rb"); | ||
8 | Bu::TafReader tr( f ); | ||
9 | |||
10 | Bu::TafGroup *pGroup = tr.readGroup(); | ||
11 | |||
12 | const Bu::TafGroup *pStats = pGroup->getChild("stats"); | ||
13 | printf("%s\n", pStats->getName().getStr() ); | ||
14 | printf(" str = %s\n", pStats->getProperty("str").getStr() ); | ||
15 | |||
16 | { | ||
17 | Bu::File fo("out.taf", "wb"); | ||
18 | Bu::TafWriter tw( fo ); | ||
19 | tw.writeGroup( pGroup ); | ||
20 | } | ||
21 | |||
22 | delete pGroup; | ||
23 | } | ||
24 | |||