tests: make the unit test result type CURLcode

Before this patch, the result code was a mixture of `int` and
`CURLcode`.

Also adjust casts and fix a couple of minor issues found along the way.

Cherry-picked from #13489
Closes #13600
This commit is contained in:
Viktor Szakats 2024-05-11 21:36:05 +02:00
parent dad03dc593
commit 25cbc2f79a
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
221 changed files with 619 additions and 616 deletions

View file

@ -94,7 +94,7 @@
#define UNITTEST_START \
int test(char *arg) \
CURLcode test(char *arg) \
{ \
(void)arg; \
if(unit_setup()) { \
@ -107,5 +107,5 @@
unit_test_abort: \
unit_stop(); \
} \
return unitfail; \
return (CURLcode)unitfail; \
}

View file

@ -69,8 +69,8 @@ static void unit_stop(void)
struct timetest {
int now_s;
int now_us;
int timeout_ms;
int connecttimeout_ms;
unsigned int timeout_ms;
unsigned int connecttimeout_ms;
bool connecting;
timediff_t result;
const char *comment;

View file

@ -44,7 +44,8 @@ static size_t print_httppost_callback(void *arg, const char *buf, size_t len)
}
UNITTEST_START
int rc;
CURLFORMcode rc;
int res;
struct curl_httppost *post = NULL;
struct curl_httppost *last = NULL;
size_t total_size = 0;
@ -70,9 +71,9 @@ UNITTEST_START
fail_unless(rc == 0, "curl_formadd returned error");
rc = curl_formget(post, &total_size, print_httppost_callback);
res = curl_formget(post, &total_size, print_httppost_callback);
fail_unless(rc == 0, "curl_formget returned error");
fail_unless(res == 0, "curl_formget returned error");
fail_unless(total_size == 518, "curl_formget got wrong size back");
@ -89,8 +90,8 @@ UNITTEST_START
fail_unless(rc == 0, "curl_formadd returned error");
rc = curl_formget(post, &total_size, print_httppost_callback);
fail_unless(rc == 0, "curl_formget returned error");
res = curl_formget(post, &total_size, print_httppost_callback);
fail_unless(res == 0, "curl_formget returned error");
fail_unless(total_size == 899, "curl_formget got wrong size back");
curl_formfree(post);

View file

@ -31,7 +31,7 @@
#include "memdebug.h" /* LAST include file */
static struct Curl_hash hash_static;
static const int slots = 3;
static const size_t slots = 3;
static void mydtor(void *p)
{

View file

@ -42,7 +42,7 @@ static void unit_stop(void)
UNITTEST_START
{
int rc;
CURLcode rc;
struct Curl_easy *empty;
const char *hostname = "hostname";
enum dupstring i;

View file

@ -57,13 +57,13 @@ struct dohrequest {
/* output */
const char *packet;
size_t size;
int rc;
DOHcode rc;
};
static const struct dohrequest req[] = {
{"test.host.name", DNS_TYPE_A, DNS_Q1, sizeof(DNS_Q1)-1, 0 },
{"test.host.name", DNS_TYPE_AAAA, DNS_Q2, sizeof(DNS_Q2)-1, 0 },
{"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 }
@ -76,7 +76,7 @@ struct dohresp {
DNStype type;
/* output */
int rc;
DOHcode rc;
const char *out;
};
@ -161,8 +161,8 @@ UNITTEST_START
unsigned char *p;
for(i = 0; i < sizeof(req) / sizeof(req[0]); i++) {
int rc = doh_encode(req[i].name, req[i].type,
buffer, sizeof(buffer), &size);
DOHcode rc = doh_encode(req[i].name, req[i].type,
buffer, sizeof(buffer), &size);
if(rc != req[i].rc) {
fprintf(stderr, "req %zu: Expected return code %d got %d\n", i,
req[i].rc, rc);
@ -185,7 +185,7 @@ UNITTEST_START
for(i = 0; i < sizeof(resp) / sizeof(resp[0]); i++) {
struct dohentry d;
int rc;
DOHcode rc;
char *ptr;
size_t len;
int u;
@ -243,7 +243,7 @@ UNITTEST_START
/* pass all sizes into the decoder until full */
for(i = 0; i < sizeof(full49)-1; i++) {
struct dohentry d;
int rc;
DOHcode rc;
memset(&d, 0, sizeof(d));
rc = doh_decode((const unsigned char *)full49, i, DNS_TYPE_A, &d);
if(!rc) {
@ -256,7 +256,7 @@ UNITTEST_START
/* and try all pieces from the other end of the packet */
for(i = 1; i < sizeof(full49); i++) {
struct dohentry d;
int rc;
DOHcode rc;
memset(&d, 0, sizeof(d));
rc = doh_decode((const unsigned char *)&full49[i], sizeof(full49)-i-1,
DNS_TYPE_A, &d);
@ -268,7 +268,7 @@ UNITTEST_START
}
{
int rc;
DOHcode rc;
struct dohentry d;
struct dohaddr *a;
memset(&d, 0, sizeof(d));

View file

@ -41,7 +41,7 @@ unit_stop(void)
#if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_HSTS)
UNITTEST_START
{
return 0; /* nothing to do when HTTP or HSTS are disabled */
return CURLE_OK; /* nothing to do when HTTP or HSTS are disabled */
}
UNITTEST_STOP
#else

View file

@ -104,7 +104,7 @@ UNITTEST_START
}
free((void *)list[0].cp);
return error;
return error == 0 ? CURLE_OK : TEST_ERR_FAILURE;
}
#endif

View file

@ -88,7 +88,7 @@ UNITTEST_START
for(i = 0; i < NUMTESTS; i++) {
FILE *fp;
struct dynbuf buf;
int len = 4096;
size_t len = 4096;
char *line;
Curl_dyn_init(&buf, len);
@ -169,7 +169,7 @@ UNITTEST_START
fclose(fp);
fprintf(stderr, "OK\n");
}
return rc;
return (CURLcode)rc;
UNITTEST_STOP
#ifdef __GNUC__