tests: drop mk-bundle exceptions

Using a mixture of techniques to avoid symbols collisions:
- reduce scope.
- add `t*_` / `T*_` prefix.
- move shared functions to `testutil.c`.
  (`suburl()`, `rlim2str()`)
- clone re-used lib*.c sources.
  (lib587, lib645)
- include shared symbols just once in re-used `lib*.c` sources.
  (using `LIB*_C` guards.)
- drop re-used `lib*.c` sources where they were identical or
  unused.
- make macros global.
- #undef macros before use.

What remain is the entry functions `test`, and `unit_setup`,
`unit_stop` in unit tests.

Also:
- fix formatting and other minor things along the way.
- add `const` where possible.
- sync some symbol names between tests.
- drop `mk-bundle-hints.sh` that's no longer necessary.

Closes #17468
This commit is contained in:
Viktor Szakats 2025-05-27 21:20:36 +02:00
parent 9ed34cc45b
commit 6897aeb105
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
142 changed files with 2055 additions and 1893 deletions

View file

@ -28,15 +28,15 @@
#include "curlx/base64.h"
#include "memdebug.h" /* LAST include file */
static struct Curl_easy *testdata;
static struct Curl_easy *t1302_easy;
static CURLcode unit_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
testdata = curl_easy_init();
if(!testdata) {
t1302_easy = curl_easy_init();
if(!t1302_easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
@ -45,7 +45,7 @@ static CURLcode unit_setup(void)
static void unit_stop(void)
{
curl_easy_cleanup(testdata);
curl_easy_cleanup(t1302_easy);
curl_global_cleanup();
}

View file

@ -27,15 +27,15 @@
#include "connect.h"
#include "memdebug.h" /* LAST include file */
static struct Curl_easy *testdata;
static struct Curl_easy *t1303_easy;
static CURLcode unit_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
testdata = curl_easy_init();
if(!testdata) {
t1303_easy = curl_easy_init();
if(!t1303_easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
@ -44,7 +44,7 @@ static CURLcode unit_setup(void)
static void unit_stop(void)
{
curl_easy_cleanup(testdata);
curl_easy_cleanup(t1303_easy);
curl_global_cleanup();
}
@ -55,8 +55,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) testdata->set.timeout = x; \
testdata->set.connecttimeout = y
#define TIMEOUTS(x,y) t1303_easy->set.timeout = x; \
t1303_easy->set.connecttimeout = y
/*
* To test:
@ -137,16 +137,16 @@ UNITTEST_START
};
/* this is the pretended start time of the transfer */
testdata->progress.t_startsingle.tv_sec = BASE;
testdata->progress.t_startsingle.tv_usec = 0;
testdata->progress.t_startop.tv_sec = BASE;
testdata->progress.t_startop.tv_usec = 0;
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;
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(testdata, &now, run[i].connecting);
timeout = Curl_timeleft(t1303_easy, &now, run[i].connecting);
if(timeout != run[i].result)
fail(run[i].comment);
}

View file

@ -40,15 +40,15 @@
#include "memdebug.h" /* LAST include file */
static struct Curl_easy *testdata;
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)
{
testdata = curl_easy_init();
if(!testdata) {
t1305_easy = curl_easy_init();
if(!t1305_easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
@ -66,7 +66,7 @@ static void unit_stop(void)
free(data_key);
Curl_dnscache_destroy(&hp);
curl_easy_cleanup(testdata);
curl_easy_cleanup(t1305_easy);
curl_global_cleanup();
}

View file

@ -57,202 +57,6 @@ static void unit_stop(void)
#define MAC_NOMATCH ((CURL_FNMATCH_NOMATCH << MAC_SHIFT) | MAC_DIFFER)
#define MAC_FAIL ((CURL_FNMATCH_FAIL << MAC_SHIFT) | MAC_DIFFER)
struct testcase {
const char *pattern;
const char *string;
int result;
};
static const struct testcase tests[] = {
/* brackets syntax */
{"*[*[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\001\177[[[[[[[[[[[[[[[[[[[[[",
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[",
NOMATCH|MAC_FAIL},
{ "\\[", "[", MATCH },
{ "[", "[", NOMATCH|LINUX_MATCH|MAC_FAIL},
{ "[]", "[]", NOMATCH|LINUX_MATCH|MAC_FAIL},
{ "[][]", "[", MATCH },
{ "[][]", "]", MATCH },
{ "[[]", "[", MATCH },
{ "[[[]", "[", MATCH },
{ "[[[[]", "[", MATCH },
{ "[[[[]", "[", MATCH },
{ "[][[]", "]", MATCH },
{ "[][[[]", "[", MATCH },
{ "[[]", "]", NOMATCH },
{ "[a@]", "a", MATCH },
{ "[a-z]", "a", MATCH },
{ "[a-z]", "A", NOMATCH },
{ "?[a-z]", "?Z", NOMATCH },
{ "[A-Z]", "C", MATCH },
{ "[A-Z]", "c", NOMATCH },
{ "[0-9]", "7", MATCH },
{ "[7-8]", "7", MATCH },
{ "[7-]", "7", MATCH },
{ "[7-]", "-", MATCH },
{ "[7-]", "[", NOMATCH },
{ "[a-bA-F]", "F", MATCH },
{ "[a-bA-B9]", "9", MATCH },
{ "[a-bA-B98]", "8", MATCH },
{ "[a-bA-B98]", "C", NOMATCH },
{ "[a-bA-Z9]", "F", MATCH },
{ "[a-bA-Z9]ero*", "Zero chance.", MATCH },
{ "S[a-][x]opho*", "Saxophone", MATCH },
{ "S[a-][x]opho*", "SaXophone", NOMATCH },
{ "S[a-][x]*.txt", "S-x.txt", MATCH },
{ "[\\a-\\b]", "a", MATCH },
{ "[\\a-\\b]", "b", MATCH },
{ "[?*[][?*[][?*[]", "?*[", MATCH },
{ "[][?*-]", "]", MATCH },
{ "[][?*-]", "[", MATCH },
{ "[][?*-]", "?", MATCH },
{ "[][?*-]", "*", MATCH },
{ "[][?*-]", "-", MATCH },
{ "[]?*-]", "-", MATCH },
{ "[\xFF]", "\xFF", MATCH|LINUX_FAIL|MAC_FAIL},
{ "?/b/c", "a/b/c", MATCH },
{ "^_{}~", "^_{}~", MATCH },
{ "!#%+,-./01234567889", "!#%+,-./01234567889", MATCH },
{ "PQRSTUVWXYZ]abcdefg", "PQRSTUVWXYZ]abcdefg", MATCH },
{ ":;=@ABCDEFGHIJKLMNO", ":;=@ABCDEFGHIJKLMNO", MATCH },
/* negate */
{ "[!a]", "b", MATCH },
{ "[!a]", "a", NOMATCH },
{ "[^a]", "b", MATCH },
{ "[^a]", "a", NOMATCH },
{ "[^a-z0-9A-Z]", "a", NOMATCH },
{ "[^a-z0-9A-Z]", "-", MATCH },
{ "curl[!a-z]lib", "curl lib", MATCH },
{ "curl[! ]lib", "curl lib", NOMATCH },
{ "[! ][ ]", " ", NOMATCH },
{ "[! ][ ]", "a ", MATCH },
{ "*[^a].t?t", "a.txt", NOMATCH },
{ "*[^a].t?t", "ba.txt", NOMATCH },
{ "*[^a].t?t", "ab.txt", MATCH },
{ "*[^a]", "", NOMATCH },
{ "[!\xFF]", "", NOMATCH|LINUX_FAIL},
{ "[!\xFF]", "\xFF", NOMATCH|LINUX_FAIL|MAC_FAIL},
{ "[!\xFF]", "a", MATCH|LINUX_FAIL|MAC_FAIL},
{ "[!?*[]", "?", NOMATCH },
{ "[!!]", "!", NOMATCH },
{ "[!!]", "x", MATCH },
{ "[[:alpha:]]", "a", MATCH },
{ "[[:alpha:]]", "9", NOMATCH },
{ "[[:alnum:]]", "a", MATCH },
{ "[[:alnum:]]", "[", NOMATCH },
{ "[[:alnum:]]", "]", NOMATCH },
{ "[[:alnum:]]", "9", MATCH },
{ "[[:digit:]]", "9", MATCH },
{ "[[:xdigit:]]", "9", MATCH },
{ "[[:xdigit:]]", "F", MATCH },
{ "[[:xdigit:]]", "G", NOMATCH },
{ "[[:upper:]]", "U", MATCH },
{ "[[:upper:]]", "u", NOMATCH },
{ "[[:lower:]]", "l", MATCH },
{ "[[:lower:]]", "L", NOMATCH },
{ "[[:print:]]", "L", MATCH },
{ "[[:print:]]", "\10", NOMATCH },
{ "[[:print:]]", "\10", NOMATCH },
{ "[[:space:]]", " ", MATCH },
{ "[[:space:]]", "x", NOMATCH },
{ "[[:graph:]]", " ", NOMATCH },
{ "[[:graph:]]", "x", MATCH },
{ "[[:blank:]]", "\t", MATCH },
{ "[[:blank:]]", " ", MATCH },
{ "[[:blank:]]", "\r", NOMATCH },
{ "[^[:blank:]]", "\t", NOMATCH },
{ "[^[:print:]]", "\10", MATCH },
{ "[[:lower:]][[:lower:]]", "ll", MATCH },
{ "[[:foo:]]", "bar", NOMATCH|MAC_FAIL},
{ "[[:foo:]]", "f]", MATCH|LINUX_NOMATCH|MAC_FAIL},
{ "Curl[[:blank:]];-)", "Curl ;-)", MATCH },
{ "*[[:blank:]]*", " ", MATCH },
{ "*[[:blank:]]*", "", NOMATCH },
{ "*[[:blank:]]*", "hi, im_Pavel", MATCH },
/* common using */
{ "filename.dat", "filename.dat", MATCH },
{ "*curl*", "lets use curl!!", MATCH },
{ "filename.txt", "filename.dat", NOMATCH },
{ "*.txt", "text.txt", MATCH },
{ "*.txt", "a.txt", MATCH },
{ "*.txt", ".txt", MATCH },
{ "*.txt", "txt", NOMATCH },
{ "??.txt", "99.txt", MATCH },
{ "??.txt", "a99.txt", NOMATCH },
{ "?.???", "a.txt", MATCH },
{ "*.???", "somefile.dat", MATCH },
{ "*.???", "photo.jpeg", NOMATCH },
{ ".*", ".htaccess", MATCH },
{ ".*", ".", MATCH },
{ ".*", "..", MATCH },
/* many stars => one star */
{ "**.txt", "text.txt", MATCH },
{ "***.txt", "t.txt", MATCH },
{ "****.txt", ".txt", MATCH },
/* empty string or pattern */
{ "", "", MATCH },
{ "", "hello", NOMATCH },
{ "file", "", NOMATCH },
{ "?", "", NOMATCH },
{ "*", "", MATCH },
{ "x", "", NOMATCH },
/* backslash */
{ "\\", "\\", MATCH|LINUX_NOMATCH},
{ "\\\\", "\\", MATCH },
{ "\\\\", "\\\\", NOMATCH },
{ "\\?", "?", MATCH },
{ "\\*", "*", MATCH },
{ "?.txt", "?.txt", MATCH },
{ "*.txt", "*.txt", MATCH },
{ "\\?.txt", "?.txt", MATCH },
{ "\\*.txt", "*.txt", MATCH },
{ "\\?.txt", "x.txt", NOMATCH },
{ "\\*.txt", "x.txt", NOMATCH },
{ "\\*\\\\.txt", "*\\.txt", MATCH },
{ "*\\**\\?*\\\\*", "cc*cc?cccc", NOMATCH },
{ "*\\?*\\**", "cc?cc", NOMATCH },
{ "\\\"\\$\\&\\'\\(\\)", "\"$&'()", MATCH },
{ "\\*\\?\\[\\\\\\`\\|", "*?[\\`|", MATCH },
{ "[\\a\\b]c", "ac", MATCH },
{ "[\\a\\b]c", "bc", MATCH },
{ "[\\a\\b]d", "bc", NOMATCH },
{ "[a-bA-B\\?]", "?", MATCH },
{ "cu[a-ab-b\\r]l", "curl", MATCH },
{ "[\\a-z]", "c", MATCH },
{ "?*?*?.*?*", "abc.c", MATCH },
{ "?*?*?.*?*", "abcc", NOMATCH },
{ "?*?*?.*?*", "abc.", NOMATCH },
{ "?*?*?.*?*", "abc.c++", MATCH },
{ "?*?*?.*?*", "abcdef.c++", MATCH },
{ "?*?*?.?", "abcdef.c", MATCH },
{ "?*?*?.?", "abcdef.cd", NOMATCH },
/* https://codepoints.net/U+00E4 Latin Small Letter A with Diaeresis */
{ "Lindm\xc3\xa4tarv", "Lindm\xc3\xa4tarv", MATCH },
{ "", "", MATCH},
{"**]*[*[\x13]**[*\x13)]*]*[**[*\x13~r-]*]**[.*]*[\xe3\xe3\xe3\xe3\xe3\xe3"
"\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3"
"\xe3\xe3\xe3\xe3\xe3*[\x13]**[*\x13)]*]*[*[\x13]*[~r]*]*\xba\x13\xa6~b-]*",
"a", NOMATCH|LINUX_FAIL}
};
static const char *ret2name(int i)
{
switch(i) {
@ -276,6 +80,203 @@ enum system {
UNITTEST_START
{
struct testcase {
const char *pattern;
const char *string;
int result;
};
static const struct testcase tests[] = {
/* brackets syntax */
{"*[*[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[\001\177[[[[[[[[[[[[[[[[[[[[[",
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[["
"[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[",
NOMATCH|MAC_FAIL},
{ "\\[", "[", MATCH },
{ "[", "[", NOMATCH|LINUX_MATCH|MAC_FAIL},
{ "[]", "[]", NOMATCH|LINUX_MATCH|MAC_FAIL},
{ "[][]", "[", MATCH },
{ "[][]", "]", MATCH },
{ "[[]", "[", MATCH },
{ "[[[]", "[", MATCH },
{ "[[[[]", "[", MATCH },
{ "[[[[]", "[", MATCH },
{ "[][[]", "]", MATCH },
{ "[][[[]", "[", MATCH },
{ "[[]", "]", NOMATCH },
{ "[a@]", "a", MATCH },
{ "[a-z]", "a", MATCH },
{ "[a-z]", "A", NOMATCH },
{ "?[a-z]", "?Z", NOMATCH },
{ "[A-Z]", "C", MATCH },
{ "[A-Z]", "c", NOMATCH },
{ "[0-9]", "7", MATCH },
{ "[7-8]", "7", MATCH },
{ "[7-]", "7", MATCH },
{ "[7-]", "-", MATCH },
{ "[7-]", "[", NOMATCH },
{ "[a-bA-F]", "F", MATCH },
{ "[a-bA-B9]", "9", MATCH },
{ "[a-bA-B98]", "8", MATCH },
{ "[a-bA-B98]", "C", NOMATCH },
{ "[a-bA-Z9]", "F", MATCH },
{ "[a-bA-Z9]ero*", "Zero chance.", MATCH },
{ "S[a-][x]opho*", "Saxophone", MATCH },
{ "S[a-][x]opho*", "SaXophone", NOMATCH },
{ "S[a-][x]*.txt", "S-x.txt", MATCH },
{ "[\\a-\\b]", "a", MATCH },
{ "[\\a-\\b]", "b", MATCH },
{ "[?*[][?*[][?*[]", "?*[", MATCH },
{ "[][?*-]", "]", MATCH },
{ "[][?*-]", "[", MATCH },
{ "[][?*-]", "?", MATCH },
{ "[][?*-]", "*", MATCH },
{ "[][?*-]", "-", MATCH },
{ "[]?*-]", "-", MATCH },
{ "[\xFF]", "\xFF", MATCH|LINUX_FAIL|MAC_FAIL},
{ "?/b/c", "a/b/c", MATCH },
{ "^_{}~", "^_{}~", MATCH },
{ "!#%+,-./01234567889", "!#%+,-./01234567889", MATCH },
{ "PQRSTUVWXYZ]abcdefg", "PQRSTUVWXYZ]abcdefg", MATCH },
{ ":;=@ABCDEFGHIJKLMNO", ":;=@ABCDEFGHIJKLMNO", MATCH },
/* negate */
{ "[!a]", "b", MATCH },
{ "[!a]", "a", NOMATCH },
{ "[^a]", "b", MATCH },
{ "[^a]", "a", NOMATCH },
{ "[^a-z0-9A-Z]", "a", NOMATCH },
{ "[^a-z0-9A-Z]", "-", MATCH },
{ "curl[!a-z]lib", "curl lib", MATCH },
{ "curl[! ]lib", "curl lib", NOMATCH },
{ "[! ][ ]", " ", NOMATCH },
{ "[! ][ ]", "a ", MATCH },
{ "*[^a].t?t", "a.txt", NOMATCH },
{ "*[^a].t?t", "ba.txt", NOMATCH },
{ "*[^a].t?t", "ab.txt", MATCH },
{ "*[^a]", "", NOMATCH },
{ "[!\xFF]", "", NOMATCH|LINUX_FAIL},
{ "[!\xFF]", "\xFF", NOMATCH|LINUX_FAIL|MAC_FAIL},
{ "[!\xFF]", "a", MATCH|LINUX_FAIL|MAC_FAIL},
{ "[!?*[]", "?", NOMATCH },
{ "[!!]", "!", NOMATCH },
{ "[!!]", "x", MATCH },
{ "[[:alpha:]]", "a", MATCH },
{ "[[:alpha:]]", "9", NOMATCH },
{ "[[:alnum:]]", "a", MATCH },
{ "[[:alnum:]]", "[", NOMATCH },
{ "[[:alnum:]]", "]", NOMATCH },
{ "[[:alnum:]]", "9", MATCH },
{ "[[:digit:]]", "9", MATCH },
{ "[[:xdigit:]]", "9", MATCH },
{ "[[:xdigit:]]", "F", MATCH },
{ "[[:xdigit:]]", "G", NOMATCH },
{ "[[:upper:]]", "U", MATCH },
{ "[[:upper:]]", "u", NOMATCH },
{ "[[:lower:]]", "l", MATCH },
{ "[[:lower:]]", "L", NOMATCH },
{ "[[:print:]]", "L", MATCH },
{ "[[:print:]]", "\10", NOMATCH },
{ "[[:print:]]", "\10", NOMATCH },
{ "[[:space:]]", " ", MATCH },
{ "[[:space:]]", "x", NOMATCH },
{ "[[:graph:]]", " ", NOMATCH },
{ "[[:graph:]]", "x", MATCH },
{ "[[:blank:]]", "\t", MATCH },
{ "[[:blank:]]", " ", MATCH },
{ "[[:blank:]]", "\r", NOMATCH },
{ "[^[:blank:]]", "\t", NOMATCH },
{ "[^[:print:]]", "\10", MATCH },
{ "[[:lower:]][[:lower:]]", "ll", MATCH },
{ "[[:foo:]]", "bar", NOMATCH|MAC_FAIL},
{ "[[:foo:]]", "f]", MATCH|LINUX_NOMATCH|MAC_FAIL},
{ "Curl[[:blank:]];-)", "Curl ;-)", MATCH },
{ "*[[:blank:]]*", " ", MATCH },
{ "*[[:blank:]]*", "", NOMATCH },
{ "*[[:blank:]]*", "hi, im_Pavel", MATCH },
/* common using */
{ "filename.dat", "filename.dat", MATCH },
{ "*curl*", "lets use curl!!", MATCH },
{ "filename.txt", "filename.dat", NOMATCH },
{ "*.txt", "text.txt", MATCH },
{ "*.txt", "a.txt", MATCH },
{ "*.txt", ".txt", MATCH },
{ "*.txt", "txt", NOMATCH },
{ "??.txt", "99.txt", MATCH },
{ "??.txt", "a99.txt", NOMATCH },
{ "?.???", "a.txt", MATCH },
{ "*.???", "somefile.dat", MATCH },
{ "*.???", "photo.jpeg", NOMATCH },
{ ".*", ".htaccess", MATCH },
{ ".*", ".", MATCH },
{ ".*", "..", MATCH },
/* many stars => one star */
{ "**.txt", "text.txt", MATCH },
{ "***.txt", "t.txt", MATCH },
{ "****.txt", ".txt", MATCH },
/* empty string or pattern */
{ "", "", MATCH },
{ "", "hello", NOMATCH },
{ "file", "", NOMATCH },
{ "?", "", NOMATCH },
{ "*", "", MATCH },
{ "x", "", NOMATCH },
/* backslash */
{ "\\", "\\", MATCH|LINUX_NOMATCH},
{ "\\\\", "\\", MATCH },
{ "\\\\", "\\\\", NOMATCH },
{ "\\?", "?", MATCH },
{ "\\*", "*", MATCH },
{ "?.txt", "?.txt", MATCH },
{ "*.txt", "*.txt", MATCH },
{ "\\?.txt", "?.txt", MATCH },
{ "\\*.txt", "*.txt", MATCH },
{ "\\?.txt", "x.txt", NOMATCH },
{ "\\*.txt", "x.txt", NOMATCH },
{ "\\*\\\\.txt", "*\\.txt", MATCH },
{ "*\\**\\?*\\\\*", "cc*cc?cccc", NOMATCH },
{ "*\\?*\\**", "cc?cc", NOMATCH },
{ "\\\"\\$\\&\\'\\(\\)", "\"$&'()", MATCH },
{ "\\*\\?\\[\\\\\\`\\|", "*?[\\`|", MATCH },
{ "[\\a\\b]c", "ac", MATCH },
{ "[\\a\\b]c", "bc", MATCH },
{ "[\\a\\b]d", "bc", NOMATCH },
{ "[a-bA-B\\?]", "?", MATCH },
{ "cu[a-ab-b\\r]l", "curl", MATCH },
{ "[\\a-z]", "c", MATCH },
{ "?*?*?.*?*", "abc.c", MATCH },
{ "?*?*?.*?*", "abcc", NOMATCH },
{ "?*?*?.*?*", "abc.", NOMATCH },
{ "?*?*?.*?*", "abc.c++", MATCH },
{ "?*?*?.*?*", "abcdef.c++", MATCH },
{ "?*?*?.?", "abcdef.c", MATCH },
{ "?*?*?.?", "abcdef.cd", NOMATCH },
/* https://codepoints.net/U+00E4 Latin Small Letter A with Diaeresis */
{ "Lindm\xc3\xa4tarv", "Lindm\xc3\xa4tarv", MATCH },
{ "", "", MATCH},
{"**]*[*[\x13]**[*\x13)]*]*[**[*\x13~r-]*]**[.*]*[\xe3\xe3\xe3\xe3\xe3\xe3"
"\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3\xe3"
"\xe3\xe3\xe3\xe3\xe3*[\x13]**[*\x13)]*]*[*[\x13]*[~r]*]*\xba\x13\xa6~b-]"
"*",
"a", NOMATCH|LINUX_FAIL}
};
int i;
enum system machine;

View file

@ -36,67 +36,68 @@ static void unit_stop(void)
/* only these backends define the tested functions */
#if defined(USE_OPENSSL) || defined(USE_SCHANNEL)
#include "vtls/hostcheck.h"
struct testcase {
const char *host;
const char *pattern;
bool match;
};
static struct testcase tests[] = {
{"", "", FALSE},
{"a", "", FALSE},
{"", "b", FALSE},
{"a", "b", FALSE},
{"aa", "bb", FALSE},
{"\xff", "\xff", TRUE},
{"aa.aa.aa", "aa.aa.bb", FALSE},
{"aa.aa.aa", "aa.aa.aa", TRUE},
{"aa.aa.aa", "*.aa.bb", FALSE},
{"aa.aa.aa", "*.aa.aa", TRUE},
{"192.168.0.1", "192.168.0.1", TRUE},
{"192.168.0.1", "*.168.0.1", FALSE},
{"192.168.0.1", "*.0.1", FALSE},
{"h.ello", "*.ello", FALSE},
{"h.ello.", "*.ello", FALSE},
{"h.ello", "*.ello.", FALSE},
{"h.e.llo", "*.e.llo", TRUE},
{"h.e.llo", " *.e.llo", FALSE},
{" h.e.llo", "*.e.llo", TRUE},
{"h.e.llo.", "*.e.llo", TRUE},
{"*.e.llo.", "*.e.llo", TRUE},
{"************.e.llo.", "*.e.llo", TRUE},
{"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
".e.llo.", "*.e.llo", TRUE},
{"\xfe\xfe.e.llo.", "*.e.llo", TRUE},
{"h.e.llo.", "*.e.llo.", TRUE},
{"h.e.llo", "*.e.llo.", TRUE},
{".h.e.llo", "*.e.llo.", FALSE},
{"h.e.llo", "*.*.llo.", FALSE},
{"h.e.llo", "h.*.llo", FALSE},
{"h.e.llo", "h.e.*", FALSE},
{"hello", "*.ello", FALSE},
{"hello", "**llo", FALSE},
{"bar.foo.example.com", "*.example.com", FALSE},
{"foo.example.com", "*.example.com", TRUE},
{"baz.example.net", "b*z.example.net", FALSE},
{"foobaz.example.net", "*baz.example.net", FALSE},
{"xn--l8j.example.local", "x*.example.local", FALSE},
{"xn--l8j.example.net", "*.example.net", TRUE},
{"xn--l8j.example.net", "*j.example.net", FALSE},
{"xn--l8j.example.net", "xn--l8j.example.net", TRUE},
{"xn--l8j.example.net", "xn--l8j.*.net", FALSE},
{"xl8j.example.net", "*.example.net", TRUE},
{"fe80::3285:a9ff:fe46:b619", "*::3285:a9ff:fe46:b619", FALSE},
{"fe80::3285:a9ff:fe46:b619", "fe80::3285:a9ff:fe46:b619", TRUE},
{NULL, NULL, FALSE}
};
UNITTEST_START
{
struct testcase {
const char *host;
const char *pattern;
bool match;
};
static struct testcase tests[] = {
{"", "", FALSE},
{"a", "", FALSE},
{"", "b", FALSE},
{"a", "b", FALSE},
{"aa", "bb", FALSE},
{"\xff", "\xff", TRUE},
{"aa.aa.aa", "aa.aa.bb", FALSE},
{"aa.aa.aa", "aa.aa.aa", TRUE},
{"aa.aa.aa", "*.aa.bb", FALSE},
{"aa.aa.aa", "*.aa.aa", TRUE},
{"192.168.0.1", "192.168.0.1", TRUE},
{"192.168.0.1", "*.168.0.1", FALSE},
{"192.168.0.1", "*.0.1", FALSE},
{"h.ello", "*.ello", FALSE},
{"h.ello.", "*.ello", FALSE},
{"h.ello", "*.ello.", FALSE},
{"h.e.llo", "*.e.llo", TRUE},
{"h.e.llo", " *.e.llo", FALSE},
{" h.e.llo", "*.e.llo", TRUE},
{"h.e.llo.", "*.e.llo", TRUE},
{"*.e.llo.", "*.e.llo", TRUE},
{"************.e.llo.", "*.e.llo", TRUE},
{"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
"BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB"
"CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC"
"DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD"
"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
".e.llo.", "*.e.llo", TRUE},
{"\xfe\xfe.e.llo.", "*.e.llo", TRUE},
{"h.e.llo.", "*.e.llo.", TRUE},
{"h.e.llo", "*.e.llo.", TRUE},
{".h.e.llo", "*.e.llo.", FALSE},
{"h.e.llo", "*.*.llo.", FALSE},
{"h.e.llo", "h.*.llo", FALSE},
{"h.e.llo", "h.e.*", FALSE},
{"hello", "*.ello", FALSE},
{"hello", "**llo", FALSE},
{"bar.foo.example.com", "*.example.com", FALSE},
{"foo.example.com", "*.example.com", TRUE},
{"baz.example.net", "b*z.example.net", FALSE},
{"foobaz.example.net", "*baz.example.net", FALSE},
{"xn--l8j.example.local", "x*.example.local", FALSE},
{"xn--l8j.example.net", "*.example.net", TRUE},
{"xn--l8j.example.net", "*j.example.net", FALSE},
{"xn--l8j.example.net", "xn--l8j.example.net", TRUE},
{"xn--l8j.example.net", "xn--l8j.*.net", FALSE},
{"xl8j.example.net", "*.example.net", TRUE},
{"fe80::3285:a9ff:fe46:b619", "*::3285:a9ff:fe46:b619", FALSE},
{"fe80::3285:a9ff:fe46:b619", "fe80::3285:a9ff:fe46:b619", TRUE},
{NULL, NULL, FALSE}
};
int i;
for(i = 0; tests[i].host; i++) {
if(tests[i].match != Curl_cert_hostcheck(tests[i].pattern,

View file

@ -28,8 +28,14 @@
#pragma GCC diagnostic ignored "-Wformat"
#endif
static CURLcode unit_setup(void) {return CURLE_OK;}
static void unit_stop(void) {}
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
UNITTEST_START

View file

@ -28,14 +28,13 @@
static int usec_magnitude = 1000000;
static bool unit_setup(void)
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void unit_stop(void)
{
}
/*

View file

@ -26,15 +26,15 @@
#include "urldata.h"
#include "curl_ntlm_core.h"
static CURL *easy;
static CURL *t1600_easy;
static CURLcode unit_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
easy = curl_easy_init();
if(!easy) {
t1600_easy = curl_easy_init();
if(!t1600_easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
@ -43,7 +43,7 @@ static CURLcode unit_setup(void)
static void unit_stop(void)
{
curl_easy_cleanup(easy);
curl_easy_cleanup(t1600_easy);
curl_global_cleanup();
}

View file

@ -29,9 +29,9 @@
#include <memdebug.h> /* LAST include file */
static struct Curl_hash hash_static;
static struct Curl_hash t1602_hash_static;
static void mydtor(void *p)
static void t1602_mydtor(void *p)
{
int *ptr = (int *)p;
free(ptr);
@ -39,14 +39,14 @@ static void mydtor(void *p)
static CURLcode unit_setup(void)
{
Curl_hash_init(&hash_static, 7, Curl_hash_str,
curlx_str_key_compare, mydtor);
Curl_hash_init(&t1602_hash_static, 7, Curl_hash_str,
curlx_str_key_compare, t1602_mydtor);
return CURLE_OK;
}
static void unit_stop(void)
{
Curl_hash_destroy(&hash_static);
Curl_hash_destroy(&t1602_hash_static);
}
UNITTEST_START
@ -62,17 +62,17 @@ UNITTEST_START
value = malloc(sizeof(int));
abort_unless(value != NULL, "Out of memory");
*value = 199;
nodep = Curl_hash_add(&hash_static, &key, klen, value);
nodep = Curl_hash_add(&t1602_hash_static, &key, klen, value);
if(!nodep)
free(value);
abort_unless(nodep, "insertion into hash failed");
Curl_hash_clean(&hash_static);
Curl_hash_clean(&t1602_hash_static);
/* Attempt to add another key/value pair */
value2 = malloc(sizeof(int));
abort_unless(value2 != NULL, "Out of memory");
*value2 = 204;
nodep = Curl_hash_add(&hash_static, &key2, klen, value2);
nodep = Curl_hash_add(&t1602_hash_static, &key2, klen, value2);
if(!nodep)
free(value2);
abort_unless(nodep, "insertion into hash failed");

View file

@ -27,10 +27,10 @@
#include "hash.h"
#include <memdebug.h> /* LAST include file */
static struct Curl_hash hash_static;
static struct Curl_hash t1603_hash_static;
static const size_t slots = 3;
static void mydtor(void *p)
static void t1603_mydtor(void *p)
{
/* Data are statically allocated */
(void)p; /* unused */
@ -48,14 +48,14 @@ static void my_elem_dtor(void *key, size_t key_len, void *p)
static CURLcode unit_setup(void)
{
Curl_hash_init(&hash_static, slots, Curl_hash_str,
curlx_str_key_compare, mydtor);
Curl_hash_init(&t1603_hash_static, slots, Curl_hash_str,
curlx_str_key_compare, t1603_mydtor);
return CURLE_OK;
}
static void unit_stop(void)
{
Curl_hash_destroy(&hash_static);
Curl_hash_destroy(&t1603_hash_static);
}
UNITTEST_START
@ -78,100 +78,100 @@ UNITTEST_START
"Warning: hashes are not computed as expected on this "
"architecture; test coverage will be less comprehensive\n");
nodep = Curl_hash_add(&hash_static, &key1, strlen(key1), &key1);
nodep = Curl_hash_add(&t1603_hash_static, &key1, strlen(key1), &key1);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
nodep = Curl_hash_pick(&t1603_hash_static, &key1, strlen(key1));
fail_unless(nodep == key1, "hash retrieval failed");
nodep = Curl_hash_add(&hash_static, &key2, strlen(key2), &key2);
nodep = Curl_hash_add(&t1603_hash_static, &key2, strlen(key2), &key2);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
nodep = Curl_hash_pick(&t1603_hash_static, &key2, strlen(key2));
fail_unless(nodep == key2, "hash retrieval failed");
nodep = Curl_hash_add(&hash_static, &key3, strlen(key3), &key3);
nodep = Curl_hash_add(&t1603_hash_static, &key3, strlen(key3), &key3);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key3, strlen(key3));
nodep = Curl_hash_pick(&t1603_hash_static, &key3, strlen(key3));
fail_unless(nodep == key3, "hash retrieval failed");
/* The fourth element exceeds the number of slots & collides */
nodep = Curl_hash_add(&hash_static, &key4, strlen(key4), &key4);
nodep = Curl_hash_add(&t1603_hash_static, &key4, strlen(key4), &key4);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
nodep = Curl_hash_pick(&t1603_hash_static, &key4, strlen(key4));
fail_unless(nodep == key4, "hash retrieval failed");
/* Make sure all elements are still accessible */
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
nodep = Curl_hash_pick(&t1603_hash_static, &key1, strlen(key1));
fail_unless(nodep == key1, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
nodep = Curl_hash_pick(&t1603_hash_static, &key2, strlen(key2));
fail_unless(nodep == key2, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key3, strlen(key3));
nodep = Curl_hash_pick(&t1603_hash_static, &key3, strlen(key3));
fail_unless(nodep == key3, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
nodep = Curl_hash_pick(&t1603_hash_static, &key4, strlen(key4));
fail_unless(nodep == key4, "hash retrieval failed");
/* Delete the second of two entries in a bucket */
rc = Curl_hash_delete(&hash_static, &key4, strlen(key4));
rc = Curl_hash_delete(&t1603_hash_static, &key4, strlen(key4));
fail_unless(rc == 0, "hash delete failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
nodep = Curl_hash_pick(&t1603_hash_static, &key1, strlen(key1));
fail_unless(nodep == key1, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
nodep = Curl_hash_pick(&t1603_hash_static, &key4, strlen(key4));
fail_unless(!nodep, "hash retrieval should have failed");
/* Insert that deleted node again */
nodep = Curl_hash_add(&hash_static, &key4, strlen(key4), &key4);
nodep = Curl_hash_add(&t1603_hash_static, &key4, strlen(key4), &key4);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
nodep = Curl_hash_pick(&t1603_hash_static, &key4, strlen(key4));
fail_unless(nodep == key4, "hash retrieval failed");
/* Delete the first of two entries in a bucket */
rc = Curl_hash_delete(&hash_static, &key1, strlen(key1));
rc = Curl_hash_delete(&t1603_hash_static, &key1, strlen(key1));
fail_unless(rc == 0, "hash delete failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
nodep = Curl_hash_pick(&t1603_hash_static, &key1, strlen(key1));
fail_unless(!nodep, "hash retrieval should have failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
nodep = Curl_hash_pick(&t1603_hash_static, &key4, strlen(key4));
fail_unless(nodep == key4, "hash retrieval failed");
/* Delete the remaining one of two entries in a bucket */
rc = Curl_hash_delete(&hash_static, &key4, strlen(key4));
rc = Curl_hash_delete(&t1603_hash_static, &key4, strlen(key4));
fail_unless(rc == 0, "hash delete failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
nodep = Curl_hash_pick(&t1603_hash_static, &key1, strlen(key1));
fail_unless(!nodep, "hash retrieval should have failed");
nodep = Curl_hash_pick(&hash_static, &key4, strlen(key4));
nodep = Curl_hash_pick(&t1603_hash_static, &key4, strlen(key4));
fail_unless(!nodep, "hash retrieval should have failed");
/* Delete an already deleted node */
rc = Curl_hash_delete(&hash_static, &key4, strlen(key4));
rc = Curl_hash_delete(&t1603_hash_static, &key4, strlen(key4));
fail_unless(rc, "hash delete should have failed");
/* Replace an existing node */
nodep = Curl_hash_add(&hash_static, &key1, strlen(key1), &notakey);
nodep = Curl_hash_add(&t1603_hash_static, &key1, strlen(key1), &notakey);
fail_unless(nodep, "insertion into hash failed");
nodep = Curl_hash_pick(&hash_static, &key1, strlen(key1));
nodep = Curl_hash_pick(&t1603_hash_static, &key1, strlen(key1));
fail_unless(nodep == notakey, "hash retrieval failed");
/* Make sure all remaining elements are still accessible */
nodep = Curl_hash_pick(&hash_static, &key2, strlen(key2));
nodep = Curl_hash_pick(&t1603_hash_static, &key2, strlen(key2));
fail_unless(nodep == key2, "hash retrieval failed");
nodep = Curl_hash_pick(&hash_static, &key3, strlen(key3));
nodep = Curl_hash_pick(&t1603_hash_static, &key3, strlen(key3));
fail_unless(nodep == key3, "hash retrieval failed");
/* Add element with own destructor */
nodep = Curl_hash_add2(&hash_static, &key1, strlen(key1), &key1,
nodep = Curl_hash_add2(&t1603_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(&hash_static, &key1, strlen(key1), &key1,
nodep = Curl_hash_add2(&t1603_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(&hash_static, &key1, strlen(key1));
rc = Curl_hash_delete(&t1603_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(&hash_static);
Curl_hash_clean(&t1603_hash_static);
UNITTEST_STOP

View file

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

View file

@ -26,15 +26,15 @@
#include "speedcheck.h"
#include "urldata.h"
static struct Curl_easy *easy;
static struct Curl_easy *t1606_easy;
static CURLcode unit_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
easy = curl_easy_init();
if(!easy) {
t1606_easy = curl_easy_init();
if(!t1606_easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
@ -43,7 +43,7 @@ static CURLcode unit_setup(void)
static void unit_stop(void)
{
curl_easy_cleanup(easy);
curl_easy_cleanup(t1606_easy);
curl_global_cleanup();
}
@ -57,14 +57,14 @@ static int runawhile(long time_limit,
CURLcode result;
int finaltime;
curl_easy_setopt(easy, CURLOPT_LOW_SPEED_LIMIT, speed_limit);
curl_easy_setopt(easy, CURLOPT_LOW_SPEED_TIME, time_limit);
Curl_speedinit(easy);
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);
do {
/* fake the current transfer speed */
easy->progress.current_speed = speed;
result = Curl_speedcheck(easy, now);
t1606_easy->progress.current_speed = speed;
result = Curl_speedcheck(t1606_easy, now);
if(result)
break;
/* step the time */

View file

@ -42,23 +42,6 @@ static CURLcode unit_setup(void)
return res;
}
struct testcase {
/* host:port:address[,address]... */
const char *optval;
/* lowercase host and port to retrieve the addresses from hostcache */
const char *host;
int port;
/* whether we expect a permanent or non-permanent cache entry */
bool permanent;
/* 0 to 9 addresses expected from hostcache */
const char *address[10];
};
/* 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;
@ -68,46 +51,61 @@ static const char skip = 0;
#define IPV6ONLY(x) &skip
#endif
/* CURLOPT_RESOLVE address parsing tests */
static const struct testcase tests[] = {
/* spaces aren't allowed, for now */
{ "test.com:80:127.0.0.1, 127.0.0.2",
"test.com", 80, TRUE, { NULL, }
},
{ "TEST.com:80:,,127.0.0.1,,,127.0.0.2,,,,::1,,,",
"test.com", 80, TRUE, { "127.0.0.1", "127.0.0.2", IPV6ONLY("::1"), }
},
{ "test.com:80:::1,127.0.0.1",
"test.com", 80, TRUE, { IPV6ONLY("::1"), "127.0.0.1", }
},
{ "test.com:80:[::1],127.0.0.1",
"test.com", 80, TRUE, { IPV6ONLY("::1"), "127.0.0.1", }
},
{ "test.com:80:::1",
"test.com", 80, TRUE, { IPV6ONLY("::1"), }
},
{ "test.com:80:[::1]",
"test.com", 80, TRUE, { IPV6ONLY("::1"), }
},
{ "test.com:80:127.0.0.1",
"test.com", 80, TRUE, { "127.0.0.1", }
},
{ "test.com:80:,127.0.0.1",
"test.com", 80, TRUE, { "127.0.0.1", }
},
{ "test.com:80:127.0.0.1,",
"test.com", 80, TRUE, { "127.0.0.1", }
},
{ "test.com:0:127.0.0.1",
"test.com", 0, TRUE, { "127.0.0.1", }
},
{ "+test.com:80:127.0.0.1,",
"test.com", 80, FALSE, { "127.0.0.1", }
},
};
UNITTEST_START
{
struct testcase {
/* host:port:address[,address]... */
const char *optval;
/* lowercase host and port to retrieve the addresses from hostcache */
const char *host;
int port;
/* whether we expect a permanent or non-permanent cache entry */
bool permanent;
/* 0 to 9 addresses expected from hostcache */
const char *address[10];
};
/* CURLOPT_RESOLVE address parsing tests */
static const struct testcase tests[] = {
/* spaces aren't allowed, for now */
{ "test.com:80:127.0.0.1, 127.0.0.2",
"test.com", 80, TRUE, { NULL, }
},
{ "TEST.com:80:,,127.0.0.1,,,127.0.0.2,,,,::1,,,",
"test.com", 80, TRUE, { "127.0.0.1", "127.0.0.2", IPV6ONLY("::1"), }
},
{ "test.com:80:::1,127.0.0.1",
"test.com", 80, TRUE, { IPV6ONLY("::1"), "127.0.0.1", }
},
{ "test.com:80:[::1],127.0.0.1",
"test.com", 80, TRUE, { IPV6ONLY("::1"), "127.0.0.1", }
},
{ "test.com:80:::1",
"test.com", 80, TRUE, { IPV6ONLY("::1"), }
},
{ "test.com:80:[::1]",
"test.com", 80, TRUE, { IPV6ONLY("::1"), }
},
{ "test.com:80:127.0.0.1",
"test.com", 80, TRUE, { "127.0.0.1", }
},
{ "test.com:80:,127.0.0.1",
"test.com", 80, TRUE, { "127.0.0.1", }
},
{ "test.com:80:127.0.0.1,",
"test.com", 80, TRUE, { "127.0.0.1", }
},
{ "test.com:0:127.0.0.1",
"test.com", 0, TRUE, { "127.0.0.1", }
},
{ "+test.com:80:127.0.0.1,",
"test.com", 80, FALSE, { "127.0.0.1", }
},
};
int i;
struct Curl_multi *multi = NULL;
struct Curl_easy *easy = NULL;

View file

@ -43,19 +43,6 @@ static CURLcode unit_setup(void)
return res;
}
struct testcase {
/* host:port:address[,address]... */
const char *optval;
/* lowercase host and port to retrieve the addresses from hostcache */
const char *host;
int port;
/* 0 to 9 addresses expected from hostcache */
const char *address[10];
};
/* CURLOPT_RESOLVE address parsing test - to test the following defect fix:
1) if there is already existing host:port pair in the DNS cache and
@ -88,18 +75,30 @@ Test:
expected result: cached address has zero timestamp and new address
*/
static const struct testcase tests[] = {
/* spaces aren't allowed, for now */
{ "test.com:80:127.0.0.1",
"test.com", 80, { "127.0.0.1", }
},
{ "test.com:80:127.0.0.2",
"test.com", 80, { "127.0.0.2", }
},
};
UNITTEST_START
{
struct testcase {
/* host:port:address[,address]... */
const char *optval;
/* lowercase host and port to retrieve the addresses from hostcache */
const char *host;
int port;
/* 0 to 9 addresses expected from hostcache */
const char *address[10];
};
static const struct testcase tests[] = {
/* spaces aren't allowed, for now */
{ "test.com:80:127.0.0.1",
"test.com", 80, { "127.0.0.1", }
},
{ "test.com:80:127.0.0.2",
"test.com", 80, { "127.0.0.2", }
},
};
int i;
struct Curl_multi *multi = NULL;
struct Curl_easy *easy = NULL;

View file

@ -27,9 +27,9 @@
#include <uint-hash.h>
#include <memdebug.h> /* LAST include file */
static struct uint_hash hash_static;
static struct uint_hash t1616_hash_static;
static void mydtor(unsigned int id, void *elem)
static void t1616_mydtor(unsigned int id, void *elem)
{
int *ptr = (int *)elem;
(void)id;
@ -38,13 +38,13 @@ static void mydtor(unsigned int id, void *elem)
static CURLcode unit_setup(void)
{
Curl_uint_hash_init(&hash_static, 15, mydtor);
Curl_uint_hash_init(&t1616_hash_static, 15, t1616_mydtor);
return CURLE_OK;
}
static void unit_stop(void)
{
Curl_uint_hash_destroy(&hash_static);
Curl_uint_hash_destroy(&t1616_hash_static);
}
UNITTEST_START
@ -59,27 +59,27 @@ UNITTEST_START
value = malloc(sizeof(int));
abort_unless(value != NULL, "Out of memory");
*value = 199;
ok = Curl_uint_hash_set(&hash_static, key, value);
ok = Curl_uint_hash_set(&t1616_hash_static, key, value);
if(!ok)
free(value);
abort_unless(ok, "insertion into hash failed");
v = Curl_uint_hash_get(&hash_static, key);
v = Curl_uint_hash_get(&t1616_hash_static, key);
abort_unless(v == value, "lookup present entry failed");
v = Curl_uint_hash_get(&hash_static, key2);
v = Curl_uint_hash_get(&t1616_hash_static, key2);
abort_unless(!v, "lookup missing entry failed");
Curl_uint_hash_clear(&hash_static);
Curl_uint_hash_clear(&t1616_hash_static);
/* 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(&hash_static, key2, value2);
ok = Curl_uint_hash_set(&t1616_hash_static, key2, value2);
if(!ok)
free(value2);
abort_unless(ok, "insertion into hash failed");
v = Curl_uint_hash_get(&hash_static, key2);
v = Curl_uint_hash_get(&t1616_hash_static, key2);
abort_unless(v == value2, "lookup present entry failed");
v = Curl_uint_hash_get(&hash_static, key);
v = Curl_uint_hash_get(&t1616_hash_static, key);
abort_unless(!v, "lookup missing entry failed");
UNITTEST_STOP

View file

@ -40,7 +40,7 @@ static void unit_stop(void)
curl_global_cleanup();
}
static void test_parse(
static void t1620_parse(
const char *input,
const char *exp_username,
const char *exp_password,
@ -106,20 +106,21 @@ UNITTEST_START
rc = Curl_init_do(empty, empty->conn);
fail_unless(rc == CURLE_OK, "Curl_init_do() failed");
test_parse("hostname", "hostname", NULL, NULL);
test_parse("user:password", "user", "password", NULL);
test_parse("user:password;options", "user", "password", "options");
test_parse("user:password;options;more", "user", "password", "options;more");
test_parse("", "", NULL, NULL);
test_parse(":", "", "", NULL);
test_parse(":;", "", "", NULL);
test_parse(":password", "", "password", NULL);
test_parse(":password;", "", "password", NULL);
test_parse(";options", "", NULL, "options");
test_parse("user;options", "user", NULL, "options");
test_parse("user:;options", "user", "", "options");
test_parse("user;options:password", "user", "password", "options");
test_parse("user;options:", "user", "", "options");
t1620_parse("hostname", "hostname", NULL, NULL);
t1620_parse("user:password", "user", "password", NULL);
t1620_parse("user:password;options", "user", "password", "options");
t1620_parse("user:password;options;more", "user", "password",
"options;more");
t1620_parse("", "", NULL, NULL);
t1620_parse(":", "", "", NULL);
t1620_parse(":;", "", "", NULL);
t1620_parse(":password", "", "password", NULL);
t1620_parse(":password;", "", "password", NULL);
t1620_parse(";options", "", NULL, "options");
t1620_parse("user;options", "user", NULL, "options");
t1620_parse("user:;options", "user", "", "options");
t1620_parse("user;options:password", "user", "password", "options");
t1620_parse("user;options:", "user", "", "options");
Curl_freeset(empty);
for(i = (enum dupstring)0; i < STRING_LAST; i++) {

View file

@ -32,7 +32,7 @@
* updated to still be valid.
*/
static struct Curl_easy *testdata;
static struct Curl_easy *t1652_easy;
static char input[4096];
static char output[4096];
@ -45,9 +45,8 @@ int debugf_cb(CURL *handle, curl_infotype type, char *buf, size_t size,
* 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)
int debugf_cb(CURL *handle, curl_infotype type, char *buf, size_t size,
void *userptr)
{
(void)handle;
(void)type;
@ -58,26 +57,24 @@ debugf_cb(CURL *handle, curl_infotype type, char *buf, size_t size,
return 0;
}
static CURLcode
unit_setup(void)
static CURLcode unit_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
testdata = curl_easy_init();
if(!testdata) {
t1652_easy = curl_easy_init();
if(!t1652_easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
curl_easy_setopt(testdata, CURLOPT_DEBUGFUNCTION, debugf_cb);
curl_easy_setopt(testdata, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(t1652_easy, CURLOPT_DEBUGFUNCTION, debugf_cb);
curl_easy_setopt(t1652_easy, CURLOPT_VERBOSE, 1L);
return res;
}
static void
unit_stop(void)
static void unit_stop(void)
{
curl_easy_cleanup(testdata);
curl_easy_cleanup(t1652_easy);
curl_global_cleanup();
}
@ -101,62 +98,65 @@ UNITTEST_START
#endif
#endif
/* Injecting a simple short string via a format */
curl_msnprintf(input, sizeof(input), "Simple Test");
Curl_infof(testdata, "%s", input);
fail_unless(verify(output, input) == 0, "Simple string test");
/* Injecting a simple short string via a format */
curl_msnprintf(input, sizeof(input), "Simple Test");
Curl_infof(t1652_easy, "%s", input);
fail_unless(verify(output, input) == 0, "Simple string test");
/* Injecting a few different variables with a format */
Curl_infof(testdata, "%s %u testing %lu", input, 42, 43L);
fail_unless(verify(output, "Simple Test 42 testing 43\n") == 0,
"Format string");
/* Injecting a few different variables with a format */
Curl_infof(t1652_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(testdata, "");
fail_unless(strlen(output) == 1, "Empty string");
Curl_infof(testdata, "%s", (char *)NULL);
fail_unless(verify(output, "(nil)") == 0, "Passing NULL as string");
/* Variations of empty strings */
Curl_infof(t1652_easy, "");
fail_unless(strlen(output) == 1, "Empty string");
Curl_infof(t1652_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
* get out of it is 2047, since we need a \0 at the end.
* Curl_infof() in addition adds a \n at the end, making the effective
* output 2046 characters.
* Any input that long or longer will truncated, ending in '...\n'.
*/
/* Note: libcurl's tracebuffer hold 2048 bytes, so the max strlen() we
* get out of it is 2047, since we need a \0 at the end.
* Curl_infof() in addition adds a \n at the end, making the effective
* output 2046 characters.
* Any input that long or longer will truncated, ending in '...\n'.
*/
/* A string just long enough to not be truncated */
memset(input, '\0', sizeof(input));
memset(input, 'A', 2045);
Curl_infof(testdata, "%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");
fail_unless(verify(output, input) == 0, "No truncation of infof input");
fail_unless(output[sizeof(output) - 1] == '\0',
"No truncation of infof input");
/* A string just long enough to not be truncated */
memset(input, '\0', sizeof(input));
memset(input, 'A', 2045);
Curl_infof(t1652_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");
fail_unless(verify(output, input) == 0, "No truncation of infof input");
fail_unless(output[sizeof(output) - 1] == '\0',
"No truncation of infof input");
/* Just over the limit without newline for truncation via '...' */
memset(input + 2045, 'A', 4);
Curl_infof(testdata, "%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', "Truncation of infof input 1");
/* Just over the limit without newline for truncation via '...' */
memset(input + 2045, 'A', 4);
Curl_infof(t1652_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',
"Truncation of infof input 1");
/* Just over the limit with newline for truncation via '...' */
memset(input + 2045, 'A', 4);
memset(input + 2045 + 4, '\n', 1);
Curl_infof(testdata, "%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', "Truncation of infof input 2");
/* 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);
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',
"Truncation of infof input 2");
/* Way over the limit for truncation via '...' */
memset(input, '\0', sizeof(input));
memset(input, 'A', sizeof(input) - 1);
Curl_infof(testdata, "%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', "Truncation of infof input 3");
/* Way over the limit for truncation via '...' */
memset(input, '\0', sizeof(input));
memset(input, 'A', sizeof(input) - 1);
Curl_infof(t1652_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',
"Truncation of infof input 3");
#if defined(CURL_GNUC_DIAG) && !defined(__clang__)
#pragma GCC diagnostic pop

View file

@ -30,14 +30,12 @@
static CURLU *u;
static CURLcode
unit_setup(void)
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void
unit_stop(void)
static void unit_stop(void)
{
curl_global_cleanup();
}

View file

@ -26,14 +26,12 @@
#include "urldata.h"
#include "altsvc.h"
static CURLcode
unit_setup(void)
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void
unit_stop(void)
static void unit_stop(void)
{
curl_global_cleanup();
}

View file

@ -26,14 +26,12 @@
#include "urldata.h"
#include "hsts.h"
static CURLcode
unit_setup(void)
static CURLcode unit_setup(void)
{
return CURLE_OK;
}
static void
unit_stop(void)
static void unit_stop(void)
{
curl_global_cleanup();
}

View file

@ -48,7 +48,7 @@ static void unit_stop(void)
curl_global_cleanup();
}
static void test_parse(
static void t1663_parse(
const char *input_data,
const char *exp_dev,
const char *exp_iface,
@ -81,17 +81,17 @@ static void test_parse(
UNITTEST_START
{
test_parse("dev", "dev", NULL, NULL, CURLE_OK);
test_parse("if!eth0", NULL, "eth0", NULL, CURLE_OK);
test_parse("host!myname", NULL, NULL, "myname", CURLE_OK);
test_parse("ifhost!eth0!myname", NULL, "eth0", "myname", CURLE_OK);
test_parse("", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
test_parse("!", "!", NULL, NULL, CURLE_OK);
test_parse("if!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
test_parse("if!eth0!blubb", NULL, "eth0!blubb", NULL, CURLE_OK);
test_parse("host!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
test_parse("ifhost!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
test_parse("ifhost!eth0", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
test_parse("ifhost!eth0!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
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);
t1663_parse("ifhost!eth0!myname", NULL, "eth0", "myname", CURLE_OK);
t1663_parse("", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
t1663_parse("!", "!", NULL, NULL, CURLE_OK);
t1663_parse("if!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
t1663_parse("if!eth0!blubb", NULL, "eth0!blubb", NULL, CURLE_OK);
t1663_parse("host!", NULL, NULL, NULL, CURLE_BAD_FUNCTION_ARGUMENT);
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_STOP

View file

@ -48,26 +48,26 @@
#include "curl_trc.h"
#include "memdebug.h"
static CURL *easy;
static CURL *t2600_easy;
static CURLcode unit_setup(void)
{
CURLcode res = CURLE_OK;
global_init(CURL_GLOBAL_ALL);
easy = curl_easy_init();
if(!easy) {
t2600_easy = curl_easy_init();
if(!t2600_easy) {
curl_global_cleanup();
return CURLE_OUT_OF_MEMORY;
}
curl_global_trace("all");
curl_easy_setopt(easy, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(t2600_easy, CURLOPT_VERBOSE, 1L);
return res;
}
static void unit_stop(void)
{
curl_easy_cleanup(easy);
curl_easy_cleanup(t2600_easy);
curl_global_cleanup();
}
@ -312,23 +312,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(easy, CURLOPT_RESOLVE, list);
curl_easy_setopt(easy, CURLOPT_IPRESOLVE, (long)tc->ip_version);
curl_easy_setopt(easy, CURLOPT_CONNECTTIMEOUT_MS,
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,
(long)tc->connect_timeout_ms);
curl_easy_setopt(easy, CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS,
curl_easy_setopt(t2600_easy, CURLOPT_HAPPY_EYEBALLS_TIMEOUT_MS,
(long)tc->he_timeout_ms);
curl_easy_setopt(easy, CURLOPT_URL, tc->url);
curl_easy_setopt(t2600_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(easy);
tr.result = curl_easy_perform(t2600_easy);
tr.ended = curlx_now();
curl_easy_setopt(easy, CURLOPT_RESOLVE, NULL);
curl_easy_setopt(t2600_easy, CURLOPT_RESOLVE, NULL);
curl_slist_free_all(list);
list = NULL;
current_tc = NULL;

View file

@ -42,9 +42,8 @@ static CURLcode unit_setup(void)
return CURLE_OK;
}
static CURLcode unit_stop(void)
static void unit_stop(void)
{
return CURLE_OK;
}
#if defined(CURL_GNUC_DIAG) || defined(__clang__)