mirror of
https://github.com/curl/curl.git
synced 2026-08-25 00:13:34 +03:00
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:
parent
1cdac95e2e
commit
2c27a67daa
386 changed files with 2996 additions and 4164 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue