curl/tests/unit/unit3214.c
Viktor Szakats 4deea9396b
tests: stop overriding system printf symbols
To make the source code match the functions called at runtime.
And to avoid the preprocessor trick that may introduces build issues.

Before this patch, libtests, tunits and units were calling a mixture
of curl and system printf calls, then transformed them all to curl
printf calls by including `curl_printf.h`.

Changes made:
- tests: stop including `curl_printf.h`.
- libtest: switch a couple of outlier system printf calls to curl
  printf.
- unit: use more curl printf to avoid casts and show whole values.
- unit: switch remaining calls to curl printf explicitly.
- tunit: switch to call curl printf explicitly.
- libtest, tunit, unit: ban system printf.
- unit1307, unit1607, unit1609, unit1652, unit1655, unit3214: bump
  types/masks to avoid casts.

After this patch:
- libtests, tunits, units: use exclusively curl printf.
  (as before, but explicitly, without relying on redefinitions.)
- servers: is unchanged (it can only use system printf).

Closes #18814
2025-10-04 00:51:06 +02:00

86 lines
3.4 KiB
C

/***************************************************************************
* _ _ ____ _
* 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"
#include "urldata.h"
static void checksize(const char *name, size_t size, size_t allowed)
{
if(size > allowed) {
curl_mfprintf(stderr, "BAD: struct %s is %zu bytes, "
"allowed to be %zu: %zu bytes too big\n",
name, size, allowed, size - allowed);
unitfail++;
}
else {
curl_mprintf("FINE: struct %s is %zu bytes, "
"allowed %zu (margin: %zu bytes)\n",
name, size, allowed, allowed - size);
}
}
/* the maximum sizes we allow specific structs to grow to */
#define MAX_CURL_EASY 5800
#define MAX_CONNECTDATA 1300
#define MAX_CURL_MULTI 750
#define MAX_CURL_HTTPPOST 112
#define MAX_CURL_SLIST 16
#define MAX_CURL_KHKEY 24
#define MAX_CURL_HSTSENTRY 40
#define MAX_CURL_INDEX 16
#define MAX_CURL_MIME 96
#define MAX_CURL_MIMEPART 440
#define MAX_CURL_CERTINFO 16
#define MAX_CURL_TLSSESSIONINFO 16
#define MAX_CURL_BLOB 24
#define MAX_CURLMSG 24
#define MAX_CURL_HEADER 48
static CURLcode test_unit3214(const char *arg)
{
UNITTEST_BEGIN_SIMPLE
checksize("Curl_easy", sizeof(struct Curl_easy), MAX_CURL_EASY);
checksize("connectdata", sizeof(struct connectdata), MAX_CONNECTDATA);
checksize("Curl_multi", sizeof(struct Curl_multi), MAX_CURL_MULTI);
/* public structs MUST NOT change (unless controlled), but exact sizes
depend on architecture */
checksize("curl_httppost", sizeof(struct curl_httppost), MAX_CURL_HTTPPOST);
checksize("curl_slist", sizeof(struct curl_slist), MAX_CURL_SLIST);
checksize("curl_khkey", sizeof(struct curl_khkey), MAX_CURL_KHKEY);
checksize("curl_hstsentry", sizeof(struct curl_hstsentry),
MAX_CURL_HSTSENTRY);
checksize("curl_index", sizeof(struct curl_index), MAX_CURL_INDEX);
checksize("curl_mime", sizeof(struct curl_mime), MAX_CURL_MIME);
checksize("curl_mimepart", sizeof(struct curl_mimepart), MAX_CURL_MIMEPART);
checksize("curl_certinfo", sizeof(struct curl_certinfo), MAX_CURL_CERTINFO);
checksize("curl_tlssessioninfo", sizeof(struct curl_tlssessioninfo),
MAX_CURL_TLSSESSIONINFO);
checksize("curl_blob", sizeof(struct curl_blob), MAX_CURL_BLOB);
checksize("CURLMsg", sizeof(struct CURLMsg), MAX_CURLMSG);
checksize("curl_header", sizeof(struct curl_header), MAX_CURL_HEADER);
UNITTEST_END_SIMPLE
}