tests: always make bundles, adapt build and tests

Make test bundles the default. Drop non-bundle build mode.
Also do all the optimizations and tidy-ups this allows, simpler builds,
less bundle exceptions, streamlined build mechanics.

Also rework the init/deinit macro magic for unit tests. The new method
allows using unique init/deinit function names, and calling them with
arguments. This is in turn makes it possible to reduce the use of global
variables.

Note this drop existing build options `-DCURL_TEST_BUNDLES=` from cmake
and `--enable-test-bundles` / `--disable-test-bundles` from autotools.

Also:
- rename test entry functions to have unique names: `test_<testname>`
  This removes the last exception that was handled in the generator.
- fix `make dist` to not miss test sources with test bundles enabled.
- sync and merge `tests/mk-bundle.pl` into `scripts/mk-unity.pl`.
- mk-unity.pl: add `--embed` option and use it when `CURL_CLANG_TIDY=ON`
  to ensure that `clang-tidy` does not miss external test C sources.
  (because `clang-tidy` ignores code that's #included.)
- tests/unit: drop no-op setup/stop functions.
- tests: reduce symbol scopes, global macros, other fixes and tidy-ups.
- tool1621: fix to run, also fix it to pass.
- sockfilt: fix Windows compiler warning in certain unity include order,
  by explicitly including `warnless.h`.

Follow-up to 6897aeb105 #17468

Closes #17590
This commit is contained in:
Viktor Szakats 2025-06-11 11:31:14 +02:00
parent 1cdac95e2e
commit 2c27a67daa
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
386 changed files with 2996 additions and 4164 deletions

View file

@ -2,6 +2,5 @@
#
# SPDX-License-Identifier: curl
/unit[0-9][0-9][0-9][0-9]
unit_bundle.c
units
units.c

View file

@ -22,42 +22,29 @@
#
###########################################################################
# Get 'UNITPROGS', '*_SOURCES', 'FIRSTFILES' variables
# Get BUNDLE, BUNDLE_SRC, FIRSTFILES, UTILS, TESTFILES variables
curl_transform_makefile_inc("Makefile.inc" "${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
include("${CMAKE_CURRENT_BINARY_DIR}/Makefile.inc.cmake")
if(CURL_TEST_BUNDLES)
add_custom_command(
OUTPUT "unit_bundle.c"
COMMAND ${PERL_EXECUTABLE} "${PROJECT_SOURCE_DIR}/tests/mk-bundle.pl" "${CMAKE_CURRENT_SOURCE_DIR}" > "unit_bundle.c"
DEPENDS
"${PROJECT_SOURCE_DIR}/tests/mk-bundle.pl" ${FIRSTFILES}
"${CMAKE_CURRENT_SOURCE_DIR}/Makefile.inc"
VERBATIM)
add_custom_command(
OUTPUT "${BUNDLE_SRC}"
COMMAND ${PERL_EXECUTABLE} "${PROJECT_SOURCE_DIR}/scripts/mk-unity.pl" --test ${TESTFILES}
${CURL_MK_UNITY_OPTION} --srcdir "${CMAKE_CURRENT_SOURCE_DIR}" > "${BUNDLE_SRC}"
DEPENDS
"${PROJECT_SOURCE_DIR}/scripts/mk-unity.pl" "${CMAKE_CURRENT_SOURCE_DIR}/Makefile.inc" ${FIRSTFILES} ${TESTFILES}
VERBATIM)
set(UNITPROGS "units")
set(units_SOURCES "unit_bundle.c")
endif()
foreach(_target IN LISTS UNITPROGS)
set(_target_name "${_target}")
add_executable(${_target_name} EXCLUDE_FROM_ALL ${${_target}_SOURCES})
add_dependencies(testdeps ${_target_name})
target_link_libraries(${_target_name} curltool curlu)
target_include_directories(${_target_name} PRIVATE
"${PROJECT_BINARY_DIR}/lib" # for "curl_config.h"
"${PROJECT_SOURCE_DIR}/lib" # for "curl_setup.h"
"${PROJECT_SOURCE_DIR}/lib/curlx" # for curlx
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/tests/libtest"
)
set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}")
# unit tests are small pretend-libcurl-programs
set_property(TARGET ${_target_name} APPEND PROPERTY COMPILE_DEFINITIONS "BUILDING_LIBCURL")
if(CURL_TEST_BUNDLES)
target_include_directories(${_target_name} PRIVATE "${PROJECT_SOURCE_DIR}/tests/unit")
endif()
set_target_properties(${_target_name} PROPERTIES
OUTPUT_NAME "${_target}"
PROJECT_LABEL "Test unit ${_target}")
endforeach()
add_executable(units EXCLUDE_FROM_ALL ${UTILS} "${BUNDLE_SRC}")
add_dependencies(testdeps units)
target_link_libraries(units curltool curlu)
target_include_directories(units PRIVATE
"${PROJECT_BINARY_DIR}/lib" # for "curl_config.h"
"${PROJECT_SOURCE_DIR}/lib" # for "curl_setup.h"
"${PROJECT_SOURCE_DIR}/lib/curlx" # for curlx
"${PROJECT_SOURCE_DIR}/src"
"${PROJECT_SOURCE_DIR}/tests/libtest"
"${PROJECT_SOURCE_DIR}/tests/unit"
)
set_property(TARGET units APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}" "CURL_NO_OLDIES" "CURL_DISABLE_DEPRECATION")
set_property(TARGET units APPEND PROPERTY COMPILE_DEFINITIONS "BUILDING_LIBCURL") # unit tests are small pretend-libcurl-programs
set_target_properties(units PROPERTIES OUTPUT_NAME "${BUNDLE}" PROJECT_LABEL "Test ${BUNDLE}")

View file

@ -40,7 +40,10 @@ AM_CPPFLAGS = -I$(top_srcdir)/include \
-I$(top_srcdir)/tests/libtest \
-I$(top_srcdir)/tests/unit
EXTRA_DIST = CMakeLists.txt README.md
# Get BUNDLE, BUNDLE_SRC, FIRSTFILES, UTILS, TESTFILES variables
include Makefile.inc
EXTRA_DIST = CMakeLists.txt README.md $(UTILS) $(TESTFILES)
CFLAGS += @CURL_CFLAG_EXTRAS@
@ -58,21 +61,15 @@ if CURLDEBUG
AM_CPPFLAGS += -DCURLDEBUG
endif
BUNDLE=units
AM_CPPFLAGS += -DCURL_NO_OLDIES -DCURL_DISABLE_DEPRECATION
if BUILD_UNITTESTS
if USE_TEST_BUNDLES
unit_bundle.c: $(top_srcdir)/tests/mk-bundle.pl Makefile.inc
@PERL@ $(top_srcdir)/tests/mk-bundle.pl $(srcdir) > unit_bundle.c
$(BUNDLE_SRC): $(top_srcdir)/scripts/mk-unity.pl Makefile.inc $(FIRSTFILES) $(UTILS) $(TESTFILES)
@PERL@ $(top_srcdir)/scripts/mk-unity.pl --include $(UTILS) --test $(TESTFILES) > $(BUNDLE_SRC)
noinst_PROGRAMS = $(BUNDLE)
nodist_units_SOURCES = unit_bundle.c
CLEANFILES = unit_bundle.c
else
# Makefile.inc provides neat definitions
include Makefile.inc
noinst_PROGRAMS = $(UNITPROGS)
endif
nodist_units_SOURCES = $(BUNDLE_SRC)
CLEANFILES = $(BUNDLE_SRC)
else
noinst_PROGRAMS =
endif
@ -85,7 +82,7 @@ CS_ = $(CS_0)
# ignore generated C files since they play by slightly different rules!
checksrc:
$(CHECKSRC)(@PERL@ $(top_srcdir)/scripts/checksrc.pl -D$(srcdir) \
-W$(srcdir)/unit_bundle.c \
-W$(srcdir)/$(BUNDLE_SRC) \
$(srcdir)/*.[ch])
if NOT_CURL_CI

View file

@ -21,138 +21,31 @@
# SPDX-License-Identifier: curl
#
###########################################################################
# Shared between CMakeLists.txt and Makefile.am
# these files are used in every single unit test program
BUNDLE = units
BUNDLE_SRC = units.c
FIRSTFILES = \
../libtest/first.c \
../libtest/first.h
# Files referenced from the bundle source
FIRSTFILES = ../libtest/first.c ../libtest/first.h
UNITFILES = curlcheck.h $(FIRSTFILES)
# Common files used by test programs
UTILS = curlcheck.h
# These are all unit test programs
UNITPROGS = unit1300 unit1302 unit1303 unit1304 unit1305 unit1307 \
unit1309 unit1323 \
unit1330 unit1395 unit1396 unit1397 unit1398 \
unit1399 \
unit1600 unit1601 unit1602 unit1603 unit1605 unit1606 unit1607 \
unit1608 unit1609 unit1610 unit1611 unit1612 unit1614 unit1615 unit1616 \
unit1620 \
unit1650 unit1651 unit1652 unit1653 unit1654 unit1655 unit1656 unit1657 \
unit1658 \
unit1660 unit1661 unit1663 unit1664 \
unit1979 unit1980 \
unit2600 unit2601 unit2602 unit2603 unit2604 \
unit3200 \
unit3205 \
unit3211 unit3212 unit3213
unit1300_SOURCES = unit1300.c $(UNITFILES)
unit1302_SOURCES = unit1302.c $(UNITFILES)
unit1303_SOURCES = unit1303.c $(UNITFILES)
unit1304_SOURCES = unit1304.c $(UNITFILES)
unit1305_SOURCES = unit1305.c $(UNITFILES)
unit1307_SOURCES = unit1307.c $(UNITFILES)
unit1309_SOURCES = unit1309.c $(UNITFILES)
unit1323_SOURCES = unit1323.c $(UNITFILES)
unit1330_SOURCES = unit1330.c $(UNITFILES)
unit1395_SOURCES = unit1395.c $(UNITFILES)
unit1396_SOURCES = unit1396.c $(UNITFILES)
unit1397_SOURCES = unit1397.c $(UNITFILES)
unit1398_SOURCES = unit1398.c $(UNITFILES)
unit1399_SOURCES = unit1399.c $(UNITFILES)
unit1600_SOURCES = unit1600.c $(UNITFILES)
unit1601_SOURCES = unit1601.c $(UNITFILES)
unit1602_SOURCES = unit1602.c $(UNITFILES)
unit1603_SOURCES = unit1603.c $(UNITFILES)
unit1605_SOURCES = unit1605.c $(UNITFILES)
unit1606_SOURCES = unit1606.c $(UNITFILES)
unit1607_SOURCES = unit1607.c $(UNITFILES)
unit1608_SOURCES = unit1608.c $(UNITFILES)
unit1609_SOURCES = unit1609.c $(UNITFILES)
unit1610_SOURCES = unit1610.c $(UNITFILES)
unit1611_SOURCES = unit1611.c $(UNITFILES)
unit1612_SOURCES = unit1612.c $(UNITFILES)
unit1614_SOURCES = unit1614.c $(UNITFILES)
unit1615_SOURCES = unit1615.c $(UNITFILES)
unit1616_SOURCES = unit1616.c $(UNITFILES)
unit1620_SOURCES = unit1620.c $(UNITFILES)
unit1650_SOURCES = unit1650.c $(UNITFILES)
unit1651_SOURCES = unit1651.c $(UNITFILES)
unit1652_SOURCES = unit1652.c $(UNITFILES)
unit1653_SOURCES = unit1653.c $(UNITFILES)
unit1654_SOURCES = unit1654.c $(UNITFILES)
unit1655_SOURCES = unit1655.c $(UNITFILES)
unit1656_SOURCES = unit1656.c $(UNITFILES)
unit1657_SOURCES = unit1657.c $(UNITFILES)
unit1658_SOURCES = unit1658.c $(UNITFILES)
unit1660_SOURCES = unit1660.c $(UNITFILES)
unit1661_SOURCES = unit1661.c $(UNITFILES)
unit1663_SOURCES = unit1663.c $(UNITFILES)
unit1664_SOURCES = unit1664.c $(UNITFILES)
unit1979_SOURCES = unit1979.c $(UNITFILES)
unit1980_SOURCES = unit1980.c $(UNITFILES)
unit2600_SOURCES = unit2600.c $(UNITFILES)
unit2601_SOURCES = unit2601.c $(UNITFILES)
unit2602_SOURCES = unit2602.c $(UNITFILES)
unit2603_SOURCES = unit2603.c $(UNITFILES)
unit2604_SOURCES = unit2604.c $(UNITFILES)
unit3200_SOURCES = unit3200.c $(UNITFILES)
unit3205_SOURCES = unit3205.c $(UNITFILES)
unit3211_SOURCES = unit3211.c $(UNITFILES)
unit3212_SOURCES = unit3212.c $(UNITFILES)
unit3213_SOURCES = unit3213.c $(UNITFILES)
# All unit test programs
TESTFILES = \
unit1300.c unit1302.c unit1303.c unit1304.c unit1305.c unit1307.c \
unit1309.c unit1323.c \
unit1330.c unit1395.c unit1396.c unit1397.c unit1398.c \
unit1399.c \
unit1600.c unit1601.c unit1602.c unit1603.c unit1605.c unit1606.c unit1607.c \
unit1608.c unit1609.c unit1610.c unit1611.c unit1612.c unit1614.c unit1615.c unit1616.c \
unit1620.c \
unit1650.c unit1651.c unit1652.c unit1653.c unit1654.c unit1655.c unit1656.c unit1657.c \
unit1658.c \
unit1660.c unit1661.c unit1663.c unit1664.c \
unit1979.c unit1980.c \
unit2600.c unit2601.c unit2602.c unit2603.c unit2604.c \
unit3200.c \
unit3205.c \
unit3211.c unit3212.c unit3213.c

View file

@ -45,7 +45,27 @@ and the `tests/FILEFORMAT.md` documentation.
For the actual C file, here's a simple example:
~~~c
#include "curlcheck.h"
#include "a libcurl header.h" /* from the lib dir */
static CURLcode test_unit9998(char *arg)
{
UNITTEST_BEGIN_SIMPLE
/* 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_END_SIMPLE
}
~~~
Here's an example using optional initialization and cleanup:
~~~c
#include "curlcheck.h"
#include "a libcurl header.h" /* from the lib dir */
@ -61,7 +81,9 @@ For the actual C file, here's a simple example:
/* done before shutting down and exiting */
}
UNITTEST_START
static CURLcode test_unit9999(char *arg)
{
UNITTEST_BEGIN(unit_setup())
/* here you start doing things and checking that the results are good */
@ -70,4 +92,6 @@ For the actual C file, here's a simple example:
/* you end the test code like this: */
UNITTEST_STOP
UNITTEST_END(unit_stop())
}
~~~

View file

@ -92,19 +92,27 @@
} while(0)
#define UNITTEST_START \
CURLcode test(char *arg) \
{ \
(void)arg; \
if(unit_setup()) { \
fail("unit_setup() FAILURE"); \
} \
else {
#define UNITTEST_BEGIN_SIMPLE \
(void)arg; \
{
#define UNITTEST_STOP \
#define UNITTEST_END_SIMPLE \
goto unit_test_abort; /* avoid warning */ \
unit_test_abort: \
unit_stop(); \
} \
return (CURLcode)unitfail; \
}
unit_test_abort: \
return (CURLcode)unitfail;
#define UNITTEST_BEGIN(setupfunc) \
(void)arg; \
if(setupfunc) { \
fail("unit_setup() FAILURE"); \
return (CURLcode)unitfail; \
} \
{
#define UNITTEST_END(stopfunc) \
goto unit_test_abort; /* avoid warning */ \
} \
unit_test_abort: \
stopfunc; \
return (CURLcode)unitfail;

View file

@ -25,10 +25,6 @@
#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 */
@ -36,19 +32,13 @@ static void test_Curl_llist_dtor(void *key, void *value)
(void)value;
}
static CURLcode unit_setup(void)
static CURLcode test_unit1300(char *arg)
{
Curl_llist_init(&llist, test_Curl_llist_dtor);
Curl_llist_init(&llist_destination, test_Curl_llist_dtor);
return CURLE_OK;
}
UNITTEST_BEGIN_SIMPLE
static void unit_stop(void)
{
}
struct Curl_llist llist;
struct Curl_llist llist_destination;
UNITTEST_START
{
int unusedData_case1 = 1;
int unusedData_case2 = 2;
int unusedData_case3 = 3;
@ -62,6 +52,9 @@ UNITTEST_START
struct Curl_llist_node *to_remove;
size_t llist_size;
Curl_llist_init(&llist, test_Curl_llist_dtor);
Curl_llist_init(&llist_destination, test_Curl_llist_dtor);
/**
* testing llist_init
* case 1:
@ -271,5 +264,6 @@ UNITTEST_START
Curl_llist_destroy(&llist, NULL);
Curl_llist_destroy(&llist_destination, NULL);
UNITTEST_END_SIMPLE
}
UNITTEST_STOP

View file

@ -28,164 +28,145 @@
#include "curlx/base64.h"
#include "memdebug.h" /* LAST include file */
static struct Curl_easy *t1302_easy;
static CURLcode unit_setup(void)
static CURLcode test_unit1302(char *arg)
{
CURLcode res = CURLE_OK;
UNITTEST_BEGIN_SIMPLE
global_init(CURL_GLOBAL_ALL);
t1302_easy = curl_easy_init();
if(!t1302_easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
return res;
char *output;
unsigned char *decoded;
size_t size = 0;
unsigned char anychar = 'x';
CURLcode rc;
rc = curlx_base64_encode("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 = curlx_base64_encode("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 = curlx_base64_encode("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 = curlx_base64_encode("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 = curlx_base64_encode("\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 = curlx_base64url_encode("\xff\x01\xfe\x02", 4, &output, &size);
fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
fail_unless(size == 6, "size should be 6");
verify_memory(output, "_wH-Ag", 6);
Curl_safefree(output);
rc = curlx_base64url_encode("iiii", 4, &output, &size);
fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
fail_unless(size == 6, "size should be 6");
verify_memory(output, "aWlpaQ", 6);
Curl_safefree(output);
/* 0 length makes it do strlen() */
rc = curlx_base64_encode("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 = curlx_base64_encode("", 0, &output, &size);
fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
fail_unless(size == 0, "size should be 0");
fail_unless(output && !output[0], "output should be a zero-length string");
Curl_safefree(output);
rc = curlx_base64url_encode("", 0, &output, &size);
fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
fail_unless(size == 0, "size should be 0");
fail_unless(output && !output[0], "output should be a zero-length string");
Curl_safefree(output);
rc = curlx_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 = curlx_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 = curlx_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 = curlx_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 = curlx_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 = curlx_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 = curlx_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 also illegal input as it contains a padding character mid input */
size = 1; /* not zero */
decoded = &anychar; /* not NULL */
rc = curlx_base64_decode("aWlpa=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 = curlx_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_END_SIMPLE
}
static void unit_stop(void)
{
curl_easy_cleanup(t1302_easy);
curl_global_cleanup();
}
UNITTEST_START
char *output;
unsigned char *decoded;
size_t size = 0;
unsigned char anychar = 'x';
CURLcode rc;
rc = curlx_base64_encode("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 = curlx_base64_encode("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 = curlx_base64_encode("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 = curlx_base64_encode("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 = curlx_base64_encode("\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 = curlx_base64url_encode("\xff\x01\xfe\x02", 4, &output, &size);
fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
fail_unless(size == 6, "size should be 6");
verify_memory(output, "_wH-Ag", 6);
Curl_safefree(output);
rc = curlx_base64url_encode("iiii", 4, &output, &size);
fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
fail_unless(size == 6, "size should be 6");
verify_memory(output, "aWlpaQ", 6);
Curl_safefree(output);
/* 0 length makes it do strlen() */
rc = curlx_base64_encode("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 = curlx_base64_encode("", 0, &output, &size);
fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
fail_unless(size == 0, "size should be 0");
fail_unless(output && !output[0], "output should be a zero-length string");
Curl_safefree(output);
rc = curlx_base64url_encode("", 0, &output, &size);
fail_unless(rc == CURLE_OK, "return code should be CURLE_OK");
fail_unless(size == 0, "size should be 0");
fail_unless(output && !output[0], "output should be a zero-length string");
Curl_safefree(output);
rc = curlx_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 = curlx_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 = curlx_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 = curlx_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 = curlx_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 = curlx_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 = curlx_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 also illegal input as it contains a padding character mid input */
size = 1; /* not zero */
decoded = &anychar; /* not NULL */
rc = curlx_base64_decode("aWlpa=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 = curlx_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

@ -27,24 +27,22 @@
#include "connect.h"
#include "memdebug.h" /* LAST include file */
static struct Curl_easy *t1303_easy;
static CURLcode unit_setup(void)
static CURLcode t1303_setup(struct Curl_easy **easy)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
t1303_easy = curl_easy_init();
if(!t1303_easy) {
*easy = curl_easy_init();
if(!*easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
return res;
}
static void unit_stop(void)
static void t1303_stop(struct Curl_easy *easy)
{
curl_easy_cleanup(t1303_easy);
curl_easy_cleanup(easy);
curl_global_cleanup();
}
@ -55,8 +53,8 @@ static void unit_stop(void)
/* 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) t1303_easy->set.timeout = x; \
t1303_easy->set.connecttimeout = y
#define TIMEOUTS(x,y) easy->set.timeout = x; \
easy->set.connecttimeout = y
/*
* To test:
@ -67,21 +65,25 @@ static void unit_stop(void)
* N various values of now
*/
struct timetest {
int now_s;
int now_us;
unsigned int timeout_ms;
unsigned int connecttimeout_ms;
bool connecting;
timediff_t result;
const char *comment;
};
UNITTEST_START
static CURLcode test_unit1303(char *arg)
{
struct Curl_easy *easy;
UNITTEST_BEGIN(t1303_setup(&easy))
struct curltime now;
unsigned int i;
struct timetest {
int now_s;
int now_us;
unsigned int timeout_ms;
unsigned int connecttimeout_ms;
bool connecting;
timediff_t result;
const char *comment;
};
const struct timetest run[] = {
/* both timeouts set, not connecting */
{BASE + 4, 0, 10000, 8000, FALSE, 6000, "6 seconds should be left"},
@ -137,18 +139,19 @@ UNITTEST_START
};
/* this is the pretended start time of the transfer */
t1303_easy->progress.t_startsingle.tv_sec = BASE;
t1303_easy->progress.t_startsingle.tv_usec = 0;
t1303_easy->progress.t_startop.tv_sec = BASE;
t1303_easy->progress.t_startop.tv_usec = 0;
easy->progress.t_startsingle.tv_sec = BASE;
easy->progress.t_startsingle.tv_usec = 0;
easy->progress.t_startop.tv_sec = BASE;
easy->progress.t_startop.tv_usec = 0;
for(i = 0; i < CURL_ARRAYSIZE(run); i++) {
timediff_t timeout;
NOW(run[i].now_s, run[i].now_us);
TIMEOUTS(run[i].timeout_ms, run[i].connecttimeout_ms);
timeout = Curl_timeleft(t1303_easy, &now, run[i].connecting);
timeout = Curl_timeleft(easy, &now, run[i].connecting);
if(timeout != run[i].result)
fail(run[i].comment);
}
UNITTEST_END(t1303_stop(easy))
}
UNITTEST_STOP

View file

@ -27,24 +27,19 @@
#ifndef CURL_DISABLE_NETRC
static char *s_login;
static char *s_password;
static CURLcode unit_setup(void)
static void t1304_stop(char **password, char **login)
{
s_password = NULL;
s_login = NULL;
return CURLE_OK;
Curl_safefree(*password);
Curl_safefree(*login);
}
static void unit_stop(void)
static CURLcode test_unit1304(char *arg)
{
Curl_safefree(s_password);
Curl_safefree(s_login);
}
char *login = NULL;
char *password = NULL;
UNITTEST_BEGIN_SIMPLE
UNITTEST_START
{
int result;
struct store_netrc store;
@ -53,142 +48,140 @@ UNITTEST_START
*/
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"test.example.com", &s_login, &s_password, arg);
"test.example.com", &login, &password, arg);
fail_unless(result == 1, "Host not found should return 1");
abort_unless(s_password == NULL, "password did not return NULL!");
abort_unless(s_login == NULL, "user did not return NULL!");
abort_unless(password == NULL, "password did not return NULL!");
abort_unless(login == NULL, "user did not return NULL!");
Curl_netrc_cleanup(&store);
/*
* Test a non existent login in our netrc file.
*/
s_login = (char *)CURL_UNCONST("me");
login = (char *)CURL_UNCONST("me");
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"example.com", &s_login, &s_password, arg);
"example.com", &login, &password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(s_password == NULL, "password is not NULL!");
abort_unless(password == NULL, "password is not NULL!");
Curl_netrc_cleanup(&store);
/*
* Test a non existent login and host in our netrc file.
*/
s_login = (char *)CURL_UNCONST("me");
login = (char *)CURL_UNCONST("me");
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"test.example.com", &s_login, &s_password, arg);
"test.example.com", &login, &password, arg);
fail_unless(result == 1, "Host not found should return 1");
abort_unless(s_password == NULL, "password is not NULL!");
abort_unless(password == NULL, "password is not NULL!");
Curl_netrc_cleanup(&store);
/*
* Test a non existent login (substring of an existing one) in our
* netrc file.
*/
s_login = (char *)CURL_UNCONST("admi");
login = (char *)CURL_UNCONST("admi");
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"example.com", &s_login, &s_password, arg);
"example.com", &login, &password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(s_password == NULL, "password is not NULL!");
abort_unless(password == NULL, "password is not NULL!");
Curl_netrc_cleanup(&store);
/*
* Test a non existent login (superstring of an existing one)
* in our netrc file.
*/
s_login = (char *)CURL_UNCONST("adminn");
login = (char *)CURL_UNCONST("adminn");
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"example.com", &s_login, &s_password, arg);
"example.com", &login, &password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(s_password == NULL, "password is not NULL!");
abort_unless(password == NULL, "password is not NULL!");
Curl_netrc_cleanup(&store);
/*
* Test for the first existing host in our netrc file
* with s_login[0] = 0.
* with login[0] = 0.
*/
s_login = NULL;
login = NULL;
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"example.com", &s_login, &s_password, arg);
"example.com", &login, &password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(s_password != NULL, "returned NULL!");
fail_unless(strncmp(s_password, "passwd", 6) == 0,
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "passwd", 6) == 0,
"password should be 'passwd'");
abort_unless(s_login != NULL, "returned NULL!");
fail_unless(strncmp(s_login, "admin", 5) == 0, "login should be 'admin'");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
Curl_netrc_cleanup(&store);
/*
* Test for the first existing host in our netrc file
* with s_login[0] != 0.
* with login[0] != 0.
*/
free(s_password);
free(s_login);
s_password = NULL;
s_login = NULL;
free(password);
free(login);
password = NULL;
login = NULL;
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"example.com", &s_login, &s_password, arg);
"example.com", &login, &password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(s_password != NULL, "returned NULL!");
fail_unless(strncmp(s_password, "passwd", 6) == 0,
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "passwd", 6) == 0,
"password should be 'passwd'");
abort_unless(s_login != NULL, "returned NULL!");
fail_unless(strncmp(s_login, "admin", 5) == 0, "login should be 'admin'");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "admin", 5) == 0, "login should be 'admin'");
Curl_netrc_cleanup(&store);
/*
* Test for the second existing host in our netrc file
* with s_login[0] = 0.
* with login[0] = 0.
*/
free(s_password);
s_password = NULL;
free(s_login);
s_login = NULL;
free(password);
password = NULL;
free(login);
login = NULL;
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"curl.example.com", &s_login, &s_password, arg);
"curl.example.com", &login, &password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(s_password != NULL, "returned NULL!");
fail_unless(strncmp(s_password, "none", 4) == 0,
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "none", 4) == 0,
"password should be 'none'");
abort_unless(s_login != NULL, "returned NULL!");
fail_unless(strncmp(s_login, "none", 4) == 0, "login should be 'none'");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
Curl_netrc_cleanup(&store);
/*
* Test for the second existing host in our netrc file
* with s_login[0] != 0.
* with login[0] != 0.
*/
free(s_password);
free(s_login);
s_password = NULL;
s_login = NULL;
free(password);
free(login);
password = NULL;
login = NULL;
Curl_netrc_init(&store);
result = Curl_parsenetrc(&store,
"curl.example.com", &s_login, &s_password, arg);
"curl.example.com", &login, &password, arg);
fail_unless(result == 0, "Host should have been found");
abort_unless(s_password != NULL, "returned NULL!");
fail_unless(strncmp(s_password, "none", 4) == 0,
abort_unless(password != NULL, "returned NULL!");
fail_unless(strncmp(password, "none", 4) == 0,
"password should be 'none'");
abort_unless(s_login != NULL, "returned NULL!");
fail_unless(strncmp(s_login, "none", 4) == 0, "login should be 'none'");
abort_unless(login != NULL, "returned NULL!");
fail_unless(strncmp(login, "none", 4) == 0, "login should be 'none'");
Curl_netrc_cleanup(&store);
UNITTEST_END(t1304_stop(&password, &login))
}
UNITTEST_STOP
#else
static CURLcode unit_setup(void)
static CURLcode test_unit1304(char *arg)
{
return CURLE_OK;
UNITTEST_BEGIN_SIMPLE
UNITTEST_END_SIMPLE
}
static void unit_stop(void)
{
}
UNITTEST_START
UNITTEST_STOP
#endif

