diff options
author | nicolas.dufresne <nicolas.dufresne@c587cffe-e639-0410-9787-d7902ae8ed56> | 2010-05-26 21:38:34 +0000 |
---|---|---|
committer | nicolas.dufresne <nicolas.dufresne@c587cffe-e639-0410-9787-d7902ae8ed56> | 2010-05-26 21:38:34 +0000 |
commit | b62c1c838815dc4090f6744ba7a9fdab58b89884 (patch) | |
tree | d62ce201718c0ea3fe94d07b9b10b22842751ac6 | |
parent | cb84cee7068cc8ff17666dd197296841fee43bb2 (diff) | |
download | libproxy-b62c1c838815dc4090f6744ba7a9fdab58b89884.tar.gz |
Added URL test to demonstrate Issue 116
git-svn-id: http://libproxy.googlecode.com/svn/trunk@679 c587cffe-e639-0410-9787-d7902ae8ed56
-rw-r--r-- | libproxy/CMakeLists.txt | 6 | ||||
-rw-r--r-- | libproxy/test/CMakeLists.txt | 10 | ||||
-rw-r--r-- | libproxy/test/url-test.cpp | 41 |
3 files changed, 57 insertions, 0 deletions
diff --git a/libproxy/CMakeLists.txt b/libproxy/CMakeLists.txt index 3fc0e3a..6f7716d 100644 --- a/libproxy/CMakeLists.txt +++ b/libproxy/CMakeLists.txt @@ -184,3 +184,9 @@ set_property(SOURCE proxy.cpp PROPERTY COMPILE_DEFINITIONS MODULEDIR="${moduledi set_target_properties(libproxy PROPERTIES PREFIX "" VERSION 1.0.0 SOVERSION 1) install(TARGETS libproxy DESTINATION ${libdir}) install(FILES proxy.h DESTINATION ${includedir}) + + +## Tests +if (BUILD_TESTING) + add_subdirectory(test) +endif(BUILD_TESTING) diff --git a/libproxy/test/CMakeLists.txt b/libproxy/test/CMakeLists.txt new file mode 100644 index 0000000..0626321 --- /dev/null +++ b/libproxy/test/CMakeLists.txt @@ -0,0 +1,10 @@ +#### +## Libproxy Tests +#### + +include_directories(../) + +# URL Test +add_executable(url-test url-test.cpp ../url.cpp) +add_test(NAME url-test COMMAND url-test) + diff --git a/libproxy/test/url-test.cpp b/libproxy/test/url-test.cpp new file mode 100644 index 0000000..1908ece --- /dev/null +++ b/libproxy/test/url-test.cpp @@ -0,0 +1,41 @@ +#include <string> +#include <iostream> +#include <cassert> + +#include "url.hpp" + +using namespace libproxy; + +#define try_url(l) _try_url(l,__FILE__,__LINE__) +bool _try_url (std::string link, const char *file, int line) +{ + bool rtv = true; + try { + url u(link); + } + catch (exception e) { + std::cerr << "Can't parse '" << link << "'" + << " (" << file << ":" << line << ")" + << std::endl; + rtv = false; + } + return rtv; +} + +int main() +{ + bool rtv = true; + + rtv = try_url ("file:///allo") && rtv; + rtv = try_url ("http://test.com") && rtv; + rtv = try_url ("http://test.com/") && rtv; + rtv = try_url ("http://test.com#") && rtv; + rtv = try_url ("http://test.com?") && rtv; + rtv = try_url ("http://nicolas@test.com") && rtv; + rtv = try_url ("http://nicolas:@test.com") && rtv; + rtv = try_url ("http://nicolas:secret@test.com") && rtv; + rtv = try_url ("http://:secret@test.com") && rtv; + rtv = try_url ("http+ssh://:secret@test.com") && rtv; + + return !rtv; +} |