summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhsoting.net>2014-10-20 18:43:39 +0200
committerJörg Frings-Fürst <debian@jff-webhsoting.net>2014-10-20 18:43:39 +0200
commit7cf57ee38648ce5729b97209e4bf87ae92c726b6 (patch)
tree7a1e89b9c5e85db7ecd736cb0fa375277de8def1 /test
parent58048f62e9ce8d1754192edd702f7f3bbcea24c6 (diff)
parentc3ccf5e3e6737f81863b085289fd830e732b41f9 (diff)
Merge tag 'upstream/0.8.1'
Upstream version 0.8.1
Diffstat (limited to 'test')
-rw-r--r--test/VersionSuite.cpp48
-rw-r--r--test/VersionSuite.h46
-rw-r--r--test/config.h.in65
-rw-r--r--test/test.cpp91
4 files changed, 248 insertions, 2 deletions
diff --git a/test/VersionSuite.cpp b/test/VersionSuite.cpp
new file mode 100644
index 0000000..82deddc
--- /dev/null
+++ b/test/VersionSuite.cpp
@@ -0,0 +1,48 @@
+/*
+ * uriparser - RFC 3986 URI parsing library
+ *
+ * Copyright (C) 2014, Sebastian Pipping <webmaster@hartwork.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 "VersionSuite.h"
+
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE // for asprintf
+#endif
+#include <stdio.h>
+
+
+#include <config.h> // for PACKAGE_VERSION
+#include <uriparser/UriBase.h>
+
+
+void VersionSuite::ensure_version_defines_in_sync() {
+ 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);
+
+ const bool equal = !strcmp(INSIDE_VERSION, PACKAGE_VERSION);
+ if (! equal) {
+ printf("Inside/outside version mismatch detected:\n");
+ printf(" Tarball version: <%s>\n", PACKAGE_VERSION);
+ printf(" Header defines version: <%s>\n", INSIDE_VERSION);
+ }
+ free(INSIDE_VERSION);
+ TEST_ASSERT(equal);
+}
diff --git a/test/VersionSuite.h b/test/VersionSuite.h
new file mode 100644
index 0000000..495d3fc
--- /dev/null
+++ b/test/VersionSuite.h
@@ -0,0 +1,46 @@
+/*
+ * uriparser - RFC 3986 URI parsing library
+ *
+ * Copyright (C) 2014, Sebastian Pipping <webmaster@hartwork.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
new file mode 100644
index 0000000..1ffe789
--- /dev/null
+++ b/test/config.h.in
@@ -0,0 +1,65 @@
+/* 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 in which 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 8eef547..915532f 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -26,6 +26,7 @@
#include <wchar.h>
#include "FourSuite.h"
+#include "VersionSuite.h"
using namespace Test;
using namespace std;
@@ -35,6 +36,7 @@ using namespace std;
extern "C" {
UriBool uri_TESTING_ONLY_ParseIpSixA(const char * text);
UriBool uri_TESTING_ONLY_ParseIpFourA(const char * text);
+int uriCompareRangeA(const UriTextRangeA * a, const UriTextRangeA * b);
}
@@ -102,6 +104,8 @@ public:
TEST_ADD(UriSuite::testQueryDissection_Bug3590761)
TEST_ADD(UriSuite::testFreeCrash_Bug20080827)
TEST_ADD(UriSuite::testParseInvalid_Bug16)
+ TEST_ADD(UriSuite::testRangeComparison)
+ TEST_ADD(UriSuite::testEquals)
}
private:
@@ -976,7 +980,7 @@ Rule | Example | hostSet | absPath | emptySeg
TEST_ASSERT(testUnescapingHelper(L"%0a%0d%0a%0d", L"\x0a\x0d\x0a\x0d", PLUS_DONT_TOUCH, URI_BR_DONT_TOUCH));
}
- bool testAddBaseHelper(const wchar_t * base, const wchar_t * rel, const wchar_t * expectedResult) {
+ bool testAddBaseHelper(const wchar_t * base, const wchar_t * rel, const wchar_t * expectedResult, bool backward_compatibility = false) {
UriParserStateW stateW;
// Base
@@ -1011,7 +1015,12 @@ Rule | Example | hostSet | absPath | emptySeg
// Transform
UriUriW transformedUri;
- res = uriAddBaseUriW(&transformedUri, &relUri, &baseUri);
+ if (backward_compatibility) {
+ res = uriAddBaseUriExW(&transformedUri, &relUri, &baseUri, URI_RESOLVE_IDENTICAL_SCHEME_COMPAT);
+ } else {
+ res = uriAddBaseUriW(&transformedUri, &relUri, &baseUri);
+ }
+
if (res != 0) {
uriFreeUriMembersW(&baseUri);
uriFreeUriMembersW(&relUri);
@@ -1101,6 +1110,12 @@ Rule | Example | hostSet | absPath | emptySeg
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"));
+ // 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));
+
// 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/"));
@@ -1738,6 +1753,77 @@ Rule | Example | hostSet | absPath | emptySeg
uriFreeUriMembersA(&uriA);
}
+
+ 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));
+ state.uri = &uriTwo;
+ TEST_ASSERT(URI_SUCCESS == uriParseUriA(&state, uri_to_test));
+ TEST_ASSERT(URI_TRUE == uriEqualsUriA(&uriOne, &uriTwo));
+ uriFreeUriMembersA(&uriOne);
+ uriFreeUriMembersA(&uriTwo);
+ }
+
+ void testEquals() {
+ testEqualsHelper("http://host");
+ testEqualsHelper("http://host:123");
+ testEqualsHelper("http://foo:bar@host:123");
+ testEqualsHelper("http://foo:bar@host:123/");
+ testEqualsHelper("http://foo:bar@host:123/path");
+ testEqualsHelper("http://foo:bar@host:123/path?query");
+ testEqualsHelper("http://foo:bar@host:123/path?query#fragment");
+
+ testEqualsHelper("path");
+ testEqualsHelper("/path");
+ testEqualsHelper("/path/");
+ testEqualsHelper("//path/");
+ testEqualsHelper("//host");
+ testEqualsHelper("//host:123");
+ }
+
+ void testCompareRangeHelper(const char * a, const char * b, int expected) {
+ UriTextRangeA ra;
+ UriTextRangeA rb;
+
+ if (a) {
+ ra.first = a;
+ ra.afterLast = a + strlen(a);
+ }
+ if (b) {
+ rb.first = b;
+ rb.afterLast = b + strlen(b);
+ }
+
+ const int received = uriCompareRangeA(
+ (a == NULL) ? NULL : &ra,
+ (b == NULL) ? NULL : &rb);
+ if (received != expected) {
+ printf("Comparing <%s> to <%s> yields %d, expected %d.\n",
+ a, b, received, expected);
+ }
+ TEST_ASSERT(received == expected);
+ }
+
+ void testRangeComparison() {
+ testCompareRangeHelper("", "", 0);
+ testCompareRangeHelper("a", "", 1);
+ testCompareRangeHelper("", "a", -1);
+
+ testCompareRangeHelper("a", "a", 0);
+ testCompareRangeHelper("a", "b", -1);
+ testCompareRangeHelper("b", "a", 1);
+
+ testCompareRangeHelper("a", "aa", -1);
+ testCompareRangeHelper("aa", "a", 1);
+
+ // Fixed with 0.8.1:
+ testCompareRangeHelper(NULL, "a", -1);
+ testCompareRangeHelper("a", NULL, 1);
+ testCompareRangeHelper(NULL, NULL, 0);
+ }
};
@@ -1746,6 +1832,7 @@ 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;
}