diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-05-01 17:11:04 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-05-01 17:11:04 +0000 |
commit | f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54 (patch) | |
tree | 53cec4864776e07950e3c72f2a990a1017d08045 /src/test | |
download | libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.gz libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.bz2 libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.tar.xz libbu++-f7a9549bd6ad83f2e0bceec9cddacfa5e3f84a54.zip |
libbu++ is finally laid out the way it should be, trunk, branches, and tags.
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/hashtest.cpp | 107 | ||||
-rw-r--r-- | src/test/httpsrv/httpconnectionmonitor.cpp | 72 | ||||
-rw-r--r-- | src/test/httpsrv/httpconnectionmonitor.h | 16 | ||||
-rw-r--r-- | src/test/httpsrv/main.cpp | 21 | ||||
-rw-r--r-- | src/test/md5test.cpp | 19 | ||||
-rw-r--r-- | src/test/teltest/main.cpp | 21 | ||||
-rw-r--r-- | src/test/teltest/telnetmonitor.cpp | 53 | ||||
-rw-r--r-- | src/test/teltest/telnetmonitor.h | 26 | ||||
-rw-r--r-- | src/test/xmlreadtest.cpp | 29 | ||||
-rw-r--r-- | src/test/xmlrepltest.cpp | 31 | ||||
-rw-r--r-- | src/test/xmlwritetest.cpp | 41 |
11 files changed, 436 insertions, 0 deletions
diff --git a/src/test/hashtest.cpp b/src/test/hashtest.cpp new file mode 100644 index 0000000..f31a3f8 --- /dev/null +++ b/src/test/hashtest.cpp | |||
@@ -0,0 +1,107 @@ | |||
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: %d, Size: %d, 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: %d, Size: %d, 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: %d, Size: %d, Load: %f\n", | ||
102 | h.getCapacity(), | ||
103 | h.getSize(), | ||
104 | h.getLoad() | ||
105 | ); | ||
106 | } | ||
107 | } | ||
diff --git a/src/test/httpsrv/httpconnectionmonitor.cpp b/src/test/httpsrv/httpconnectionmonitor.cpp new file mode 100644 index 0000000..4eb6817 --- /dev/null +++ b/src/test/httpsrv/httpconnectionmonitor.cpp | |||
@@ -0,0 +1,72 @@ | |||
1 | #include "httpconnectionmonitor.h" | ||
2 | #include "http.h" | ||
3 | #include <sys/stat.h> | ||
4 | |||
5 | HttpConnectionMonitor::HttpConnectionMonitor() | ||
6 | { | ||
7 | } | ||
8 | |||
9 | HttpConnectionMonitor::~HttpConnectionMonitor() | ||
10 | { | ||
11 | } | ||
12 | |||
13 | bool HttpConnectionMonitor::onNewConnection( Connection *pCon ) | ||
14 | { | ||
15 | Http hp( pCon ); | ||
16 | |||
17 | pCon->readInput( 60, 0 ); | ||
18 | printf("#######################\n%s\n#######################\n", pCon->getInput() ); | ||
19 | |||
20 | while( hp.parseRequest() == false ); | ||
21 | printf("Done parsing.\n\n"); | ||
22 | |||
23 | if( hp.getRequestType() == Http::reqGet ) | ||
24 | { | ||
25 | printf("\"\"\"%s\"\"\"\n", hp.getRequestURI() ); | ||
26 | if( !strcmp( hp.getRequestURI(), "/" ) ) | ||
27 | { | ||
28 | 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>"); | ||
29 | hp.buildResponse(); | ||
30 | hp.setResponseContent( | ||
31 | "text/html", | ||
32 | content.c_str(), | ||
33 | content.size() | ||
34 | ); | ||
35 | hp.sendResponse(); | ||
36 | } | ||
37 | else | ||
38 | { | ||
39 | 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>"); | ||
40 | hp.buildResponse( 404, "File not found."); | ||
41 | hp.setResponseContent( | ||
42 | "text/html", | ||
43 | content.c_str(), | ||
44 | content.size() | ||
45 | ); | ||
46 | hp.sendResponse(); | ||
47 | } | ||
48 | } | ||
49 | else | ||
50 | { | ||
51 | printf("Non get: %s\n", hp.getRequestTypeStr() ); | ||
52 | } | ||
53 | pCon->writeOutput(); | ||
54 | |||
55 | if( pCon->hasInput() ) | ||
56 | { | ||
57 | std::string s( pCon->getInput(), pCon->getInputAmnt() ); | ||
58 | |||
59 | printf("Reamining data\n==============\n%s\n==============\n", | ||
60 | s.c_str() ); | ||
61 | } | ||
62 | |||
63 | pCon->disconnect(); | ||
64 | |||
65 | return true; | ||
66 | } | ||
67 | |||
68 | bool HttpConnectionMonitor::onClosedConnection( Connection *pCon ) | ||
69 | { | ||
70 | return true; | ||
71 | } | ||
72 | |||
diff --git a/src/test/httpsrv/httpconnectionmonitor.h b/src/test/httpsrv/httpconnectionmonitor.h new file mode 100644 index 0000000..63f29e4 --- /dev/null +++ b/src/test/httpsrv/httpconnectionmonitor.h | |||
@@ -0,0 +1,16 @@ | |||
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 ); | ||
13 | bool onClosedConnection( Connection *pCon ); | ||
14 | }; | ||
15 | |||
16 | #endif | ||
diff --git a/src/test/httpsrv/main.cpp b/src/test/httpsrv/main.cpp new file mode 100644 index 0000000..4ee1ad3 --- /dev/null +++ b/src/test/httpsrv/main.cpp | |||
@@ -0,0 +1,21 @@ | |||
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 | srv.startServer( 7331, 40 ); | ||
14 | |||
15 | for(;;) | ||
16 | { | ||
17 | srv.scanConnections( 5000, false ); | ||
18 | } | ||
19 | |||
20 | return 0; | ||
21 | } | ||
diff --git a/src/test/md5test.cpp b/src/test/md5test.cpp new file mode 100644 index 0000000..6f832df --- /dev/null +++ b/src/test/md5test.cpp | |||
@@ -0,0 +1,19 @@ | |||
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/test/teltest/main.cpp b/src/test/teltest/main.cpp new file mode 100644 index 0000000..ce968c4 --- /dev/null +++ b/src/test/teltest/main.cpp | |||
@@ -0,0 +1,21 @@ | |||
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, 40 ); | ||
14 | |||
15 | for(;;) | ||
16 | { | ||
17 | srv.scanConnections( 5000, false ); | ||
18 | } | ||
19 | |||
20 | return 0; | ||
21 | } | ||
diff --git a/src/test/teltest/telnetmonitor.cpp b/src/test/teltest/telnetmonitor.cpp new file mode 100644 index 0000000..001932f --- /dev/null +++ b/src/test/teltest/telnetmonitor.cpp | |||
@@ -0,0 +1,53 @@ | |||
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 | } | ||
38 | |||
39 | bool TelnetMonitor::onNewConnection( Connection *pCon ) | ||
40 | { | ||
41 | ProtocolTelnet *pt = new ProtocolTelnet(); | ||
42 | pCon->setProtocol( pt ); | ||
43 | |||
44 | lCon.append( pt ); | ||
45 | |||
46 | return true; | ||
47 | } | ||
48 | |||
49 | bool TelnetMonitor::onClosedConnection( Connection *pCon ) | ||
50 | { | ||
51 | return true; | ||
52 | } | ||
53 | |||
diff --git a/src/test/teltest/telnetmonitor.h b/src/test/teltest/telnetmonitor.h new file mode 100644 index 0000000..95c8493 --- /dev/null +++ b/src/test/teltest/telnetmonitor.h | |||
@@ -0,0 +1,26 @@ | |||
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 ); | ||
20 | bool onClosedConnection( Connection *pCon ); | ||
21 | |||
22 | private: | ||
23 | LinkedList lCon; | ||
24 | }; | ||
25 | |||
26 | #endif | ||
diff --git a/src/test/xmlreadtest.cpp b/src/test/xmlreadtest.cpp new file mode 100644 index 0000000..5fbd021 --- /dev/null +++ b/src/test/xmlreadtest.cpp | |||
@@ -0,0 +1,29 @@ | |||
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.getRoot() ); | ||
18 | w.write(); | ||
19 | //XmlWriter::write( argv[3], r.getRoot(), "\t" ); | ||
20 | } | ||
21 | else if( argv[1][0] == 's' ) | ||
22 | { | ||
23 | XmlStringReader r( argv[2], true ); | ||
24 | //XmlWriter::write( argv[3], r.getRoot(), "\t" ); | ||
25 | } | ||
26 | |||
27 | return 0; | ||
28 | } | ||
29 | |||
diff --git a/src/test/xmlrepltest.cpp b/src/test/xmlrepltest.cpp new file mode 100644 index 0000000..1fe9ec2 --- /dev/null +++ b/src/test/xmlrepltest.cpp | |||
@@ -0,0 +1,31 @@ | |||
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/test/xmlwritetest.cpp b/src/test/xmlwritetest.cpp new file mode 100644 index 0000000..340c9a3 --- /dev/null +++ b/src/test/xmlwritetest.cpp | |||
@@ -0,0 +1,41 @@ | |||
1 | #include "xmlfilewriter.h" | ||
2 | #include "xmlstringwriter.h" | ||
3 | |||
4 | void fillItIn( XmlWriter &w ) | ||
5 | { | ||
6 | w.addNode("thinglist"); | ||
7 | |||
8 | w.addNode("thing"); | ||
9 | w.addProperty("type", "Weapon"); | ||
10 | |||
11 | w.addNode("id", "Klophin Staff", true ); | ||
12 | w.addNode("name", "Klophin Staff", true ); | ||
13 | w.addNode("durability", "0.01", true ); | ||
14 | w.addNode("size", "0.1", true ); | ||
15 | |||
16 | w.addNode("config"); | ||
17 | w.addNode("damage", "3d6+4", true ); | ||
18 | w.addNode("class", "melee", true ); | ||
19 | w.addNode("type", "bludgeon", true ); | ||
20 | w.addNode("damagedesc", "club/clubs", true ); | ||
21 | w.closeNode(); | ||
22 | |||
23 | w.closeNode(); | ||
24 | |||
25 | w.closeNode(); | ||
26 | } | ||
27 | |||
28 | int main() | ||
29 | { | ||
30 | printf("Testing XmlWriter...\n"); | ||
31 | XmlFileWriter wf("test.xml", "\t"); | ||
32 | |||
33 | fillItIn( wf ); | ||
34 | |||
35 | XmlStringWriter ws("\t"); | ||
36 | fillItIn( ws ); | ||
37 | |||
38 | printf("Now the string version:\n\n%s\n", ws.getString().c_str() ); | ||
39 | |||
40 | return 0; | ||
41 | } | ||