aboutsummaryrefslogtreecommitdiff
path: root/src/unit
diff options
context:
space:
mode:
Diffstat (limited to 'src/unit')
-rw-r--r--src/unit/hashtable/hashtable.cpp107
-rw-r--r--src/unit/xml/xml.cpp59
2 files changed, 0 insertions, 166 deletions
diff --git a/src/unit/hashtable/hashtable.cpp b/src/unit/hashtable/hashtable.cpp
deleted file mode 100644
index b2e1cf5..0000000
--- a/src/unit/hashtable/hashtable.cpp
+++ /dev/null
@@ -1,107 +0,0 @@
1#include <cstdlib>
2#include <cstring>
3#include <iostream>
4#include <cpptest.h>
5#include <string.h>
6#include <set>
7#include <map>
8
9#include "hashfunctionstring.h"
10#include "hashfunctioncasestring.h"
11#include "hashfunctionint.h"
12
13class HashFunctionSuite : public Test::Suite
14{
15public:
16 HashFunctionSuite()
17 {
18 TEST_ADD( HashFunctionSuite::functionString )
19 TEST_ADD( HashFunctionSuite::functionCaseString )
20 TEST_ADD( HashFunctionSuite::functionInt )
21 }
22
23private:
24 void functionStringWorker( HashFunction &hf, std::set<unsigned long> &sCodes, char *str, int nLevel, int nMax )
25 {
26 for( char let = 'A'; let <= 'z'; let += 3 )
27 {
28 str[nLevel+1] = '\0';
29 str[nLevel] = let;
30 unsigned long x = hf.hash( str );
31 TEST_ASSERT( sCodes.find( x ) == sCodes.end() );
32 TEST_ASSERT( hf.cmpIDs( str, str ) );
33 sCodes.insert( x );
34
35 if( nLevel < nMax )
36 functionStringWorker( hf, sCodes, str, nLevel+1, nMax );
37 }
38 }
39
40 void functionString()
41 {
42 HashFunctionString hf;
43 char str[10];
44
45 std::set<unsigned long> sCodes;
46
47 functionStringWorker( hf, sCodes, str, 0, 3 );
48 }
49
50 void functionCaseStringWorker( HashFunction &hf, std::map<unsigned long, char *> &sCodes, char *str, int nLevel, int nMax )
51 {
52 for( char let = 'A'; let <= 'z'; let += 3 )
53 {
54 str[nLevel+1] = '\0';
55 str[nLevel] = let;
56 unsigned long x = hf.hash( str );
57 std::map<unsigned long, char *>::iterator i = sCodes.find( x );
58 if( i == sCodes.end() )
59 {
60 sCodes[x] = strdup( str );
61 }
62 else
63 {
64 TEST_ASSERT( strcasecmp( (*i).second, str ) == 0 );
65 TEST_ASSERT( hf.cmpIDs( (*i).second, str ) == true );
66 }
67
68 if( nLevel < nMax )
69 functionCaseStringWorker( hf, sCodes, str, nLevel+1, nMax );
70 }
71 }
72
73 void functionCaseString()
74 {
75 HashFunctionCaseString hf;
76 char str[10];
77
78 std::map<unsigned long, char *> sCodes;
79
80 functionCaseStringWorker( hf, sCodes, str, 0, 3 );
81
82 std::map<unsigned long, char *>::iterator i;
83 for( i = sCodes.begin(); i != sCodes.end(); i++ )
84 {
85 free( (*i).second );
86 }
87 }
88
89 void functionInt()
90 {
91 HashFunctionInt hf;
92
93 for( long i = -100000; i <= 100000; i += 100 )
94 {
95 TEST_ASSERT( ((long)hf.hash( (void *)i )) == i );
96 TEST_ASSERT( ((long)hf.cmpIDs( (void *)i, (void *)i )) );
97 }
98 }
99};
100
101int main( int argc, char *argv[] )
102{
103 Test::TextOutput output( Test::TextOutput::Verbose );
104 HashFunctionSuite ts;
105 return ts.run( output ) ? EXIT_SUCCESS : EXIT_FAILURE;
106}
107
diff --git a/src/unit/xml/xml.cpp b/src/unit/xml/xml.cpp
deleted file mode 100644
index e4d779c..0000000
--- a/src/unit/xml/xml.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
1#include <cstdlib>
2#include <cstring>
3#include <iostream>
4#include <cpptest.h>
5#include <string.h>
6
7#include "xmlstringreader.h"
8#include "xmlexception.h"
9
10class XmlCoreTestSuite : public Test::Suite
11{
12public:
13 XmlCoreTestSuite()
14 {
15 TEST_ADD( XmlCoreTestSuite::badXml01 )
16 TEST_ADD( XmlCoreTestSuite::badXml02 )
17 TEST_ADD( XmlCoreTestSuite::badXml03 )
18
19 TEST_ADD( XmlCoreTestSuite::entityBuiltin01 )
20
21 TEST_ADD( XmlCoreTestSuite::entityDoc01 )
22 }
23
24private:
25 void badXml01()
26 {
27 TEST_THROWS( XmlStringReader r("<hello></bye>"), XmlException & );
28 }
29
30 void badXml02()
31 {
32 TEST_THROWS( XmlStringReader r("<hello>"), XmlException & );
33 }
34
35 void badXml03()
36 {
37 TEST_THROWS( XmlStringReader r("<hello param=\"stuff?"), XmlException & );
38 }
39
40 void entityBuiltin01()
41 {
42 XmlStringReader r("<hello>&gt;&lt;&amp;&apos;&quot;</hello>");
43 TEST_ASSERT( strcmp( r.getRoot()->getContent(), "><&\'\"" ) == 0 );
44 }
45
46 void entityDoc01()
47 {
48 XmlStringReader r("<!ENTITY name \"bob the man\"><hello>&quot;&name;&quot;</hello>");
49 TEST_ASSERT( strcmp( r.getRoot()->getContent(), "\"bob the man\"" ) == 0 );
50 }
51};
52
53int main( int argc, char *argv[] )
54{
55 Test::TextOutput output( Test::TextOutput::Verbose );
56 XmlCoreTestSuite ts;
57 return ts.run( output ) ? EXIT_SUCCESS : EXIT_FAILURE;
58}
59