summaryrefslogtreecommitdiffabout
path: root/test/test.cc
Unidiff
Diffstat (limited to 'test/test.cc') (more/less context) (ignore whitespace changes)
-rw-r--r--test/test.cc68
1 files changed, 68 insertions, 0 deletions
diff --git a/test/test.cc b/test/test.cc
new file mode 100644
index 0000000..f0526c6
--- a/dev/null
+++ b/test/test.cc
@@ -0,0 +1,68 @@
1#include <iostream>
2#include <stdexcept>
3using namespace std;
4#include <opkele/exception.h>
5#include <opkele/consumer.h>
6
7#include "config.h"
8
9class failed_test : public opkele::exception {
10 public:
11 failed_test(OPKELE_E_PARS)
12 : exception(OPKELE_E_CONS) { }
13};
14
15class dummy_consumer_t : public opkele::consumer_t {
16 public:
17 virtual opkele::assoc_t store_assoc(const string& server,const string& handle,const opkele::secret_t& secret,int expires_in) {
18 throw opkele::not_implemented(OPKELE_CP_ "Not implemented");
19 }
20 virtual opkele::assoc_t retrieve_assoc(const string& server,const string& handle) {
21 throw opkele::not_implemented(OPKELE_CP_ "Not implemented");
22 }
23 virtual void invalidate_assoc(const string& server,const string& handle) {
24 throw opkele::not_implemented(OPKELE_CP_ "Not implemented");
25 }
26};
27
28
29void test_retrieve_links(const string& f,bool success,const string& s="",const string& d="") {
30 dummy_consumer_t dc;
31 string server, delegate;
32 try {
33 dc.retrieve_links("file://" OPKELE_SRC_DIR "/test/html/"+f,server,delegate);
34 if(!success)
35 throw failed_test(OPKELE_CP_ "Retrieved links when it shouldn't");
36 if(server!=s)
37 throw failed_test(OPKELE_CP_ "retrieve_links test failed, expected server '"+s+"', got '"+server+"'");
38 if(delegate!=d)
39 throw failed_test(OPKELE_CP_ "retrieve_links test failed, expected delegate '"+d+"', got '"+delegate+"'");
40 }catch(opkele::bad_input& obi) {
41 if(success)
42 throw failed_test(OPKELE_CP_ "Test failed");
43 }catch(opkele::failed_assertion& ofa) {
44 if(success)
45 throw failed_test(OPKELE_CP_ "Test failed");
46 }
47}
48
49void test_retrieve_links() {
50 test_retrieve_links("empty.html",false);
51 test_retrieve_links("in-body.html",false);
52 test_retrieve_links("head-in-body.html",false);
53 test_retrieve_links("hkn.html",true,"http://www.klever.net/openid.server","http://hacker.klever.net/");
54 test_retrieve_links("hkn-server.html",true,"http://www.klever.net/openid.server");
55 test_retrieve_links("hkn-delegate.html",false);
56}
57
58main() {
59 try {
60 test_retrieve_links();
61 }catch(failed_test& ft) {
62 cerr << "Test failed: " << ft.what() << endl;
63 }catch(exception& e) {
64 cerr << "oops: " << e.what() << endl;
65 _exit(1);
66 }
67 _exit(0);
68}