author | Michael Krelin <hacker@klever.net> | 2007-09-11 22:01:00 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2007-09-11 22:01:00 (UTC) |
commit | 2c6565f363527142928062afe3d3101fdbb3c550 (patch) (side-by-side diff) | |
tree | 7f5b26dad9a2870897ab4e63285fee4516881224 | |
parent | 5c41d9c975fc80495eebb0ac2cf062bf20c62d86 (diff) | |
download | libopkele-2c6565f363527142928062afe3d3101fdbb3c550.zip libopkele-2c6565f363527142928062afe3d3101fdbb3c550.tar.gz libopkele-2c6565f363527142928062afe3d3101fdbb3c550.tar.bz2 |
a quick set of tests for retrieve_links machinery
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | Makefile.am | 2 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | test/.gitignore | 4 | ||||
-rw-r--r-- | test/Makefile.am | 8 | ||||
-rw-r--r-- | test/html/empty.html | 0 | ||||
-rw-r--r-- | test/html/head-in-body.html | 10 | ||||
-rw-r--r-- | test/html/hkn-delegate.html | 7 | ||||
-rw-r--r-- | test/html/hkn-server.html | 7 | ||||
-rw-r--r-- | test/html/hkn.html | 8 | ||||
-rw-r--r-- | test/html/in-body.html | 8 | ||||
-rw-r--r-- | test/test.cc | 68 |
11 files changed, 124 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index c577ef8..741d585 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,18 +1,18 @@ -SUBDIRS=include lib +SUBDIRS=include lib test EXTRA_DIST= NEWS NEWS.xml NEWS.xsl DISTCHECK_CONFIGURE_FLAGS=--with-pkgconfigdir=$${dc_install_base}/lib/pkgconfig if HAVE_PKGCONFIG pkgconfigdir=@PKGCONFIG_DIR@ pkgconfig_DATA=libopkele.pc endif all-local: NEWS if HAVE_DOXYGEN clean-local: rm -rf doxydox endif NEWS: NEWS.xsl NEWS.xml ${XSLTPROC} -o $@ NEWS.xsl NEWS.xml diff --git a/configure.ac b/configure.ac index eb3f4d6..2094273 100644 --- a/configure.ac +++ b/configure.ac @@ -69,24 +69,27 @@ AC_ARG_ENABLE([ssl-verify-host], ${curl_ssl_verify_host} || AC_DEFINE([DISABLE_CURL_SSL_VERIFYHOST],,[defined if cURL is not to verify cert/host]) curl_ssl_verify_peer="true" AC_ARG_ENABLE([ssl-verify-peer], AC_HELP_STRING([--disable-ssl-verify-peer],[disable cURL cert validity verification]), [ test "${enableval}" = "no" && curl_ssl_verify_peer="false" ] ) ${curl_ssl_verify_peer} || AC_DEFINE([DISABLE_CURL_SSL_VERIFYPEER],,[defined if cURL is not to verify cert validity]) postels_law=true AC_ARG_ENABLE([postels-law], AC_HELP_STRING([--disable-postels-law],[Be strict, do not adhere to Postel's Law ("be conservative in what you do, be liberal in what you accept from others", RFC 793)]), [ test "${enableval}" = "no" && postels_law=false ] ) $postels_law && AC_DEFINE([POSTELS_LAW],,[defined if we want to adhere to Postel's Law]) +AC_DEFINE_UNQUOTED([OPKELE_SRC_DIR],["$PWD"],[source directory]) + AC_CONFIG_FILES([ Makefile libopkele.pc Doxyfile include/Makefile lib/Makefile + test/Makefile ]) AC_OUTPUT 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 @@ +<html> + <head> + </head> + <body> + <head> + <link rel="openid.server" href="http://www.klever.net/openid.server" /> + <link rel="openid.delegate" href="http://hacker.klever.net/" /> + </head> + </body> +</html> 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 @@ +<html> + <head> + <link rel="openid.delegate" href="http://hacker.klever.net/" /> + </head> + <body> + </body> +</html> 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 @@ +<html> + <head> + <link rel="openid.server" href="http://www.klever.net/openid.server" /> + </head> + <body> + </body> +</html> 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 @@ +<html> + <head> + <link rel="openid.server" href="http://www.klever.net/openid.server" /> + <link rel="openid.delegate" href="http://hacker.klever.net/" /> + </head> + <body> + </body> +</html> 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 @@ +<html> + <head> + </head> + <body> + <link rel="openid.server" href="http://www.klever.net/openid.server" /> + <link rel="openid.delegate" href="http://hacker.klever.net/" /> + </body> +</html> 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 <iostream> +#include <stdexcept> +using namespace std; +#include <opkele/exception.h> +#include <opkele/consumer.h> + +#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); +} |