aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
authorBertrand SIMONNET <bsimonnet@google.com>2015-07-01 15:39:44 -0700
committerBertrand SIMONNET <bsimonnet@google.com>2015-07-08 10:51:12 -0700
commite6cd738ed3716c02557fb3a47515244e949ade39 (patch)
tree8d093306c27b850f828317ed67d6efea3ec7e084 /tests/unit
parentd43abe883892fe84137052fd27ecd956a2c7cacf (diff)
downloadandroid_external_curl-e6cd738ed3716c02557fb3a47515244e949ade39.tar.gz
android_external_curl-e6cd738ed3716c02557fb3a47515244e949ade39.tar.bz2
android_external_curl-e6cd738ed3716c02557fb3a47515244e949ade39.zip
Import curl 7.43
This is a simple import of curl 7.43. The only change from the official release is the fact that the Android.mk was removed to avoid build error trying to parse it. BUG: 22347561 Change-Id: I52ef6798d30b25d22d1f62770d571adec8bcf4d5
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/.gitignore1
-rw-r--r--tests/unit/Makefile.am78
-rw-r--r--tests/unit/Makefile.inc68
-rw-r--r--tests/unit/README70
-rw-r--r--tests/unit/curlcheck.h100
-rw-r--r--tests/unit/unit1300.c292
-rw-r--r--tests/unit/unit1301.c54
-rw-r--r--tests/unit/unit1302.c157
-rw-r--r--tests/unit/unit1303.c146
-rw-r--r--tests/unit/unit1304.c185
-rw-r--r--tests/unit/unit1305.c141
-rw-r--r--tests/unit/unit1307.c234
-rw-r--r--tests/unit/unit1308.c95
-rw-r--r--tests/unit/unit1309.c110
-rw-r--r--tests/unit/unit1330.c41
-rw-r--r--tests/unit/unit1394.c122
-rw-r--r--tests/unit/unit1395.c84
-rw-r--r--tests/unit/unit1396.c111
-rw-r--r--tests/unit/unit1397.c51
-rw-r--r--tests/unit/unit1398.c91
-rw-r--r--tests/unit/unit1600.c63
-rw-r--r--tests/unit/unit1601.c51
-rw-r--r--tests/unit/unit1602.c80
23 files changed, 2425 insertions, 0 deletions
diff --git a/tests/unit/.gitignore b/tests/unit/.gitignore
new file mode 100644
index 0000000..d5ee151
--- /dev/null
+++ b/tests/unit/.gitignore
@@ -0,0 +1 @@
+/unit1[36][0-9][0-9]
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
new file mode 100644
index 0000000..4b47f72
--- /dev/null
+++ b/tests/unit/Makefile.am
@@ -0,0 +1,78 @@
+#***************************************************************************
+# _ _ ____ _
+# Project ___| | | | _ \| |
+# / __| | | | |_) | |
+# | (__| |_| | _ <| |___
+# \___|\___/|_| \_\_____|
+#
+# Copyright (C) 1998 - 2013, 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 http://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.
+#
+###########################################################################
+AUTOMAKE_OPTIONS = foreign nostdinc
+
+# Specify our include paths here, and do it relative to $(top_srcdir) and
+# $(top_builddir), to ensure that these paths which belong to the library
+# being currently built and tested are searched before the library which
+# might possibly already be installed in the system.
+#
+# $(top_builddir)/include/curl for generated curlbuild.h included from curl.h
+# $(top_builddir)/include for generated curlbuild.h inc. from lib/curl_setup.h
+# $(top_srcdir)/include is for libcurl's external include files
+# $(top_builddir)/lib is for libcurl's generated lib/curl_config.h file
+# $(top_srcdir)/lib for libcurl's lib/curl_setup.h and other "borrowed" files
+# $(top_builddir)/ares is for in-tree c-ares's generated ares_build.h file
+# $(top_srcdir)/ares is for in-tree c-ares's external include files
+
+if USE_EMBEDDED_ARES
+AM_CPPFLAGS = -I$(top_builddir)/include/curl \
+ -I$(top_builddir)/include \
+ -I$(top_srcdir)/include \
+ -I$(top_builddir)/lib \
+ -I$(top_srcdir)/lib \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/tests/libtest \
+ -I$(top_builddir)/ares \
+ -I$(top_srcdir)/ares
+else
+AM_CPPFLAGS = -I$(top_builddir)/include/curl \
+ -I$(top_builddir)/include \
+ -I$(top_srcdir)/include \
+ -I$(top_builddir)/lib \
+ -I$(top_srcdir)/lib \
+ -I$(top_srcdir)/src \
+ -I$(top_srcdir)/tests/libtest
+endif
+
+EXTRA_DIST = Makefile.inc
+
+# Prevent LIBS from being used for all link targets
+LIBS = $(BLANK_AT_MAKETIME)
+
+LDADD = $(top_builddir)/src/libcurltool.la \
+ $(top_builddir)/lib/libcurlu.la \
+ @LDFLAGS@ @LIBCURL_LIBS@
+
+DEPENDENCIES = $(top_builddir)/src/libcurltool.la \
+ $(top_builddir)/lib/libcurlu.la
+
+AM_CPPFLAGS += -DCURL_STATICLIB -DUNITTESTS
+
+# Makefile.inc provides neat definitions
+include Makefile.inc
+
+if BUILD_UNITTESTS
+noinst_PROGRAMS = $(UNITPROGS)
+else
+noinst_PROGRAMS =
+endif
diff --git a/tests/unit/Makefile.inc b/tests/unit/Makefile.inc
new file mode 100644
index 0000000..9073b34
--- /dev/null
+++ b/tests/unit/Makefile.inc
@@ -0,0 +1,68 @@
+# these files are used in every single unit test program
+
+UNITFILES = curlcheck.h \
+ ../libtest/test.h \
+ ../libtest/first.c
+
+# These are all unit test programs
+UNITPROGS = unit1300 unit1301 unit1302 unit1303 unit1304 unit1305 unit1307 \
+ unit1308 unit1309 unit1330 unit1394 unit1395 unit1396 unit1397 unit1398 \
+ unit1600 unit1601 unit1602
+
+unit1300_SOURCES = unit1300.c $(UNITFILES)
+unit1300_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1301_SOURCES = unit1301.c $(UNITFILES)
+unit1301_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1302_SOURCES = unit1302.c $(UNITFILES)
+unit1302_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1303_SOURCES = unit1303.c $(UNITFILES)
+unit1303_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1304_SOURCES = unit1304.c $(UNITFILES)
+unit1304_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1305_SOURCES = unit1305.c $(UNITFILES)
+unit1305_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1307_SOURCES = unit1307.c $(UNITFILES)
+unit1307_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1308_SOURCES = unit1308.c $(UNITFILES)
+unit1308_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1309_SOURCES = unit1309.c $(UNITFILES)
+unit1309_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1330_SOURCES = unit1330.c $(UNITFILES)
+unit1330_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1394_SOURCES = unit1394.c $(UNITFILES)
+unit1394_CPPFLAGS = $(AM_CPPFLAGS) $(LIBMETALINK_CPPFLAGS)
+unit1394_LDADD = @LIBMETALINK_LIBS@ $(top_builddir)/lib/libcurl.la @LIBCURL_LIBS@
+unit1394_LDFLAGS = @LIBMETALINK_LDFLAGS@ $(top_builddir)/src/libcurltool.la
+unit1394_LIBS =
+
+unit1395_SOURCES = unit1395.c $(UNITFILES)
+unit1395_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1396_SOURCES = unit1396.c $(UNITFILES)
+unit1396_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1397_SOURCES = unit1397.c $(UNITFILES)
+unit1397_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1398_SOURCES = unit1398.c $(UNITFILES)
+unit1398_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1600_SOURCES = unit1600.c $(UNITFILES)
+unit1600_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1601_SOURCES = unit1601.c $(UNITFILES)
+unit1601_CPPFLAGS = $(AM_CPPFLAGS)
+
+unit1602_SOURCES = unit1602.c $(UNITFILES)
+unit1602_CPPFLAGS = $(AM_CPPFLAGS)
+
diff --git a/tests/unit/README b/tests/unit/README
new file mode 100644
index 0000000..301cd17
--- /dev/null
+++ b/tests/unit/README
@@ -0,0 +1,70 @@
+Unit tests
+==========
+
+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
+================
+
+'./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
+==============
+
+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 then invoke individual unit tests with ./runtests.pl NNNN
+where NNNN is the specific test number.
+
+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.
+
+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.
+
+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.
+
+For the actual C file, here's a very simple example:
+
+----------------------- start -------------------------------
+#include "curlcheck.h"
+
+#include "a libcurl header.h" /* from the lib dir */
+
+static void unit_setup( void )
+{
+ /* whatever you want done first */
+}
+
+static void unit_stop( void )
+{
+ /* done before shutting down and exiting */
+}
+
+UNITTEST_START
+
+ /* here you start doing things and checking that the results are good */
+
+ fail_unless( size == 0 , "initial size should be zero" );
+ fail_if( head == NULL , "head should not be initiated to NULL" );
+
+ /* you end the test code like this: */
+
+UNITTEST_STOP
+
+----------------------- end -------------------------------
diff --git a/tests/unit/curlcheck.h b/tests/unit/curlcheck.h
new file mode 100644
index 0000000..2e3746b
--- /dev/null
+++ b/tests/unit/curlcheck.h
@@ -0,0 +1,100 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2015, 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 http://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 "test.h"
+
+/* The fail macros mark the current test step as failed, and continue */
+#define fail_if(expr, msg) \
+ if(expr) { \
+ fprintf(stderr, "%s:%d Assertion '%s' met: %s\n" , \
+ __FILE__, __LINE__, #expr, msg); \
+ unitfail++; \
+ }
+
+#define fail_unless(expr, msg) \
+ if(!(expr)) { \
+ fprintf(stderr, "%s:%d Assertion '%s' failed: %s\n", \
+ __FILE__, __LINE__, #expr, msg); \
+ unitfail++; \
+ }
+
+#define verify_memory(dynamic, check, len) \
+ if(dynamic && memcmp(dynamic, check, len)) { \
+ fprintf(stderr, "%s:%d Memory buffer mismatch size %d. '%s' is not\n", \
+ __FILE__, __LINE__, len, hexdump((unsigned char *)check, len)); \
+ fprintf(stderr, "%s:%d the same as '%s'\n", \
+ __FILE__, __LINE__, hexdump((unsigned char *)dynamic, len)); \
+ unitfail++; \
+ }
+
+/* fail() is for when the test case figured out by itself that a check
+ proved a failure */
+#define fail(msg) do { \
+ fprintf(stderr, "%s:%d test failed: '%s'\n", \
+ __FILE__, __LINE__, msg); \
+ unitfail++; \
+ } WHILE_FALSE
+
+
+/* The abort macros mark the current test step as failed, and exit the test */
+#define abort_if(expr, msg) \
+ if(expr) { \
+ fprintf(stderr, "%s:%d Abort assertion '%s' met: %s\n" , \
+ __FILE__, __LINE__, #expr, msg); \
+ unitfail++; \
+ goto unit_test_abort; \
+ }
+
+#define abort_unless(expr, msg) \
+ if(!(expr)) { \
+ fprintf(stderr, "%s:%d Abort assertion '%s' failed: %s\n", \
+ __FILE__, __LINE__, #expr, msg); \
+ unitfail++; \
+ goto unit_test_abort; \
+ }
+
+#define abort_test(msg) do { \
+ fprintf(stderr, "%s:%d test aborted: '%s'\n", \
+ __FILE__, __LINE__, msg); \
+ unitfail++; \
+ goto unit_test_abort; \
+ } WHILE_FALSE
+
+
+
+extern int unitfail;
+
+#define UNITTEST_START \
+ int test(char *arg) \
+ { \
+ (void)arg; \
+ if (unit_setup()) { \
+ fail("unit_setup() failure"); \
+ } else {
+
+#define UNITTEST_STOP \
+ goto unit_test_abort; /* avoid warning */ \
+unit_test_abort: \
+ unit_stop(); \
+ } \
+ return unitfail; \
+ }
+
diff --git a/tests/unit/unit1300.c b/tests/unit/unit1300.c
new file mode 100644
index 0000000..2b83416
--- /dev/null
+++ b/tests/unit/unit1300.c
@@ -0,0 +1,292 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2011, 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 http://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 "llist.h"
+
+static struct curl_llist *llist;
+
+static struct curl_llist *llist_destination;
+
+static void test_curl_llist_dtor(void *key, void *value)
+{
+ /* used by the llist API, does nothing here */
+ (void)key;
+ (void)value;
+}
+
+static CURLcode unit_setup(void)
+{
+ llist = Curl_llist_alloc(test_curl_llist_dtor);
+ if(!llist)
+ return CURLE_OUT_OF_MEMORY;
+ llist_destination = Curl_llist_alloc(test_curl_llist_dtor);
+ if(!llist_destination) {
+ Curl_llist_destroy(llist, NULL);
+ return CURLE_OUT_OF_MEMORY;
+ }
+
+ return CURLE_OK;
+}
+
+static void unit_stop(void)
+{
+ Curl_llist_destroy(llist, NULL);
+ Curl_llist_destroy(llist_destination, NULL);
+}
+
+UNITTEST_START
+ int unusedData_case1 = 1;
+ int unusedData_case2 = 2;
+ int unusedData_case3 = 3;
+ 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);
+ int curlErrCode = 0;
+
+ /**
+ * testing llist_init
+ * case 1:
+ * list initiation
+ * @assumptions:
+ * 1: list size will be 0
+ * 2: list head will be NULL
+ * 3: list tail will be NULL
+ * 4: list dtor will be NULL
+ */
+
+ 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 shold initiate to test_curl_llist_dtor");
+
+ /**
+ * testing Curl_llist_insert_next
+ * case 1:
+ * list is empty
+ * @assumptions:
+ * 1: list size will be 1
+ * 2: list head will hold the data "unusedData_case1"
+ * 3: list tail will be the same as list head
+ */
+
+ curlErrCode = Curl_llist_insert_next(llist, llist->head, &unusedData_case1);
+ if(curlErrCode == 1) {
+ fail_unless(Curl_llist_count(llist) == 1,
+ "List size should be 1 after adding a new element");
+ /*test that the list head data holds my unusedData */
+ fail_unless(llist->head->ptr == &unusedData_case1,
+ "List size should be 1 after adding a new element");
+ /*same goes for the list tail */
+ fail_unless(llist->tail == llist->head,
+ "List size should be 1 after adding a new element");
+
+ /**
+ * testing Curl_llist_insert_next
+ * case 2:
+ * list has 1 element, adding one element after the head
+ * @assumptions:
+ * 1: the element next to head should be our newly created element
+ * 2: the list tail should be our newly created element
+ */
+
+ curlErrCode = Curl_llist_insert_next(llist, llist->head,
+ &unusedData_case3);
+ if(curlErrCode == 1) {
+ fail_unless(llist->head->next->ptr == &unusedData_case3,
+ "the node next to head is not getting set correctly");
+ fail_unless(llist->tail->ptr == &unusedData_case3,
+ "the list tail is not getting set correctly");
+ }
+ else {
+ printf("skipping Curl_llist_insert_next as a non "
+ "success error code was returned\n");
+ }
+
+ /**
+ * testing Curl_llist_insert_next
+ * case 3:
+ * list has >1 element, adding one element after "NULL"
+ * @assumptions:
+ * 1: the element next to head should be our newly created element
+ * 2: the list tail should different from newly created element
+ */
+
+ curlErrCode = Curl_llist_insert_next(llist, llist->head,
+ &unusedData_case2);
+ if(curlErrCode == 1) {
+ fail_unless(llist->head->next->ptr == &unusedData_case2,
+ "the node next to head is not getting set correctly");
+ /* better safe than sorry, check that the tail isn't corrupted */
+ fail_unless(llist->tail->ptr != &unusedData_case2,
+ "the list tail is not getting set correctly");
+ }
+ else {
+ printf("skipping Curl_llist_insert_next as a non "
+ "success error code was returned\n");
+ }
+
+ }
+ else {
+ printf("skipping Curl_llist_insert_next as a non "
+ "success error code was returned\n");
+ }
+
+ /* unit tests for Curl_llist_remove */
+
+ /**
+ * case 1:
+ * list has >1 element, removing head
+ * @assumptions:
+ * 1: list size will be decremented by one
+ * 2: head will be the head->next
+ * 3: "new" head's previous will be NULL
+ */
+
+ head=llist->head;
+ abort_unless(head, "llist->head is NULL");
+ element_next = head->next;
+ llist_size = Curl_llist_count(llist);
+
+ Curl_llist_remove(llist, llist->head, NULL);
+
+ fail_unless(Curl_llist_count(llist) == (llist_size-1),
+ "llist size not decremented as expected");
+ fail_unless(llist->head == element_next,
+ "llist new head not modified properly");
+ abort_unless(llist->head, "llist->head is NULL");
+ fail_unless(llist->head->prev == NULL,
+ "new head previous not set to null");
+
+ /**
+ * case 2:
+ * removing non head element, with list having >=2 elements
+ * @setup:
+ * 1: insert another element to the list to make element >=2
+ * @assumptions:
+ * 1: list size will be decremented by one ; tested
+ * 2: element->previous->next will be element->next
+ * 3: element->next->previous will be element->previous
+ */
+ Curl_llist_insert_next(llist, llist->head, &unusedData_case3);
+ llist_size = Curl_llist_count(llist);
+ to_remove = llist->head->next;
+ abort_unless(to_remove, "to_remove is NULL");
+ element_next = to_remove->next;
+ element_prev = to_remove->prev;
+ Curl_llist_remove(llist, to_remove, NULL);
+ fail_unless(element_prev->next == element_next,
+ "element previous->next is not being adjusted");
+ abort_unless(element_next, "element_next is NULL");
+ fail_unless(element_next->prev == element_prev,
+ "element next->previous is not being adjusted");
+
+ /**
+ * case 3:
+ * removing the tail with list having >=1 element
+ * @assumptions
+ * 1: list size will be decremented by one ;tested
+ * 2: element->previous->next will be element->next ;tested
+ * 3: element->next->previous will be element->previous ;tested
+ * 4: list->tail will be tail->previous
+ */
+
+ to_remove = llist->tail;
+ element_prev = to_remove->prev;
+ Curl_llist_remove(llist, to_remove, NULL);
+ fail_unless(llist->tail == element_prev,
+ "llist tail is not being adjusted when removing tail");
+
+ /**
+ * case 4:
+ * removing head with list having 1 element
+ * @assumptions:
+ * 1: list size will be decremented by one ;tested
+ * 2: list head will be null
+ * 3: list tail will be null
+ */
+
+ to_remove = llist->head;
+ Curl_llist_remove(llist, to_remove, NULL);
+ fail_unless(llist->head == NULL,
+ "llist head is not NULL while the llist is empty");
+ fail_unless(llist->tail == NULL,
+ "llist tail is not NULL while the llist is empty");
+
+ /* @testing Curl_llist_move(struct curl_llist *,
+ * struct curl_llist_element *, struct curl_llist *,
+ * struct curl_llist_element *);
+ */
+
+ /**
+ * @case 1:
+ * moving head from an llist containg one element to an empty llist
+ * @assumptions:
+ * 1: llist size will be 0
+ * 2: llist_destination size will be 1
+ * 3: llist head will be NULL
+ * 4: llist_destination head == llist_destination tail != NULL
+ */
+
+ /*
+ * @setup
+ * add one element to the list
+ */
+
+ curlErrCode = Curl_llist_insert_next(llist, llist->head, &unusedData_case1);
+ /* necessary assertions */
+
+ abort_unless(curlErrCode == 1,
+ "Curl_llist_insert_next returned an error, Can't move on with test");
+ abort_unless(Curl_llist_count(llist) == 1,
+ "Number of list elements is not as expected, Aborting");
+ abort_unless(Curl_llist_count(llist_destination) == 0,
+ "Number of list elements is not as expected, Aborting");
+
+ /*actual testing code*/
+ curlErrCode = Curl_llist_move(llist, llist->head, llist_destination, NULL);
+ abort_unless(curlErrCode == 1,
+ "Curl_llist_move returned an error, Can't move on with test");
+ fail_unless(Curl_llist_count(llist) == 0,
+ "moving element from llist didn't decrement the size");
+
+ fail_unless(Curl_llist_count(llist_destination) == 1,
+ "moving element to llist_destination didn't increment the size");
+
+ fail_unless(llist->head == NULL,
+ "llist head not set to null after moving the head");
+
+ fail_unless(llist_destination->head != NULL,
+ "llist_destination head set to null after moving an element");
+
+ fail_unless(llist_destination->tail != NULL,
+ "llist_destination tail set to null after moving an element");
+
+ fail_unless(llist_destination->tail == llist_destination->tail,
+ "llist_destination tail doesn't equal llist_destination head");
+
+
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1301.c b/tests/unit/unit1301.c
new file mode 100644
index 0000000..47df481
--- /dev/null
+++ b/tests/unit/unit1301.c
@@ -0,0 +1,54 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2011, 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 http://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 "strequal.h"
+
+static CURLcode unit_setup( void ) {return CURLE_OK;}
+static void unit_stop( void ) {}
+
+UNITTEST_START
+
+int rc;
+
+rc = curl_strequal("iii", "III");
+fail_unless( rc != 0 , "return code should be zero" );
+
+rc = curl_strequal("iiia", "III");
+fail_unless( rc == 0 , "return code should be zero" );
+
+rc = curl_strequal("iii", "IIIa");
+fail_unless( rc == 0 , "return code should be zero" );
+
+rc = curl_strequal("iiiA", "IIIa");
+fail_unless( rc != 0 , "return code should be non-zero" );
+
+rc = curl_strnequal("iii", "III", 3);
+fail_unless( rc != 0 , "return code should be non-zero" );
+
+rc = curl_strnequal("iiiABC", "IIIcba", 3);
+fail_unless( rc != 0 , "return code should be non-zero" );
+
+rc = curl_strnequal("ii", "II", 3);
+fail_unless( rc != 0 , "return code should be non-zero" );
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1302.c b/tests/unit/unit1302.c
new file mode 100644
index 0000000..412a71f
--- /dev/null
+++ b/tests/unit/unit1302.c
@@ -0,0 +1,157 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2014, 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 http://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 "url.h" /* for Curl_safefree */
+#include "curl_base64.h"
+#include "memdebug.h" /* LAST include file */
+
+static struct SessionHandle *data;
+
+static CURLcode unit_setup( void )
+{
+ data = curl_easy_init();
+ if(!data)
+ return CURLE_OUT_OF_MEMORY;
+ return CURLE_OK;
+}
+
+static void unit_stop( void )
+{
+ curl_easy_cleanup(data);
+}
+
+UNITTEST_START
+
+char *output;
+unsigned char *decoded;
+size_t size = 0;
+unsigned char anychar = 'x';
+CURLcode rc;
+
+rc = Curl_base64_encode(data, "i", 1, &output, &size);
+fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
+fail_unless(size == 4, "size should be 4");
+verify_memory( output, "aQ==", 4);
+Curl_safefree(output);
+
+rc = Curl_base64_encode(data, "ii", 2, &output, &size);
+fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
+fail_unless(size == 4, "size should be 4");
+verify_memory( output, "aWk=", 4);
+Curl_safefree(output);
+
+rc = Curl_base64_encode(data, "iii", 3, &output, &size);
+fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
+fail_unless(size == 4, "size should be 4");
+verify_memory( output, "aWlp", 4);
+Curl_safefree(output);
+
+rc = Curl_base64_encode(data, "iiii", 4, &output, &size);
+fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
+fail_unless(size == 8, "size should be 8");
+verify_memory( output, "aWlpaQ==", 8);
+Curl_safefree(output);
+
+rc = Curl_base64_encode(data, "\xff\x01\xfe\x02", 4, &output, &size);
+fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
+fail_unless(size == 8, "size should be 8");
+verify_memory( output, "/wH+Ag==", 8);
+Curl_safefree(output);
+
+rc = Curl_base64url_encode(data, "\xff\x01\xfe\x02", 4, &output, &size);
+fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
+fail_unless(size == 8, "size should be 8");
+verify_memory( output, "_wH-Ag==", 8);
+Curl_safefree(output);
+
+rc = Curl_base64url_encode(data, "iiii", 4, &output, &size);
+fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
+fail_unless(size == 8, "size should be 8");
+verify_memory( output, "aWlpaQ==", 8);
+Curl_safefree(output);
+
+/* 0 length makes it do strlen() */
+rc = Curl_base64_encode(data, "iiii", 0, &output, &size);
+fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
+fail_unless(size == 8, "size should be 8");
+verify_memory( output, "aWlpaQ==", 8);
+Curl_safefree(output);
+
+rc = Curl_base64_decode("aWlpaQ==", &decoded, &size);
+fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
+fail_unless(size == 4, "size should be 4");
+verify_memory(decoded, "iiii", 4);
+Curl_safefree(decoded);
+
+rc = Curl_base64_decode("aWlp", &decoded, &size);
+fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
+fail_unless(size == 3, "size should be 3");
+verify_memory(decoded, "iii", 3);
+Curl_safefree(decoded);
+
+rc = Curl_base64_decode("aWk=", &decoded, &size);
+fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
+fail_unless(size == 2, "size should be 2");
+verify_memory(decoded, "ii", 2);
+Curl_safefree(decoded);
+
+rc = Curl_base64_decode("aQ==", &decoded, &size);
+fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
+fail_unless(size == 1, "size should be 1");
+verify_memory(decoded, "i", 2);
+Curl_safefree(decoded);
+
+/* This is illegal input as the data is too short */
+size = 1; /* not zero */
+decoded = &anychar; /* not NULL */
+rc = Curl_base64_decode("aQ", &decoded, &size);
+fail_unless(rc == CURLE_BAD_CONTENT_ENCODING, "return code should be CURLE_BAD_CONTENT_ENCODING");
+fail_unless(size == 0, "size should be 0");
+fail_if(decoded, "returned pointer should be NULL");
+
+/* This is illegal input as it contains three padding characters */
+size = 1; /* not zero */
+decoded = &anychar; /* not NULL */
+rc = Curl_base64_decode("a===", &decoded, &size);
+fail_unless(rc == CURLE_BAD_CONTENT_ENCODING, "return code should be CURLE_BAD_CONTENT_ENCODING");
+fail_unless(size == 0, "size should be 0");
+fail_if(decoded, "returned pointer should be NULL");
+
+/* This is illegal input as it contains a padding character mid input */
+size = 1; /* not zero */
+decoded = &anychar; /* not NULL */
+rc = Curl_base64_decode("a=Q=", &decoded, &size);
+fail_unless(rc == CURLE_BAD_CONTENT_ENCODING, "return code should be CURLE_BAD_CONTENT_ENCODING");
+fail_unless(size == 0, "size should be 0");
+fail_if(decoded, "returned pointer should be NULL");
+
+/* This is garbage input as it contains an illegal base64 character */
+size = 1; /* not zero */
+decoded = &anychar; /* not NULL */
+rc = Curl_base64_decode("a\x1f==", &decoded, &size);
+fail_unless(rc == CURLE_BAD_CONTENT_ENCODING, "return code should be CURLE_BAD_CONTENT_ENCODING");
+fail_unless(size == 0, "size should be 0");
+fail_if(decoded, "returned pointer should be NULL");
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1303.c b/tests/unit/unit1303.c
new file mode 100644
index 0000000..b48a625
--- /dev/null
+++ b/tests/unit/unit1303.c
@@ -0,0 +1,146 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2014, 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 http://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 "connect.h"
+#include "memdebug.h" /* LAST include file */
+
+static struct SessionHandle *data;
+
+static CURLcode unit_setup( void )
+{
+ data = curl_easy_init();
+ if (!data)
+ return CURLE_OUT_OF_MEMORY;
+ return CURLE_OK;
+}
+
+static void unit_stop( void )
+{
+ curl_easy_cleanup(data);
+}
+
+/* BASE is just a define to make us fool around with decently large number so
+ that we aren't zero-based */
+#define BASE 1000000
+
+/* macro to set the pretended current time */
+#define NOW(x,y) now.tv_sec = x; now.tv_usec = y
+/* macro to set the millisecond based timeouts to use */
+#define TIMEOUTS(x,y) data->set.timeout = x; data->set.connecttimeout = y
+
+/*
+ * To test:
+ *
+ * 00/10/01/11 timeouts set
+ * 0/1 during connect
+ * T various values on the timeouts
+ * N various values of now
+ */
+
+struct timetest {
+ int now_s;
+ int now_us;
+ int timeout_ms;
+ int connecttimeout_ms;
+ bool connecting;
+ long result;
+ const char *comment;
+};
+
+UNITTEST_START
+
+struct timeval now;
+long timeout;
+unsigned int i;
+
+const struct timetest run[] = {
+ /* both timeouts set, not connecting */
+ {BASE + 4, 0, 10000, 8000, FALSE, 6000, "6 seconds should be left"},
+ {BASE + 4, 990000, 10000, 8000, FALSE, 5010, "5010 ms should be left"},
+ {BASE + 10, 0, 10000, 8000, FALSE, -1, "timeout is -1, expired"},
+ {BASE + 12, 0, 10000, 8000, FALSE, -2000, "-2000, overdue 2 seconds"},
+
+ /* both timeouts set, connecting */
+ {BASE + 4, 0, 10000, 8000, TRUE, 4000, "4 seconds should be left"},
+ {BASE + 4, 990000, 10000, 8000, TRUE, 3010, "3010 ms should be left"},
+ {BASE + 8, 0, 10000, 8000, TRUE, -1, "timeout is -1, expired"},
+ {BASE + 10, 0, 10000, 8000, TRUE, -2000, "-2000, overdue 2 seconds"},
+
+ /* no connect timeout set, not connecting */
+ {BASE + 4, 0, 10000, 0, FALSE, 6000, "6 seconds should be left"},
+ {BASE + 4, 990000, 10000, 0, FALSE, 5010, "5010 ms should be left"},
+ {BASE + 10, 0, 10000, 0, FALSE, -1, "timeout is -1, expired"},
+ {BASE + 12, 0, 10000, 0, FALSE, -2000, "-2000, overdue 2 seconds"},
+
+ /* no connect timeout set, connecting */
+ {BASE + 4, 0, 10000, 0, FALSE, 6000, "6 seconds should be left"},
+ {BASE + 4, 990000, 10000, 0, FALSE, 5010, "5010 ms should be left"},
+ {BASE + 10, 0, 10000, 0, FALSE, -1, "timeout is -1, expired"},
+ {BASE + 12, 0, 10000, 0, FALSE, -2000, "-2000, overdue 2 seconds"},
+
+ /* only connect timeout set, not connecting */
+ {BASE + 4, 0, 0, 10000, FALSE, 0, "no timeout active"},
+ {BASE + 4, 990000, 0, 10000, FALSE, 0, "no timeout active"},
+ {BASE + 10, 0, 0, 10000, FALSE, 0, "no timeout active"},
+ {BASE + 12, 0, 0, 10000, FALSE, 0, "no timeout active"},
+
+ /* only connect timeout set, connecting */
+ {BASE + 4, 0, 0, 10000, TRUE, 6000, "6 seconds should be left"},
+ {BASE + 4, 990000, 0, 10000, TRUE, 5010, "5010 ms should be left"},
+ {BASE + 10, 0, 0, 10000, TRUE, -1, "timeout is -1, expired"},
+ {BASE + 12, 0, 0, 10000, TRUE, -2000, "-2000, overdue 2 seconds"},
+
+ /* no timeout set, not connecting */
+ {BASE + 4, 0, 0, 0, FALSE, 0, "no timeout active"},
+ {BASE + 4, 990000, 0, 0, FALSE, 0, "no timeout active"},
+ {BASE + 10, 0, 0, 0, FALSE, 0, "no timeout active"},
+ {BASE + 12, 0, 0, 0, FALSE, 0, "no timeout active"},
+
+ /* no timeout set, connecting */
+ {BASE + 4, 0, 0, 0, TRUE, 296000, "no timeout active"},
+ {BASE + 4, 990000, 0, 0, TRUE, 295010, "no timeout active"},
+ {BASE + 10, 0, 0, 0, TRUE, 290000, "no timeout active"},
+ {BASE + 12, 0, 0, 0, TRUE, 288000, "no timeout active"},
+
+ /* both timeouts set, connecting, connect timeout the longer one */
+ {BASE + 4, 0, 10000, 12000, TRUE, 6000, "6 seconds should be left"},
+
+};
+
+/* this is the pretended start time of the transfer */
+data->progress.t_startsingle.tv_sec = BASE;
+data->progress.t_startsingle.tv_usec = 0;
+data->progress.t_startop.tv_sec = BASE;
+data->progress.t_startop.tv_usec = 0;
+
+for(i=0; i < sizeof(run)/sizeof(run[0]); i++) {
+ NOW(run[i].now_s, run[i].now_us);
+ TIMEOUTS(run[i].timeout_ms, run[i].connecttimeout_ms);
+ timeout = Curl_timeleft(data, &now, run[i].connecting);
+ if(timeout != run[i].result)
+ fail(run[i].comment);
+}
+
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1304.c b/tests/unit/unit1304.c
new file mode 100644
index 0000000..12b0273
--- /dev/null
+++ b/tests/unit/unit1304.c
@@ -0,0 +1,185 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2013, 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 http://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 "netrc.h"
+#include "memdebug.h" /* LAST include file */
+
+static char *login;
+static char *password;
+static char filename[64];
+
+static CURLcode unit_setup(void)
+{
+ password = strdup("");
+ login = strdup("");
+ if (!password || !login) {
+ Curl_safefree(password);
+ Curl_safefree(login);
+ return CURLE_OUT_OF_MEMORY;
+ }
+ return CURLE_OK;
+}
+
+static void unit_stop(void)
+{
+ Curl_safefree(password);
+ Curl_safefree(login);
+}
+
+UNITTEST_START
+ int result;
+
+ static const char* const filename1 = "log/netrc1304";
+ memcpy(filename, filename1, strlen(filename1));
+
+ /*
+ * Test a non existent host in our netrc file.
+ */
+ result = Curl_parsenetrc("test.example.com", &login, &password, 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!");
+ fail_unless(login[0] == 0, "login should not have been changed");
+
+ /*
+ * Test a non existent login in our netrc file.
+ */
+ 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");
+ abort_unless(password != NULL, "returned NULL!");
+ fail_unless(password[0] == 0, "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");
+
+ /*
+ * Test a non existent login and host in our netrc file.
+ */
+ 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");
+ abort_unless(password != NULL, "returned NULL!");
+ fail_unless(password[0] == 0, "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");
+
+ /*
+ * Test a non existent login (substring of an existing one) in our
+ * netrc file.
+ */
+ 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");
+ abort_unless(password != NULL, "returned NULL!");
+ fail_unless(password[0] == 0, "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");
+
+ /*
+ * Test a non existent login (superstring of an existing one)
+ * in our netrc file.
+ */
+ 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");
+ abort_unless(password != NULL, "returned NULL!");
+ fail_unless(password[0] == 0, "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");
+
+ /*
+ * Test for the first existing host in our netrc file
+ * with login[0] = 0.
+ */
+ free(login);
+ login = strdup("");
+ abort_unless(login != NULL, "returned NULL!");
+ result = Curl_parsenetrc("example.com", &login, &password, 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'");
+ abort_unless(login != NULL, "returned NULL!");
+ fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
+
+ /*
+ * Test for the first existing host in our netrc file
+ * with login[0] != 0.
+ */
+ free(password);
+ password = strdup("");
+ abort_unless(password != NULL, "returned NULL!");
+ result = Curl_parsenetrc("example.com", &login, &password, 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'");
+ abort_unless(login != NULL, "returned NULL!");
+ fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
+
+ /*
+ * Test for the second existing host in our netrc file
+ * with login[0] = 0.
+ */
+ free(password);
+ password = strdup("");
+ abort_unless(password != NULL, "returned NULL!");
+ free(login);
+ login = strdup("");
+ abort_unless(login != NULL, "returned NULL!");
+ result = Curl_parsenetrc("curl.example.com", &login, &password, 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'");
+ abort_unless(login != NULL, "returned NULL!");
+ fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
+
+ /*
+ * Test for the second existing host in our netrc file
+ * with login[0] != 0.
+ */
+ free(password);
+ password = strdup("");
+ abort_unless(password != NULL, "returned NULL!");
+ result = Curl_parsenetrc("curl.example.com", &login, &password, 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'");
+ abort_unless(login != NULL, "returned NULL!");
+ fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
+
+ /* TODO:
+ * Test over the size limit password / login!
+ * Test files with a bad format
+ */
+UNITTEST_STOP
diff --git a/tests/unit/unit1305.c b/tests/unit/unit1305.c
new file mode 100644
index 0000000..96913f1
--- /dev/null
+++ b/tests/unit/unit1305.c
@@ -0,0 +1,141 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2015, 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 http://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"
+
+#ifdef HAVE_NETINET_IN_H
+# include <netinet/in.h>
+#endif
+#ifdef HAVE_NETDB_H
+# include <netdb.h>
+#endif
+#ifdef HAVE_ARPA_INET_H
+# include <arpa/inet.h>
+#endif
+
+#define ENABLE_CURLX_PRINTF
+#include "curlx.h"
+
+#include "hash.h"
+#include "hostip.h"
+
+#include "memdebug.h" /* LAST include file */
+
+static struct SessionHandle *data;
+static struct curl_hash hp;
+static char *data_key;
+static struct Curl_dns_entry *data_node;
+
+static CURLcode unit_setup( void )
+{
+ int rc;
+ data = curl_easy_init();
+ if (!data)
+ return CURLE_OUT_OF_MEMORY;
+
+ rc = Curl_mk_dnscache(&hp);
+ if(rc) {
+ curl_easy_cleanup(data);
+ curl_global_cleanup();
+ return CURLE_OUT_OF_MEMORY;
+ }
+ return CURLE_OK;
+}
+
+static void unit_stop( void )
+{
+ if (data_node) {
+ Curl_freeaddrinfo(data_node->addr);
+ free(data_node);
+ }
+ free(data_key);
+ Curl_hash_destroy(&hp);
+
+ curl_easy_cleanup(data);
+ curl_global_cleanup();
+}
+
+static Curl_addrinfo *fake_ai(void)
+{
+ static Curl_addrinfo *ai;
+ int ss_size;
+
+ ss_size = sizeof (struct sockaddr_in);
+
+ if((ai = calloc(1, sizeof(Curl_addrinfo))) == NULL)
+ return NULL;
+
+ if((ai->ai_canonname = strdup("dummy")) == NULL) {
+ free(ai);
+ return NULL;
+ }
+
+ if((ai->ai_addr = calloc(1, ss_size)) == NULL) {
+ free(ai->ai_canonname);
+ free(ai);
+ return NULL;
+ }
+
+ ai->ai_family = AF_INET;
+ ai->ai_addrlen = ss_size;
+
+ return ai;
+}
+
+static CURLcode create_node(void)
+{
+ data_key = aprintf("%s:%d", "dummy", 0);
+ if (!data_key)
+ return CURLE_OUT_OF_MEMORY;
+
+ data_node = calloc(1, sizeof(struct Curl_dns_entry));
+ if (!data_node)
+ return CURLE_OUT_OF_MEMORY;
+
+ data_node->addr = fake_ai();
+ if (!data_node->addr)
+ return CURLE_OUT_OF_MEMORY;
+
+ return CURLE_OK;
+}
+
+
+UNITTEST_START
+
+ struct Curl_dns_entry *nodep;
+ size_t key_len;
+
+ /* Test 1305 exits without adding anything to the hash */
+ if (strcmp(arg, "1305") != 0) {
+ CURLcode rc = create_node();
+ abort_unless(rc == CURLE_OK, "data node creation failed");
+ key_len = strlen(data_key);
+
+ data_node->inuse = 1; /* hash will hold the reference */
+ nodep = Curl_hash_add(&hp, data_key, key_len+1, data_node);
+ abort_unless(nodep, "insertion into hash failed");
+ /* Freeing will now be done by Curl_hash_destroy */
+ data_node = NULL;
+
+ /* To do: test retrieval, deletion, edge conditions */
+ }
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1307.c b/tests/unit/unit1307.c
new file mode 100644
index 0000000..c26e80c
--- /dev/null
+++ b/tests/unit/unit1307.c
@@ -0,0 +1,234 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2011, 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 http://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 "curl_fnmatch.h"
+
+#define MATCH CURL_FNMATCH_MATCH
+#define NOMATCH CURL_FNMATCH_NOMATCH
+#define RE_ERR CURL_FNMATCH_FAIL
+
+#define MAX_PATTERN_L 100
+#define MAX_STRING_L 100
+
+struct testcase {
+ char pattern[MAX_PATTERN_L];
+ char string[MAX_STRING_L];
+ int result;
+};
+
+static const struct testcase tests[] = {
+ /* brackets syntax */
+ { "\\[", "[", MATCH },
+ { "[", "[", RE_ERR },
+ { "[]", "[]", RE_ERR },
+ { "[][]", "[", MATCH },
+ { "[][]", "]", MATCH },
+ { "[[]", "[", MATCH },
+ { "[[[]", "[", MATCH },
+ { "[[[[]", "[", MATCH },
+ { "[[[[]", "[", MATCH },
+
+ { "[][[]", "]", MATCH },
+ { "[][[[]", "[", MATCH },
+ { "[[]", "]", NOMATCH },
+
+ { "[a-z]", "a", MATCH },
+ { "[a-z]", "A", NOMATCH },
+ { "?[a-z]", "?Z", NOMATCH },
+ { "[A-Z]", "C", MATCH },
+ { "[A-Z]", "c", NOMATCH },
+ { "[0-9]", "7", MATCH },
+ { "[7-8]", "7", MATCH },
+ { "[7-]", "7", MATCH },
+ { "[7-]", "-", MATCH },
+ { "[7-]", "[", NOMATCH },
+ { "[a-bA-F]", "F", MATCH },
+ { "[a-bA-B9]", "9", MATCH },
+ { "[a-bA-B98]", "8", MATCH },
+ { "[a-bA-B98]", "C", NOMATCH },
+ { "[a-bA-Z9]", "F", MATCH },
+ { "[a-bA-Z9]ero*", "Zero chance.", MATCH },
+ { "S[a-][x]opho*", "Saxophone", MATCH },
+ { "S[a-][x]opho*", "SaXophone", NOMATCH },
+ { "S[a-][x]*.txt", "S-x.txt", MATCH },
+ { "[\\a-\\b]", "a", MATCH },
+ { "[\\a-\\b]", "b", MATCH },
+ { "[?*[][?*[][?*[]", "?*[", MATCH },
+ { "[][?*-]", "]", MATCH },
+ { "[][?*-]", "[", MATCH },
+ { "[][?*-]", "?", MATCH },
+ { "[][?*-]", "*", MATCH },
+ { "[][?*-]", "-", MATCH },
+ { "[]?*-]", "-", MATCH },
+ { "?/b/c", "a/b/c", MATCH },
+ { "^_{}~", "^_{}~", MATCH },
+ { "!#%+,-./01234567889", "!#%+,-./01234567889", MATCH },
+ { "PQRSTUVWXYZ]abcdefg", "PQRSTUVWXYZ]abcdefg", MATCH },
+ { ":;=@ABCDEFGHIJKLMNO", ":;=@ABCDEFGHIJKLMNO", MATCH },
+
+ /* negate */
+ { "[!a]", "b", MATCH },
+ { "[!a]", "a", NOMATCH },
+ { "[^a]", "b", MATCH },
+ { "[^a]", "a", NOMATCH },
+ { "[^a-z0-9A-Z]", "a", NOMATCH },
+ { "[^a-z0-9A-Z]", "-", MATCH },
+ { "curl[!a-z]lib", "curl lib", MATCH },
+ { "curl[! ]lib", "curl lib", NOMATCH },
+ { "[! ][ ]", " ", NOMATCH },
+ { "[! ][ ]", "a ", MATCH },
+ { "*[^a].t?t", "a.txt", NOMATCH },
+ { "*[^a].t?t", "ba.txt", NOMATCH },
+ { "*[^a].t?t", "ab.txt", MATCH },
+ { "[!?*[]", "?", NOMATCH },
+ { "[!!]", "!", NOMATCH },
+ { "[!!]", "x", MATCH },
+
+ { "[[:alpha:]]", "a", MATCH },
+ { "[[:alpha:]]", "9", NOMATCH },
+ { "[[:alnum:]]", "a", MATCH },
+ { "[[:alnum:]]", "[", NOMATCH },
+ { "[[:alnum:]]", "]", NOMATCH },
+ { "[[:alnum:]]", "9", MATCH },
+ { "[[:digit:]]", "9", MATCH },
+ { "[[:xdigit:]]", "9", MATCH },
+ { "[[:xdigit:]]", "F", MATCH },
+ { "[[:xdigit:]]", "G", NOMATCH },
+ { "[[:upper:]]", "U", MATCH },
+ { "[[:upper:]]", "u", NOMATCH },
+ { "[[:lower:]]", "l", MATCH },
+ { "[[:lower:]]", "L", NOMATCH },
+ { "[[:print:]]", "L", MATCH },
+ { "[[:print:]]", {'\10'}, NOMATCH },
+ { "[[:print:]]", {'\10'}, NOMATCH },
+ { "[[:space:]]", " ", MATCH },
+ { "[[:space:]]", "x", NOMATCH },
+ { "[[:graph:]]", " ", NOMATCH },
+ { "[[:graph:]]", "x", MATCH },
+ { "[[:blank:]]", {'\t'}, MATCH },
+ { "[[:blank:]]", {' '}, MATCH },
+ { "[[:blank:]]", {'\r'}, NOMATCH },
+ { "[^[:blank:]]", {'\t'}, NOMATCH },
+ { "[^[:print:]]", {'\10'}, MATCH },
+ { "[[:lower:]][[:lower:]]", "ll", MATCH },
+
+ { "Curl[[:blank:]];-)", "Curl ;-)", MATCH },
+ { "*[[:blank:]]*", " ", MATCH },
+ { "*[[:blank:]]*", "", NOMATCH },
+ { "*[[:blank:]]*", "hi, im_Pavel", MATCH },
+
+ /* common using */
+ { "filename.dat", "filename.dat", MATCH },
+ { "*curl*", "lets use curl!!", MATCH },
+ { "filename.txt", "filename.dat", NOMATCH },
+ { "*.txt", "text.txt", MATCH },
+ { "*.txt", "a.txt", MATCH },
+ { "*.txt", ".txt", MATCH },
+ { "*.txt", "txt", NOMATCH },
+ { "??.txt", "99.txt", MATCH },
+ { "??.txt", "a99.txt", NOMATCH },
+ { "?.???", "a.txt", MATCH },
+ { "*.???", "somefile.dat", MATCH },
+ { "*.???", "photo.jpeg", NOMATCH },
+ { ".*", ".htaccess", MATCH },
+ { ".*", ".", MATCH },
+ { ".*", "..", MATCH },
+
+ /* many stars => one star */
+ { "**.txt", "text.txt", MATCH },
+ { "***.txt", "t.txt", MATCH },
+ { "****.txt", ".txt", MATCH },
+
+ /* empty string or pattern */
+ { "", "", MATCH } ,
+ { "", "hello", NOMATCH },
+ { "file", "", NOMATCH },
+ { "?", "", NOMATCH },
+ { "*", "", MATCH },
+ { "x", "", NOMATCH },
+
+ /* backslash */
+ { "\\", "\\", RE_ERR },
+ { "\\\\", "\\", MATCH },
+ { "\\\\", "\\\\", NOMATCH },
+ { "\\?", "?", MATCH },
+ { "\\*", "*", MATCH },
+ { "?.txt", "?.txt", MATCH },
+ { "*.txt", "*.txt", MATCH },
+ { "\\?.txt", "?.txt", MATCH },
+ { "\\*.txt", "*.txt", MATCH },
+ { "\\?.txt", "x.txt", NOMATCH },
+ { "\\*.txt", "x.txt", NOMATCH },
+ { "\\*\\\\.txt", "*\\.txt", MATCH },
+ { "*\\**\\?*\\\\*", "cc*cc?cc\\cc*cc", MATCH },
+ { "*\\**\\?*\\\\*", "cc*cc?cccc", NOMATCH },
+ { "*\\**\\?*\\\\*", "cc*cc?cc\\cc*cc", MATCH },
+ { "*\\?*\\**", "cc?c*c", MATCH },
+ { "*\\?*\\**curl*", "cc?c*curl", MATCH },
+ { "*\\?*\\**", "cc?cc", NOMATCH },
+ { "\\\"\\$\\&\\'\\(\\)", "\"$&'()", MATCH },
+ { "\\*\\?\\[\\\\\\`\\|", "*?[\\`|", MATCH },
+ { "[\\a\\b]c", "ac", MATCH },
+ { "[\\a\\b]c", "bc", MATCH },
+ { "[\\a\\b]d", "bc", NOMATCH },
+ { "[a-bA-B\\?]", "?", MATCH },
+ { "cu[a-ab-b\\r]l", "curl", MATCH },
+ { "[\\a-z]", "c", MATCH },
+
+ { "?*?*?.*?*", "abc.c", MATCH },
+ { "?*?*?.*?*", "abcc", NOMATCH },
+ { "?*?*?.*?*", "abc.", NOMATCH },
+ { "?*?*?.*?*", "abc.c++", MATCH },
+ { "?*?*?.*?*", "abcdef.c++", MATCH },
+ { "?*?*?.?", "abcdef.c", MATCH },
+ { "?*?*?.?", "abcdef.cd", NOMATCH },
+
+ { "Lindmätarv", "Lindmätarv", MATCH },
+
+ { "", "", MATCH }
+};
+
+static CURLcode unit_setup( void )
+{
+ return CURLE_OK;
+}
+
+static void unit_stop( void )
+{
+}
+
+UNITTEST_START
+
+ int testnum = sizeof(tests) / sizeof(struct testcase);
+ int i, rc;
+
+ for(i = 0; i < testnum; i++) {
+ rc = Curl_fnmatch(NULL, tests[i].pattern, tests[i].string);
+ if(rc != tests[i].result) {
+ printf("Curl_fnmatch(\"%s\", \"%s\") should return %d (returns %d)\n",
+ tests[i].pattern, tests[i].string, tests[i].result, rc);
+ fail("pattern mismatch");
+ }
+ }
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1308.c b/tests/unit/unit1308.c
new file mode 100644
index 0000000..80e6c57
--- /dev/null
+++ b/tests/unit/unit1308.c
@@ -0,0 +1,95 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2011, 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 http://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 <curl/curl.h>
+
+static CURLcode unit_setup(void)
+{
+ return CURLE_OK;
+}
+
+static void unit_stop(void)
+{
+
+}
+
+static size_t print_httppost_callback(void *arg, const char *buf, size_t len)
+{
+ fwrite(buf, len, 1, stdout);
+ (*(size_t *) arg) += len;
+ return len;
+}
+
+UNITTEST_START
+ int rc;
+ struct curl_httppost* post = NULL;
+ struct curl_httppost* last = NULL;
+ size_t total_size = 0;
+ char buffer[] = "test buffer";
+
+ rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
+ CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
+
+ fail_unless(rc == 0, "curl_formadd returned error");
+
+ /* after the first curl_formadd when there's a single entry, both pointers
+ should point to the same struct */
+ fail_unless(post == last, "post and last weren't the same");
+
+ rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "htmlcode",
+ CURLFORM_COPYCONTENTS, "<HTML></HTML>",
+ CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
+
+ fail_unless(rc == 0, "curl_formadd returned error");
+
+ rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name_for_ptrcontent",
+ CURLFORM_PTRCONTENTS, buffer, CURLFORM_END);
+
+ fail_unless(rc == 0, "curl_formadd returned error");
+
+ rc = curl_formget(post, &total_size, print_httppost_callback);
+
+ fail_unless(rc == 0, "curl_formget returned error");
+
+ fail_unless(total_size == 486, "curl_formget got wrong size back");
+
+ curl_formfree(post);
+
+ /* start a new formpost with a file upload and formget */
+ post = last = NULL;
+
+ rc = curl_formadd(&post, &last,
+ CURLFORM_PTRNAME, "name of file field",
+ CURLFORM_FILE, "log/test-1308",
+ CURLFORM_FILENAME, "custom named file",
+ CURLFORM_END);
+
+ fail_unless(rc == 0, "curl_formadd returned error");
+
+ rc = curl_formget(post, &total_size, print_httppost_callback);
+ fail_unless(rc == 0, "curl_formget returned error");
+ fail_unless(total_size == 847, "curl_formget got wrong size back");
+
+ curl_formfree(post);
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1309.c b/tests/unit/unit1309.c
new file mode 100644
index 0000000..1304ba1
--- /dev/null
+++ b/tests/unit/unit1309.c
@@ -0,0 +1,110 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2011, 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 http://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 "splay.h"
+
+
+static CURLcode unit_setup(void)
+{
+ return CURLE_OK;
+}
+
+static void unit_stop(void)
+{
+
+}
+
+static void splayprint(struct Curl_tree * t, int d, char output)
+{
+ struct Curl_tree *node;
+ int i;
+ int count;
+ if(t == NULL)
+ return;
+
+ splayprint(t->larger, d+1, output);
+ for(i=0; i<d; i++)
+ if(output)
+ printf(" ");
+
+ if(output) {
+ printf("%ld.%ld[%d]", (long)t->key.tv_sec,
+ (long)t->key.tv_usec, i);
+ }
+
+ for(count=0, node = t->same; node; node = node->same, count++)
+ ;
+
+ if(output) {
+ if(count)
+ printf(" [%d more]\n", count);
+ else
+ printf("\n");
+ }
+
+ splayprint(t->smaller, d+1, output);
+}
+
+UNITTEST_START
+
+/* number of nodes to add to the splay tree */
+#define NUM_NODES 50
+
+ struct Curl_tree *root;
+ struct Curl_tree nodes[NUM_NODES];
+ int rc;
+ int i;
+ root = NULL; /* the empty tree */
+
+ for(i = 0; i < NUM_NODES; i++) {
+ struct timeval key;
+
+ key.tv_sec = 0;
+ key.tv_usec = (541*i)%1023;
+
+ nodes[i].payload = (void *)key.tv_usec; /* for simplicity */
+ root = Curl_splayinsert(key, root, &nodes[i]);
+ }
+
+ puts("Result:");
+ splayprint(root, 0, 1);
+
+ for(i = 0; i < NUM_NODES; i++) {
+ int rem = (i+7)%NUM_NODES;
+ printf("Tree look:\n");
+ splayprint(root, 0, 1);
+ printf("remove pointer %d, payload %ld\n", rem,
+ (long)(nodes[rem].payload));
+ rc = Curl_splayremovebyaddr(root, &nodes[rem], &root);
+ if(rc) {
+ /* failed! */
+ printf("remove %d failed!\n", rem);
+ fail("remove");
+ }
+ }
+
+UNITTEST_STOP
+
+
+
+
diff --git a/tests/unit/unit1330.c b/tests/unit/unit1330.c
new file mode 100644
index 0000000..31caf30
--- /dev/null
+++ b/tests/unit/unit1330.c
@@ -0,0 +1,41 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2013, 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 http://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 "memdebug.h"
+
+
+static CURLcode unit_setup(void)
+{
+ return CURLE_OK;
+}
+
+static void unit_stop(void)
+{
+}
+
+UNITTEST_START
+
+char *ptr = malloc(1330);
+Curl_safefree(ptr);
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1394.c b/tests/unit/unit1394.c
new file mode 100644
index 0000000..a3ef8fa
--- /dev/null
+++ b/tests/unit/unit1394.c
@@ -0,0 +1,122 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2013, 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 http://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 "tool_getparam.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "memdebug.h" /* LAST include file */
+
+static CURLcode unit_setup(void)
+{
+ return CURLE_OK;
+}
+
+static void unit_stop(void)
+{
+
+}
+
+UNITTEST_START
+
+ const char *values[] = {
+ /* -E parameter */ /* exp. cert name */ /* exp. passphrase */
+ "foo:bar:baz", "foo", "bar:baz",
+ "foo\\:bar:baz", "foo:bar", "baz",
+ "foo\\\\:bar:baz", "foo\\", "bar:baz",
+ "foo:bar\\:baz", "foo", "bar\\:baz",
+ "foo:bar\\\\:baz", "foo", "bar\\\\:baz",
+ "foo\\bar\\baz", "foo\\bar\\baz", NULL,
+ "foo\\\\bar\\\\baz", "foo\\bar\\baz", NULL,
+ "foo\\", "foo\\", NULL,
+ "foo\\\\", "foo\\", NULL,
+ "foo:bar\\", "foo", "bar\\",
+ "foo:bar\\\\", "foo", "bar\\\\",
+ "foo:bar:", "foo", "bar:",
+ "foo\\::bar\\:", "foo:", "bar\\:",
+#ifdef WIN32
+ "c:\\foo:bar:baz", "c:\\foo", "bar:baz",
+ "c:\\foo\\:bar:baz", "c:\\foo:bar", "baz",
+ "c:\\foo\\\\:bar:baz", "c:\\foo\\", "bar:baz",
+ "c:\\foo:bar\\:baz", "c:\\foo", "bar\\:baz",
+ "c:\\foo:bar\\\\:baz", "c:\\foo", "bar\\\\:baz",
+ "c:\\foo\\bar\\baz", "c:\\foo\\bar\\baz", NULL,
+ "c:\\foo\\\\bar\\\\baz", "c:\\foo\\bar\\baz", NULL,
+ "c:\\foo\\", "c:\\foo\\", NULL,
+ "c:\\foo\\\\", "c:\\foo\\", NULL,
+ "c:\\foo:bar\\", "c:\\foo", "bar\\",
+ "c:\\foo:bar\\\\", "c:\\foo", "bar\\\\",
+ "c:\\foo:bar:", "c:\\foo", "bar:",
+ "c:\\foo\\::bar\\:", "c:\\foo:", "bar\\:",
+#endif
+ NULL, NULL, NULL,
+ };
+ const char **p;
+ char *certname, *passphrase;
+ for(p = values; *p; p += 3) {
+ parse_cert_parameter(p[0], &certname, &passphrase);
+ if(p[1]) {
+ if(certname) {
+ if(strcmp(p[1], certname)) {
+ printf("expected certname '%s' but got '%s' "
+ "for -E param '%s'\n", p[1], certname, p[0]);
+ fail("assertion failure");
+ }
+ } else {
+ printf("expected certname '%s' but got NULL "
+ "for -E param '%s'\n", p[1], p[0]);
+ fail("assertion failure");
+ }
+ } else {
+ if(certname) {
+ printf("expected certname NULL but got '%s' "
+ "for -E param '%s'\n", certname, p[0]);
+ fail("assertion failure");
+ }
+ }
+ if(p[2]) {
+ if(passphrase) {
+ if(strcmp(p[2], passphrase)) {
+ printf("expected passphrase '%s' but got '%s'"
+ "for -E param '%s'\n", p[2], passphrase, p[0]);
+ fail("assertion failure");
+ }
+ } else {
+ printf("expected passphrase '%s' but got NULL "
+ "for -E param '%s'\n", p[2], p[0]);
+ fail("assertion failure");
+ }
+ } else {
+ if(passphrase) {
+ printf("expected passphrase NULL but got '%s' "
+ "for -E param '%s'\n", passphrase, p[0]);
+ fail("assertion failure");
+ }
+ }
+ if(certname) free(certname);
+ if(passphrase) free(passphrase);
+ }
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1395.c b/tests/unit/unit1395.c
new file mode 100644
index 0000000..6f9fc8c
--- /dev/null
+++ b/tests/unit/unit1395.c
@@ -0,0 +1,84 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2014, 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 http://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 "dotdot.h"
+
+#include "memdebug.h"
+
+static CURLcode unit_setup(void)
+{
+ return CURLE_OK;
+}
+
+static void unit_stop(void)
+{
+
+}
+
+struct dotdot {
+ const char *input;
+ const char *output;
+};
+
+UNITTEST_START
+
+ unsigned int i;
+ int fails=0;
+ const struct dotdot pairs[] = {
+ { "/a/b/c/./../../g", "/a/g" },
+ { "mid/content=5/../6", "mid/6" },
+ { "/hello/../moo", "/moo" },
+ { "/1/../1", "/1" },
+ { "/1/./1", "/1/1" },
+ { "/1/..", "/" },
+ { "/1/.", "/1/" },
+ { "/1/./..", "/" },
+ { "/1/./../2", "/2" },
+ { "/hello/1/./../2", "/hello/2" },
+ { "test/this", "test/this" },
+ { "test/this/../now", "test/now" },
+ { "/1../moo../foo", "/1../moo../foo"},
+ { "/../../moo", "/moo"},
+ { "/../../moo?andnot/../yay", "/moo?andnot/../yay"},
+ { "/123?foo=/./&bar=/../", "/123?foo=/./&bar=/../"},
+ { "/../moo/..?what", "/?what" },
+ };
+
+ for(i=0; i < sizeof(pairs)/sizeof(pairs[0]); i++) {
+ char *out = Curl_dedotdotify((char *)pairs[i].input);
+ abort_unless(out != NULL, "returned NULL!");
+
+ if(strcmp(out, pairs[i].output)) {
+ fprintf(stderr, "Test %d: '%s' gave '%s' instead of '%s'\n",
+ i, pairs[i].input, out, pairs[i].output);
+ fail("Test case output mismatched");
+ fails++;
+ }
+ else
+ fprintf(stderr, "Test %d: OK\n", i);
+ free(out);
+ }
+
+ fail_if(fails, "output mismatched");
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1396.c b/tests/unit/unit1396.c
new file mode 100644
index 0000000..b18d7a8
--- /dev/null
+++ b/tests/unit/unit1396.c
@@ -0,0 +1,111 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2013, 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 http://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"
+
+CURL *hnd;
+
+static CURLcode unit_setup(void)
+{
+ return CURLE_OK;
+}
+
+static void unit_stop(void)
+{
+ if (hnd)
+ curl_easy_cleanup(hnd);
+}
+
+struct test {
+ const char *in;
+ int inlen;
+ const char *out;
+ int outlen;
+};
+
+UNITTEST_START
+{
+ /* unescape, this => that */
+ const struct test list1[]={
+ {"%61", 3, "a", 1},
+ {"%61a", 4, "aa", 2},
+ {"%61b", 4, "ab", 2},
+ {"%6 1", 4, "%6 1", 4},
+ {"%61", 1, "%", 1},
+ {"%61", 2, "%6", 2},
+ {"%6%a", 4, "%6%a", 4},
+ {"%6a", 0, "j", 1},
+ {"%FF", 0, "\xff", 1},
+ {"%FF%00%ff", 9, "\xff\x00\xff", 3},
+ {"%-2", 0, "%-2", 3},
+ {"%FG", 0, "%FG", 3},
+ {NULL, 0, NULL, 0} /* end of list marker */
+ };
+ /* escape, this => that */
+ const struct test list2[]={
+ {"a", 1, "a", 1},
+ {"/", 1, "%2F", 3},
+ {"a=b", 3, "a%3Db", 5},
+ {"a=b", 0, "a%3Db", 5},
+ {"a=b", 1, "a", 1},
+ {"a=b", 2, "a%3D", 4},
+ {"1/./0", 5, "1%2F.%2F0", 9},
+ {"-._~!#%&", 0, "-._~%21%23%25%26", 16},
+ {"a", 2, "a%00", 4},
+ {"a\xff\x01g", 4, "a%FF%01g", 8},
+ {NULL, 0, NULL, 0} /* end of list marker */
+ };
+ int i;
+
+ hnd = curl_easy_init();
+ abort_unless(hnd != NULL, "returned NULL!");
+ for(i=0; list1[i].in; i++) {
+ int outlen;
+ char *out = curl_easy_unescape(hnd,
+ list1[i].in, list1[i].inlen,
+ &outlen);
+
+ abort_unless(out != NULL, "returned NULL!");
+ fail_unless(outlen == list1[i].outlen, "wrong output length returned");
+ fail_unless(!memcmp(out, list1[i].out, list1[i].outlen),
+ "bad output data returned");
+
+ printf("curl_easy_unescape test %d DONE\n", i);
+
+ curl_free(out);
+ }
+
+ for(i=0; list2[i].in; i++) {
+ int outlen;
+ char *out = curl_easy_escape(hnd, list2[i].in, list2[i].inlen);
+ abort_unless(out != NULL, "returned NULL!");
+
+ outlen = (int)strlen(out);
+ fail_unless(outlen == list2[i].outlen, "wrong output length returned");
+ fail_unless(!memcmp(out, list2[i].out, list2[i].outlen),
+ "bad output data returned");
+
+ printf("curl_easy_escape test %d DONE (%s)\n", i, out);
+
+ curl_free(out);
+ }
+}
+UNITTEST_STOP
diff --git a/tests/unit/unit1397.c b/tests/unit/unit1397.c
new file mode 100644
index 0000000..c05c119
--- /dev/null
+++ b/tests/unit/unit1397.c
@@ -0,0 +1,51 @@
+#include "curlcheck.h"
+
+#include "hostcheck.h" /* from the lib dir */
+
+static CURLcode unit_setup(void)
+{
+ return CURLE_OK;
+}
+
+static void unit_stop( void )
+{
+ /* done before shutting down and exiting */
+}
+
+UNITTEST_START
+
+/* only these backends define the tested functions */
+#if defined(USE_OPENSSL) || defined(USE_AXTLS) || defined(USE_GSKIT)
+
+ /* here you start doing things and checking that the results are good */
+
+fail_unless( Curl_cert_hostcheck("www.example.com", "www.example.com"), "good 1" );
+fail_unless( Curl_cert_hostcheck("*.example.com", "www.example.com"), "good 2" );
+fail_unless( Curl_cert_hostcheck("xxx*.example.com", "xxxwww.example.com"), "good 3" );
+fail_unless( Curl_cert_hostcheck("f*.example.com", "foo.example.com"), "good 4" );
+fail_unless( Curl_cert_hostcheck("192.168.0.0", "192.168.0.0"), "good 5" );
+
+fail_if( Curl_cert_hostcheck("xxx.example.com", "www.example.com"), "bad 1" );
+fail_if( Curl_cert_hostcheck("*", "www.example.com"), "bad 2" );
+fail_if( Curl_cert_hostcheck("*.*.com", "www.example.com"), "bad 3" );
+fail_if( Curl_cert_hostcheck("*.example.com", "baa.foo.example.com"), "bad 4" );
+fail_if( Curl_cert_hostcheck("f*.example.com", "baa.example.com"), "bad 5" );
+fail_if( Curl_cert_hostcheck("*.com", "example.com"), "bad 6" );
+fail_if( Curl_cert_hostcheck("*fail.com", "example.com"), "bad 7" );
+fail_if( Curl_cert_hostcheck("*.example.", "www.example."), "bad 8" );
+fail_if( Curl_cert_hostcheck("*.example.", "www.example"), "bad 9" );
+fail_if( Curl_cert_hostcheck("", "www"), "bad 10" );
+fail_if( Curl_cert_hostcheck("*", "www"), "bad 11" );
+fail_if( Curl_cert_hostcheck("*.168.0.0", "192.168.0.0"), "bad 12" );
+fail_if( Curl_cert_hostcheck("www.example.com", "192.168.0.0"), "bad 13" );
+
+#ifdef ENABLE_IPV6
+fail_if( Curl_cert_hostcheck("*::3285:a9ff:fe46:b619", "fe80::3285:a9ff:fe46:b619"), "bad 14" );
+fail_unless( Curl_cert_hostcheck("fe80::3285:a9ff:fe46:b619", "fe80::3285:a9ff:fe46:b619"), "good 6" );
+#endif
+
+#endif
+
+ /* you end the test code like this: */
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1398.c b/tests/unit/unit1398.c
new file mode 100644
index 0000000..e579a62
--- /dev/null
+++ b/tests/unit/unit1398.c
@@ -0,0 +1,91 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2014, 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 http://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 "curl/mprintf.h"
+
+static CURLcode unit_setup( void ) {return CURLE_OK;}
+static void unit_stop( void ) {}
+
+UNITTEST_START
+
+int rc;
+char buf[3] = {'b', 'u', 'g'};
+const char *str="bug";
+int width = 3;
+char output[24];
+
+/*#define curl_msnprintf snprintf */
+
+/* without a trailing zero */
+rc = curl_msnprintf(output, 4, "%.*s", width, buf);
+fail_unless( rc == 3 , "return code should be 3" );
+fail_unless(!strcmp(output, "bug"), "wrong output");
+
+/* with a trailing zero */
+rc = curl_msnprintf(output, 4, "%.*s", width, str);
+fail_unless( rc == 3 , "return code should be 3" );
+fail_unless(!strcmp(output, "bug"), "wrong output");
+
+width = 2;
+/* one byte less */
+rc = curl_msnprintf(output, 4, "%.*s", width, buf);
+fail_unless( rc == 2 , "return code should be 2" );
+fail_unless(!strcmp(output, "bu"), "wrong output");
+
+/* string with larger precision */
+rc = curl_msnprintf(output, 8, "%.8s", str);
+fail_unless( rc == 3 , "return code should be 3" );
+fail_unless(!strcmp(output, "bug"), "wrong output");
+
+/* longer string with precision */
+rc = curl_msnprintf(output, 8, "%.3s", "0123456789");
+fail_unless( rc == 3 , "return code should be 3" );
+fail_unless(!strcmp(output, "012"), "wrong output");
+
+/* negative width */
+rc = curl_msnprintf(output, 8, "%-8s", str);
+fail_unless( rc == 8 , "return code should be 8" );
+fail_unless(!strcmp(output, "bug "), "wrong output");
+
+/* larger width that string length */
+rc = curl_msnprintf(output, 8, "%8s", str);
+fail_unless( rc == 8 , "return code should be 8" );
+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! */
+fail_unless( rc == 4 , "return code should be 4" );
+fail_unless(!strcmp(output, "102"), "wrong output");
+
+/* padded strings */
+rc = curl_msnprintf(output, 16, "%8s%8s", str, str);
+fail_unless( rc == 16 , "return code should be 16" );
+fail_unless(!strcmp(output, " bug bu"), "wrong output");
+
+/* padded numbers */
+rc = curl_msnprintf(output, 16, "%8d%8d", 1234, 5678);
+fail_unless( rc == 16 , "return code should be 16" );
+fail_unless(!strcmp(output, " 1234 567"), "wrong output");
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1600.c b/tests/unit/unit1600.c
new file mode 100644
index 0000000..6803cf3
--- /dev/null
+++ b/tests/unit/unit1600.c
@@ -0,0 +1,63 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2015, 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 http://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_ntlm_core.h"
+
+CURL *easy;
+
+static CURLcode unit_setup(void)
+{
+ easy = curl_easy_init();
+ return CURLE_OK;
+}
+
+static void unit_stop(void)
+{
+ curl_easy_cleanup(easy);
+}
+
+UNITTEST_START
+
+#if defined(USE_NTLM) && (!defined(USE_WINDOWS_SSPI) || defined(USE_WIN32_CRYPTO))
+ unsigned char output[21];
+ unsigned char *testp = output;
+ Curl_ntlm_core_mk_nt_hash(easy, "1", output);
+
+ verify_memory(testp,
+ "\x69\x94\x3c\x5e\x63\xb4\xd2\xc1\x04\xdb"
+ "\xbc\xc1\x51\x38\xb7\x2b\x00\x00\x00\x00\x00", 21);
+
+ Curl_ntlm_core_mk_nt_hash(easy, "hello-you-fool", output);
+
+ verify_memory(testp,
+ "\x39\xaf\x87\xa6\x75\x0a\x7a\x00\xba\xa0"
+ "\xd3\x4f\x04\x9e\xc1\xd0\x00\x00\x00\x00\x00", 21);
+
+ Curl_ntlm_core_mk_nt_hash(easy, "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA", output);
+
+ verify_memory(testp,
+ "\x36\x9d\xae\x06\x84\x7e\xe1\xc1\x4a\x94\x39\xea\x6f\x44\x8c\x65\x00\x00\x00\x00\x00", 21);
+#endif
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1601.c b/tests/unit/unit1601.c
new file mode 100644
index 0000000..17aba05
--- /dev/null
+++ b/tests/unit/unit1601.c
@@ -0,0 +1,51 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2015, 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 http://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 "curl_md5.h"
+
+static CURLcode unit_setup(void)
+{
+ return CURLE_OK;
+}
+
+static void unit_stop(void)
+{
+
+}
+
+UNITTEST_START
+
+ unsigned char output[16];
+ unsigned char *testp = output;
+ Curl_md5it(output, (const unsigned char *)"1");
+
+ verify_memory(testp,
+ "\xc4\xca\x42\x38\xa0\xb9\x23\x82\x0d\xcc\x50\x9a\x6f\x75\x84\x9b", 16);
+
+ Curl_md5it(output, (const unsigned char *)"hello-you-fool");
+
+ verify_memory(testp,
+ "\x88\x67\x0b\x6d\x5d\x74\x2f\xad\xa5\xcd\xf9\xb6\x82\x87\x5f\x22", 16);
+
+
+UNITTEST_STOP
diff --git a/tests/unit/unit1602.c b/tests/unit/unit1602.c
new file mode 100644
index 0000000..3b25556
--- /dev/null
+++ b/tests/unit/unit1602.c
@@ -0,0 +1,80 @@
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2011, 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 http://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"
+
+#define ENABLE_CURLX_PRINTF
+#include "curlx.h"
+
+#include "hash.h"
+
+#include "memdebug.h" /* LAST include file */
+
+ static CURLcode unit_setup( void )
+{
+ return CURLE_OK;
+}
+
+static void unit_stop( void )
+{
+
+}
+
+static void mydtor(void *p)
+{
+ int *ptr = (int*)p;
+ free(ptr);
+}
+
+UNITTEST_START
+ int *value;
+ int *value2;
+ size_t klen = sizeof(int);
+
+ struct curl_hash hash_static;
+ int key = 20;
+ int key2 = 25;
+ int rc = 0;
+
+ rc = Curl_hash_init(&hash_static, 7, Curl_hash_str,
+ Curl_str_key_compare, mydtor);
+
+ if(rc)
+ {
+ fail("Curl_hash_init failed to initialize static hash!");
+ goto unit_test_abort;
+ }
+
+ value = malloc(sizeof(int));
+ value2 = malloc(sizeof(int));
+
+ *value = 199;
+ *value2 = 204;
+ Curl_hash_add(&hash_static, &key, klen, value);
+
+ Curl_hash_clean(&hash_static);
+
+ /* Attempt to add another key/value pair */
+ Curl_hash_add(&hash_static, &key2, klen, value2);
+
+ Curl_hash_destroy(&hash_static);
+
+UNITTEST_STOP