diff options
Diffstat (limited to 'src/tests')
45 files changed, 505 insertions, 1541 deletions
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/clistress.cpp b/src/tests/clistress.cpp deleted file mode 100644 index 6b0ac66..0000000 --- a/src/tests/clistress.cpp +++ /dev/null | |||
@@ -1,20 +0,0 @@ | |||
1 | #include "connection.h" | ||
2 | |||
3 | int main() | ||
4 | { | ||
5 | Connection c; | ||
6 | |||
7 | c.open("localhost", 4001 ); | ||
8 | |||
9 | c.appendOutput("w"); | ||
10 | c.writeOutput(); | ||
11 | |||
12 | c.waitForInput( 6, 5, 0 ); | ||
13 | |||
14 | printf("read: %s\n", c.getInput() ); | ||
15 | |||
16 | c.close(); | ||
17 | |||
18 | return 0; | ||
19 | } | ||
20 | |||
diff --git a/src/tests/confpair.cpp b/src/tests/confpair.cpp deleted file mode 100644 index fb1b0d3..0000000 --- a/src/tests/confpair.cpp +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | #include "confpair.h" | ||
2 | #include <iostream> | ||
3 | |||
4 | using namespace std; | ||
5 | |||
6 | int main() | ||
7 | { | ||
8 | ConfPair<float> p1("DebugMode"); | ||
9 | p1.value() = 12; | ||
10 | cout << p1.value() << "\n"; | ||
11 | p1.value() = 55; | ||
12 | cout << p1.value() << "\n"; | ||
13 | |||
14 | ConfPairBase &p = p1; | ||
15 | |||
16 | p = "33.12"; | ||
17 | cout << p.getAsString(); | ||
18 | } | ||
19 | |||
diff --git a/src/tests/connect.cpp b/src/tests/connect.cpp deleted file mode 100644 index a9fca64..0000000 --- a/src/tests/connect.cpp +++ /dev/null | |||
@@ -1,38 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <unistd.h> | ||
4 | #include <fcntl.h> | ||
5 | #include "connection.h" | ||
6 | |||
7 | int main() | ||
8 | { | ||
9 | Connection c; | ||
10 | c.open("127.0.0.1", 12457 ); | ||
11 | |||
12 | { | ||
13 | int newSocket = c.getSocket(); | ||
14 | int flags; | ||
15 | |||
16 | flags = fcntl(newSocket, F_GETFL, 0); | ||
17 | flags |= O_NONBLOCK; | ||
18 | if (fcntl(newSocket, F_SETFL, flags) < 0) | ||
19 | { | ||
20 | return false; | ||
21 | } | ||
22 | } | ||
23 | |||
24 | for( int i = 0; i < 50; i++ ) | ||
25 | { | ||
26 | usleep( 100000 ); | ||
27 | int nbytes = c.readInput(); | ||
28 | if( nbytes == 0 ) | ||
29 | printf("0 bytes, EOF?\n"); | ||
30 | else | ||
31 | printf("Got %d bytes, whacky...\n", nbytes ); | ||
32 | } | ||
33 | |||
34 | c.close(); | ||
35 | |||
36 | return 0; | ||
37 | } | ||
38 | |||
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/exception.cpp b/src/tests/exception.cpp deleted file mode 100644 index 6417692..0000000 --- a/src/tests/exception.cpp +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | #include <iostream> | ||
2 | #include "exceptions.h" | ||
3 | |||
4 | int main() | ||
5 | { | ||
6 | try | ||
7 | { | ||
8 | throw ExceptionBase( 42, "There was an error on line: %d", __LINE__ ); | ||
9 | } | ||
10 | catch( ExceptionBase &e ) | ||
11 | { | ||
12 | std::cout << "Error "<< e.getErrorCode() << ": " << e.what() << "\n"; | ||
13 | } | ||
14 | |||
15 | throw ExceptionBase( 112, "This exception wasn't caught!"); | ||
16 | } | ||
diff --git a/src/tests/formula.cpp b/src/tests/formula.cpp deleted file mode 100644 index 976b039..0000000 --- a/src/tests/formula.cpp +++ /dev/null | |||
@@ -1,13 +0,0 @@ | |||
1 | #include "formula.h" | ||
2 | |||
3 | int main( int argc, char *argv[] ) | ||
4 | { | ||
5 | if( argc < 2 ) return 0; | ||
6 | |||
7 | Formula f; | ||
8 | double dOut = f.run( argv[1] ); | ||
9 | printf("%s = %f\n", argv[1], dOut ); | ||
10 | |||
11 | return 0; | ||
12 | } | ||
13 | |||
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/hashtest.cpp b/src/tests/hashtest.cpp deleted file mode 100644 index eaa84a0..0000000 --- a/src/tests/hashtest.cpp +++ /dev/null | |||
@@ -1,107 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <iostream> | ||
3 | #include "hashtable.h" | ||
4 | #include "hashfunctioncasestring.h" | ||
5 | |||
6 | int main() | ||
7 | { | ||
8 | const char *names[]={ | ||
9 | "Homer the Great", | ||
10 | "And Maggie Makes Three", | ||
11 | "Bart's Comet", | ||
12 | "Homie The Clown", | ||
13 | "Bart Vs Australia", | ||
14 | "Homer vs Patty and Selma", | ||
15 | "A star is burns", | ||
16 | "Lisa's Wedding", | ||
17 | "Two Dozen and One Greyhounds", | ||
18 | "The PTA Disbands", | ||
19 | "Round Springfield", | ||
20 | "The Springfield connection", | ||
21 | "Lemon of Troy", | ||
22 | "Who Shot Mr. Burns (Pt. 1)", | ||
23 | "Who Shot Mr. Burns (pt. 2)", | ||
24 | "Radioactive Man", | ||
25 | "Home Sweet Homediddly-dum-doodly", | ||
26 | "Bart Sells His Soul", | ||
27 | "Lisa the Vegetarian", | ||
28 | "Treehouse of horror VI", | ||
29 | "King Size Homer", | ||
30 | "Mother Simpson", | ||
31 | "Sideshow Bob's Last Gleaming", | ||
32 | "The Simpson's 138th Show Spectacular", | ||
33 | "Marge Be Not Proud", | ||
34 | "Team Homer", | ||
35 | "Two Bad Neighbors", | ||
36 | "Scenes From the Class Struggle in Springfield", | ||
37 | "Bart the Fink", | ||
38 | "Lisa the Iconoclast", | ||
39 | "Homer the Smithers", | ||
40 | "The Day the Violence Died", | ||
41 | "A Fish Called Selma", | ||
42 | "Bart on the road", | ||
43 | "22 Short Films about Springfield", | ||
44 | "The Curse of the Flying Hellfish", | ||
45 | "Much Apu about Nothing", | ||
46 | "Homerpalooza", | ||
47 | "The Summer of 4 Ft 2", | ||
48 | "Treehouse of Horror VII", | ||
49 | "You Only Move Twice", | ||
50 | "The Homer They Fall", | ||
51 | "Burns Baby Burns", | ||
52 | "Bart After Dark", | ||
53 | "A Millhouse Divided", | ||
54 | "Lisas Date With Destiny", | ||
55 | "Hurricane Neddy", | ||
56 | "The Mysterious Voyage of Our Homer", | ||
57 | "The Springfield Files", | ||
58 | "The Twisted World of Marge Simpson", | ||
59 | "Mountain of Madness", | ||
60 | NULL | ||
61 | }; | ||
62 | |||
63 | HashTable h( new HashFunctionCaseString(), 5, false ); | ||
64 | |||
65 | int j; | ||
66 | printf("Inserting...\n"); | ||
67 | for( j = 0; j < 10; j++ ) | ||
68 | { | ||
69 | h.insert( names[j], (void *)(j+1) ); | ||
70 | h.insert( names[j], (void *)(j+1) ); | ||
71 | printf("Capacity: %lu, Size: %lu, Load: %f\n", | ||
72 | h.getCapacity(), | ||
73 | h.getSize(), | ||
74 | h.getLoad() | ||
75 | ); | ||
76 | } | ||
77 | |||
78 | for( j = 0; j < 10; j++ ) | ||
79 | { | ||
80 | printf("\"%s\" = %d\n", names[j], (int)h[names[j]] ); | ||
81 | } | ||
82 | |||
83 | printf("\nDeleting some...\n"); | ||
84 | |||
85 | for( int k = 0; k < 7; k++ ) | ||
86 | { | ||
87 | h.del( names[k] ); | ||
88 | //h.insert( names[j], (void *)(j+1) ); | ||
89 | printf("Capacity: %lu, Size: %lu, Load: %f\n", | ||
90 | h.getCapacity(), | ||
91 | h.getSize(), | ||
92 | h.getLoad() | ||
93 | ); | ||
94 | } | ||
95 | |||
96 | printf("\nInserting more...\n"); | ||
97 | |||
98 | for( ; names[j] != NULL; j++ ) | ||
99 | { | ||
100 | h.insert( names[j], (void *)(j+1) ); | ||
101 | printf("Capacity: %lu, Size: %lu, Load: %f\n", | ||
102 | h.getCapacity(), | ||
103 | h.getSize(), | ||
104 | h.getLoad() | ||
105 | ); | ||
106 | } | ||
107 | } | ||
diff --git a/src/tests/hashtest2.cpp b/src/tests/hashtest2.cpp deleted file mode 100644 index 74700fd..0000000 --- a/src/tests/hashtest2.cpp +++ /dev/null | |||
@@ -1,15 +0,0 @@ | |||
1 | #include "hash.h" | ||
2 | #include <string.h> | ||
3 | |||
4 | int main() | ||
5 | { | ||
6 | char *a, *b; | ||
7 | a = new char[10]; | ||
8 | b = new char[10]; | ||
9 | strcpy( a, "Hey there"); | ||
10 | strcpy( b, "Hey there"); | ||
11 | printf("Same: %s\n", __cmpHashKeys( a, b )?"yes":"no"); | ||
12 | |||
13 | return 0; | ||
14 | } | ||
15 | |||
diff --git a/src/tests/httpsrv/httpconnectionmonitor.cpp b/src/tests/httpsrv/httpconnectionmonitor.cpp deleted file mode 100644 index 51d82f3..0000000 --- a/src/tests/httpsrv/httpconnectionmonitor.cpp +++ /dev/null | |||
@@ -1,88 +0,0 @@ | |||
1 | #include "httpconnectionmonitor.h" | ||
2 | #include "http.h" | ||
3 | #include "exceptions.h" | ||
4 | #include <sys/stat.h> | ||
5 | |||
6 | HttpConnectionMonitor::HttpConnectionMonitor() | ||
7 | { | ||
8 | } | ||
9 | |||
10 | HttpConnectionMonitor::~HttpConnectionMonitor() | ||
11 | { | ||
12 | } | ||
13 | |||
14 | bool HttpConnectionMonitor::onNewConnection( Connection *pCon, int nPort ) | ||
15 | { | ||
16 | printf("Got connection on port %d\n", nPort ); | ||
17 | |||
18 | try | ||
19 | { | ||
20 | pCon->readInput( 60, 0 ); | ||
21 | printf("#######################\n%s\n#######################\n", pCon->getInput() ); | ||
22 | |||
23 | Http hp( pCon ); | ||
24 | while( hp.parseRequest() == false ); | ||
25 | printf("Done parsing.\n\n"); | ||
26 | |||
27 | if( hp.getRequestType() == Http::reqGet ) | ||
28 | { | ||
29 | printf("\"\"\"%s\"\"\"\n", hp.getRequestURI() ); | ||
30 | if( !strcmp( hp.getRequestURI(), "/" ) ) | ||
31 | { | ||
32 | std::string content("<html><head><title>Server Test</test></head><body>This is a test of a new system where all the pages will be more or less dynamic...<br>If you want to try to login, you can do that here:<br><form method=\"post\" action=\"showvars\" enctype=\"multipart/form-data\">Name: <input type=\"text\" name=\"name\"><br>Password: <input type=\"password\" name=\"pass\"><br><input type=\"submit\" name=\"action\" value=\"login\"></form></body></html>"); | ||
33 | hp.buildResponse(); | ||
34 | hp.setResponseContent( | ||
35 | "text/html", | ||
36 | content.c_str(), | ||
37 | content.size() | ||
38 | ); | ||
39 | hp.sendResponse(); | ||
40 | } | ||
41 | else | ||
42 | { | ||
43 | std::string content("<html><head><title>URL Not Found</test></head><body>There is no content mapped to the URL you requested. Please try another one.</body></html>"); | ||
44 | hp.buildResponse( 404, "File not found."); | ||
45 | hp.setResponseContent( | ||
46 | "text/html", | ||
47 | content.c_str(), | ||
48 | content.size() | ||
49 | ); | ||
50 | hp.sendResponse(); | ||
51 | } | ||
52 | } | ||
53 | else | ||
54 | { | ||
55 | printf("Non get: %s\n", hp.getRequestTypeStr() ); | ||
56 | pCon->appendOutput("HTTP/1.1 100 Continue\r\n\r\n"); | ||
57 | } | ||
58 | pCon->writeOutput(); | ||
59 | //for( int j = 0; j < 50; j++ ) | ||
60 | { | ||
61 | pCon->readInput( 1, 0 ); | ||
62 | //printf("Size so far: %d\n", pCon->getInputAmnt() ); | ||
63 | } | ||
64 | |||
65 | if( pCon->hasInput() ) | ||
66 | { | ||
67 | std::string s( pCon->getInput(), pCon->getInputAmnt() ); | ||
68 | |||
69 | pCon->printInputDebug(); | ||
70 | //printf("Reamining data\n==============\n%s\n==============\n", | ||
71 | // s.c_str() ); | ||
72 | } | ||
73 | |||
74 | pCon->disconnect(); | ||
75 | } | ||
76 | catch( ConnectionException &e ) | ||
77 | { | ||
78 | printf("Connection: %s\n", e.what() ); | ||
79 | } | ||
80 | |||
81 | return true; | ||
82 | } | ||
83 | |||
84 | bool HttpConnectionMonitor::onClosedConnection( Connection *pCon ) | ||
85 | { | ||
86 | return true; | ||
87 | } | ||
88 | |||
diff --git a/src/tests/httpsrv/httpconnectionmonitor.h b/src/tests/httpsrv/httpconnectionmonitor.h deleted file mode 100644 index 30c0afd..0000000 --- a/src/tests/httpsrv/httpconnectionmonitor.h +++ /dev/null | |||
@@ -1,16 +0,0 @@ | |||
1 | #ifndef HTTPCONNECTIONMONITOR_H | ||
2 | #define HTTPCONNECTIONMONITOR_H | ||
3 | |||
4 | #include "connectionmonitor.h" | ||
5 | |||
6 | class HttpConnectionMonitor : public ConnectionMonitor | ||
7 | { | ||
8 | public: | ||
9 | HttpConnectionMonitor(); | ||
10 | ~HttpConnectionMonitor(); | ||
11 | |||
12 | bool onNewConnection( Connection *pCon, int nPort ); | ||
13 | bool onClosedConnection( Connection *pCon ); | ||
14 | }; | ||
15 | |||
16 | #endif | ||
diff --git a/src/tests/httpsrv/main.cpp b/src/tests/httpsrv/main.cpp deleted file mode 100644 index 2f1563c..0000000 --- a/src/tests/httpsrv/main.cpp +++ /dev/null | |||
@@ -1,22 +0,0 @@ | |||
1 | #include "connectionmanager.h" | ||
2 | #include "httpconnectionmonitor.h" | ||
3 | |||
4 | int main() | ||
5 | { | ||
6 | printf("Starting server...\n"); | ||
7 | |||
8 | ConnectionManager srv; | ||
9 | HttpConnectionMonitor http; | ||
10 | |||
11 | srv.setConnectionMonitor( &http ); | ||
12 | |||
13 | printf("Listening on port 7331\n"); | ||
14 | srv.startServer( 7331 ); | ||
15 | |||
16 | for(;;) | ||
17 | { | ||
18 | srv.scanConnections( 5000, false ); | ||
19 | } | ||
20 | |||
21 | return 0; | ||
22 | } | ||
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/log.cpp b/src/tests/log.cpp deleted file mode 100644 index d7cfa0b..0000000 --- a/src/tests/log.cpp +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <iostream> | ||
4 | #include "multilog.h" | ||
5 | #include "multilogtext.h" | ||
6 | |||
7 | class Test | ||
8 | { | ||
9 | public: | ||
10 | Test() | ||
11 | { | ||
12 | MultiLineLog( 4, "Test init'd\n"); | ||
13 | } | ||
14 | }; | ||
15 | |||
16 | int main() | ||
17 | { | ||
18 | MultiLog &xLog = MultiLog::getInstance(); | ||
19 | |||
20 | xLog.LineLog( 2, "Hello again"); | ||
21 | |||
22 | MultiLog::getInstance().addChannel( | ||
23 | new MultiLogText( STDOUT_FILENO, "%02y-%02m-%02d %02h:%02M:%02s: %t" ) | ||
24 | ); | ||
25 | |||
26 | MultiLineLog( MultiLog::LError, "Hi there!"); | ||
27 | Test t; | ||
28 | } | ||
29 | |||
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/md5test.cpp b/src/tests/md5test.cpp deleted file mode 100644 index 6f832df..0000000 --- a/src/tests/md5test.cpp +++ /dev/null | |||
@@ -1,19 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <string.h> | ||
3 | #include "md5.h" | ||
4 | |||
5 | int main() | ||
6 | { | ||
7 | md5 mproc; | ||
8 | md5sum sum; | ||
9 | char hexstr[33]; | ||
10 | |||
11 | memset( hexstr, 0, 33 ); | ||
12 | |||
13 | mproc.sumString( &sum, "qwertyuiopasdfgh" ); | ||
14 | mproc.sumToHex( &sum, hexstr ); | ||
15 | printf("sum: %s\n", hexstr ); | ||
16 | printf("chk: 1ebfc043d8880b758b13ddc8aa1638ef\n"); | ||
17 | |||
18 | return 0; | ||
19 | } | ||
diff --git a/src/tests/ordhash.cpp b/src/tests/ordhash.cpp deleted file mode 100644 index f1d96ec..0000000 --- a/src/tests/ordhash.cpp +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | #include "ordhash.h" | ||
2 | #include <string> | ||
3 | |||
4 | typedef struct eldef | ||
5 | { | ||
6 | eldef( int a, int b, const std::string &c ) : | ||
7 | id( a ), nSequence( b ), sName( c ) {} | ||
8 | int id; | ||
9 | int nSequence; | ||
10 | std::string sName; | ||
11 | } eldef; | ||
12 | |||
13 | struct seqcmp | ||
14 | { | ||
15 | bool operator()( eldef **a, eldef **b ) | ||
16 | { | ||
17 | return (*a)->nSequence < (*b)->nSequence; | ||
18 | } | ||
19 | }; | ||
20 | |||
21 | struct namcmp | ||
22 | { | ||
23 | bool operator()( eldef **a, eldef **b ) | ||
24 | { | ||
25 | return (*a)->sName < (*b)->sName; | ||
26 | } | ||
27 | }; | ||
28 | |||
29 | typedef OrdHash<int, eldef, seqcmp> AHash; | ||
30 | //typedef OrdHash<int, eldef, namcmp> AHash; | ||
31 | |||
32 | int main() | ||
33 | { | ||
34 | AHash hsh; | ||
35 | hsh[1] = eldef( 0, 43, "Bob"); | ||
36 | hsh[4] = eldef( 1, 443, "Abby"); | ||
37 | hsh[2] = eldef( 2, 1, "Name"); | ||
38 | hsh[5] = eldef( 3, 0, "Catagory"); | ||
39 | hsh[32] = eldef( 4, 12, "Epilogue"); | ||
40 | |||
41 | for( AHash::iterator i = hsh.begin(); i != hsh.end(); i++ ) | ||
42 | { | ||
43 | eldef e = (*i).second; | ||
44 | printf("%d, %d, %s\n", e.id, e.nSequence, e.sName.c_str() ); | ||
45 | } | ||
46 | |||
47 | } | ||
48 | |||
diff --git a/src/tests/param.cpp b/src/tests/param.cpp deleted file mode 100644 index a4d2824..0000000 --- a/src/tests/param.cpp +++ /dev/null | |||
@@ -1,46 +0,0 @@ | |||
1 | #include "param.h" | ||
2 | #include <stdio.h> | ||
3 | |||
4 | Param::Param() | ||
5 | { | ||
6 | addHelpBanner("param - A test of the libbu++ parameter systems\n" | ||
7 | "Enjoy with care and caution\n\nTest stuff:\n"); | ||
8 | addParam( "name", 's', mkproc( Param::printStuff ), &str, "Test a param param" ); | ||
9 | //addParam( "name", &str ); | ||
10 | addParam( "job", 'U', mkproc( Param::printStuff ), "Test a paramless param" ); | ||
11 | |||
12 | addHelpBanner("\nInformational:\n"); | ||
13 | addParam( "help", mkproc( ParamProc::help ), "Help!" ); | ||
14 | |||
15 | addHelpBanner("\nThanks for trying my test!\n\n"); | ||
16 | } | ||
17 | |||
18 | Param::~Param() | ||
19 | { | ||
20 | } | ||
21 | |||
22 | int Param::printStuff( int argc, char *argv[] ) | ||
23 | { | ||
24 | printf("------------%02d-------------\n", argc ); | ||
25 | for( int j = 0; j < argc; j++ ) | ||
26 | { | ||
27 | printf("%d: %s\n", j, argv[j] ); | ||
28 | } | ||
29 | printf("---------------------------\n" ); | ||
30 | printf("SETVAR===\"%s\"\n", str.c_str() ); | ||
31 | |||
32 | return 1; | ||
33 | } | ||
34 | |||
35 | int main( int argc, char *argv[] ) | ||
36 | { | ||
37 | if( argc == 1 ) | ||
38 | { | ||
39 | printf("You have to enter some parameter, try '--help'\n\n"); | ||
40 | return 0; | ||
41 | } | ||
42 | |||
43 | Param p; | ||
44 | p.process( argc, argv ); | ||
45 | } | ||
46 | |||
diff --git a/src/tests/param.h b/src/tests/param.h deleted file mode 100644 index 2756b69..0000000 --- a/src/tests/param.h +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | #ifndef PARAM_H | ||
2 | #define PARAM_H | ||
3 | |||
4 | #include <stdint.h> | ||
5 | |||
6 | #include "paramproc.h" | ||
7 | |||
8 | class Param : public ParamProc | ||
9 | { | ||
10 | public: | ||
11 | Param(); | ||
12 | virtual ~Param(); | ||
13 | |||
14 | private: | ||
15 | int printStuff( int argc, char *argv[] ); | ||
16 | |||
17 | std::string str; | ||
18 | uint32_t uint32; | ||
19 | }; | ||
20 | |||
21 | #endif | ||
diff --git a/src/tests/plugin/main.cpp b/src/tests/plugin/main.cpp deleted file mode 100644 index 51c8390..0000000 --- a/src/tests/plugin/main.cpp +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | #include "plugger.h" | ||
2 | #include "plugin.h" | ||
3 | |||
4 | int main() | ||
5 | { | ||
6 | Plugger<Plugin> p; | ||
7 | |||
8 | p.registerExternalPlugin( "./guy.so", "Guy" ); | ||
9 | |||
10 | Plugin *t = p.instantiate( "Guy" ); | ||
11 | |||
12 | p.destroy( t ); | ||
13 | } | ||
14 | |||
diff --git a/src/tests/plugin/plugin.cpp b/src/tests/plugin/plugin.cpp deleted file mode 100644 index ea558fd..0000000 --- a/src/tests/plugin/plugin.cpp +++ /dev/null | |||
@@ -1,10 +0,0 @@ | |||
1 | #include "plugin.h" | ||
2 | |||
3 | Plugin::Plugin() | ||
4 | { | ||
5 | } | ||
6 | |||
7 | Plugin::~Plugin() | ||
8 | { | ||
9 | } | ||
10 | |||
diff --git a/src/tests/plugin/plugin.h b/src/tests/plugin/plugin.h deleted file mode 100644 index f726867..0000000 --- a/src/tests/plugin/plugin.h +++ /dev/null | |||
@@ -1,14 +0,0 @@ | |||
1 | #ifndef PLUGIN_H | ||
2 | #define PLUGIN_H | ||
3 | |||
4 | class Plugin | ||
5 | { | ||
6 | public: | ||
7 | Plugin(); | ||
8 | virtual ~Plugin(); | ||
9 | |||
10 | private: | ||
11 | |||
12 | }; | ||
13 | |||
14 | #endif | ||
diff --git a/src/tests/qsort.cpp b/src/tests/qsort.cpp deleted file mode 100644 index 28c6f03..0000000 --- a/src/tests/qsort.cpp +++ /dev/null | |||
@@ -1,228 +0,0 @@ | |||
1 | #define _QSORT_SWAP(a, b, t) ((void)((t = *a), (*a = *b), (*b = t))) | ||
2 | |||
3 | /* Discontinue quicksort algorithm when partition gets below this size. | ||
4 | This particular magic number was chosen to work best on a Sun 4/260. */ | ||
5 | #define _QSORT_MAX_THRESH 4 | ||
6 | |||
7 | /* Stack node declarations used to store unfulfilled partition obligations | ||
8 | * (inlined in QSORT). | ||
9 | typedef struct { | ||
10 | QSORT_TYPE *_lo, *_hi; | ||
11 | } qsort_stack_node; | ||
12 | */ | ||
13 | |||
14 | /* The next 4 #defines implement a very fast in-line stack abstraction. */ | ||
15 | /* The stack needs log (total_elements) entries (we could even subtract | ||
16 | log(MAX_THRESH)). Since total_elements has type unsigned, we get as | ||
17 | upper bound for log (total_elements): | ||
18 | bits per byte (CHAR_BIT) * sizeof(unsigned). */ | ||
19 | #define _QSORT_STACK_SIZE (8 * sizeof(unsigned)) | ||
20 | #define _QSORT_PUSH(top, low, high) \ | ||
21 | (((top->_lo = (low)), (top->_hi = (high)), ++top)) | ||
22 | #define _QSORT_POP(low, high, top) \ | ||
23 | ((--top, (low = top->_lo), (high = top->_hi))) | ||
24 | #define _QSORT_STACK_NOT_EMPTY (_stack < _top) | ||
25 | |||
26 | |||
27 | /* Order size using quicksort. This implementation incorporates | ||
28 | four optimizations discussed in Sedgewick: | ||
29 | |||
30 | 1. Non-recursive, using an explicit stack of pointer that store the | ||
31 | next array partition to sort. To save time, this maximum amount | ||
32 | of space required to store an array of SIZE_MAX is allocated on the | ||
33 | stack. Assuming a 32-bit (64 bit) integer for size_t, this needs | ||
34 | only 32 * sizeof(stack_node) == 256 bytes (for 64 bit: 1024 bytes). | ||
35 | Pretty cheap, actually. | ||
36 | |||
37 | 2. Chose the pivot element using a median-of-three decision tree. | ||
38 | This reduces the probability of selecting a bad pivot value and | ||
39 | eliminates certain extraneous comparisons. | ||
40 | |||
41 | 3. Only quicksorts TOTAL_ELEMS / MAX_THRESH partitions, leaving | ||
42 | insertion sort to order the MAX_THRESH items within each partition. | ||
43 | This is a big win, since insertion sort is faster for small, mostly | ||
44 | sorted array segments. | ||
45 | |||
46 | 4. The larger of the two sub-partitions is always pushed onto the | ||
47 | stack first, with the algorithm then concentrating on the | ||
48 | smaller partition. This *guarantees* no more than log (total_elems) | ||
49 | stack size is needed (actually O(1) in this case)! */ | ||
50 | |||
51 | /* The main code starts here... */ | ||
52 | |||
53 | template<typename QSORT_TYPE, typename QSORT_LTT> | ||
54 | void qsrt( QSORT_TYPE *QSORT_BASE, int QSORT_NELT ) | ||
55 | { | ||
56 | QSORT_LTT QSORT_LT; | ||
57 | QSORT_TYPE *const _base = (QSORT_BASE); | ||
58 | const unsigned _elems = (QSORT_NELT); | ||
59 | QSORT_TYPE _hold; | ||
60 | |||
61 | /* Don't declare two variables of type QSORT_TYPE in a single | ||
62 | * statement: eg `TYPE a, b;', in case if TYPE is a pointer, | ||
63 | * expands to `type* a, b;' wich isn't what we want. | ||
64 | */ | ||
65 | |||
66 | if (_elems > _QSORT_MAX_THRESH) { | ||
67 | QSORT_TYPE *_lo = _base; | ||
68 | QSORT_TYPE *_hi = _lo + _elems - 1; | ||
69 | struct { | ||
70 | QSORT_TYPE *_hi; QSORT_TYPE *_lo; | ||
71 | } _stack[_QSORT_STACK_SIZE], *_top = _stack + 1; | ||
72 | |||
73 | while (_QSORT_STACK_NOT_EMPTY) { | ||
74 | QSORT_TYPE *_left_ptr; QSORT_TYPE *_right_ptr; | ||
75 | |||
76 | /* Select median value from among LO, MID, and HI. Rearrange | ||
77 | LO and HI so the three values are sorted. This lowers the | ||
78 | probability of picking a pathological pivot value and | ||
79 | skips a comparison for both the LEFT_PTR and RIGHT_PTR in | ||
80 | the while loops. */ | ||
81 | |||
82 | QSORT_TYPE *_mid = _lo + ((_hi - _lo) >> 1); | ||
83 | |||
84 | if (QSORT_LT (_mid, _lo)) | ||
85 | _QSORT_SWAP (_mid, _lo, _hold); | ||
86 | if (QSORT_LT (_hi, _mid)) | ||
87 | _QSORT_SWAP (_mid, _hi, _hold); | ||
88 | else | ||
89 | goto _jump_over; | ||
90 | if (QSORT_LT (_mid, _lo)) | ||
91 | _QSORT_SWAP (_mid, _lo, _hold); | ||
92 | _jump_over:; | ||
93 | |||
94 | _left_ptr = _lo + 1; | ||
95 | _right_ptr = _hi - 1; | ||
96 | |||
97 | /* Here's the famous ``collapse the walls'' section of quicksort. | ||
98 | Gotta like those tight inner loops! They are the main reason | ||
99 | that this algorithm runs much faster than others. */ | ||
100 | do { | ||
101 | while (QSORT_LT (_left_ptr, _mid)) | ||
102 | ++_left_ptr; | ||
103 | |||
104 | while (QSORT_LT (_mid, _right_ptr)) | ||
105 | --_right_ptr; | ||
106 | |||
107 | if (_left_ptr < _right_ptr) { | ||
108 | _QSORT_SWAP (_left_ptr, _right_ptr, _hold); | ||
109 | if (_mid == _left_ptr) | ||
110 | _mid = _right_ptr; | ||
111 | else if (_mid == _right_ptr) | ||
112 | _mid = _left_ptr; | ||
113 | ++_left_ptr; | ||
114 | --_right_ptr; | ||
115 | } | ||
116 | else if (_left_ptr == _right_ptr) { | ||
117 | ++_left_ptr; | ||
118 | --_right_ptr; | ||
119 | break; | ||
120 | } | ||
121 | } while (_left_ptr <= _right_ptr); | ||
122 | |||
123 | /* Set up pointers for next iteration. First determine whether | ||
124 | left and right partitions are below the threshold size. If so, | ||
125 | ignore one or both. Otherwise, push the larger partition's | ||
126 | bounds on the stack and continue sorting the smaller one. */ | ||
127 | |||
128 | if (_right_ptr - _lo <= _QSORT_MAX_THRESH) { | ||
129 | if (_hi - _left_ptr <= _QSORT_MAX_THRESH) | ||
130 | /* Ignore both small partitions. */ | ||
131 | _QSORT_POP (_lo, _hi, _top); | ||
132 | else | ||
133 | /* Ignore small left partition. */ | ||
134 | _lo = _left_ptr; | ||
135 | } | ||
136 | else if (_hi - _left_ptr <= _QSORT_MAX_THRESH) | ||
137 | /* Ignore small right partition. */ | ||
138 | _hi = _right_ptr; | ||
139 | else if (_right_ptr - _lo > _hi - _left_ptr) { | ||
140 | /* Push larger left partition indices. */ | ||
141 | _QSORT_PUSH (_top, _lo, _right_ptr); | ||
142 | _lo = _left_ptr; | ||
143 | } | ||
144 | else { | ||
145 | /* Push larger right partition indices. */ | ||
146 | _QSORT_PUSH (_top, _left_ptr, _hi); | ||
147 | _hi = _right_ptr; | ||
148 | } | ||
149 | } | ||
150 | } | ||
151 | |||
152 | /* Once the BASE array is partially sorted by quicksort the rest | ||
153 | is completely sorted using insertion sort, since this is efficient | ||
154 | for partitions below MAX_THRESH size. BASE points to the | ||
155 | beginning of the array to sort, and END_PTR points at the very | ||
156 | last element in the array (*not* one beyond it!). */ | ||
157 | |||
158 | { | ||
159 | QSORT_TYPE *const _end_ptr = _base + _elems - 1; | ||
160 | QSORT_TYPE *_tmp_ptr = _base; | ||
161 | register QSORT_TYPE *_run_ptr; | ||
162 | QSORT_TYPE *_thresh; | ||
163 | |||
164 | _thresh = _base + _QSORT_MAX_THRESH; | ||
165 | if (_thresh > _end_ptr) | ||
166 | _thresh = _end_ptr; | ||
167 | |||
168 | /* Find smallest element in first threshold and place it at the | ||
169 | array's beginning. This is the smallest array element, | ||
170 | and the operation speeds up insertion sort's inner loop. */ | ||
171 | |||
172 | for (_run_ptr = _tmp_ptr + 1; _run_ptr <= _thresh; ++_run_ptr) | ||
173 | if (QSORT_LT (_run_ptr, _tmp_ptr)) | ||
174 | _tmp_ptr = _run_ptr; | ||
175 | |||
176 | if (_tmp_ptr != _base) | ||
177 | _QSORT_SWAP (_tmp_ptr, _base, _hold); | ||
178 | |||
179 | /* Insertion sort, running from left-hand-side | ||
180 | * up to right-hand-side. */ | ||
181 | |||
182 | _run_ptr = _base + 1; | ||
183 | while (++_run_ptr <= _end_ptr) { | ||
184 | _tmp_ptr = _run_ptr - 1; | ||
185 | while (QSORT_LT (_run_ptr, _tmp_ptr)) | ||
186 | --_tmp_ptr; | ||
187 | |||
188 | ++_tmp_ptr; | ||
189 | if (_tmp_ptr != _run_ptr) { | ||
190 | QSORT_TYPE *_trav = _run_ptr + 1; | ||
191 | while (--_trav >= _run_ptr) { | ||
192 | QSORT_TYPE *_hi; QSORT_TYPE *_lo; | ||
193 | _hold = *_trav; | ||
194 | |||
195 | for (_hi = _lo = _trav; --_lo >= _tmp_ptr; _hi = _lo) | ||
196 | *_hi = *_lo; | ||
197 | *_hi = _hold; | ||
198 | } | ||
199 | } | ||
200 | } | ||
201 | } | ||
202 | |||
203 | } | ||
204 | |||
205 | |||
206 | struct cc | ||
207 | { | ||
208 | bool operator()( int *a, int *b ) | ||
209 | { | ||
210 | return *a < *b; | ||
211 | } | ||
212 | }; | ||
213 | |||
214 | #include <stdio.h> | ||
215 | |||
216 | int main() | ||
217 | { | ||
218 | int lst[] = { 43, 1, 342, 12, 491, 32, 12321, 32, 3, -3 }; | ||
219 | |||
220 | for( int j = 0; j < 10; j++ ) | ||
221 | printf("%s%d", (j>0)?", ":"", lst[j] ); | ||
222 | printf("\n"); | ||
223 | qsrt<int, cc>( lst, 10 ); | ||
224 | for( int j = 0; j < 10; j++ ) | ||
225 | printf("%s%d", (j>0)?", ":"", lst[j] ); | ||
226 | printf("\n"); | ||
227 | } | ||
228 | |||
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/sbuffer.cpp b/src/tests/sbuffer.cpp deleted file mode 100644 index 02798cb..0000000 --- a/src/tests/sbuffer.cpp +++ /dev/null | |||
@@ -1,27 +0,0 @@ | |||
1 | #include "sbuffer.h" | ||
2 | |||
3 | int main() | ||
4 | { | ||
5 | SBuffer buf; | ||
6 | |||
7 | buf.write("abcdefg", 7 ); | ||
8 | |||
9 | printf("tell: %ld\n", buf.tell() ); | ||
10 | |||
11 | char abuf[6]; | ||
12 | int nRead; | ||
13 | nRead = buf.read( abuf, 5 ); | ||
14 | abuf[nRead] = '\0'; | ||
15 | printf("Read %d bytes \"%s\"\n", nRead, abuf ); | ||
16 | |||
17 | buf.setPos( 0 ); | ||
18 | nRead = buf.read( abuf, 5 ); | ||
19 | abuf[nRead] = '\0'; | ||
20 | printf("Read %d bytes \"%s\"\n", nRead, abuf ); | ||
21 | |||
22 | nRead = buf.read( abuf, 5 ); | ||
23 | abuf[nRead] = '\0'; | ||
24 | printf("Read %d bytes \"%s\"\n", nRead, abuf ); | ||
25 | |||
26 | } | ||
27 | |||
diff --git a/src/tests/serialize.cpp b/src/tests/serialize.cpp deleted file mode 100644 index e233704..0000000 --- a/src/tests/serialize.cpp +++ /dev/null | |||
@@ -1,30 +0,0 @@ | |||
1 | #include "serializerbinary.h" | ||
2 | #include "staticstring.h" | ||
3 | #include <stdio.h> | ||
4 | #include <string> | ||
5 | |||
6 | int main() | ||
7 | { | ||
8 | int32_t one; | ||
9 | double two; | ||
10 | bool three; | ||
11 | StaticString s("Test string!"); | ||
12 | std::string ss("Another test string"); | ||
13 | SerializerBinary ar("hello.dat", false); | ||
14 | ar << (int)85; | ||
15 | ar << (double)2.63434; | ||
16 | ar << false; | ||
17 | ar << ss; | ||
18 | ar.close(); | ||
19 | |||
20 | one = 0; two = 0; three = true; s = "die"; | ||
21 | |||
22 | SerializerBinary ar2("hello.dat", true); | ||
23 | ar2 >> one; | ||
24 | ar2 >> two; | ||
25 | ar2 >> three; | ||
26 | ar2 >> s; | ||
27 | |||
28 | printf("we got %d - %f - %s - \"%s\"\n", one, two, (three ? "true":"false"), s.getString() ); | ||
29 | return 0; | ||
30 | } | ||
diff --git a/src/tests/serializetext.cpp b/src/tests/serializetext.cpp deleted file mode 100644 index f6be7d3..0000000 --- a/src/tests/serializetext.cpp +++ /dev/null | |||
@@ -1,28 +0,0 @@ | |||
1 | #include "serializertext.h" | ||
2 | #include "staticstring.h" | ||
3 | #include <iostream> | ||
4 | |||
5 | int main() | ||
6 | { | ||
7 | StaticString s("You're a dog!!"); | ||
8 | SerializerText ar("hello.dat", false); | ||
9 | |||
10 | ar << 4 << 3.993 << true << s; | ||
11 | |||
12 | ar.close(); | ||
13 | |||
14 | int one=0;float two=0.0;bool three=false; s = ""; | ||
15 | |||
16 | SerializerText ar2("hello.dat", true); | ||
17 | |||
18 | ar2 >> one; | ||
19 | ar2 >> two; | ||
20 | ar2 >> three; | ||
21 | ar2 >> s; | ||
22 | |||
23 | //printf("out: %d, %f, %s, \"%s\"\n", one, two, (three ? "true" : "false"), s.getString()); | ||
24 | std::cout << one << ", " << two << ", " << three << ", " << s.getString() << "\n"; | ||
25 | |||
26 | return 0; | ||
27 | } | ||
28 | |||
diff --git a/src/tests/sha1.cpp b/src/tests/sha1.cpp deleted file mode 100644 index df3113c..0000000 --- a/src/tests/sha1.cpp +++ /dev/null | |||
@@ -1,44 +0,0 @@ | |||
1 | #include "sha1.h" | ||
2 | #include "sfile.h" | ||
3 | |||
4 | #define BS 1024 | ||
5 | |||
6 | int main( int argc, char *argv[] ) | ||
7 | { | ||
8 | argc--; argv++; | ||
9 | |||
10 | if( argc == 0 ) | ||
11 | { | ||
12 | printf("Provide a filename.\n"); | ||
13 | return 0; | ||
14 | } | ||
15 | |||
16 | char buf[BS]; | ||
17 | |||
18 | Sha1 s; | ||
19 | SFile fin( *argv, "rb" ); | ||
20 | for(;;) | ||
21 | { | ||
22 | int nRead = fin.read( buf, BS ); | ||
23 | if( nRead == 0 ) | ||
24 | break; | ||
25 | |||
26 | s.update( buf, nRead ); | ||
27 | if( nRead < BS ) | ||
28 | break; | ||
29 | } | ||
30 | |||
31 | unsigned char *dig = s.getDigest(); | ||
32 | |||
33 | char val[]={"0123456789ABCDEF"}; | ||
34 | |||
35 | for( int j = 0; j < 20; j++ ) | ||
36 | { | ||
37 | putchar( val[dig[j]>>4] ); | ||
38 | putchar( val[dig[j]&0x0F] ); | ||
39 | } | ||
40 | putchar('\n'); | ||
41 | |||
42 | delete[] dig; | ||
43 | } | ||
44 | |||
diff --git a/src/tests/sptr.cpp b/src/tests/sptr.cpp deleted file mode 100644 index 252463b..0000000 --- a/src/tests/sptr.cpp +++ /dev/null | |||
@@ -1,79 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include "sptr.h" | ||
3 | |||
4 | class Annoy | ||
5 | { | ||
6 | public: | ||
7 | Annoy() : nCnt( 0 ) | ||
8 | { | ||
9 | printf("Created.\n"); | ||
10 | } | ||
11 | |||
12 | virtual ~Annoy() | ||
13 | { | ||
14 | printf("Destroyed.\n"); | ||
15 | } | ||
16 | |||
17 | virtual void go() | ||
18 | { | ||
19 | printf("%d: I'm annoying.\n", ++nCnt); | ||
20 | } | ||
21 | |||
22 | int nCnt; | ||
23 | }; | ||
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 ) | ||
42 | { | ||
43 | printf("bob-Count: %d\n", bob.count() ); | ||
44 | bob->go(); | ||
45 | } | ||
46 | |||
47 | int main() | ||
48 | { | ||
49 | SPtr<Annoy> pt( new Annoy2 ); | ||
50 | printf("Count: %d\n", pt.count() ); | ||
51 | pt->go(); | ||
52 | |||
53 | { | ||
54 | SPtr<Annoy> pt2 = pt; | ||
55 | printf("Count: %d\n", pt2.count() ); | ||
56 | |||
57 | pt2->go(); | ||
58 | |||
59 | { | ||
60 | SPtr<Annoy> pt3( pt2 ); | ||
61 | printf("Count: %d\n", pt3.count() ); | ||
62 | |||
63 | pt3->go(); | ||
64 | |||
65 | 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 | } | ||
75 | printf("Count: %d\n", pt.count() ); | ||
76 | } | ||
77 | printf("Count: %d\n", pt.count() ); | ||
78 | } | ||
79 | |||
diff --git a/src/tests/srvstress.cpp b/src/tests/srvstress.cpp deleted file mode 100644 index d9a9a1c..0000000 --- a/src/tests/srvstress.cpp +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | #include "connectionmanager.h" | ||
2 | #include "programlink.h" | ||
3 | #include "linkedlist.h" | ||
4 | #include "protocol.h" | ||
5 | |||
6 | class StressProtocol : public Protocol | ||
7 | { | ||
8 | public: | ||
9 | bool onNewData() | ||
10 | { | ||
11 | switch( getConnection()->getInput()[0] ) | ||
12 | { | ||
13 | case 'd': | ||
14 | throw "Hello"; | ||
15 | break; | ||
16 | |||
17 | case 'w': | ||
18 | getConnection()->appendOutput("Hello"); | ||
19 | break; | ||
20 | }; | ||
21 | |||
22 | return true; | ||
23 | } | ||
24 | |||
25 | bool onNewConnection() | ||
26 | { | ||
27 | return true; | ||
28 | } | ||
29 | }; | ||
30 | |||
31 | class StressMonitor : public ConnectionMonitor, public ProgramLink | ||
32 | { | ||
33 | public: | ||
34 | bool init() | ||
35 | { | ||
36 | return true; | ||
37 | } | ||
38 | |||
39 | bool deInit() | ||
40 | { | ||
41 | return true; | ||
42 | } | ||
43 | |||
44 | bool timeSlice() | ||
45 | { | ||
46 | return true; | ||
47 | } | ||
48 | |||
49 | bool onNewConnection( Connection *pCon, int nPort ) | ||
50 | { | ||
51 | StressProtocol *sp = new StressProtocol(); | ||
52 | pCon->setProtocol( sp ); | ||
53 | |||
54 | printf(" sys: New connection: socket(%d), port(%d)\n", | ||
55 | pCon->getSocket(), nPort ); | ||
56 | |||
57 | return true; | ||
58 | } | ||
59 | |||
60 | bool onClosedConnection( Connection *pCon ) | ||
61 | { | ||
62 | printf(" sys: Closed connection: socket(%d)\n", | ||
63 | pCon->getSocket() ); | ||
64 | |||
65 | return true; | ||
66 | } | ||
67 | |||
68 | LinkMessage *processIRM( LinkMessage *pMsg ) | ||
69 | { | ||
70 | return NULL; | ||
71 | } | ||
72 | }; | ||
73 | |||
74 | int main() | ||
75 | { | ||
76 | printf("Starting server...\n"); | ||
77 | |||
78 | ConnectionManager srv; | ||
79 | StressMonitor telnet; | ||
80 | |||
81 | srv.setConnectionMonitor( &telnet ); | ||
82 | |||
83 | srv.startServer( 4001 ); | ||
84 | |||
85 | for(;;) | ||
86 | { | ||
87 | srv.scanConnections( 5000, false ); | ||
88 | } | ||
89 | |||
90 | return 0; | ||
91 | } | ||
diff --git a/src/tests/strhash.cpp b/src/tests/strhash.cpp deleted file mode 100644 index f6528ca..0000000 --- a/src/tests/strhash.cpp +++ /dev/null | |||
@@ -1,12 +0,0 @@ | |||
1 | #include <stdio.h> | ||
2 | #include "hashfunctionstring.h" | ||
3 | |||
4 | int main( int argc, char *argv[] ) | ||
5 | { | ||
6 | HashFunctionString h; | ||
7 | |||
8 | printf("\"%s\": %lu\n", argv[1], h.hash( argv[1] ) ); | ||
9 | |||
10 | return 0; | ||
11 | } | ||
12 | |||
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 | |||
diff --git a/src/tests/teltest/main.cpp b/src/tests/teltest/main.cpp deleted file mode 100644 index 5d3ec26..0000000 --- a/src/tests/teltest/main.cpp +++ /dev/null | |||
@@ -1,21 +0,0 @@ | |||
1 | #include "connectionmanager.h" | ||
2 | #include "telnetmonitor.h" | ||
3 | |||
4 | int main() | ||
5 | { | ||
6 | printf("Starting server...\n"); | ||
7 | |||
8 | ConnectionManager srv; | ||
9 | TelnetMonitor telnet; | ||
10 | |||
11 | srv.setConnectionMonitor( &telnet ); | ||
12 | |||
13 | srv.startServer( 4001 ); | ||
14 | |||
15 | for(;;) | ||
16 | { | ||
17 | srv.scanConnections( 5000, false ); | ||
18 | } | ||
19 | |||
20 | return 0; | ||
21 | } | ||
diff --git a/src/tests/teltest/telnetmonitor.cpp b/src/tests/teltest/telnetmonitor.cpp deleted file mode 100644 index 65954eb..0000000 --- a/src/tests/teltest/telnetmonitor.cpp +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | #include "telnetmonitor.h" | ||
2 | #include "protocoltelnet.h" | ||
3 | #include <sys/stat.h> | ||
4 | |||
5 | TelnetMonitor::TelnetMonitor() | ||
6 | { | ||
7 | } | ||
8 | |||
9 | TelnetMonitor::~TelnetMonitor() | ||
10 | { | ||
11 | } | ||
12 | |||
13 | bool TelnetMonitor::init() | ||
14 | { | ||
15 | return true; | ||
16 | } | ||
17 | |||
18 | bool TelnetMonitor::deInit() | ||
19 | { | ||
20 | return true; | ||
21 | } | ||
22 | |||
23 | bool TelnetMonitor::timeSlice() | ||
24 | { | ||
25 | for( int j = 0; j < lCon.getSize(); j++ ) | ||
26 | { | ||
27 | if( ((Connection *)lCon[j])->hasInput() ) | ||
28 | { | ||
29 | printf("%s\n", ((Connection *)lCon[j])->getInput() ); | ||
30 | } | ||
31 | } | ||
32 | return true; | ||
33 | } | ||
34 | |||
35 | LinkMessage* TelnetMonitor::processIRM( LinkMessage *pMsg ) | ||
36 | { | ||
37 | return NULL; | ||
38 | } | ||
39 | |||
40 | bool TelnetMonitor::onNewConnection( Connection *pCon, int nPort ) | ||
41 | { | ||
42 | ProtocolTelnet *pt = new ProtocolTelnet(); | ||
43 | pCon->setProtocol( pt ); | ||
44 | |||
45 | lCon.append( pt ); | ||
46 | |||
47 | return true; | ||
48 | } | ||
49 | |||
50 | bool TelnetMonitor::onClosedConnection( Connection *pCon ) | ||
51 | { | ||
52 | return true; | ||
53 | } | ||
54 | |||
diff --git a/src/tests/teltest/telnetmonitor.h b/src/tests/teltest/telnetmonitor.h deleted file mode 100644 index ba5761e..0000000 --- a/src/tests/teltest/telnetmonitor.h +++ /dev/null | |||
@@ -1,26 +0,0 @@ | |||
1 | #ifndef HTTPCONNECTIONMONITOR_H | ||
2 | #define HTTPCONNECTIONMONITOR_H | ||
3 | |||
4 | #include "connectionmonitor.h" | ||
5 | #include "programlink.h" | ||
6 | #include "linkedlist.h" | ||
7 | |||
8 | class TelnetMonitor : public ConnectionMonitor, public ProgramLink | ||
9 | { | ||
10 | public: | ||
11 | TelnetMonitor(); | ||
12 | ~TelnetMonitor(); | ||
13 | |||
14 | bool init(); | ||
15 | bool deInit(); | ||
16 | bool timeSlice(); | ||
17 | LinkMessage* processIRM( LinkMessage *pMsgIn ); | ||
18 | |||
19 | bool onNewConnection( Connection *pCon, int nPort ); | ||
20 | bool onClosedConnection( Connection *pCon ); | ||
21 | |||
22 | private: | ||
23 | LinkedList lCon; | ||
24 | }; | ||
25 | |||
26 | #endif | ||
diff --git a/src/tests/xmlreadtest.cpp b/src/tests/xmlreadtest.cpp deleted file mode 100644 index d061810..0000000 --- a/src/tests/xmlreadtest.cpp +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | #include "xmlfilereader.h" | ||
2 | #include "xmlstringreader.h" | ||
3 | #include "xmlfilewriter.h" | ||
4 | |||
5 | int main( int argc, char *argv[] ) | ||
6 | { | ||
7 | if( argc < 4 ) | ||
8 | { | ||
9 | printf("Usage: %s f <file in> <file out>\n", argv[0] ); | ||
10 | printf(" %s s <xml string> <file out>\n\n", argv[0] ); | ||
11 | return 0; | ||
12 | } | ||
13 | |||
14 | if( argv[1][0] == 'f' ) | ||
15 | { | ||
16 | XmlFileReader r( argv[2], true ); | ||
17 | // XmlFileWriter w( argv[3], "\t", r.detatchRoot() ); | ||
18 | // w.write(); | ||
19 | } | ||
20 | else if( argv[1][0] == 's' ) | ||
21 | { | ||
22 | XmlStringReader r( argv[2], true ); | ||
23 | XmlFileWriter w(stdout, "\t", r.detatchRoot() ); | ||
24 | w.write(); | ||
25 | } | ||
26 | |||
27 | return 0; | ||
28 | } | ||
29 | |||
diff --git a/src/tests/xmlrepltest.cpp b/src/tests/xmlrepltest.cpp deleted file mode 100644 index 9667705..0000000 --- a/src/tests/xmlrepltest.cpp +++ /dev/null | |||
@@ -1,31 +0,0 @@ | |||
1 | #include "xmlwriter.h" | ||
2 | |||
3 | int main() | ||
4 | { | ||
5 | printf("Testing Xml Replacement...\n"); | ||
6 | XmlDocument w; | ||
7 | |||
8 | w.addNode("text"); | ||
9 | w.setContent("this text is before the node. "); | ||
10 | w.addNode("keepme", "This one we keep...", true ); | ||
11 | w.setContent("this text is after."); | ||
12 | w.addNode("deleteme", "This one we don't...", true ); | ||
13 | w.setContent("this is last..." ); | ||
14 | w.closeNode(); | ||
15 | |||
16 | //XmlWriter::writeNode( stdout, w.getRoot(), 0, NULL ); | ||
17 | |||
18 | printf("\n\n"); | ||
19 | |||
20 | //XmlNode *xNode = w.getRoot()->detatchNode( 1 ); | ||
21 | |||
22 | //XmlWriter::writeNode( stdout, w.getRoot(), 0, NULL ); | ||
23 | |||
24 | printf("\n\n"); | ||
25 | |||
26 | //XmlWriter::writeNode( stdout, xNode, 0, NULL ); | ||
27 | |||
28 | printf("\n\n"); | ||
29 | |||
30 | return 0; | ||
31 | } | ||
diff --git a/src/tests/xmlwritetest.cpp b/src/tests/xmlwritetest.cpp deleted file mode 100644 index a22d19d..0000000 --- a/src/tests/xmlwritetest.cpp +++ /dev/null | |||
@@ -1,48 +0,0 @@ | |||
1 | #include "xmlfilewriter.h" | ||
2 | #include "xmlstringwriter.h" | ||
3 | #include "xmlstringreader.h" | ||
4 | |||
5 | void fillItIn( XmlWriter &w ) | ||
6 | { | ||
7 | w.addNode("thinglist"); | ||
8 | |||
9 | w.addNode("thing"); | ||
10 | w.addProperty("type", " ±î´<M-F6><M-F6>³¸®°êòì¯"); | ||
11 | |||
12 | w.addNode("id", "Klophin²³±¹¸·µ´äêíëã Staff", true ); | ||
13 | w.addNode("name", "Klophin Staff", true ); | ||
14 | w.addNode("durability", "0.01", true ); | ||
15 | w.addNode("size", "0.1", true ); | ||
16 | |||
17 | w.addNode("config"); | ||
18 | w.addNode("damage", "3d6+4", true ); | ||
19 | w.addNode("class", "melee", true ); | ||
20 | w.addNode("type", "bludgeon", true ); | ||
21 | w.addNode("damagedesc", "club/clubs", true ); | ||
22 | w.closeNode(); | ||
23 | |||
24 | w.closeNode(); | ||
25 | |||
26 | w.closeNode(); | ||
27 | } | ||
28 | |||
29 | int main() | ||
30 | { | ||
31 | printf("Testing XmlWriter...\n"); | ||
32 | |||
33 | //XmlStringReader *xsr = new XmlStringReader("<stuff/>"); | ||
34 | |||
35 | //printf("%08X\n%08X\n%08X\n", xsr, (XmlReader *)xsr, (XmlDocument *)xsr ); | ||
36 | |||
37 | //delete (XmlDocument *)xsr; | ||
38 | XmlFileWriter wf("test.xml", "\t"); | ||
39 | |||
40 | fillItIn( wf ); | ||
41 | |||
42 | XmlStringWriter ws("\t"); | ||
43 | fillItIn( ws ); | ||
44 | |||
45 | printf("Now the string version:\n\n%s\n", ws.getString().c_str() ); | ||
46 | |||
47 | return 0; | ||
48 | } | ||