View file

@ -40,24 +40,17 @@
#include "memdebug.h" /* LAST include file */
static struct Curl_easy *t1305_easy;
static struct Curl_dnscache hp;
static char *data_key;
static struct Curl_dns_entry *data_node;
static CURLcode unit_setup(void)
static CURLcode t1305_setup(void)
{
t1305_easy = curl_easy_init();
if(!t1305_easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
Curl_dnscache_init(&hp, 7);
return CURLE_OK;
}
static void unit_stop(void)
static void t1305_stop(void)
{
if(data_node) {
Curl_freeaddrinfo(data_node->addr);
@ -65,15 +58,12 @@ static void unit_stop(void)
}
free(data_key);
Curl_dnscache_destroy(&hp);
curl_easy_cleanup(t1305_easy);
curl_global_cleanup();
}
static struct Curl_addrinfo *fake_ai(void)
{
static struct Curl_addrinfo *ai;
static const char dummy[]="dummy";
static const char dummy[] = "dummy";
size_t namelen = sizeof(dummy); /* including the null-terminator */
ai = calloc(1, sizeof(struct Curl_addrinfo) + sizeof(struct sockaddr_in) +
@ -109,14 +99,15 @@ static CURLcode create_node(void)
return CURLE_OK;
}
UNITTEST_START
static CURLcode test_unit1305(char *arg)
{
UNITTEST_BEGIN(t1305_setup())
struct Curl_dns_entry *nodep;
size_t key_len;
/* Test 1305 exits without adding anything to the hash */
if(strcmp(arg, "1305") != 0) {
if(testnum == 1306) {
CURLcode rc = create_node();
abort_unless(rc == CURLE_OK, "data node creation failed");
key_len = strlen(data_key);
@ -128,4 +119,5 @@ UNITTEST_START
data_node = NULL;
}
UNITTEST_STOP
UNITTEST_END(t1305_stop())
}

View file

@ -25,15 +25,6 @@
#include "curl_fnmatch.h"
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
#ifndef CURL_DISABLE_FTP
/*
@ -72,14 +63,10 @@ static const char *ret2name(int i)
/* not reached */
}
enum system {
SYSTEM_CUSTOM,
SYSTEM_LINUX,
SYSTEM_MACOS
};
UNITTEST_START
static CURLcode test_unit1307(char *arg)
{
UNITTEST_BEGIN_SIMPLE
struct testcase {
const char *pattern;
const char *string;
@ -278,6 +265,13 @@ UNITTEST_START
};
int i;
enum system {
SYSTEM_CUSTOM,
SYSTEM_LINUX,
SYSTEM_MACOS
};
enum system machine;
#ifdef HAVE_FNMATCH
@ -311,12 +305,16 @@ UNITTEST_START
fail("pattern mismatch");
}
}
UNITTEST_END_SIMPLE
}
UNITTEST_STOP
#else
UNITTEST_START
UNITTEST_STOP
static CURLcode test_unit1307(char *arg)
{
UNITTEST_BEGIN_SIMPLE
UNITTEST_END_SIMPLE
}
#endif

View file

@ -26,17 +26,6 @@
#include "splay.h"
#include "warnless.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;
@ -68,7 +57,9 @@ static void splayprint(struct Curl_tree *t, int d, char output)
splayprint(t->smaller, d + 1, output);
}
UNITTEST_START
static CURLcode test_unit1309(char *arg)
{
UNITTEST_BEGIN_SIMPLE
/* number of nodes to add to the splay tree */
#define NUM_NODES 50
@ -141,4 +132,5 @@ UNITTEST_START
fail_unless(root == NULL, "tree not empty when it should be");
UNITTEST_STOP
UNITTEST_END_SIMPLE
}

View file

@ -25,30 +25,23 @@
#include "timeval.h"
static CURLcode unit_setup(void)
static CURLcode test_unit1323(char *arg)
{
return CURLE_OK;
}
UNITTEST_BEGIN_SIMPLE
static void unit_stop(void)
{
struct a {
struct curltime first;
struct curltime second;
time_t result;
};
}
struct a {
struct curltime first;
struct curltime second;
time_t result;
};
UNITTEST_START
{
struct a tests[] = {
{ {36762, 8345 }, {36761, 995926 }, 13 },
{ {36761, 995926 }, {36762, 8345 }, -13 },
{ {36761, 995926 }, {0, 0}, 36761995 },
{ {0, 0}, {36761, 995926 }, -36761995 },
};
size_t i;
for(i = 0; i < CURL_ARRAYSIZE(tests); i++) {
@ -64,5 +57,6 @@ UNITTEST_START
fail("unexpected result!");
}
}
UNITTEST_END_SIMPLE
}
UNITTEST_STOP

View file

@ -25,19 +25,12 @@
#include "memdebug.h"
static CURLcode unit_setup(void)
static CURLcode test_unit1330(char *arg)
{
return CURLE_OK;
UNITTEST_BEGIN_SIMPLE
char *ptr = malloc(1330);
Curl_safefree(ptr);
UNITTEST_END_SIMPLE
}
static void unit_stop(void)
{
}
UNITTEST_START
char *ptr = malloc(1330);
Curl_safefree(ptr);
UNITTEST_STOP

View file

@ -28,25 +28,18 @@ extern int dedotdotify(const char *input, size_t clen, char **out);
#include "memdebug.h"
static CURLcode unit_setup(void)
static CURLcode test_unit1395(char *arg)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
struct dotdot {
const char *input;
const char *output;
};
UNITTEST_START
UNITTEST_BEGIN_SIMPLE
unsigned int i;
int fails = 0;
struct dotdot {
const char *input;
const char *output;
};
const struct dotdot pairs[] = {
{ "%2f%2e%2e%2f/../a", "%2f%2e%2e%2f/a" },
{ "%2f%2e%2e%2f/../", "%2f%2e%2e%2f/" },
@ -148,4 +141,5 @@ UNITTEST_START
fail_if(fails, "output mismatched");
UNITTEST_STOP
UNITTEST_END_SIMPLE
}

