commit ac6bb34de823314932304cde301d60190680763b
parent dce50cca7deee22d58f76974b70816a5423c6f01
Author: Evgeny Grin (Karlson2k) <k2k@drgrin.dev>
Date: Thu, 25 Dec 2025 11:56:33 +0100
unit_str: simplified to use test framework directly
Diffstat:
1 file changed, 84 insertions(+), 80 deletions(-)
diff --git a/src/tests/unit/unit_str.c b/src/tests/unit/unit_str.c
@@ -2,6 +2,7 @@
/*
This file is part of GNU libmicrohttpd.
Copyright (C) 2025 Christian Grothoff
+ Copyright (C) 2025 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
@@ -40,6 +41,7 @@
* @file src/test/unit/unit_str.c
* @brief Unit tests for string functions
* @author Christian Grothoff
+ * @author Karlson2k (Evgeny Grin)
*/
#include "mhd_sys_options.h"
@@ -50,92 +52,94 @@
#include <stdint.h>
#include "../mhd2/mhd_str.h"
#include "../mhd2/mhd_str.c"
-#include "../mhdt_checks.h"
+#include "mhdt_checks.h"
-#define CHECK_TRUE(cond) \
- if (0 == MHDT_EXPECT_TRUE (cond)) { failures++; } else {}
-
-#define CHECK_FALSE(cond) \
- if (0 == MHDT_EXPECT_FALSE (cond)) { failures++; } else {}
+#include "mhdt_has_param.h"
int
-main (void)
+main (int argc,
+ char *const *argv)
{
- unsigned int failures = 0;
-
- MHDT_set_verbosity (MHDT_VERB_LVL_VERBOSE);
- CHECK_TRUE (mhd_str_equal_caseless ("ab",
- "AB"));
- CHECK_TRUE (mhd_str_equal_caseless ("ab",
- "ab"));
- CHECK_TRUE (mhd_str_equal_caseless ("",
- ""));
- CHECK_FALSE (mhd_str_equal_caseless ("ab",
- "ABc"));
- CHECK_FALSE (mhd_str_equal_caseless ("a b",
- "ab"));
- CHECK_FALSE (mhd_str_equal_caseless ("",
- " "));
+ if (mhdt_has_param (argc, argv, "-s") ||
+ mhdt_has_param (argc, argv, "--silent"))
+ MHDT_set_verbosity (MHDT_VERB_LVL_SILENT);
+ else
+ MHDT_set_verbosity (MHDT_VERB_LVL_VERBOSE);
+
+ MHDT_EXPECT_TRUE (mhd_str_equal_caseless ("ab",
+ "AB"));
+ MHDT_EXPECT_TRUE (mhd_str_equal_caseless ("ab",
+ "ab"));
+ MHDT_EXPECT_TRUE (mhd_str_equal_caseless ("",
+ ""));
+ MHDT_EXPECT_FALSE (mhd_str_equal_caseless ("ab",
+ "ABc"));
+ MHDT_EXPECT_FALSE (mhd_str_equal_caseless ("a b",
+ "ab"));
+ MHDT_EXPECT_FALSE (mhd_str_equal_caseless ("",
+ " "));
/* Note: our caseless ONLY refers to US-ASCII */
- CHECK_FALSE (mhd_str_equal_caseless ("Ä",
- "ä"));
-
- CHECK_TRUE (mhd_str_equal_caseless_n ("ab\0x",
- "AB\0y",
- 4));
- CHECK_TRUE (mhd_str_equal_caseless_n ("abc",
- "abd",
- 2));
- CHECK_TRUE (mhd_str_equal_caseless_n ("",
- "",
- 0));
- CHECK_FALSE (mhd_str_equal_caseless_n ("ab",
- "ABc",
- 3));
- CHECK_FALSE (mhd_str_equal_caseless_n ("a b",
- "ab",
- 2));
- CHECK_FALSE (mhd_str_equal_caseless_n ("",
- " ",
- 1));
+ MHDT_EXPECT_FALSE (mhd_str_equal_caseless ("Ä",
+ "ä"));
+
+ MHDT_EXPECT_TRUE (mhd_str_equal_caseless_n ("ab\0x",
+ "AB\0y",
+ 4));
+ MHDT_EXPECT_TRUE (mhd_str_equal_caseless_n ("abc",
+ "abd",
+ 2));
+ MHDT_EXPECT_TRUE (mhd_str_equal_caseless_n ("",
+ "",
+ 0));
+ MHDT_EXPECT_FALSE (mhd_str_equal_caseless_n ("ab",
+ "ABc",
+ 3));
+ MHDT_EXPECT_FALSE (mhd_str_equal_caseless_n ("a b",
+ "ab",
+ 2));
+ MHDT_EXPECT_FALSE (mhd_str_equal_caseless_n ("",
+ " ",
+ 1));
/* Note: our caseless ONLY refers to US-ASCII,
Need 3 here because Umlaut is equal in first
byte and diffes in 2nd byte. */
- CHECK_FALSE (mhd_str_equal_caseless_n ("xÄbb",
- "xäbb",
- 3));
- CHECK_TRUE (mhd_str_equal_caseless_n ("ab\0x",
- "AB\0y",
- 4));
-
- CHECK_TRUE (mhd_str_equal_caseless_bin_n ("ab\0x",
- "AB\0x",
- 4));
- CHECK_FALSE (mhd_str_equal_caseless_bin_n ("ab\0x",
- "AB\0y",
- 4));
- CHECK_FALSE (mhd_str_equal_caseless_bin_n ("ab\0x",
- "AB\0y",
- 4));
-
- CHECK_TRUE (mhd_str_equal_lowercase_bin_n ("AB",
- "ab",
- 2));
- CHECK_FALSE (mhd_str_equal_lowercase_bin_n ("ab",
- "AB",
- 2));
- CHECK_TRUE (mhd_str_is_lowercase_bin_n (0,
- ""));
- CHECK_TRUE (mhd_str_is_lowercase_bin_n (2,
- "ab"));
- CHECK_TRUE (mhd_str_is_lowercase_bin_n (2,
- "abC"));
- CHECK_TRUE (mhd_str_is_lowercase_bin_n (2,
- "xä"));
- CHECK_TRUE (mhd_str_is_lowercase_bin_n (2,
- "xÄ"));
- CHECK_FALSE (mhd_str_is_lowercase_bin_n (2,
- "aB"));
-
- return (0 == failures) ? 0 : 1;
+ MHDT_EXPECT_FALSE (mhd_str_equal_caseless_n ("xÄbb",
+ "xäbb",
+ 3));
+ MHDT_EXPECT_TRUE (mhd_str_equal_caseless_n ("ab\0x",
+ "AB\0y",
+ 4));
+
+ MHDT_EXPECT_TRUE (mhd_str_equal_caseless_bin_n ("ab\0x",
+ "AB\0x",
+ 4));
+ MHDT_EXPECT_FALSE (mhd_str_equal_caseless_bin_n ("ab\0x",
+ "AB\0y",
+ 4));
+ MHDT_EXPECT_FALSE (mhd_str_equal_caseless_bin_n ("ab\0x",
+ "AB\0y",
+ 4));
+
+ MHDT_EXPECT_TRUE (mhd_str_equal_lowercase_bin_n ("AB",
+ "ab",
+ 2));
+ MHDT_EXPECT_FALSE (mhd_str_equal_lowercase_bin_n ("ab",
+ "AB",
+ 2));
+ MHDT_EXPECT_TRUE (mhd_str_is_lowercase_bin_n (0,
+ ""));
+ MHDT_EXPECT_TRUE (mhd_str_is_lowercase_bin_n (2,
+ "ab"));
+ MHDT_EXPECT_TRUE (mhd_str_is_lowercase_bin_n (2,
+ "abC"));
+ MHDT_EXPECT_TRUE (mhd_str_is_lowercase_bin_n (2,
+ "xä"));
+ MHDT_EXPECT_TRUE (mhd_str_is_lowercase_bin_n (2,
+ "xÄ"));
+ MHDT_EXPECT_FALSE (mhd_str_is_lowercase_bin_n (2,
+ "aB"));
+
+ MHDT_TEST_RESULT ();
+
+ return MHDT_FINAL_RESULT (argv[0]);
}