From 2c6565f363527142928062afe3d3101fdbb3c550 Mon Sep 17 00:00:00 2001 From: Michael Krelin Date: Tue, 11 Sep 2007 22:01:00 +0000 Subject: a quick set of tests for retrieve_links machinery Signed-off-by: Michael Krelin --- (limited to 'test') diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000..918b3c9 --- a/dev/null +++ b/test/.gitignore @@ -0,0 +1,4 @@ +/.deps +/.libs +/test +*.o diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..0dbba65 --- a/dev/null +++ b/test/Makefile.am @@ -0,0 +1,8 @@ +noinst_PROGRAMS = test + +INCLUDES = -I${top_srcdir}/include/ + +test_SOURCES = test.cc +test_LDADD = ${top_builddir}/lib/libopkele.la + +EXTRA_DIST=$(addsuffix .html,$(addprefix html/, empty head-in-body hkn-delegate hkn-server hkn in-body)) diff --git a/test/html/empty.html b/test/html/empty.html new file mode 100644 index 0000000..e69de29 --- a/dev/null +++ b/test/html/empty.html diff --git a/test/html/head-in-body.html b/test/html/head-in-body.html new file mode 100644 index 0000000..0f778f3 --- a/dev/null +++ b/test/html/head-in-body.html @@ -0,0 +1,10 @@ + + + + + + + + + + diff --git a/test/html/hkn-delegate.html b/test/html/hkn-delegate.html new file mode 100644 index 0000000..62e25a3 --- a/dev/null +++ b/test/html/hkn-delegate.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/test/html/hkn-server.html b/test/html/hkn-server.html new file mode 100644 index 0000000..e6b64e8 --- a/dev/null +++ b/test/html/hkn-server.html @@ -0,0 +1,7 @@ + + + + + + + diff --git a/test/html/hkn.html b/test/html/hkn.html new file mode 100644 index 0000000..8d6e409 --- a/dev/null +++ b/test/html/hkn.html @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/test/html/in-body.html b/test/html/in-body.html new file mode 100644 index 0000000..53bc06d --- a/dev/null +++ b/test/html/in-body.html @@ -0,0 +1,8 @@ + + + + + + + + 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 @@ +#include +#include +using namespace std; +#include +#include + +#include "config.h" + +class failed_test : public opkele::exception { + public: + failed_test(OPKELE_E_PARS) + : exception(OPKELE_E_CONS) { } +}; + +class dummy_consumer_t : public opkele::consumer_t { + public: + virtual opkele::assoc_t store_assoc(const string& server,const string& handle,const opkele::secret_t& secret,int expires_in) { + throw opkele::not_implemented(OPKELE_CP_ "Not implemented"); + } + virtual opkele::assoc_t retrieve_assoc(const string& server,const string& handle) { + throw opkele::not_implemented(OPKELE_CP_ "Not implemented"); + } + virtual void invalidate_assoc(const string& server,const string& handle) { + throw opkele::not_implemented(OPKELE_CP_ "Not implemented"); + } +}; + + +void test_retrieve_links(const string& f,bool success,const string& s="",const string& d="") { + dummy_consumer_t dc; + string server, delegate; + try { + dc.retrieve_links("file://" OPKELE_SRC_DIR "/test/html/"+f,server,delegate); + if(!success) + throw failed_test(OPKELE_CP_ "Retrieved links when it shouldn't"); + if(server!=s) + throw failed_test(OPKELE_CP_ "retrieve_links test failed, expected server '"+s+"', got '"+server+"'"); + if(delegate!=d) + throw failed_test(OPKELE_CP_ "retrieve_links test failed, expected delegate '"+d+"', got '"+delegate+"'"); + }catch(opkele::bad_input& obi) { + if(success) + throw failed_test(OPKELE_CP_ "Test failed"); + }catch(opkele::failed_assertion& ofa) { + if(success) + throw failed_test(OPKELE_CP_ "Test failed"); + } +} + +void test_retrieve_links() { + test_retrieve_links("empty.html",false); + test_retrieve_links("in-body.html",false); + test_retrieve_links("head-in-body.html",false); + test_retrieve_links("hkn.html",true,"http://www.klever.net/openid.server","http://hacker.klever.net/"); + test_retrieve_links("hkn-server.html",true,"http://www.klever.net/openid.server"); + test_retrieve_links("hkn-delegate.html",false); +} + +main() { + try { + test_retrieve_links(); + }catch(failed_test& ft) { + cerr << "Test failed: " << ft.what() << endl; + }catch(exception& e) { + cerr << "oops: " << e.what() << endl; + _exit(1); + } + _exit(0); +} -- cgit v0.9.0.2