commit a700c92d1a6666e7a2b948e3487fac4a3d72536b
parent 0f5c32a4bb7f2a627926825bf28697e08afef1b5
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Thu, 5 Sep 2024 18:04:01 +0200
Fixed tests: compiler warnings, libcurl compatibility
Diffstat:
7 files changed, 78 insertions(+), 35 deletions(-)
diff --git a/src/tests/basic/test_basic_checks.c b/src/tests/basic/test_basic_checks.c
@@ -26,7 +26,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <microhttpd2.h>
+#include "microhttpd2.h"
/* Helper macros */
diff --git a/src/tests/client_server/libtest.c b/src/tests/client_server/libtest.c
@@ -28,7 +28,6 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
-#include "microhttpd2.h"
#include "libtest.h"
/**
@@ -279,7 +278,7 @@ run_single_client (void *cls)
const char *err;
fprintf (stderr,
- "Client %u started in phase `%s'\n",
+ "Client %u started in phase '%s'\n",
cc->pc.client_id,
cc->phase->label);
err = cc->phase->client_cb (cc->phase->client_cb_cls,
@@ -287,7 +286,7 @@ run_single_client (void *cls)
if (NULL != err)
{
fprintf (stderr,
- "Client %u failed in phase `%s': %s\n",
+ "Client %u failed in phase '%s': %s\n",
cc->pc.client_id,
cc->phase->label,
err);
@@ -305,7 +304,7 @@ run_single_client (void *cls)
"s",
1));
fprintf (stderr,
- "Client %u finished in phase `%s'\n",
+ "Client %u finished in phase '%s'\n",
cc->pc.client_id,
cc->phase->label);
return NULL;
@@ -357,7 +356,7 @@ run_client_phase (const struct MHDT_Phase *phase,
make_pipe (p);
fprintf (stderr,
- "Starting phase `%s'\n",
+ "Starting phase '%s'\n",
phase->label);
for (i = 0; i<num_clients; i++)
{
@@ -404,7 +403,7 @@ run_client_phase (const struct MHDT_Phase *phase,
if (0 != clients_left)
{
fprintf (stderr,
- "Timeout (%u ms) in phase `%s': %u clients still running\n",
+ "Timeout (%u ms) in phase '%s': %u clients still running\n",
phase->timeout_ms,
phase->label,
clients_left);
@@ -424,7 +423,7 @@ cleanup:
test_check (0 == close (p[0]));
test_check (0 == close (p[1]));
fprintf (stderr,
- "Finished phase `%s' with %s\n",
+ "Finished phase '%s' with %s\n",
phase->label,
ret ? "success" : "FAILURE");
return ret;
@@ -447,7 +446,7 @@ server_phase_logic (void *cls)
for (i = 0; NULL != ctx->phase->label; i++)
{
fprintf (stderr,
- "Running server phase `%s'\n",
+ "Running server phase '%s'\n",
ctx->phase->label);
semaphore_down (&ctx->client_sem);
ctx->phase++;
@@ -569,7 +568,7 @@ MHDT_test (MHDT_ServerSetup ss_cb,
for (i = 0; NULL != phases[i].label; i++)
{
fprintf (stderr,
- "Running test phase `%s'\n",
+ "Running test phase '%s'\n",
phases[i].label);
if (! run_client_phase (&phases[i],
&pc))
diff --git a/src/tests/client_server/libtest.h b/src/tests/client_server/libtest.h
@@ -26,10 +26,14 @@
#ifndef LIBTEST_H
#define LIBTEST_H
+#include "mhd_sys_options.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <microhttpd2.h>
+#ifdef HAVE_STDBOOL_H
+# include <stdbool.h>
+#endif
+#include "microhttpd2.h"
/**
* Information about the current phase.
diff --git a/src/tests/client_server/libtest_convenience.c b/src/tests/client_server/libtest_convenience.c
@@ -28,7 +28,6 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
-#include "microhttpd2.h"
#include "libtest.h"
#include <curl/curl.h>
@@ -63,6 +62,9 @@ MHDT_server_run_minimal (void *cls,
fd_set r;
char c;
+ (void) cls; /* Unused */
+ (void) d; /* Unused */
+
FD_ZERO (&r);
FD_SET (finsig, &r);
while (1)
@@ -104,6 +106,9 @@ MHDT_server_run_blocking (void *cls,
fd_set r;
char c;
+ (void) cls; /* Unused */
+ (void) d; /* Unused */
+
FD_ZERO (&r);
FD_SET (finsig, &r);
while (1)
diff --git a/src/tests/client_server/libtest_convenience_client_request.c b/src/tests/client_server/libtest_convenience_client_request.c
@@ -28,10 +28,23 @@
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
-#include "microhttpd2.h"
#include "libtest.h"
#include <curl/curl.h>
+
+#ifndef CURL_VERSION_BITS
+# define CURL_VERSION_BITS(x,y,z) ((x) << 16 | (y) << 8 | (z))
+#endif
+#ifndef CURL_AT_LEAST_VERSION
+# define CURL_AT_LEAST_VERSION(x,y,z) \
+ (LIBCURL_VERSION_NUM >= CURL_VERSION_BITS (x, y, z))
+#endif
+
+#if CURL_AT_LEAST_VERSION (7,83,0)
+# define HAVE_LIBCRUL_NEW_HDR_API 1
+#endif
+
+
/**
* Closure for the write_cb().
*/
@@ -201,7 +214,7 @@ check_status (CURL *c,
"Failed to get HTTP status");
return false;
}
- if (status != expected_status)
+ if (((unsigned int) status) != expected_status)
{
fprintf (stderr,
"Expected HTTP status %u, got %ld\n",
@@ -329,6 +342,7 @@ const char *
MHDT_client_expect_header (void *cls,
const struct MHDT_PhaseContext *pc)
{
+#ifdef HAVE_LIBCRUL_NEW_HDR_API
const char *hdr = cls;
size_t hlen = strlen (hdr) + 1;
char key[hlen];
@@ -381,6 +395,10 @@ MHDT_client_expect_header (void *cls,
}
curl_easy_cleanup (c);
return NULL;
+#else /* ! HAVE_LIBCRUL_NEW_HDR_API */
+ (void) cls; (void) pc;
+ return NULL;
+#endif /* ! HAVE_LIBCRUL_NEW_HDR_API */
}
diff --git a/src/tests/client_server/libtest_convenience_server_reply.c b/src/tests/client_server/libtest_convenience_server_reply.c
@@ -1,6 +1,7 @@
/*
This file is part of GNU libmicrohttpd
Copyright (C) 2024 Christian Grothoff
+ Copyright (C) 2024 Evgeny Grin (Karlson2k)
GNU libmicrohttpd is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
@@ -30,7 +31,6 @@
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
-#include "microhttpd2.h"
#include "libtest.h"
#include <curl/curl.h>
@@ -45,6 +45,8 @@ MHDT_server_reply_text (
{
const char *text = cls;
+ (void) path; (void) method; (void) upload_size; /* Unused */
+
return MHD_action_from_response (
request,
MHD_response_from_buffer_static (MHD_HTTP_STATUS_OK,
@@ -66,19 +68,21 @@ MHDT_server_reply_file (
char fn[] = "/tmp/mhd-test-XXXXXX";
int fd;
+ (void) path; (void) method; (void) upload_size; /* Unused */
+
fd = mkstemp (fn);
if (-1 == fd)
{
fprintf (stderr,
"Failed to mkstemp() temporary file\n");
- return NULL;
+ return MHD_action_abort_request (request);
}
- if (tlen != write (fd, text, tlen))
+ if (((ssize_t) tlen) != write (fd, text, tlen))
{
fprintf (stderr,
"Failed to write() temporary file in one go: %s\n",
strerror (errno));
- return NULL;
+ return MHD_action_abort_request (request);
}
fsync (fd);
if (0 != remove (fn))
@@ -112,6 +116,8 @@ MHDT_server_reply_with_header (
const char *value;
struct MHD_Response *resp;
+ (void) path; (void) method; (void) upload_size; /* Unused */
+
memcpy (name,
header,
hlen);
@@ -123,7 +129,10 @@ MHDT_server_reply_with_header (
MHD_response_add_header (resp,
name,
value))
- return NULL;
+ {
+ MHD_response_destroy (resp);
+ return MHD_action_abort_request (request);
+ }
return MHD_action_from_response (
request,
resp);
@@ -142,6 +151,8 @@ MHDT_server_reply_check_query (
size_t qlen = strlen (equery) + 1;
char qc[qlen];
+ (void) path; (void) method; (void) upload_size; /* Unused */
+
memcpy (qc,
equery,
qlen);
@@ -164,7 +175,7 @@ MHDT_server_reply_check_query (
val = end + 1;
}
{
- size_t alen = end - tok;
+ size_t alen = (size_t) (end - tok);
char arg[alen + 1];
memcpy (arg,
@@ -179,7 +190,7 @@ MHDT_server_reply_check_query (
fprintf (stderr,
"NULL returned for query key %s\n",
arg);
- return NULL;
+ return MHD_action_abort_request (request);
}
if (NULL == val)
{
@@ -189,7 +200,7 @@ MHDT_server_reply_check_query (
"NULL expected for value for query key %s, got %s\n",
arg,
sn->cstr);
- return NULL;
+ return MHD_action_abort_request (request);
}
}
else
@@ -200,7 +211,7 @@ MHDT_server_reply_check_query (
"%s expected for value for query key %s, got NULL\n",
val,
arg);
- return NULL;
+ return MHD_action_abort_request (request);
}
if (0 != strcmp (val,
sn->cstr))
@@ -210,7 +221,7 @@ MHDT_server_reply_check_query (
val,
arg,
sn->cstr);
- return NULL;
+ return MHD_action_abort_request (request);
}
}
}
@@ -238,6 +249,8 @@ MHDT_server_reply_check_header (
const struct MHD_StringNullable *have;
const char *value;
+ (void) path; (void) method; (void) upload_size; /* Unused */
+
memcpy (key,
want,
wlen);
@@ -258,7 +271,7 @@ MHDT_server_reply_check_header (
fprintf (stderr,
"Missing client header `%s'\n",
want);
- return NULL;
+ return MHD_action_abort_request (request);
}
if (NULL == value)
{
@@ -268,7 +281,7 @@ MHDT_server_reply_check_header (
"Have unexpected client header `%s': `%s'\n",
key,
have->cstr);
- return NULL;
+ return MHD_action_abort_request (request);
}
}
else
@@ -278,7 +291,7 @@ MHDT_server_reply_check_header (
fprintf (stderr,
"Missing value for client header `%s'\n",
want);
- return NULL;
+ return MHD_action_abort_request (request);
}
if (0 != strcmp (have->cstr,
value))
@@ -288,7 +301,7 @@ MHDT_server_reply_check_header (
key,
value,
have->cstr);
- return NULL;
+ return MHD_action_abort_request (request);
}
}
return MHD_action_from_response (
@@ -332,7 +345,7 @@ check_upload_cb (void *cls,
{
fprintf (stderr,
"Invalid body size given to full upload callback\n");
- return NULL;
+ return MHD_upload_action_abort_request (request);
}
if (0 != memcmp (want,
content_data,
@@ -340,7 +353,7 @@ check_upload_cb (void *cls,
{
fprintf (stderr,
"Invalid body data given to full upload callback\n");
- return NULL;
+ return MHD_upload_action_abort_request (request);
}
/* success! */
return MHD_upload_action_from_response (
@@ -361,6 +374,8 @@ MHDT_server_reply_check_upload (
const char *want = cls;
size_t wlen = strlen (want);
+ (void) path; (void) method; (void) upload_size; /* Unused */
+
return MHD_action_process_upload_full (request,
wlen,
&check_upload_cb,
@@ -409,10 +424,12 @@ chunk_return (void *cls,
size_t imax = strlen (cc->pos);
const char *space = strchr (cc->pos, ' ');
+ (void) pos; // TODO: add check
+
if (0 == imax)
return MHD_DCC_action_finish (ctx);
if (NULL != space)
- imax = space - cc->pos + 1;
+ imax = (size_t) (space - cc->pos) + 1;
if (imax > max)
imax = max;
memcpy (buf,
@@ -435,6 +452,8 @@ MHDT_server_reply_chunked_text (
const char *text = cls;
struct ChunkContext *cc;
+ (void) path; (void) method; (void) upload_size; /* Unused */
+
cc = malloc (sizeof (struct ChunkContext));
if (NULL == cc)
return NULL;
diff --git a/src/tests/client_server/test_client_server.c b/src/tests/client_server/test_client_server.c
@@ -23,8 +23,6 @@
* @brief test with client against server
* @author Christian Grothoff
*/
-#include <microhttpd2.h>
-#include "mhd_config.h"
#include "libtest.h"
@@ -261,7 +259,7 @@ main (int argc, char *argv[])
int ret;
fprintf (stderr,
- "Running tests with server setup `%s'\n",
+ "Running tests with server setup '%s'\n",
configs[i].label);
ret = MHDT_test (configs[i].server_setup,
configs[i].server_setup_cls,
@@ -271,7 +269,7 @@ main (int argc, char *argv[])
if (0 != ret)
{
fprintf (stderr,
- "Test failed with server of type `%s' (%u)\n",
+ "Test failed with server of type '%s' (%u)\n",
configs[i].label,
i);
return ret;