summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/VersionSuite.cpp8
-rw-r--r--test/test.cpp52
2 files changed, 45 insertions, 15 deletions
diff --git a/test/VersionSuite.cpp b/test/VersionSuite.cpp
index fb28c15..c85bbd2 100644
--- a/test/VersionSuite.cpp
+++ b/test/VersionSuite.cpp
@@ -20,9 +20,6 @@
#include <gtest/gtest.h>
-#ifndef _GNU_SOURCE
-# define _GNU_SOURCE // for asprintf
-#endif
#include <stdio.h>
@@ -31,8 +28,8 @@
TEST(VersionSuite, EnsureVersionDefinesInSync) {
- char * INSIDE_VERSION = NULL;
- const int bytes_printed = asprintf(&INSIDE_VERSION, "%d.%d.%d%s",
+ char INSIDE_VERSION[256];
+ const int bytes_printed = sprintf(INSIDE_VERSION, "%d.%d.%d%s",
URI_VER_MAJOR, URI_VER_MINOR, URI_VER_RELEASE, URI_VER_SUFFIX_ANSI);
ASSERT_TRUE(bytes_printed != -1);
@@ -42,6 +39,5 @@ TEST(VersionSuite, EnsureVersionDefinesInSync) {
printf(" Tarball version: <%s>\n", PACKAGE_VERSION);
printf(" Header defines version: <%s>\n", INSIDE_VERSION);
}
- free(INSIDE_VERSION);
ASSERT_TRUE(equal);
}
diff --git a/test/test.cpp b/test/test.cpp
index 78fd980..7a68c39 100644
--- a/test/test.cpp
+++ b/test/test.cpp
@@ -242,6 +242,19 @@ TEST(UriSuite, TestIpSixFail) {
URI_TEST_IP_SIX_FAIL("g:0:0:0:0:0:0");
}
+TEST(UriSuite, TestIpSixOverread) {
+ UriUriA uri;
+ const char * errorPos;
+
+ // NOTE: This string is designed to not have a terminator
+ char uriText[2 + 3 + 2 + 1 + 1];
+ strncpy(uriText, "//[::44.1", sizeof(uriText));
+
+ EXPECT_EQ(uriParseSingleUriExA(&uri, uriText,
+ uriText + sizeof(uriText), &errorPos), URI_ERROR_SYNTAX);
+ EXPECT_EQ(errorPos, uriText + sizeof(uriText));
+}
+
TEST(UriSuite, TestUri) {
UriParserStateA stateA;
UriParserStateW stateW;
@@ -1214,6 +1227,8 @@ namespace {
return false;
}
+ EXPECT_EQ(charsRequired, wcslen(text));
+
// Minimum
wchar_t * buffer = new wchar_t[charsRequired + 1];
if (uriToStringW(buffer, &uri, charsRequired + 1, NULL) != 0) {
@@ -1236,15 +1251,24 @@ namespace {
} // 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"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.1.1/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://12.1.1.1/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://123.1.1.1/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.12.1.1/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.123.1.1/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.12.1/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.123.1/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.1.12/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://1.1.1.123/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com:80/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://user:pass@www.example.com/"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/index.html"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/?abc"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/#def"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"http://www.example.com/?abc#def"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"/test"));
+ EXPECT_TRUE(testToStringCharsRequiredHelper(L"test"));
}
namespace {
@@ -2041,6 +2065,16 @@ TEST(UriSuite, TestRangeComparisonRemoveBaseUriIssue19) {
"http://example2/x/y/z");
}
+TEST(ErrorPosSuite, TestErrorPosIPvFuture) {
+ UriUriA uri;
+ const char * errorPos;
+
+ const char * const uriText = "http://[vA.123456"; // missing "]"
+ EXPECT_EQ(uriParseSingleUriA(&uri, uriText, &errorPos),
+ URI_ERROR_SYNTAX);
+ EXPECT_EQ(errorPos, uriText + strlen(uriText));
+}
+
TEST(UriParseSingleSuite, Success) {
UriUriA uri;