1
0

Add project files.

This commit is contained in:
sgraves
2017-02-02 21:08:13 -06:00
parent 7377d13134
commit e53ad03dd7
2592 changed files with 532713 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
set(UT_SRC
unit1300.c
unit1301.c
unit1302.c
unit1303.c
unit1304.c
unit1305.c
unit1307.c
unit1308.c
unit1309.c
unit1330.c
# Broken link on Linux
# unit1394.c
unit1395.c
unit1396.c
unit1397.c
unit1398.c
unit1600.c
unit1601.c
unit1603.c
# Broken link on Linux
# unit1604.c
)
set(UT_COMMON_FILES ../libtest/first.c ../libtest/test.h curlcheck.h)
include_directories(
${CURL_SOURCE_DIR}/lib # To be able to reach "curl_setup_once.h"
${CURL_SOURCE_DIR}/tests/libtest
${CURL_SOURCE_DIR}/src
${CURL_BINARY_DIR}/lib # To be able to reach "curl_config.h"
${CURL_BINARY_DIR}/include # To be able to reach "curl/curlbuild.h"
)
foreach(_testfile ${UT_SRC})
get_filename_component(_testname ${_testfile} NAME_WE)
add_executable(${_testname} ${_testfile} ${UT_COMMON_FILES})
target_link_libraries(${_testname} libcurl ${CURL_LIBS})
set_target_properties(${_testname}
PROPERTIES COMPILE_DEFINITIONS "UNITTESTS")
if(HIDES_CURL_PRIVATE_SYMBOLS)
set_target_properties(${_testname}
PROPERTIES
EXCLUDE_FROM_ALL TRUE
EXCLUDE_FROM_DEFAULT_BUILD TRUE
)
else()
add_test(NAME ${_testname}
COMMAND ${_testname} "http://www.google.com"
)
endif()
endforeach()

View File

@@ -0,0 +1,81 @@
#***************************************************************************
# _ _ ____ _
# Project ___| | | | _ \| |
# / __| | | | |_) | |
# | (__| |_| | _ <| |___
# \___|\___/|_| \_\_____|
#
# Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution. The terms
# are also available at https://curl.haxx.se/docs/copyright.html.
#
# You may opt to use, copy, modify, merge, publish, distribute and/or sell
# copies of the Software, and permit persons to whom the Software is
# furnished to do so, under the terms of the COPYING file.
#
# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
# KIND, either express or implied.
#
###########################################################################
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 CMakeLists.txt
# 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
checksrc:
@PERL@ $(top_srcdir)/lib/checksrc.pl $(srcdir)/*.c
if BUILD_UNITTESTS
noinst_PROGRAMS = $(UNITPROGS)
else
noinst_PROGRAMS =
endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,76 @@
# 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 unit1603 unit1604 unit1605
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)
unit1603_SOURCES = unit1603.c $(UNITFILES)
unit1603_CPPFLAGS = $(AM_CPPFLAGS)
unit1604_SOURCES = unit1604.c $(UNITFILES)
unit1604_CPPFLAGS = $(AM_CPPFLAGS) $(LIBMETALINK_CPPFLAGS)
unit1605_SOURCES = unit1605.c $(UNITFILES)
unit1605_CPPFLAGS = $(AM_CPPFLAGS)

70
3rd-party/curl-7.52.1/tests/unit/README vendored Normal file
View File

@@ -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 -------------------------------

View File

@@ -0,0 +1,101 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "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; \
}

View File

@@ -0,0 +1,292 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "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

View File

@@ -0,0 +1,54 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "strcase.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

View File

@@ -0,0 +1,161 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "urldata.h"
#include "url.h" /* for Curl_safefree */
#include "curl_base64.h"
#include "memdebug.h" /* LAST include file */
static struct Curl_easy *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

View File

@@ -0,0 +1,145 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "urldata.h"
#include "connect.h"
#include "memdebug.h" /* LAST include file */
static struct Curl_easy *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

View File

@@ -0,0 +1,189 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "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

View File

