mirror of
https://github.com/curl/curl.git
synced 2026-08-26 06:33:32 +03:00
tests: convert unit test 1396 and 1398 into libtests
They were previously unit tests but used only public library functions. Closes #22471
This commit is contained in:
parent
b3cd319655
commit
a2b178d378
6 changed files with 11 additions and 12 deletions
|
|
@ -33,7 +33,7 @@ TESTS_C = \
|
|||
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 \
|
||||
unit1395.c unit1397.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 \
|
||||
|
|
|
|||
|
|
@ -1,117 +0,0 @@
|
|||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "unitcheck.h"
|
||||
|
||||
static CURLcode t1396_setup(void)
|
||||
{
|
||||
CURLcode result = CURLE_OK;
|
||||
global_init(CURL_GLOBAL_ALL);
|
||||
return result;
|
||||
}
|
||||
|
||||
static void t1396_stop(CURL *easy)
|
||||
{
|
||||
if(easy)
|
||||
curl_easy_cleanup(easy);
|
||||
curl_global_cleanup();
|
||||
}
|
||||
|
||||
static CURLcode test_unit1396(const char *arg)
|
||||
{
|
||||
CURL *easy;
|
||||
|
||||
UNITTEST_BEGIN(t1396_setup())
|
||||
|
||||
struct test {
|
||||
const char *in;
|
||||
int inlen;
|
||||
const char *out;
|
||||
int outlen;
|
||||
};
|
||||
|
||||
/* unescape, this => that */
|
||||
static const struct test list1[] = {
|
||||
{ "%61", 3, "a", 1 },
|
||||
{ "%61a", 4, "aa", 2 },
|
||||
{ "%61b", 4, "ab", 2 },
|
||||
{ "%6 1", 4, "%6 1", 4 },
|
||||
{ "%61", 1, "%", 1 },
|
||||
{ "%61", 2, "%6", 2 },
|
||||
{ "%6%a", 4, "%6%a", 4 },
|
||||
{ "%6a", 0, "j", 1 },
|
||||
{ "%FF", 0, "\xff", 1 },
|
||||
{ "%FF%00%ff", 9, "\xff\x00\xff", 3 },
|
||||
{ "%-2", 0, "%-2", 3 },
|
||||
{ "%FG", 0, "%FG", 3 },
|
||||
{ NULL, 0, NULL, 0 } /* end of list marker */
|
||||
};
|
||||
/* escape, this => that */
|
||||
static const struct test list2[] = {
|
||||
{ "a", 1, "a", 1 },
|
||||
{ "/", 1, "%2F", 3 },
|
||||
{ "a=b", 3, "a%3Db", 5 },
|
||||
{ "a=b", 0, "a%3Db", 5 },
|
||||
{ "a=b", 1, "a", 1 },
|
||||
{ "a=b", 2, "a%3D", 4 },
|
||||
{ "1/./0", 5, "1%2F.%2F0", 9 },
|
||||
{ "-._~!#%&", 0, "-._~%21%23%25%26", 16 },
|
||||
{ "a", 2, "a%00", 4 },
|
||||
{ "a\xff\x01g", 4, "a%FF%01g", 8 },
|
||||
{ NULL, 0, NULL, 0 } /* end of list marker */
|
||||
};
|
||||
int i;
|
||||
|
||||
easy = curl_easy_init();
|
||||
abort_unless(easy, "returned NULL!");
|
||||
for(i = 0; list1[i].in; i++) {
|
||||
int outlen;
|
||||
char *out = curl_easy_unescape(easy, list1[i].in, list1[i].inlen, &outlen);
|
||||
|
||||
abort_unless(out, "returned NULL!");
|
||||
fail_unless(outlen == list1[i].outlen, "wrong output length returned");
|
||||
fail_unless(!memcmp(out, list1[i].out, list1[i].outlen),
|
||||
"bad output data returned");
|
||||
|
||||
curl_mprintf("curl_easy_unescape test %d DONE\n", i);
|
||||
|
||||
curl_free(out);
|
||||
}
|
||||
|
||||
for(i = 0; list2[i].in; i++) {
|
||||
int outlen;
|
||||
char *out = curl_easy_escape(easy, list2[i].in, list2[i].inlen);
|
||||
abort_unless(out, "returned NULL!");
|
||||
|
||||
outlen = (int)strlen(out);
|
||||
fail_unless(outlen == list2[i].outlen, "wrong output length returned");
|
||||
fail_unless(!memcmp(out, list2[i].out, list2[i].outlen),
|
||||
"bad output data returned");
|
||||
|
||||
curl_mprintf("curl_easy_escape test %d DONE (%s)\n", i, out);
|
||||
|
||||
curl_free(out);
|
||||
}
|
||||
|
||||
UNITTEST_END(t1396_stop(easy))
|
||||
}
|
||||
|
|
@ -1,225 +0,0 @@
|
|||
/***************************************************************************
|
||||
* _ _ ____ _
|
||||
* Project ___| | | | _ \| |
|
||||
* / __| | | | |_) | |
|
||||
* | (__| |_| | _ <| |___
|
||||
* \___|\___/|_| \_\_____|
|
||||
*
|
||||
* Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
|
||||
*
|
||||
* This software is licensed as described in the file COPYING, which
|
||||
* you should have received as part of this distribution. The terms
|
||||
* are also available at https://curl.se/docs/copyright.html.
|
||||
*
|
||||
* You may opt to use, copy, modify, merge, publish, distribute and/or sell
|
||||
* copies of the Software, and permit persons to whom the Software is
|
||||
* furnished to do so, under the terms of the COPYING file.
|
||||
*
|
||||
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
||||
* KIND, either express or implied.
|
||||
*
|
||||
* SPDX-License-Identifier: curl
|
||||
*
|
||||
***************************************************************************/
|
||||
#include "unitcheck.h"
|
||||
|
||||
#ifdef CURL_HAVE_DIAG
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wformat"
|
||||
#endif
|
||||
|
||||
static CURLcode test_unit1398(const char *arg)
|
||||
{
|
||||
UNITTEST_BEGIN_SIMPLE
|
||||
|
||||
int rc;
|
||||
char buf[3] = { 'b', 'u', 'g' };
|
||||
static const char str[] = "bug";
|
||||
int width = 3;
|
||||
char output[130];
|
||||
|
||||
/* #define curl_msnprintf snprintf */
|
||||
|
||||
/* negative precision is treated as if omitted */
|
||||
rc = curl_msnprintf(output, sizeof(output), "%.*s", -1, str);
|
||||
fail_unless(rc == 3, "return code should be 3");
|
||||
fail_unless(!strcmp(output, "bug"), "wrong output");
|
||||
|
||||
rc = curl_msnprintf(output, sizeof(output), "%.*s", -1, "0123456789");
|
||||
fail_unless(rc == 10, "return code should be 10");
|
||||
fail_unless(!strcmp(output, "0123456789"), "wrong output");
|
||||
|
||||
rc = curl_msnprintf(output, sizeof(output), "%.*s", 0, "0123456789");
|
||||
fail_unless(rc == 0, "return code should be 0");
|
||||
fail_unless(!strcmp(output, ""), "wrong output");
|
||||
|
||||
rc = curl_msnprintf(output, sizeof(output), "%.*s", -2, str);
|
||||
fail_unless(rc == 3, "return code should be 3");
|
||||
fail_unless(!strcmp(output, "bug"), "wrong output");
|
||||
|
||||
rc = curl_msnprintf(output, sizeof(output), "%.*d", -3, 10000);
|
||||
fail_unless(rc == 5, "return code should be 5");
|
||||
fail_unless(!strcmp(output, "10000"), "wrong output");
|
||||
|
||||
rc = curl_msnprintf(output, sizeof(output), "%.*d", 0, 1234567);
|
||||
fail_unless(rc == 7, "return code should be 0");
|
||||
fail_unless(!strcmp(output, "1234567"), "wrong output");
|
||||
|
||||
/* 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");
|
||||
|
||||
#if defined(__clang__) && \
|
||||
(__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1))
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wformat-non-iso"
|
||||
#endif
|
||||
/* double precision */
|
||||
rc = curl_msnprintf(output, 24, "%2$.*1$.99d", 3, 5678);
|
||||
fail_unless(rc == 0, "return code should be 0");
|
||||
#if defined(__clang__) && \
|
||||
(__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 1))
|
||||
#pragma clang diagnostic pop
|
||||
#endif
|
||||
|
||||
/* 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
|
||||
}
|
||||
|
||||
#ifdef CURL_HAVE_DIAG
|
||||
#pragma GCC diagnostic pop
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue