summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhsoting.net>2018-11-16 07:14:58 +0100
committerJörg Frings-Fürst <debian@jff-webhsoting.net>2018-11-16 07:14:58 +0100
commit37162209a3da8812203022de6b81e4f05015043a (patch)
tree19d8a4b4a3e6cd31c64c608b46c6fe710f8e6eb8 /test
parent21ce7e27a89c3f9c2fb4bc8bd59877dc2d8cd6b9 (diff)
New upstream version 0.9.0upstream/0.9.0
Diffstat (limited to 'test')
-rw-r--r--test/FourSuite.cpp689
-rw-r--r--test/FourSuite.h70
-rw-r--r--test/MemoryManagerSuite.cpp376
-rw-r--r--test/VersionSuite.cpp9
-rw-r--r--test/VersionSuite.h46
-rw-r--r--test/config.h.in64
-rw-r--r--test/test.cpp1633
7 files changed, 1585 insertions, 1302 deletions
diff --git a/test/FourSuite.cpp b/test/FourSuite.cpp
index 5ecdcb4..466a94c 100644
--- a/test/FourSuite.cpp
+++ b/test/FourSuite.cpp
@@ -19,7 +19,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "FourSuite.h"
+#include <gtest/gtest.h>
#include <uriparser/Uri.h>
@@ -29,9 +29,10 @@
// http://cvs.4suite.org/viewcvs/4Suite/test/Lib/test_uri.py
+namespace {
-bool FourSuite::testAddOrRemoveBaseHelper(const char * ref, const char * base,
- const char * expected, bool add, bool domainRootMode) {
+bool testAddOrRemoveBaseHelper(const char * ref, const char * base,
+ const char * expected, bool add = true, bool domainRootMode = false) {
UriParserStateA stateA;
// Base
@@ -94,9 +95,10 @@ bool FourSuite::testAddOrRemoveBaseHelper(const char * ref, const char * base,
return equal;
}
+} // namespace
-void FourSuite::absolutize_test_cases() {
+TEST(FourSuite, AbsolutizeTestCases) {
const char * const BASE_URI[] = {
"http://a/b/c/d;p?q",
"http://a/b/c/d;p?q=1/2",
@@ -107,288 +109,289 @@ void FourSuite::absolutize_test_cases() {
// ref, base, exptected
// http://lists.w3.org/Archives/Public/uri/2004Feb/0114.html
- TEST_ASSERT(testAddOrRemoveBaseHelper("../c", "foo:a/b", "foo:c"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("foo:.", "foo:a", "foo:"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/foo/../../../bar", "zz:abc", "zz:/bar"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/foo/../bar", "zz:abc", "zz:/bar"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("foo/../../../bar", "zz:abc", "zz:bar"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("foo/../bar", "zz:abc", "zz:bar"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("zz:.", "zz:abc", "zz:"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/.", BASE_URI[0], "http://a/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/.foo", BASE_URI[0], "http://a/.foo"));
- TEST_ASSERT(testAddOrRemoveBaseHelper(".foo", BASE_URI[0], "http://a/b/c/.foo"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../c", "foo:a/b", "foo:c"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("foo:.", "foo:a", "foo:"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/foo/../../../bar", "zz:abc", "zz:/bar"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/foo/../bar", "zz:abc", "zz:/bar"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("foo/../../../bar", "zz:abc", "zz:bar"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("foo/../bar", "zz:abc", "zz:bar"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("zz:.", "zz:abc", "zz:"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/.", BASE_URI[0], "http://a/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/.foo", BASE_URI[0], "http://a/.foo"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper(".foo", BASE_URI[0], "http://a/b/c/.foo"));
// http://gbiv.com/protocols/uri/test/rel_examples1.html
// examples from RFC 2396
- TEST_ASSERT(testAddOrRemoveBaseHelper("g:h", BASE_URI[0], "g:h"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g", BASE_URI[0], "http://a/b/c/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./g", BASE_URI[0], "http://a/b/c/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g/", BASE_URI[0], "http://a/b/c/g/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/g", BASE_URI[0], "http://a/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("//g", BASE_URI[0], "http://g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g:h", BASE_URI[0], "g:h"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[0], "http://a/b/c/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[0], "http://a/b/c/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[0], "http://a/b/c/g/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/g", BASE_URI[0], "http://a/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("//g", BASE_URI[0], "http://g"));
// changed with RFC 2396bis
- TEST_ASSERT(testAddOrRemoveBaseHelper("?y", BASE_URI[0], "http://a/b/c/d;p?y"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g?y", BASE_URI[0], "http://a/b/c/g?y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("?y", BASE_URI[0], "http://a/b/c/d;p?y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y", BASE_URI[0], "http://a/b/c/g?y"));
// changed with RFC 2396bis
- TEST_ASSERT(testAddOrRemoveBaseHelper("#s", BASE_URI[0], "http://a/b/c/d;p?q#s"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g#s", BASE_URI[0], "http://a/b/c/g#s"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g?y#s", BASE_URI[0], "http://a/b/c/g?y#s"));
- TEST_ASSERT(testAddOrRemoveBaseHelper(";x", BASE_URI[0], "http://a/b/c/;x"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g;x", BASE_URI[0], "http://a/b/c/g;x"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g;x?y#s", BASE_URI[0], "http://a/b/c/g;x?y#s"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("#s", BASE_URI[0], "http://a/b/c/d;p?q#s"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s", BASE_URI[0], "http://a/b/c/g#s"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y#s", BASE_URI[0], "http://a/b/c/g?y#s"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper(";x", BASE_URI[0], "http://a/b/c/;x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x", BASE_URI[0], "http://a/b/c/g;x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x?y#s", BASE_URI[0], "http://a/b/c/g;x?y#s"));
// changed with RFC 2396bis
- TEST_ASSERT(testAddOrRemoveBaseHelper("", BASE_URI[0], "http://a/b/c/d;p?q"));
- TEST_ASSERT(testAddOrRemoveBaseHelper(".", BASE_URI[0], "http://a/b/c/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./", BASE_URI[0], "http://a/b/c/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("..", BASE_URI[0], "http://a/b/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../", BASE_URI[0], "http://a/b/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../g", BASE_URI[0], "http://a/b/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../..", BASE_URI[0], "http://a/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../", BASE_URI[0], "http://a/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../g", BASE_URI[0], "http://a/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../../g", BASE_URI[0], "http://a/g")); // http://a/../g
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../../../g", BASE_URI[0], "http://a/g")); // http://a/../../g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", BASE_URI[0], "http://a/b/c/d;p?q"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper(".", BASE_URI[0], "http://a/b/c/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[0], "http://a/b/c/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("..", BASE_URI[0], "http://a/b/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[0], "http://a/b/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[0], "http://a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../..", BASE_URI[0], "http://a/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[0], "http://a/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[0], "http://a/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../g", BASE_URI[0], "http://a/g")); // http://a/../g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../../g", BASE_URI[0], "http://a/g")); // http://a/../../g
// changed with RFC 2396bis
- TEST_ASSERT(testAddOrRemoveBaseHelper("/./g", BASE_URI[0], "http://a/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/./g", BASE_URI[0], "http://a/g"));
// changed with RFC 2396bis
- TEST_ASSERT(testAddOrRemoveBaseHelper("/../g", BASE_URI[0], "http://a/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g.", BASE_URI[0], "http://a/b/c/g."));
- TEST_ASSERT(testAddOrRemoveBaseHelper(".g", BASE_URI[0], "http://a/b/c/.g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g..", BASE_URI[0], "http://a/b/c/g.."));
- TEST_ASSERT(testAddOrRemoveBaseHelper("..g", BASE_URI[0], "http://a/b/c/..g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./../g", BASE_URI[0], "http://a/b/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./g/.", BASE_URI[0], "http://a/b/c/g/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g/./h", BASE_URI[0], "http://a/b/c/g/h"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g/../h", BASE_URI[0], "http://a/b/c/h"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g;x=1/./y", BASE_URI[0], "http://a/b/c/g;x=1/y"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g;x=1/../y", BASE_URI[0], "http://a/b/c/y"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g?y/./x", BASE_URI[0], "http://a/b/c/g?y/./x"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g?y/../x", BASE_URI[0], "http://a/b/c/g?y/../x"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g#s/./x", BASE_URI[0], "http://a/b/c/g#s/./x"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g#s/../x", BASE_URI[0], "http://a/b/c/g#s/../x"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("http:g", BASE_URI[0], "http:g")); // http://a/b/c/g
- TEST_ASSERT(testAddOrRemoveBaseHelper("http:", BASE_URI[0], "http:")); // BASE_URI[0]
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/../g", BASE_URI[0], "http://a/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g.", BASE_URI[0], "http://a/b/c/g."));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper(".g", BASE_URI[0], "http://a/b/c/.g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g..", BASE_URI[0], "http://a/b/c/g.."));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("..g", BASE_URI[0], "http://a/b/c/..g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./../g", BASE_URI[0], "http://a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./g/.", BASE_URI[0], "http://a/b/c/g/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g/./h", BASE_URI[0], "http://a/b/c/g/h"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g/../h", BASE_URI[0], "http://a/b/c/h"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x=1/./y", BASE_URI[0], "http://a/b/c/g;x=1/y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x=1/../y", BASE_URI[0], "http://a/b/c/y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y/./x", BASE_URI[0], "http://a/b/c/g?y/./x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y/../x", BASE_URI[0], "http://a/b/c/g?y/../x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s/./x", BASE_URI[0], "http://a/b/c/g#s/./x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s/../x", BASE_URI[0], "http://a/b/c/g#s/../x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("http:g", BASE_URI[0], "http:g")); // http://a/b/c/g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("http:", BASE_URI[0], "http:")); // BASE_URI[0]
// not sure where this one originated
- TEST_ASSERT(testAddOrRemoveBaseHelper("/a/b/c/./../../g", BASE_URI[0], "http://a/a/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/a/b/c/./../../g", BASE_URI[0], "http://a/a/g"));
// http://gbiv.com/protocols/uri/test/rel_examples2.html
// slashes in base URI's query args
- TEST_ASSERT(testAddOrRemoveBaseHelper("g", BASE_URI[1], "http://a/b/c/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./g", BASE_URI[1], "http://a/b/c/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g/", BASE_URI[1], "http://a/b/c/g/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/g", BASE_URI[1], "http://a/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("//g", BASE_URI[1], "http://g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[1], "http://a/b/c/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[1], "http://a/b/c/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[1], "http://a/b/c/g/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/g", BASE_URI[1], "http://a/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("//g", BASE_URI[1], "http://g"));
// changed in RFC 2396bis
- // TEST_ASSERT(testAddOrRemoveBaseHelper("?y", BASE_URI[1], "http://a/b/c/?y"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("?y", BASE_URI[1], "http://a/b/c/d;p?y"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g?y", BASE_URI[1], "http://a/b/c/g?y"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g?y/./x", BASE_URI[1], "http://a/b/c/g?y/./x"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g?y/../x", BASE_URI[1], "http://a/b/c/g?y/../x"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g#s", BASE_URI[1], "http://a/b/c/g#s"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g#s/./x", BASE_URI[1], "http://a/b/c/g#s/./x"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g#s/../x", BASE_URI[1], "http://a/b/c/g#s/../x"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./", BASE_URI[1], "http://a/b/c/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../", BASE_URI[1], "http://a/b/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../g", BASE_URI[1], "http://a/b/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../", BASE_URI[1], "http://a/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../g", BASE_URI[1], "http://a/g"));
+ // ASSERT_TRUE(testAddOrRemoveBaseHelper("?y", BASE_URI[1], "http://a/b/c/?y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("?y", BASE_URI[1], "http://a/b/c/d;p?y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y", BASE_URI[1], "http://a/b/c/g?y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y/./x", BASE_URI[1], "http://a/b/c/g?y/./x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y/../x", BASE_URI[1], "http://a/b/c/g?y/../x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s", BASE_URI[1], "http://a/b/c/g#s"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s/./x", BASE_URI[1], "http://a/b/c/g#s/./x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g#s/../x", BASE_URI[1], "http://a/b/c/g#s/../x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[1], "http://a/b/c/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[1], "http://a/b/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[1], "http://a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[1], "http://a/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[1], "http://a/g"));
// http://gbiv.com/protocols/uri/test/rel_examples3.html
// slashes in path params
// all of these changed in RFC 2396bis
- TEST_ASSERT(testAddOrRemoveBaseHelper("g", BASE_URI[2], "http://a/b/c/d;p=1/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./g", BASE_URI[2], "http://a/b/c/d;p=1/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g/", BASE_URI[2], "http://a/b/c/d;p=1/g/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g?y", BASE_URI[2], "http://a/b/c/d;p=1/g?y"));
- TEST_ASSERT(testAddOrRemoveBaseHelper(";x", BASE_URI[2], "http://a/b/c/d;p=1/;x"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g;x", BASE_URI[2], "http://a/b/c/d;p=1/g;x"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g;x=1/./y", BASE_URI[2], "http://a/b/c/d;p=1/g;x=1/y"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g;x=1/../y", BASE_URI[2], "http://a/b/c/d;p=1/y"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./", BASE_URI[2], "http://a/b/c/d;p=1/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../", BASE_URI[2], "http://a/b/c/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../g", BASE_URI[2], "http://a/b/c/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../", BASE_URI[2], "http://a/b/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../g", BASE_URI[2], "http://a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[2], "http://a/b/c/d;p=1/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[2], "http://a/b/c/d;p=1/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[2], "http://a/b/c/d;p=1/g/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g?y", BASE_URI[2], "http://a/b/c/d;p=1/g?y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper(";x", BASE_URI[2], "http://a/b/c/d;p=1/;x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x", BASE_URI[2], "http://a/b/c/d;p=1/g;x"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x=1/./y", BASE_URI[2], "http://a/b/c/d;p=1/g;x=1/y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g;x=1/../y", BASE_URI[2], "http://a/b/c/d;p=1/y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[2], "http://a/b/c/d;p=1/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[2], "http://a/b/c/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[2], "http://a/b/c/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[2], "http://a/b/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[2], "http://a/b/g"));
// http://gbiv.com/protocols/uri/test/rel_examples4.html
// double and triple slash, unknown scheme
- TEST_ASSERT(testAddOrRemoveBaseHelper("g:h", BASE_URI[3], "g:h"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g", BASE_URI[3], "fred:///s//a/b/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./g", BASE_URI[3], "fred:///s//a/b/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g/", BASE_URI[3], "fred:///s//a/b/g/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/g", BASE_URI[3], "fred:///g")); // may change to fred:///s//a/g
- TEST_ASSERT(testAddOrRemoveBaseHelper("//g", BASE_URI[3], "fred://g")); // may change to fred:///s//g
- TEST_ASSERT(testAddOrRemoveBaseHelper("//g/x", BASE_URI[3], "fred://g/x")); // may change to fred:///s//g/x
- TEST_ASSERT(testAddOrRemoveBaseHelper("///g", BASE_URI[3], "fred:///g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./", BASE_URI[3], "fred:///s//a/b/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../", BASE_URI[3], "fred:///s//a/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../g", BASE_URI[3], "fred:///s//a/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../", BASE_URI[3], "fred:///s//")); // may change to fred:///s//a/../
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../g", BASE_URI[3], "fred:///s//g")); // may change to fred:///s//a/../g
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../../g", BASE_URI[3], "fred:///s/g")); // may change to fred:///s//a/../../g
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../../../g", BASE_URI[3], "fred:///g")); // may change to fred:///s//a/../../../g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g:h", BASE_URI[3], "g:h"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[3], "fred:///s//a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[3], "fred:///s//a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[3], "fred:///s//a/b/g/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/g", BASE_URI[3], "fred:///g")); // may change to fred:///s//a/g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("//g", BASE_URI[3], "fred://g")); // may change to fred:///s//g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("//g/x", BASE_URI[3], "fred://g/x")); // may change to fred:///s//g/x
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("///g", BASE_URI[3], "fred:///g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[3], "fred:///s//a/b/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[3], "fred:///s//a/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[3], "fred:///s//a/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[3], "fred:///s//")); // may change to fred:///s//a/../
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[3], "fred:///s//g")); // may change to fred:///s//a/../g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../g", BASE_URI[3], "fred:///s/g")); // may change to fred:///s//a/../../g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../../g", BASE_URI[3], "fred:///g")); // may change to fred:///s//a/../../../g
// http://gbiv.com/protocols/uri/test/rel_examples5.html
// double and triple slash, well-known scheme
- TEST_ASSERT(testAddOrRemoveBaseHelper("g:h", BASE_URI[4], "g:h"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g", BASE_URI[4], "http:///s//a/b/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./g", BASE_URI[4], "http:///s//a/b/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("g/", BASE_URI[4], "http:///s//a/b/g/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/g", BASE_URI[4], "http:///g")); // may change to http:///s//a/g
- TEST_ASSERT(testAddOrRemoveBaseHelper("//g", BASE_URI[4], "http://g")); // may change to http:///s//g
- TEST_ASSERT(testAddOrRemoveBaseHelper("//g/x", BASE_URI[4], "http://g/x")); // may change to http:///s//g/x
- TEST_ASSERT(testAddOrRemoveBaseHelper("///g", BASE_URI[4], "http:///g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./", BASE_URI[4], "http:///s//a/b/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../", BASE_URI[4], "http:///s//a/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../g", BASE_URI[4], "http:///s//a/g"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../", BASE_URI[4], "http:///s//")); // may change to http:///s//a/../
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../g", BASE_URI[4], "http:///s//g")); // may change to http:///s//a/../g
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../../g", BASE_URI[4], "http:///s/g")); // may change to http:///s//a/../../g
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../../../g", BASE_URI[4], "http:///g")); // may change to http:///s//a/../../../g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g:h", BASE_URI[4], "g:h"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g", BASE_URI[4], "http:///s//a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./g", BASE_URI[4], "http:///s//a/b/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("g/", BASE_URI[4], "http:///s//a/b/g/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/g", BASE_URI[4], "http:///g")); // may change to http:///s//a/g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("//g", BASE_URI[4], "http://g")); // may change to http:///s//g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("//g/x", BASE_URI[4], "http://g/x")); // may change to http:///s//g/x
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("///g", BASE_URI[4], "http:///g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./", BASE_URI[4], "http:///s//a/b/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../", BASE_URI[4], "http:///s//a/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../g", BASE_URI[4], "http:///s//a/g"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../", BASE_URI[4], "http:///s//")); // may change to http:///s//a/../
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../g", BASE_URI[4], "http:///s//g")); // may change to http:///s//a/../g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../g", BASE_URI[4], "http:///s/g")); // may change to http:///s//a/../../g
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../../../g", BASE_URI[4], "http:///g")); // may change to http:///s//a/../../../g
// from Dan Connelly's tests in http://www.w3.org/2000/10/swap/uripath.py
- TEST_ASSERT(testAddOrRemoveBaseHelper("bar:abc", "foo:xyz", "bar:abc"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../abc", "http://example/x/y/z", "http://example/x/abc"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("http://example/x/abc", "http://example2/x/y/z", "http://example/x/abc"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../r", "http://ex/x/y/z", "http://ex/x/r"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("q/r", "http://ex/x/y", "http://ex/x/q/r"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("q/r#s", "http://ex/x/y", "http://ex/x/q/r#s"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("q/r#s/t", "http://ex/x/y", "http://ex/x/q/r#s/t"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("ftp://ex/x/q/r", "http://ex/x/y", "ftp://ex/x/q/r"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("", "http://ex/x/y", "http://ex/x/y"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("", "http://ex/x/y/", "http://ex/x/y/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("", "http://ex/x/y/pdq", "http://ex/x/y/pdq"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("z/", "http://ex/x/y/", "http://ex/x/y/z/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("#Animal", "file:/swap/test/animal.rdf", "file:/swap/test/animal.rdf#Animal"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../abc", "file:/e/x/y/z", "file:/e/x/abc"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/example/x/abc", "file:/example2/x/y/z", "file:/example/x/abc"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../r", "file:/ex/x/y/z", "file:/ex/x/r"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/r", "file:/ex/x/y/z", "file:/r"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("q/r", "file:/ex/x/y", "file:/ex/x/q/r"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("q/r#s", "file:/ex/x/y", "file:/ex/x/q/r#s"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("q/r#", "file:/ex/x/y", "file:/ex/x/q/r#"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("q/r#s/t", "file:/ex/x/y", "file:/ex/x/q/r#s/t"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("ftp://ex/x/q/r", "file:/ex/x/y", "ftp://ex/x/q/r"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("", "file:/ex/x/y", "file:/ex/x/y"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("", "file:/ex/x/y/", "file:/ex/x/y/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("", "file:/ex/x/y/pdq", "file:/ex/x/y/pdq"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("z/", "file:/ex/x/y/", "file:/ex/x/y/z/"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("file://meetings.example.com/cal#m1", "file:/devel/WWW/2000/10/swap/test/reluri-1.n3", "file://meetings.example.com/cal#m1"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("file://meetings.example.com/cal#m1", "file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/reluri-1.n3", "file://meetings.example.com/cal#m1"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./#blort", "file:/some/dir/foo", "file:/some/dir/#blort"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./#", "file:/some/dir/foo", "file:/some/dir/#"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("bar:abc", "foo:xyz", "bar:abc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../abc", "http://example/x/y/z", "http://example/x/abc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("http://example/x/abc", "http://example2/x/y/z", "http://example/x/abc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../r", "http://ex/x/y/z", "http://ex/x/r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r", "http://ex/x/y", "http://ex/x/q/r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#s", "http://ex/x/y", "http://ex/x/q/r#s"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#s/t", "http://ex/x/y", "http://ex/x/q/r#s/t"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("ftp://ex/x/q/r", "http://ex/x/y", "ftp://ex/x/q/r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", "http://ex/x/y", "http://ex/x/y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", "http://ex/x/y/", "http://ex/x/y/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", "http://ex/x/y/pdq", "http://ex/x/y/pdq"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("z/", "http://ex/x/y/", "http://ex/x/y/z/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("#Animal", "file:/swap/test/animal.rdf", "file:/swap/test/animal.rdf#Animal"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../abc", "file:/e/x/y/z", "file:/e/x/abc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/example/x/abc", "file:/example2/x/y/z", "file:/example/x/abc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../r", "file:/ex/x/y/z", "file:/ex/x/r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/r", "file:/ex/x/y/z", "file:/r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r", "file:/ex/x/y", "file:/ex/x/q/r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#s", "file:/ex/x/y", "file:/ex/x/q/r#s"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#", "file:/ex/x/y", "file:/ex/x/q/r#"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q/r#s/t", "file:/ex/x/y", "file:/ex/x/q/r#s/t"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("ftp://ex/x/q/r", "file:/ex/x/y", "ftp://ex/x/q/r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", "file:/ex/x/y", "file:/ex/x/y"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", "file:/ex/x/y/", "file:/ex/x/y/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", "file:/ex/x/y/pdq", "file:/ex/x/y/pdq"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("z/", "file:/ex/x/y/", "file:/ex/x/y/z/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("file://meetings.example.com/cal#m1", "file:/devel/WWW/2000/10/swap/test/reluri-1.n3", "file://meetings.example.com/cal#m1"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("file://meetings.example.com/cal#m1", "file:/home/connolly/w3ccvs/WWW/2000/10/swap/test/reluri-1.n3", "file://meetings.example.com/cal#m1"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./#blort", "file:/some/dir/foo", "file:/some/dir/#blort"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./#", "file:/some/dir/foo", "file:/some/dir/#"));
// Ryan Lee
- TEST_ASSERT(testAddOrRemoveBaseHelper("./", "http://example/x/abc.efg", "http://example/x/"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./", "http://example/x/abc.efg", "http://example/x/"));
// Graham Klyne's tests
// http://www.ninebynine.org/Software/HaskellUtils/Network/UriTest.xls
// 01-31 are from Connelly's cases
// 32-49
- TEST_ASSERT(testAddOrRemoveBaseHelper("./q:r", "http://ex/x/y", "http://ex/x/q:r"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./p=q:r", "http://ex/x/y", "http://ex/x/p=q:r"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("?pp/rr", "http://ex/x/y?pp/qq", "http://ex/x/y?pp/rr"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("y/z", "http://ex/x/y?pp/qq", "http://ex/x/y/z"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("local/qual@domain.org#frag", "mailto:local", "mailto:local/qual@domain.org#frag"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("more/qual2@domain2.org#frag", "mailto:local/qual1@domain1.org", "mailto:local/more/qual2@domain2.org#frag"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("y?q", "http://ex/x/y?q", "http://ex/x/y?q"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/x/y?q", "http://ex?p", "http://ex/x/y?q"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("c/d", "foo:a/b", "foo:a/c/d"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/c/d", "foo:a/b", "foo:/c/d"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("", "foo:a/b?c#d", "foo:a/b?c"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("b/c", "foo:a", "foo:b/c"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../b/c", "foo:/a/y/z", "foo:/a/b/c"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("./b/c", "foo:a", "foo:b/c"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/./b/c", "foo:a", "foo:/b/c"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../d", "foo://a//b/c", "foo://a/d"));
- TEST_ASSERT(testAddOrRemoveBaseHelper(".", "foo:a", "foo:"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("..", "foo:a", "foo:"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./q:r", "http://ex/x/y", "http://ex/x/q:r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./p=q:r", "http://ex/x/y", "http://ex/x/p=q:r"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("?pp/rr", "http://ex/x/y?pp/qq", "http://ex/x/y?pp/rr"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("y/z", "http://ex/x/y?pp/qq", "http://ex/x/y/z"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("local/qual@domain.org#frag", "mailto:local", "mailto:local/qual@domain.org#frag"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("more/qual2@domain2.org#frag", "mailto:local/qual1@domain1.org", "mailto:local/more/qual2@domain2.org#frag"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("y?q", "http://ex/x/y?q", "http://ex/x/y?q"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/x/y?q", "http://ex?p", "http://ex/x/y?q"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("c/d", "foo:a/b", "foo:a/c/d"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/c/d", "foo:a/b", "foo:/c/d"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("", "foo:a/b?c#d", "foo:a/b?c"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("b/c", "foo:a", "foo:b/c"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../b/c", "foo:/a/y/z", "foo:/a/b/c"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("./b/c", "foo:a", "foo:b/c"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/./b/c", "foo:a", "foo:/b/c"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../d", "foo://a//b/c", "foo://a/d"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper(".", "foo:a", "foo:"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("..", "foo:a", "foo:"));
// 50-57 (cf. TimBL comments --
// http://lists.w3.org/Archives/Public/uri/2003Feb/0028.html,
// http://lists.w3.org/Archives/Public/uri/2003Jan/0008.html)
- TEST_ASSERT(testAddOrRemoveBaseHelper("abc", "http://example/x/y%2Fz", "http://example/x/abc"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../../x%2Fabc", "http://example/a/x/y/z", "http://example/a/x%2Fabc"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../x%2Fabc", "http://example/a/x/y%2Fz", "http://example/a/x%2Fabc"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("abc", "http://example/x%2Fy/z", "http://example/x%2Fy/abc"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("q%3Ar", "http://ex/x/y", "http://ex/x/q%3Ar"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/x%2Fabc", "http://example/x/y%2Fz", "http://example/x%2Fabc"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/x%2Fabc", "http://example/x/y/z", "http://example/x%2Fabc"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("/x%2Fabc", "http://example/x/y%2Fz", "http://example/x%2Fabc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("abc", "http://example/x/y%2Fz", "http://example/x/abc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../../x%2Fabc", "http://example/a/x/y/z", "http://example/a/x%2Fabc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../x%2Fabc", "http://example/a/x/y%2Fz", "http://example/a/x%2Fabc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("abc", "http://example/x%2Fy/z", "http://example/x%2Fy/abc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("q%3Ar", "http://ex/x/y", "http://ex/x/q%3Ar"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/x%2Fabc", "http://example/x/y%2Fz", "http://example/x%2Fabc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/x%2Fabc", "http://example/x/y/z", "http://example/x%2Fabc"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("/x%2Fabc", "http://example/x/y%2Fz", "http://example/x%2Fabc"));
// 70-77
- TEST_ASSERT(testAddOrRemoveBaseHelper("local2@domain2", "mailto:local1@domain1?query1", "mailto:local2@domain2"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("local2@domain2?query2", "mailto:local1@domain1", "mailto:local2@domain2?query2"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("local2@domain2?query2", "mailto:local1@domain1?query1", "mailto:local2@domain2?query2"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("?query2", "mailto:local@domain?query1", "mailto:local@domain?query2"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("local@domain?query2", "mailto:?query1", "mailto:local@domain?query2"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("?query2", "mailto:local@domain?query1", "mailto:local@domain?query2"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("http://example/a/b?c/../d", "foo:bar", "http://example/a/b?c/../d"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("http://example/a/b#c/../d", "foo:bar", "http://example/a/b#c/../d"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("local2@domain2", "mailto:local1@domain1?query1", "mailto:local2@domain2"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("local2@domain2?query2", "mailto:local1@domain1", "mailto:local2@domain2?query2"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("local2@domain2?query2", "mailto:local1@domain1?query1", "mailto:local2@domain2?query2"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("?query2", "mailto:local@domain?query1", "mailto:local@domain?query2"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("local@domain?query2", "mailto:?query1", "mailto:local@domain?query2"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("?query2", "mailto:local@domain?query1", "mailto:local@domain?query2"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("http://example/a/b?c/../d", "foo:bar", "http://example/a/b?c/../d"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("http://example/a/b#c/../d", "foo:bar", "http://example/a/b#c/../d"));
// 82-88
- TEST_ASSERT(testAddOrRemoveBaseHelper("http:this", "http://example.org/base/uri", "http:this"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("http:this", "http:base", "http:this"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("http:this", "http://example.org/base/uri", "http:this"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("http:this", "http:base", "http:this"));
// Whole in the URI spec, see http://lists.w3.org/Archives/Public/uri/2007Aug/0003.html
- // TEST_ASSERT(testAddOrRemoveBaseHelper(".//g", "f:/a", "f://g")); // ORIGINAL
- TEST_ASSERT(testAddOrRemoveBaseHelper(".//g", "f:/a", "f:/.//g")); // FIXED ONE
- TEST_ASSERT(testAddOrRemoveBaseHelper("b/c//d/e", "f://example.org/base/a", "f://example.org/base/b/c//d/e"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("m2@example.ord/c2@example.org", "mid:m@example.ord/c@example.org", "mid:m@example.ord/m2@example.ord/c2@example.org"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("mini1.xml", "file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/", "file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/mini1.xml"));
- TEST_ASSERT(testAddOrRemoveBaseHelper("../b/c", "foo:a/y/z", "foo:a/b/c"));
+ // ASSERT_TRUE(testAddOrRemoveBaseHelper(".//g", "f:/a", "f://g")); // ORIGINAL
+ ASSERT_TRUE(testAddOrRemoveBaseHelper(".//g", "f:/a", "f:/.//g")); // FIXED ONE
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("b/c//d/e", "f://example.org/base/a", "f://example.org/base/b/c//d/e"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("m2@example.ord/c2@example.org", "mid:m@example.ord/c@example.org", "mid:m@example.ord/m2@example.ord/c2@example.org"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("mini1.xml", "file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/", "file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/mini1.xml"));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("../b/c", "foo:a/y/z", "foo:a/b/c"));
}
-void FourSuite::relativize_test_cases() {
+TEST(FourSuite, RelativizeTestCases) {
const bool REMOVE_MODE = false;
const bool DOMAIN_ROOT_MODE = true;
// to convert, base, exptected
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/a/d", "b/c", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/b/b/c", "s://ex/a/d", "/b/b/c", REMOVE_MODE, DOMAIN_ROOT_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/a/b/", "c", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://other.ex/a/b/", "s://ex/a/d", "//other.ex/a/b/", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://other.ex/a/d", "//ex/a/b/c", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("t://ex/a/b/c", "s://ex/a/d", "t://ex/a/b/c", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b/c", "t://ex/a/d", "s://ex/a/b/c", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a", "s://ex/b/c/d", "/a", REMOVE_MODE, DOMAIN_ROOT_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/b/c/d", "s://ex/a", "b/c/d", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b/c?h", "s://ex/a/d?w", "b/c?h", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b/c#h", "s://ex/a/d#w", "b/c#h", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b/c?h#i", "s://ex/a/d?w#j", "b/c?h#i", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a#i", "s://ex/a", "#i", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a?i", "s://ex/a", "?i", REMOVE_MODE));
-
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b/", "s://ex/a/b/", "", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b", "s://ex/a/b", "", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/", "s://ex/", "", REMOVE_MODE));
-
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/a/d/c", "../b/c", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b/c/", "s://ex/a/d/c", "../b/c/", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b/c/d", "s://ex/a/d/c/d", "../../b/c/d", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/d/e/f", "/a/b/c", REMOVE_MODE, DOMAIN_ROOT_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b/", "s://ex/a/c/d/e", "../../b/", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/a/d", "b/c", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/b/b/c", "s://ex/a/d", "/b/b/c", REMOVE_MODE, DOMAIN_ROOT_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/a/b/", "c", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://other.ex/a/b/", "s://ex/a/d", "//other.ex/a/b/", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://other.ex/a/d", "//ex/a/b/c", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("t://ex/a/b/c", "s://ex/a/d", "t://ex/a/b/c", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "t://ex/a/d", "s://ex/a/b/c", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a", "s://ex/b/c/d", "/a", REMOVE_MODE, DOMAIN_ROOT_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/b/c/d", "s://ex/a", "b/c/d", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c?h", "s://ex/a/d?w", "b/c?h", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c#h", "s://ex/a/d#w", "b/c#h", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c?h#i", "s://ex/a/d?w#j", "b/c?h#i", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a#i", "s://ex/a", "#i", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a?i", "s://ex/a", "?i", REMOVE_MODE));
+
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/", "s://ex/a/b/", "", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b", "s://ex/a/b", "", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/", "s://ex/", "", REMOVE_MODE));
+
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/a/d/c", "../b/c", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c/", "s://ex/a/d/c", "../b/c/", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c/d", "s://ex/a/d/c/d", "../../b/c/d", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/c", "s://ex/d/e/f", "/a/b/c", REMOVE_MODE, DOMAIN_ROOT_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b/", "s://ex/a/c/d/e", "../../b/", REMOVE_MODE));
// Some tests to ensure that empty path segments don't cause problems.
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/b", "s://ex/a//b/c", "../../b", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a///b", "s://ex/a/", ".///b", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a/", "s://ex/a///b", "../../", REMOVE_MODE));
- TEST_ASSERT(testAddOrRemoveBaseHelper("s://ex/a//b/c", "s://ex/a/b", ".//b/c", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/b", "s://ex/a//b/c", "../../b", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a///b", "s://ex/a/", ".///b", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a/", "s://ex/a///b", "../../", REMOVE_MODE));
+ ASSERT_TRUE(testAddOrRemoveBaseHelper("s://ex/a//b/c", "s://ex/a/b", ".//b/c", REMOVE_MODE));
}
+namespace {
-int FourSuite::testParseUri(const char * uriText, const char ** expectedErrorPos) {
+int testParseUri(const char * uriText, const char ** expectedErrorPos = NULL) {
UriParserStateA state;
UriUriA uri;
state.uri = &uri;
@@ -402,13 +405,13 @@ int FourSuite::testParseUri(const char * uriText, const char ** expectedErrorPos
-bool FourSuite::testGoodUri(const char * uriText) {
+bool testGoodUri(const char * uriText) {
return (testParseUri(uriText) == 0);
}
-bool FourSuite::testBadUri(const char * uriText, int expectedErrorOffset) {
+bool testBadUri(const char * uriText, int expectedErrorOffset = -1) {
const char * errorPos = NULL;
const int ret = testParseUri(uriText, &errorPos);
return ((ret == URI_ERROR_SYNTAX)
@@ -419,143 +422,147 @@ bool FourSuite::testBadUri(const char * uriText, int expectedErrorOffset) {
));
}
+} // namespace
-void FourSuite::good_URI_references() {
- TEST_ASSERT(testGoodUri("file:///foo/bar"));
- TEST_ASSERT(testGoodUri("mailto:user@host?subject=blah"));
- TEST_ASSERT(testGoodUri("dav:")); // empty opaque part / rel-path allowed by RFC 2396bis
- TEST_ASSERT(testGoodUri("about:")); // empty opaque part / rel-path allowed by RFC 2396bis
+
+TEST(FourSuite, GoodUriReferences) {
+ ASSERT_TRUE(testGoodUri("file:///foo/bar"));
+ ASSERT_TRUE(testGoodUri("mailto:user@host?subject=blah"));
+ ASSERT_TRUE(testGoodUri("dav:")); // empty opaque part / rel-path allowed by RFC 2396bis
+ ASSERT_TRUE(testGoodUri("about:")); // empty opaque part / rel-path allowed by RFC 2396bis
// the following test cases are from a Perl script by David A. Wheeler
// at http://www.dwheeler.com/secure-programs/url.pl
- TEST_ASSERT(testGoodUri("http://www.yahoo.com"));
- TEST_ASSERT(testGoodUri("http://www.yahoo.com/"));
- TEST_ASSERT(testGoodUri("http://1.2.3.4/"));
- TEST_ASSERT(testGoodUri("http://www.yahoo.com/stuff"));
- TEST_ASSERT(testGoodUri("http://www.yahoo.com/stuff/"));
- TEST_ASSERT(testGoodUri("http://www.yahoo.com/hello%20world/"));
- TEST_ASSERT(testGoodUri("http://www.yahoo.com?name=obi"));
- TEST_ASSERT(testGoodUri("http://www.yahoo.com?name=obi+wan&status=jedi"));
- TEST_ASSERT(testGoodUri("http://www.yahoo.com?onery"));
- TEST_ASSERT(testGoodUri("http://www.yahoo.com#bottom"));
- TEST_ASSERT(testGoodUri("http://www.yahoo.com/yelp.html#bottom"));
- TEST_ASSERT(testGoodUri("https://www.yahoo.com/"));
- TEST_ASSERT(testGoodUri("ftp://www.yahoo.com/"));
- TEST_ASSERT(testGoodUri("ftp://www.yahoo.com/hello"));
- TEST_ASSERT(testGoodUri("demo.txt"));
- TEST_ASSERT(testGoodUri("demo/hello.txt"));
- TEST_ASSERT(testGoodUri("demo/hello.txt?query=hello#fragment"));
- TEST_ASSERT(testGoodUri("/cgi-bin/query?query=hello#fragment"));
- TEST_ASSERT(testGoodUri("/demo.txt"));
- TEST_ASSERT(testGoodUri("/hello/demo.txt"));
- TEST_ASSERT(testGoodUri("hello/demo.txt"));
- TEST_ASSERT(testGoodUri("/"));
- TEST_ASSERT(testGoodUri(""));
- TEST_ASSERT(testGoodUri("#"));
- TEST_ASSERT(testGoodUri("#here"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/"));
+ ASSERT_TRUE(testGoodUri("http://1.2.3.4/"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/stuff"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/stuff/"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/hello%20world/"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=obi"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=obi+wan&status=jedi"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com?onery"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com#bottom"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/yelp.html#bottom"));
+ ASSERT_TRUE(testGoodUri("https://www.yahoo.com/"));
+ ASSERT_TRUE(testGoodUri("ftp://www.yahoo.com/"));
+ ASSERT_TRUE(testGoodUri("ftp://www.yahoo.com/hello"));
+ ASSERT_TRUE(testGoodUri("demo.txt"));
+ ASSERT_TRUE(testGoodUri("demo/hello.txt"));
+ ASSERT_TRUE(testGoodUri("demo/hello.txt?query=hello#fragment"));
+ ASSERT_TRUE(testGoodUri("/cgi-bin/query?query=hello#fragment"));
+ ASSERT_TRUE(testGoodUri("/demo.txt"));
+ ASSERT_TRUE(testGoodUri("/hello/demo.txt"));
+ ASSERT_TRUE(testGoodUri("hello/demo.txt"));
+ ASSERT_TRUE(testGoodUri("/"));
+ ASSERT_TRUE(testGoodUri(""));
+ ASSERT_TRUE(testGoodUri("#"));
+ ASSERT_TRUE(testGoodUri("#here"));
// Wheeler's script says these are invalid, but they aren't
- TEST_ASSERT(testGoodUri("http://www.yahoo.com?name=%00%01"));
- TEST_ASSERT(testGoodUri("http://www.yaho%6f.com"));
- TEST_ASSERT(testGoodUri("http://www.yahoo.com/hello%00world/"));
- TEST_ASSERT(testGoodUri("http://www.yahoo.com/hello+world/"));
- TEST_ASSERT(testGoodUri("http://www.yahoo.com?name=obi&"));
- TEST_ASSERT(testGoodUri("http://www.yahoo.com?name=obi&type="));
- TEST_ASSERT(testGoodUri("http://www.yahoo.com/yelp.html#"));
- TEST_ASSERT(testGoodUri("//"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=%00%01"));
+ ASSERT_TRUE(testGoodUri("http://www.yaho%6f.com"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/hello%00world/"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/hello+world/"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=obi&"));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com?name=obi&type="));
+ ASSERT_TRUE(testGoodUri("http://www.yahoo.com/yelp.html#"));
+ ASSERT_TRUE(testGoodUri("//"));
// the following test cases are from a Haskell program by Graham Klyne
// at http://www.ninebynine.org/Software/HaskellUtils/Network/URITest.hs
- TEST_ASSERT(testGoodUri("http://example.org/aaa/bbb#ccc"));
- TEST_ASSERT(testGoodUri("mailto:local@domain.org"));
- TEST_ASSERT(testGoodUri("mailto:local@domain.org#frag"));
- TEST_ASSERT(testGoodUri("HTTP://EXAMPLE.ORG/AAA/BBB#CCC"));
- TEST_ASSERT(testGoodUri("//example.org/aaa/bbb#ccc"));
- TEST_ASSERT(testGoodUri("/aaa/bbb#ccc"));
- TEST_ASSERT(testGoodUri("bbb#ccc"));
- TEST_ASSERT(testGoodUri("#ccc"));
- TEST_ASSERT(testGoodUri("#"));
- TEST_ASSERT(testGoodUri("A'C"));
+ ASSERT_TRUE(testGoodUri("http://example.org/aaa/bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("mailto:local@domain.org"));
+ ASSERT_TRUE(testGoodUri("mailto:local@domain.org#frag"));
+ ASSERT_TRUE(testGoodUri("HTTP://EXAMPLE.ORG/AAA/BBB#CCC"));
+ ASSERT_TRUE(testGoodUri("//example.org/aaa/bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("/aaa/bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("#ccc"));
+ ASSERT_TRUE(testGoodUri("#"));
+ ASSERT_TRUE(testGoodUri("A'C"));
// escapes
- TEST_ASSERT(testGoodUri("http://example.org/aaa%2fbbb#ccc"));
- TEST_ASSERT(testGoodUri("http://example.org/aaa%2Fbbb#ccc"));
- TEST_ASSERT(testGoodUri("%2F"));
- TEST_ASSERT(testGoodUri("aaa%2Fbbb"));
+ ASSERT_TRUE(testGoodUri("http://example.org/aaa%2fbbb#ccc"));
+ ASSERT_TRUE(testGoodUri("http://example.org/aaa%2Fbbb#ccc"));
+ ASSERT_TRUE(testGoodUri("%2F"));
+ ASSERT_TRUE(testGoodUri("aaa%2Fbbb"));
// ports
- TEST_ASSERT(testGoodUri("http://example.org:80/aaa/bbb#ccc"));
- TEST_ASSERT(testGoodUri("http://example.org:/aaa/bbb#ccc"));
- TEST_ASSERT(testGoodUri("http://example.org./aaa/bbb#ccc"));
- TEST_ASSERT(testGoodUri("http://example.123./aaa/bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("http://example.org:80/aaa/bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("http://example.org:/aaa/bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("http://example.org./aaa/bbb#ccc"));
+ ASSERT_TRUE(testGoodUri("http://example.123./aaa/bbb#ccc"));
// bare authority
- TEST_ASSERT(testGoodUri("http://example.org"));
+ ASSERT_TRUE(testGoodUri("http://example.org"));
// IPv6 literals (from RFC2732):
- TEST_ASSERT(testGoodUri("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html"));
- TEST_ASSERT(testGoodUri("http://[1080:0:0:0:8:800:200C:417A]/index.html"));
- TEST_ASSERT(testGoodUri("http://[3ffe:2a00:100:7031::1]"));
- TEST_ASSERT(testGoodUri("http://[1080::8:800:200C:417A]/foo"));
- TEST_ASSERT(testGoodUri("http://[::192.9.5.5]/ipng"));
- TEST_ASSERT(testGoodUri("http://[::FFFF:129.144.52.38]:80/index.html"));
- TEST_ASSERT(testGoodUri("http://[2010:836B:4179::836B:4179]"));
- TEST_ASSERT(testGoodUri("//[2010:836B:4179::836B:4179]"));
+ ASSERT_TRUE(testGoodUri("http://[FEDC:BA98:7654:3210:FEDC:BA98:7654:3210]:80/index.html"));
+ ASSERT_TRUE(testGoodUri("http://[1080:0:0:0:8:800:200C:417A]/index.html"));
+ ASSERT_TRUE(testGoodUri("http://[3ffe:2a00:100:7031::1]"));
+ ASSERT_TRUE(testGoodUri("http://[1080::8:800:200C:417A]/foo"));
+ ASSERT_TRUE(testGoodUri("http://[::192.9.5.5]/ipng"));
+ ASSERT_TRUE(testGoodUri("http://[::FFFF:129.144.52.38]:80/index.html"));
+ ASSERT_TRUE(testGoodUri("http://[2010:836B:4179::836B:4179]"));
+ ASSERT_TRUE(testGoodUri("//[2010:836B:4179::836B:4179]"));
// Random other things that crop up
- TEST_ASSERT(testGoodUri("http://example/Andr&#567;"));
- TEST_ASSERT(testGoodUri("file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/"));
+ ASSERT_TRUE(testGoodUri("http://example/Andr&#567;"));
+ ASSERT_TRUE(testGoodUri("file:///C:/DEV/Haskell/lib/HXmlToolbox-3.01/examples/"));
}
-void FourSuite::bad_URI_references() {
- TEST_ASSERT(testBadUri("beepbeep\x07\x07", 8));
- TEST_ASSERT(testBadUri("\n", 0));
- TEST_ASSERT(testBadUri("::", 0)); // not OK, per Roy Fielding on the W3C uri list on 2004-04-01
+TEST(FourSuite, BadUriReferences) {
+ ASSERT_TRUE(testBadUri("beepbeep\x07\x07", 8));
+ ASSERT_TRUE(testBadUri("\n", 0));
+ ASSERT_TRUE(testBadUri("::", 0)); // not OK, per Roy Fielding on the W3C uri list on 2004-04-01
// the following test cases are from a Perl script by David A. Wheeler
// at http://www.dwheeler.com/secure-programs/url.pl
- TEST_ASSERT(testBadUri("http://www yahoo.com", 10));
- TEST_ASSERT(testBadUri("http://www.yahoo.com/hello world/", 26));
- TEST_ASSERT(testBadUri("http://www.yahoo.com/yelp.html#\"", 31));
+ ASSERT_TRUE(testBadUri("http://www yahoo.com", 10));
+ ASSERT_TRUE(testBadUri("http://www.yahoo.com/hello world/", 26));
+ ASSERT_TRUE(testBadUri("http://www.yahoo.com/yelp.html#\"", 31));
// the following test cases are from a Haskell program by Graham Klyne
// at http://www.ninebynine.org/Software/HaskellUtils/Network/URITest.hs
- TEST_ASSERT(testBadUri("[2010:836B:4179::836B:4179]", 0));
- TEST_ASSERT(testBadUri(" ", 0));
- TEST_ASSERT(testBadUri("%", 1));
- TEST_ASSERT(testBadUri("A%Z", 2));
- TEST_ASSERT(testBadUri("%ZZ", 1));
- TEST_ASSERT(testBadUri("%AZ", 2));
- TEST_ASSERT(testBadUri("A C", 1));
- TEST_ASSERT(testBadUri("A\\'C", 1)); // r"A\'C"
- TEST_ASSERT(testBadUri("A`C", 1));
- TEST_ASSERT(testBadUri("A<C", 1));
- TEST_ASSERT(testBadUri("A>C", 1));
- TEST_ASSERT(testBadUri("A^C", 1));
- TEST_ASSERT(testBadUri("A\\\\C", 1)); // r'A\\C'
- TEST_ASSERT(testBadUri("A{C", 1));
- TEST_ASSERT(testBadUri("A|C", 1));
- TEST_ASSERT(testBadUri("A}C", 1));
- TEST_ASSERT(testBadUri("A[C", 1));
- TEST_ASSERT(testBadUri("A]C", 1));
- TEST_ASSERT(testBadUri("A[**]C", 1));
- TEST_ASSERT(testBadUri("http://[xyz]/", 8));
- TEST_ASSERT(testBadUri("http://]/", 7));
- TEST_ASSERT(testBadUri("http://example.org/[2010:836B:4179::836B:4179]", 19));
- TEST_ASSERT(testBadUri("http://example.org/abc#[2010:836B:4179::836B:4179]", 23));
- TEST_ASSERT(testBadUri("http://example.org/xxx/[qwerty]#a[b]", 23));
+ ASSERT_TRUE(testBadUri("[2010:836B:4179::836B:4179]", 0));
+ ASSERT_TRUE(testBadUri(" ", 0));
+ ASSERT_TRUE(testBadUri("%", 1));
+ ASSERT_TRUE(testBadUri("A%Z", 2));
+ ASSERT_TRUE(testBadUri("%ZZ", 1));
+ ASSERT_TRUE(testBadUri("%AZ", 2));
+ ASSERT_TRUE(testBadUri("A C", 1));
+ ASSERT_TRUE(testBadUri("A\\'C", 1)); // r"A\'C"
+ ASSERT_TRUE(testBadUri("A`C", 1));
+ ASSERT_TRUE(testBadUri("A<C", 1));
+ ASSERT_TRUE(testBadUri("A>C", 1));
+ ASSERT_TRUE(testBadUri("A^C", 1));
+ ASSERT_TRUE(testBadUri("A\\\\C", 1)); // r'A\\C'
+ ASSERT_TRUE(testBadUri("A{C", 1));
+ ASSERT_TRUE(testBadUri("A|C", 1));
+ ASSERT_TRUE(testBadUri("A}C", 1));
+ ASSERT_TRUE(testBadUri("A[C", 1));
+ ASSERT_TRUE(testBadUri("A]C", 1));
+ ASSERT_TRUE(testBadUri("A[**]C", 1));
+ ASSERT_TRUE(testBadUri("http://[xyz]/", 8));
+ ASSERT_TRUE(testBadUri("http://]/", 7));
+ ASSERT_TRUE(testBadUri("http://example.org/[2010:836B:4179::836B:4179]", 19));
+ ASSERT_TRUE(testBadUri("http://example.org/abc#[2010:836B:4179::836B:4179]", 23));
+ ASSERT_TRUE(testBadUri("http://example.org/xxx/[qwerty]#a[b]", 23));
// from a post to the W3C uri list on 2004-02-17
// breaks at 22 instead of 17 because everything up to that point is a valid userinfo
- TEST_ASSERT(testBadUri("http://w3c.org:80path1/path2", 22));
+ ASSERT_TRUE(testBadUri("http://w3c.org:80path1/path2", 22));
}
-bool FourSuite::normalizeAndCompare(const char * uriText,
+namespace {
+
+bool normalizeAndCompare(const char * uriText,
const char * expectedNormalized) {
UriParserStateA stateA;
int res;
@@ -591,33 +598,35 @@ bool FourSuite::normalizeAndCompare(const char * uriText,
return equalAfter;
}
+} // namespace
+
-void FourSuite::caseNormalizationTests() {
- TEST_ASSERT(normalizeAndCompare("HTTP://www.EXAMPLE.com/", "http://www.example.com/"));
- TEST_ASSERT(normalizeAndCompare("example://A/b/c/%7bfoo%7d", "example://a/b/c/%7Bfoo%7D"));
+TEST(FourSuite, CaseNormalizationTests) {
+ ASSERT_TRUE(normalizeAndCompare("HTTP://www.EXAMPLE.com/", "http://www.example.com/"));
+ ASSERT_TRUE(normalizeAndCompare("example://A/b/c/%7bfoo%7d", "example://a/b/c/%7Bfoo%7D"));
}
-void FourSuite::pctEncNormalizationTests() {
- TEST_ASSERT(normalizeAndCompare("http://host/%7Euser/x/y/z", "http://host/~user/x/y/z"));
- TEST_ASSERT(normalizeAndCompare("http://host/%7euser/x/y/z", "http://host/~user/x/y/z"));
+TEST(FourSuite, PctEncNormalizationTests) {
+ ASSERT_TRUE(normalizeAndCompare("http://host/%7Euser/x/y/z", "http://host/~user/x/y/z"));
+ ASSERT_TRUE(normalizeAndCompare("http://host/%7euser/x/y/z", "http://host/~user/x/y/z"));
}
-void FourSuite::pathSegmentNormalizationTests() {
- TEST_ASSERT(normalizeAndCompare("/a/b/../../c", "/c"));
- // TEST_ASSERT(normalizeAndCompare("a/b/../../c", "a/b/../../c"));
+TEST(FourSuite, PathSegmentNormalizationTests) {
+ ASSERT_TRUE(normalizeAndCompare("/a/b/../../c", "/c"));
+ // ASSERT_TRUE(normalizeAndCompare("a/b/../../c", "a/b/../../c"));
// Fixed:
- TEST_ASSERT(normalizeAndCompare("a/b/../../c", "c"));
- TEST_ASSERT(normalizeAndCompare("/a/b/././c", "/a/b/c"));
- // TEST_ASSERT(normalizeAndCompare("a/b/././c", "a/b/././c"));
+ ASSERT_TRUE(normalizeAndCompare("a/b/../../c", "c"));
+ ASSERT_TRUE(normalizeAndCompare("/a/b/././c", "/a/b/c"));
+ // ASSERT_TRUE(normalizeAndCompare("a/b/././c", "a/b/././c"));
// Fixed:
- TEST_ASSERT(normalizeAndCompare("a/b/././c", "a/b/c"));
- TEST_ASSERT(normalizeAndCompare("/a/b/../c/././d", "/a/c/d"));
- // TEST_ASSERT(normalizeAndCompare("a/b/../c/././d", "a/b/../c/././d"));
+ ASSERT_TRUE(normalizeAndCompare("a/b/././c", "a/b/c"));
+ ASSERT_TRUE(normalizeAndCompare("/a/b/../c/././d", "/a/c/d"));
+ // ASSERT_TRUE(normalizeAndCompare("a/b/../c/././d", "a/b/../c/././d"));
// Fixed:
- TEST_ASSERT(normalizeAndCompare("a/b/../c/././d", "a/c/d"));
+ ASSERT_TRUE(normalizeAndCompare("a/b/../c/././d", "a/c/d"));
}
diff --git a/test/FourSuite.h b/test/FourSuite.h
deleted file mode 100644
index 9a33c16..0000000
--- a/test/FourSuite.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * uriparser - RFC 3986 URI parsing library
- *
- * Copyright (C) 2007, Weijia Song <songweijia@gmail.com>
- * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef TEST_FOUR_SUITE_H
-#define TEST_FOUR_SUITE_H 1
-
-
-
-#include <cpptest.h>
-
-using namespace Test;
-
-
-
-class FourSuite : public Suite {
-
-public:
- FourSuite() {
- TEST_ADD(FourSuite::absolutize_test_cases)
- TEST_ADD(FourSuite::relativize_test_cases)
- TEST_ADD(FourSuite::good_URI_references)
- TEST_ADD(FourSuite::bad_URI_references)
- TEST_ADD(FourSuite::caseNormalizationTests)
- TEST_ADD(FourSuite::pctEncNormalizationTests)
- TEST_ADD(FourSuite::pathSegmentNormalizationTests)
- }
-
-private:
- bool testAddOrRemoveBaseHelper(const char * ref,
- const char * base, const char * expected, bool add = true,
- bool domainRootMode = false);
-
- void absolutize_test_cases();
- void relativize_test_cases();
-
- int testParseUri(const char * uriText, const char ** expectedErrorPos = NULL);
- bool testGoodUri(const char * uriText);
- bool testBadUri(const char * uriText, int expectedErrorOffset = -1);
- void good_URI_references();
- void bad_URI_references();
-
- bool normalizeAndCompare(const char * uriText,
- const char * expectedNormalized);
- void caseNormalizationTests();
- void pctEncNormalizationTests();
- void pathSegmentNormalizationTests();
-
-};
-
-
-
-#endif // TEST_FOUR_SUITE_H
diff --git a/test/MemoryManagerSuite.cpp b/test/MemoryManagerSuite.cpp
new file mode 100644
index 0000000..85f498b
--- /dev/null
+++ b/test/MemoryManagerSuite.cpp
@@ -0,0 +1,376 @@
+/*
+ * uriparser - RFC 3986 URI parsing library
+ *
+ * Copyright (C) 2007, Weijia Song <songweijia@gmail.com>
+ * Copyright (C) 2007, Sebastian Pipping <sebastian@pipping.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <cassert>
+#include <cerrno>
+#include <cstring> // memcpy
+#include <gtest/gtest.h>
+
+#include <uriparser/Uri.h>
+#include "../src/UriMemory.h"
+
+
+namespace {
+
+class CallCountLog {
+public:
+ unsigned int callCountFree;
+
+ CallCountLog() : callCountFree(0) {
+ // no-op
+ }
+};
+
+
+
+static void * failingMalloc(UriMemoryManager * URI_UNUSED(memory),
+ size_t URI_UNUSED(size)) {
+ return NULL;
+}
+
+
+
+static void * failingCalloc(UriMemoryManager * URI_UNUSED(memory),
+ size_t URI_UNUSED(nmemb), size_t URI_UNUSED(size)) {
+ return NULL;
+}
+
+
+
+static void * failingRealloc(UriMemoryManager * URI_UNUSED(memory),
+ void * URI_UNUSED(ptr), size_t URI_UNUSED(size)) {
+ return NULL;
+}
+
+
+
+static void * failingReallocarray(UriMemoryManager * URI_UNUSED(memory),
+ void * URI_UNUSED(ptr), size_t URI_UNUSED(nmemb),
+ size_t URI_UNUSED(size)) {
+ return NULL;
+}
+
+
+
+static void countingFree(UriMemoryManager * memory, void * ptr) {
+ static_cast<CallCountLog *>(memory->userData)->callCountFree++;
+ free(ptr);
+}
+
+
+
+class FailingMemoryManager {
+private:
+ UriMemoryManager memoryManager;
+ CallCountLog callCountLog;
+
+public:
+ FailingMemoryManager() {
+ this->memoryManager.malloc = failingMalloc;
+ this->memoryManager.calloc = failingCalloc;
+ this->memoryManager.realloc = failingRealloc;
+ this->memoryManager.reallocarray = failingReallocarray;
+ this->memoryManager.free = countingFree;
+ this->memoryManager.userData = &(this->callCountLog);
+ }
+
+ UriMemoryManager * operator&() {
+ return &(this->memoryManager);
+ }
+
+ unsigned int getCallCountFree() const {
+ return this->callCountLog.callCountFree;
+ }
+};
+
+
+
+static UriUriA parse(const char * sourceUriString) {
+ UriParserStateA state;
+ UriUriA uri;
+ state.uri = &uri;
+ assert(uriParseUriA(&state, sourceUriString) == URI_SUCCESS);
+ return uri;
+}
+
+
+
+static UriQueryListA * parseQueryList(const char * queryString) {
+ UriQueryListA * queryList;
+ const char * const first = queryString;
+ const char * const afterLast = first + strlen(first);
+ assert(uriDissectQueryMallocA(&queryList, NULL, first, afterLast)
+ == URI_SUCCESS);
+ return queryList;
+}
+
+} // namespace
+
+
+
+TEST(MemoryManagerCompletenessSuite, AllFunctionMembersRequired) {
+ UriUriA uri = parse("whatever");
+ UriMemoryManager memory;
+
+ memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
+ memory.malloc = NULL;
+ ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
+ URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
+
+ memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
+ memory.calloc = NULL;
+ ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
+ URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
+
+ memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
+ memory.realloc = NULL;
+ ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
+ URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
+
+ memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
+ memory.reallocarray = NULL;
+ ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
+ URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
+
+ memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
+ memory.free = NULL;
+ ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory),
+ URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
+
+ memcpy(&memory, &defaultMemoryManager, sizeof(UriMemoryManager));
+ ASSERT_EQ(uriFreeUriMembersMmA(&uri, &memory), URI_SUCCESS);
+}
+
+
+
+TEST(MemoryManagerCompletenessSuite, MallocAndFreeRequiredOnly) {
+ UriMemoryManager memory;
+ UriMemoryManager backend;
+
+ memcpy(&backend, &defaultMemoryManager, sizeof(UriMemoryManager));
+ backend.malloc = NULL;
+ ASSERT_EQ(uriCompleteMemoryManager(&memory, &backend),
+ URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
+
+ memcpy(&backend, &defaultMemoryManager, sizeof(UriMemoryManager));
+ backend.free = NULL;
+ ASSERT_EQ(uriCompleteMemoryManager(&memory, &backend),
+ URI_ERROR_MEMORY_MANAGER_INCOMPLETE);
+}
+
+
+
+TEST(MemoryManagerTestingSuite, DefaultMemoryManager) {
+ ASSERT_EQ(uriTestMemoryManager(&defaultMemoryManager), URI_SUCCESS);
+}
+
+
+
+TEST(MemoryManagerTestingSuite, CompleteMemoryManager) {
+ UriMemoryManager memory;
+ UriMemoryManager backend;
+
+ memset(&backend, 0, sizeof(UriMemoryManager));
+ backend.malloc = defaultMemoryManager.malloc;
+ backend.free = defaultMemoryManager.free;
+
+ ASSERT_EQ(uriCompleteMemoryManager(&memory, &backend),
+ URI_SUCCESS);
+
+ ASSERT_EQ(uriTestMemoryManager(&memory), URI_SUCCESS);
+}
+
+
+
+TEST(MemoryManagerTestingSuite, EmulateCalloc) {
+ UriMemoryManager partialEmulationMemoryManager;
+ memcpy(&partialEmulationMemoryManager, &defaultMemoryManager,
+ sizeof(UriMemoryManager));
+ partialEmulationMemoryManager.calloc = uriEmulateCalloc;
+
+ ASSERT_EQ(uriTestMemoryManager(&partialEmulationMemoryManager),
+ URI_SUCCESS);
+}
+
+
+
+TEST(MemoryManagerTestingSuite, EmulateReallocarray) {
+ UriMemoryManager partialEmulationMemoryManager;
+ memcpy(&partialEmulationMemoryManager, &defaultMemoryManager,
+ sizeof(UriMemoryManager));
+ partialEmulationMemoryManager.reallocarray = uriEmulateReallocarray;
+
+ ASSERT_EQ(uriTestMemoryManager(&partialEmulationMemoryManager),
+ URI_SUCCESS);
+}
+
+
+
+TEST(MemoryManagerTestingOverflowDetectionSuite, EmulateCalloc) {
+ EXPECT_GT(2 * sizeof(size_t), sizeof(void *));
+
+ errno = 0;
+ ASSERT_EQ(NULL, uriEmulateCalloc(
+ &defaultMemoryManager, (size_t)-1, (size_t)-1));
+ ASSERT_EQ(errno, ENOMEM);
+}
+
+
+
+TEST(MemoryManagerTestingOverflowDetectionSuite, EmulateReallocarray) {
+ EXPECT_GT(2 * sizeof(size_t), sizeof(void *));
+
+ errno = 0;
+ ASSERT_EQ(NULL, uriEmulateReallocarray(
+ &defaultMemoryManager, NULL, (size_t)-1, (size_t)-1));
+ ASSERT_EQ(errno, ENOMEM);
+}
+
+
+
+TEST(MemoryManagerTestingSuite, EmulateCallocAndReallocarray) {
+ UriMemoryManager partialEmulationMemoryManager;
+ memcpy(&partialEmulationMemoryManager, &defaultMemoryManager,
+ sizeof(UriMemoryManager));
+ partialEmulationMemoryManager.calloc = uriEmulateCalloc;
+ partialEmulationMemoryManager.reallocarray = uriEmulateReallocarray;
+
+ ASSERT_EQ(uriTestMemoryManager(&partialEmulationMemoryManager),
+ URI_SUCCESS);
+}
+
+
+
+TEST(FailingMemoryManagerSuite, AddBaseUriExMm) {
+ UriUriA absoluteDest;
+ UriUriA relativeSource = parse("foo");
+ UriUriA absoluteBase = parse("http://example.org/bar");
+ const UriResolutionOptions options = URI_RESOLVE_STRICTLY;
+ FailingMemoryManager failingMemoryManager;
+
+ ASSERT_EQ(uriAddBaseUriExMmA(&absoluteDest, &relativeSource,
+ &absoluteBase, options, &failingMemoryManager),
+ URI_ERROR_MALLOC);
+
+ uriFreeUriMembersA(&relativeSource);
+ uriFreeUriMembersA(&absoluteBase);
+}
+
+
+
+TEST(FailingMemoryManagerSuite, ComposeQueryMallocExMm) {
+ char * dest = NULL;
+ UriQueryListA * const queryList = parseQueryList("k1=v1");
+ UriBool spaceToPlus = URI_TRUE; // not of interest
+ UriBool normalizeBreaks = URI_TRUE; // not of interest
+ FailingMemoryManager failingMemoryManager;
+
+ ASSERT_EQ(uriComposeQueryMallocExMmA(&dest, queryList,
+ spaceToPlus, normalizeBreaks, &failingMemoryManager),
+ URI_ERROR_MALLOC);
+
+ uriFreeQueryListA(queryList);
+}
+
+
+
+TEST(FailingMemoryManagerSuite, DissectQueryMallocExMm) {
+ UriQueryListA * queryList;
+ int itemCount;
+ const char * const first = "k1=v1&k2=v2";
+ const char * const afterLast = first + strlen(first);
+ const UriBool plusToSpace = URI_TRUE; // not of interest
+ const UriBreakConversion breakConversion = URI_BR_DONT_TOUCH; // not o. i.
+ FailingMemoryManager failingMemoryManager;
+
+ ASSERT_EQ(uriDissectQueryMallocExMmA(&queryList, &itemCount,
+ first, afterLast, plusToSpace, breakConversion,
+ &failingMemoryManager),
+ URI_ERROR_MALLOC);
+}
+
+
+
+TEST(FailingMemoryManagerSuite, FreeQueryListMm) {
+ UriQueryListA * const queryList = parseQueryList("k1=v1");
+ FailingMemoryManager failingMemoryManager;
+ ASSERT_EQ(failingMemoryManager.getCallCountFree(), 0);
+
+ uriFreeQueryListMmA(queryList, &failingMemoryManager);
+
+ ASSERT_GE(failingMemoryManager.getCallCountFree(), 1);
+}
+
+
+
+TEST(FailingMemoryManagerSuite, FreeUriMembersMm) {
+ UriUriA uri = parse("http://example.org/");
+ FailingMemoryManager failingMemoryManager;
+ ASSERT_EQ(failingMemoryManager.getCallCountFree(), 0);
+
+ uriFreeUriMembersMmA(&uri, &failingMemoryManager);
+
+ ASSERT_GE(failingMemoryManager.getCallCountFree(), 1);
+ uriFreeUriMembersA(&uri);
+}
+
+
+
+TEST(FailingMemoryManagerSuite, NormalizeSyntaxExMm) {
+ UriUriA uri = parse("hTTp://example.org/path");
+ const unsigned int mask = URI_NORMALIZE_SCHEME; // anything but URI_NORMALIZED
+ FailingMemoryManager failingMemoryManager;
+
+ ASSERT_EQ(uriNormalizeSyntaxExMmA(&uri, mask, &failingMemoryManager),
+ URI_ERROR_MALLOC);
+
+ uriFreeUriMembersA(&uri);
+}
+
+
+
+TEST(FailingMemoryManagerSuite, ParseSingleUriExMm) {
+ UriUriA uri;
+ const char * const first = "k1=v1&k2=v2";
+ const char * const afterLast = first + strlen(first);
+ FailingMemoryManager failingMemoryManager;
+
+ ASSERT_EQ(uriParseSingleUriExMmA(&uri, first, afterLast, NULL,
+ &failingMemoryManager),
+ URI_ERROR_MALLOC);
+}
+
+
+
+TEST(FailingMemoryManagerSuite, RemoveBaseUriMm) {
+ UriUriA dest;
+ UriUriA absoluteSource = parse("http://example.org/a/b/c/");
+ UriUriA absoluteBase = parse("http://example.org/a/");
+ const UriBool domainRootMode = URI_TRUE; // not of interest
+ FailingMemoryManager failingMemoryManager;
+
+ ASSERT_EQ(uriRemoveBaseUriMmA(&dest, &absoluteSource, &absoluteBase,
+ domainRootMode, &failingMemoryManager),
+ URI_ERROR_MALLOC);
+
+ uriFreeUriMembersA(&absoluteSource);
+ uriFreeUriMembersA(&absoluteBase);
+}
diff --git a/test/VersionSuite.cpp b/test/VersionSuite.cpp
index 1c2d072..fb28c15 100644
--- a/test/VersionSuite.cpp
+++ b/test/VersionSuite.cpp
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#include "VersionSuite.h"
+#include <gtest/gtest.h>
#ifndef _GNU_SOURCE
# define _GNU_SOURCE // for asprintf
@@ -30,12 +30,11 @@
#include <uriparser/UriBase.h>
-void VersionSuite::ensure_version_defines_in_sync() {
+TEST(VersionSuite, EnsureVersionDefinesInSync) {
char * INSIDE_VERSION = NULL;
const int bytes_printed = asprintf(&INSIDE_VERSION, "%d.%d.%d%s",
URI_VER_MAJOR, URI_VER_MINOR, URI_VER_RELEASE, URI_VER_SUFFIX_ANSI);
- TEST_ASSERT(bytes_printed != -1);
- printf("bytes_printed: %d\n", bytes_printed);
+ ASSERT_TRUE(bytes_printed != -1);
const bool equal = !strcmp(INSIDE_VERSION, PACKAGE_VERSION);
if (! equal) {
@@ -44,5 +43,5 @@ void VersionSuite::ensure_version_defines_in_sync() {
printf(" Header defines version: <%s>\n", INSIDE_VERSION);
}
free(INSIDE_VERSION);
- TEST_ASSERT(equal);
+ ASSERT_TRUE(equal);
}
diff --git a/test/VersionSuite.h b/test/VersionSuite.h
deleted file mode 100644
index f0276c5..0000000
--- a/test/VersionSuite.h
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * uriparser - RFC 3986 URI parsing library
- *
- * Copyright (C) 2014, Sebastian Pipping <sebastian@pipping.org>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef TEST_VERSION_TEST_H
-#define TEST_VERSION_TEST_H 1
-
-
-
-#include <cpptest.h>
-
-using namespace Test;
-
-
-
-class VersionSuite : public Suite {
-
-public:
- VersionSuite() {
- TEST_ADD(VersionSuite::ensure_version_defines_in_sync)
- }
-
-private:
- void ensure_version_defines_in_sync();
-
-};
-
-
-
-#endif // TEST_VERSION_TEST_H
diff --git a/test/config.h.in b/test/config.h.in
deleted file mode 100644
index b81315e..0000000
--- a/test/config.h.in
+++ /dev/null
@@ -1,64 +0,0 @@
-/* test/config.h.in. Generated from configure.ac by autoheader. */
-
-/* Define to 1 if you have the <dlfcn.h> header file. */
-#undef HAVE_DLFCN_H
-
-/* Define to 1 if you have the <inttypes.h> header file. */
-#undef HAVE_INTTYPES_H
-
-/* Define to 1 if you have the <memory.h> header file. */
-#undef HAVE_MEMORY_H
-
-/* Define to 1 if you have the <stdint.h> header file. */
-#undef HAVE_STDINT_H
-
-/* Define to 1 if you have the <stdlib.h> header file. */
-#undef HAVE_STDLIB_H
-
-/* Define to 1 if you have the <strings.h> header file. */
-#undef HAVE_STRINGS_H
-
-/* Define to 1 if you have the <string.h> header file. */
-#undef HAVE_STRING_H
-
-/* Define to 1 if you have the <sys/stat.h> header file. */
-#undef HAVE_SYS_STAT_H
-
-/* Define to 1 if you have the <sys/types.h> header file. */
-#undef HAVE_SYS_TYPES_H
-
-/* Define to 1 if you have the <unistd.h> header file. */
-#undef HAVE_UNISTD_H
-
-/* Define if your C runtime provides the wprintf function. */
-#undef HAVE_WPRINTF
-
-/* Define to the sub-directory where libtool stores uninstalled libraries. */
-#undef LT_OBJDIR
-
-/* Name of package */
-#undef PACKAGE
-
-/* Define to the address where bug reports for this package should be sent. */
-#undef PACKAGE_BUGREPORT
-
-/* Define to the full name of this package. */
-#undef PACKAGE_NAME
-
-/* Define to the full name and version of this package. */
-#undef PACKAGE_STRING
-
-/* Define to the one symbol short name of this package. */
-#undef PACKAGE_TARNAME
-
-/* Define to the home page for this package. */
-#undef PACKAGE_URL
-
-/* Define to the version of this package. */
-#undef PACKAGE_VERSION
-
-/* Define to 1 if you have the ANSI C header files. */
-#undef STDC_HEADERS
-
-/* Version number of package */
-#undef VERSION
diff --git a/test/test.cpp b/test/test.cpp
index 41e3912..78fd980 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -20,16 +20,12 @@
*/
#include <uriparser/Uri.h>
-#include <cpptest.h>
+#include <gtest/gtest.h>
#include <memory>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
-#include "FourSuite.h"
-#include "VersionSuite.h"
-
-using namespace Test;
using namespace std;
@@ -42,77 +38,15 @@ int uriCompareRangeA(const UriTextRangeA * a, const UriTextRangeA * b);
-#define URI_TEST_IP_FOUR_FAIL(x) TEST_ASSERT(URI_FALSE == uri_TESTING_ONLY_ParseIpFourA(x))
-#define URI_TEST_IP_FOUR_PASS(x) TEST_ASSERT(URI_TRUE == uri_TESTING_ONLY_ParseIpFourA(x))
+#define URI_TEST_IP_FOUR_FAIL(x) ASSERT_TRUE(URI_FALSE == uri_TESTING_ONLY_ParseIpFourA(x))
+#define URI_TEST_IP_FOUR_PASS(x) ASSERT_TRUE(URI_TRUE == uri_TESTING_ONLY_ParseIpFourA(x))
// Note the closing brackets! TODO
-#define URI_TEST_IP_SIX_FAIL(x) TEST_ASSERT(URI_FALSE == uri_TESTING_ONLY_ParseIpSixA(x "]"))
-#define URI_TEST_IP_SIX_PASS(x) TEST_ASSERT(URI_TRUE == uri_TESTING_ONLY_ParseIpSixA(x "]"))
-
-
-
-class UriSuite : public Suite {
-
-public:
- UriSuite() {
- TEST_ADD(UriSuite::testDistinction)
- TEST_ADD(UriSuite::testIpFour)
- TEST_ADD(UriSuite::testIpSixPass)
- TEST_ADD(UriSuite::testIpSixFail)
- TEST_ADD(UriSuite::testUri)
- TEST_ADD(UriSuite::testUriUserInfoHostPort1)
- TEST_ADD(UriSuite::testUriUserInfoHostPort2)
- TEST_ADD(UriSuite::testUriUserInfoHostPort22_Bug1948038)
- TEST_ADD(UriSuite::testUriUserInfoHostPort23_Bug3510198_1)
- TEST_ADD(UriSuite::testUriUserInfoHostPort23_Bug3510198_2)
- TEST_ADD(UriSuite::testUriUserInfoHostPort23_Bug3510198_3)
- TEST_ADD(UriSuite::testUriUserInfoHostPort23_Bug3510198_4)
- TEST_ADD(UriSuite::testUriUserInfoHostPort23_Bug3510198_related_1)
- TEST_ADD(UriSuite::testUriUserInfoHostPort23_Bug3510198_related_12)
- TEST_ADD(UriSuite::testUriUserInfoHostPort23_Bug3510198_related_2)
- TEST_ADD(UriSuite::testUriUserInfoHostPort3)
- TEST_ADD(UriSuite::testUriUserInfoHostPort4)
- TEST_ADD(UriSuite::testUriUserInfoHostPort5)
- TEST_ADD(UriSuite::testUriUserInfoHostPort6)
- TEST_ADD(UriSuite::testUriHostRegname)
- TEST_ADD(UriSuite::testUriHostIpFour1)
- TEST_ADD(UriSuite::testUriHostIpFour2)
- TEST_ADD(UriSuite::testUriHostIpSix1)
- TEST_ADD(UriSuite::testUriHostIpSix2)
- TEST_ADD(UriSuite::testUriHostIpFuture)
- TEST_ADD(UriSuite::testUriHostEmpty)
- TEST_ADD(UriSuite::testUriComponents)
- TEST_ADD(UriSuite::testUriComponents_Bug20070701)
- TEST_ADD(UriSuite::testEscaping)
- TEST_ADD(UriSuite::testUnescaping)
- TEST_ADD(UriSuite::testTrailingSlash)
- TEST_ADD(UriSuite::testAddBase)
- TEST_ADD(UriSuite::testToString)
- TEST_ADD(UriSuite::testToString_Bug1950126)
- TEST_ADD(UriSuite::testToStringCharsRequired)
- TEST_ADD(UriSuite::testToStringCharsRequired)
- TEST_ADD(UriSuite::testNormalizeSyntaxMaskRequired)
- TEST_ADD(UriSuite::testNormalizeSyntax)
- TEST_ADD(UriSuite::testNormalizeSyntaxComponents)
- TEST_ADD(UriSuite::testNormalizeCrash_Bug20080224)
- TEST_ADD(UriSuite::testFilenameUriConversion)
- TEST_ADD(UriSuite::testCrash_FreeUriMembers_Bug20080116)
- TEST_ADD(UriSuite::testCrash_Report2418192)
- TEST_ADD(UriSuite::testPervertedQueryString);
- TEST_ADD(UriSuite::testQueryStringEndingInEqualSign_NonBug32);
- TEST_ADD(UriSuite::testCrash_MakeOwner_Bug20080207)
- TEST_ADD(UriSuite::testQueryList)
- TEST_ADD(UriSuite::testQueryListPair)
- TEST_ADD(UriSuite::testQueryDissection_Bug3590761)
- TEST_ADD(UriSuite::testFreeCrash_Bug20080827)
- TEST_ADD(UriSuite::testParseInvalid_Bug16)
- TEST_ADD(UriSuite::testRangeComparison)
- TEST_ADD(UriSuite::testRangeComparison_RemoveBaseUri_Issue19)
- TEST_ADD(UriSuite::testEquals)
- TEST_ADD(UriSuite::testHostTextTermination_Issue15)
- }
+#define URI_TEST_IP_SIX_FAIL(x) ASSERT_TRUE(URI_FALSE == uri_TESTING_ONLY_ParseIpSixA(x "]"))
+#define URI_TEST_IP_SIX_PASS(x) ASSERT_TRUE(URI_TRUE == uri_TESTING_ONLY_ParseIpSixA(x "]"))
+
-private:
+namespace {
bool testDistinctionHelper(const char * uriText, bool expectedHostSet,
bool expectedAbsPath, bool expectedEmptyTailSegment) {
UriParserStateA state;
@@ -144,8 +78,10 @@ private:
uriFreeUriMembersA(&uri);
return true;
}
+} // namespace
- void testDistinction() {
+
+TEST(UriSuite, TestDistinction) {
/*
============================================================================
Rule | Example | hostSet | absPath | emptySeg
@@ -169,24 +105,24 @@ Rule | Example | hostSet | absPath | emptySeg
4) path-empty | "" | false | false | false
============================================================================
*/
- TEST_ASSERT(testDistinctionHelper("s://", true, false, false));
- TEST_ASSERT(testDistinctionHelper("s:///", true, false, true));
- TEST_ASSERT(testDistinctionHelper("s://a", true, false, false));
- TEST_ASSERT(testDistinctionHelper("s://a/", true, false, true));
- TEST_ASSERT(testDistinctionHelper("s:/", false, true, false));
- TEST_ASSERT(testDistinctionHelper("s:a", false, false, false));
- TEST_ASSERT(testDistinctionHelper("s:a/", false, false, true));
- TEST_ASSERT(testDistinctionHelper("s:", false, false, false));
-
- TEST_ASSERT(testDistinctionHelper("//", true, false, false));
- TEST_ASSERT(testDistinctionHelper("///", true, false, true));
- TEST_ASSERT(testDistinctionHelper("/", false, true, false));
- TEST_ASSERT(testDistinctionHelper("a", false, false, false));
- TEST_ASSERT(testDistinctionHelper("a/", false, false, true));
- TEST_ASSERT(testDistinctionHelper("", false, false, false));
- }
+ ASSERT_TRUE(testDistinctionHelper("s://", true, false, false));
+ ASSERT_TRUE(testDistinctionHelper("s:///", true, false, true));
+ ASSERT_TRUE(testDistinctionHelper("s://a", true, false, false));
+ ASSERT_TRUE(testDistinctionHelper("s://a/", true, false, true));
+ ASSERT_TRUE(testDistinctionHelper("s:/", false, true, false));
+ ASSERT_TRUE(testDistinctionHelper("s:a", false, false, false));
+ ASSERT_TRUE(testDistinctionHelper("s:a/", false, false, true));
+ ASSERT_TRUE(testDistinctionHelper("s:", false, false, false));
+
+ ASSERT_TRUE(testDistinctionHelper("//", true, false, false));
+ ASSERT_TRUE(testDistinctionHelper("///", true, false, true));
+ ASSERT_TRUE(testDistinctionHelper("/", false, true, false));
+ ASSERT_TRUE(testDistinctionHelper("a", false, false, false));
+ ASSERT_TRUE(testDistinctionHelper("a/", false, false, true));
+ ASSERT_TRUE(testDistinctionHelper("", false, false, false));
+}
- void testIpFour() {
+TEST(UriSuite, TestIpFour) {
URI_TEST_IP_FOUR_FAIL("01.0.0.0");
URI_TEST_IP_FOUR_FAIL("001.0.0.0");
URI_TEST_IP_FOUR_FAIL("00.0.0.0");
@@ -208,9 +144,9 @@ Rule | Example | hostSet | absPath | emptySeg
URI_TEST_IP_FOUR_PASS("2.0.0.0");
URI_TEST_IP_FOUR_PASS("3.0.0.0");
URI_TEST_IP_FOUR_PASS("30.0.0.0");
- }
+}
- void testIpSixPass() {
+TEST(UriSuite, TestIpSixPass) {
// Quad length
URI_TEST_IP_SIX_PASS("abcd::");
@@ -258,9 +194,9 @@ Rule | Example | hostSet | absPath | emptySeg
URI_TEST_IP_SIX_PASS("2001:db8:100:f101::1");
URI_TEST_IP_SIX_PASS("a:b:c::12:1");
URI_TEST_IP_SIX_PASS("a:b::0:1:2:3");
- }
+}
- void testIpSixFail() {
+TEST(UriSuite, TestIpSixFail) {
// 5 char quad
URI_TEST_IP_SIX_FAIL("::12345");
@@ -304,9 +240,9 @@ Rule | Example | hostSet | absPath | emptySeg
// Nonhex
URI_TEST_IP_SIX_FAIL("g:0:0:0:0:0:0");
- }
+}
- void testUri() {
+TEST(UriSuite, TestUri) {
UriParserStateA stateA;
UriParserStateW stateW;
UriUriA uriA;
@@ -316,65 +252,65 @@ Rule | Example | hostSet | absPath | emptySeg
stateW.uri = &uriW;
// On/off for each
- TEST_ASSERT(0 == uriParseUriA(&stateA, "//user:pass@[::1]:80/segment/index.html?query#frag"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "//user:pass@[::1]:80/segment/index.html?query#frag"));
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 == uriParseUriA(&stateA, "http://[::1]:80/segment/index.html?query#frag"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://[::1]:80/segment/index.html?query#frag"));
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 == uriParseUriA(&stateA, "http://user:pass@[::1]/segment/index.html?query#frag"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://user:pass@[::1]/segment/index.html?query#frag"));
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 == uriParseUriA(&stateA, "http://user:pass@[::1]:80?query#frag"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://user:pass@[::1]:80?query#frag"));
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 == uriParseUriA(&stateA, "http://user:pass@[::1]:80/segment/index.html#frag"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://user:pass@[::1]:80/segment/index.html#frag"));
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 == uriParseUriA(&stateA, "http://user:pass@[::1]:80/segment/index.html?query"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://user:pass@[::1]:80/segment/index.html?query"));
uriFreeUriMembersA(&uriA);
// Schema, port, one segment
- TEST_ASSERT(0 == uriParseUriA(&stateA, "ftp://host:21/gnu/"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "ftp://host:21/gnu/"));
uriFreeUriMembersA(&uriA);
// Relative
- TEST_ASSERT(0 == uriParseUriA(&stateA, "one/two/three"));
- TEST_ASSERT(!uriA.absolutePath);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "one/two/three"));
+ ASSERT_TRUE(!uriA.absolutePath);
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 == uriParseUriA(&stateA, "/one/two/three"));
- TEST_ASSERT(uriA.absolutePath);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "/one/two/three"));
+ ASSERT_TRUE(uriA.absolutePath);
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 == uriParseUriA(&stateA, "//user:pass@localhost/one/two/three"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "//user:pass@localhost/one/two/three"));
uriFreeUriMembersA(&uriA);
// ANSI and Unicode
- TEST_ASSERT(0 == uriParseUriA(&stateA, "http://www.example.com/"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://www.example.com/"));
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 == uriParseUriW(&stateW, L"http://www.example.com/"));
+ ASSERT_TRUE(0 == uriParseUriW(&stateW, L"http://www.example.com/"));
uriFreeUriMembersW(&uriW);
// Real life examples
- TEST_ASSERT(0 == uriParseUriA(&stateA, "http://sourceforge.net/projects/uriparser/"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://sourceforge.net/projects/uriparser/"));
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 == uriParseUriA(&stateA, "http://sourceforge.net/project/platformdownload.php?group_id=182840"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://sourceforge.net/project/platformdownload.php?group_id=182840"));
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 == uriParseUriA(&stateA, "mailto:test@example.com"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "mailto:test@example.com"));
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 == uriParseUriA(&stateA, "../../"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "../../"));
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 == uriParseUriA(&stateA, "/"));
- TEST_ASSERT(uriA.absolutePath)
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "/"));
+ ASSERT_TRUE(uriA.absolutePath);
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 == uriParseUriA(&stateA, ""));
- TEST_ASSERT(!uriA.absolutePath)
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, ""));
+ ASSERT_TRUE(!uriA.absolutePath);
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 == uriParseUriA(&stateA, "file:///bin/bash"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "file:///bin/bash"));
uriFreeUriMembersA(&uriA);
// Percent encoding
- TEST_ASSERT(0 == uriParseUriA(&stateA, "http://www.example.com/name%20with%20spaces/"));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, "http://www.example.com/name%20with%20spaces/"));
uriFreeUriMembersA(&uriA);
- TEST_ASSERT(0 != uriParseUriA(&stateA, "http://www.example.com/name with spaces/"));
+ ASSERT_TRUE(0 != uriParseUriA(&stateA, "http://www.example.com/name with spaces/"));
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriComponents() {
+TEST(UriSuite, TestUriComponents) {
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
@@ -382,85 +318,85 @@ Rule | Example | hostSet | absPath | emptySeg
const char * const input = "http" "://" "sourceforge.net" "/" "project" "/"
// 0 20 01 0 15
"platformdownload.php" "?" "group_id=182840";
- TEST_ASSERT(0 == uriParseUriA(&stateA, input));
-
- TEST_ASSERT(uriA.scheme.first == input);
- TEST_ASSERT(uriA.scheme.afterLast == input + 4);
- TEST_ASSERT(uriA.userInfo.first == NULL);
- TEST_ASSERT(uriA.userInfo.afterLast == NULL);
- TEST_ASSERT(uriA.hostText.first == input + 4 + 3);
- TEST_ASSERT(uriA.hostText.afterLast == input + 4 + 3 + 15);
- TEST_ASSERT(uriA.hostData.ipFuture.first == NULL);
- TEST_ASSERT(uriA.hostData.ipFuture.afterLast == NULL);
- TEST_ASSERT(uriA.portText.first == NULL);
- TEST_ASSERT(uriA.portText.afterLast == NULL);
-
- TEST_ASSERT(uriA.pathHead->text.first == input + 4 + 3 + 15 + 1);
- TEST_ASSERT(uriA.pathHead->text.afterLast == input + 4 + 3 + 15 + 1 + 7);
- TEST_ASSERT(uriA.pathHead->next->text.first == input + 4 + 3 + 15 + 1 + 7 + 1);
- TEST_ASSERT(uriA.pathHead->next->text.afterLast == input + 4 + 3 + 15 + 1 + 7 + 1 + 20);
- TEST_ASSERT(uriA.pathHead->next->next == NULL);
- TEST_ASSERT(uriA.pathTail == uriA.pathHead->next);
-
- TEST_ASSERT(uriA.query.first == input + 4 + 3 + 15 + 1 + 7 + 1 + 20 + 1);
- TEST_ASSERT(uriA.query.afterLast == input + 4 + 3 + 15 + 1 + 7 + 1 + 20 + 1 + 15);
- TEST_ASSERT(uriA.fragment.first == NULL);
- TEST_ASSERT(uriA.fragment.afterLast == NULL);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.scheme.first == input);
+ ASSERT_TRUE(uriA.scheme.afterLast == input + 4);
+ ASSERT_TRUE(uriA.userInfo.first == NULL);
+ ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 15);
+ ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+
+ ASSERT_TRUE(uriA.pathHead->text.first == input + 4 + 3 + 15 + 1);
+ ASSERT_TRUE(uriA.pathHead->text.afterLast == input + 4 + 3 + 15 + 1 + 7);
+ ASSERT_TRUE(uriA.pathHead->next->text.first == input + 4 + 3 + 15 + 1 + 7 + 1);
+ ASSERT_TRUE(uriA.pathHead->next->text.afterLast == input + 4 + 3 + 15 + 1 + 7 + 1 + 20);
+ ASSERT_TRUE(uriA.pathHead->next->next == NULL);
+ ASSERT_TRUE(uriA.pathTail == uriA.pathHead->next);
+
+ ASSERT_TRUE(uriA.query.first == input + 4 + 3 + 15 + 1 + 7 + 1 + 20 + 1);
+ ASSERT_TRUE(uriA.query.afterLast == input + 4 + 3 + 15 + 1 + 7 + 1 + 20 + 1 + 15);
+ ASSERT_TRUE(uriA.fragment.first == NULL);
+ ASSERT_TRUE(uriA.fragment.afterLast == NULL);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriComponents_Bug20070701() {
+TEST(UriSuite, TestUriComponentsBug20070701) {
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
// 01 01 01
const char * const input = "a" ":" "b";
- TEST_ASSERT(0 == uriParseUriA(&stateA, input));
-
- TEST_ASSERT(uriA.scheme.first == input);
- TEST_ASSERT(uriA.scheme.afterLast == input + 1);
- TEST_ASSERT(uriA.userInfo.first == NULL);
- TEST_ASSERT(uriA.userInfo.afterLast == NULL);
- TEST_ASSERT(uriA.hostText.first == NULL);
- TEST_ASSERT(uriA.hostText.afterLast == NULL);
- TEST_ASSERT(uriA.hostData.ipFuture.first == NULL);
- TEST_ASSERT(uriA.hostData.ipFuture.afterLast == NULL);
- TEST_ASSERT(uriA.portText.first == NULL);
- TEST_ASSERT(uriA.portText.afterLast == NULL);
-
- TEST_ASSERT(uriA.pathHead->text.first == input + 1 + 1);
- TEST_ASSERT(uriA.pathHead->text.afterLast == input + 1 + 1 + 1);
- TEST_ASSERT(uriA.pathHead->next == NULL);
- TEST_ASSERT(uriA.pathTail == uriA.pathHead);
-
- TEST_ASSERT(uriA.query.first == NULL);
- TEST_ASSERT(uriA.query.afterLast == NULL);
- TEST_ASSERT(uriA.fragment.first == NULL);
- TEST_ASSERT(uriA.fragment.afterLast == NULL);
-
- TEST_ASSERT(!uriA.absolutePath);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.scheme.first == input);
+ ASSERT_TRUE(uriA.scheme.afterLast == input + 1);
+ ASSERT_TRUE(uriA.userInfo.first == NULL);
+ ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
+ ASSERT_TRUE(uriA.hostText.first == NULL);
+ ASSERT_TRUE(uriA.hostText.afterLast == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
+
+ ASSERT_TRUE(uriA.pathHead->text.first == input + 1 + 1);
+ ASSERT_TRUE(uriA.pathHead->text.afterLast == input + 1 + 1 + 1);
+ ASSERT_TRUE(uriA.pathHead->next == NULL);
+ ASSERT_TRUE(uriA.pathTail == uriA.pathHead);
+
+ ASSERT_TRUE(uriA.query.first == NULL);
+ ASSERT_TRUE(uriA.query.afterLast == NULL);
+ ASSERT_TRUE(uriA.fragment.first == NULL);
+ ASSERT_TRUE(uriA.fragment.afterLast == NULL);
+
+ ASSERT_TRUE(!uriA.absolutePath);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriUserInfoHostPort1() {
+TEST(UriSuite, TestUriUserInfoHostPort1) {
// User info with ":", no port
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
// 0 4 0 3 0 7 01 0 9
const char * const input = "http" "://" "abc:def" "@" "localhost";
- TEST_ASSERT(0 == uriParseUriA(&stateA, input));
-
- TEST_ASSERT(uriA.userInfo.first == input + 4 + 3);
- TEST_ASSERT(uriA.userInfo.afterLast == input + 4 + 3 + 7);
- TEST_ASSERT(uriA.hostText.first == input + 4 + 3 + 7 + 1);
- TEST_ASSERT(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
- TEST_ASSERT(uriA.portText.first == NULL);
- TEST_ASSERT(uriA.portText.afterLast == NULL);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.userInfo.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.userInfo.afterLast == input + 4 + 3 + 7);
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 7 + 1);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriUserInfoHostPort2() {
+TEST(UriSuite, TestUriUserInfoHostPort2) {
// User info with ":", with port
UriParserStateA stateA;
UriUriA uriA;
@@ -469,18 +405,18 @@ Rule | Example | hostSet | absPath | emptySeg
const char * const input = "http" "://" "abc:def" "@" "localhost"
// 01 0 3
":" "123";
- TEST_ASSERT(0 == uriParseUriA(&stateA, input));
-
- TEST_ASSERT(uriA.userInfo.first == input + 4 + 3);
- TEST_ASSERT(uriA.userInfo.afterLast == input + 4 + 3 + 7);
- TEST_ASSERT(uriA.hostText.first == input + 4 + 3 + 7 + 1);
- TEST_ASSERT(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
- TEST_ASSERT(uriA.portText.first == input + 4 + 3 + 7 + 1 + 9 + 1);
- TEST_ASSERT(uriA.portText.afterLast == input + 4 + 3 + 7 + 1 + 9 + 1 + 3);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.userInfo.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.userInfo.afterLast == input + 4 + 3 + 7);
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 7 + 1);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
+ ASSERT_TRUE(uriA.portText.first == input + 4 + 3 + 7 + 1 + 9 + 1);
+ ASSERT_TRUE(uriA.portText.afterLast == input + 4 + 3 + 7 + 1 + 9 + 1 + 3);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriUserInfoHostPort22_Bug1948038() {
+TEST(UriSuite, TestUriUserInfoHostPort22Bug1948038) {
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
@@ -488,29 +424,29 @@ Rule | Example | hostSet | absPath | emptySeg
int res;
res = uriParseUriA(&stateA, "http://user:21@host/");
- TEST_ASSERT(URI_SUCCESS == res);
- TEST_ASSERT(!memcmp(uriA.userInfo.first, "user:21", 7 * sizeof(char)));
- TEST_ASSERT(uriA.userInfo.afterLast - uriA.userInfo.first == 7);
- TEST_ASSERT(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
- TEST_ASSERT(uriA.hostText.afterLast - uriA.hostText.first == 4);
- TEST_ASSERT(uriA.portText.first == NULL);
- TEST_ASSERT(uriA.portText.afterLast == NULL);
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(!memcmp(uriA.userInfo.first, "user:21", 7 * sizeof(char)));
+ ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 7);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
uriFreeUriMembersA(&uriA);
res = uriParseUriA(&stateA, "http://user:1234@192.168.0.1:1234/foo.com");
- TEST_ASSERT(URI_SUCCESS == res);
+ ASSERT_TRUE(URI_SUCCESS == res);
uriFreeUriMembersA(&uriA);
res = uriParseUriA(&stateA, "http://moo:21@moo:21@moo/");
- TEST_ASSERT(URI_ERROR_SYNTAX == res);
+ ASSERT_TRUE(URI_ERROR_SYNTAX == res);
uriFreeUriMembersA(&uriA);
res = uriParseUriA(&stateA, "http://moo:21@moo:21@moo:21/");
- TEST_ASSERT(URI_ERROR_SYNTAX == res);
+ ASSERT_TRUE(URI_ERROR_SYNTAX == res);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriUserInfoHostPort23_Bug3510198_1() {
+TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198One) {
// User info with ":", with port, with escaped chars in password
UriParserStateA stateA;
UriUriA uriA;
@@ -519,18 +455,17 @@ Rule | Example | hostSet | absPath | emptySeg
int res;
// 0 4 0 3 0 10 01 0 4 01
res = uriParseUriA(&stateA, "http" "://" "user:%2F21" "@" "host" "/");
- TEST_ASSERT(URI_SUCCESS == res);
- TEST_ASSERT(!memcmp(uriA.userInfo.first, "user:%2F21", 10 * sizeof(char)));
- TEST_ASSERT(uriA.userInfo.afterLast - uriA.userInfo.first == 10);
- TEST_ASSERT(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
- TEST_ASSERT(uriA.hostText.afterLast - uriA.hostText.first == 4);
- TEST_ASSERT(uriA.portText.first == NULL);
- TEST_ASSERT(uriA.portText.afterLast == NULL);
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(!memcmp(uriA.userInfo.first, "user:%2F21", 10 * sizeof(char)));
+ ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 10);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
uriFreeUriMembersA(&uriA);
+}
- }
-
- void testUriUserInfoHostPort23_Bug3510198_2() {
+TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198Two) {
// User info with ":", with port, with escaped chars in user name and password
UriParserStateA stateA;
UriUriA uriA;
@@ -539,17 +474,17 @@ Rule | Example | hostSet | absPath | emptySeg
int res;
// 0 4 0 3 0 13 01 0 4 01
res = uriParseUriA(&stateA, "http" "://" "%2Fuser:%2F21" "@" "host" "/");
- TEST_ASSERT(URI_SUCCESS == res);
- TEST_ASSERT(!memcmp(uriA.userInfo.first, "%2Fuser:%2F21", 13 * sizeof(char)));
- TEST_ASSERT(uriA.userInfo.afterLast - uriA.userInfo.first == 13);
- TEST_ASSERT(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
- TEST_ASSERT(uriA.hostText.afterLast - uriA.hostText.first == 4);
- TEST_ASSERT(uriA.portText.first == NULL);
- TEST_ASSERT(uriA.portText.afterLast == NULL);
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(!memcmp(uriA.userInfo.first, "%2Fuser:%2F21", 13 * sizeof(char)));
+ ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 13);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriUserInfoHostPort23_Bug3510198_3() {
+TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198Three) {
// User info with ":", with port, with escaped chars in password
UriParserStateA stateA;
UriUriA uriA;
@@ -558,18 +493,17 @@ Rule | Example | hostSet | absPath | emptySeg
int res;
// 0 4 0 3 0 16 01 0 4 01
res = uriParseUriA(&stateA, "http" "://" "user:!$&'()*+,;=" "@" "host" "/");
- TEST_ASSERT(URI_SUCCESS == res);
- TEST_ASSERT(!memcmp(uriA.userInfo.first, "user:!$&'()*+,;=", 16 * sizeof(char)));
- TEST_ASSERT(uriA.userInfo.afterLast - uriA.userInfo.first == 16);
- TEST_ASSERT(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
- TEST_ASSERT(uriA.hostText.afterLast - uriA.hostText.first == 4);
- TEST_ASSERT(uriA.portText.first == NULL);
- TEST_ASSERT(uriA.portText.afterLast == NULL);
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(!memcmp(uriA.userInfo.first, "user:!$&'()*+,;=", 16 * sizeof(char)));
+ ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 16);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
uriFreeUriMembersA(&uriA);
+}
- }
-
- void testUriUserInfoHostPort23_Bug3510198_4() {
+TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198Four) {
// User info with ":", with port, with escaped chars in user name and password
UriParserStateA stateA;
UriUriA uriA;
@@ -578,17 +512,17 @@ Rule | Example | hostSet | absPath | emptySeg
int res;
// 0 4 0 3 0 20 01 0 4 01
res = uriParseUriA(&stateA, "http" "://" "!$&'()*+,;=:password" "@" "host" "/");
- TEST_ASSERT(URI_SUCCESS == res);
- TEST_ASSERT(!memcmp(uriA.userInfo.first, "!$&'()*+,;=:password", 20 * sizeof(char)));
- TEST_ASSERT(uriA.userInfo.afterLast - uriA.userInfo.first == 20);
- TEST_ASSERT(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
- TEST_ASSERT(uriA.hostText.afterLast - uriA.hostText.first == 4);
- TEST_ASSERT(uriA.portText.first == NULL);
- TEST_ASSERT(uriA.portText.afterLast == NULL);
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(!memcmp(uriA.userInfo.first, "!$&'()*+,;=:password", 20 * sizeof(char)));
+ ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 20);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriUserInfoHostPort23_Bug3510198_related_1() {
+TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198RelatedOne) {
// Empty user info
UriParserStateA stateA;
UriUriA uriA;
@@ -597,18 +531,18 @@ Rule | Example | hostSet | absPath | emptySeg
int res;
// 0 4 0 3 01 0 4 01
res = uriParseUriA(&stateA, "http" "://" "@" "host" "/");
- TEST_ASSERT(URI_SUCCESS == res);
- TEST_ASSERT(uriA.userInfo.afterLast != NULL);
- TEST_ASSERT(uriA.userInfo.first != NULL);
- TEST_ASSERT(uriA.userInfo.afterLast - uriA.userInfo.first == 0);
- TEST_ASSERT(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
- TEST_ASSERT(uriA.hostText.afterLast - uriA.hostText.first == 4);
- TEST_ASSERT(uriA.portText.first == NULL);
- TEST_ASSERT(uriA.portText.afterLast == NULL);
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(uriA.userInfo.afterLast != NULL);
+ ASSERT_TRUE(uriA.userInfo.first != NULL);
+ ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 0);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriUserInfoHostPort23_Bug3510198_related_12() {
+TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198RelatedOneTwo) {
// Empty user info
UriParserStateA stateA;
UriUriA uriA;
@@ -617,17 +551,17 @@ Rule | Example | hostSet | absPath | emptySeg
int res;
// 0 4 0 3 0 7 01
res = uriParseUriA(&stateA, "http" "://" "%2Fhost" "/");
- TEST_ASSERT(URI_SUCCESS == res);
- TEST_ASSERT(uriA.userInfo.afterLast == NULL);
- TEST_ASSERT(uriA.userInfo.first == NULL);
- TEST_ASSERT(!memcmp(uriA.hostText.first, "%2Fhost", 7 * sizeof(char)));
- TEST_ASSERT(uriA.hostText.afterLast - uriA.hostText.first == 7);
- TEST_ASSERT(uriA.portText.first == NULL);
- TEST_ASSERT(uriA.portText.afterLast == NULL);
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
+ ASSERT_TRUE(uriA.userInfo.first == NULL);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "%2Fhost", 7 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 7);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriUserInfoHostPort23_Bug3510198_related_2() {
+TEST(UriSuite, TestUriUserInfoHostPort23Bug3510198RelatedTwo) {
// Several colons in userinfo
UriParserStateA stateA;
UriUriA uriA;
@@ -636,35 +570,35 @@ Rule | Example | hostSet | absPath | emptySeg
int res;
// 0 4 0 3 0 2 01 0 4 01
res = uriParseUriA(&stateA, "http" "://" "::" "@" "host" "/");
- TEST_ASSERT(URI_SUCCESS == res);
- TEST_ASSERT(!memcmp(uriA.userInfo.first, "::", 2 * sizeof(char)));
- TEST_ASSERT(uriA.userInfo.afterLast - uriA.userInfo.first == 2);
- TEST_ASSERT(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
- TEST_ASSERT(uriA.hostText.afterLast - uriA.hostText.first == 4);
- TEST_ASSERT(uriA.portText.first == NULL);
- TEST_ASSERT(uriA.portText.afterLast == NULL);
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(!memcmp(uriA.userInfo.first, "::", 2 * sizeof(char)));
+ ASSERT_TRUE(uriA.userInfo.afterLast - uriA.userInfo.first == 2);
+ ASSERT_TRUE(!memcmp(uriA.hostText.first, "host", 4 * sizeof(char)));
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 4);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriUserInfoHostPort3() {
+TEST(UriSuite, TestUriUserInfoHostPort3) {
// User info without ":", no port
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
// 0 4 0 3 0 7 01 0 9
const char * const input = "http" "://" "abcdefg" "@" "localhost";
- TEST_ASSERT(0 == uriParseUriA(&stateA, input));
-
- TEST_ASSERT(uriA.userInfo.first == input + 4 + 3);
- TEST_ASSERT(uriA.userInfo.afterLast == input + 4 + 3 + 7);
- TEST_ASSERT(uriA.hostText.first == input + 4 + 3 + 7 + 1);
- TEST_ASSERT(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
- TEST_ASSERT(uriA.portText.first == NULL);
- TEST_ASSERT(uriA.portText.afterLast == NULL);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.userInfo.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.userInfo.afterLast == input + 4 + 3 + 7);
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 7 + 1);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriUserInfoHostPort4() {
+TEST(UriSuite, TestUriUserInfoHostPort4) {
// User info without ":", with port
UriParserStateA stateA;
UriUriA uriA;
@@ -673,160 +607,161 @@ Rule | Example | hostSet | absPath | emptySeg
const char * const input = "http" "://" "abcdefg" "@" "localhost"
// 01 0 3
":" "123";
- TEST_ASSERT(0 == uriParseUriA(&stateA, input));
-
- TEST_ASSERT(uriA.userInfo.first == input + 4 + 3);
- TEST_ASSERT(uriA.userInfo.afterLast == input + 4 + 3 + 7);
- TEST_ASSERT(uriA.hostText.first == input + 4 + 3 + 7 + 1);
- TEST_ASSERT(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
- TEST_ASSERT(uriA.portText.first == input + 4 + 3 + 7 + 1 + 9 + 1);
- TEST_ASSERT(uriA.portText.afterLast == input + 4 + 3 + 7 + 1 + 9 + 1 + 3);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.userInfo.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.userInfo.afterLast == input + 4 + 3 + 7);
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 7 + 1);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7 + 1 + 9);
+ ASSERT_TRUE(uriA.portText.first == input + 4 + 3 + 7 + 1 + 9 + 1);
+ ASSERT_TRUE(uriA.portText.afterLast == input + 4 + 3 + 7 + 1 + 9 + 1 + 3);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriUserInfoHostPort5() {
+TEST(UriSuite, TestUriUserInfoHostPort5) {
// No user info, no port
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
// 0 4 0 3 0 9
const char * const input = "http" "://" "localhost";
- TEST_ASSERT(0 == uriParseUriA(&stateA, input));
-
- TEST_ASSERT(uriA.userInfo.first == NULL);
- TEST_ASSERT(uriA.userInfo.afterLast == NULL);
- TEST_ASSERT(uriA.hostText.first == input + 4 + 3);
- TEST_ASSERT(uriA.hostText.afterLast == input + 4 + 3 + 9);
- TEST_ASSERT(uriA.portText.first == NULL);
- TEST_ASSERT(uriA.portText.afterLast == NULL);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.userInfo.first == NULL);
+ ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 9);
+ ASSERT_TRUE(uriA.portText.first == NULL);
+ ASSERT_TRUE(uriA.portText.afterLast == NULL);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriUserInfoHostPort6() {
+TEST(UriSuite, TestUriUserInfoHostPort6) {
// No user info, with port
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
// 0 4 0 3 0 9 01 0 3
const char * const input = "http" "://" "localhost" ":" "123";
- TEST_ASSERT(0 == uriParseUriA(&stateA, input));
-
- TEST_ASSERT(uriA.userInfo.first == NULL);
- TEST_ASSERT(uriA.userInfo.afterLast == NULL);
- TEST_ASSERT(uriA.hostText.first == input + 4 + 3);
- TEST_ASSERT(uriA.hostText.afterLast == input + 4 + 3 + 9);
- TEST_ASSERT(uriA.portText.first == input + 4 + 3 + 9 + 1);
- TEST_ASSERT(uriA.portText.afterLast == input + 4 + 3 + 9 + 1 + 3);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.userInfo.first == NULL);
+ ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 9);
+ ASSERT_TRUE(uriA.portText.first == input + 4 + 3 + 9 + 1);
+ ASSERT_TRUE(uriA.portText.afterLast == input + 4 + 3 + 9 + 1 + 3);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriHostRegname() {
+TEST(UriSuite, TestUriHostRegname) {
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
// 0 4 0 3 0 11
const char * const input = "http" "://" "example.com";
- TEST_ASSERT(0 == uriParseUriA(&stateA, input));
-
- TEST_ASSERT(uriA.hostText.first == input + 4 + 3);
- TEST_ASSERT(uriA.hostText.afterLast == input + 4 + 3 + 11);
- TEST_ASSERT(uriA.hostData.ip4 == NULL);
- TEST_ASSERT(uriA.hostData.ip6 == NULL);
- TEST_ASSERT(uriA.hostData.ipFuture.first == NULL);
- TEST_ASSERT(uriA.hostData.ipFuture.afterLast == NULL);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 11);
+ ASSERT_TRUE(uriA.hostData.ip4 == NULL);
+ ASSERT_TRUE(uriA.hostData.ip6 == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriHostIpFour1() {
+TEST(UriSuite, TestUriHostIpFour1) {
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
// 0 4 0 3 0 7 01 0 2
const char * const input = "http" "://" "1.2.3.4" ":" "80";
- TEST_ASSERT(0 == uriParseUriA(&stateA, input));
-
- TEST_ASSERT(uriA.hostText.first == input + 4 + 3);
- TEST_ASSERT(uriA.hostText.afterLast == input + 4 + 3 + 7);
- TEST_ASSERT(uriA.hostData.ip4 != NULL);
- TEST_ASSERT(uriA.hostData.ip6 == NULL);
- TEST_ASSERT(uriA.hostData.ipFuture.first == NULL);
- TEST_ASSERT(uriA.hostData.ipFuture.afterLast == NULL);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7);
+ ASSERT_TRUE(uriA.hostData.ip4 != NULL);
+ ASSERT_TRUE(uriA.hostData.ip6 == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriHostIpFour2() {
+TEST(UriSuite, TestUriHostIpFour2) {
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
// 0 4 0 3 0 7
const char * const input = "http" "://" "1.2.3.4";
- TEST_ASSERT(0 == uriParseUriA(&stateA, input));
-
- TEST_ASSERT(uriA.hostText.first == input + 4 + 3);
- TEST_ASSERT(uriA.hostText.afterLast == input + 4 + 3 + 7);
- TEST_ASSERT(uriA.hostData.ip4 != NULL);
- TEST_ASSERT(uriA.hostData.ip6 == NULL);
- TEST_ASSERT(uriA.hostData.ipFuture.first == NULL);
- TEST_ASSERT(uriA.hostData.ipFuture.afterLast == NULL);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 7);
+ ASSERT_TRUE(uriA.hostData.ip4 != NULL);
+ ASSERT_TRUE(uriA.hostData.ip6 == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriHostIpSix1() {
+TEST(UriSuite, TestUriHostIpSix1) {
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
// 0 4 0 3 01 45 01 0 2
const char * const input = "http" "://" "[::1]" ":" "80";
- TEST_ASSERT(0 == uriParseUriA(&stateA, input));
-
- TEST_ASSERT(uriA.hostText.first == input + 4 + 3 + 1);
- TEST_ASSERT(uriA.hostText.afterLast == input + 4 + 3 + 4);
- TEST_ASSERT(uriA.hostData.ip4 == NULL);
- TEST_ASSERT(uriA.hostData.ip6 != NULL);
- TEST_ASSERT(uriA.hostData.ipFuture.first == NULL);
- TEST_ASSERT(uriA.hostData.ipFuture.afterLast == NULL);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 1);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 4);
+ ASSERT_TRUE(uriA.hostData.ip4 == NULL);
+ ASSERT_TRUE(uriA.hostData.ip6 != NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriHostIpSix2() {
+TEST(UriSuite, TestUriHostIpSix2) {
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
// 0 4 0 3 01 45
const char * const input = "http" "://" "[::1]";
- TEST_ASSERT(0 == uriParseUriA(&stateA, input));
-
- TEST_ASSERT(uriA.hostText.first == input + 4 + 3 + 1);
- TEST_ASSERT(uriA.hostText.afterLast == input + 4 + 3 + 4);
- TEST_ASSERT(uriA.hostData.ip4 == NULL);
- TEST_ASSERT(uriA.hostData.ip6 != NULL);
- TEST_ASSERT(uriA.hostData.ipFuture.first == NULL);
- TEST_ASSERT(uriA.hostData.ipFuture.afterLast == NULL);
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
+
+ ASSERT_TRUE(uriA.hostText.first == input + 4 + 3 + 1);
+ ASSERT_TRUE(uriA.hostText.afterLast == input + 4 + 3 + 4);
+ ASSERT_TRUE(uriA.hostData.ip4 == NULL);
+ ASSERT_TRUE(uriA.hostData.ip6 != NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.first == NULL);
+ ASSERT_TRUE(uriA.hostData.ipFuture.afterLast == NULL);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriHostEmpty() {
+TEST(UriSuite, TestUriHostEmpty) {
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
// 0 4 0 3 01 0 3
const char * const input = "http" "://" ":" "123";
const int res = uriParseUriA(&stateA, input);
- TEST_ASSERT(URI_SUCCESS == res);
- TEST_ASSERT(uriA.userInfo.first == NULL);
- TEST_ASSERT(uriA.userInfo.afterLast == NULL);
- TEST_ASSERT(uriA.hostText.first != NULL);
- TEST_ASSERT(uriA.hostText.afterLast != NULL);
- TEST_ASSERT(uriA.hostText.afterLast - uriA.hostText.first == 0);
- TEST_ASSERT(uriA.portText.first == input + 4 + 3 + 1);
- TEST_ASSERT(uriA.portText.afterLast == input + 4 + 3 + 1 + 3);
+ ASSERT_TRUE(URI_SUCCESS == res);
+ ASSERT_TRUE(uriA.userInfo.first == NULL);
+ ASSERT_TRUE(uriA.userInfo.afterLast == NULL);
+ ASSERT_TRUE(uriA.hostText.first != NULL);
+ ASSERT_TRUE(uriA.hostText.afterLast != NULL);
+ ASSERT_TRUE(uriA.hostText.afterLast - uriA.hostText.first == 0);
+ ASSERT_TRUE(uriA.portText.first == input + 4 + 3 + 1);
+ ASSERT_TRUE(uriA.portText.afterLast == input + 4 + 3 + 1 + 3);
uriFreeUriMembersA(&uriA);
- }
+}
- void testUriHostIpFuture() {
+TEST(UriSuite, TestUriHostIpFuture) {
// TODO
- }
+}
+namespace {
bool testEscapingHelper(const wchar_t * in, const wchar_t * expectedOut,
bool spaceToPlus = false, bool normalizeBreaks = false) {
wchar_t * const buffer = new wchar_t[(normalizeBreaks ? 6 : 3)
@@ -841,52 +776,54 @@ Rule | Example | hostSet | absPath | emptySeg
delete [] buffer;
return equal;
}
+} // namespace
- void testEscaping() {
+TEST(UriSuite, TestEscaping) {
const bool SPACE_TO_PLUS = true;
const bool SPACE_TO_PERCENT = false;
const bool KEEP_UNMODIFIED = false;
const bool NORMALIZE = true;
// '+' to ' '
- TEST_ASSERT(testEscapingHelper(L"abc def", L"abc+def", SPACE_TO_PLUS));
- TEST_ASSERT(testEscapingHelper(L"abc def", L"abc%20def", SPACE_TO_PERCENT));
+ ASSERT_TRUE(testEscapingHelper(L"abc def", L"abc+def", SPACE_TO_PLUS));
+ ASSERT_TRUE(testEscapingHelper(L"abc def", L"abc%20def", SPACE_TO_PERCENT));
// Percent encoding
- TEST_ASSERT(testEscapingHelper(L"\x00", L"\0"));
- TEST_ASSERT(testEscapingHelper(L"\x01", L"%01"));
- TEST_ASSERT(testEscapingHelper(L"\xff", L"%FF"));
+ ASSERT_TRUE(testEscapingHelper(L"\x00", L"\0"));
+ ASSERT_TRUE(testEscapingHelper(L"\x01", L"%01"));
+ ASSERT_TRUE(testEscapingHelper(L"\xff", L"%FF"));
// Linebreak normalization
- TEST_ASSERT(testEscapingHelper(L"\x0d", L"%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- TEST_ASSERT(testEscapingHelper(L"g\x0d", L"g%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- TEST_ASSERT(testEscapingHelper(L"\x0dg", L"%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
- TEST_ASSERT(testEscapingHelper(L"\x0d", L"%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- TEST_ASSERT(testEscapingHelper(L"g\x0d", L"g%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- TEST_ASSERT(testEscapingHelper(L"\x0dg", L"%0Dg", SPACE_TO_PLUS, KEEP_UNMODIFIED));
-
- TEST_ASSERT(testEscapingHelper(L"\x0a", L"%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- TEST_ASSERT(testEscapingHelper(L"g\x0a", L"g%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- TEST_ASSERT(testEscapingHelper(L"\x0ag", L"%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
- TEST_ASSERT(testEscapingHelper(L"\x0a", L"%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- TEST_ASSERT(testEscapingHelper(L"g\x0a", L"g%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- TEST_ASSERT(testEscapingHelper(L"\x0ag", L"%0Ag", SPACE_TO_PLUS, KEEP_UNMODIFIED));
-
- TEST_ASSERT(testEscapingHelper(L"\x0d\x0a", L"%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- TEST_ASSERT(testEscapingHelper(L"g\x0d\x0a", L"g%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- TEST_ASSERT(testEscapingHelper(L"\x0d\x0ag", L"%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
- TEST_ASSERT(testEscapingHelper(L"\x0d\x0a", L"%0D%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- TEST_ASSERT(testEscapingHelper(L"g\x0d\x0a", L"g%0D%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- TEST_ASSERT(testEscapingHelper(L"\x0d\x0ag", L"%0D%0Ag", SPACE_TO_PLUS, KEEP_UNMODIFIED));
-
- TEST_ASSERT(testEscapingHelper(L"\x0a\x0d", L"%0D%0A%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- TEST_ASSERT(testEscapingHelper(L"g\x0a\x0d", L"g%0D%0A%0D%0A", SPACE_TO_PLUS, NORMALIZE));
- TEST_ASSERT(testEscapingHelper(L"\x0a\x0dg", L"%0D%0A%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
- TEST_ASSERT(testEscapingHelper(L"\x0a\x0d", L"%0A%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- TEST_ASSERT(testEscapingHelper(L"g\x0a\x0d", L"g%0A%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- TEST_ASSERT(testEscapingHelper(L"\x0a\x0dg", L"%0A%0Dg", SPACE_TO_PLUS, KEEP_UNMODIFIED));
- }
+ ASSERT_TRUE(testEscapingHelper(L"\x0d", L"%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0d", L"g%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0dg", L"%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0d", L"%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0d", L"g%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"\x0dg", L"%0Dg", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+
+ ASSERT_TRUE(testEscapingHelper(L"\x0a", L"%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0a", L"g%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0ag", L"%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0a", L"%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0a", L"g%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"\x0ag", L"%0Ag", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+
+ ASSERT_TRUE(testEscapingHelper(L"\x0d\x0a", L"%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0d\x0a", L"g%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0d\x0ag", L"%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0d\x0a", L"%0D%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0d\x0a", L"g%0D%0A", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"\x0d\x0ag", L"%0D%0Ag", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+
+ ASSERT_TRUE(testEscapingHelper(L"\x0a\x0d", L"%0D%0A%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0a\x0d", L"g%0D%0A%0D%0A", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0a\x0dg", L"%0D%0A%0D%0Ag", SPACE_TO_PLUS, NORMALIZE));
+ ASSERT_TRUE(testEscapingHelper(L"\x0a\x0d", L"%0A%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"g\x0a\x0d", L"g%0A%0D", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+ ASSERT_TRUE(testEscapingHelper(L"\x0a\x0dg", L"%0A%0Dg", SPACE_TO_PLUS, KEEP_UNMODIFIED));
+}
+namespace {
bool testUnescapingHelper(const wchar_t * input, const wchar_t * output,
bool plusToSpace = false, UriBreakConversion breakConversion = URI_BR_DONT_TOUCH) {
wchar_t * working = new wchar_t[URI_STRLEN(input) + 1];
@@ -898,95 +835,97 @@ Rule | Example | hostSet | absPath | emptySeg
delete[] working;
return success;
}
+} // namespace
- void testUnescaping() {
+TEST(UriSuite, TestUnescaping) {
const bool PLUS_TO_SPACE = true;
const bool PLUS_DONT_TOUCH = false;
// Proper
- TEST_ASSERT(testUnescapingHelper(L"abc%20%41BC", L"abc ABC"));
- TEST_ASSERT(testUnescapingHelper(L"%20", L" "));
+ ASSERT_TRUE(testUnescapingHelper(L"abc%20%41BC", L"abc ABC"));
+ ASSERT_TRUE(testUnescapingHelper(L"%20", L" "));
// Incomplete
- TEST_ASSERT(testUnescapingHelper(L"%0", L"%0"));
+ ASSERT_TRUE(testUnescapingHelper(L"%0", L"%0"));
// Nonhex
- TEST_ASSERT(testUnescapingHelper(L"%0g", L"%0g"));
- TEST_ASSERT(testUnescapingHelper(L"%G0", L"%G0"));
+ ASSERT_TRUE(testUnescapingHelper(L"%0g", L"%0g"));
+ ASSERT_TRUE(testUnescapingHelper(L"%G0", L"%G0"));
// No double decoding
- TEST_ASSERT(testUnescapingHelper(L"%2520", L"%20"));
+ ASSERT_TRUE(testUnescapingHelper(L"%2520", L"%20"));
// Decoding of '+'
- TEST_ASSERT(testUnescapingHelper(L"abc+def", L"abc+def", PLUS_DONT_TOUCH));
- TEST_ASSERT(testUnescapingHelper(L"abc+def", L"abc def", PLUS_TO_SPACE));
+ ASSERT_TRUE(testUnescapingHelper(L"abc+def", L"abc+def", PLUS_DONT_TOUCH));
+ ASSERT_TRUE(testUnescapingHelper(L"abc+def", L"abc def", PLUS_TO_SPACE));
// Line break conversion
- TEST_ASSERT(testUnescapingHelper(L"%0d", L"\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- TEST_ASSERT(testUnescapingHelper(L"%0d", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- TEST_ASSERT(testUnescapingHelper(L"%0d", L"\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- TEST_ASSERT(testUnescapingHelper(L"%0d", L"\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- TEST_ASSERT(testUnescapingHelper(L"%0d%0d", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0d", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
-
- TEST_ASSERT(testUnescapingHelper(L"%0a", L"\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- TEST_ASSERT(testUnescapingHelper(L"%0a", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- TEST_ASSERT(testUnescapingHelper(L"%0a", L"\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- TEST_ASSERT(testUnescapingHelper(L"%0a", L"\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- TEST_ASSERT(testUnescapingHelper(L"%0a%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
-
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a", L"\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a", L"\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a%0a", L"\x0d\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a%0d", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a%0d", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a%0d", L"\x0d\x0a\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- TEST_ASSERT(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
-
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d", L"\x0a\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d%0a", L"\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d%0d", L"\x0a\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d%0d", L"\x0d\x0a\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d%0d", L"\x0d\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d%0d", L"\x0a\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
-
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0a\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0d\x0a\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0d\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
- TEST_ASSERT(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0a\x0d\x0a\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
- }
+ ASSERT_TRUE(testUnescapingHelper(L"%0d", L"\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d", L"\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d", L"\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0d", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0d", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0a", L"\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a", L"\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a", L"\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a", L"\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a", L"\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a", L"\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0a", L"\x0d\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d", L"\x0d\x0a\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0d%0a%0d%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d", L"\x0a\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a", L"\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a", L"\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a", L"\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a", L"\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0d", L"\x0a\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0d", L"\x0d\x0a\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0d", L"\x0d\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0d", L"\x0a\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0a\x0a\x0a", PLUS_DONT_TOUCH, URI_BR_TO_UNIX));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0d\x0a\x0d\x0a\x0d\x0a", PLUS_DONT_TOUCH, URI_BR_TO_WINDOWS));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0d\x0d\x0d", PLUS_DONT_TOUCH, URI_BR_TO_MAC));
+ ASSERT_TRUE(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0a\x0d\x0a\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
+}
+namespace {
bool testAddBaseHelper(const wchar_t * base, const wchar_t * rel, const wchar_t * expectedResult, bool backward_compatibility = false) {
UriParserStateW stateW;
@@ -1053,81 +992,83 @@ Rule | Example | hostSet | absPath | emptySeg
uriFreeUriMembersW(&transformedUri);
return equal;
}
+} // namespace
- void testTrailingSlash() {
+TEST(UriSuite, TestTrailingSlash) {
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
// 0 3 01
const char * const input = "abc" "/";
- TEST_ASSERT(0 == uriParseUriA(&stateA, input));
+ ASSERT_TRUE(0 == uriParseUriA(&stateA, input));
- TEST_ASSERT(uriA.pathHead->text.first == input);
- TEST_ASSERT(uriA.pathHead->text.afterLast == input + 3);
- TEST_ASSERT(uriA.pathHead->next->text.first == uriA.pathHead->next->text.afterLast);
- TEST_ASSERT(uriA.pathHead->next->next == NULL);
- TEST_ASSERT(uriA.pathTail == uriA.pathHead->next);
+ ASSERT_TRUE(uriA.pathHead->text.first == input);
+ ASSERT_TRUE(uriA.pathHead->text.afterLast == input + 3);
+ ASSERT_TRUE(uriA.pathHead->next->text.first == uriA.pathHead->next->text.afterLast);
+ ASSERT_TRUE(uriA.pathHead->next->next == NULL);
+ ASSERT_TRUE(uriA.pathTail == uriA.pathHead->next);
uriFreeUriMembersA(&uriA);
- }
+}
- void testAddBase() {
+TEST(UriSuite, TestAddBase) {
// 5.4.1. Normal Examples
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g:h", L"g:h"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g", L"http://a/b/c/g"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./g", L"http://a/b/c/g"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g/", L"http://a/b/c/g/"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/g", L"http://a/g"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"//g", L"http://g"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"?y", L"http://a/b/c/d;p?y"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y", L"http://a/b/c/g?y"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"#s", L"http://a/b/c/d;p?q#s"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g#s", L"http://a/b/c/g#s"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y#s", L"http://a/b/c/g?y#s"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L";x", L"http://a/b/c/;x"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x", L"http://a/b/c/g;x"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x?y#s", L"http://a/b/c/g;x?y#s"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"", L"http://a/b/c/d;p?q"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L".", L"http://a/b/c/"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./", L"http://a/b/c/"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"..", L"http://a/b/"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../", L"http://a/b/"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../g", L"http://a/b/g"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../..", L"http://a/"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../", L"http://a/"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../g", L"http://a/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g:h", L"g:h"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g", L"http://a/b/c/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./g", L"http://a/b/c/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g/", L"http://a/b/c/g/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/g", L"http://a/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"//g", L"http://g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"?y", L"http://a/b/c/d;p?y"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y", L"http://a/b/c/g?y"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"#s", L"http://a/b/c/d;p?q#s"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g#s", L"http://a/b/c/g#s"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y#s", L"http://a/b/c/g?y#s"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L";x", L"http://a/b/c/;x"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x", L"http://a/b/c/g;x"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x?y#s", L"http://a/b/c/g;x?y#s"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"", L"http://a/b/c/d;p?q"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L".", L"http://a/b/c/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./", L"http://a/b/c/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"..", L"http://a/b/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../", L"http://a/b/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../g", L"http://a/b/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../..", L"http://a/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../", L"http://a/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../g", L"http://a/g"));
// 5.4.2. Abnormal Examples
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../../g", L"http://a/g"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../../../g", L"http://a/g"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/./g", L"http://a/g"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/../g", L"http://a/g"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g.", L"http://a/b/c/g."));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L".g", L"http://a/b/c/.g"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g..", L"http://a/b/c/g.."));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"..g", L"http://a/b/c/..g"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./../g", L"http://a/b/g"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./g/.", L"http://a/b/c/g/"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g/./h", L"http://a/b/c/g/h"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g/../h", L"http://a/b/c/h"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x=1/./y", L"http://a/b/c/g;x=1/y"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x=1/../y", L"http://a/b/c/y"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y/./x", L"http://a/b/c/g?y/./x"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y/../x", L"http://a/b/c/g?y/../x"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g#s/./x", L"http://a/b/c/g#s/./x"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g#s/../x", L"http://a/b/c/g#s/../x"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g", L"http:g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../../g", L"http://a/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"../../../../g", L"http://a/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/./g", L"http://a/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/../g", L"http://a/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g.", L"http://a/b/c/g."));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L".g", L"http://a/b/c/.g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g..", L"http://a/b/c/g.."));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"..g", L"http://a/b/c/..g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./../g", L"http://a/b/g"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"./g/.", L"http://a/b/c/g/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g/./h", L"http://a/b/c/g/h"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g/../h", L"http://a/b/c/h"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x=1/./y", L"http://a/b/c/g;x=1/y"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g;x=1/../y", L"http://a/b/c/y"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y/./x", L"http://a/b/c/g?y/./x"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g?y/../x", L"http://a/b/c/g?y/../x"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g#s/./x", L"http://a/b/c/g#s/./x"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"g#s/../x", L"http://a/b/c/g#s/../x"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g", L"http:g"));
// Backward compatibility (feature request #4, RFC3986 5.4.2)
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g", L"http:g", false));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g", L"http://a/b/c/g", true));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g?q#f", L"http://a/b/c/g?q#f", true));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"other:g?q#f", L"other:g?q#f", true));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g", L"http:g", false));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g", L"http://a/b/c/g", true));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"http:g?q#f", L"http://a/b/c/g?q#f", true));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"other:g?q#f", L"other:g?q#f", true));
// Bug related to absolutePath flag set despite presence of host
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/", L"http://a/"));
- TEST_ASSERT(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/g/", L"http://a/g/"));
- }
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/", L"http://a/"));
+ ASSERT_TRUE(testAddBaseHelper(L"http://a/b/c/d;p?q", L"/g/", L"http://a/g/"));
+}
+namespace {
bool testToStringHelper(const wchar_t * text) {
// Parse
UriParserStateW state;
@@ -1174,85 +1115,87 @@ Rule | Example | hostSet | absPath | emptySeg
uriFreeUriMembersW(&uri);
return equals;
}
+} // namespace
- void testToString() {
+TEST(UriSuite, TestToString) {
// Scheme
- TEST_ASSERT(testToStringHelper(L"ftp://localhost/"));
+ ASSERT_TRUE(testToStringHelper(L"ftp://localhost/"));
// UserInfo
- TEST_ASSERT(testToStringHelper(L"http://user:pass@localhost/"));
+ ASSERT_TRUE(testToStringHelper(L"http://user:pass@localhost/"));
// IPv4
- TEST_ASSERT(testToStringHelper(L"http://123.0.1.255/"));
+ ASSERT_TRUE(testToStringHelper(L"http://123.0.1.255/"));
// IPv6
- TEST_ASSERT(testToStringHelper(L"http://[abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd]/"));
+ ASSERT_TRUE(testToStringHelper(L"http://[abcd:abcd:abcd:abcd:abcd:abcd:abcd:abcd]/"));
// IPvFuture
- TEST_ASSERT(testToStringHelper(L"http://[vA.123456]/"));
+ ASSERT_TRUE(testToStringHelper(L"http://[vA.123456]/"));
// Port
- TEST_ASSERT(testToStringHelper(L"http://example.com:123/"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com:123/"));
// Path
- TEST_ASSERT(testToStringHelper(L"http://example.com"));
- TEST_ASSERT(testToStringHelper(L"http://example.com/"));
- TEST_ASSERT(testToStringHelper(L"http://example.com/abc/"));
- TEST_ASSERT(testToStringHelper(L"http://example.com/abc/def"));
- TEST_ASSERT(testToStringHelper(L"http://example.com/abc/def/"));
- TEST_ASSERT(testToStringHelper(L"http://example.com//"));
- TEST_ASSERT(testToStringHelper(L"http://example.com/./.."));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/abc/"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/abc/def"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/abc/def/"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com//"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/./.."));
// Query
- TEST_ASSERT(testToStringHelper(L"http://example.com/?abc"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/?abc"));
// Fragment
- TEST_ASSERT(testToStringHelper(L"http://example.com/#abc"));
- TEST_ASSERT(testToStringHelper(L"http://example.com/?def#abc"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/#abc"));
+ ASSERT_TRUE(testToStringHelper(L"http://example.com/?def#abc"));
// Relative
- TEST_ASSERT(testToStringHelper(L"a"));
- TEST_ASSERT(testToStringHelper(L"a/"));
- TEST_ASSERT(testToStringHelper(L"/a"));
- TEST_ASSERT(testToStringHelper(L"/a/"));
- TEST_ASSERT(testToStringHelper(L"abc"));
- TEST_ASSERT(testToStringHelper(L"abc/"));
- TEST_ASSERT(testToStringHelper(L"/abc"));
- TEST_ASSERT(testToStringHelper(L"/abc/"));
- TEST_ASSERT(testToStringHelper(L"a/def"));
- TEST_ASSERT(testToStringHelper(L"a/def/"));
- TEST_ASSERT(testToStringHelper(L"/a/def"));
- TEST_ASSERT(testToStringHelper(L"/a/def/"));
- TEST_ASSERT(testToStringHelper(L"abc/def"));
- TEST_ASSERT(testToStringHelper(L"abc/def/"));
- TEST_ASSERT(testToStringHelper(L"/abc/def"));
- TEST_ASSERT(testToStringHelper(L"/abc/def/"));
- TEST_ASSERT(testToStringHelper(L"/"));
- TEST_ASSERT(testToStringHelper(L"//a/"));
- TEST_ASSERT(testToStringHelper(L"."));
- TEST_ASSERT(testToStringHelper(L"./"));
- TEST_ASSERT(testToStringHelper(L"/."));
- TEST_ASSERT(testToStringHelper(L"/./"));
- TEST_ASSERT(testToStringHelper(L""));
- TEST_ASSERT(testToStringHelper(L"./abc/def"));
- TEST_ASSERT(testToStringHelper(L"?query"));
- TEST_ASSERT(testToStringHelper(L"#fragment"));
- TEST_ASSERT(testToStringHelper(L"?query#fragment"));
+ ASSERT_TRUE(testToStringHelper(L"a"));
+ ASSERT_TRUE(testToStringHelper(L"a/"));
+ ASSERT_TRUE(testToStringHelper(L"/a"));
+ ASSERT_TRUE(testToStringHelper(L"/a/"));
+ ASSERT_TRUE(testToStringHelper(L"abc"));
+ ASSERT_TRUE(testToStringHelper(L"abc/"));
+ ASSERT_TRUE(testToStringHelper(L"/abc"));
+ ASSERT_TRUE(testToStringHelper(L"/abc/"));
+ ASSERT_TRUE(testToStringHelper(L"a/def"));
+ ASSERT_TRUE(testToStringHelper(L"a/def/"));
+ ASSERT_TRUE(testToStringHelper(L"/a/def"));
+ ASSERT_TRUE(testToStringHelper(L"/a/def/"));
+ ASSERT_TRUE(testToStringHelper(L"abc/def"));
+ ASSERT_TRUE(testToStringHelper(L"abc/def/"));
+ ASSERT_TRUE(testToStringHelper(L"/abc/def"));
+ ASSERT_TRUE(testToStringHelper(L"/abc/def/"));
+ ASSERT_TRUE(testToStringHelper(L"/"));
+ ASSERT_TRUE(testToStringHelper(L"//a/"));
+ ASSERT_TRUE(testToStringHelper(L"."));
+ ASSERT_TRUE(testToStringHelper(L"./"));
+ ASSERT_TRUE(testToStringHelper(L"/."));
+ ASSERT_TRUE(testToStringHelper(L"/./"));
+ ASSERT_TRUE(testToStringHelper(L""));
+ ASSERT_TRUE(testToStringHelper(L"./abc/def"));
+ ASSERT_TRUE(testToStringHelper(L"?query"));
+ ASSERT_TRUE(testToStringHelper(L"#fragment"));
+ ASSERT_TRUE(testToStringHelper(L"?query#fragment"));
// Tests for bugs from the past
- TEST_ASSERT(testToStringHelper(L"f:/.//g"));
- }
+ ASSERT_TRUE(testToStringHelper(L"f:/.//g"));
+}
- void testToString_Bug1950126() {
+TEST(UriSuite, TestToStringBug1950126) {
UriParserStateW state;
UriUriW uriOne;
UriUriW uriTwo;
const wchar_t * const uriOneString = L"http://e.com/";
const wchar_t * const uriTwoString = L"http://e.com";
state.uri = &uriOne;
- TEST_ASSERT(URI_SUCCESS == uriParseUriW(&state, uriOneString));
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriW(&state, uriOneString));
state.uri = &uriTwo;
- TEST_ASSERT(URI_SUCCESS == uriParseUriW(&state, uriTwoString));
- TEST_ASSERT(URI_FALSE == uriEqualsUriW(&uriOne, &uriTwo));
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriW(&state, uriTwoString));
+ ASSERT_TRUE(URI_FALSE == uriEqualsUriW(&uriOne, &uriTwo));
uriFreeUriMembersW(&uriOne);
uriFreeUriMembersW(&uriTwo);
- TEST_ASSERT(testToStringHelper(uriOneString));
- TEST_ASSERT(testToStringHelper(uriTwoString));
- }
+ ASSERT_TRUE(testToStringHelper(uriOneString));
+ ASSERT_TRUE(testToStringHelper(uriTwoString));
+}
+namespace {
bool testToStringCharsRequiredHelper(const wchar_t * text) {
// Parse
UriParserStateW state;
@@ -1290,19 +1233,21 @@ Rule | Example | hostSet | absPath | emptySeg
delete [] buffer;
return true;
}
+} // namespace
+
+TEST(UriSuite, TestToStringCharsRequired) {
+ ASSERT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/"));
+ ASSERT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com:80/"));
+ ASSERT_TRUE(testToStringCharsRequiredHelper(L"http://user:pass@www.example.com/"));
+ ASSERT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/index.html"));
+ ASSERT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/?abc"));
+ ASSERT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/#def"));
+ ASSERT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/?abc#def"));
+ ASSERT_TRUE(testToStringCharsRequiredHelper(L"/test"));
+ ASSERT_TRUE(testToStringCharsRequiredHelper(L"test"));
+}
- void testToStringCharsRequired() {
- TEST_ASSERT(testToStringCharsRequiredHelper(L"http://www.example.com/"));
- TEST_ASSERT(testToStringCharsRequiredHelper(L"http://www.example.com:80/"));
- TEST_ASSERT(testToStringCharsRequiredHelper(L"http://user:pass@www.example.com/"));
- TEST_ASSERT(testToStringCharsRequiredHelper(L"http://www.example.com/index.html"));
- TEST_ASSERT(testToStringCharsRequiredHelper(L"http://www.example.com/?abc"));
- TEST_ASSERT(testToStringCharsRequiredHelper(L"http://www.example.com/#def"));
- TEST_ASSERT(testToStringCharsRequiredHelper(L"http://www.example.com/?abc#def"));
- TEST_ASSERT(testToStringCharsRequiredHelper(L"/test"));
- TEST_ASSERT(testToStringCharsRequiredHelper(L"test"));
- }
-
+namespace {
bool testNormalizeMaskHelper(const wchar_t * uriText, unsigned int expectedMask) {
UriParserStateW state;
UriUriW uri;
@@ -1333,17 +1278,19 @@ Rule | Example | hostSet | absPath | emptySeg
return (maskAfter == URI_NORMALIZED);
}
+} // namespace
- void testNormalizeSyntaxMaskRequired() {
- TEST_ASSERT(testNormalizeMaskHelper(L"http://localhost/", URI_NORMALIZED));
- TEST_ASSERT(testNormalizeMaskHelper(L"httP://localhost/", URI_NORMALIZE_SCHEME));
- TEST_ASSERT(testNormalizeMaskHelper(L"http://%0d@localhost/", URI_NORMALIZE_USER_INFO));
- TEST_ASSERT(testNormalizeMaskHelper(L"http://localhosT/", URI_NORMALIZE_HOST));
- TEST_ASSERT(testNormalizeMaskHelper(L"http://localhost/./abc", URI_NORMALIZE_PATH));
- TEST_ASSERT(testNormalizeMaskHelper(L"http://localhost/?AB%43", URI_NORMALIZE_QUERY));
- TEST_ASSERT(testNormalizeMaskHelper(L"http://localhost/#AB%43", URI_NORMALIZE_FRAGMENT));
- }
+TEST(UriSuite, TestNormalizeSyntaxMaskRequired) {
+ ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhost/", URI_NORMALIZED));
+ ASSERT_TRUE(testNormalizeMaskHelper(L"httP://localhost/", URI_NORMALIZE_SCHEME));
+ ASSERT_TRUE(testNormalizeMaskHelper(L"http://%0d@localhost/", URI_NORMALIZE_USER_INFO));
+ ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhosT/", URI_NORMALIZE_HOST));
+ ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhost/./abc", URI_NORMALIZE_PATH));
+ ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhost/?AB%43", URI_NORMALIZE_QUERY));
+ ASSERT_TRUE(testNormalizeMaskHelper(L"http://localhost/#AB%43", URI_NORMALIZE_FRAGMENT));
+}
+namespace {
bool testNormalizeSyntaxHelper(const wchar_t * uriText, const wchar_t * expectedNormalized,
unsigned int mask = static_cast<unsigned int>(-1)) {
UriParserStateW stateW;
@@ -1392,122 +1339,124 @@ Rule | Example | hostSet | absPath | emptySeg
uriFreeUriMembersW(&expectedUri);
return equalAfter;
}
+} // namespace
- void testNormalizeSyntax() {
- TEST_ASSERT(testNormalizeSyntaxHelper(
+TEST(UriSuite, TestNormalizeSyntax) {
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"eXAMPLE://a/./b/../b/%63/%7bfoo%7d",
L"example://a/b/c/%7Bfoo%7D"));
// Testcase by Adrian Manrique
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"http://examp%4Ce.com/",
L"http://example.com/"));
// Testcase by Adrian Manrique
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"http://example.com/a/b/%2E%2E/",
L"http://example.com/a/"));
// Reported by Adrian Manrique
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"http://user:pass@SOMEHOST.COM:123",
L"http://user:pass@somehost.com:123"));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"HTTP://a:b@HOST:123/./1/2/../%41?abc#def",
L"http://a:b@host:123/1/A?abc#def"));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"../../abc",
L"../../abc"));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"../../abc/..",
L"../../"));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"../../abc/../def",
L"../../def"));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"abc/..",
L""));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"abc/../",
L""));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"../../abc/./def",
L"../../abc/def"));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"./def",
L"def"));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"def/.",
L"def/"));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"./abc:def",
L"./abc:def"));
- }
+}
- void testNormalizeSyntaxComponents() {
- TEST_ASSERT(testNormalizeSyntaxHelper(
+TEST(UriSuite, TestNormalizeSyntaxComponents) {
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
L"http://%41@EXAMPLE.ORG/../a?%41#%41",
URI_NORMALIZE_SCHEME));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
L"HTTP://A@EXAMPLE.ORG/../a?%41#%41",
URI_NORMALIZE_USER_INFO));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
L"HTTP://%41@example.org/../a?%41#%41",
URI_NORMALIZE_HOST));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
L"HTTP://%41@EXAMPLE.ORG/a?%41#%41",
URI_NORMALIZE_PATH));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
L"HTTP://%41@EXAMPLE.ORG/../a?A#%41",
URI_NORMALIZE_QUERY));
- TEST_ASSERT(testNormalizeSyntaxHelper(
+ ASSERT_TRUE(testNormalizeSyntaxHelper(
L"HTTP://%41@EXAMPLE.ORG/../a?%41#%41",
L"HTTP://%41@EXAMPLE.ORG/../a?%41#A",
URI_NORMALIZE_FRAGMENT));
- }
+}
- void testNormalizeCrash_Bug20080224() {
+TEST(UriSuite, TestNormalizeCrashBug20080224) {
UriParserStateW stateW;
int res;
UriUriW testUri;
stateW.uri = &testUri;
res = uriParseUriW(&stateW, L"http://example.org/abc//../def");
- TEST_ASSERT(res == 0);
+ ASSERT_TRUE(res == 0);
// First call will make us owner of copied memory
res = uriNormalizeSyntaxExW(&testUri, URI_NORMALIZE_SCHEME);
- TEST_ASSERT(res == 0);
+ ASSERT_TRUE(res == 0);
res = uriNormalizeSyntaxExW(&testUri, URI_NORMALIZE_HOST);
- TEST_ASSERT(res == 0);
+ ASSERT_TRUE(res == 0);
// Frees empty path segment -> crash
res = uriNormalizeSyntaxW(&testUri);
- TEST_ASSERT(res == 0);
+ ASSERT_TRUE(res == 0);
uriFreeUriMembersW(&testUri);
- }
+}
+namespace {
void testFilenameUriConversionHelper(const wchar_t * filename,
const wchar_t * uriString, bool forUnix,
const wchar_t * expectedUriString = NULL) {
@@ -1527,7 +1476,7 @@ Rule | Example | hostSet | absPath | emptySeg
#ifdef HAVE_WPRINTF
// wprintf(L"1 [%s][%s]\n", uriBuffer, expectedUriString);
#endif
- TEST_ASSERT(!wcscmp(uriBuffer, expectedUriString));
+ ASSERT_TRUE(!wcscmp(uriBuffer, expectedUriString));
delete [] uriBuffer;
// URI string to filename
@@ -1541,11 +1490,12 @@ Rule | Example | hostSet | absPath | emptySeg
#ifdef HAVE_WPRINTF
// wprintf(L"2 [%s][%s]\n", filenameBuffer, filename);
#endif
- TEST_ASSERT(!wcscmp(filenameBuffer, filename));
+ ASSERT_TRUE(!wcscmp(filenameBuffer, filename));
delete [] filenameBuffer;
}
+} // namespace
- void testFilenameUriConversion() {
+TEST(UriSuite, TestFilenameUriConversion) {
const bool FOR_UNIX = true;
const bool FOR_WINDOWS = false;
testFilenameUriConversionHelper(L"/bin/bash", L"file:///bin/bash", FOR_UNIX);
@@ -1564,9 +1514,9 @@ Rule | Example | hostSet | absPath | emptySeg
testFilenameUriConversionHelper(L"abc def", L"abc%20def", FOR_UNIX);
testFilenameUriConversionHelper(L"\\\\Server01\\user\\docs\\Letter.txt", L"file://Server01/user/docs/Letter.txt", FOR_WINDOWS);
- }
+}
- void testCrash_FreeUriMembers_Bug20080116() {
+TEST(UriSuite, TestCrashFreeUriMembersBug20080116) {
// Testcase by Adrian Manrique
UriParserStateA state;
UriUriA uri;
@@ -1575,19 +1525,23 @@ Rule | Example | hostSet | absPath | emptySeg
uriNormalizeSyntaxA(&uri);
uriFreeUriMembersA(&uri);
- TEST_ASSERT(true);
- }
+ ASSERT_TRUE(true);
+}
+
+namespace {
+ void helperTestQueryString(char const * uriString, int pairsExpected);
+}
- void testCrash_Report2418192() {
+TEST(UriSuite, TestCrashReport2418192) {
// Testcase by Harvey Vrsalovic
helperTestQueryString("http://svcs.cnn.com/weather/wrapper.jsp?&csiID=csi1", 1);
- }
+}
- void testPervertedQueryString() {
+TEST(UriSuite, TestPervertedQueryString) {
helperTestQueryString("http://example.org/?&&=&&&=&&&&==&===&====", 5);
- }
+}
- void testQueryStringEndingInEqualSign_NonBug32() {
+TEST(UriSuite, TestQueryStringEndingInEqualSignNonBug32) {
const char * queryString = "firstname=sdsd&lastname=";
UriQueryListA * queryList = NULL;
@@ -1595,53 +1549,56 @@ Rule | Example | hostSet | absPath | emptySeg
const int res = uriDissectQueryMallocA(&queryList, &itemCount,
queryString, queryString + strlen(queryString));
- TEST_ASSERT(res == URI_SUCCESS);
- TEST_ASSERT(itemCount == 2);
- TEST_ASSERT(queryList != NULL);
- TEST_ASSERT(strcmp(queryList->key, "firstname") == 0);
- TEST_ASSERT(strcmp(queryList->value, "sdsd") == 0);
- TEST_ASSERT(strcmp(queryList->next->key, "lastname") == 0);
- TEST_ASSERT(strcmp(queryList->next->value, "") == 0);
- TEST_ASSERT(queryList->next->next == NULL);
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(itemCount == 2);
+ ASSERT_TRUE(queryList != NULL);
+ ASSERT_TRUE(strcmp(queryList->key, "firstname") == 0);
+ ASSERT_TRUE(strcmp(queryList->value, "sdsd") == 0);
+ ASSERT_TRUE(strcmp(queryList->next->key, "lastname") == 0);
+ ASSERT_TRUE(strcmp(queryList->next->value, "") == 0);
+ ASSERT_TRUE(queryList->next->next == NULL);
uriFreeQueryListA(queryList);
- }
+}
+namespace {
void helperTestQueryString(char const * uriString, int pairsExpected) {
UriParserStateA state;
UriUriA uri;
state.uri = &uri;
int res = uriParseUriA(&state, uriString);
- TEST_ASSERT(res == URI_SUCCESS);
+ ASSERT_TRUE(res == URI_SUCCESS);
UriQueryListA * queryList = NULL;
int itemCount = 0;
res = uriDissectQueryMallocA(&queryList, &itemCount,
uri.query.first, uri.query.afterLast);
- TEST_ASSERT(res == URI_SUCCESS);
- TEST_ASSERT(queryList != NULL);
- TEST_ASSERT(itemCount == pairsExpected);
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(queryList != NULL);
+ ASSERT_TRUE(itemCount == pairsExpected);
uriFreeQueryListA(queryList);
uriFreeUriMembersA(&uri);
}
+} // namespace
- void testCrash_MakeOwner_Bug20080207() {
+TEST(UriSuite, TestCrashMakeOwnerBug20080207) {
// Testcase by Adrian Manrique
UriParserStateA state;
UriUriA sourceUri;
state.uri = &sourceUri;
const char * const sourceUriString = "http://user:pass@somehost.com:80/";
if (uriParseUriA(&state, sourceUriString) != 0) {
- TEST_ASSERT(false);
+ ASSERT_TRUE(false);
}
if (uriNormalizeSyntaxA(&sourceUri) != 0) {
- TEST_ASSERT(false);
+ ASSERT_TRUE(false);
}
uriFreeUriMembersA(&sourceUri);
- TEST_ASSERT(true);
- }
+ ASSERT_TRUE(true);
+}
+namespace {
void testQueryListHelper(const wchar_t * input, int expectedItemCount) {
int res;
@@ -1653,49 +1610,51 @@ Rule | Example | hostSet | absPath | emptySeg
UriQueryListW * queryList;
res = uriDissectQueryMallocExW(&queryList, &itemCount,
input, input + wcslen(input), spacePlusConversion, breakConversion);
- TEST_ASSERT(res == URI_SUCCESS);
- TEST_ASSERT(itemCount == expectedItemCount);
- TEST_ASSERT((queryList == NULL) == (expectedItemCount == 0));
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(itemCount == expectedItemCount);
+ ASSERT_TRUE((queryList == NULL) == (expectedItemCount == 0));
if (expectedItemCount != 0) {
// First
int charsRequired;
res = uriComposeQueryCharsRequiredExW(queryList, &charsRequired, spacePlusConversion,
normalizeBreaks);
- TEST_ASSERT(res == URI_SUCCESS);
- TEST_ASSERT(charsRequired >= (int)wcslen(input));
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(charsRequired >= (int)wcslen(input));
wchar_t * recomposed = new wchar_t[charsRequired + 1];
int charsWritten;
res = uriComposeQueryExW(recomposed, queryList, charsRequired + 1,
&charsWritten, spacePlusConversion, normalizeBreaks);
- TEST_ASSERT(res == URI_SUCCESS);
- TEST_ASSERT(charsWritten <= charsRequired);
- TEST_ASSERT(charsWritten == (int)wcslen(input) + 1);
- TEST_ASSERT(!wcscmp(input, recomposed));
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(charsWritten <= charsRequired);
+ ASSERT_TRUE(charsWritten == (int)wcslen(input) + 1);
+ ASSERT_TRUE(!wcscmp(input, recomposed));
delete [] recomposed;
recomposed = NULL;
res = uriComposeQueryMallocW(&recomposed, queryList);
- TEST_ASSERT(res == URI_SUCCESS);
- TEST_ASSERT(recomposed != NULL);
- TEST_ASSERT(charsWritten == (int)wcslen(input) + 1);
- TEST_ASSERT(!wcscmp(input, recomposed));
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(recomposed != NULL);
+ ASSERT_TRUE(charsWritten == (int)wcslen(input) + 1);
+ ASSERT_TRUE(!wcscmp(input, recomposed));
free(recomposed);
}
uriFreeQueryListW(queryList);
}
+} // namespace
- void testQueryList() {
+TEST(UriSuite, QueryList) {
testQueryListHelper(L"one=ONE&two=TWO", 2);
testQueryListHelper(L"one=ONE&two=&three=THREE", 3);
testQueryListHelper(L"one=ONE&two&three=THREE", 3);
testQueryListHelper(L"one=ONE", 1);
testQueryListHelper(L"one", 1);
testQueryListHelper(L"", 0);
- }
+}
+namespace {
void testQueryListPairHelper(const char * pair, const char * unescapedKey,
const char * unescapedValue, const char * fixed = NULL) {
int res;
@@ -1703,53 +1662,101 @@ Rule | Example | hostSet | absPath | emptySeg
int itemCount;
res = uriDissectQueryMallocA(&queryList, &itemCount, pair, pair + strlen(pair));
- TEST_ASSERT(res == URI_SUCCESS);
- TEST_ASSERT(queryList != NULL);
- TEST_ASSERT(itemCount == 1);
- TEST_ASSERT(!strcmp(queryList->key, unescapedKey));
- TEST_ASSERT(!strcmp(queryList->value, unescapedValue));
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(queryList != NULL);
+ ASSERT_TRUE(itemCount == 1);
+ ASSERT_TRUE(!strcmp(queryList->key, unescapedKey));
+ ASSERT_TRUE(!strcmp(queryList->value, unescapedValue));
char * recomposed;
res = uriComposeQueryMallocA(&recomposed, queryList);
- TEST_ASSERT(res == URI_SUCCESS);
- TEST_ASSERT(recomposed != NULL);
- TEST_ASSERT(!strcmp(recomposed, (fixed != NULL) ? fixed : pair));
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(recomposed != NULL);
+ ASSERT_TRUE(!strcmp(recomposed, (fixed != NULL) ? fixed : pair));
free(recomposed);
uriFreeQueryListA(queryList);
}
+} // namespace
- void testQueryListPair() {
+TEST(UriSuite, TestQueryListPair) {
testQueryListPairHelper("one+two+%26+three=%2B", "one two & three", "+");
testQueryListPairHelper("one=two=three", "one", "two=three", "one=two%3Dthree");
testQueryListPairHelper("one=two=three=four", "one", "two=three=four", "one=two%3Dthree%3Dfour");
- }
+}
- void testQueryDissection_Bug3590761() {
+TEST(UriSuite, TestQueryDissectionBug3590761) {
int res;
UriQueryListA * queryList;
int itemCount;
const char * const pair = "q=hello&x=&y=";
res = uriDissectQueryMallocA(&queryList, &itemCount, pair, pair + strlen(pair));
- TEST_ASSERT(res == URI_SUCCESS);
- TEST_ASSERT(queryList != NULL);
- TEST_ASSERT(itemCount == 3);
+ ASSERT_TRUE(res == URI_SUCCESS);
+ ASSERT_TRUE(queryList != NULL);
+ ASSERT_TRUE(itemCount == 3);
- TEST_ASSERT(!strcmp(queryList->key, "q"));
- TEST_ASSERT(!strcmp(queryList->value, "hello"));
+ ASSERT_TRUE(!strcmp(queryList->key, "q"));
+ ASSERT_TRUE(!strcmp(queryList->value, "hello"));
- TEST_ASSERT(!strcmp(queryList->next->key, "x"));
- TEST_ASSERT(!strcmp(queryList->next->value, ""));
+ ASSERT_TRUE(!strcmp(queryList->next->key, "x"));
+ ASSERT_TRUE(!strcmp(queryList->next->value, ""));
- TEST_ASSERT(!strcmp(queryList->next->next->key, "y"));
- TEST_ASSERT(!strcmp(queryList->next->next->value, ""));
+ ASSERT_TRUE(!strcmp(queryList->next->next->key, "y"));
+ ASSERT_TRUE(!strcmp(queryList->next->next->value, ""));
- TEST_ASSERT(! queryList->next->next->next);
+ ASSERT_TRUE(! queryList->next->next->next);
uriFreeQueryListA(queryList);
- }
+}
+
+TEST(UriSuite, TestQueryCompositionMathCalc) {
+ UriQueryListA second = { /*.key =*/ "k2", /*.value =*/ "v2", /*.next =*/ NULL };
+ UriQueryListA first = { /*.key =*/ "k1", /*.value =*/ "v1", /*.next =*/ &second };
+
+ int charsRequired;
+ ASSERT_TRUE(uriComposeQueryCharsRequiredA(&first, &charsRequired)
+ == URI_SUCCESS);
+
+ const int FACTOR = 6; /* due to escaping with normalizeBreaks */
+ ASSERT_TRUE((unsigned)charsRequired ==
+ FACTOR * strlen(first.key) + 1 + FACTOR * strlen(first.value)
+ + 1
+ + FACTOR * strlen(second.key) + 1 + FACTOR * strlen(second.value)
+ );
+}
+
+TEST(UriSuite, TestQueryCompositionMathWriteGoogleAutofuzz113244572) {
+ UriQueryListA second = { /*.key =*/ "\x11", /*.value =*/ NULL, /*.next =*/ NULL };
+ UriQueryListA first = { /*.key =*/ "\x01", /*.value =*/ "\x02", /*.next =*/ &second };
+
+ const UriBool spaceToPlus = URI_TRUE;
+ const UriBool normalizeBreaks = URI_FALSE; /* for factor 3 but 6 */
+
+ const int charsRequired = (3 + 1 + 3) + 1 + (3);
+
+ {
+ // Minimum space to hold everything fine
+ const char * const expected = "%01=%02" "&" "%11";
+ char dest[charsRequired + 1];
+ int charsWritten;
+ ASSERT_TRUE(uriComposeQueryExA(dest, &first, sizeof(dest),
+ &charsWritten, spaceToPlus, normalizeBreaks)
+ == URI_SUCCESS);
+ ASSERT_TRUE(! strcmp(dest, expected));
+ ASSERT_TRUE(charsWritten == strlen(expected) + 1);
+ }
+
+ {
+ // Previous math failed to take ampersand into account
+ char dest[charsRequired + 1 - 1];
+ int charsWritten;
+ ASSERT_TRUE(uriComposeQueryExA(dest, &first, sizeof(dest),
+ &charsWritten, spaceToPlus, normalizeBreaks)
+ == URI_ERROR_OUTPUT_TOO_LARGE);
+ }
+}
- void testFreeCrash_Bug20080827() {
+TEST(UriSuite, TestFreeCrashBug20080827) {
char const * const sourceUri = "abc";
char const * const baseUri = "http://www.example.org/";
@@ -1761,21 +1768,21 @@ Rule | Example | hostSet | absPath | emptySeg
state.uri = &relativeSource;
res = uriParseUriA(&state, sourceUri);
- TEST_ASSERT(res == URI_SUCCESS);
+ ASSERT_TRUE(res == URI_SUCCESS);
state.uri = &absoluteBase;
res = uriParseUriA(&state, baseUri);
- TEST_ASSERT(res == URI_SUCCESS);
+ ASSERT_TRUE(res == URI_SUCCESS);
res = uriRemoveBaseUriA(&absoluteDest, &relativeSource, &absoluteBase, URI_FALSE);
- TEST_ASSERT(res == URI_ERROR_REMOVEBASE_REL_SOURCE);
+ ASSERT_TRUE(res == URI_ERROR_REMOVEBASE_REL_SOURCE);
uriFreeUriMembersA(&relativeSource);
uriFreeUriMembersA(&absoluteBase);
uriFreeUriMembersA(&absoluteDest); // Crashed here
- }
+}
- void testParseInvalid_Bug16() {
+TEST(UriSuite, TestInvalidInputBug16) {
UriParserStateA stateA;
UriUriA uriA;
stateA.uri = &uriA;
@@ -1783,27 +1790,29 @@ Rule | Example | hostSet | absPath | emptySeg
const int res = uriParseUriA(&stateA, input);
- TEST_ASSERT(res == URI_ERROR_SYNTAX);
- TEST_ASSERT(stateA.errorPos == input + 1);
- TEST_ASSERT(stateA.errorCode == URI_ERROR_SYNTAX); /* failed previously */
+ ASSERT_TRUE(res == URI_ERROR_SYNTAX);
+ ASSERT_TRUE(stateA.errorPos == input + 1);
+ ASSERT_TRUE(stateA.errorCode == URI_ERROR_SYNTAX); /* failed previously */
uriFreeUriMembersA(&uriA);
- }
+}
+namespace {
void testEqualsHelper(const char * uri_to_test) {
UriParserStateA state;
UriUriA uriOne;
UriUriA uriTwo;
state.uri = &uriOne;
- TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state, uri_to_test));
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, uri_to_test));
state.uri = &uriTwo;
- TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state, uri_to_test));
- TEST_ASSERT(URI_TRUE == uriEqualsUriA(&uriOne, &uriTwo));
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, uri_to_test));
+ ASSERT_TRUE(URI_TRUE == uriEqualsUriA(&uriOne, &uriTwo));
uriFreeUriMembersA(&uriOne);
uriFreeUriMembersA(&uriTwo);
}
+} // namespace
- void testEquals() {
+TEST(UriSuite, TestEquals) {
testEqualsHelper("http://host");
testEqualsHelper("http://host:123");
testEqualsHelper("http://foo:bar@host:123");
@@ -1818,81 +1827,82 @@ Rule | Example | hostSet | absPath | emptySeg
testEqualsHelper("//path/");
testEqualsHelper("//host");
testEqualsHelper("//host:123");
- }
+}
- void testHostTextTermination_Issue15() {
+TEST(UriSuite, TestHostTextTerminationIssue15) {
UriParserStateA state;
UriUriA uri;
state.uri = &uri;
// Empty host and port
const char * const emptyHostWithPortUri = "//:123";
- TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state, emptyHostWithPortUri));
- TEST_ASSERT(uri.hostText.first == emptyHostWithPortUri + strlen("//"));
- TEST_ASSERT(uri.hostText.afterLast == uri.hostText.first + 0);
- TEST_ASSERT(uri.portText.first == emptyHostWithPortUri
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, emptyHostWithPortUri));
+ ASSERT_TRUE(uri.hostText.first == emptyHostWithPortUri + strlen("//"));
+ ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first + 0);
+ ASSERT_TRUE(uri.portText.first == emptyHostWithPortUri
+ strlen("//:"));
- TEST_ASSERT(uri.portText.afterLast == uri.portText.first
+ ASSERT_TRUE(uri.portText.afterLast == uri.portText.first
+ strlen("123"));
uriFreeUriMembersA(&uri);
// Non-empty host and port
const char * const hostWithPortUri = "//h:123";
- TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state, hostWithPortUri));
- TEST_ASSERT(uri.hostText.first == hostWithPortUri + strlen("//"));
- TEST_ASSERT(uri.hostText.afterLast == uri.hostText.first
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, hostWithPortUri));
+ ASSERT_TRUE(uri.hostText.first == hostWithPortUri + strlen("//"));
+ ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first
+ strlen("h"));
- TEST_ASSERT(uri.portText.first == hostWithPortUri + strlen("//h:"));
- TEST_ASSERT(uri.portText.afterLast == uri.portText.first
+ ASSERT_TRUE(uri.portText.first == hostWithPortUri + strlen("//h:"));
+ ASSERT_TRUE(uri.portText.afterLast == uri.portText.first
+ strlen("123"));
uriFreeUriMembersA(&uri);
// Empty host, empty user info
const char * const emptyHostEmptyUserInfoUri = "//@";
- TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state,
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state,
emptyHostEmptyUserInfoUri));
- TEST_ASSERT(uri.userInfo.first == emptyHostEmptyUserInfoUri
+ ASSERT_TRUE(uri.userInfo.first == emptyHostEmptyUserInfoUri
+ strlen("//"));
- TEST_ASSERT(uri.userInfo.afterLast == uri.userInfo.first + 0);
- TEST_ASSERT(uri.hostText.first == emptyHostEmptyUserInfoUri
+ ASSERT_TRUE(uri.userInfo.afterLast == uri.userInfo.first + 0);
+ ASSERT_TRUE(uri.hostText.first == emptyHostEmptyUserInfoUri
+ strlen("//@"));
- TEST_ASSERT(uri.hostText.afterLast == uri.hostText.first + 0);
+ ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first + 0);
uriFreeUriMembersA(&uri);
// Non-empty host, empty user info
const char * const hostEmptyUserInfoUri = "//@h";
- TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state, hostEmptyUserInfoUri));
- TEST_ASSERT(uri.userInfo.first == hostEmptyUserInfoUri + strlen("//"));
- TEST_ASSERT(uri.userInfo.afterLast == uri.userInfo.first + 0);
- TEST_ASSERT(uri.hostText.first == hostEmptyUserInfoUri
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, hostEmptyUserInfoUri));
+ ASSERT_TRUE(uri.userInfo.first == hostEmptyUserInfoUri + strlen("//"));
+ ASSERT_TRUE(uri.userInfo.afterLast == uri.userInfo.first + 0);
+ ASSERT_TRUE(uri.hostText.first == hostEmptyUserInfoUri
+ strlen("//@"));
- TEST_ASSERT(uri.hostText.afterLast == uri.hostText.first
+ ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first
+ strlen("h"));
uriFreeUriMembersA(&uri);
// Empty host, non-empty user info
const char * const emptyHostWithUserInfoUri = "//:@";
- TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state,
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state,
emptyHostWithUserInfoUri));
- TEST_ASSERT(uri.userInfo.first == emptyHostWithUserInfoUri
+ ASSERT_TRUE(uri.userInfo.first == emptyHostWithUserInfoUri
+ strlen("//"));
- TEST_ASSERT(uri.userInfo.afterLast == uri.userInfo.first + 1);
- TEST_ASSERT(uri.hostText.first == emptyHostWithUserInfoUri
+ ASSERT_TRUE(uri.userInfo.afterLast == uri.userInfo.first + 1);
+ ASSERT_TRUE(uri.hostText.first == emptyHostWithUserInfoUri
+ strlen("//:@"));
- TEST_ASSERT(uri.hostText.afterLast == uri.hostText.first + 0);
+ ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first + 0);
uriFreeUriMembersA(&uri);
// Exact case from issue #15
const char * const issue15Uri = "//:%aa@";
- TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state, issue15Uri));
- TEST_ASSERT(uri.userInfo.first == issue15Uri + strlen("//"));
- TEST_ASSERT(uri.userInfo.afterLast == uri.userInfo.first
+ ASSERT_TRUE(URI_SUCCESS == uriParseUriA(&state, issue15Uri));
+ ASSERT_TRUE(uri.userInfo.first == issue15Uri + strlen("//"));
+ ASSERT_TRUE(uri.userInfo.afterLast == uri.userInfo.first
+ strlen(":%aa"));
- TEST_ASSERT(uri.hostText.first == issue15Uri + strlen("//:%aa@"));
- TEST_ASSERT(uri.hostText.afterLast == uri.hostText.first + 0);
+ ASSERT_TRUE(uri.hostText.first == issue15Uri + strlen("//:%aa@"));
+ ASSERT_TRUE(uri.hostText.afterLast == uri.hostText.first + 0);
uriFreeUriMembersA(&uri);
- }
+}
+namespace {
void testCompareRangeHelper(const char * a, const char * b, int expected, bool avoidNullRange = true) {
UriTextRangeA ra;
UriTextRangeA rb;
@@ -1920,10 +1930,11 @@ Rule | Example | hostSet | absPath | emptySeg
printf("Comparing <%s> to <%s> yields %d, expected %d.\n",
a, b, received, expected);
}
- TEST_ASSERT(received == expected);
+ ASSERT_TRUE(received == expected);
}
+} // namespace
- void testRangeComparison() {
+TEST(UriSuite, TestRangeComparison) {
testCompareRangeHelper("", "", 0);
testCompareRangeHelper("a", "", 1);
testCompareRangeHelper("", "a", -1);
@@ -1947,8 +1958,9 @@ Rule | Example | hostSet | absPath | emptySeg
testCompareRangeHelper(NULL, "", -1, KEEP_NULL_RANGE);
testCompareRangeHelper("", NULL, 1, AVOID_NULL_RANGE);
testCompareRangeHelper("", NULL, 1, KEEP_NULL_RANGE);
- }
+}
+namespace {
void testRemoveBaseUriHelper(const char * expected,
const char * absSourceStr,
const char * absBaseStr) {
@@ -1958,28 +1970,33 @@ Rule | Example | hostSet | absPath | emptySeg
UriUriA dest;
state.uri = &absSource;
- TEST_ASSERT(uriParseUriA(&state, absSourceStr) == URI_SUCCESS);
+ ASSERT_TRUE(uriParseUriA(&state, absSourceStr) == URI_SUCCESS);
state.uri = &absBase;
- TEST_ASSERT(uriParseUriA(&state, absBaseStr) == URI_SUCCESS);
+ ASSERT_TRUE(uriParseUriA(&state, absBaseStr) == URI_SUCCESS);
- TEST_ASSERT(uriRemoveBaseUriA(&dest, &absSource, &absBase, URI_FALSE)
+ ASSERT_TRUE(uriRemoveBaseUriA(&dest, &absSource, &absBase, URI_FALSE)
== URI_SUCCESS);
int size = 0;
- TEST_ASSERT(uriToStringCharsRequiredA(&dest, &size) == URI_SUCCESS);
+ ASSERT_TRUE(uriToStringCharsRequiredA(&dest, &size) == URI_SUCCESS);
char * const buffer = (char *)malloc(size + 1);
- TEST_ASSERT(buffer);
- TEST_ASSERT(uriToStringA(buffer, &dest, size + 1, &size)
+ ASSERT_TRUE(buffer);
+ ASSERT_TRUE(uriToStringA(buffer, &dest, size + 1, &size)
== URI_SUCCESS);
if (strcmp(buffer, expected)) {
printf("Expected \"%s\" but got \"%s\"\n", expected, buffer);
- TEST_ASSERT(0);
+ ASSERT_TRUE(0);
}
free(buffer);
+
+ uriFreeUriMembersA(&absSource);
+ uriFreeUriMembersA(&absBase);
+ uriFreeUriMembersA(&dest);
}
+} // namespace
- void testRangeComparison_RemoveBaseUri_Issue19() {
+TEST(UriSuite, TestRangeComparisonRemoveBaseUriIssue19) {
// scheme
testRemoveBaseUriHelper("scheme://host/source",
"scheme://host/source",
@@ -2022,15 +2039,77 @@ Rule | Example | hostSet | absPath | emptySeg
testRemoveBaseUriHelper("//example/x/abc",
"http://example/x/abc",
"http://example2/x/y/z");
- }
-};
+}
+
+TEST(UriParseSingleSuite, Success) {
+ UriUriA uri;
+
+ EXPECT_EQ(uriParseSingleUriA(&uri, "file:///home/user/song.mp3", NULL),
+ URI_SUCCESS);
+
+ uriFreeUriMembersA(&uri);
+}
+
+TEST(UriParseSingleSuite, ErrorSyntaxParseErrorSetsErrorPos) {
+ UriUriA uri;
+ const char * errorPos;
+ const char * const uriString = "abc{}def";
+
+ EXPECT_EQ(uriParseSingleUriA(&uri, uriString, &errorPos),
+ URI_ERROR_SYNTAX);
+ EXPECT_EQ(errorPos, uriString + strlen("abc"));
+
+ uriFreeUriMembersA(&uri);
+}
+
+TEST(UriParseSingleSuite, ErrorNullFirstDetected) {
+ UriUriA uri;
+ const char * errorPos;
+
+ EXPECT_EQ(uriParseSingleUriExA(&uri, NULL, "notnull", &errorPos),
+ URI_ERROR_NULL);
+}
+
+TEST(UriParseSingleSuite, ErrorNullAfterLastDetected) {
+ UriUriA uri;
+
+ EXPECT_EQ(uriParseSingleUriExA(&uri, "foo", NULL, NULL), URI_SUCCESS);
+
+ uriFreeUriMembersA(&uri);
+}
+
+TEST(UriParseSingleSuite, ErrorNullMemoryManagerDetected) {
+ UriUriA uri;
+ const char * errorPos;
+ const char * const uriString = "somethingwellformed";
+
+ EXPECT_EQ(uriParseSingleUriExMmA(&uri,
+ uriString,
+ uriString + strlen(uriString),
+ &errorPos, NULL), URI_SUCCESS);
+
+ EXPECT_EQ(uriFreeUriMembersMmA(&uri, NULL), URI_SUCCESS);
+}
+
+TEST(FreeUriMembersSuite, MultiFreeWorksFine) {
+ UriUriA uri;
+
+ EXPECT_EQ(uriParseSingleUriA(&uri, "file:///home/user/song.mp3", NULL),
+ URI_SUCCESS);
+
+ UriUriA uriBackup = uri;
+ EXPECT_EQ(memcmp(&uriBackup, &uri, sizeof(UriUriA)), 0);
+
+ uriFreeUriMembersA(&uri);
+
+ // Did some pointers change (to NULL)?
+ EXPECT_NE(memcmp(&uriBackup, &uri, sizeof(UriUriA)), 0);
+
+ uriFreeUriMembersA(&uri); // second time
+}
-int main() {
- Suite suite;
- suite.add(auto_ptr<Suite>(new UriSuite()));
- suite.add(auto_ptr<Suite>(new FourSuite()));
- suite.add(auto_ptr<Suite>(new VersionSuite()));
- TextOutput output(TextOutput::Verbose);
- return suite.run(output, false) ? 0 : 1;
+int main(int argc, char ** argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
}