@@ -0,0 +1,142 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#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 Curl_easy *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);
ai = calloc(1, sizeof(Curl_addrinfo));
if(!ai)
return NULL;
ai->ai_canonname = strdup("dummy");
if(!ai->ai_canonname) {
free(ai);
return NULL;
}
ai->ai_addr = calloc(1, ss_size);
if(!ai->ai_addr) {
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;
}
UNITTEST_STOP

View File

@@ -0,0 +1,234 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "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

View File

@@ -0,0 +1,95 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include <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

View File

@@ -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 https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "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

View File

@@ -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 https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "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

View File

@@ -0,0 +1,126 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "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

View File

@@ -0,0 +1,87 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "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

View File

@@ -0,0 +1,111 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
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

View File

@@ -0,0 +1,79 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "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

View File

@@ -0,0 +1,91 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "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

View File

@@ -0,0 +1,65 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "urldata.h"
#include "curl_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);
/* !checksrc! disable LONGLINE 2 */
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

View File

@@ -0,0 +1,54 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "curl_md5.h"
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
UNITTEST_START
#ifndef CURL_DISABLE_CRYPTO_AUTH
unsigned char output[16];
unsigned char *testp = output;
Curl_md5it(output, (const unsigned char *)"1");
/* !checksrc! disable LONGLINE 2 */
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);
#endif
UNITTEST_STOP

View File

@@ -0,0 +1,78 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#define ENABLE_CURLX_PRINTF
#include "curlx.h"
#include "hash.h"
#include "memdebug.h" /* LAST include file */
static struct curl_hash hash_static;
static void mydtor(void *p)
{
int *ptr = (int *)p;
free(ptr);
}
static CURLcode unit_setup(void)
{
return Curl_hash_init(&hash_static, 7, Curl_hash_str,
Curl_str_key_compare, mydtor);
}
static void unit_stop(void)
{
Curl_hash_destroy(&hash_static);
}
UNITTEST_START
int *value;
int *value2;
int *nodep;
size_t klen = sizeof(int);
int key = 20;
int key2 = 25;
value = malloc(sizeof(int));
abort_unless(value != NULL, "Out of memory");
*value = 199;
nodep = Curl_hash_add(&hash_static, &key, klen, value);
if(!nodep)
free(value);
abort_unless(nodep, "insertion into hash failed");
Curl_hash_clean(&hash_static);
/* Attempt to add another key/value pair */
value2 = malloc(sizeof(int));
abort_unless(value2 != NULL, "Out of memory");
*value2 = 204;
nodep = Curl_hash_add(&hash_static, &key2, klen, value2);
if(!nodep)
free(value2);
abort_unless(nodep, "insertion into hash failed");
UNITTEST_STOP

View File

