summaryrefslogtreecommitdiff
path: root/test/test.cpp
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhsoting.net>2020-06-01 18:51:16 +0200
committerJörg Frings-Fürst <debian@jff-webhsoting.net>2020-06-01 18:51:16 +0200
commit9a2dfe455d3ccf649e2a0f78a50927580bcbbe19 (patch)
tree34bde47bb4e1c2a05a6d6cda3cb475754d2eb515 /test/test.cpp
parentb08941cd7113d882790c7d62edb59f31649daadd (diff)
New upstream version 0.9.4upstream/0.9.4
Diffstat (limited to 'test/test.cpp')
-rw-r--r--test/test.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/test/test.cpp b/test/test.cpp
index 728e57b..9a189f9 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -46,6 +46,24 @@ int uriCompareRangeA(const UriTextRangeA * a, const UriTextRangeA * b);
#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 "]"))
+#define URI_EXPECT_BETWEEN(candidate, first, afterLast) \
+ EXPECT_TRUE((candidate >= first) && (candidate <= afterLast))
+
+#define URI_EXPECT_OUTSIDE(candidate, first, afterLast) \
+ EXPECT_TRUE((candidate < first) || (candidate > afterLast))
+
+#define URI_EXPECT_RANGE_BETWEEN(range, uriFirst, uriAfterLast) \
+ URI_EXPECT_BETWEEN(range.first, uriFirst, uriAfterLast); \
+ URI_EXPECT_BETWEEN(range.afterLast, uriFirst, uriAfterLast)
+
+#define URI_EXPECT_RANGE_OUTSIDE(range, uriFirst, uriAfterLast) \
+ URI_EXPECT_OUTSIDE(range.first, uriFirst, uriAfterLast); \
+ URI_EXPECT_OUTSIDE(range.afterLast, uriFirst, uriAfterLast)
+
+#define URI_EXPECT_RANGE_EMPTY(range) \
+ EXPECT_TRUE((range.first != NULL) \
+ && (range.afterLast != NULL) \
+ && (range.first == range.afterLast))
namespace {
bool testDistinctionHelper(const char * uriText, bool expectedHostSet,
@@ -2143,6 +2161,65 @@ TEST(FreeUriMembersSuite, MultiFreeWorksFine) {
uriFreeUriMembersA(&uri); // second time
}
+TEST(MakeOwnerSuite, MakeOwner) {
+ const char * const uriString = "scheme://user:pass@[v7.X]:55555/path/../path/?query#fragment";
+ UriUriA uri;
+ char * uriFirst = strdup(uriString);
+ const size_t uriLen = strlen(uriFirst);
+ char * uriAfterLast = uriFirst + uriLen;
+
+ EXPECT_EQ(uriParseSingleUriExA(&uri, uriFirst, uriAfterLast, NULL), URI_SUCCESS);
+
+ // After plain parse, all strings should point inside the original URI string
+ EXPECT_EQ(uri.owner, URI_FALSE);
+ URI_EXPECT_RANGE_BETWEEN(uri.scheme, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.userInfo, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.hostText, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.hostData.ipFuture, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.portText, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.pathHead->text, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.pathHead->next->text, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.pathHead->next->next->text, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_EMPTY(uri.pathHead->next->next->next->text);
+ EXPECT_TRUE(uri.pathHead->next->next->next->next == NULL);
+ URI_EXPECT_RANGE_BETWEEN(uri.query, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_BETWEEN(uri.fragment, uriFirst, uriAfterLast);
+
+ EXPECT_EQ(uriMakeOwnerA(&uri), URI_SUCCESS);
+
+ // After making owner, *none* of the strings should point inside the original URI string
+ EXPECT_EQ(uri.owner, URI_TRUE);
+ URI_EXPECT_RANGE_OUTSIDE(uri.scheme, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.userInfo, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.hostText, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.hostData.ipFuture, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.portText, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.pathHead->text, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.pathHead->next->text, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.pathHead->next->next->text, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_EMPTY(uri.pathHead->next->next->next->text);
+ EXPECT_TRUE(uri.pathHead->next->next->next->next == NULL);
+ URI_EXPECT_RANGE_OUTSIDE(uri.query, uriFirst, uriAfterLast);
+ URI_EXPECT_RANGE_OUTSIDE(uri.fragment, uriFirst, uriAfterLast);
+
+ // Free originally used memory so we'd get violations on access with ASan
+ uriAfterLast = NULL;
+ free(uriFirst);
+ uriFirst = NULL;
+
+ // Can we recompose the URI without accessing any old freed memory?
+ int charsRequired;
+ EXPECT_EQ(uriToStringCharsRequiredA(&uri, &charsRequired), URI_SUCCESS);
+ EXPECT_TRUE((charsRequired >= 0) && (charsRequired >= static_cast<int>(uriLen)));
+ char * const uriRemake = new char[charsRequired + 1];
+ EXPECT_TRUE(uriRemake != NULL);
+ EXPECT_EQ(uriToStringA(uriRemake, &uri, charsRequired + 1, NULL), URI_SUCCESS);
+ EXPECT_TRUE(! strcmp(uriString, uriRemake));
+ delete [] uriRemake;
+
+ uriFreeUriMembersA(&uri);
+}
+
TEST(ParseIpFourAddressSuite, FourSaneOctets) {
unsigned char octetOutput[4];
const char * const ipAddressText = "111.22.3.40";