summaryrefslogtreecommitdiffabout
path: root/test/test.cc
Unidiff
Diffstat (limited to 'test/test.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--test/test.cc67
1 files changed, 67 insertions, 0 deletions
diff --git a/test/test.cc b/test/test.cc
index f92284c..1a012b5 100644
--- a/test/test.cc
+++ b/test/test.cc
@@ -4,4 +4,5 @@ using namespace std;
4#include <opkele/exception.h> 4#include <opkele/exception.h>
5#include <opkele/consumer.h> 5#include <opkele/consumer.h>
6#include <opkele/util.h>
6 7
7#include "config.h" 8#include "config.h"
@@ -60,6 +61,72 @@ void test_retrieve_links() {
60} 61}
61 62
63void test_rfc_3986_normalize_uri(const string &ouri,bool success,const string& nuri="") {
64 try {
65 string n = opkele::util::rfc_3986_normalize_uri(ouri);
66 if(!success)
67 throw failed_test(OPKELE_CP_ "Normalized URI when it shouldn't");
68 if(n!=nuri)
69 throw failed_test(OPKELE_CP_ "rfc_3986_test_failed for '"+ouri+"' failed, expected '"+nuri+"', got '"+n+"'");
70 }catch(opkele::bad_input& obi) {
71 if(success)
72 throw failed_test(OPKELE_CP_ "Test '"+ouri+"' failed due to 'bad_input'["+obi.what()+"]");
73 }catch(opkele::not_implemented& oni) {
74 if(success)
75 throw failed_test(OPKELE_CP_ "Test '"+ouri+"' failed due to 'not_implemented'["+oni.what()+"]");
76 }
77}
78
79void test_rfc_3986_normalize_uri() {
80 test_rfc_3986_normalize_uri(
81 "invalid", false );
82 test_rfc_3986_normalize_uri(
83 "ftp://hacker.klever.net/", false );
84 test_rfc_3986_normalize_uri(
85 "http://", false );
86 test_rfc_3986_normalize_uri(
87 "http:/hacker.klever.net/", false );
88 test_rfc_3986_normalize_uri(
89 "hTTp://hacker.klever.net#uh?oh", true, "http://hacker.klever.net/#uh?oh" );
90 test_rfc_3986_normalize_uri(
91 "http://hacker.klever.net?uh#oh", true, "http://hacker.klever.net/?uh#oh" );
92 test_rfc_3986_normalize_uri(
93 "http://hacker.klever.net:80/", true, "http://hacker.klever.net/" );
94 test_rfc_3986_normalize_uri(
95 "http://hacker.klever.net:80?uh", true, "http://hacker.klever.net/?uh" );
96 test_rfc_3986_normalize_uri(
97 "http://hacker.klever.net:80#uh", true, "http://hacker.klever.net/#uh" );
98 test_rfc_3986_normalize_uri(
99 "https://hacker.klever.net:443", true, "https://hacker.klever.net/" );
100 test_rfc_3986_normalize_uri(
101 "http://hacker.klever.net:?oh", true, "http://hacker.klever.net/?oh" );
102 test_rfc_3986_normalize_uri(
103 "http://hacker.klever.net/ah%2E", true, "http://hacker.klever.net/ah." );
104 test_rfc_3986_normalize_uri(
105 "http://hacker.klever.net/ah/%2E/", true, "http://hacker.klever.net/ah/" );
106 test_rfc_3986_normalize_uri(
107 "http://hacker.klever.net/ah/%2b/", true, "http://hacker.klever.net/ah/%2B/" );
108 test_rfc_3986_normalize_uri(
109 "http://hacker.klever.net/ah/./oh?eh", true, "http://hacker.klever.net/ah/oh?eh" );
110 test_rfc_3986_normalize_uri(
111 "http://hacker.klever.net/ah/../oh?", true, "http://hacker.klever.net/oh?" );
112 test_rfc_3986_normalize_uri(
113 "http://hacker.klever.net/ah//oh?", true, "http://hacker.klever.net/ah/oh?" );
114 test_rfc_3986_normalize_uri(
115 "http://hacker.klever.net/ah/?", true, "http://hacker.klever.net/ah/?" );
116 test_rfc_3986_normalize_uri(
117 "http://hacker.klever.net/ah/%", false );
118 test_rfc_3986_normalize_uri(
119 "http://hacker.klever.net/ah/%a", false );
120 test_rfc_3986_normalize_uri(
121 "http://hacker.klever.net/ah/%zx", false );
122 test_rfc_3986_normalize_uri(
123 "http://hacker.klever.net/ah/%5x", false );
124 test_rfc_3986_normalize_uri(
125 "Http://Hacker.Klever.Net:", true, "http://hacker.klever.net/" );
126}
127
62int main() { 128int main() {
63 try { 129 try {
130 test_rfc_3986_normalize_uri();
64 test_retrieve_links(); 131 test_retrieve_links();
65 }catch(failed_test& ft) { 132 }catch(failed_test& ft) {