@@ -0,0 +1,150 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 2015 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#define ENABLE_CURLX_PRINTF
#include "curlx.h"
#include "hash.h"
#include "memdebug.h" /* LAST include file */
static struct curl_hash hash_static;
static const int slots = 3;
static void mydtor(void *p)
{
/* Data are statically allocated */
(void)p; /* unused */
}
static CURLcode unit_setup(void)
{
return Curl_hash_init(&hash_static, slots, Curl_hash_str,
Curl_str_key_compare, mydtor);
}
static void unit_stop(void)
{
Curl_hash_destroy(&hash_static);
}
UNITTEST_START
char key1[] = "key1";
char key2[] = "key2b";
char key3[] = "key3";
char key4[] = "key4";
char notakey[] = "notakey";
char *nodep;
int rc;
/* Ensure the key hashes are as expected in order to test both hash
collisions and a full table. Unfortunately, the hashes can vary
between architectures. */
if(Curl_hash_str(key1, strlen(key1), slots) != 1 ||
Curl_hash_str(key2, strlen(key2), slots) != 0 ||
Curl_hash_str(key3, strlen(key3), slots) != 2 ||
Curl_hash_str(key4, strlen(key4), slots) != 1)
fprintf(stderr, "Warning: hashes are not computed as expected on this "
"architecture; test coverage will be less comprehensive\n");
nodep = Curl_hash_add(&hash_static, &key1, strlen(key1), &key1);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(nodep == key1, "hash retrieval failed");
nodep = Curl_hash_add(&hash_static, &key2, strlen(key2), &key2);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
fail_unless(nodep == key2, "hash retrieval failed");
nodep = Curl_hash_add(&hash_static, &key3, strlen(key3), &key3);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key3, strlen(key3));
fail_unless(nodep == key3, "hash retrieval failed");
/* The fourth element exceeds the number of slots & collides */
nodep = Curl_hash_add(&hash_static, &key4, strlen(key4), &key4);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
fail_unless(nodep == key4, "hash retrieval failed");
/* Make sure all elements are still accessible */
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(nodep == key1, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
fail_unless(nodep == key2, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key3, strlen(key3));
fail_unless(nodep == key3, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
fail_unless(nodep == key4, "hash retrieval failed");
/* Delete the second of two entries in a bucket */
rc = Curl_hash_delete(&hash_static, &key4, strlen(key4));
fail_unless(rc == 0, "hash delete failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(nodep == key1, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
fail_unless(!nodep, "hash retrieval should have failed");
/* Insert that deleted node again */
nodep = Curl_hash_add(&hash_static, &key4, strlen(key4), &key4);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
fail_unless(nodep == key4, "hash retrieval failed");
/* Delete the first of two entries in a bucket */
rc = Curl_hash_delete(&hash_static, &key1, strlen(key1));
fail_unless(rc == 0, "hash delete failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(!nodep, "hash retrieval should have failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
fail_unless(nodep == key4, "hash retrieval failed");
/* Delete the remaining one of two entries in a bucket */
rc = Curl_hash_delete(&hash_static, &key4, strlen(key4));
fail_unless(rc == 0, "hash delete failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(!nodep, "hash retrieval should have failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
fail_unless(!nodep, "hash retrieval should have failed");
/* Delete an already deleted node */
rc = Curl_hash_delete(&hash_static, &key4, strlen(key4));
fail_unless(rc, "hash delete should have failed");
/* Replace an existing node */
nodep = Curl_hash_add(&hash_static, &key1, strlen(key1), &notakey);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(nodep == notakey, "hash retrieval failed");
/* Make sure all remaining elements are still accessible */
nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
fail_unless(nodep == key2, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key3, strlen(key3));
fail_unless(nodep == key3, "hash retrieval failed");
/* Clean up */
Curl_hash_clean(&hash_static);
UNITTEST_STOP

View File

@@ -0,0 +1,348 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, 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_cfgable.h"
#include "tool_doswin.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)
{
}
#if defined(MSDOS) || defined(WIN32)
static char *getflagstr(int flags)
{
char *buf = malloc(256);
fail_unless(buf, "out of memory");
snprintf(buf, 256, "%s,%s,%s,%s",
((flags & SANITIZE_ALLOW_COLONS) ? "SANITIZE_ALLOW_COLONS" : ""),
((flags & SANITIZE_ALLOW_PATH) ? "SANITIZE_ALLOW_PATH" : ""),
((flags & SANITIZE_ALLOW_RESERVED) ? "SANITIZE_ALLOW_RESERVED" : ""),
((flags & SANITIZE_ALLOW_TRUNCATE) ? "SANITIZE_ALLOW_TRUNCATE" : ""));
return buf;
}
static char *getcurlcodestr(int cc)
{
char *buf = malloc(256);
fail_unless(buf, "out of memory");
snprintf(buf, 256, "%s (%d)",
(cc == SANITIZE_ERR_OK ? "SANITIZE_ERR_OK" :
cc == SANITIZE_ERR_BAD_ARGUMENT ? "SANITIZE_ERR_BAD_ARGUMENT" :
cc == SANITIZE_ERR_INVALID_PATH ? "SANITIZE_ERR_INVALID_PATH" :
cc == SANITIZE_ERR_OUT_OF_MEMORY ? "SANITIZE_ERR_OUT_OF_MEMORY" :
"unexpected error code - add name"),
cc);
return buf;
}
struct data {
const char *input;
int flags;
const char *expected_output;
CURLcode expected_result;
};
UNITTEST_START
{ /* START sanitize_file_name */
struct data data[] = {
{ "", 0,
"", SANITIZE_ERR_OK
},
{ "normal filename", 0,
"normal filename", SANITIZE_ERR_OK
},
{ "control\tchar", 0,
"control_char", SANITIZE_ERR_OK
},
{ "banned*char", 0,
"banned_char", SANITIZE_ERR_OK
},
{ "f:foo", 0,
"f_foo", SANITIZE_ERR_OK
},
{ "f:foo", SANITIZE_ALLOW_COLONS,
"f:foo", SANITIZE_ERR_OK
},
{ "f:foo", SANITIZE_ALLOW_PATH,
"f:foo", SANITIZE_ERR_OK
},
{ "f:\\foo", 0,
"f__foo", SANITIZE_ERR_OK
},
{ "f:\\foo", SANITIZE_ALLOW_PATH,
"f:\\foo", SANITIZE_ERR_OK
},
{ "f:/foo", 0,
"f__foo", SANITIZE_ERR_OK
},
{ "f:/foo", SANITIZE_ALLOW_PATH,
"f:/foo", SANITIZE_ERR_OK
},
#ifndef MSDOS
{ "\\\\?\\C:\\foo", SANITIZE_ALLOW_PATH,
"\\\\?\\C:\\foo", SANITIZE_ERR_OK
},
{ "\\\\?\\C:\\foo", 0,
"____C__foo", SANITIZE_ERR_OK
},
#endif
{ "foo:bar", 0,
"foo_bar", SANITIZE_ERR_OK
},
{ "foo|<>/bar\\\":?*baz", 0,
"foo____bar_____baz", SANITIZE_ERR_OK
},
{ "f:foo::$DATA", 0,
"f_foo__$DATA", SANITIZE_ERR_OK
},
{ "con . air", 0,
"con _ air", SANITIZE_ERR_OK
},
{ "con.air", 0,
"con_air", SANITIZE_ERR_OK
},
{ "con:/x", 0,
"con__x", SANITIZE_ERR_OK
},
{ "file . . . . .. .", 0,
"file", SANITIZE_ERR_OK
},
{ "foo . . ? . . ", 0,
"foo . . _", SANITIZE_ERR_OK
},
{ "com1", 0,
"_com1", SANITIZE_ERR_OK
},
{ "com1", SANITIZE_ALLOW_RESERVED,
"com1", SANITIZE_ERR_OK
},
{ "f:\\com1", 0,
"f__com1", SANITIZE_ERR_OK
},
{ "f:\\com1", SANITIZE_ALLOW_PATH,
"f:\\_com1", SANITIZE_ERR_OK
},
{ "f:\\com1", SANITIZE_ALLOW_RESERVED,
"f__com1", SANITIZE_ERR_OK
},
{ "f:\\com1", SANITIZE_ALLOW_RESERVED | SANITIZE_ALLOW_COLONS,
"f:_com1", SANITIZE_ERR_OK
},
{ "f:\\com1", SANITIZE_ALLOW_RESERVED | SANITIZE_ALLOW_PATH,
"f:\\com1", SANITIZE_ERR_OK
},
{ "com1:\\com1", SANITIZE_ALLOW_PATH,
"_com1:\\_com1", SANITIZE_ERR_OK
},
{ "com1:\\com1", SANITIZE_ALLOW_RESERVED | SANITIZE_ALLOW_PATH,
"com1:\\com1", SANITIZE_ERR_OK
},
{ "com1:\\com1", SANITIZE_ALLOW_RESERVED,
"com1__com1", SANITIZE_ERR_OK
},
#ifndef MSDOS
{ "\\com1", SANITIZE_ALLOW_PATH,
"\\_com1", SANITIZE_ERR_OK
},
{ "\\\\com1", SANITIZE_ALLOW_PATH,
"\\\\com1", SANITIZE_ERR_OK
},
{ "\\\\?\\C:\\com1", SANITIZE_ALLOW_PATH,
"\\\\?\\C:\\com1", SANITIZE_ERR_OK
},
#endif
{ "CoM1", 0,
"_CoM1", SANITIZE_ERR_OK
},
{ "CoM1", SANITIZE_ALLOW_RESERVED,
"CoM1", SANITIZE_ERR_OK
},
{ "COM56", 0,
"COM56", SANITIZE_ERR_OK
},
/* At the moment we expect a maximum path length of 259. I assume MSDOS
has variable max path lengths depending on compiler that are shorter
so currently these "good" truncate tests won't run on MSDOS */
#ifndef MSDOS
{ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
SANITIZE_ALLOW_TRUNCATE,
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
"FFFFF", SANITIZE_ERR_OK
},
{ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
"FFF\\FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
SANITIZE_ALLOW_TRUNCATE | SANITIZE_ALLOW_PATH,
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
"FFF\\FFFFF", SANITIZE_ERR_OK
},
{ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
"FFF\\FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
SANITIZE_ALLOW_TRUNCATE,
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
"FFF_F", SANITIZE_ERR_OK
},
#endif /* !MSDOS */
{ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
0,
NULL, SANITIZE_ERR_INVALID_PATH
},
{ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
"FFFF\\FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
SANITIZE_ALLOW_TRUNCATE,
NULL, SANITIZE_ERR_INVALID_PATH
},
{ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
"FFFFFFFFFFFFFFFFFFFFFFFFF\\FFFFFFFFFFFFFFFFFFFFFFFF",
SANITIZE_ALLOW_TRUNCATE | SANITIZE_ALLOW_PATH,
NULL, SANITIZE_ERR_INVALID_PATH
},
{ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
"FFF\\FFFFFFFFFFFFFFFFFFFFF:FFFFFFFFFFFFFFFFFFFFFFFF",
SANITIZE_ALLOW_TRUNCATE | SANITIZE_ALLOW_PATH,
NULL, SANITIZE_ERR_INVALID_PATH
},
{ "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
"FF\\F:FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF",
SANITIZE_ALLOW_TRUNCATE | SANITIZE_ALLOW_PATH,
NULL, SANITIZE_ERR_INVALID_PATH
},
{ NULL, 0,
NULL, SANITIZE_ERR_BAD_ARGUMENT
},
};
size_t i;
for(i = 0; i < sizeof data / sizeof data[0]; ++i) {
char *output = NULL;
char *flagstr = NULL;
char *received_ccstr = NULL;
char *expected_ccstr = NULL;
CURLcode res = sanitize_file_name(&output, data[i].input, data[i].flags);
if(res == data[i].expected_result &&
((!output && !data[i].expected_output) ||
(output && data[i].expected_output &&
!strcmp(output, data[i].expected_output)))) { /* OK */
free(output);
continue;
}
flagstr = getflagstr(data[i].flags);
received_ccstr = getcurlcodestr(res);
expected_ccstr = getcurlcodestr(data[i].expected_result);
unitfail++;
fprintf(stderr, "\n"
"%s:%d sanitize_file_name failed.\n"
"input: %s\n"
"flags: %s\n"
"output: %s\n"
"result: %s\n"
"expected output: %s\n"
"expected result: %s\n",
__FILE__, __LINE__,
data[i].input,
flagstr,
(output ? output : "(null)"),
received_ccstr,
(data[i].expected_output ? data[i].expected_output : "(null)"),
expected_ccstr);
free(output);
free(flagstr);
free(received_ccstr);
free(expected_ccstr);
}
} /* END sanitize_file_name */
#else
UNITTEST_START
{
fprintf(stderr, "Skipped test not for this platform\n");
}
#endif /* MSDOS || WIN32 */
UNITTEST_STOP

View File

@@ -0,0 +1,49 @@
/***************************************************************************
* _ _ ____ _
* Project ___| | | | _ \| |
* / __| | | | |_) | |
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
* are also available at https://curl.haxx.se/docs/copyright.html.
*
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
* copies of the Software, and permit persons to whom the Software is
* furnished to do so, under the terms of the COPYING file.
*
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
* KIND, either express or implied.
*
***************************************************************************/
#include "curlcheck.h"
#include "llist.h"
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
UNITTEST_START
CURL *easy = curl_easy_init();
int len;
char *esc;
esc = curl_easy_escape(easy, "", -1);
fail_unless(esc == NULL, "negative string length can't work");
esc = curl_easy_unescape(easy, "%41%41%41%41", -1, &len);
fail_unless(esc == NULL, "negative string length can't work");
curl_easy_cleanup(easy);
UNITTEST_STOP