aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/Makefile.inc8
-rw-r--r--tests/unit/unit1304.c51
-rw-r--r--tests/unit/unit1397.c4
-rw-r--r--tests/unit/unit1398.c4
-rw-r--r--tests/unit/unit1399.c4
-rw-r--r--tests/unit/unit1604.c28
-rw-r--r--tests/unit/unit1650.c12
-rw-r--r--tests/unit/unit1652.c133
-rw-r--r--tests/unit/unit1653.c129
9 files changed, 335 insertions, 38 deletions
diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc
index 95d6cb44..8b1a6071 100644
--- a/tests/unit/Makefile.inc
+++ b/tests/unit/Makefile.inc
@@ -11,7 +11,7 @@ UNITPROGS = unit1300 unit1301 unit1302 unit1303 unit1304 unit1305 unit1307 \
unit1399 \
unit1600 unit1601 unit1602 unit1603 unit1604 unit1605 unit1606 unit1607 \
unit1608 unit1609 unit1620 \
- unit1650 unit1651
+ unit1650 unit1651 unit1652 unit1653
unit1300_SOURCES = unit1300.c $(UNITFILES)
unit1300_CPPFLAGS = $(AM_CPPFLAGS)
@@ -105,3 +105,9 @@ unit1650_CPPFLAGS = $(AM_CPPFLAGS)
unit1651_SOURCES = unit1651.c $(UNITFILES)
unit1651_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1652_SOURCES = unit1652.c $(UNITFILES)
+unit1652_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1653_SOURCES = unit1653.c $(UNITFILES)
+unit1653_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/tests/unit/unit1304.c b/tests/unit/unit1304.c
index 83375f55..6d8334c9 100644
--- a/tests/unit/unit1304.c
+++ b/tests/unit/unit1304.c
@@ -47,6 +47,8 @@ static void unit_stop(void)
UNITTEST_START
int result;
+ bool login_changed;
+ bool password_changed;
static const char * const filename1 = "log/netrc1304";
memcpy(filename, filename1, strlen(filename1));
@@ -54,7 +56,8 @@ UNITTEST_START
/*
* Test a non existent host in our netrc file.
*/
- result = Curl_parsenetrc("test.example.com", &login, &password, filename);
+ result = Curl_parsenetrc("test.example.com", &login, &password,
+ &login_changed, &password_changed, filename);
fail_unless(result == 1, "Host not found should return 1");
abort_unless(password != NULL, "returned NULL!");
fail_unless(password[0] == 0, "password should not have been changed");
@@ -67,13 +70,16 @@ UNITTEST_START
free(login);
login = strdup("me");
abort_unless(login != NULL, "returned NULL!");
- result = Curl_parsenetrc("example.com", &login, &password, filename);
- fail_unless(result == 0, "Host should be found");
+ result = Curl_parsenetrc("example.com", &login, &password,
+ &login_changed, &password_changed, filename);
+ fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(password[0] == 0, "password should not have been changed");
+ fail_unless(!password_changed, "password should not have been changed");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "me", 2) == 0,
"login should not have been changed");
+ fail_unless(!login_changed, "login should not have been changed");
/*
* Test a non existent login and host in our netrc file.
@@ -81,8 +87,9 @@ UNITTEST_START
free(login);
login = strdup("me");
abort_unless(login != NULL, "returned NULL!");
- result = Curl_parsenetrc("test.example.com", &login, &password, filename);
- fail_unless(result == 1, "Host should be found");
+ result = Curl_parsenetrc("test.example.com", &login, &password,
+ &login_changed, &password_changed, filename);
+ fail_unless(result == 1, "Host not found should return 1");
abort_unless(password != NULL, "returned NULL!");
fail_unless(password[0] == 0, "password should not have been changed");
abort_unless(login != NULL, "returned NULL!");
@@ -96,13 +103,16 @@ UNITTEST_START
free(login);
login = strdup("admi");
abort_unless(login != NULL, "returned NULL!");
- result = Curl_parsenetrc("example.com", &login, &password, filename);
- fail_unless(result == 0, "Host should be found");
+ result = Curl_parsenetrc("example.com", &login, &password,
+ &login_changed, &password_changed, filename);
+ fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(password[0] == 0, "password should not have been changed");
+ fail_unless(!password_changed, "password should not have been changed");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "admi", 4) == 0,
"login should not have been changed");
+ fail_unless(!login_changed, "login should not have been changed");
/*
* Test a non existent login (superstring of an existing one)
@@ -111,13 +121,16 @@ UNITTEST_START
free(login);
login = strdup("adminn");
abort_unless(login != NULL, "returned NULL!");
- result = Curl_parsenetrc("example.com", &login, &password, filename);
- fail_unless(result == 0, "Host should be found");
+ result = Curl_parsenetrc("example.com", &login, &password,
+ &login_changed, &password_changed, filename);
+ fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(password[0] == 0, "password should not have been changed");
+ fail_unless(!password_changed, "password should not have been changed");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "adminn", 6) == 0,
"login should not have been changed");
+ fail_unless(!login_changed, "login should not have been changed");
/*
* Test for the first existing host in our netrc file
@@ -126,13 +139,16 @@ UNITTEST_START
free(login);
login = strdup("");
abort_unless(login != NULL, "returned NULL!");
- result = Curl_parsenetrc("example.com", &login, &password, filename);
+ result = Curl_parsenetrc("example.com", &login, &password,
+ &login_changed, &password_changed, filename);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "passwd", 6) == 0,
"password should be 'passwd'");
+ fail_unless(password_changed, "password should have been changed");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
+ fail_unless(login_changed, "login should have been changed");
/*
* Test for the first existing host in our netrc file
@@ -141,13 +157,16 @@ UNITTEST_START
free(password);
password = strdup("");
abort_unless(password != NULL, "returned NULL!");
- result = Curl_parsenetrc("example.com", &login, &password, filename);
+ result = Curl_parsenetrc("example.com", &login, &password,
+ &login_changed, &password_changed, filename);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "passwd", 6) == 0,
"password should be 'passwd'");
+ fail_unless(password_changed, "password should have been changed");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
+ fail_unless(!login_changed, "login should not have been changed");
/*
* Test for the second existing host in our netrc file
@@ -159,13 +178,16 @@ UNITTEST_START
free(login);
login = strdup("");
abort_unless(login != NULL, "returned NULL!");
- result = Curl_parsenetrc("curl.example.com", &login, &password, filename);
+ result = Curl_parsenetrc("curl.example.com", &login, &password,
+ &login_changed, &password_changed, filename);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "none", 4) == 0,
"password should be 'none'");
+ fail_unless(password_changed, "password should have been changed");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
+ fail_unless(login_changed, "login should have been changed");
/*
* Test for the second existing host in our netrc file
@@ -174,13 +196,16 @@ UNITTEST_START
free(password);
password = strdup("");
abort_unless(password != NULL, "returned NULL!");
- result = Curl_parsenetrc("curl.example.com", &login, &password, filename);
+ result = Curl_parsenetrc("curl.example.com", &login, &password,
+ &login_changed, &password_changed, filename);
fail_unless(result == 0, "Host should have been found");
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "none", 4) == 0,
"password should be 'none'");
+ fail_unless(password_changed, "password should have been changed");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
+ fail_unless(!login_changed, "login should not have been changed");
/* TODO:
* Test over the size limit password / login!
diff --git a/tests/unit/unit1397.c b/tests/unit/unit1397.c
index 539433ca..432b9097 100644
--- a/tests/unit/unit1397.c
+++ b/tests/unit/unit1397.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -36,7 +36,7 @@ static void unit_stop(void)
UNITTEST_START
/* only these backends define the tested functions */
-#if defined(USE_OPENSSL) || defined(USE_AXTLS) || defined(USE_GSKIT)
+#if defined(USE_OPENSSL) || defined(USE_GSKIT)
/* here you start doing things and checking that the results are good */
diff --git a/tests/unit/unit1398.c b/tests/unit/unit1398.c
index b7260195..22cc837e 100644
--- a/tests/unit/unit1398.c
+++ b/tests/unit/unit1398.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -74,7 +74,7 @@ fail_unless(!strcmp(output, " bu"), "wrong output");
/* output a number in a limited output */
rc = curl_msnprintf(output, 4, "%d", 10240);
-/* TODO: this should return 5 to be POSIX/snprintf compliant! */
+/* TODO: this should return 5 to be POSIX/msnprintf compliant! */
fail_unless(rc == 4, "return code should be 4");
fail_unless(!strcmp(output, "102"), "wrong output");
diff --git a/tests/unit/unit1399.c b/tests/unit/unit1399.c
index 897a3431..7383fbd8 100644
--- a/tests/unit/unit1399.c
+++ b/tests/unit/unit1399.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@@ -63,7 +63,7 @@ static bool usec_matches_seconds(time_t time_usec, int expected_seconds)
static void expect_timer_seconds(struct Curl_easy *data, int seconds)
{
char msg[64];
- snprintf(msg, sizeof(msg), "about %d seconds should have passed", seconds);
+ msnprintf(msg, sizeof(msg), "about %d seconds should have passed", seconds);
fail_unless(usec_matches_seconds(data->progress.t_nslookup, seconds), msg);
fail_unless(usec_matches_seconds(data->progress.t_connect, seconds), msg);
fail_unless(usec_matches_seconds(data->progress.t_appconnect, seconds), msg);
diff --git a/tests/unit/unit1604.c b/tests/unit/unit1604.c
index fbfd2c42..c285ced4 100644
--- a/tests/unit/unit1604.c
+++ b/tests/unit/unit1604.c
@@ -46,11 +46,15 @@ static char *getflagstr(int flags)
{
char *buf = malloc(256);
if(buf) {
- snprintf(buf, 256, "%s,%s,%s,%s",
- ((flags & SANITIZE_ALLOW_COLONS) ? "SANITIZE_ALLOW_COLONS" : ""),
- ((flags & SANITIZE_ALLOW_PATH) ? "SANITIZE_ALLOW_PATH" : ""),
- ((flags & SANITIZE_ALLOW_RESERVED) ? "SANITIZE_ALLOW_RESERVED" : ""),
- ((flags & SANITIZE_ALLOW_TRUNCATE) ? "SANITIZE_ALLOW_TRUNCATE" : ""));
+ msnprintf(buf, 256, "%s,%s,%s,%s",
+ ((flags & SANITIZE_ALLOW_COLONS) ?
+ "SANITIZE_ALLOW_COLONS" : ""),
+ ((flags & SANITIZE_ALLOW_PATH) ?
+ "SANITIZE_ALLOW_PATH" : ""),
+ ((flags & SANITIZE_ALLOW_RESERVED) ?
+ "SANITIZE_ALLOW_RESERVED" : ""),
+ ((flags & SANITIZE_ALLOW_TRUNCATE) ?
+ "SANITIZE_ALLOW_TRUNCATE" : ""));
}
return buf;
}
@@ -59,13 +63,13 @@ static char *getcurlcodestr(int cc)
{
char *buf = malloc(256);
if(buf) {
- snprintf(buf, 256, "%s (%d)",
- (cc == SANITIZE_ERR_OK ? "SANITIZE_ERR_OK" :
- cc == SANITIZE_ERR_BAD_ARGUMENT ? "SANITIZE_ERR_BAD_ARGUMENT" :
- cc == SANITIZE_ERR_INVALID_PATH ? "SANITIZE_ERR_INVALID_PATH" :
- cc == SANITIZE_ERR_OUT_OF_MEMORY ? "SANITIZE_ERR_OUT_OF_MEMORY" :
- "unexpected error code - add name"),
- cc);
+ msnprintf(buf, 256, "%s (%d)",
+ (cc == SANITIZE_ERR_OK ? "SANITIZE_ERR_OK" :
+ cc == SANITIZE_ERR_BAD_ARGUMENT ? "SANITIZE_ERR_BAD_ARGUMENT" :
+ cc == SANITIZE_ERR_INVALID_PATH ? "SANITIZE_ERR_INVALID_PATH" :
+ cc == SANITIZE_ERR_OUT_OF_MEMORY ? "SANITIZE_ERR_OUT_OF_MEMORY":
+ "unexpected error code - add name"),
+ cc);
}
return buf;
}
diff --git a/tests/unit/unit1650.c b/tests/unit/unit1650.c
index ddf228f8..4962bfac 100644
--- a/tests/unit/unit1650.c
+++ b/tests/unit/unit1650.c
@@ -200,7 +200,7 @@ UNITTEST_START
a = &d.addr[u];
if(resp[i].type == DNS_TYPE_A) {
p = &a->ip.v4[0];
- snprintf(ptr, len, "%u.%u.%u.%u ", p[0], p[1], p[2], p[3]);
+ msnprintf(ptr, len, "%u.%u.%u.%u ", p[0], p[1], p[2], p[3]);
o = strlen(ptr);
len -= o;
ptr += o;
@@ -209,20 +209,20 @@ UNITTEST_START
int j;
for(j = 0; j < 16; j += 2) {
size_t l;
- snprintf(ptr, len, "%s%02x%02x", j?":":"", a->ip.v6[j],
+ msnprintf(ptr, len, "%s%02x%02x", j?":":"", a->ip.v6[j],
a->ip.v6[j + 1]);
l = strlen(ptr);
len -= l;
ptr += l;
}
- snprintf(ptr, len, " ");
+ msnprintf(ptr, len, " ");
len--;
ptr++;
}
}
for(u = 0; u < d.numcname; u++) {
size_t o;
- snprintf(ptr, len, "%s ", d.cname[u].alloc);
+ msnprintf(ptr, len, "%s ", d.cname[u].alloc);
o = strlen(ptr);
len -= o;
ptr += o;
@@ -271,8 +271,8 @@ UNITTEST_START
fail_if(d.numaddr != 1, "missing address");
a = &d.addr[0];
p = &a->ip.v4[0];
- snprintf((char *)buffer, sizeof(buffer),
- "%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
+ msnprintf((char *)buffer, sizeof(buffer),
+ "%u.%u.%u.%u", p[0], p[1], p[2], p[3]);
if(rc || strcmp((char *)buffer, "127.0.0.1")) {
fprintf(stderr, "bad address decoded: %s, rc == %d\n", buffer, rc);
return 7;
diff --git a/tests/unit/unit1652.c b/tests/unit/unit1652.c
new file mode 100644
index 00000000..9693fe63
--- /dev/null
+++ b/tests/unit/unit1652.c
@@ -0,0 +1,133 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+#include "curlcheck.h"
+
+#include "urldata.h"
+#include "sendf.h"
+
+/*
+ * This test hardcodes the knowledge of the buffer size which is internal to
+ * Curl_infof(). If that buffer is changed in size, this tests needs to be
+ * updated to still be valid.
+ */
+
+static struct Curl_easy *data;
+
+static char input[4096];
+static char result[4096];
+
+int debugf_cb(CURL *handle, curl_infotype type, char *buf, size_t size,
+ void *userptr);
+
+/*
+ * This debugf callback is simply dumping the string into the static buffer
+ * for the unit test to inspect. Since we know that we're only dealing with
+ * text we can afford the luxury of skipping the type check here.
+ */
+int
+debugf_cb(CURL *handle, curl_infotype type, char *buf, size_t size,
+ void *userptr)
+{
+ (void)handle;
+ (void)type;
+ (void)userptr;
+
+ memset(result, '\0', sizeof(result));
+ memcpy(result, buf, size);
+ return 0;
+}
+
+static CURLcode
+unit_setup(void)
+{
+ int res = 0;
+
+ global_init(CURL_GLOBAL_ALL);
+ data = curl_easy_init();
+ if(!data)
+ return CURLE_OUT_OF_MEMORY;
+ curl_easy_setopt(data, CURLOPT_DEBUGFUNCTION, debugf_cb);
+ curl_easy_setopt(data, CURLOPT_VERBOSE, 1L);
+ return CURLE_OK;
+}
+
+static void
+unit_stop(void)
+{
+ curl_easy_cleanup(data);
+ curl_global_cleanup();
+}
+
+UNITTEST_START
+
+/* Injecting a simple short string via a format */
+msnprintf(input, sizeof(input), "Simple Test");
+Curl_infof(data, "%s", input);
+fail_unless(strcmp(result, input) == 0, "Simple string test");
+
+/* Injecting a few different variables with a format */
+Curl_infof(data, "%s %u testing %lu\n", input, 42, 43L);
+fail_unless(strcmp(result, "Simple Test 42 testing 43\n") == 0,
+ "Format string");
+
+/* Variations of empty strings */
+Curl_infof(data, "");
+fail_unless(strlen(result) == 0, "Empty string");
+Curl_infof(data, "%s", NULL);
+fail_unless(strcmp(result, "(nil)") == 0, "Passing NULL as string");
+
+/* A string just long enough to not be truncated */
+memset(input, '\0', sizeof(input));
+memset(input, 'A', 2048);
+Curl_infof(data, "%s", input);
+fail_unless(strlen(result) == 2048, "No truncation of infof input");
+fail_unless(strcmp(result, input) == 0, "No truncation of infof input");
+fail_unless(result[sizeof(result) - 1] == '\0',
+ "No truncation of infof input");
+
+/* Just over the limit for truncation without newline */
+memset(input + 2047, 'A', 4);
+Curl_infof(data, "%s", input);
+fail_unless(strlen(result) == 2048, "Truncation of infof input 1");
+fail_unless(result[sizeof(result) - 1] == '\0', "Truncation of infof input 1");
+fail_unless(strncmp(result + 2045, "...", 3) == 0,
+ "Truncation of infof input 1");
+
+/* Just over the limit for truncation with newline */
+memset(input + 2047, 'A', 4);
+memset(input + 2047 + 4, '\n', 1);
+Curl_infof(data, "%s\n", input);
+fail_unless(strlen(result) == 2048, "Truncation of infof input 2");
+fail_unless(result[sizeof(result) - 1] == '\0', "Truncation of infof input 2");
+fail_unless(strncmp(result + 2044, "...", 3) == 0,
+ "Truncation of infof input 2");
+
+/* Way over the limit for truncation with newline */
+memset(input, '\0', sizeof(input));
+memset(input, 'A', sizeof(input) - 1);
+Curl_infof(data, "%s\n", input);
+fail_unless(strlen(result) == 2048, "Truncation of infof input 3");
+fail_unless(result[sizeof(result) - 1] == '\0', "Truncation of infof input 3");
+fail_unless(strncmp(result + 2044, "...", 3) == 0,
+ "Truncation of infof input 3");
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1653.c b/tests/unit/unit1653.c
new file mode 100644
index 00000000..9851ee58
--- /dev/null
+++ b/tests/unit/unit1653.c
@@ -0,0 +1,129 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at https://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ***************************************************************************/
+#include "curlcheck.h"
+
+#include "urldata.h"
+#include "curl/urlapi.h"
+#include "urlapi-int.h"
+
+
+static CURLU *u;
+
+static CURLcode
+unit_setup(void)
+{
+ return CURLE_OK;
+}
+
+static void
+unit_stop(void)
+{
+ curl_global_cleanup();
+}
+
+UNITTEST_START
+
+ CURLUcode ret;
+ char *ipv6port;
+ char *portnum;
+
+ /* Valid IPv6 */
+ u = curl_url();
+ ipv6port = strdup("[fe80::250:56ff:fea7:da15]");
+ ret = Curl_parse_port(u, ipv6port);
+ fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
+ ret = curl_url_get(u, CURLUPART_PORT, &portnum, CURLU_NO_DEFAULT_PORT);
+ fail_unless(ret != CURLUE_OK, "curl_url_get portnum returned something");
+ free(ipv6port);
+ curl_url_cleanup(u);
+
+ /* Invalid IPv6 */
+ u = curl_url();
+ ipv6port = strdup("[fe80::250:56ff:fea7:da15|");
+ ret = Curl_parse_port(u, ipv6port);
+ fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
+ free(ipv6port);
+ curl_url_cleanup(u);
+
+ u = curl_url();
+ ipv6port = strdup("[fe80::250:56ff;fea7:da15]:80");
+ ret = Curl_parse_port(u, ipv6port);
+ fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
+ free(ipv6port);
+ curl_url_cleanup(u);
+
+ /* Valid IPv6 with zone index and port number */
+ u = curl_url();
+ ipv6port = strdup("[fe80::250:56ff:fea7:da15%25eth3]:80");
+ ret = Curl_parse_port(u, ipv6port);
+ fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
+ ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0);
+ fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error");
+ fail_unless(strcmp(portnum, "80") == 0, "Check portnumber");
+ curl_free(portnum);
+ free(ipv6port);
+ curl_url_cleanup(u);
+
+ /* Valid IPv6 with port number */
+ u = curl_url();
+ ipv6port = strdup("[fe80::250:56ff:fea7:da15]:81");
+ ret = Curl_parse_port(u, ipv6port);
+ fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
+ ret = curl_url_get(u, CURLUPART_PORT, &portnum, 0);
+ fail_unless(ret == CURLUE_OK, "curl_url_get portnum returned error");
+ fail_unless(strcmp(portnum, "81") == 0, "Check portnumber");
+ curl_free(portnum);
+ free(ipv6port);
+ curl_url_cleanup(u);
+
+ /* Valid IPv6 with syntax error in the port number */
+ u = curl_url();
+ ipv6port = strdup("[fe80::250:56ff:fea7:da15];81");
+ ret = Curl_parse_port(u, ipv6port);
+ fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
+ free(ipv6port);
+ curl_url_cleanup(u);
+
+ u = curl_url();
+ ipv6port = strdup("[fe80::250:56ff:fea7:da15]80");
+ ret = Curl_parse_port(u, ipv6port);
+ fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
+ free(ipv6port);
+ curl_url_cleanup(u);
+
+ /* Incorrect zone index syntax */
+ u = curl_url();
+ ipv6port = strdup("[fe80::250:56ff:fea7:da15%!25eth3]:80");
+ ret = Curl_parse_port(u, ipv6port);
+ fail_unless(ret != CURLUE_OK, "Curl_parse_port returned non-error");
+ free(ipv6port);
+ curl_url_cleanup(u);
+
+ /* Non percent-encoded zone index */
+ u = curl_url();
+ ipv6port = strdup("[fe80::250:56ff:fea7:da15%eth3]:80");
+ ret = Curl_parse_port(u, ipv6port);
+ fail_unless(ret != CURLUE_OK, "Curl_parse_port returned non-error");
+ free(ipv6port);
+ curl_url_cleanup(u);
+
+UNITTEST_STOP