summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/CMakeLists.txt2
-rw-r--r--tests/unit/Makefile.am6
-rw-r--r--tests/unit/Makefile.inc7
-rw-r--r--tests/unit/README.md (renamed from tests/unit/README)42
-rw-r--r--tests/unit/curlcheck.h2
-rw-r--r--tests/unit/unit1300.c32
-rw-r--r--tests/unit/unit1301.c4
-rw-r--r--tests/unit/unit1302.c2
-rw-r--r--tests/unit/unit1303.c4
-rw-r--r--tests/unit/unit1304.c4
-rw-r--r--tests/unit/unit1305.c4
-rw-r--r--tests/unit/unit1307.c4
-rw-r--r--tests/unit/unit1308.c4
-rw-r--r--tests/unit/unit1309.c4
-rw-r--r--tests/unit/unit1323.c4
-rw-r--r--tests/unit/unit1330.c2
-rw-r--r--tests/unit/unit1394.c2
-rw-r--r--tests/unit/unit1395.c2
-rw-r--r--tests/unit/unit1396.c4
-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/unit1600.c2
-rw-r--r--tests/unit/unit1601.c2
-rw-r--r--tests/unit/unit1602.c6
-rw-r--r--tests/unit/unit1603.c6
-rw-r--r--tests/unit/unit1604.c4
-rw-r--r--tests/unit/unit1605.c2
-rw-r--r--tests/unit/unit1606.c4
-rw-r--r--tests/unit/unit1607.c4
-rw-r--r--tests/unit/unit1608.c2
-rw-r--r--tests/unit/unit1609.c4
-rw-r--r--tests/unit/unit1610.c2
-rw-r--r--tests/unit/unit1611.c2
-rw-r--r--tests/unit/unit1612.c2
-rw-r--r--tests/unit/unit1620.c2
-rw-r--r--tests/unit/unit1621.c4
-rw-r--r--tests/unit/unit1650.c2
-rw-r--r--tests/unit/unit1651.c4
-rw-r--r--tests/unit/unit1652.c4
-rw-r--r--tests/unit/unit1653.c44
-rw-r--r--tests/unit/unit1654.c17
-rw-r--r--tests/unit/unit1655.c2
-rw-r--r--tests/unit/unit1660.c171
44 files changed, 310 insertions, 129 deletions
diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt
index c5def5328..4bb48ab63 100644
--- a/tests/unit/CMakeLists.txt
+++ b/tests/unit/CMakeLists.txt
@@ -9,7 +9,7 @@
#
# 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.
+# are also available at https://curl.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
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
index 5055aa86b..e2fdd8760 100644
--- a/tests/unit/Makefile.am
+++ b/tests/unit/Makefile.am
@@ -5,11 +5,11 @@
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
-# Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
+# Copyright (C) 1998 - 2020, 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.
+# are also available at https://curl.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
@@ -48,7 +48,7 @@ AM_CPPFLAGS = -I$(top_srcdir)/include \
-I$(top_srcdir)/tests/libtest
endif
-EXTRA_DIST = Makefile.inc
+EXTRA_DIST = Makefile.inc CMakeLists.txt README.md
CFLAGS += @CURL_CFLAG_EXTRAS@
diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc
index 158619657..c3cb7ed22 100644
--- a/tests/unit/Makefile.inc
+++ b/tests/unit/Makefile.inc
@@ -9,7 +9,7 @@
#
# 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.
+# are also available at https://curl.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
@@ -34,7 +34,8 @@ UNITPROGS = unit1300 unit1301 unit1302 unit1303 unit1304 unit1305 unit1307 \
unit1600 unit1601 unit1602 unit1603 unit1604 unit1605 unit1606 unit1607 \
unit1608 unit1609 unit1610 unit1611 unit1612 \
unit1620 unit1621 \
- unit1650 unit1651 unit1652 unit1653 unit1654 unit1655
+ unit1650 unit1651 unit1652 unit1653 unit1654 unit1655 \
+ unit1660
unit1300_SOURCES = unit1300.c $(UNITFILES)
unit1300_CPPFLAGS = $(AM_CPPFLAGS)
@@ -154,3 +155,5 @@ unit1654_CPPFLAGS = $(AM_CPPFLAGS)
unit1655_SOURCES = unit1655.c $(UNITFILES)
unit1655_CPPFLAGS = $(AM_CPPFLAGS)
+unit1660_SOURCES = unit1660.c $(UNITFILES)
+unit1660_CPPFLAGS = $(AM_CPPFLAGS)
diff --git a/tests/unit/README b/tests/unit/README.md
index 060b670c6..2880d1979 100644
--- a/tests/unit/README
+++ b/tests/unit/README.md
@@ -1,50 +1,44 @@
-Unit tests
-==========
+# Unit tests
-The goal is to add tests for *ALL* functions in libcurl. If functions are too
+The goal is to add tests for *all* functions in libcurl. If functions are too
big and complicated, we should split them into smaller and testable ones.
-Build Unit Tests
-================
+## Build Unit Tests
-'./configure --enable-debug' is required for the unit tests to build. To
+`./configure --enable-debug` is required for the unit tests to build. To
enable unit tests, there will be a separate static libcurl built that will be
used exclusively for linking unit test programs. Just build everything as
normal, and then you can run the unit test cases as well.
-Run Unit Tests
-==============
+## Run Unit Tests
Unit tests are run as part of the regular test suite. If you have built
everything to run unit tests, to can do 'make test' at the root level. Or you
-can 'cd tests' and 'make' and then invoke individual unit tests with
-./runtests.pl NNNN where NNNN is the specific test number.
+can `cd tests` and `make` and then invoke individual unit tests with
+`./runtests.pl NNNN` where `NNNN` is the specific test number.
-Debug Unit Tests
-================
+## Debug Unit Tests
If a specific test fails you will get told. The test case then has output left
in the log/ subdirectory, but most importantly you can re-run the test again
-using gdb by doing ./runtests.pl -g NNNN. That is, add a -g to make it start
-up gdb and run the same case using that.
+using gdb by doing `./runtests.pl -g NNNN`. That is, add a `-g` to make it
+start up gdb and run the same case using that.
-Write Unit Tests
-================
+## Write Unit Tests
We put tests that focus on an area or a specific function into a single C
source file. The source file should be named 'unitNNNN.c' where NNNN is a
-number that starts with 1300 and you can pick the next free number.
+previously unused number.
-Add your test to tests/unit/Makefile.inc (if it is a unit test).
-Add your test data to tests/data/Makefile.inc
+Add your test to `tests/unit/Makefile.inc` (if it is a unit test). Add your
+test data file name to `tests/data/Makefile.inc`
-You also need a separate file called tests/data/testNNNN (using the same
+You also need a separate file called `tests/data/testNNNN` (using the same
number) that describes your test case. See the test1300 file for inspiration
-and the tests/FILEFORMAT documentation.
+and the `tests/FILEFORMAT.md` documentation.
For the actual C file, here's a very simple example:
-
------------------------ start -------------------------------
+~~~c
#include "curlcheck.h"
#include "a libcurl header.h" /* from the lib dir */
@@ -70,5 +64,3 @@ UNITTEST_START
/* you end the test code like this: */
UNITTEST_STOP
-
------------------------ end -------------------------------
diff --git a/tests/unit/curlcheck.h b/tests/unit/curlcheck.h
index 016119a39..88bbdcb52 100644
--- a/tests/unit/curlcheck.h
+++ b/tests/unit/curlcheck.h
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1300.c b/tests/unit/unit1300.c
index 3e4c33ccc..aba068a00 100644
--- a/tests/unit/unit1300.c
+++ b/tests/unit/unit1300.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
@@ -23,11 +23,11 @@
#include "llist.h"
-static struct curl_llist llist;
+static struct Curl_llist llist;
-static struct curl_llist llist_destination;
+static struct Curl_llist llist_destination;
-static void test_curl_llist_dtor(void *key, void *value)
+static void test_Curl_llist_dtor(void *key, void *value)
{
/* used by the llist API, does nothing here */
(void)key;
@@ -36,8 +36,8 @@ static void test_curl_llist_dtor(void *key, void *value)
static CURLcode unit_setup(void)
{
- Curl_llist_init(&llist, test_curl_llist_dtor);
- Curl_llist_init(&llist_destination, test_curl_llist_dtor);
+ Curl_llist_init(&llist, test_Curl_llist_dtor);
+ Curl_llist_init(&llist_destination, test_Curl_llist_dtor);
return CURLE_OK;
}
@@ -50,14 +50,14 @@ UNITTEST_START
int unusedData_case1 = 1;
int unusedData_case2 = 2;
int unusedData_case3 = 3;
- struct curl_llist_element case1_list;
- struct curl_llist_element case2_list;
- struct curl_llist_element case3_list;
- struct curl_llist_element case4_list;
- struct curl_llist_element *head;
- struct curl_llist_element *element_next;
- struct curl_llist_element *element_prev;
- struct curl_llist_element *to_remove;
+ struct Curl_llist_element case1_list;
+ struct Curl_llist_element case2_list;
+ struct Curl_llist_element case3_list;
+ struct Curl_llist_element case4_list;
+ struct Curl_llist_element *head;
+ struct Curl_llist_element *element_next;
+ struct Curl_llist_element *element_prev;
+ struct Curl_llist_element *to_remove;
size_t llist_size = Curl_llist_count(&llist);
/**
@@ -74,8 +74,8 @@ UNITTEST_START
fail_unless(llist.size == 0, "list initial size should be zero");
fail_unless(llist.head == NULL, "list head should initiate to NULL");
fail_unless(llist.tail == NULL, "list tail should intiate to NULL");
- fail_unless(llist.dtor == test_curl_llist_dtor,
- "list dtor should initiate to test_curl_llist_dtor");
+ fail_unless(llist.dtor == test_Curl_llist_dtor,
+ "list dtor should initiate to test_Curl_llist_dtor");
/**
* testing Curl_llist_insert_next
diff --git a/tests/unit/unit1301.c b/tests/unit/unit1301.c
index 2af60bef4..ec5787405 100644
--- a/tests/unit/unit1301.c
+++ b/tests/unit/unit1301.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1302.c b/tests/unit/unit1302.c
index bd240d52c..8cc485d58 100644
--- a/tests/unit/unit1302.c
+++ b/tests/unit/unit1302.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1303.c b/tests/unit/unit1303.c
index 945b82ba7..16ec09816 100644
--- a/tests/unit/unit1303.c
+++ b/tests/unit/unit1303.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1304.c b/tests/unit/unit1304.c
index c1d36e840..a6dc64d6c 100644
--- a/tests/unit/unit1304.c
+++ b/tests/unit/unit1304.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1305.c b/tests/unit/unit1305.c
index 50f6da8bb..2432ebef2 100644
--- a/tests/unit/unit1305.c
+++ b/tests/unit/unit1305.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
@@ -40,7 +40,7 @@
#include "memdebug.h" /* LAST include file */
static struct Curl_easy *data;
-static struct curl_hash hp;
+static struct Curl_hash hp;
static char *data_key;
static struct Curl_dns_entry *data_node;
diff --git a/tests/unit/unit1307.c b/tests/unit/unit1307.c
index 7e88ea4d9..a657b61cf 100644
--- a/tests/unit/unit1307.c
+++ b/tests/unit/unit1307.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1308.c b/tests/unit/unit1308.c
index 27624a648..b46072378 100644
--- a/tests/unit/unit1308.c
+++ b/tests/unit/unit1308.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1309.c b/tests/unit/unit1309.c
index 880530313..5a2c154b0 100644
--- a/tests/unit/unit1309.c
+++ b/tests/unit/unit1309.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
@@ -99,7 +99,7 @@ UNITTEST_START
splayprint(root, 0, 1);
printf("remove pointer %d, payload %zu\n", rem,
*(size_t *)nodes[rem].payload);
- rc = Curl_splayremovebyaddr(root, &nodes[rem], &root);
+ rc = Curl_splayremove(root, &nodes[rem], &root);
if(rc) {
/* failed! */
printf("remove %d failed!\n", rem);
diff --git a/tests/unit/unit1323.c b/tests/unit/unit1323.c
index 1adb27494..165825323 100644
--- a/tests/unit/unit1323.c
+++ b/tests/unit/unit1323.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1330.c b/tests/unit/unit1330.c
index c9f19ccc5..b365798b8 100644
--- a/tests/unit/unit1330.c
+++ b/tests/unit/unit1330.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1394.c b/tests/unit/unit1394.c
index d6644f8eb..035ccf584 100644
--- a/tests/unit/unit1394.c
+++ b/tests/unit/unit1394.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1395.c b/tests/unit/unit1395.c
index b8440b477..c362cc3be 100644
--- a/tests/unit/unit1395.c
+++ b/tests/unit/unit1395.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1396.c b/tests/unit/unit1396.c
index 4dd25b40d..66f8fc156 100644
--- a/tests/unit/unit1396.c
+++ b/tests/unit/unit1396.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1397.c b/tests/unit/unit1397.c
index 432b90973..508f41af9 100644
--- a/tests/unit/unit1397.c
+++ b/tests/unit/unit1397.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1398.c b/tests/unit/unit1398.c
index b29bc0830..1e62e2fc9 100644
--- a/tests/unit/unit1398.c
+++ b/tests/unit/unit1398.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1399.c b/tests/unit/unit1399.c
index 3b52989e4..261e0b115 100644
--- a/tests/unit/unit1399.c
+++ b/tests/unit/unit1399.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1600.c b/tests/unit/unit1600.c
index 4e774aabb..a76fab270 100644
--- a/tests/unit/unit1600.c
+++ b/tests/unit/unit1600.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1601.c b/tests/unit/unit1601.c
index bf00bc7e9..4bee3f078 100644
--- a/tests/unit/unit1601.c
+++ b/tests/unit/unit1601.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1602.c b/tests/unit/unit1602.c
index 5f1ee9f47..ee6acacc5 100644
--- a/tests/unit/unit1602.c
+++ b/tests/unit/unit1602.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
@@ -28,7 +28,7 @@
#include "memdebug.h" /* LAST include file */
-static struct curl_hash hash_static;
+static struct Curl_hash hash_static;
static void mydtor(void *p)
{
diff --git a/tests/unit/unit1603.c b/tests/unit/unit1603.c
index c20b20b0e..f9170ef99 100644
--- a/tests/unit/unit1603.c
+++ b/tests/unit/unit1603.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 2015 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 2015 - 2020, 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.
+ * are also available at https://curl.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
@@ -28,7 +28,7 @@
#include "memdebug.h" /* LAST include file */
-static struct curl_hash hash_static;
+static struct Curl_hash hash_static;
static const int slots = 3;
static void mydtor(void *p)
diff --git a/tests/unit/unit1604.c b/tests/unit/unit1604.c
index 9c4f77670..d811858df 100644
--- a/tests/unit/unit1604.c
+++ b/tests/unit/unit1604.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
@@ -82,7 +82,6 @@ struct data {
};
UNITTEST_START
-
{ /* START sanitize_file_name */
struct data data[] = {
{ "", 0,
@@ -349,7 +348,6 @@ UNITTEST_START
#else
UNITTEST_START
-
{
fprintf(stderr, "Skipped test not for this platform\n");
}
diff --git a/tests/unit/unit1605.c b/tests/unit/unit1605.c
index 0ec726a72..9a77da2f0 100644
--- a/tests/unit/unit1605.c
+++ b/tests/unit/unit1605.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1606.c b/tests/unit/unit1606.c
index 9da0b70b6..7ef344b2c 100644
--- a/tests/unit/unit1606.c
+++ b/tests/unit/unit1606.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1607.c b/tests/unit/unit1607.c
index e8d412080..f1016837b 100644
--- a/tests/unit/unit1607.c
+++ b/tests/unit/unit1607.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1608.c b/tests/unit/unit1608.c
index fc767d1d5..5243cd7cd 100644
--- a/tests/unit/unit1608.c
+++ b/tests/unit/unit1608.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1609.c b/tests/unit/unit1609.c
index ce3ddf9d8..76d295b7c 100644
--- a/tests/unit/unit1609.c
+++ b/tests/unit/unit1609.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1610.c b/tests/unit/unit1610.c
index bb9c937c9..2a18f5c5f 100644
--- a/tests/unit/unit1610.c
+++ b/tests/unit/unit1610.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1611.c b/tests/unit/unit1611.c
index bc19f8a5c..948484b53 100644
--- a/tests/unit/unit1611.c
+++ b/tests/unit/unit1611.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1612.c b/tests/unit/unit1612.c
index 3fb2de033..caddd02a0 100644
--- a/tests/unit/unit1612.c
+++ b/tests/unit/unit1612.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1620.c b/tests/unit/unit1620.c
index b23e5b912..4f1aaaf0a 100644
--- a/tests/unit/unit1620.c
+++ b/tests/unit/unit1620.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1621.c b/tests/unit/unit1621.c
index 618abedfa..ec361dfbf 100644
--- a/tests/unit/unit1621.c
+++ b/tests/unit/unit1621.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1650.c b/tests/unit/unit1650.c
index b2fc89efa..de54c0841 100644
--- a/tests/unit/unit1650.c
+++ b/tests/unit/unit1650.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1651.c b/tests/unit/unit1651.c
index 44dbf4b51..07e5b3f7a 100644
--- a/tests/unit/unit1651.c
+++ b/tests/unit/unit1651.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
@@ -35,7 +35,7 @@ static void unit_stop(void)
#if defined(USE_GSKIT) || defined(USE_NSS) || defined(USE_GNUTLS) || \
defined(USE_WOLFSSL) || defined(USE_SCHANNEL)
-/* cert captured from gdb when connecting to curl.haxx.se on October 26
+/* cert captured from gdb when connecting to curl.se on October 26
2018 */
static unsigned char cert[] = {
0x30, 0x82, 0x0F, 0x5B, 0x30, 0x82, 0x0E, 0x43, 0xA0, 0x03, 0x02, 0x01, 0x02,
diff --git a/tests/unit/unit1652.c b/tests/unit/unit1652.c
index 9693fe63a..2500ce95f 100644
--- a/tests/unit/unit1652.c
+++ b/tests/unit/unit1652.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1653.c b/tests/unit/unit1653.c
index 8d4eb915d..618e76d48 100644
--- a/tests/unit/unit1653.c
+++ b/tests/unit/unit1653.c
@@ -5,11 +5,11 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2020, 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.
+ * are also available at https://curl.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
@@ -55,7 +55,7 @@ UNITTEST_START
ipv6port = strdup("[fe80::250:56ff:fea7:da15]");
if(!ipv6port)
goto fail;
- ret = Curl_parse_port(u, ipv6port);
+ ret = Curl_parse_port(u, ipv6port, FALSE);
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");
@@ -69,7 +69,7 @@ UNITTEST_START
ipv6port = strdup("[fe80::250:56ff:fea7:da15|");
if(!ipv6port)
goto fail;
- ret = Curl_parse_port(u, ipv6port);
+ ret = Curl_parse_port(u, ipv6port, FALSE);
fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
free_and_clear(ipv6port);
curl_url_cleanup(u);
@@ -80,7 +80,7 @@ UNITTEST_START
ipv6port = strdup("[fe80::250:56ff;fea7:da15]:80");
if(!ipv6port)
goto fail;
- ret = Curl_parse_port(u, ipv6port);
+ ret = Curl_parse_port(u, ipv6port, FALSE);
fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
free_and_clear(ipv6port);
curl_url_cleanup(u);
@@ -92,7 +92,7 @@ UNITTEST_START
ipv6port = strdup("[fe80::250:56ff:fea7:da15%25eth3]:80");
if(!ipv6port)
goto fail;
- ret = Curl_parse_port(u, ipv6port);
+ ret = Curl_parse_port(u, ipv6port, FALSE);
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");
@@ -108,7 +108,7 @@ UNITTEST_START
ipv6port = strdup("[fe80::250:56ff:fea7:da15%25eth3]");
if(!ipv6port)
goto fail;
- ret = Curl_parse_port(u, ipv6port);
+ ret = Curl_parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
free_and_clear(ipv6port);
curl_url_cleanup(u);
@@ -120,7 +120,7 @@ UNITTEST_START
ipv6port = strdup("[fe80::250:56ff:fea7:da15]:81");
if(!ipv6port)
goto fail;
- ret = Curl_parse_port(u, ipv6port);
+ ret = Curl_parse_port(u, ipv6port, FALSE);
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");
@@ -136,7 +136,7 @@ UNITTEST_START
ipv6port = strdup("[fe80::250:56ff:fea7:da15];81");
if(!ipv6port)
goto fail;
- ret = Curl_parse_port(u, ipv6port);
+ ret = Curl_parse_port(u, ipv6port, FALSE);
fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
free_and_clear(ipv6port);
curl_url_cleanup(u);
@@ -147,19 +147,20 @@ UNITTEST_START
ipv6port = strdup("[fe80::250:56ff:fea7:da15]80");
if(!ipv6port)
goto fail;
- ret = Curl_parse_port(u, ipv6port);
+ ret = Curl_parse_port(u, ipv6port, FALSE);
fail_unless(ret != CURLUE_OK, "Curl_parse_port true on error");
free_and_clear(ipv6port);
curl_url_cleanup(u);
- /* Valid IPv6 with no port after the colon, should use default */
+ /* Valid IPv6 with no port after the colon, should use default if a scheme
+ was used in the URL */
u = curl_url();
if(!u)
goto fail;
ipv6port = strdup("[fe80::250:56ff:fea7:da15]:");
if(!ipv6port)
goto fail;
- ret = Curl_parse_port(u, ipv6port);
+ ret = Curl_parse_port(u, ipv6port, TRUE);
fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
free_and_clear(ipv6port);
curl_url_cleanup(u);
@@ -171,7 +172,7 @@ UNITTEST_START
ipv6port = strdup("[fe80::250:56ff:fea7:da15!25eth3]:80");
if(!ipv6port)
goto fail;
- ret = Curl_parse_port(u, ipv6port);
+ ret = Curl_parse_port(u, ipv6port, FALSE);
fail_unless(ret != CURLUE_OK, "Curl_parse_port returned non-error");
free_and_clear(ipv6port);
curl_url_cleanup(u);
@@ -183,10 +184,25 @@ UNITTEST_START
ipv6port = strdup("[fe80::250:56ff:fea7:da15%eth3]:80");
if(!ipv6port)
goto fail;
- ret = Curl_parse_port(u, ipv6port);
+ ret = Curl_parse_port(u, ipv6port, FALSE);
fail_unless(ret == CURLUE_OK, "Curl_parse_port returned error");
+ free_and_clear(ipv6port);
+ curl_url_cleanup(u);
+
+ /* No scheme and no digits following the colon - not accepted. Because that
+ makes (a*50):// that looks like a scheme be an acceptable input. */
+ u = curl_url();
+ if(!u)
+ goto fail;
+ ipv6port = strdup("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
+ "aaaaaaaaaaaaaaaaaaaaaa:");
+ if(!ipv6port)
+ goto fail;
+ ret = Curl_parse_port(u, ipv6port, FALSE);
+ fail_unless(ret == CURLUE_BAD_PORT_NUMBER, "Curl_parse_port did wrong");
fail:
free(ipv6port);
curl_url_cleanup(u);
+
}
UNITTEST_STOP
diff --git a/tests/unit/unit1654.c b/tests/unit/unit1654.c
index 79e97631c..667551ce9 100644
--- a/tests/unit/unit1654.c
+++ b/tests/unit/unit1654.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
@@ -36,11 +36,10 @@ unit_stop(void)
curl_global_cleanup();
}
-#if defined(CURL_DISABLE_HTTP) || !defined(USE_ALTSVC)
+#if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_ALTSVC)
UNITTEST_START
{
- return 0; /* nothing to do when HTTP is disabled or alt-svc support is
- missing */
+ return 0; /* nothing to do when HTTP or alt-svc is disabled */
}
UNITTEST_STOP
#else
@@ -54,9 +53,10 @@ UNITTEST_START
return 1;
result = Curl_altsvc_load(asi, arg);
if(result) {
- Curl_altsvc_cleanup(asi);
+ Curl_altsvc_cleanup(&asi);
return result;
}
+ curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(!curl)
goto fail;
@@ -111,7 +111,7 @@ UNITTEST_START
result =
Curl_altsvc_parse(curl, asi,
"h2=\":443\", h3=\":443\"; ma = 120; persist = 1\r\n",
- ALPN_h1, "curl.haxx.se", 80);
+ ALPN_h1, "curl.se", 80);
if(result) {
fprintf(stderr, "Curl_altsvc_parse(5) failed!\n");
unitfail++;
@@ -120,7 +120,7 @@ UNITTEST_START
/* clear that one again and decrease the counter */
result = Curl_altsvc_parse(curl, asi, "clear;\r\n",
- ALPN_h1, "curl.haxx.se", 80);
+ ALPN_h1, "curl.se", 80);
if(result) {
fprintf(stderr, "Curl_altsvc_parse(6) failed!\n");
unitfail++;
@@ -130,8 +130,9 @@ UNITTEST_START
Curl_altsvc_save(curl, asi, outname);
curl_easy_cleanup(curl);
+ curl_global_cleanup();
fail:
- Curl_altsvc_cleanup(asi);
+ Curl_altsvc_cleanup(&asi);
return unitfail;
}
UNITTEST_STOP
diff --git a/tests/unit/unit1655.c b/tests/unit/unit1655.c
index 1b910ed9f..1d7880d58 100644
--- a/tests/unit/unit1655.c
+++ b/tests/unit/unit1655.c
@@ -9,7 +9,7 @@
*
* 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.
+ * are also available at https://curl.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
diff --git a/tests/unit/unit1660.c b/tests/unit/unit1660.c
new file mode 100644
index 000000000..3e9b1a40e
--- /dev/null
+++ b/tests/unit/unit1660.c
@@ -0,0 +1,171 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 2020, 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.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 "hsts.h"
+
+static CURLcode
+unit_setup(void)
+{
+ return CURLE_OK;
+}
+
+static void
+unit_stop(void)
+{
+ curl_global_cleanup();
+}
+
+#if defined(CURL_DISABLE_HTTP) || !defined(USE_HSTS)
+UNITTEST_START
+{
+ return 0; /* nothing to do when HTTP or HSTS are disabled */
+}
+UNITTEST_STOP
+#else
+
+struct testit {
+ const char *host;
+ const char *chost; /* if non-NULL, use to lookup with */
+ const char *hdr; /* if NULL, just do the lookup */
+ const CURLcode result; /* parse result */
+};
+
+static const struct testit headers[] = {
+ /* two entries read from disk cache, verify first */
+ { "-", "readfrom.example", NULL, CURLE_OK},
+ { "-", "old.example", NULL, CURLE_OK},
+ /* delete the remaining one read from disk */
+ { "readfrom.example", NULL, "max-age=\"0\"", CURLE_OK},
+
+ { "example.com", NULL, "max-age=\"31536000\"\r\n", CURLE_OK },
+ { "example.com", NULL, "max-age=\"21536000\"\r\n", CURLE_OK },
+ { "example.com", NULL, "max-age=\"21536000\"; \r\n", CURLE_OK },
+ { "example.com", NULL, "max-age=\"21536000\"; includeSubDomains\r\n",
+ CURLE_OK },
+ { "example.org", NULL, "max-age=\"31536000\"\r\n", CURLE_OK },
+ { "this.example", NULL, "max=\"31536\";", CURLE_BAD_FUNCTION_ARGUMENT },
+ { "this.example", NULL, "max-age=\"31536", CURLE_BAD_FUNCTION_ARGUMENT },
+ { "this.example", NULL, "max-age=31536\"", CURLE_OK },
+ /* max-age=0 removes the entry */
+ { "this.example", NULL, "max-age=0", CURLE_OK },
+ { "another.example", NULL, "includeSubDomains; ",
+ CURLE_BAD_FUNCTION_ARGUMENT },
+
+ /* Two max-age is illegal */
+ { "example.com", NULL,
+ "max-age=\"21536000\"; includeSubDomains; max-age=\"3\";",
+ CURLE_BAD_FUNCTION_ARGUMENT },
+ /* Two includeSubDomains is illegal */
+ { "2.example.com", NULL,
+ "max-age=\"21536000\"; includeSubDomains; includeSubDomains;",
+ CURLE_BAD_FUNCTION_ARGUMENT },
+ /* use a unknown directive "include" that should be ignored */
+ { "3.example.com", NULL, "max-age=\"21536000\"; include; includeSubDomains;",
+ CURLE_OK },
+ /* remove the "3.example.com" one, should still match the example.com */
+ { "3.example.com", NULL, "max-age=\"0\"; includeSubDomains;",
+ CURLE_OK },
+ { "-", "foo.example.com", NULL, CURLE_OK},
+ { "-", "foo.xample.com", NULL, CURLE_OK},
+
+ /* should not match */
+ { "example.net", "forexample.net", "max-age=\"31536000\"\r\n", CURLE_OK },
+
+ /* should not match either, since forexample.net is not in the example.net
+ domain */
+ { "example.net", "forexample.net",
+ "max-age=\"31536000\"; includeSubDomains\r\n", CURLE_OK },
+ /* remove example.net again */
+ { "example.net", NULL, "max-age=\"0\"; includeSubDomains\r\n", CURLE_OK },
+
+ /* make this live for 7 seconds */
+ { "expire.example", NULL, "max-age=\"7\"\r\n", CURLE_OK },
+ { NULL, NULL, NULL, 0 }
+};
+
+static void showsts(struct stsentry *e, const char *chost)
+{
+ if(!e)
+ printf("'%s' is not HSTS\n", chost);
+ else {
+ printf("%s [%s]: %" CURL_FORMAT_CURL_OFF_T "%s\n",
+ chost, e->host, e->expires,
+ e->includeSubDomains ? " includeSubDomains" : "");
+ }
+}
+
+UNITTEST_START
+{
+ CURLcode result;
+ struct stsentry *e;
+ struct hsts *h = Curl_hsts_init();
+ int i;
+ const char *chost;
+ CURL *easy;
+ if(!h)
+ return 1;
+ easy = curl_easy_init();
+ if(!easy)
+ return 1;
+
+ Curl_hsts_loadfile(easy, h, "log/input1660");
+
+ for(i = 0; headers[i].host ; i++) {
+ if(headers[i].hdr) {
+ result = Curl_hsts_parse(h, headers[i].host, headers[i].hdr);
+
+ if(result != headers[i].result) {
+ fprintf(stderr, "Curl_hsts_parse(%s) failed: %d\n",
+ headers[i].hdr, result);
+ unitfail++;
+ continue;
+ }
+ else if(result) {
+ printf("Input %u: error %d\n", i, (int) result);
+ continue;
+ }
+ }
+
+ chost = headers[i].chost ? headers[i].chost : headers[i].host;
+ e = Curl_hsts(h, chost, TRUE);
+ showsts(e, chost);
+ }
+
+ printf("Number of entries: %zu\n", h->list.size);
+
+ /* verify that it is exists for 7 seconds */
+ chost = "expire.example";
+ for(i = 100; i < 110; i++) {
+ e = Curl_hsts(h, chost, TRUE);
+ showsts(e, chost);
+ deltatime++; /* another second passed */
+ }
+
+ (void)Curl_hsts_save(easy, h, "log/hsts1660");
+ Curl_hsts_cleanup(&h);
+ curl_easy_cleanup(easy);
+ return unitfail;
+}
+UNITTEST_STOP
+#endif