tests: fix 1301, 1308 to fail on error

They were using a macro designed for unit tests. It does not fail when
used in libtests. Make similar macros for these tests, and make them
return a failure.

Also:
- makes these two tests align with the rest of libtests, by including
  `first.h` instead of `curlcheck.h`.
- since libtests no longer need to depend on tests/unit, drop this
  dependency from build scripts.

Closes #17867
This commit is contained in:
Viktor Szakats 2025-07-08 22:38:02 +02:00
parent 454395ba1e
commit 9db9137066
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201
4 changed files with 39 additions and 22 deletions

View file

@ -54,7 +54,6 @@ target_include_directories(${BUNDLE} PRIVATE
"${PROJECT_BINARY_DIR}/lib" # for "curl_config.h"
"${PROJECT_SOURCE_DIR}/lib" # for "curl_setup.h", curlx
"${CMAKE_CURRENT_SOURCE_DIR}" # for the generated bundle source to find included test sources
"${PROJECT_SOURCE_DIR}/tests/unit" # for "curlcheck.h"
)
set_property(TARGET ${BUNDLE} APPEND PROPERTY COMPILE_DEFINITIONS "${CURL_DEBUG_MACROS}")
set_property(TARGET ${BUNDLE} APPEND PROPERTY COMPILE_DEFINITIONS "CURL_NO_OLDIES" "CURL_DISABLE_DEPRECATION")

View file

@ -36,8 +36,7 @@ AUTOMAKE_OPTIONS = foreign nostdinc
AM_CPPFLAGS = -I$(top_srcdir)/include \
-I$(top_builddir)/lib \
-I$(top_srcdir)/lib \
-I$(srcdir) \
-I$(top_srcdir)/tests/unit
-I$(srcdir)
# Get BUNDLE, FIRST_C, FIRST_H, UTILS_C, UTILS_H, CURLX_C, TESTS_C variables
include Makefile.inc

View file

@ -21,7 +21,16 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "curlcheck.h"
#include "first.h"
#define t1301_fail_unless(expr, msg) \
do { \
if(!(expr)) { \
curl_mfprintf(stderr, "%s:%d Assertion '%s' FAILED: %s\n", \
__FILE__, __LINE__, #expr, msg); \
return TEST_ERR_FAILURE; \
} \
} while(0)
static CURLcode test_lib1301(char *URL)
{
@ -29,25 +38,25 @@ static CURLcode test_lib1301(char *URL)
(void)URL;
rc = curl_strequal("iii", "III");
fail_unless(rc != 0, "return code should be non-zero");
t1301_fail_unless(rc != 0, "return code should be non-zero");
rc = curl_strequal("iiia", "III");
fail_unless(rc == 0, "return code should be zero");
t1301_fail_unless(rc == 0, "return code should be zero");
rc = curl_strequal("iii", "IIIa");
fail_unless(rc == 0, "return code should be zero");
t1301_fail_unless(rc == 0, "return code should be zero");
rc = curl_strequal("iiiA", "IIIa");
fail_unless(rc != 0, "return code should be non-zero");
t1301_fail_unless(rc != 0, "return code should be non-zero");
rc = curl_strnequal("iii", "III", 3);
fail_unless(rc != 0, "return code should be non-zero");
t1301_fail_unless(rc != 0, "return code should be non-zero");
rc = curl_strnequal("iiiABC", "IIIcba", 3);
fail_unless(rc != 0, "return code should be non-zero");
t1301_fail_unless(rc != 0, "return code should be non-zero");
rc = curl_strnequal("ii", "II", 3);
fail_unless(rc != 0, "return code should be non-zero");
t1301_fail_unless(rc != 0, "return code should be non-zero");
return CURLE_OK;
}

View file

@ -21,7 +21,7 @@
* SPDX-License-Identifier: curl
*
***************************************************************************/
#include "curlcheck.h"
#include "first.h"
static size_t print_httppost_callback(void *arg, const char *buf, size_t len)
{
@ -30,8 +30,18 @@ static size_t print_httppost_callback(void *arg, const char *buf, size_t len)
return len;
}
#define t1308_fail_unless(expr, msg) \
do { \
if(!(expr)) { \
curl_mfprintf(stderr, "%s:%d Assertion '%s' FAILED: %s\n", \
__FILE__, __LINE__, #expr, msg); \
errorcount++; \
} \
} while(0)
static CURLcode test_lib1308(char *URL)
{
int errorcount = 0;
CURLFORMcode rc;
int res;
struct curl_httppost *post = NULL;
@ -41,25 +51,25 @@ static CURLcode test_lib1308(char *URL)
rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name",
CURLFORM_COPYCONTENTS, "content", CURLFORM_END);
fail_unless(rc == 0, "curl_formadd returned error");
t1308_fail_unless(rc == 0, "curl_formadd returned error");
/* after the first curl_formadd when there's a single entry, both pointers
should point to the same struct */
fail_unless(post == last, "post and last weren't the same");
t1308_fail_unless(post == last, "post and last weren't the same");
rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "htmlcode",
CURLFORM_COPYCONTENTS, "<HTML></HTML>",
CURLFORM_CONTENTTYPE, "text/html", CURLFORM_END);
fail_unless(rc == 0, "curl_formadd returned error");
t1308_fail_unless(rc == 0, "curl_formadd returned error");
rc = curl_formadd(&post, &last, CURLFORM_COPYNAME, "name_for_ptrcontent",
CURLFORM_PTRCONTENTS, buffer, CURLFORM_END);
fail_unless(rc == 0, "curl_formadd returned error");
t1308_fail_unless(rc == 0, "curl_formadd returned error");
res = curl_formget(post, &total_size, print_httppost_callback);
fail_unless(res == 0, "curl_formget returned error");
t1308_fail_unless(res == 0, "curl_formget returned error");
fail_unless(total_size == 518, "curl_formget got wrong size back");
t1308_fail_unless(total_size == 518, "curl_formget got wrong size back");
curl_formfree(post);
@ -71,14 +81,14 @@ static CURLcode test_lib1308(char *URL)
CURLFORM_FILE, URL,
CURLFORM_FILENAME, "custom named file",
CURLFORM_END);
fail_unless(rc == 0, "curl_formadd returned error");
t1308_fail_unless(rc == 0, "curl_formadd 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");
t1308_fail_unless(res == 0, "curl_formget returned error");
t1308_fail_unless(total_size == 899, "curl_formget got wrong size back");
curl_formfree(post);
return CURLE_OK;
return errorcount ? TEST_ERR_FAILURE : CURLE_OK;
}