tests: rename more CURLcode variables to result

For consistency.

Also:
- one remaining in `src/tool_writeout.c`.
- replace casting an `int` to `CURLcode`.
- lib758: rename `CURLMcode` `result` to `mresult`.
- move literals to the right side of if expressions.

Follow-up to d0dc6e2ec0 #20426
Follow-up to 56f600ec23

Closes #20432
This commit is contained in:
Viktor Szakats 2026-01-25 18:12:40 +01:00
parent 26c39d8df1
commit 2da1bbca96
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
33 changed files with 307 additions and 303 deletions

View file

@ -33,13 +33,13 @@ static size_t write_tse_cb(char *ptr, size_t size, size_t nmemb, void *opaque)
(void)ptr;
if(!tse_found_tls_session) {
struct curl_tlssessioninfo *tlssession;
CURLcode rc;
CURLcode result;
rc = curl_easy_getinfo(curl, CURLINFO_TLS_SSL_PTR, &tlssession);
if(rc) {
result = curl_easy_getinfo(curl, CURLINFO_TLS_SSL_PTR, &tlssession);
if(result) {
curl_mfprintf(stderr, "curl_easy_getinfo(CURLINFO_TLS_SSL_PTR) "
"failed: %s\n", curl_easy_strerror(rc));
return rc;
"failed: %s\n", curl_easy_strerror(result));
return result;
}
if(tlssession->backend == CURLSSLBACKEND_NONE) {
curl_mfprintf(stderr, "curl_easy_getinfo(CURLINFO_TLS_SSL_PTR) "

View file

@ -74,7 +74,7 @@ static CURLcode test_ws_data_m2_echo(const char *url,
size_t plen_max)
{
CURL *curl = NULL;
CURLcode r = CURLE_OK;
CURLcode result = CURLE_OK;
const struct curl_ws_frame *frame;
size_t len;
char *send_buf = NULL, *recv_buf = NULL;
@ -84,7 +84,7 @@ static CURLcode test_ws_data_m2_echo(const char *url,
send_buf = curlx_calloc(1, plen_max + 1);
recv_buf = curlx_calloc(1, plen_max + 1);
if(!send_buf || !recv_buf) {
r = CURLE_OUT_OF_MEMORY;
result = CURLE_OUT_OF_MEMORY;
goto out;
}
for(i = 0; i < plen_max; ++i) {
@ -93,7 +93,7 @@ static CURLcode test_ws_data_m2_echo(const char *url,
curl = curl_easy_init();
if(!curl) {
r = CURLE_OUT_OF_MEMORY;
result = CURLE_OUT_OF_MEMORY;
goto out;
}
@ -103,9 +103,9 @@ static CURLcode test_ws_data_m2_echo(const char *url,
curl_easy_setopt(curl, CURLOPT_USERAGENT, "ws-data");
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_CONNECT_ONLY, 2L); /* websocket style */
r = curl_easy_perform(curl);
curl_mfprintf(stderr, "curl_easy_perform() returned %u\n", r);
if(r != CURLE_OK)
result = curl_easy_perform(curl);
curl_mfprintf(stderr, "curl_easy_perform() returned %u\n", result);
if(result != CURLE_OK)
goto out;
for(len = plen_min; len <= plen_max; ++len) {
@ -116,12 +116,12 @@ static CURLcode test_ws_data_m2_echo(const char *url,
while(slen || rlen || scount || rcount) {
sblock = rblock = 1;
if(slen) {
r = curl_ws_send(curl, sbuf, slen, &nwritten, 0, CURLWS_BINARY);
sblock = (r == CURLE_AGAIN);
if(!r || (r == CURLE_AGAIN)) {
result = curl_ws_send(curl, sbuf, slen, &nwritten, 0, CURLWS_BINARY);
sblock = (result == CURLE_AGAIN);
if(!result || (result == CURLE_AGAIN)) {
curl_mfprintf(stderr, "curl_ws_send(len=%zu) -> %d, "
"%zu (%" CURL_FORMAT_CURL_OFF_T "/%zu)\n",
slen, r, nwritten, (curl_off_t)(len - slen), len);
slen, result, nwritten, (curl_off_t)(len - slen), len);
sbuf += nwritten;
slen -= nwritten;
}
@ -136,15 +136,15 @@ static CURLcode test_ws_data_m2_echo(const char *url,
if(rlen) {
size_t max_recv = (64 * 1024);
r = curl_ws_recv(curl, rbuf, (rlen > max_recv) ? max_recv : rlen,
&nread, &frame);
if(!r || (r == CURLE_AGAIN)) {
rblock = (r == CURLE_AGAIN);
result = curl_ws_recv(curl, rbuf, (rlen > max_recv) ? max_recv : rlen,
&nread, &frame);
if(!result || (result == CURLE_AGAIN)) {
rblock = (result == CURLE_AGAIN);
curl_mfprintf(stderr, "curl_ws_recv(len=%zu) -> %d, %zu (%ld/%zu) "
"\n", rlen, r, nread, (long)(len - rlen), len);
if(!r) {
r = test_ws_data_m2_check_recv(frame, len - rlen, nread, len);
if(r)
"\n", rlen, result, nread, (long)(len - rlen), len);
if(!result) {
result = test_ws_data_m2_check_recv(frame, len - rlen, nread, len);
if(result)
goto out;
}
rbuf += nread;
@ -171,20 +171,20 @@ static CURLcode test_ws_data_m2_echo(const char *url,
(const unsigned char *)send_buf, len, FALSE);
debug_dump("", "received:", stderr,
(const unsigned char *)recv_buf, len, FALSE);
r = CURLE_RECV_ERROR;
result = CURLE_RECV_ERROR;
goto out;
}
}
out:
if(curl) {
if(!r)
if(!result)
ws_close(curl);
curl_easy_cleanup(curl);
}
curlx_free(send_buf);
curlx_free(recv_buf);
return r;
return result;
}
struct test_ws_m1_ctx {

View file

@ -160,7 +160,7 @@ static CURLcode test_lib1156(const char *URL)
curl_global_cleanup();
curl_mprintf("%d\n", status);
return (CURLcode)status;
return status ? TEST_ERR_FAILURE : CURLE_OK;
test_cleanup:

View file

@ -63,7 +63,7 @@ static CURLcode test_lib1509(const char *URL)
easy_setopt(curl, CURLOPT_HTTPPROXYTUNNEL, 1L);
code = curl_easy_perform(curl);
if(CURLE_OK != code) {
if(code != CURLE_OK) {
curl_mfprintf(stderr, "%s:%d curl_easy_perform() failed, "
"with code %d (%s)\n",
__FILE__, __LINE__, code, curl_easy_strerror(code));
@ -72,7 +72,7 @@ static CURLcode test_lib1509(const char *URL)
}
code = curl_easy_getinfo(curl, CURLINFO_HEADER_SIZE, &headerSize);
if(CURLE_OK != code) {
if(code != CURLE_OK) {
curl_mfprintf(stderr, "%s:%d curl_easy_getinfo() failed, "
"with code %d (%s)\n",
__FILE__, __LINE__, code, curl_easy_strerror(code));

View file

@ -28,7 +28,7 @@
struct pair {
const char *in;
CURLcode *exp;
CURLcode *result_exp;
};
static CURLcode test_lib1597(const char *URL)
@ -95,7 +95,7 @@ static CURLcode test_lib1597(const char *URL)
/* Run the tests. */
for(i = 0; prots[i].in; i++) {
result = curl_easy_setopt(curl, CURLOPT_PROTOCOLS_STR, prots[i].in);
if(result != *prots[i].exp) {
if(result != *prots[i].result_exp) {
curl_mprintf("unexpectedly '%s' returned %d\n", prots[i].in, result);
break;
}

View file

@ -35,16 +35,16 @@ static CURLcode test_lib1939(const char *URL)
if(multi) {
curl = curl_easy_init();
if(curl) {
CURLcode c;
CURLcode result;
CURLMcode mresult;
/* Crash only happens when using HTTPS */
c = curl_easy_setopt(curl, CURLOPT_URL, URL);
if(!c)
result = curl_easy_setopt(curl, CURLOPT_URL, URL);
if(!result)
/* Any old HTTP tunneling proxy will do here */
c = curl_easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
result = curl_easy_setopt(curl, CURLOPT_PROXY, libtest_arg2);
if(!c) {
if(!result) {
/* We are going to drive the transfer using multi interface here,
because we want to stop during the middle. */

View file

@ -35,19 +35,19 @@ static size_t callback(char *ptr, size_t size, size_t nmemb, void *data)
ssize_t idx = ((CURL **)data) - ntlm_curls;
curl_socket_t sock;
long longdata;
CURLcode code;
CURLcode result;
const size_t failure = (size && nmemb) ? 0 : 1;
(void)ptr;
ntlm_counter[idx] += (int)(size * nmemb);
/* Get socket being used for this easy handle, otherwise CURL_SOCKET_BAD */
code = curl_easy_getinfo(ntlm_curls[idx], CURLINFO_LASTSOCKET, &longdata);
result = curl_easy_getinfo(ntlm_curls[idx], CURLINFO_LASTSOCKET, &longdata);
if(CURLE_OK != code) {
if(result != CURLE_OK) {
curl_mfprintf(stderr, "%s:%d curl_easy_getinfo() failed, "
"with code %d (%s)\n",
__FILE__, __LINE__, code, curl_easy_strerror(code));
__FILE__, __LINE__, result, curl_easy_strerror(result));
ntlmcb_res = TEST_ERR_MAJOR_BAD;
return failure;
}

View file

@ -42,7 +42,7 @@ static CURLcode test_lib3026(const char *URL)
CURLcode results[NUM_THREADS];
HANDLE thread_handles[NUM_THREADS];
unsigned tid_count = NUM_THREADS, i;
CURLcode test_failure = CURLE_OK;
CURLcode result = CURLE_OK;
curl_version_info_data *ver;
(void)URL;
@ -63,7 +63,7 @@ static CURLcode test_lib3026(const char *URL)
"GetLastError 0x%08lx\n",
__FILE__, __LINE__, GetLastError());
tid_count = i;
test_failure = TEST_ERR_MAJOR_BAD;
result = TEST_ERR_MAJOR_BAD;
goto cleanup;
}
thread_handles[i] = th;
@ -77,11 +77,11 @@ cleanup:
curl_mfprintf(stderr, "%s:%d thread[%u]: curl_global_init() failed,"
"with code %d (%s)\n", __FILE__, __LINE__,
i, results[i], curl_easy_strerror(results[i]));
test_failure = TEST_ERR_MAJOR_BAD;
result = TEST_ERR_MAJOR_BAD;
}
}
return test_failure;
return result;
}
#elif defined(HAVE_PTHREAD_H)
@ -103,7 +103,7 @@ static CURLcode test_lib3026(const char *URL)
CURLcode results[NUM_THREADS];
pthread_t tids[NUM_THREADS];
unsigned tid_count = NUM_THREADS, i;
CURLcode test_failure = CURLE_OK;
CURLcode result = CURLE_OK;
curl_version_info_data *ver;
(void)URL;
@ -123,7 +123,7 @@ static CURLcode test_lib3026(const char *URL)
curl_mfprintf(stderr, "%s:%d Could not create thread, errno %d\n",
__FILE__, __LINE__, res);
tid_count = i;
test_failure = TEST_ERR_MAJOR_BAD;
result = TEST_ERR_MAJOR_BAD;
goto cleanup;
}
}
@ -135,11 +135,11 @@ cleanup:
curl_mfprintf(stderr, "%s:%d thread[%u]: curl_global_init() failed,"
"with code %d (%s)\n", __FILE__, __LINE__,
i, results[i], curl_easy_strerror(results[i]));
test_failure = TEST_ERR_MAJOR_BAD;
result = TEST_ERR_MAJOR_BAD;
}
}
return test_failure;
return result;
}
#else /* without pthread or Windows, this test does not work */

View file

@ -25,7 +25,7 @@
static CURLcode test_lib3027(const char *URL)
{
CURLcode ret = CURLE_OK;
CURLcode result = CURLE_OK;
CURL *curl;
start_test_timing();
@ -35,18 +35,18 @@ static CURLcode test_lib3027(const char *URL)
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, URL);
curl_easy_setopt(curl, CURLOPT_FILETIME, 1L);
ret = curl_easy_perform(curl);
if(CURLE_OK == ret) {
result = curl_easy_perform(curl);
if(result == CURLE_OK) {
long filetime;
ret = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
result = curl_easy_getinfo(curl, CURLINFO_FILETIME, &filetime);
/* MTDM fails with 550, so filetime should be -1 */
if((CURLE_OK == ret) && (filetime != -1)) {
if((result == CURLE_OK) && (filetime != -1)) {
/* we just need to return something which is not CURLE_OK */
ret = CURLE_UNSUPPORTED_PROTOCOL;
result = CURLE_UNSUPPORTED_PROTOCOL;
}
}
curl_easy_cleanup(curl);
}
curl_global_cleanup();
return ret;
return result;
}

View file

@ -28,11 +28,11 @@
static CURLcode test_lib512(const char *URL)
{
CURLcode code;
CURLcode result;
int rc = 99;
code = curl_global_init(CURL_GLOBAL_ALL);
if(code == CURLE_OK) {
result = curl_global_init(CURL_GLOBAL_ALL);
if(result == CURLE_OK) {
CURL *curl = curl_easy_init();
if(curl) {
CURL *curl2;
@ -43,11 +43,11 @@ static CURLcode test_lib512(const char *URL)
curl2 = curl_easy_duphandle(curl);
if(curl2) {
code = curl_easy_setopt(curl2, CURLOPT_URL, URL);
if(code == CURLE_OK) {
result = curl_easy_setopt(curl2, CURLOPT_URL, URL);
if(result == CURLE_OK) {
code = curl_easy_perform(curl2);
if(code == CURLE_OK)
result = curl_easy_perform(curl2);
if(result == CURLE_OK)
rc = 0;
else
rc = 1;

View file

@ -389,28 +389,28 @@ test_cleanup:
static CURLcode test_lib530(const char *URL)
{
CURLcode rc;
CURLcode result;
/* rerun the same transfer multiple times and make it fail in different
callback calls */
rc = testone(URL, 0, 0); /* no callback fails */
if(rc)
curl_mfprintf(stderr, "%s FAILED: %d\n", t530_tag(), rc);
result = testone(URL, 0, 0); /* no callback fails */
if(result)
curl_mfprintf(stderr, "%s FAILED: %d\n", t530_tag(), result);
rc = testone(URL, 1, 0); /* fail 1st call to timer callback */
if(!rc)
curl_mfprintf(stderr, "%s FAILED: %d\n", t530_tag(), rc);
result = testone(URL, 1, 0); /* fail 1st call to timer callback */
if(!result)
curl_mfprintf(stderr, "%s FAILED: %d\n", t530_tag(), result);
rc = testone(URL, 2, 0); /* fail 2nd call to timer callback */
if(!rc)
curl_mfprintf(stderr, "%s FAILED: %d\n", t530_tag(), rc);
result = testone(URL, 2, 0); /* fail 2nd call to timer callback */
if(!result)
curl_mfprintf(stderr, "%s FAILED: %d\n", t530_tag(), result);
rc = testone(URL, 0, 1); /* fail 1st call to socket callback */
if(!rc)
curl_mfprintf(stderr, "%s FAILED: %d\n", t530_tag(), rc);
result = testone(URL, 0, 1); /* fail 1st call to socket callback */
if(!result)
curl_mfprintf(stderr, "%s FAILED: %d\n", t530_tag(), result);
rc = testone(URL, 0, 2); /* fail 2nd call to socket callback */
if(!rc)
curl_mfprintf(stderr, "%s FAILED: %d\n", t530_tag(), rc);
result = testone(URL, 0, 2); /* fail 2nd call to socket callback */
if(!result)
curl_mfprintf(stderr, "%s FAILED: %d\n", t530_tag(), result);
return CURLE_OK;
}

View file

@ -97,7 +97,7 @@ static void t586_test_unlock(CURL *curl, curl_lock_data data, void *useptr)
/* the dummy thread function */
static void *t586_test_fire(void *ptr)
{
CURLcode code;
CURLcode result;
struct t586_Tdata *tdata = (struct t586_Tdata *)ptr;
CURL *curl;
@ -114,11 +114,11 @@ static void *t586_test_fire(void *ptr)
curl_easy_setopt(curl, CURLOPT_SHARE, tdata->share);
curl_mprintf("PERFORM\n");
code = curl_easy_perform(curl);
if(code != CURLE_OK) {
result = curl_easy_perform(curl);
if(result != CURLE_OK) {
int i = 0;
curl_mfprintf(stderr, "perform URL '%s' repeat %d failed, curlcode %d\n",
tdata->url, i, code);
tdata->url, i, result);
}
curl_mprintf("CLEANUP\n");

View file

@ -224,19 +224,19 @@ static CURLcode t643_cyclic_add(void)
CURL *curl = curl_easy_init();
curl_mime *mime = curl_mime_init(curl);
curl_mimepart *part = curl_mime_addpart(mime);
CURLcode a1 = curl_mime_subparts(part, mime);
CURLcode result = curl_mime_subparts(part, mime);
if(a1 == CURLE_BAD_FUNCTION_ARGUMENT) {
if(result == CURLE_BAD_FUNCTION_ARGUMENT) {
curl_mime *submime = curl_mime_init(curl);
curl_mimepart *subpart = curl_mime_addpart(submime);
curl_mime_subparts(part, submime);
a1 = curl_mime_subparts(subpart, mime);
result = curl_mime_subparts(subpart, mime);
}
curl_mime_free(mime);
curl_easy_cleanup(curl);
if(a1 != CURLE_BAD_FUNCTION_ARGUMENT)
if(result != CURLE_BAD_FUNCTION_ARGUMENT)
/* that should have failed */
return TEST_ERR_FAILURE;

View file

@ -60,7 +60,7 @@ static int loadfile(const char *filename, void **filedata, size_t *filesize)
static CURLcode test_cert_blob(const char *url, const char *cafile)
{
CURLcode code = CURLE_OUT_OF_MEMORY;
CURLcode result = CURLE_OUT_OF_MEMORY;
CURL *curl;
struct curl_blob blob;
size_t certsize;
@ -84,11 +84,11 @@ static CURLcode test_cert_blob(const char *url, const char *cafile)
blob.flags = CURL_BLOB_COPY;
curl_easy_setopt(curl, CURLOPT_CAINFO_BLOB, &blob);
curlx_free(certdata);
code = curl_easy_perform(curl);
result = curl_easy_perform(curl);
}
curl_easy_cleanup(curl);
return code;
return result;
}
static CURLcode test_lib678(const char *URL)

View file

@ -307,15 +307,15 @@ static CURLMcode t758_checkFdSet(CURLM *multi, struct t758_Sockets *sockets,
const char *name)
{
int i;
CURLMcode result = CURLM_OK;
CURLMcode mresult = CURLM_OK;
for(i = 0; i < sockets->count; ++i) {
if(FD_ISSET(sockets->sockets[i], fdset)) {
result = t758_saction(multi, sockets->sockets[i], evBitmask, name);
if(result)
mresult = t758_saction(multi, sockets->sockets[i], evBitmask, name);
if(mresult)
break;
}
}
return result;
return mresult;
}
static CURLcode t758_one(const char *URL, int timer_fail_at,
@ -485,14 +485,14 @@ test_cleanup:
static CURLcode test_lib758(const char *URL)
{
CURLcode rc;
CURLcode result;
/* rerun the same transfer multiple times and make it fail in different
callback calls */
rc = t758_one(URL, 0, 0); /* no callback fails */
if(rc)
curl_mfprintf(stderr, "%s FAILED: %d\n", t758_tag(), rc);
result = t758_one(URL, 0, 0); /* no callback fails */
if(result)
curl_mfprintf(stderr, "%s FAILED: %d\n", t758_tag(), result);
return rc;
return result;
}
#else /* T578_ENABLED */