summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--test/test.cc20
1 files changed, 17 insertions, 3 deletions
diff --git a/test/test.cc b/test/test.cc
index 35f58ab..4bb2969 100644
--- a/test/test.cc
+++ b/test/test.cc
@@ -7,42 +7,40 @@ using namespace std;
7#include "config.h" 7#include "config.h"
8 8
9class failed_test : public opkele::exception { 9class failed_test : public opkele::exception {
10 public: 10 public:
11 failed_test(OPKELE_E_PARS) 11 failed_test(OPKELE_E_PARS)
12 : exception(OPKELE_E_CONS) { } 12 : exception(OPKELE_E_CONS) { }
13}; 13};
14 14
15void test_rfc_3986_normalize_uri(const string &ouri,bool success,const string& nuri="") { 15void test_rfc_3986_normalize_uri(const string &ouri,bool success,const string& nuri="") {
16 try { 16 try {
17 string n = opkele::util::rfc_3986_normalize_uri(ouri); 17 string n = opkele::util::rfc_3986_normalize_uri(ouri);
18 if(!success) 18 if(!success)
19 throw failed_test(OPKELE_CP_ "Normalized URI when it shouldn't"); 19 throw failed_test(OPKELE_CP_ "Normalized URI when it shouldn't ('"+ouri+"' normalization resulted in '"+n+"')");
20 if(n!=nuri) 20 if(n!=nuri)
21 throw failed_test(OPKELE_CP_ "rfc_3986_test_failed for '"+ouri+"' failed, expected '"+nuri+"', got '"+n+"'"); 21 throw failed_test(OPKELE_CP_ "rfc_3986_test_failed for '"+ouri+"' failed, expected '"+nuri+"', got '"+n+"'");
22 }catch(opkele::bad_input& obi) { 22 }catch(opkele::bad_input& obi) {
23 if(success) 23 if(success)
24 throw failed_test(OPKELE_CP_ "Test '"+ouri+"' failed due to 'bad_input'["+obi.what()+"]"); 24 throw failed_test(OPKELE_CP_ "Test '"+ouri+"' failed due to 'bad_input'["+obi.what()+"]");
25 }catch(opkele::not_implemented& oni) { 25 }catch(opkele::not_implemented& oni) {
26 if(success) 26 if(success)
27 throw failed_test(OPKELE_CP_ "Test '"+ouri+"' failed due to 'not_implemented'["+oni.what()+"]"); 27 throw failed_test(OPKELE_CP_ "Test '"+ouri+"' failed due to 'not_implemented'["+oni.what()+"]");
28 } 28 }
29} 29}
30 30
31void test_rfc_3986_normalize_uri() { 31void test_rfc_3986_normalize_uri() {
32 test_rfc_3986_normalize_uri( 32 test_rfc_3986_normalize_uri(
33 "invalid", false ); 33 "invalid", false );
34 test_rfc_3986_normalize_uri( 34 test_rfc_3986_normalize_uri(
35 "ftp://hacker.klever.net/", false );
36 test_rfc_3986_normalize_uri(
37 "http://", false ); 35 "http://", false );
38 test_rfc_3986_normalize_uri( 36 test_rfc_3986_normalize_uri(
39 "http:/hacker.klever.net/", false ); 37 "http:/hacker.klever.net/", false );
40 test_rfc_3986_normalize_uri( 38 test_rfc_3986_normalize_uri(
41 "hTTp://hacker.klever.net#uh?oh", true, "http://hacker.klever.net/#uh?oh" ); 39 "hTTp://hacker.klever.net#uh?oh", true, "http://hacker.klever.net/#uh?oh" );
42 test_rfc_3986_normalize_uri( 40 test_rfc_3986_normalize_uri(
43 "http://hacker.klever.net?uh#oh", true, "http://hacker.klever.net/?uh#oh" ); 41 "http://hacker.klever.net?uh#oh", true, "http://hacker.klever.net/?uh#oh" );
44 test_rfc_3986_normalize_uri( 42 test_rfc_3986_normalize_uri(
45 "http://hacker.klever.net:80/", true, "http://hacker.klever.net/" ); 43 "http://hacker.klever.net:80/", true, "http://hacker.klever.net/" );
46 test_rfc_3986_normalize_uri( 44 test_rfc_3986_normalize_uri(
47 "http://hacker.klever.net:80?uh", true, "http://hacker.klever.net/?uh" ); 45 "http://hacker.klever.net:80?uh", true, "http://hacker.klever.net/?uh" );
48 test_rfc_3986_normalize_uri( 46 test_rfc_3986_normalize_uri(
@@ -68,23 +66,39 @@ void test_rfc_3986_normalize_uri() {
68 test_rfc_3986_normalize_uri( 66 test_rfc_3986_normalize_uri(
69 "http://hacker.klever.net/ah/%", false ); 67 "http://hacker.klever.net/ah/%", false );
70 test_rfc_3986_normalize_uri( 68 test_rfc_3986_normalize_uri(
71 "http://hacker.klever.net/ah/%a", false ); 69 "http://hacker.klever.net/ah/%a", false );
72 test_rfc_3986_normalize_uri( 70 test_rfc_3986_normalize_uri(
73 "http://hacker.klever.net/ah/%zx", false ); 71 "http://hacker.klever.net/ah/%zx", false );
74 test_rfc_3986_normalize_uri( 72 test_rfc_3986_normalize_uri(
75 "http://hacker.klever.net/ah/%5x", false ); 73 "http://hacker.klever.net/ah/%5x", false );
76 test_rfc_3986_normalize_uri( 74 test_rfc_3986_normalize_uri(
77 "Http://Hacker.Klever.Net:", true, "http://hacker.klever.net/" ); 75 "Http://Hacker.Klever.Net:", true, "http://hacker.klever.net/" );
78} 76}
79 77
78void test_w3c_to_time(const char *w3c,time_t expected) {
79 time_t t = opkele::util::w3c_to_time(w3c);
80 if(t!=expected) {
81 char tmp[512]; snprintf(tmp,sizeof(tmp)-1,
82 "test failed for %s, expected %lu, got %lu (expected-got == %lu)",
83 w3c, (unsigned long)expected, (unsigned long)t,
84 (unsigned long)(expected-t) );
85 throw failed_test(OPKELE_CP_ tmp);
86 }
87}
88
89void test_w3c_to_time() {
90 test_w3c_to_time("2008-06-29T12:33:44",1214742824);
91}
92
80int main() { 93int main() {
81 try { 94 try {
95 test_w3c_to_time();
82 test_rfc_3986_normalize_uri(); 96 test_rfc_3986_normalize_uri();
83 }catch(failed_test& ft) { 97 }catch(failed_test& ft) {
84 cerr << "Test failed: " << ft.what() << endl; 98 cerr << "Test failed: " << ft.what() << endl;
85 }catch(exception& e) { 99 }catch(exception& e) {
86 cerr << "oops: " << e.what() << endl; 100 cerr << "oops: " << e.what() << endl;
87 _exit(1); 101 _exit(1);
88 } 102 }
89 _exit(0); 103 _exit(0);
90} 104}