View file

@ -23,34 +23,35 @@
***************************************************************************/
#include "curlcheck.h"
static CURL *hnd;
static CURLcode unit_setup(void)
static CURLcode t1396_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
return res;
}
static void unit_stop(void)
static void t1396_stop(CURL *easy)
{
if(hnd)
curl_easy_cleanup(hnd);
if(easy)
curl_easy_cleanup(easy);
curl_global_cleanup();
}
struct test {
const char *in;
int inlen;
const char *out;
int outlen;
};
UNITTEST_START
static CURLcode test_unit1396(char *arg)
{
CURL *easy;
UNITTEST_BEGIN(t1396_setup())
struct test {
const char *in;
int inlen;
const char *out;
int outlen;
};
/* unescape, this => that */
const struct test list1[]={
const struct test list1[] = {
{"%61", 3, "a", 1},
{"%61a", 4, "aa", 2},
{"%61b", 4, "ab", 2},
@ -66,7 +67,7 @@ UNITTEST_START
{NULL, 0, NULL, 0} /* end of list marker */
};
/* escape, this => that */
const struct test list2[]={
const struct test list2[] = {
{"a", 1, "a", 1},
{"/", 1, "%2F", 3},
{"a=b", 3, "a%3Db", 5},
@ -81,11 +82,11 @@ UNITTEST_START
};
int i;
hnd = curl_easy_init();
abort_unless(hnd != NULL, "returned NULL!");
easy = curl_easy_init();
abort_unless(easy != NULL, "returned NULL!");
for(i = 0; list1[i].in; i++) {
int outlen;
char *out = curl_easy_unescape(hnd,
char *out = curl_easy_unescape(easy,
list1[i].in, list1[i].inlen,
&outlen);
@ -101,7 +102,7 @@ UNITTEST_START
for(i = 0; list2[i].in; i++) {
int outlen;
char *out = curl_easy_escape(hnd, list2[i].in, list2[i].inlen);
char *out = curl_easy_escape(easy, list2[i].in, list2[i].inlen);
abort_unless(out != NULL, "returned NULL!");
outlen = (int)strlen(out);
@ -113,5 +114,6 @@ UNITTEST_START
curl_free(out);
}
UNITTEST_END(t1396_stop(easy))
}
UNITTEST_STOP

View file

@ -23,29 +23,22 @@
***************************************************************************/
#include "curlcheck.h"
#include "vtls/hostcheck.h"
static CURLcode unit_setup(void)
static CURLcode test_unit1397(char *arg)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
UNITTEST_BEGIN_SIMPLE
/* only these backends define the tested functions */
#if defined(USE_OPENSSL) || defined(USE_SCHANNEL)
#include "vtls/hostcheck.h"
UNITTEST_START
{
struct testcase {
const char *host;
const char *pattern;
bool match;
};
static struct testcase tests[] = {
static const struct testcase tests[] = {
{"", "", FALSE},
{"a", "", FALSE},
{"", "b", FALSE},
@ -114,12 +107,7 @@ UNITTEST_START
unitfail++;
}
}
}
UNITTEST_STOP
#else
UNITTEST_START
UNITTEST_STOP
#endif
UNITTEST_END_SIMPLE
}

View file

@ -28,170 +28,164 @@
#pragma GCC diagnostic ignored "-Wformat"
#endif
static CURLcode unit_setup(void)
static CURLcode test_unit1398(char *arg)
{
return CURLE_OK;
UNITTEST_BEGIN_SIMPLE
int rc;
char buf[3] = {'b', 'u', 'g'};
const char *str = "bug";
int width = 3;
char output[130];
/*#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 == 7, "return code should be 7");
fail_unless(!strcmp(output, "bug "), "wrong output");
/* larger width that string length */
rc = curl_msnprintf(output, 8, "%8s", str);
fail_unless(rc == 7, "return code should be 7");
fail_unless(!strcmp(output, " bu"), "wrong output");
/* output a number in a limited output */
rc = curl_msnprintf(output, 4, "%d", 10240);
fail_unless(rc == 3, "return code should be 3");
fail_unless(!strcmp(output, "102"), "wrong output");
/* padded strings */
rc = curl_msnprintf(output, 16, "%8s%8s", str, str);
fail_unless(rc == 15, "return code should be 15");
fail_unless(!strcmp(output, " bug bu"), "wrong output");
/* padded numbers */
rc = curl_msnprintf(output, 16, "%8d%8d", 1234, 5678);
fail_unless(rc == 15, "return code should be 15");
fail_unless(!strcmp(output, " 1234 567"), "wrong output");
/* double precision */
rc = curl_msnprintf(output, 24, "%2$.*1$.99d", 3, 5678);
fail_unless(rc == 0, "return code should be 0");
/* 129 input % flags */
rc = curl_msnprintf(output, 130,
"%s%s%s%s%s%s%s%s%s%s" /* 10 */
"%s%s%s%s%s%s%s%s%s%s" /* 20 */
"%s%s%s%s%s%s%s%s%s%s" /* 30 */
"%s%s%s%s%s%s%s%s%s%s" /* 40 */
"%s%s%s%s%s%s%s%s%s%s" /* 50 */
"%s%s%s%s%s%s%s%s%s%s" /* 60 */
"%s%s%s%s%s%s%s%s%s%s" /* 70 */
"%s%s%s%s%s%s%s%s%s%s" /* 80 */
"%s%s%s%s%s%s%s%s%s%s" /* 90 */
"%s%s%s%s%s%s%s%s%s%s" /* 100 */
"%s%s%s%s%s%s%s%s%s%s" /* 110 */
"%s%s%s%s%s%s%s%s%s%s" /* 120 */
"%s%s%s%s%s%s%s%s%s", /* 129 */
"a", "", "", "", "", "", "", "", "", "", /* 10 */
"b", "", "", "", "", "", "", "", "", "", /* 20 */
"c", "", "", "", "", "", "", "", "", "", /* 30 */
"d", "", "", "", "", "", "", "", "", "", /* 40 */
"e", "", "", "", "", "", "", "", "", "", /* 50 */
"f", "", "", "", "", "", "", "", "", "", /* 60 */
"g", "", "", "", "", "", "", "", "", "", /* 70 */
"h", "", "", "", "", "", "", "", "", "", /* 80 */
"i", "", "", "", "", "", "", "", "", "", /* 90 */
"j", "", "", "", "", "", "", "", "", "", /* 100 */
"k", "", "", "", "", "", "", "", "", "", /* 110 */
"l", "", "", "", "", "", "", "", "", "", /* 120 */
"m", "", "", "", "", "", "", "", "" /* 129 */
);
fail_unless(rc == 0, "return code should be 0");
/* 128 input % flags */
rc = curl_msnprintf(output, 130,
"%s%s%s%s%s%s%s%s%s%s" /* 10 */
"%s%s%s%s%s%s%s%s%s%s" /* 20 */
"%s%s%s%s%s%s%s%s%s%s" /* 30 */
"%s%s%s%s%s%s%s%s%s%s" /* 40 */
"%s%s%s%s%s%s%s%s%s%s" /* 50 */
"%s%s%s%s%s%s%s%s%s%s" /* 60 */
"%s%s%s%s%s%s%s%s%s%s" /* 70 */
"%s%s%s%s%s%s%s%s%s%s" /* 80 */
"%s%s%s%s%s%s%s%s%s%s" /* 90 */
"%s%s%s%s%s%s%s%s%s%s" /* 100 */
"%s%s%s%s%s%s%s%s%s%s" /* 110 */
"%s%s%s%s%s%s%s%s%s%s" /* 120 */
"%s%s%s%s%s%s%s%s", /* 128 */
"a", "", "", "", "", "", "", "", "", "", /* 10 */
"b", "", "", "", "", "", "", "", "", "", /* 20 */
"c", "", "", "", "", "", "", "", "", "", /* 30 */
"d", "", "", "", "", "", "", "", "", "", /* 40 */
"e", "", "", "", "", "", "", "", "", "", /* 50 */
"f", "", "", "", "", "", "", "", "", "", /* 60 */
"g", "", "", "", "", "", "", "", "", "", /* 70 */
"h", "", "", "", "", "", "", "", "", "", /* 80 */
"i", "", "", "", "", "", "", "", "", "", /* 90 */
"j", "", "", "", "", "", "", "", "", "", /* 100 */
"k", "", "", "", "", "", "", "", "", "", /* 110 */
"l", "", "", "", "", "", "", "", "", "", /* 120 */
"m", "", "", "", "", "", "", "" /* 128 */
);
fail_unless(rc == 13, "return code should be 13");
/* 129 output segments */
rc = curl_msnprintf(output, 130,
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 20 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 40 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 60 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 80 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 100 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 120 */
"%%%%%%%%%%%%%%%%%%" /* 129 */
);
fail_unless(rc == 0, "return code should be 0");
/* 128 output segments */
rc = curl_msnprintf(output, 129,
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 20 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 40 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 60 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 80 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 100 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 120 */
"%%%%%%%%%%%%%%%%" /* 128 */
);
fail_unless(rc == 128, "return code should be 128");
UNITTEST_END_SIMPLE
}
static void unit_stop(void)
{
}
UNITTEST_START
int rc;
char buf[3] = {'b', 'u', 'g'};
const char *str = "bug";
int width = 3;
char output[130];
/*#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 == 7, "return code should be 7");
fail_unless(!strcmp(output, "bug "), "wrong output");
/* larger width that string length */
rc = curl_msnprintf(output, 8, "%8s", str);
fail_unless(rc == 7, "return code should be 7");
fail_unless(!strcmp(output, " bu"), "wrong output");
/* output a number in a limited output */
rc = curl_msnprintf(output, 4, "%d", 10240);
fail_unless(rc == 3, "return code should be 3");
fail_unless(!strcmp(output, "102"), "wrong output");
/* padded strings */
rc = curl_msnprintf(output, 16, "%8s%8s", str, str);
fail_unless(rc == 15, "return code should be 15");
fail_unless(!strcmp(output, " bug bu"), "wrong output");
/* padded numbers */
rc = curl_msnprintf(output, 16, "%8d%8d", 1234, 5678);
fail_unless(rc == 15, "return code should be 15");
fail_unless(!strcmp(output, " 1234 567"), "wrong output");
/* double precision */
rc = curl_msnprintf(output, 24, "%2$.*1$.99d", 3, 5678);
fail_unless(rc == 0, "return code should be 0");
/* 129 input % flags */
rc = curl_msnprintf(output, 130,
"%s%s%s%s%s%s%s%s%s%s" /* 10 */
"%s%s%s%s%s%s%s%s%s%s" /* 20 */
"%s%s%s%s%s%s%s%s%s%s" /* 30 */
"%s%s%s%s%s%s%s%s%s%s" /* 40 */
"%s%s%s%s%s%s%s%s%s%s" /* 50 */
"%s%s%s%s%s%s%s%s%s%s" /* 60 */
"%s%s%s%s%s%s%s%s%s%s" /* 70 */
"%s%s%s%s%s%s%s%s%s%s" /* 80 */
"%s%s%s%s%s%s%s%s%s%s" /* 90 */
"%s%s%s%s%s%s%s%s%s%s" /* 100 */
"%s%s%s%s%s%s%s%s%s%s" /* 110 */
"%s%s%s%s%s%s%s%s%s%s" /* 120 */
"%s%s%s%s%s%s%s%s%s", /* 129 */
"a", "", "", "", "", "", "", "", "", "", /* 10 */
"b", "", "", "", "", "", "", "", "", "", /* 20 */
"c", "", "", "", "", "", "", "", "", "", /* 30 */
"d", "", "", "", "", "", "", "", "", "", /* 40 */
"e", "", "", "", "", "", "", "", "", "", /* 50 */
"f", "", "", "", "", "", "", "", "", "", /* 60 */
"g", "", "", "", "", "", "", "", "", "", /* 70 */
"h", "", "", "", "", "", "", "", "", "", /* 80 */
"i", "", "", "", "", "", "", "", "", "", /* 90 */
"j", "", "", "", "", "", "", "", "", "", /* 100 */
"k", "", "", "", "", "", "", "", "", "", /* 110 */
"l", "", "", "", "", "", "", "", "", "", /* 120 */
"m", "", "", "", "", "", "", "", "" /* 129 */
);
fail_unless(rc == 0, "return code should be 0");
/* 128 input % flags */
rc = curl_msnprintf(output, 130,
"%s%s%s%s%s%s%s%s%s%s" /* 10 */
"%s%s%s%s%s%s%s%s%s%s" /* 20 */
"%s%s%s%s%s%s%s%s%s%s" /* 30 */
"%s%s%s%s%s%s%s%s%s%s" /* 40 */
"%s%s%s%s%s%s%s%s%s%s" /* 50 */
"%s%s%s%s%s%s%s%s%s%s" /* 60 */
"%s%s%s%s%s%s%s%s%s%s" /* 70 */
"%s%s%s%s%s%s%s%s%s%s" /* 80 */
"%s%s%s%s%s%s%s%s%s%s" /* 90 */
"%s%s%s%s%s%s%s%s%s%s" /* 100 */
"%s%s%s%s%s%s%s%s%s%s" /* 110 */
"%s%s%s%s%s%s%s%s%s%s" /* 120 */
"%s%s%s%s%s%s%s%s", /* 128 */
"a", "", "", "", "", "", "", "", "", "", /* 10 */
"b", "", "", "", "", "", "", "", "", "", /* 20 */
"c", "", "", "", "", "", "", "", "", "", /* 30 */
"d", "", "", "", "", "", "", "", "", "", /* 40 */
"e", "", "", "", "", "", "", "", "", "", /* 50 */
"f", "", "", "", "", "", "", "", "", "", /* 60 */
"g", "", "", "", "", "", "", "", "", "", /* 70 */
"h", "", "", "", "", "", "", "", "", "", /* 80 */
"i", "", "", "", "", "", "", "", "", "", /* 90 */
"j", "", "", "", "", "", "", "", "", "", /* 100 */
"k", "", "", "", "", "", "", "", "", "", /* 110 */
"l", "", "", "", "", "", "", "", "", "", /* 120 */
"m", "", "", "", "", "", "", "" /* 128 */
);
fail_unless(rc == 13, "return code should be 13");
/* 129 output segments */
rc = curl_msnprintf(output, 130,
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 20 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 40 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 60 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 80 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 100 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 120 */
"%%%%%%%%%%%%%%%%%%" /* 129 */
);
fail_unless(rc == 0, "return code should be 0");
/* 128 output segments */
rc = curl_msnprintf(output, 129,
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 20 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 40 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 60 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 80 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 100 */
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" /* 120 */
"%%%%%%%%%%%%%%%%" /* 128 */
);
fail_unless(rc == 128, "return code should be 128");
UNITTEST_STOP
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic pop
#endif

View file

@ -26,17 +26,6 @@
#include "urldata.h"
#include "progress.h"
static int usec_magnitude = 1000000;
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
/*
* Invoke Curl_pgrsTime for TIMER_STARTSINGLE to trigger the behavior that
* manages is_t_startransfer_set, but fake the t_startsingle time for purposes
@ -53,6 +42,8 @@ static void fake_t_startsingle_time(struct Curl_easy *data,
static bool usec_matches_seconds(timediff_t time_usec, int expected_seconds)
{
static int usec_magnitude = 1000000;
int time_sec = (int)(time_usec / usec_magnitude);
bool same = (time_sec == expected_seconds);
curl_mfprintf(stderr, "is %d us same as %d seconds? %s\n",
@ -80,7 +71,10 @@ static void expect_timer_seconds(struct Curl_easy *data, int seconds)
* E.g., if t_starttransfer took 2 seconds initially and took another 1
* second for the redirect request, then the resulting t_starttransfer should
* be 3 seconds. */
UNITTEST_START
static CURLcode test_unit1399(char *arg)
{
UNITTEST_BEGIN_SIMPLE
struct Curl_easy data;
struct curltime now = curlx_now();
@ -116,4 +110,6 @@ UNITTEST_START
Curl_pgrsTime(&data, TIMER_STARTTRANSFER);
expect_timer_seconds(&data, 3);
UNITTEST_STOP
UNITTEST_END_SIMPLE
}

View file

@ -26,28 +26,30 @@
#include "urldata.h"
#include "curl_ntlm_core.h"
static CURL *t1600_easy;
static CURLcode unit_setup(void)
static CURLcode t1600_setup(CURL **easy)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
t1600_easy = curl_easy_init();
if(!t1600_easy) {
*easy = curl_easy_init();
if(!*easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
return res;
}
static void unit_stop(void)
static void t1600_stop(CURL *easy)
{
curl_easy_cleanup(t1600_easy);
curl_easy_cleanup(easy);
curl_global_cleanup();
}
UNITTEST_START
static CURLcode test_unit1600(char *arg)
{
CURL *easy;
UNITTEST_BEGIN(t1600_setup(&easy))
#if defined(USE_NTLM) && (!defined(USE_WINDOWS_SSPI) || \
defined(USE_WIN32_CRYPTO))
@ -65,11 +67,12 @@ UNITTEST_START
"\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 */
/* !checksrc! disable LONGLINE 2 */
Curl_ntlm_core_mk_nt_hash("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
UNITTEST_END(t1600_stop(easy))
}

View file

@ -25,17 +25,9 @@
#include "curl_md5.h"
static CURLcode unit_setup(void)
static CURLcode test_unit1601(char *arg)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
UNITTEST_START
UNITTEST_BEGIN_SIMPLE
#if (defined(USE_CURL_NTLM_CORE) && !defined(USE_WINDOWS_SSPI)) \
|| !defined(CURL_DISABLE_DIGEST_AUTH)
@ -56,5 +48,5 @@ UNITTEST_START
"\x87\x5f\x22", MD5_DIGEST_LEN);
#endif
UNITTEST_STOP
UNITTEST_END_SIMPLE
}

View file

@ -29,27 +29,30 @@
#include <memdebug.h> /* LAST include file */
static struct Curl_hash t1602_hash_static;
static void t1602_mydtor(void *p)
{
int *ptr = (int *)p;
free(ptr);
}
static CURLcode unit_setup(void)
static CURLcode t1602_setup(struct Curl_hash *hash)
{
Curl_hash_init(&t1602_hash_static, 7, Curl_hash_str,
Curl_hash_init(hash, 7, Curl_hash_str,
curlx_str_key_compare, t1602_mydtor);
return CURLE_OK;
}
static void unit_stop(void)
static void t1602_stop(struct Curl_hash *hash)
{
Curl_hash_destroy(&t1602_hash_static);
Curl_hash_destroy(hash);
}
UNITTEST_START
static CURLcode test_unit1602(char *arg)
{
struct Curl_hash hash;
UNITTEST_BEGIN(t1602_setup(&hash))
int *value;
int *value2;
int *nodep;
@ -58,23 +61,23 @@ UNITTEST_START
int key = 20;
int key2 = 25;
value = malloc(sizeof(int));
abort_unless(value != NULL, "Out of memory");
*value = 199;
nodep = Curl_hash_add(&t1602_hash_static, &key, klen, value);
nodep = Curl_hash_add(&hash, &key, klen, value);
if(!nodep)
free(value);
abort_unless(nodep, "insertion into hash failed");
Curl_hash_clean(&t1602_hash_static);
Curl_hash_clean(&hash);
/* Attempt to add another key/value pair */
value2 = malloc(sizeof(int));
abort_unless(value2 != NULL, "Out of memory");
*value2 = 204;
nodep = Curl_hash_add(&t1602_hash_static, &key2, klen, value2);
nodep = Curl_hash_add(&hash, &key2, klen, value2);
if(!nodep)
free(value2);
abort_unless(nodep, "insertion into hash failed");
UNITTEST_STOP
UNITTEST_END(t1602_stop(&hash))
}

View file

@ -27,7 +27,6 @@
#include "hash.h"
#include <memdebug.h> /* LAST include file */
static struct Curl_hash t1603_hash_static;
static const size_t slots = 3;
static void t1603_mydtor(void *p)
@ -46,19 +45,24 @@ static void my_elem_dtor(void *key, size_t key_len, void *p)
++elem_dtor_calls;
}
static CURLcode unit_setup(void)
static CURLcode t1603_setup(struct Curl_hash *hash_static)
{
Curl_hash_init(&t1603_hash_static, slots, Curl_hash_str,
Curl_hash_init(hash_static, slots, Curl_hash_str,
curlx_str_key_compare, t1603_mydtor);
return CURLE_OK;
}
static void unit_stop(void)
static void t1603_stop(struct Curl_hash *hash_static)
{
Curl_hash_destroy(&t1603_hash_static);
Curl_hash_destroy(hash_static);
}
UNITTEST_START
static CURLcode test_unit1603(char *arg)
{
struct Curl_hash hash_static;
UNITTEST_BEGIN(t1603_setup(&hash_static))
char key1[] = "key1";
char key2[] = "key2b";
char key3[] = "key3";
@ -78,100 +82,100 @@ UNITTEST_START
"Warning: hashes are not computed as expected on this "
"architecture; test coverage will be less comprehensive\n");
nodep = Curl_hash_add(&t1603_hash_static, &key1, strlen(key1), &key1);
nodep = Curl_hash_add(&hash_static, &key1, strlen(key1), &key1);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key1, strlen(key1));
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(nodep == key1, "hash retrieval failed");
nodep = Curl_hash_add(&t1603_hash_static, &key2, strlen(key2), &key2);
nodep = Curl_hash_add(&hash_static, &key2, strlen(key2), &key2);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key2, strlen(key2));
nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
fail_unless(nodep == key2, "hash retrieval failed");
nodep = Curl_hash_add(&t1603_hash_static, &key3, strlen(key3), &key3);
nodep = Curl_hash_add(&hash_static, &key3, strlen(key3), &key3);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key3, strlen(key3));
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(&t1603_hash_static, &key4, strlen(key4), &key4);
nodep = Curl_hash_add(&hash_static, &key4, strlen(key4), &key4);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key4, strlen(key4));
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(&t1603_hash_static, &key1, strlen(key1));
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(nodep == key1, "hash retrieval failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key2, strlen(key2));
nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
fail_unless(nodep == key2, "hash retrieval failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key3, strlen(key3));
nodep = Curl_hash_pick(&hash_static, &key3, strlen(key3));
fail_unless(nodep == key3, "hash retrieval failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key4, strlen(key4));
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(&t1603_hash_static, &key4, strlen(key4));
rc = Curl_hash_delete(&hash_static, &key4, strlen(key4));
fail_unless(rc == 0, "hash delete failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key1, strlen(key1));
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(nodep == key1, "hash retrieval failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key4, strlen(key4));
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(&t1603_hash_static, &key4, strlen(key4), &key4);
nodep = Curl_hash_add(&hash_static, &key4, strlen(key4), &key4);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key4, strlen(key4));
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(&t1603_hash_static, &key1, strlen(key1));
rc = Curl_hash_delete(&hash_static, &key1, strlen(key1));
fail_unless(rc == 0, "hash delete failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key1, strlen(key1));
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(!nodep, "hash retrieval should have failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key4, strlen(key4));
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(&t1603_hash_static, &key4, strlen(key4));
rc = Curl_hash_delete(&hash_static, &key4, strlen(key4));
fail_unless(rc == 0, "hash delete failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key1, strlen(key1));
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
fail_unless(!nodep, "hash retrieval should have failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key4, strlen(key4));
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(&t1603_hash_static, &key4, strlen(key4));
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(&t1603_hash_static, &key1, strlen(key1), &notakey);
nodep = Curl_hash_add(&hash_static, &key1, strlen(key1), &notakey);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key1, strlen(key1));
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(&t1603_hash_static, &key2, strlen(key2));
nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
fail_unless(nodep == key2, "hash retrieval failed");
nodep = Curl_hash_pick(&t1603_hash_static, &key3, strlen(key3));
nodep = Curl_hash_pick(&hash_static, &key3, strlen(key3));
fail_unless(nodep == key3, "hash retrieval failed");
/* Add element with own destructor */
nodep = Curl_hash_add2(&t1603_hash_static, &key1, strlen(key1), &key1,
nodep = Curl_hash_add2(&hash_static, &key1, strlen(key1), &key1,
my_elem_dtor);
fail_unless(nodep, "add2 insertion into hash failed");
fail_unless(elem_dtor_calls == 0, "element destructor count should be 0");
/* Add it again, should invoke destructor on first */
nodep = Curl_hash_add2(&t1603_hash_static, &key1, strlen(key1), &key1,
nodep = Curl_hash_add2(&hash_static, &key1, strlen(key1), &key1,
my_elem_dtor);
fail_unless(nodep, "add2 again, insertion into hash failed");
fail_unless(elem_dtor_calls == 1, "element destructor count should be 1");
/* remove, should invoke destructor */
rc = Curl_hash_delete(&t1603_hash_static, &key1, strlen(key1));
rc = Curl_hash_delete(&hash_static, &key1, strlen(key1));
fail_unless(rc == 0, "hash delete failed");
fail_unless(elem_dtor_calls == 2, "element destructor count should be 1");
/* Clean up */
Curl_hash_clean(&t1603_hash_static);
Curl_hash_clean(&hash_static);
UNITTEST_STOP
UNITTEST_END(t1603_stop(&hash_static))
}

View file

@ -25,35 +25,39 @@
#include "llist.h"
static CURL *t1605_easy;
static CURLcode unit_setup(void)
static CURLcode t1605_setup(CURL **easy)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
t1605_easy = curl_easy_init();
if(!t1605_easy) {
*easy = curl_easy_init();
if(!*easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
return res;
}
static void unit_stop(void)
static void t1605_stop(CURL *easy)
{
curl_easy_cleanup(t1605_easy);
curl_easy_cleanup(easy);
curl_global_cleanup();
}
UNITTEST_START
static CURLcode test_unit1605(char *arg)
{
CURL *easy;
UNITTEST_BEGIN(t1605_setup(&easy))
int len;
char *esc;
esc = curl_easy_escape(t1605_easy, "", -1);
esc = curl_easy_escape(easy, "", -1);
fail_unless(esc == NULL, "negative string length can't work");
esc = curl_easy_unescape(t1605_easy, "%41%41%41%41", -1, &len);
esc = curl_easy_unescape(easy, "%41%41%41%41", -1, &len);
fail_unless(esc == NULL, "negative string length can't work");
UNITTEST_STOP
UNITTEST_END(t1605_stop(easy))
}

View file

@ -26,28 +26,27 @@
#include "speedcheck.h"
#include "urldata.h"
static struct Curl_easy *t1606_easy;
static CURLcode unit_setup(void)
static CURLcode t1606_setup(struct Curl_easy **easy)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
t1606_easy = curl_easy_init();
if(!t1606_easy) {
*easy = curl_easy_init();
if(!*easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
return res;
}
static void unit_stop(void)
static void t1606_stop(struct Curl_easy *easy)
{
curl_easy_cleanup(t1606_easy);
curl_easy_cleanup(easy);
curl_global_cleanup();
}
static int runawhile(long time_limit,
static int runawhile(struct Curl_easy *easy,
long time_limit,
long speed_limit,
curl_off_t speed,
int dec)
@ -57,14 +56,14 @@ static int runawhile(long time_limit,
CURLcode result;
int finaltime;
curl_easy_setopt(t1606_easy, CURLOPT_LOW_SPEED_LIMIT, speed_limit);
curl_easy_setopt(t1606_easy, CURLOPT_LOW_SPEED_TIME, time_limit);
Curl_speedinit(t1606_easy);
curl_easy_setopt(easy, CURLOPT_LOW_SPEED_LIMIT, speed_limit);
curl_easy_setopt(easy, CURLOPT_LOW_SPEED_TIME, time_limit);
Curl_speedinit(easy);
do {
/* fake the current transfer speed */
t1606_easy->progress.current_speed = speed;
result = Curl_speedcheck(t1606_easy, now);
easy->progress.current_speed = speed;
result = Curl_speedcheck(easy, now);
if(result)
break;
/* step the time */
@ -77,17 +76,24 @@ static int runawhile(long time_limit,
return finaltime;
}
UNITTEST_START
fail_unless(runawhile(41, 41, 40, 0) == 41,
static CURLcode test_unit1606(char *arg)
{
struct Curl_easy *easy;
UNITTEST_BEGIN(t1606_setup(&easy))
fail_unless(runawhile(easy, 41, 41, 40, 0) == 41,
"wrong low speed timeout");
fail_unless(runawhile(21, 21, 20, 0) == 21,
fail_unless(runawhile(easy, 21, 21, 20, 0) == 21,
"wrong low speed timeout");
fail_unless(runawhile(60, 60, 40, 0) == 60,
fail_unless(runawhile(easy, 60, 60, 40, 0) == 60,
"wrong log speed timeout");
fail_unless(runawhile(50, 50, 40, 0) == 50,
fail_unless(runawhile(easy, 50, 50, 40, 0) == 50,
"wrong log speed timeout");
fail_unless(runawhile(40, 40, 40, 0) == 99,
fail_unless(runawhile(easy, 40, 40, 40, 0) == 99,
"should not time out");
fail_unless(runawhile(10, 50, 100, 2) == 36,
fail_unless(runawhile(easy, 10, 50, 100, 2) == 36,
"bad timeout");
UNITTEST_STOP
UNITTEST_END(t1606_stop(easy))
}

View file

@ -29,30 +29,26 @@
#include "memdebug.h" /* LAST include file */
static void unit_stop(void)
{
curl_global_cleanup();
}
static CURLcode unit_setup(void)
static CURLcode t1607_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
return res;
}
/* In builds without IPv6 support CURLOPT_RESOLVE should skip over those
addresses, so we have to do that as well. */
static const char skip = 0;
static CURLcode test_unit1607(char *arg)
{
/* In builds without IPv6 support CURLOPT_RESOLVE should skip over those
addresses, so we have to do that as well. */
static const char skip = 0;
#ifdef USE_IPV6
#define IPV6ONLY(x) x
#else
#define IPV6ONLY(x) &skip
#endif
UNITTEST_START
{
UNITTEST_BEGIN(t1607_setup())
struct testcase {
/* host:port:address[,address]... */
const char *optval;
@ -233,5 +229,6 @@ error:
curl_easy_cleanup(easy);
curl_multi_cleanup(multi);
curl_slist_free_all(list);
UNITTEST_END(curl_global_cleanup())
}
UNITTEST_STOP

View file

@ -30,25 +30,21 @@
CURLcode Curl_shuffle_addr(struct Curl_easy *data,
struct Curl_addrinfo **addr);
#define NUM_ADDRS 8
static struct Curl_addrinfo addrs[NUM_ADDRS];
static struct Curl_addrinfo addrs[8];
static CURLcode unit_setup(void)
static CURLcode t1608_setup(void)
{
int i;
for(i = 0; i < NUM_ADDRS - 1; i++) {
size_t i;
for(i = 0; i < CURL_ARRAYSIZE(addrs) - 1; i++) {
addrs[i].ai_next = &addrs[i + 1];
}
return CURLE_OK;
}
static void unit_stop(void)
static CURLcode test_unit1608(char *arg)
{
curl_global_cleanup();
}
UNITTEST_START
UNITTEST_BEGIN(t1608_setup())
int i;
CURLcode code;
@ -73,17 +69,15 @@ UNITTEST_START
abort_unless(addrhead != addrs, "addresses are not being reordered");
UNITTEST_STOP
UNITTEST_END(curl_global_cleanup())
}
#else
static CURLcode unit_setup(void)
static CURLcode test_unit1608(char *arg)
{
return CURLE_OK;
UNITTEST_BEGIN_SIMPLE
UNITTEST_END_SIMPLE
}
static void unit_stop(void)
{
}
UNITTEST_START
UNITTEST_STOP
#endif

View file

@ -29,17 +29,10 @@
#include "memdebug.h" /* LAST include file */
static void unit_stop(void)
{
curl_global_cleanup();
}
static CURLcode unit_setup(void)
static CURLcode t1609_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
return res;
}
@ -75,8 +68,10 @@ Test:
expected result: cached address has zero timestamp and new address
*/
UNITTEST_START
static CURLcode test_unit1609(char *arg)
{
UNITTEST_BEGIN(t1609_setup())
struct testcase {
/* host:port:address[,address]... */
const char *optval;
@ -217,5 +212,6 @@ error:
curl_easy_cleanup(easy);
curl_multi_cleanup(multi);
curl_slist_free_all(list);
UNITTEST_END(curl_global_cleanup())
}
UNITTEST_STOP

View file

@ -25,19 +25,16 @@
#include "curl_sha256.h"
static CURLcode unit_setup(void)
static CURLcode t1610_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
return res;
}
static void unit_stop(void)
static CURLcode test_unit1610(char *arg)
{
curl_global_cleanup();
}
UNITTEST_START
UNITTEST_BEGIN(t1610_setup())
#if !defined(CURL_DISABLE_AWS) || !defined(CURL_DISABLE_DIGEST_AUTH) \
|| defined(USE_LIBSSH2)
@ -62,5 +59,5 @@ UNITTEST_START
"\x15\xae", CURL_SHA256_DIGEST_LENGTH);
#endif
UNITTEST_STOP
UNITTEST_END(curl_global_cleanup())
}

View file

@ -25,17 +25,9 @@
#include "curl_md4.h"
static CURLcode unit_setup(void)
static CURLcode test_unit1611(char *arg)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
UNITTEST_START
UNITTEST_BEGIN_SIMPLE
#ifdef USE_CURL_NTLM_CORE
const char string1[] = "1";
@ -56,5 +48,5 @@ UNITTEST_START
"\x0b", MD4_DIGEST_LENGTH);
#endif
UNITTEST_STOP
UNITTEST_END_SIMPLE
}

View file

@ -26,17 +26,9 @@
#include "curl_hmac.h"
#include "curl_md5.h"
static CURLcode unit_setup(void)
static CURLcode test_unit1612(char *arg)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
UNITTEST_START
UNITTEST_BEGIN_SIMPLE
#if (defined(USE_CURL_NTLM_CORE) && !defined(USE_WINDOWS_SSPI)) \
|| !defined(CURL_DISABLE_DIGEST_AUTH)
@ -66,5 +58,5 @@ UNITTEST_START
"\xd0", HMAC_MD5_LENGTH);
#endif
UNITTEST_STOP
UNITTEST_END_SIMPLE
}

View file

@ -25,34 +25,20 @@
#include "noproxy.h"
static CURLcode unit_setup(void)
static CURLcode test_unit1614(char *arg)
{
return CURLE_OK;
}
UNITTEST_BEGIN_SIMPLE
static void unit_stop(void)
{
}
struct check {
const char *a;
const char *n;
unsigned int bits;
bool match;
};
struct noproxy {
const char *a;
const char *n;
bool match;
};
UNITTEST_START
#if defined(DEBUGBUILD) && !defined(CURL_DISABLE_PROXY)
{
int i;
int err = 0;
struct check {
const char *a;
const char *n;
unsigned int bits;
bool match;
};
struct check list4[]= {
{ "192.160.0.1", "192.160.0.1", 33, FALSE},
{ "192.160.0.1", "192.160.0.1", 32, TRUE},
@ -78,6 +64,11 @@ UNITTEST_START
{ NULL, NULL, 0, FALSE} /* end marker */
};
#endif
struct noproxy {
const char *a;
const char *n;
bool match;
};
struct noproxy list[]= {
{ "www.example.com", "localhost .example.com .example.de", FALSE},
{ "www.example.com", "localhost,.example.com,.example.de", TRUE},
@ -161,6 +152,7 @@ UNITTEST_START
}
}
fail_if(err, "errors");
}
#endif
UNITTEST_STOP
UNITTEST_END_SIMPLE
}

View file

@ -26,17 +26,9 @@
#include "curl_sha512_256.h"
static CURLcode unit_setup(void)
static CURLcode test_unit1615(char *arg)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
UNITTEST_START
UNITTEST_BEGIN_SIMPLE
#ifdef CURL_HAVE_SHA512_256
@ -155,5 +147,5 @@ UNITTEST_START
#endif /* CURL_HAVE_SHA512_256 */
UNITTEST_STOP
UNITTEST_END_SIMPLE
}

View file

@ -27,8 +27,6 @@
#include <uint-hash.h>
#include <memdebug.h> /* LAST include file */
static struct uint_hash t1616_hash_static;
static void t1616_mydtor(unsigned int id, void *elem)
{
int *ptr = (int *)elem;
@ -36,18 +34,23 @@ static void t1616_mydtor(unsigned int id, void *elem)
free(ptr);
}
static CURLcode unit_setup(void)
static CURLcode t1616_setup(struct uint_hash *hash)
{
Curl_uint_hash_init(&t1616_hash_static, 15, t1616_mydtor);
Curl_uint_hash_init(hash, 15, t1616_mydtor);
return CURLE_OK;
}
static void unit_stop(void)
static void t1616_stop(struct uint_hash *hash)
{
Curl_uint_hash_destroy(&t1616_hash_static);
Curl_uint_hash_destroy(hash);
}
UNITTEST_START
static CURLcode test_unit1616(char *arg)
{
struct uint_hash hash;
UNITTEST_BEGIN(t1616_setup(&hash))
int *value, *v;
int *value2;
bool ok;
@ -55,31 +58,31 @@ UNITTEST_START
unsigned int key = 20;
unsigned int key2 = 25;
value = malloc(sizeof(int));
abort_unless(value != NULL, "Out of memory");
*value = 199;
ok = Curl_uint_hash_set(&t1616_hash_static, key, value);
ok = Curl_uint_hash_set(&hash, key, value);
if(!ok)
free(value);
abort_unless(ok, "insertion into hash failed");
v = Curl_uint_hash_get(&t1616_hash_static, key);
v = Curl_uint_hash_get(&hash, key);
abort_unless(v == value, "lookup present entry failed");
v = Curl_uint_hash_get(&t1616_hash_static, key2);
v = Curl_uint_hash_get(&hash, key2);
abort_unless(!v, "lookup missing entry failed");
Curl_uint_hash_clear(&t1616_hash_static);
Curl_uint_hash_clear(&hash);
/* Attempt to add another key/value pair */
value2 = malloc(sizeof(int));
abort_unless(value2 != NULL, "Out of memory");
*value2 = 204;
ok = Curl_uint_hash_set(&t1616_hash_static, key2, value2);
ok = Curl_uint_hash_set(&hash, key2, value2);
if(!ok)
free(value2);
abort_unless(ok, "insertion into hash failed");
v = Curl_uint_hash_get(&t1616_hash_static, key2);
v = Curl_uint_hash_get(&hash, key2);
abort_unless(v == value2, "lookup present entry failed");
v = Curl_uint_hash_get(&t1616_hash_static, key);
v = Curl_uint_hash_get(&hash, key);
abort_unless(!v, "lookup missing entry failed");
UNITTEST_STOP
UNITTEST_END(t1616_stop(&hash))
}

View file

@ -28,18 +28,13 @@
#include "memdebug.h" /* LAST include file */
static CURLcode unit_setup(void)
static CURLcode t1620_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
return res;
}
static void unit_stop(void)
{
curl_global_cleanup();
}
static void t1620_parse(
const char *input,
const char *exp_username,
@ -74,8 +69,10 @@ static void t1620_parse(
free(options);
}
UNITTEST_START
static CURLcode test_unit1620(char *arg)
{
UNITTEST_BEGIN(t1620_setup())
CURLcode rc;
struct Curl_easy *empty;
enum dupstring i;
@ -131,5 +128,5 @@ UNITTEST_START
rc = Curl_close(&empty);
fail_unless(rc == CURLE_OK, "Curl_close() failed");
UNITTEST_END(curl_global_cleanup())
}
UNITTEST_STOP

View file

@ -26,17 +26,12 @@
#include "doh.h"
#include "dynbuf.h"
static CURLcode unit_setup(void)
static CURLcode test_unit1650(char *arg)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
UNITTEST_BEGIN_SIMPLE
#ifndef CURL_DISABLE_DOH
#define DNS_PREAMBLE "\x00\x00\x01\x00\x00\x01\x00\x00\x00\x00\x00\x00"
#define LABEL_TEST "\x04\x74\x65\x73\x74"
#define LABEL_HOST "\x04\x68\x6f\x73\x74"
@ -49,36 +44,35 @@ static void unit_stop(void)
#define DNS_Q1 DNS_PREAMBLE LABEL_TEST LABEL_HOST LABEL_NAME DNSA_EPILOGUE
#define DNS_Q2 DNS_PREAMBLE LABEL_TEST LABEL_HOST LABEL_NAME DNSAAAA_EPILOGUE
struct dohrequest {
/* input */
const char *name;
DNStype type;
struct dohrequest {
/* input */
const char *name;
DNStype type;
/* output */
const char *packet;
size_t size;
DOHcode rc;
};
/* output */
const char *packet;
size_t size;
DOHcode rc;
};
static const struct dohrequest req[] = {
{"test.host.name", DNS_TYPE_A, DNS_Q1, sizeof(DNS_Q1)-1, DOH_OK },
{"test.host.name", DNS_TYPE_AAAA, DNS_Q2, sizeof(DNS_Q2)-1, DOH_OK },
{"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
".host.name",
DNS_TYPE_AAAA, NULL, 0, DOH_DNS_BAD_LABEL }
};
static const struct dohrequest req[] = {
{"test.host.name", DNS_TYPE_A, DNS_Q1, sizeof(DNS_Q1)-1, DOH_OK },
{"test.host.name", DNS_TYPE_AAAA, DNS_Q2, sizeof(DNS_Q2)-1, DOH_OK },
{"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
".host.name",
DNS_TYPE_AAAA, NULL, 0, DOH_DNS_BAD_LABEL }
};
struct dohresp {
/* input */
const char *packet;
size_t size;
DNStype type;
struct dohresp {
/* input */
const char *packet;
size_t size;
DNStype type;
/* output */
DOHcode rc;
const char *out;
};
/* output */
DOHcode rc;
const char *out;
};
#define DNS_FOO_EXAMPLE_COM \
"\x00\x00\x01\x00\x00\x01\x00\x01\x00\x00\x00\x00\x03\x66\x6f\x6f" \
@ -86,9 +80,9 @@ struct dohresp {
"\x01\xc0\x0c\x00\x01\x00\x01\x00\x00\x00\x37\x00\x04\x7f\x00\x00" \
"\x01"
static const char full49[] = DNS_FOO_EXAMPLE_COM;
static const char full49[] = DNS_FOO_EXAMPLE_COM;
static const struct dohresp resp[] = {
static const struct dohresp resp[] = {
{"\x00\x00", 2, DNS_TYPE_A, DOH_TOO_SMALL_BUFFER, NULL },
{"\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01\x00\x01", 12,
DNS_TYPE_A, DOH_DNS_BAD_ID, NULL },
@ -151,10 +145,8 @@ static const struct dohresp resp[] = {
DNS_TYPE_AAAA, DOH_OK,
"2020:2020:0000:0000:0000:0000:0000:2020 " },
};
};
UNITTEST_START
{
size_t size = 0;
unsigned char buffer[256];
size_t i;
@ -285,13 +277,7 @@ UNITTEST_START
}
fail_if(d.numcname, "bad cname counter");
}
}
UNITTEST_STOP
#else /* CURL_DISABLE_DOH */
UNITTEST_START
/* nothing to do, just succeed */
UNITTEST_STOP
#endif
UNITTEST_END_SIMPLE
}

View file

@ -25,20 +25,15 @@
#include "vtls/x509asn1.h"
static CURLcode unit_setup(void)
static CURLcode test_unit1651(char *arg)
{
return CURLE_OK;
}
UNITTEST_BEGIN_SIMPLE
static void unit_stop(void)
{
}
#if defined(USE_GNUTLS) || defined(USE_SCHANNEL)
/* cert captured from gdb when connecting to curl.se on October 26
2018 */
static unsigned char cert[] = {
/* cert captured from gdb when connecting to curl.se on October 26
2018 */
static unsigned char cert[] = {
0x30, 0x82, 0x0F, 0x5B, 0x30, 0x82, 0x0E, 0x43, 0xA0, 0x03, 0x02, 0x01, 0x02,
0x02, 0x0C, 0x08, 0x77, 0x99, 0x2C, 0x6B, 0x67, 0xE1, 0x18, 0xD6, 0x66, 0x66,
0x9E, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01,
@ -342,10 +337,8 @@ static unsigned char cert[] = {
0x70, 0x77, 0x54, 0x57, 0x09, 0x03, 0x56, 0x4A, 0x33, 0x60, 0x00, 0x27, 0xFE,
0xA7, 0xD7, 0xA9, 0xC4, 0xEC, 0x17, 0x17, 0x8D, 0x87, 0x70, 0x6B, 0x48, 0x88,
0x61, 0x54, 0x4A, 0x2B, 0xB7, 0x6A, 0x12, 0x08, 0xFB,
};
};
UNITTEST_START
{
CURLcode result;
const char *beg = (const char *)&cert[0];
const char *end = (const char *)&cert[sizeof(cert)];
@ -378,15 +371,9 @@ UNITTEST_START
curl_easy_cleanup(data);
}
curl_global_cleanup();
}
UNITTEST_STOP
#else
UNITTEST_START
{
puts("not tested since Curl_extract_certinfo() is not built-in");
}
UNITTEST_STOP
puts("not tested since Curl_extract_certinfo() is not built in");
#endif
UNITTEST_END_SIMPLE
}

View file

@ -32,21 +32,16 @@
* updated to still be valid.
*/
static struct Curl_easy *t1652_easy;
static char input[4096];
static char output[4096];
int debugf_cb(CURL *handle, curl_infotype type, char *buf, size_t size,
void *userptr);
/*
* This debugf callback is simply dumping the string into the static buffer
* for the unit test to inspect. Since we know that we're only dealing with
* text we can afford the luxury of skipping the type check here.
*/
int debugf_cb(CURL *handle, curl_infotype type, char *buf, size_t size,
void *userptr)
static int debugf_cb(CURL *handle, curl_infotype type, char *buf, size_t size,
void *userptr)
{
(void)handle;
(void)type;
@ -57,24 +52,24 @@ int debugf_cb(CURL *handle, curl_infotype type, char *buf, size_t size,
return 0;
}
static CURLcode unit_setup(void)
static CURLcode t1652_setup(struct Curl_easy **easy)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
t1652_easy = curl_easy_init();
if(!t1652_easy) {
*easy = curl_easy_init();
if(!*easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
curl_easy_setopt(t1652_easy, CURLOPT_DEBUGFUNCTION, debugf_cb);
curl_easy_setopt(t1652_easy, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(*easy, CURLOPT_DEBUGFUNCTION, debugf_cb);
curl_easy_setopt(*easy, CURLOPT_VERBOSE, 1L);
return res;
}
static void unit_stop(void)
static void t1652_stop(struct Curl_easy *easy)
{
curl_easy_cleanup(t1652_easy);
curl_easy_cleanup(easy);
curl_global_cleanup();
}
@ -87,7 +82,11 @@ static int verify(const char *info, const char *two)
return strncmp(info, two, nl - info);
}
UNITTEST_START
static CURLcode test_unit1652(char *arg)
{
struct Curl_easy *easy;
UNITTEST_BEGIN(t1652_setup(&easy))
#if defined(CURL_GNUC_DIAG) && !defined(__clang__)
#pragma GCC diagnostic push
@ -100,18 +99,18 @@ UNITTEST_START
/* Injecting a simple short string via a format */
curl_msnprintf(input, sizeof(input), "Simple Test");
Curl_infof(t1652_easy, "%s", input);
Curl_infof(easy, "%s", input);
fail_unless(verify(output, input) == 0, "Simple string test");
/* Injecting a few different variables with a format */
Curl_infof(t1652_easy, "%s %u testing %lu", input, 42, 43L);
Curl_infof(easy, "%s %u testing %lu", input, 42, 43L);
fail_unless(verify(output, "Simple Test 42 testing 43\n") == 0,
"Format string");
/* Variations of empty strings */
Curl_infof(t1652_easy, "");
Curl_infof(easy, "");
fail_unless(strlen(output) == 1, "Empty string");
Curl_infof(t1652_easy, "%s", (char *)NULL);
Curl_infof(easy, "%s", (char *)NULL);
fail_unless(verify(output, "(nil)") == 0, "Passing NULL as string");
/* Note: libcurl's tracebuffer hold 2048 bytes, so the max strlen() we
@ -124,7 +123,7 @@ UNITTEST_START
/* A string just long enough to not be truncated */
memset(input, '\0', sizeof(input));
memset(input, 'A', 2045);
Curl_infof(t1652_easy, "%s", input);
Curl_infof(easy, "%s", input);
fprintf(stderr, "output len %d: %s", (int)strlen(output), output);
/* output is input + \n */
fail_unless(strlen(output) == 2046, "No truncation of infof input");
@ -134,7 +133,7 @@ UNITTEST_START
/* Just over the limit without newline for truncation via '...' */
memset(input + 2045, 'A', 4);
Curl_infof(t1652_easy, "%s", input);
Curl_infof(easy, "%s", input);
fprintf(stderr, "output len %d: %s", (int)strlen(output), output);
fail_unless(strlen(output) == 2047, "Truncation of infof input 1");
fail_unless(output[sizeof(output) - 1] == '\0',
@ -143,7 +142,7 @@ UNITTEST_START
/* Just over the limit with newline for truncation via '...' */
memset(input + 2045, 'A', 4);
memset(input + 2045 + 4, '\n', 1);
Curl_infof(t1652_easy, "%s", input);
Curl_infof(easy, "%s", input);
fprintf(stderr, "output len %d: %s", (int)strlen(output), output);
fail_unless(strlen(output) == 2047, "Truncation of infof input 2");
fail_unless(output[sizeof(output) - 1] == '\0',
@ -152,7 +151,7 @@ UNITTEST_START
/* Way over the limit for truncation via '...' */
memset(input, '\0', sizeof(input));
memset(input, 'A', sizeof(input) - 1);
Curl_infof(t1652_easy, "%s", input);
Curl_infof(easy, "%s", input);
fprintf(stderr, "output len %d: %s", (int)strlen(output), output);
fail_unless(strlen(output) == 2047, "Truncation of infof input 3");
fail_unless(output[sizeof(output) - 1] == '\0',
@ -162,4 +161,5 @@ UNITTEST_START
#pragma GCC diagnostic pop
#endif
UNITTEST_STOP
UNITTEST_END(t1652_stop(easy))
}

View file

@ -27,23 +27,9 @@
#include "curl/urlapi.h"
#include "urlapi-int.h"
static CURLU *u;
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void unit_stop(void)
{
curl_global_cleanup();
}
#define free_and_clear(x) free(x); x = NULL
static CURLUcode parse_port(CURLU *url,
char *h, bool has_scheme)
static CURLUcode parse_port(CURLU *url, char *h, bool has_scheme)
{
struct dynbuf host;
CURLUcode ret;
@ -55,8 +41,12 @@ static CURLUcode parse_port(CURLU *url,
return ret;
}
UNITTEST_START
static CURLcode test_unit1653(char *arg)
{
UNITTEST_BEGIN_SIMPLE
CURLU *u;
CURLUcode ret;
char *ipv6port = NULL;
char *portnum;
@ -226,5 +216,5 @@ fail:
free(ipv6port);
curl_url_cleanup(u);
UNITTEST_END_SIMPLE
}
UNITTEST_STOP

View file

@ -26,19 +26,11 @@
#include "urldata.h"
#include "altsvc.h"
static CURLcode unit_setup(void)
static CURLcode test_unit1654(char *arg)
{
return CURLE_OK;
}
UNITTEST_BEGIN_SIMPLE
static void unit_stop(void)
{
curl_global_cleanup();
}
UNITTEST_START
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_ALTSVC)
{
char outname[256];
CURL *curl;
CURLcode result;
@ -132,6 +124,7 @@ UNITTEST_START
curl_easy_cleanup(curl);
fail:
Curl_altsvc_cleanup(&asi);
}
#endif
UNITTEST_STOP
UNITTEST_END(curl_global_cleanup())
}

View file

@ -25,166 +25,153 @@
#include "doh.h" /* from the lib dir */
static CURLcode unit_setup(void)
static CURLcode test_unit1655(char *arg)
{
/* whatever you want done first */
return CURLE_OK;
}
static void unit_stop(void)
{
/* done before shutting down and exiting */
}
UNITTEST_BEGIN_SIMPLE
#ifndef CURL_DISABLE_DOH
/*
* Prove detection of write overflow using a short buffer and a name
* of maximal valid length.
*
* Prove detection of other invalid input.
*/
do {
static const char max[] =
/* ..|....1.........2.........3.........4.........5.........6... */
/* 3456789012345678901234567890123456789012345678901234567890123 */
"this.is.a.maximum-length.hostname." /* 34: 34 */
"with-no-label-of-greater-length-than-the-sixty-three-characters."
/* 64: 98 */
"specified.in.the.RFCs." /* 22: 120 */
"and.with.a.QNAME.encoding.whose.length.is.exactly." /* 50: 170 */
"the.maximum.length.allowed." /* 27: 197 */
"that.is.two-hundred.and.fifty-six." /* 34: 231 */
"including.the.last.null." /* 24: 255 */
"";
static const char toolong[] =
/* ..|....1.........2.........3.........4.........5.........6... */
/* 3456789012345678901234567890123456789012345678901234567890123 */
"here.is.a.hostname.which.is.just.barely.too.long." /* 49: 49 */
"to.be.encoded.as.a.QNAME.of.the.maximum.allowed.length."
/* 55: 104 */
"which.is.256.including.a.final.zero-length.label." /* 49: 153 */
"representing.the.root.node.so.that.a.name.with." /* 47: 200 */
"a.trailing.dot.may.have.up.to." /* 30: 230 */
"255.characters.never.more." /* 26: 256 */
"";
static const char emptylabel[] =
"this.is.an.otherwise-valid.hostname."
".with.an.empty.label.";
static const char outsizelabel[] =
"this.is.an.otherwise-valid.hostname."
"with-a-label-of-greater-length-than-the-sixty-three-characters-"
"specified.in.the.RFCs.";
int i;
UNITTEST_START
struct test {
const char *name;
const DOHcode expected_result;
};
/*
* Prove detection of write overflow using a short buffer and a name
* of maximal valid length.
*
* Prove detection of other invalid input.
*/
do {
static const char max[] =
/* ..|....1.........2.........3.........4.........5.........6... */
/* 3456789012345678901234567890123456789012345678901234567890123 */
"this.is.a.maximum-length.hostname." /* 34: 34 */
"with-no-label-of-greater-length-than-the-sixty-three-characters."
/* 64: 98 */
"specified.in.the.RFCs." /* 22: 120 */
"and.with.a.QNAME.encoding.whose.length.is.exactly." /* 50: 170 */
"the.maximum.length.allowed." /* 27: 197 */
"that.is.two-hundred.and.fifty-six." /* 34: 231 */
"including.the.last.null." /* 24: 255 */
"";
static const char toolong[] =
/* ..|....1.........2.........3.........4.........5.........6... */
/* 3456789012345678901234567890123456789012345678901234567890123 */
"here.is.a.hostname.which.is.just.barely.too.long." /* 49: 49 */
"to.be.encoded.as.a.QNAME.of.the.maximum.allowed.length."
/* 55: 104 */
"which.is.256.including.a.final.zero-length.label." /* 49: 153 */
"representing.the.root.node.so.that.a.name.with." /* 47: 200 */
"a.trailing.dot.may.have.up.to." /* 30: 230 */
"255.characters.never.more." /* 26: 256 */
"";
static const char emptylabel[] =
"this.is.an.otherwise-valid.hostname."
".with.an.empty.label.";
static const char outsizelabel[] =
"this.is.an.otherwise-valid.hostname."
"with-a-label-of-greater-length-than-the-sixty-three-characters-"
"specified.in.the.RFCs.";
int i;
/* plays the role of struct dnsprobe in urldata.h */
struct demo {
unsigned char dohbuffer[255 + 16]; /* deliberately short buffer */
unsigned char canary1;
unsigned char canary2;
unsigned char canary3;
};
struct test {
const char *name;
const DOHcode expected_result;
};
const struct test playlist[4] = {
{ toolong, DOH_DNS_NAME_TOO_LONG }, /* expect early failure */
{ emptylabel, DOH_DNS_BAD_LABEL }, /* also */
{ outsizelabel, DOH_DNS_BAD_LABEL }, /* also */
{ max, DOH_OK } /* expect buffer overwrite */
};
/* plays the role of struct dnsprobe in urldata.h */
struct demo {
unsigned char dohbuffer[255 + 16]; /* deliberately short buffer */
unsigned char canary1;
unsigned char canary2;
unsigned char canary3;
};
for(i = 0; i < (int)(CURL_ARRAYSIZE(playlist)); i++) {
const char *name = playlist[i].name;
size_t olen = 100000;
struct demo victim;
DOHcode d;
const struct test playlist[4] = {
{ toolong, DOH_DNS_NAME_TOO_LONG }, /* expect early failure */
{ emptylabel, DOH_DNS_BAD_LABEL }, /* also */
{ outsizelabel, DOH_DNS_BAD_LABEL }, /* also */
{ max, DOH_OK } /* expect buffer overwrite */
};
victim.canary1 = 87; /* magic numbers, arbitrarily picked */
victim.canary2 = 35;
victim.canary3 = 41;
d = doh_req_encode(name, DNS_TYPE_A, victim.dohbuffer,
sizeof(struct demo), /* allow room for overflow */
&olen);
for(i = 0; i < (int)(CURL_ARRAYSIZE(playlist)); i++) {
const char *name = playlist[i].name;
size_t olen = 100000;
struct demo victim;
DOHcode d;
victim.canary1 = 87; /* magic numbers, arbitrarily picked */
victim.canary2 = 35;
victim.canary3 = 41;
d = doh_req_encode(name, DNS_TYPE_A, victim.dohbuffer,
sizeof(struct demo), /* allow room for overflow */
&olen);
fail_unless(d == playlist[i].expected_result,
"result returned was not as expected");
if(d == playlist[i].expected_result) {
if(name == max) {
fail_if(victim.canary1 == 87,
"demo one-byte buffer overwrite did not happen");
fail_unless(d == playlist[i].expected_result,
"result returned was not as expected");
if(d == playlist[i].expected_result) {
if(name == max) {
fail_if(victim.canary1 == 87,
"demo one-byte buffer overwrite did not happen");
}
else {
fail_unless(victim.canary1 == 87,
"one-byte buffer overwrite has happened");
}
fail_unless(victim.canary2 == 35,
"two-byte buffer overwrite has happened");
fail_unless(victim.canary3 == 41,
"three-byte buffer overwrite has happened");
}
else {
fail_unless(victim.canary1 == 87,
"one-byte buffer overwrite has happened");
}
fail_unless(victim.canary2 == 35,
"two-byte buffer overwrite has happened");
fail_unless(victim.canary3 == 41,
"three-byte buffer overwrite has happened");
}
else {
if(d == DOH_OK) {
fail_unless(olen <= sizeof(victim.dohbuffer), "wrote outside bounds");
fail_unless(olen > strlen(name), "unrealistic low size");
if(d == DOH_OK) {
fail_unless(olen <= sizeof(victim.dohbuffer),
"wrote outside bounds");
fail_unless(olen > strlen(name), "unrealistic low size");
}
}
}
}
} while(0);
} while(0);
/* run normal cases and try to trigger buffer length related errors */
do {
DNStype dnstype = DNS_TYPE_A;
unsigned char buffer[128];
const size_t buflen = sizeof(buffer);
const size_t magic1 = 9765;
size_t olen1 = magic1;
const char *sunshine1 = "a.com";
const char *dotshine1 = "a.com.";
const char *sunshine2 = "aa.com";
size_t olen2;
DOHcode ret2;
size_t olen;
/* run normal cases and try to trigger buffer length related errors */
do {
DNStype dnstype = DNS_TYPE_A;
unsigned char buffer[128];
const size_t buflen = sizeof(buffer);
const size_t magic1 = 9765;
size_t olen1 = magic1;
const char *sunshine1 = "a.com";
const char *dotshine1 = "a.com.";
const char *sunshine2 = "aa.com";
size_t olen2;
DOHcode ret2;
size_t olen;
DOHcode ret = doh_req_encode(sunshine1, dnstype, buffer, buflen, &olen1);
fail_unless(ret == DOH_OK, "sunshine case 1 should pass fine");
fail_if(olen1 == magic1, "olen has not been assigned properly");
fail_unless(olen1 > strlen(sunshine1), "bad out length");
DOHcode ret = doh_req_encode(sunshine1, dnstype, buffer, buflen, &olen1);
fail_unless(ret == DOH_OK, "sunshine case 1 should pass fine");
fail_if(olen1 == magic1, "olen has not been assigned properly");
fail_unless(olen1 > strlen(sunshine1), "bad out length");
/* with a trailing dot, the response should have the same length */
olen2 = magic1;
ret2 = doh_req_encode(dotshine1, dnstype, buffer, buflen, &olen2);
fail_unless(ret2 == DOH_OK, "dotshine case should pass fine");
fail_if(olen2 == magic1, "olen has not been assigned properly");
fail_unless(olen1 == olen2, "olen should not grow for a trailing dot");
/* with a trailing dot, the response should have the same length */
olen2 = magic1;
ret2 = doh_req_encode(dotshine1, dnstype, buffer, buflen, &olen2);
fail_unless(ret2 == DOH_OK, "dotshine case should pass fine");
fail_if(olen2 == magic1, "olen has not been assigned properly");
fail_unless(olen1 == olen2, "olen should not grow for a trailing dot");
/* add one letter, the response should be one longer */
olen2 = magic1;
ret2 = doh_req_encode(sunshine2, dnstype, buffer, buflen, &olen2);
fail_unless(ret2 == DOH_OK, "sunshine case 2 should pass fine");
fail_if(olen2 == magic1, "olen has not been assigned properly");
fail_unless(olen1 + 1 == olen2, "olen should grow with the hostname");
/* add one letter, the response should be one longer */
olen2 = magic1;
ret2 = doh_req_encode(sunshine2, dnstype, buffer, buflen, &olen2);
fail_unless(ret2 == DOH_OK, "sunshine case 2 should pass fine");
fail_if(olen2 == magic1, "olen has not been assigned properly");
fail_unless(olen1 + 1 == olen2, "olen should grow with the hostname");
/* pass a short buffer, should fail */
ret = doh_req_encode(sunshine1, dnstype, buffer, olen1 - 1, &olen);
fail_if(ret == DOH_OK, "short buffer should have been noticed");
/* pass a short buffer, should fail */
ret = doh_req_encode(sunshine1, dnstype, buffer, olen1 - 1, &olen);
fail_if(ret == DOH_OK, "short buffer should have been noticed");
/* pass a minimum buffer, should succeed */
ret = doh_req_encode(sunshine1, dnstype, buffer, olen1, &olen);
fail_unless(ret == DOH_OK, "minimal length buffer should be long enough");
fail_unless(olen == olen1, "bad buffer length");
} while(0);
UNITTEST_STOP
/* pass a minimum buffer, should succeed */
ret = doh_req_encode(sunshine1, dnstype, buffer, olen1, &olen);
fail_unless(ret == DOH_OK, "minimal length buffer should be long enough");
fail_unless(olen == olen1, "bad buffer length");
} while(0);
#else /* CURL_DISABLE_DOH */
#endif /* CURL_DISABLE_DOH */
UNITTEST_START
/* nothing to do, just succeed */
UNITTEST_STOP
#endif
UNITTEST_END_SIMPLE
}

View file

@ -25,16 +25,6 @@
#include "vtls/x509asn1.h"
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
#if defined(USE_GNUTLS) || defined(USE_SCHANNEL) || defined(USE_MBEDTLS)
struct test_spec {
@ -43,7 +33,34 @@ struct test_spec {
CURLcode exp_result;
};
static struct test_spec test_specs[] = {
static bool do_test(const struct test_spec *spec, size_t i,
struct dynbuf *dbuf)
{
CURLcode result;
const char *in = spec->input;
curlx_dyn_reset(dbuf);
result = Curl_x509_GTime2str(dbuf, in, in + strlen(in));
if(result != spec->exp_result) {
curl_mfprintf(stderr, "test %zu: expect result %d, got %d\n",
i, spec->exp_result, result);
return FALSE;
}
else if(!result && strcmp(spec->exp_output, curlx_dyn_ptr(dbuf))) {
curl_mfprintf(stderr,
"test %zu: input '%s', expected output '%s', got '%s'\n",
i, in, spec->exp_output, curlx_dyn_ptr(dbuf));
return FALSE;
}
return TRUE;
}
static CURLcode test_unit1656(char *arg)
{
UNITTEST_BEGIN_SIMPLE
static const struct test_spec test_specs[] = {
{ "190321134340", "1903-21-13 43:40:00", CURLE_OK },
{ "", NULL, CURLE_BAD_FUNCTION_ARGUMENT },
{ "WTF", NULL, CURLE_BAD_FUNCTION_ARGUMENT },
@ -70,32 +87,8 @@ static struct test_spec test_specs[] = {
{ "190321134340-3", "1903-21-13 43:40:00 UTC-3", CURLE_OK },
{ "19032113434017.0-04", "1903-21-13 43:40:17 UTC-04", CURLE_OK },
{ "19032113434017.01-01:10", "1903-21-13 43:40:17.01 UTC-01:10", CURLE_OK },
};
};
static bool do_test(struct test_spec *spec, size_t i, struct dynbuf *dbuf)
{
CURLcode result;
const char *in = spec->input;
curlx_dyn_reset(dbuf);
result = Curl_x509_GTime2str(dbuf, in, in + strlen(in));
if(result != spec->exp_result) {
curl_mfprintf(stderr, "test %zu: expect result %d, got %d\n",
i, spec->exp_result, result);
return FALSE;
}
else if(!result && strcmp(spec->exp_output, curlx_dyn_ptr(dbuf))) {
curl_mfprintf(stderr,
"test %zu: input '%s', expected output '%s', got '%s'\n",
i, in, spec->exp_output, curlx_dyn_ptr(dbuf));
return FALSE;
}
return TRUE;
}
UNITTEST_START
{
size_t i;
struct dynbuf dbuf;
bool all_ok = TRUE;
@ -115,15 +108,17 @@ UNITTEST_START
curlx_dyn_free(&dbuf);
curl_global_cleanup();
UNITTEST_END_SIMPLE
}
UNITTEST_STOP
#else
UNITTEST_START
static CURLcode test_unit1656(char *arg)
{
puts("not tested since Curl_x509_GTime2str() is not built-in");
UNITTEST_BEGIN_SIMPLE
puts("not tested since Curl_x509_GTime2str() is not built in");
UNITTEST_END_SIMPLE
}
UNITTEST_STOP
#endif

View file

@ -25,30 +25,21 @@
#include "vtls/x509asn1.h"
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
#if defined(USE_GNUTLS) || defined(USE_SCHANNEL) || defined(USE_MBEDTLS)
struct test1657_spec {
CURLcode (*setbuf)(struct test1657_spec *spec, struct dynbuf *buf);
CURLcode (*setbuf)(const struct test1657_spec *spec, struct dynbuf *buf);
size_t n;
CURLcode exp_result;
};
static CURLcode make1657_nested(struct test1657_spec *spec, struct dynbuf *buf)
static CURLcode make1657_nested(const struct test1657_spec *spec,
struct dynbuf *buf)
{
CURLcode r;
size_t i;
unsigned char open_undef[] = { 0x32, 0x80 };
unsigned char close_undef[] = { 0x00, 0x00 };
unsigned char open_undef[] = { 0x32, 0x80 };
unsigned char close_undef[] = { 0x00, 0x00 };
for(i = 0; i < spec->n; ++i) {
r = curlx_dyn_addn(buf, open_undef, sizeof(open_undef));
@ -63,14 +54,14 @@ static CURLcode make1657_nested(struct test1657_spec *spec, struct dynbuf *buf)
return CURLE_OK;
}
static struct test1657_spec test1657_specs[] = {
static const struct test1657_spec test1657_specs[] = {
{ make1657_nested, 3, CURLE_OK },
{ make1657_nested, 16, CURLE_OK },
{ make1657_nested, 17, CURLE_BAD_FUNCTION_ARGUMENT },
{ make1657_nested, 1024, CURLE_BAD_FUNCTION_ARGUMENT },
};
static bool do_test1657(struct test1657_spec *spec, size_t i,
static bool do_test1657(const struct test1657_spec *spec, size_t i,
struct dynbuf *buf)
{
CURLcode result;
@ -94,8 +85,10 @@ static bool do_test1657(struct test1657_spec *spec, size_t i,
return TRUE;
}
UNITTEST_START
static CURLcode test_unit1657(char *arg)
{
UNITTEST_BEGIN_SIMPLE
size_t i;
bool all_ok = TRUE;
struct dynbuf dbuf;
@ -115,15 +108,17 @@ UNITTEST_START
curlx_dyn_free(&dbuf);
curl_global_cleanup();
UNITTEST_END_SIMPLE
}
UNITTEST_STOP
#else
UNITTEST_START
static CURLcode test_unit1657(char *arg)
{
puts("not tested since Curl_x509_getASN1Element() is not built-in");
UNITTEST_BEGIN_SIMPLE
puts("not tested since Curl_x509_getASN1Element() is not built in");
UNITTEST_END_SIMPLE
}
UNITTEST_STOP
#endif

View file

@ -25,35 +25,22 @@
#include "doh.h" /* from the lib dir */
static CURLcode unit_setup(void)
/* DoH + HTTPSRR are required */
#if !defined(CURL_DISABLE_DOH) && defined(USE_HTTPSRR)
static CURLcode t1658_setup(void)
{
/* whatever you want done first */
curl_global_init(CURL_GLOBAL_ALL);
return CURLE_OK;
}
static void unit_stop(void)
{
curl_global_cleanup();
/* done before shutting down and exiting */
}
/* DoH + HTTPSRR are required */
#if !defined(CURL_DISABLE_DOH) && defined(USE_HTTPSRR)
extern CURLcode doh_resp_decode_httpsrr(struct Curl_easy *data,
const unsigned char *cp, size_t len,
struct Curl_https_rrinfo **hrr);
extern void doh_print_httpsrr(struct Curl_easy *data,
struct Curl_https_rrinfo *hrr);
struct test {
const char *name;
const unsigned char *dns;
size_t len; /* size of the dns packet */
const char *expect;
};
/*
* The idea here is that we pass one DNS packet at the time to the decoder. we
* then generate a string output with the results and compare if it matches
@ -127,12 +114,21 @@ static void rrresults(struct Curl_https_rrinfo *rr, CURLcode result)
}
}
UNITTEST_START
static CURLcode test_unit1658(char *arg)
{
UNITTEST_BEGIN(t1658_setup())
/* The "SvcParamKeys" specified within the HTTPS RR packet *must* be
provided in numerical order. */
static struct test t[] = {
struct test {
const char *name;
const unsigned char *dns;
size_t len; /* size of the dns packet */
const char *expect;
};
static const struct test t[] = {
{
"single h2 alpn",
(const unsigned char *)"\x00\x00" /* 16-bit prio */
@ -541,13 +537,16 @@ UNITTEST_START
}
curl_easy_cleanup(easy);
}
UNITTEST_END(curl_global_cleanup())
}
UNITTEST_STOP
#else /* CURL_DISABLE_DOH or not HTTPSRR enabled */
UNITTEST_START
/* nothing to do, just succeed */
UNITTEST_STOP
static CURLcode test_unit1658(char *arg)
{
UNITTEST_BEGIN_SIMPLE
UNITTEST_END_SIMPLE
}
#endif

View file

@ -26,32 +26,38 @@
#include "urldata.h"
#include "hsts.h"
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void unit_stop(void)
{
curl_global_cleanup();
}
#if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_HSTS)
UNITTEST_START
static CURLcode test_unit1660(char *arg)
{
UNITTEST_BEGIN_SIMPLE
puts("nothing to do when HTTP or HSTS are disabled");
UNITTEST_END_SIMPLE
}
UNITTEST_STOP
#else
struct testit {
const char *host;
const char *chost; /* if non-NULL, use to lookup with */
const char *hdr; /* if NULL, just do the lookup */
const CURLcode result; /* parse result */
};
static void showsts(struct stsentry *e, const char *chost)
{
if(!e)
printf("'%s' is not HSTS\n", chost);
else {
curl_mprintf("%s [%s]: %" CURL_FORMAT_CURL_OFF_T "%s\n",
chost, e->host, e->expires,
e->includeSubDomains ? " includeSubDomains" : "");
}
}
static const struct testit headers[] = {
static CURLcode test_unit1660(char *arg)
{
UNITTEST_BEGIN_SIMPLE
struct testit {
const char *host;
const char *chost; /* if non-NULL, use to lookup with */
const char *hdr; /* if NULL, just do the lookup */
const CURLcode result; /* parse result */
};
static const struct testit headers[] = {
/* two entries read from disk cache, verify first */
{ "-", "readfrom.example", NULL, CURLE_OK},
{ "-", "old.example", NULL, CURLE_OK},
@ -102,21 +108,8 @@ static const struct testit headers[] = {
/* make this live for 7 seconds */
{ "expire.example", NULL, "max-age=\"7\"\r\n", CURLE_OK },
{ NULL, NULL, NULL, CURLE_OK }
};
};
static void showsts(struct stsentry *e, const char *chost)
{
if(!e)
printf("'%s' is not HSTS\n", chost);
else {
curl_mprintf("%s [%s]: %" CURL_FORMAT_CURL_OFF_T "%s\n",
chost, e->host, e->expires,
e->includeSubDomains ? " includeSubDomains" : "");
}
}
UNITTEST_START
{
CURLcode result;
struct stsentry *e;
struct hsts *h = Curl_hsts_init();
@ -173,6 +166,7 @@ UNITTEST_START
Curl_hsts_cleanup(&h);
curl_easy_cleanup(easy);
curl_global_cleanup();
UNITTEST_END(curl_global_cleanup())
}
UNITTEST_STOP
#endif

View file

@ -25,8 +25,6 @@
#include "bufref.h"
#include "memdebug.h"
static struct bufref bufref;
static int freecount = 0;
static void test_free(void *p)
@ -36,19 +34,23 @@ static void test_free(void *p)
free(p);
}
static CURLcode unit_setup(void)
static CURLcode t1661_setup(struct bufref *bufref)
{
Curl_bufref_init(&bufref);
Curl_bufref_init(bufref);
return CURLE_OK;
}
static void unit_stop(void)
static void t1661_stop(struct bufref *bufref)
{
Curl_bufref_free(&bufref);
Curl_bufref_free(bufref);
}
UNITTEST_START
static CURLcode test_unit1661(char *arg)
{
struct bufref bufref;
UNITTEST_BEGIN(t1661_setup(&bufref))
const char *buffer = NULL;
CURLcode result = CURLE_OK;
@ -59,7 +61,6 @@ UNITTEST_START
* 2: reference will be NULL
* 3: destructor will be NULL
*/
fail_unless(!bufref.ptr, "Initial reference must be NULL");
fail_unless(!bufref.len, "Initial length must be NULL");
fail_unless(!bufref.dtor, "Destructor must be NULL");
@ -67,7 +68,6 @@ UNITTEST_START
/**
* testing Curl_bufref_set
*/
buffer = malloc(13);
abort_unless(buffer, "Out of memory");
Curl_bufref_set(&bufref, buffer, 13, test_free);
@ -79,20 +79,17 @@ UNITTEST_START
/**
* testing Curl_bufref_ptr
*/
fail_unless((const char *) Curl_bufref_ptr(&bufref) == buffer,
"Wrong pointer value returned");
/**
* testing Curl_bufref_len
*/
fail_unless(Curl_bufref_len(&bufref) == 13, "Wrong data size returned");
/**
* testing Curl_bufref_memdup
*/
result = Curl_bufref_memdup(&bufref, "1661", 3);
abort_unless(result == CURLE_OK, curl_easy_strerror(result));
fail_unless(freecount == 1, "Destructor not called");
@ -108,11 +105,11 @@ UNITTEST_START
/**
* testing Curl_bufref_free
*/
Curl_bufref_free(&bufref);
fail_unless(freecount == 1, "Wrong destructor called");
fail_unless(!bufref.ptr, "Initial reference must be NULL");
fail_unless(!bufref.len, "Initial length must be NULL");
fail_unless(!bufref.dtor, "Destructor must be NULL");
UNITTEST_END(t1661_stop(&bufref))
}
UNITTEST_STOP

View file

@ -30,24 +30,17 @@
#include <netinet/in6.h>
#endif
#include <curl/curl.h>
#include "cf-socket.h"
#include "memdebug.h" /* LAST include file */
static CURLcode unit_setup(void)
static CURLcode t1663_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
return res;
}
static void unit_stop(void)
{
curl_global_cleanup();
}
static void t1663_parse(
const char *input_data,
const char *exp_dev,
@ -79,8 +72,10 @@ static void t1663_parse(
free(host);
}
UNITTEST_START
static CURLcode test_unit1663(char *arg)
{
UNITTEST_BEGIN(t1663_setup())
t1663_parse("dev", "dev", NULL, NULL, CURLE_OK);
t1663_parse("if!eth0", NULL, "eth0", NULL, CURLE_OK);
t1663_parse("host!myname", NULL, NULL, "myname", CURLE_OK);
@ -93,5 +88,6 @@ UNITTEST_START
t1663_parse("ifhost!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
t1663_parse("ifhost!eth0", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
t1663_parse("ifhost!eth0!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
UNITTEST_END(curl_global_cleanup())
}
UNITTEST_STOP

View file

@ -30,26 +30,21 @@
#include <netinet/in6.h>
#endif
#include <curl/curl.h>
#include "curlx/strparse.h"
#include "memdebug.h" /* LAST include file */
static CURLcode unit_setup(void)
static CURLcode t1664_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
return res;
}
static void unit_stop(void)
static CURLcode test_unit1664(char *arg)
{
curl_global_cleanup();
}
UNITTEST_BEGIN(t1664_setup())
UNITTEST_START
{
static const char *wordparse[] = {
"word",
"word ",
@ -487,5 +482,5 @@ UNITTEST_START
}
}
UNITTEST_END(curl_global_cleanup())
}
UNITTEST_STOP

View file

@ -26,17 +26,10 @@
#include "http_aws_sigv4.h"
#include "dynbuf.h"
static CURLcode unit_setup(void)
static CURLcode test_unit1979(char *arg)
{
return CURLE_OK;
}
UNITTEST_BEGIN_SIMPLE
static void unit_stop(void)
{
}
UNITTEST_START
{
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS)
struct testcase {
const char *testname;
@ -140,5 +133,6 @@ UNITTEST_START
curlx_dyn_free(&canonical_path);
}
#endif /* !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS) */
UNITTEST_END_SIMPLE
}
UNITTEST_STOP

View file

@ -26,17 +26,10 @@
#include "http_aws_sigv4.h"
#include "dynbuf.h"
static CURLcode unit_setup(void)
static CURLcode test_unit1980(char *arg)
{
return CURLE_OK;
}
UNITTEST_BEGIN_SIMPLE
static void unit_stop(void)
{
}
UNITTEST_START
{
#if !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS)
struct testcase {
const char *testname;
@ -111,5 +104,6 @@ UNITTEST_START
curlx_dyn_free(&canonical_query);
}
#endif /* !defined(CURL_DISABLE_HTTP) && !defined(CURL_DISABLE_AWS) */
UNITTEST_END_SIMPLE
}
UNITTEST_STOP

View file

@ -48,26 +48,24 @@
#include "curl_trc.h"
#include "memdebug.h"
static CURL *t2600_easy;
static CURLcode unit_setup(void)
static CURLcode t2600_setup(CURL **easy)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
t2600_easy = curl_easy_init();
if(!t2600_easy) {
*easy = curl_easy_init();
if(!*easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
curl_global_trace("all");
curl_easy_setopt(t2600_easy, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(*easy, CURLOPT_VERBOSE, 1L);
return res;
}
static void unit_stop(void)
static void t2600_stop(CURL *easy)
{
curl_easy_cleanup(t2600_easy);
curl_easy_cleanup(easy);
curl_global_cleanup();
}
@ -104,7 +102,7 @@ struct test_result {
struct ai_family_stats cf6;
};
static struct test_case *current_tc;
static const struct test_case *current_tc;
static struct test_result *current_tr;
struct cf_test_ctx {
@ -161,31 +159,31 @@ static void cf_test_adjust_pollset(struct Curl_cfilter *cf,
Curl_pollset_set(data, ps, 1, TRUE, TRUE);
}
static struct Curl_cftype cft_test = {
"TEST",
CF_TYPE_IP_CONNECT,
CURL_LOG_LVL_NONE,
cf_test_destroy,
cf_test_connect,
Curl_cf_def_close,
Curl_cf_def_shutdown,
Curl_cf_def_get_host,
cf_test_adjust_pollset,
Curl_cf_def_data_pending,
Curl_cf_def_send,
Curl_cf_def_recv,
Curl_cf_def_cntrl,
Curl_cf_def_conn_is_alive,
Curl_cf_def_conn_keep_alive,
Curl_cf_def_query,
};
static CURLcode cf_test_create(struct Curl_cfilter **pcf,
struct Curl_easy *data,
struct connectdata *conn,
const struct Curl_addrinfo *ai,
int transport)
{
static const struct Curl_cftype cft_test = {
"TEST",
CF_TYPE_IP_CONNECT,
CURL_LOG_LVL_NONE,
cf_test_destroy,
cf_test_connect,
Curl_cf_def_close,
Curl_cf_def_shutdown,
Curl_cf_def_get_host,
cf_test_adjust_pollset,
Curl_cf_def_data_pending,
Curl_cf_def_send,
Curl_cf_def_recv,
Curl_cf_def_cntrl,
Curl_cf_def_conn_is_alive,
Curl_cf_def_conn_keep_alive,
Curl_cf_def_query,
};
struct cf_test_ctx *ctx = NULL;
struct Curl_cfilter *cf = NULL;
timediff_t created_at;
@ -238,7 +236,7 @@ out:
return result;
}
static void check_result(struct test_case *tc,
static void check_result(const struct test_case *tc,
struct test_result *tr)
{
char msg[256];
@ -301,7 +299,7 @@ static void check_result(struct test_case *tc,
}
}
static void test_connect(struct test_case *tc)
static void test_connect(CURL *easy, const struct test_case *tc)
{
struct test_result tr;
struct curl_slist *list = NULL;
@ -312,23 +310,23 @@ static void test_connect(struct test_case *tc)
list = curl_slist_append(NULL, tc->resolve_info);
fail_unless(list, "error allocating resolve list entry");
curl_easy_setopt(t2600_easy, CURLOPT_RESOLVE, list);
curl_easy_setopt(t2600_easy, CURLOPT_IPRESOLVE, (long)tc->ip_version);
curl_easy_setopt(t2600_easy, CURLOPT_CONNECTTIMEOUT_MS,
curl_easy_setopt(easy, CURLOPT_RESOLVE, list);
curl_easy_setopt(easy, CURLOPT_IPRESOLVE, (long)tc->ip_version);
curl_easy_setopt(easy, CURLOPT_CONNECTTIMEOUT_MS,
(long)tc->connect_timeout_ms);
curl_easy_setopt(t2600_easy, CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS,
curl_easy_setopt(easy, CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS,
(long)tc->he_timeout_ms);
curl_easy_setopt(t2600_easy, CURLOPT_URL, tc->url);
curl_easy_setopt(easy, CURLOPT_URL, tc->url);
memset(&tr, 0, sizeof(tr));
tr.cf6.family = "v6";
tr.cf4.family = "v4";
tr.started = curlx_now();
tr.result = curl_easy_perform(t2600_easy);
tr.result = curl_easy_perform(easy);
tr.ended = curlx_now();
curl_easy_setopt(t2600_easy, CURLOPT_RESOLVE, NULL);
curl_easy_setopt(easy, CURLOPT_RESOLVE, NULL);
curl_slist_free_all(list);
list = NULL;
current_tc = NULL;
@ -355,46 +353,51 @@ static void test_connect(struct test_case *tc)
#define TC_TMOT 90000 /* 90 sec max test duration */
#define CNCT_TMOT 60000 /* 60sec connect timeout */
static struct test_case TEST_CASES[] = {
/* TIMEOUT_MS, FAIL_MS CREATED DURATION Result, HE_PREF */
/* CNCT HE v4 v6 v4 v6 MIN MAX */
{ 1, TURL, "test.com:123:192.0.2.1", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 200, 200, 1, 0, 200, TC_TMOT, R_FAIL, NULL },
/* 1 ipv4, fails after ~200ms, reports COULDNT_CONNECT */
{ 2, TURL, "test.com:123:192.0.2.1,192.0.2.2", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 200, 200, 2, 0, 400, TC_TMOT, R_FAIL, NULL },
/* 2 ipv4, fails after ~400ms, reports COULDNT_CONNECT */
static CURLcode test_unit2600(char *arg)
{
CURL *easy;
UNITTEST_BEGIN(t2600_setup(&easy))
static const struct test_case TEST_CASES[] = {
/* TIMEOUT_MS, FAIL_MS CREATED DURATION Result, HE_PREF */
/* CNCT HE v4 v6 v4 v6 MIN MAX */
{ 1, TURL, "test.com:123:192.0.2.1", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 200, 200, 1, 0, 200, TC_TMOT, R_FAIL, NULL },
/* 1 ipv4, fails after ~200ms, reports COULDNT_CONNECT */
{ 2, TURL, "test.com:123:192.0.2.1,192.0.2.2", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 200, 200, 2, 0, 400, TC_TMOT, R_FAIL, NULL },
/* 2 ipv4, fails after ~400ms, reports COULDNT_CONNECT */
#ifdef USE_IPV6
{ 3, TURL, "test.com:123:::1", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 200, 200, 0, 1, 200, TC_TMOT, R_FAIL, NULL },
/* 1 ipv6, fails after ~200ms, reports COULDNT_CONNECT */
{ 4, TURL, "test.com:123:::1,::2", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 200, 200, 0, 2, 400, TC_TMOT, R_FAIL, NULL },
/* 2 ipv6, fails after ~400ms, reports COULDNT_CONNECT */
{ 3, TURL, "test.com:123:::1", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 200, 200, 0, 1, 200, TC_TMOT, R_FAIL, NULL },
/* 1 ipv6, fails after ~200ms, reports COULDNT_CONNECT */
{ 4, TURL, "test.com:123:::1,::2", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 200, 200, 0, 2, 400, TC_TMOT, R_FAIL, NULL },
/* 2 ipv6, fails after ~400ms, reports COULDNT_CONNECT */
{ 5, TURL, "test.com:123:192.0.2.1,::1", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 200, 200, 1, 1, 350, TC_TMOT, R_FAIL, "v6" },
/* mixed ip4+6, v6 always first, v4 kicks in on HE, fails after ~350ms */
{ 6, TURL, "test.com:123:::1,192.0.2.1", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 200, 200, 1, 1, 350, TC_TMOT, R_FAIL, "v6" },
/* mixed ip6+4, v6 starts, v4 never starts due to high HE, TIMEOUT */
{ 7, TURL, "test.com:123:192.0.2.1,::1", CURL_IPRESOLVE_V4,
CNCT_TMOT, 150, 500, 500, 1, 0, 400, TC_TMOT, R_FAIL, NULL },
/* mixed ip4+6, but only use v4, check it uses full connect timeout,
although another address of the 'wrong' family is available */
{ 8, TURL, "test.com:123:::1,192.0.2.1", CURL_IPRESOLVE_V6,
CNCT_TMOT, 150, 500, 500, 0, 1, 400, TC_TMOT, R_FAIL, NULL },
/* mixed ip4+6, but only use v6, check it uses full connect timeout,
although another address of the 'wrong' family is available */
{ 5, TURL, "test.com:123:192.0.2.1,::1", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 200, 200, 1, 1, 350, TC_TMOT, R_FAIL, "v6" },
/* mixed ip4+6, v6 always first, v4 kicks in on HE, fails after ~350ms */
{ 6, TURL, "test.com:123:::1,192.0.2.1", CURL_IPRESOLVE_WHATEVER,
CNCT_TMOT, 150, 200, 200, 1, 1, 350, TC_TMOT, R_FAIL, "v6" },
/* mixed ip6+4, v6 starts, v4 never starts due to high HE, TIMEOUT */
{ 7, TURL, "test.com:123:192.0.2.1,::1", CURL_IPRESOLVE_V4,
CNCT_TMOT, 150, 500, 500, 1, 0, 400, TC_TMOT, R_FAIL, NULL },
/* mixed ip4+6, but only use v4, check it uses full connect timeout,
although another address of the 'wrong' family is available */
{ 8, TURL, "test.com:123:::1,192.0.2.1", CURL_IPRESOLVE_V6,
CNCT_TMOT, 150, 500, 500, 0, 1, 400, TC_TMOT, R_FAIL, NULL },
/* mixed ip4+6, but only use v6, check it uses full connect timeout,
although another address of the 'wrong' family is available */
#endif
};
UNITTEST_START
};
size_t i;
for(i = 0; i < CURL_ARRAYSIZE(TEST_CASES); ++i) {
test_connect(&TEST_CASES[i]);
test_connect(easy, &TEST_CASES[i]);
}
UNITTEST_STOP
UNITTEST_END(t2600_stop(easy))
}

View file

@ -27,16 +27,6 @@
#include "bufq.h"
#include "curl_trc.h"
static CURLcode unit_setup(void)
{
CURLcode res = CURLE_OK;
return res;
}
static void unit_stop(void)
{
}
static const char *tail_err(struct bufq *q)
{
struct buf_chunk *chunk;
@ -86,12 +76,12 @@ static void dump_bufq(struct bufq *q, const char *msg)
curl_mfprintf(stderr, "- spares: %zu\n", n);
}
static unsigned char test_data[32*1024];
static void check_bufq(size_t pool_spares,
size_t chunk_size, size_t max_chunks,
size_t wsize, size_t rsize, int opts)
{
static unsigned char test_data[32*1024];
struct bufq q;
struct bufc_pool pool;
size_t max_len = chunk_size * max_chunks;
@ -250,7 +240,10 @@ static void check_bufq(size_t pool_spares,
Curl_bufcp_free(&pool);
}
UNITTEST_START
static CURLcode test_unit2601(char *arg)
{
UNITTEST_BEGIN_SIMPLE
struct bufq q;
ssize_t n;
CURLcode result;
@ -278,4 +271,5 @@ UNITTEST_START
check_bufq(8, 8000, 10, 1234, 1234, BUFQ_OPT_NONE);
check_bufq(8, 1024, 4, 129, 127, BUFQ_OPT_NO_SPARES);
UNITTEST_STOP
UNITTEST_END_SIMPLE
}

View file

@ -28,17 +28,9 @@
#include "dynhds.h"
#include "curl_trc.h"
static CURLcode unit_setup(void)
static CURLcode test_unit2602(char *arg)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
UNITTEST_START
UNITTEST_BEGIN_SIMPLE
struct dynhds hds;
struct dynbuf dbuf;
@ -145,4 +137,5 @@ UNITTEST_START
Curl_dynhds_free(&hds);
UNITTEST_STOP
UNITTEST_END_SIMPLE
}

View file

@ -28,27 +28,7 @@
#include "http1.h"
#include "curl_trc.h"
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
#ifndef CURL_DISABLE_HTTP
struct tcase {
const char **input;
const char *default_scheme;
const char *method;
const char *scheme;
const char *authority;
const char *path;
size_t header_count;
size_t input_remain;
};
static void check_eq(const char *s, const char *exp_s, const char *name)
{
if(s && exp_s) {
@ -68,7 +48,18 @@ static void check_eq(const char *s, const char *exp_s, const char *name)
}
}
static void parse_success(struct tcase *t)
struct tcase {
const char **input;
const char *default_scheme;
const char *method;
const char *scheme;
const char *authority;
const char *path;
size_t header_count;
size_t input_remain;
};
static void parse_success(const struct tcase *t)
{
struct h1_req_parser p;
const char *buf;
@ -119,70 +110,72 @@ static void parse_success(struct tcase *t)
Curl_h1_req_parse_free(&p);
}
static const char *T1_INPUT[] = {
"GET /path HTTP/1.1\r\nHost: test.curl.se\r\n\r\n",
NULL,
};
static struct tcase TEST1a = {
T1_INPUT, NULL, "GET", NULL, NULL, "/path", 1, 0
};
static struct tcase TEST1b = {
T1_INPUT, "https", "GET", "https", NULL, "/path", 1, 0
};
static const char *T2_INPUT[] = {
"GET /path HTT",
"P/1.1\r\nHost: te",
"st.curl.se\r\n\r",
"\n12345678",
NULL,
};
static struct tcase TEST2 = {
T2_INPUT, NULL, "GET", NULL, NULL, "/path", 1, 8
};
static const char *T3_INPUT[] = {
"GET ftp://ftp.curl.se/xxx?a=2 HTTP/1.1\r\nContent-Length: 0\r",
"\nUser-Agent: xxx\r\n\r\n",
NULL,
};
static struct tcase TEST3a = {
T3_INPUT, NULL, "GET", "ftp", "ftp.curl.se", "/xxx?a=2", 2, 0
};
static const char *T4_INPUT[] = {
"CONNECT ftp.curl.se:123 HTTP/1.1\r\nContent-Length: 0\r\n",
"User-Agent: xxx\r\n",
"nothing: \r\n\r\n\n\n",
NULL,
};
static struct tcase TEST4a = {
T4_INPUT, NULL, "CONNECT", NULL, "ftp.curl.se:123", NULL, 3, 2
};
static const char *T5_INPUT[] = {
"OPTIONS * HTTP/1.1\r\nContent-Length: 0\r\nBlabla: xxx.yyy\r",
"\n\tzzzzzz\r\n\r\n",
"123",
NULL,
};
static struct tcase TEST5a = {
T5_INPUT, NULL, "OPTIONS", NULL, NULL, "*", 2, 3
};
static const char *T6_INPUT[] = {
"PUT /path HTTP/1.1\nHost: test.curl.se\n\n123",
NULL,
};
static struct tcase TEST6a = {
T6_INPUT, NULL, "PUT", NULL, NULL, "/path", 1, 3
};
#endif
UNITTEST_START
static CURLcode test_unit2603(char *arg)
{
UNITTEST_BEGIN_SIMPLE
#ifndef CURL_DISABLE_HTTP
static const char *T1_INPUT[] = {
"GET /path HTTP/1.1\r\nHost: test.curl.se\r\n\r\n",
NULL,
};
static const struct tcase TEST1a = {
T1_INPUT, NULL, "GET", NULL, NULL, "/path", 1, 0
};
static const struct tcase TEST1b = {
T1_INPUT, "https", "GET", "https", NULL, "/path", 1, 0
};
static const char *T2_INPUT[] = {
"GET /path HTT",
"P/1.1\r\nHost: te",
"st.curl.se\r\n\r",
"\n12345678",
NULL,
};
static const struct tcase TEST2 = {
T2_INPUT, NULL, "GET", NULL, NULL, "/path", 1, 8
};
static const char *T3_INPUT[] = {
"GET ftp://ftp.curl.se/xxx?a=2 HTTP/1.1\r\nContent-Length: 0\r",
"\nUser-Agent: xxx\r\n\r\n",
NULL,
};
static const struct tcase TEST3a = {
T3_INPUT, NULL, "GET", "ftp", "ftp.curl.se", "/xxx?a=2", 2, 0
};
static const char *T4_INPUT[] = {
"CONNECT ftp.curl.se:123 HTTP/1.1\r\nContent-Length: 0\r\n",
"User-Agent: xxx\r\n",
"nothing: \r\n\r\n\n\n",
NULL,
};
static const struct tcase TEST4a = {
T4_INPUT, NULL, "CONNECT", NULL, "ftp.curl.se:123", NULL, 3, 2
};
static const char *T5_INPUT[] = {
"OPTIONS * HTTP/1.1\r\nContent-Length: 0\r\nBlabla: xxx.yyy\r",
"\n\tzzzzzz\r\n\r\n",
"123",
NULL,
};
static const struct tcase TEST5a = {
T5_INPUT, NULL, "OPTIONS", NULL, NULL, "*", 2, 3
};
static const char *T6_INPUT[] = {
"PUT /path HTTP/1.1\nHost: test.curl.se\n\n123",
NULL,
};
static const struct tcase TEST6a = {
T6_INPUT, NULL, "PUT", NULL, NULL, "/path", 1, 3
};
parse_success(&TEST1a);
parse_success(&TEST1b);
parse_success(&TEST2);
@ -192,4 +185,5 @@ UNITTEST_START
parse_success(&TEST6a);
#endif
UNITTEST_STOP
UNITTEST_END_SIMPLE
}

View file

@ -25,27 +25,20 @@
#include "vssh/curl_path.h"
#include "memdebug.h"
static CURLcode unit_setup(void)
static CURLcode test_unit2604(char *arg)
{
return CURLE_OK;
}
UNITTEST_BEGIN_SIMPLE
static void unit_stop(void)
{
}
struct set {
const char *cp;
const char *expect; /* the returned content */
const char *next; /* what cp points to after the call */
const char *home;
CURLcode result;
};
UNITTEST_START
#ifdef USE_SSH
{
struct set {
const char *cp;
const char *expect; /* the returned content */
const char *next; /* what cp points to after the call */
const char *home;
CURLcode result;
};
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverlength-strings"
@ -79,7 +72,7 @@ UNITTEST_START
};
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic warning "-Woverlength-strings"
#pragma GCC diagnostic pop
#endif
list[0].cp = calloc(1, too_long + 1);
@ -113,11 +106,8 @@ UNITTEST_START
}
free(CURL_UNCONST(list[0].cp));
#endif
UNITTEST_END_SIMPLE
}
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
#endif
UNITTEST_STOP

View file

@ -25,67 +25,59 @@
#include "curl_get_line.h"
#include "memdebug.h"
static CURLcode test_unit3200(char *arg)
{
UNITTEST_BEGIN_SIMPLE
#if !defined(CURL_DISABLE_COOKIES) || !defined(CURL_DISABLE_ALTSVC) || \
!defined(CURL_DISABLE_HSTS) || !defined(CURL_DISABLE_NETRC)
/* The test XML does not supply a way to write files without newlines
* so we write our own
*/
#define C64 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
#define C256 C64 C64 C64 C64
#define C1024 C256 C256 C256 C256
#define C4096 C1024 C1024 C1024 C1024
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Woverlength-strings"
#endif
#define NUMTESTS 6
static const char *filecontents[] = {
/* Both should be read */
"LINE1\n"
"LINE2 NEWLINE\n",
/* The test XML does not supply a way to write files without newlines
* so we write our own
*/
/* Both should be read */
"LINE1\n"
"LINE2 NONEWLINE",
#define C64 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
#define C256 C64 C64 C64 C64
#define C1024 C256 C256 C256 C256
#define C4096 C1024 C1024 C1024 C1024
/* Only first should be read */
"LINE1\n"
C4096,
static const char *filecontents[] = {
/* Both should be read */
"LINE1\n"
"LINE2 NEWLINE\n",
/* First line should be read */
"LINE1\n"
C4096 "SOME EXTRA TEXT",
/* Both should be read */
"LINE1\n"
"LINE2 NONEWLINE",
/* Only first should be read */
"LINE1\n"
C4096 "SOME EXTRA TEXT\n"
"LINE3\n",
/* Only first should be read */
"LINE1\n"
C4096,
"LINE1\x1aTEST"
};
/* First line should be read */
"LINE1\n"
C4096 "SOME EXTRA TEXT",
/* Only first should be read */
"LINE1\n"
C4096 "SOME EXTRA TEXT\n"
"LINE3\n",
"LINE1\x1aTEST"
};
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic warning "-Woverlength-strings"
#pragma GCC diagnostic pop
#endif
UNITTEST_START
size_t i;
int rc = 0;
for(i = 0; i < NUMTESTS; i++) {
for(i = 0; i < CURL_ARRAYSIZE(filecontents); i++) {
FILE *fp;
struct dynbuf buf;
size_t len = 4096;
@ -170,21 +162,8 @@ UNITTEST_START
curl_mfprintf(stderr, "OK\n");
}
return (CURLcode)rc;
UNITTEST_STOP
#if defined(CURL_GNUC_DIAG) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
#else
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
UNITTEST_START
UNITTEST_STOP
#endif
UNITTEST_END_SIMPLE
}

File diff suppressed because it is too large Load diff

View file

@ -27,28 +27,8 @@
#include "uint-bset.h"
#include "curl_trc.h"
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static unsigned int s1[] = { /* spread numbers, some at slot edges */
0, 1, 4, 17, 63, 64, 65, 66,
90, 99,
};
static unsigned int s2[] = { /* set with all bits in slot1 set */
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127,
};
static void check_set(const char *name, unsigned int capacity,
unsigned int *s, size_t slen)
const unsigned int *s, size_t slen)
{
struct uint_bset bset;
size_t i, j;
@ -140,14 +120,27 @@ static void check_set(const char *name, unsigned int capacity,
Curl_uint_bset_destroy(&bset);
}
static void unit_stop(void)
static CURLcode test_unit3211(char *arg)
{
}
UNITTEST_BEGIN_SIMPLE
UNITTEST_START
static const unsigned int s1[] = { /* spread numbers, some at slot edges */
0, 1, 4, 17, 63, 64, 65, 66,
90, 99,
};
static const unsigned int s2[] = { /* set with all bits in slot1 set */
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127,
};
check_set("s1", 100, s1, CURL_ARRAYSIZE(s1));
check_set("s2", 1000, s2, CURL_ARRAYSIZE(s2));
UNITTEST_STOP
UNITTEST_END_SIMPLE
}

View file

@ -29,23 +29,24 @@
#define TBL_SIZE 100
static struct uint_tbl tbl;
static int dummy;
static CURLcode unit_setup(void)
static CURLcode t3212_setup(struct uint_tbl *tbl)
{
Curl_uint_tbl_init(&tbl, NULL);
return Curl_uint_tbl_resize(&tbl, TBL_SIZE);
Curl_uint_tbl_init(tbl, NULL);
return Curl_uint_tbl_resize(tbl, TBL_SIZE);
}
static void unit_stop(void)
static void t3212_stop(struct uint_tbl *tbl)
{
Curl_uint_tbl_destroy(&tbl);
Curl_uint_tbl_destroy(tbl);
}
static void check3212(void)
static CURLcode test_unit3212(char *arg)
{
struct uint_tbl tbl;
int dummy;
UNITTEST_BEGIN(t3212_setup(&tbl))
unsigned int i, key, n;
void *entry;
@ -127,10 +128,6 @@ static void check3212(void)
Curl_uint_tbl_remove(&tbl, 17);
fail_unless(Curl_uint_tbl_add(&tbl, &dummy, &key), "failed to add again");
fail_unless(key == 17, "unexpected key assigned");
UNITTEST_END(t3212_stop(&tbl))
}
UNITTEST_START
check3212();
UNITTEST_STOP

View file

@ -27,31 +27,7 @@
#include "uint-spbset.h"
#include "curl_trc.h"
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static unsigned int s1_3213[] = { /* spread numbers, some at slot edges */
0, 1, 4, 17, 63, 64, 65, 66,
90, 99,
};
static unsigned int s2_3213[] = { /* set with all bits in slot1 set */
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127,
};
static unsigned int s3_3213[] = { /* very spread numbers */
2232, 5167, 8204, 8526, 8641, 10056, 10140, 10611,
10998, 11626, 13735, 15539, 17947, 24295, 27833, 30318,
};
static void check_spbset(const char *name, unsigned int *s, size_t slen)
static void check_spbset(const char *name, const unsigned int *s, size_t slen)
{
struct uint_spbset bset;
size_t i, j;
@ -113,15 +89,32 @@ static void check_spbset(const char *name, unsigned int *s, size_t slen)
Curl_uint_spbset_destroy(&bset);
}
static void unit_stop(void)
static CURLcode test_unit3213(char *arg)
{
UNITTEST_BEGIN_SIMPLE
static const unsigned int s1[] = { /* spread numbers, some at slot edges */
0, 1, 4, 17, 63, 64, 65, 66,
90, 99,
};
static const unsigned int s2[] = { /* set with all bits in slot1 set */
64, 65, 66, 67, 68, 69, 70, 71,
72, 73, 74, 75, 76, 77, 78, 79,
80, 81, 82, 83, 84, 85, 86, 87,
88, 89, 90, 91, 92, 93, 94, 95,
96, 97, 98, 99, 100, 101, 102, 103,
104, 105, 106, 107, 108, 109, 110, 111,
112, 113, 114, 115, 116, 117, 118, 119,
120, 121, 122, 123, 124, 125, 126, 127,
};
static const unsigned int s3[] = { /* very spread numbers */
2232, 5167, 8204, 8526, 8641, 10056, 10140, 10611,
10998, 11626, 13735, 15539, 17947, 24295, 27833, 30318,
};
check_spbset("s1", s1, CURL_ARRAYSIZE(s1));
check_spbset("s2", s2, CURL_ARRAYSIZE(s2));
check_spbset("s3", s3, CURL_ARRAYSIZE(s3));
UNITTEST_END_SIMPLE
}
UNITTEST_START
check_spbset("s1", s1_3213, CURL_ARRAYSIZE(s1_3213));
check_spbset("s2", s2_3213, CURL_ARRAYSIZE(s2_3213));
check_spbset("s3", s3_3213, CURL_ARRAYSIZE(s3_3213));
UNITTEST_STOP