summaryrefslogtreecommitdiffabout
path: root/test/test.cc
Unidiff
Diffstat (limited to 'test/test.cc') (more/less context) (show whitespace changes)
-rw-r--r--test/test.cc49
1 files changed, 0 insertions, 49 deletions
diff --git a/test/test.cc b/test/test.cc
index 1a012b5..35f58ab 100644
--- a/test/test.cc
+++ b/test/test.cc
@@ -1,74 +1,26 @@
1#include <iostream> 1#include <iostream>
2#include <stdexcept> 2#include <stdexcept>
3using namespace std; 3using namespace std;
4#include <opkele/exception.h> 4#include <opkele/exception.h>
5#include <opkele/consumer.h>
6#include <opkele/util.h> 5#include <opkele/util.h>
7 6
8#include "config.h" 7#include "config.h"
9 8
10class failed_test : public opkele::exception { 9class failed_test : public opkele::exception {
11 public: 10 public:
12 failed_test(OPKELE_E_PARS) 11 failed_test(OPKELE_E_PARS)
13 : exception(OPKELE_E_CONS) { } 12 : exception(OPKELE_E_CONS) { }
14}; 13};
15 14
16class dummy_consumer_t : public opkele::consumer_t {
17 public:
18 virtual opkele::assoc_t store_assoc(const string& /* server */,const string& /* handle */,const opkele::secret_t& /* secret */,int /* expires_in */) {
19 throw opkele::not_implemented(OPKELE_CP_ "Not implemented");
20 }
21 virtual opkele::assoc_t retrieve_assoc(const string& /* server */ ,const string& /* handle */) {
22 throw opkele::not_implemented(OPKELE_CP_ "Not implemented");
23 }
24 virtual void invalidate_assoc(const string& /* server */,const string& /* handle */) {
25 throw opkele::not_implemented(OPKELE_CP_ "Not implemented");
26 }
27};
28
29
30void test_retrieve_links(const string& f,bool success,const string& s="",const string& d="") {
31 dummy_consumer_t dc;
32 string server, delegate;
33 try {
34 dc.retrieve_links("file://" OPKELE_SRC_DIR "/test/html/"+f,server,delegate);
35 if(!success)
36 throw failed_test(OPKELE_CP_ "Retrieved links when it shouldn't");
37 if(server!=s)
38 throw failed_test(OPKELE_CP_ "retrieve_links test failed, expected server '"+s+"', got '"+server+"'");
39 if(delegate!=d)
40 throw failed_test(OPKELE_CP_ "retrieve_links test failed, expected delegate '"+d+"', got '"+delegate+"'");
41 }catch(opkele::bad_input& obi) {
42 if(success)
43 throw failed_test(OPKELE_CP_ "Test '"+f+"' failed due to 'bad_input'["+obi.what()+"]");
44 }catch(opkele::failed_assertion& ofa) {
45 if(success)
46 throw failed_test(OPKELE_CP_ "Test '"+f+"' failed due to 'failed_assertion'["+ofa.what()+"]");
47 }
48}
49
50void test_retrieve_links() {
51 test_retrieve_links("empty.html",false);
52 test_retrieve_links("in-body.html",false);
53 test_retrieve_links("head-in-body.html",false);
54 test_retrieve_links("hkn.html",true,"http://www.klever.net/openid.server","http://hacker.klever.net/");
55 test_retrieve_links("hkn-server.html",true,"http://www.klever.net/openid.server");
56 test_retrieve_links("hkn-delegate.html",false);
57 test_retrieve_links("unclosed-head.html",true,"http://www.klever.net/openid.server","http://hacker.klever.net/");
58 test_retrieve_links("spaced-links.html",true,"http://www.klever.net/openid.server","http://hacker.klever.net/");
59 test_retrieve_links("spaced-link-attrs.html",true,"http://www.klever.net/openid.server","http://hacker.klever.net/");
60 test_retrieve_links("2rels.html",true,"http://www.klever.net/openid.server","http://www.klever.net/openid.server");
61}
62
63void 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="") {
64 try { 16 try {
65 string n = opkele::util::rfc_3986_normalize_uri(ouri); 17 string n = opkele::util::rfc_3986_normalize_uri(ouri);
66 if(!success) 18 if(!success)
67 throw failed_test(OPKELE_CP_ "Normalized URI when it shouldn't"); 19 throw failed_test(OPKELE_CP_ "Normalized URI when it shouldn't");
68 if(n!=nuri) 20 if(n!=nuri)
69 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+"'");
70 }catch(opkele::bad_input& obi) { 22 }catch(opkele::bad_input& obi) {
71 if(success) 23 if(success)
72 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()+"]");
73 }catch(opkele::not_implemented& oni) { 25 }catch(opkele::not_implemented& oni) {
74 if(success) 26 if(success)
@@ -119,21 +71,20 @@ void test_rfc_3986_normalize_uri() {
119 "http://hacker.klever.net/ah/%a", false ); 71 "http://hacker.klever.net/ah/%a", false );
120 test_rfc_3986_normalize_uri( 72 test_rfc_3986_normalize_uri(
121 "http://hacker.klever.net/ah/%zx", false ); 73 "http://hacker.klever.net/ah/%zx", false );
122 test_rfc_3986_normalize_uri( 74 test_rfc_3986_normalize_uri(
123 "http://hacker.klever.net/ah/%5x", false ); 75 "http://hacker.klever.net/ah/%5x", false );
124 test_rfc_3986_normalize_uri( 76 test_rfc_3986_normalize_uri(
125 "Http://Hacker.Klever.Net:", true, "http://hacker.klever.net/" ); 77 "Http://Hacker.Klever.Net:", true, "http://hacker.klever.net/" );
126} 78}
127 79
128int main() { 80int main() {
129 try { 81 try {
130 test_rfc_3986_normalize_uri(); 82 test_rfc_3986_normalize_uri();
131 test_retrieve_links();
132 }catch(failed_test& ft) { 83 }catch(failed_test& ft) {
133 cerr << "Test failed: " << ft.what() << endl; 84 cerr << "Test failed: " << ft.what() << endl;
134 }catch(exception& e) { 85 }catch(exception& e) {
135 cerr << "oops: " << e.what() << endl; 86 cerr << "oops: " << e.what() << endl;
136 _exit(1); 87 _exit(1);
137 } 88 }
138 _exit(0); 89 _exit(0);
139} 90}