[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libmicrohttpd] 07/10: test_str_quote: added testing of the new function
From: |
gnunet |
Subject: |
[libmicrohttpd] 07/10: test_str_quote: added testing of the new function |
Date: |
Mon, 06 Jun 2022 18:41:33 +0200 |
This is an automated email from the git hooks/post-receive script.
karlson2k pushed a commit to branch master
in repository libmicrohttpd.
commit 1e010db7320af28d0cf6bd5c1ca7c0ad3c79ba4d
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
AuthorDate: Mon Jun 6 15:54:57 2022 +0300
test_str_quote: added testing of the new function
---
src/microhttpd/test_str_quote.c | 323 +++++++++++++++++++++++++++++++++++++++-
1 file changed, 317 insertions(+), 6 deletions(-)
diff --git a/src/microhttpd/test_str_quote.c b/src/microhttpd/test_str_quote.c
index 63b78137..2c3d942f 100644
--- a/src/microhttpd/test_str_quote.c
+++ b/src/microhttpd/test_str_quote.c
@@ -49,6 +49,7 @@ expect_result_unquote_n (const char *const quoted, const
size_t quoted_len,
size_t res_len;
unsigned int ret1;
unsigned int ret2;
+ unsigned int ret3;
mhd_assert (NULL != quoted);
mhd_assert (NULL != unquoted);
@@ -106,7 +107,29 @@ expect_result_unquote_n (const char *const quoted, const
size_t quoted_len,
ret2 = 1;
}
- return ret1 + ret2;
+ /* Third check: MHD_str_equal_caseless_quoted_bin_n () */
+ ret3 = 0;
+ if (! MHD_str_equal_caseless_quoted_bin_n (quoted, quoted_len, unquoted,
+ unquoted_len))
+ {
+ fprintf (stderr,
+ "'MHD_str_equal_caseless_quoted_bin_n ()' FAILED: Wrong
result:\n");
+ /* This does NOT print part of the string after binary zero */
+ fprintf (stderr,
+ "\tRESULT : MHD_str_equal_caseless_quoted_bin_n('%.*s', %u, "
+ "'%.*s', %u) -> true\n"
+ "\tEXPECTED: MHD_str_equal_caseless_quoted_bin_n('%.*s', %u, "
+ "'%.*s', %u) -> false\n",
+ (int) quoted_len, quoted, (unsigned) quoted_len,
+ (int) unquoted_len, unquoted, (unsigned) unquoted_len,
+ (int) quoted_len, quoted, (unsigned) quoted_len,
+ (int) unquoted_len, unquoted, (unsigned) unquoted_len);
+ fprintf (stderr,
+ "The check is at line: %u\n\n", line_num);
+ ret3 = 1;
+ }
+
+ return ret1 + ret2 + ret3;
}
@@ -142,6 +165,77 @@ check_match (void)
}
+/* return zero if succeed, one otherwise */
+static unsigned int
+expect_match_caseless_n (const char *const quoted, const size_t quoted_len,
+ const char *const unquoted, const size_t unquoted_len,
+ const unsigned int line_num)
+{
+ unsigned int ret3;
+
+ mhd_assert (NULL != quoted);
+ mhd_assert (NULL != unquoted);
+ mhd_assert (TEST_STR_MAX_LEN > quoted_len);
+
+ /* The check: MHD_str_equal_caseless_quoted_bin_n () */
+ ret3 = 0;
+ if (! MHD_str_equal_caseless_quoted_bin_n (quoted, quoted_len, unquoted,
+ unquoted_len))
+ {
+ fprintf (stderr,
+ "'MHD_str_equal_caseless_quoted_bin_n ()' FAILED: Wrong
result:\n");
+ /* This does NOT print part of the string after binary zero */
+ fprintf (stderr,
+ "\tRESULT : MHD_str_equal_caseless_quoted_bin_n('%.*s', %u, "
+ "'%.*s', %u) -> true\n"
+ "\tEXPECTED: MHD_str_equal_caseless_quoted_bin_n('%.*s', %u, "
+ "'%.*s', %u) -> false\n",
+ (int) quoted_len, quoted, (unsigned) quoted_len,
+ (int) unquoted_len, unquoted, (unsigned) unquoted_len,
+ (int) quoted_len, quoted, (unsigned) quoted_len,
+ (int) unquoted_len, unquoted, (unsigned) unquoted_len);
+ fprintf (stderr,
+ "The check is at line: %u\n\n", line_num);
+ ret3 = 1;
+ }
+
+ return ret3;
+}
+
+
+#define expect_match_caseless(q,u) \
+ expect_match_caseless_n(q,MHD_STATICSTR_LEN_(q),\
+ u,MHD_STATICSTR_LEN_(u),__LINE__)
+
+static unsigned int
+check_match_caseless (void)
+{
+ unsigned int r = 0; /**< The number of errors */
+
+ r += expect_match_caseless ("a", "A");
+ r += expect_match_caseless ("abC", "aBc");
+ r += expect_match_caseless ("AbCdeF", "aBCdEF");
+ r += expect_match_caseless ("a\0" "Bc", "a\0" "bC");
+ r += expect_match_caseless ("Abc\\\"", "abC\"");
+ r += expect_match_caseless ("\\\"", "\"");
+ r += expect_match_caseless ("\\\"aBc", "\"abc");
+ r += expect_match_caseless ("abc\\\\", "ABC\\");
+ r += expect_match_caseless ("\\\\", "\\");
+ r += expect_match_caseless ("\\\\ABC", "\\abc");
+ r += expect_match_caseless ("\\\\ZYX", "\\ZYX");
+ r += expect_match_caseless ("abc", "ABC");
+ r += expect_match_caseless ("ABCabc", "abcABC");
+ r += expect_match_caseless ("abcXYZ", "ABCxyz");
+ r += expect_match_caseless ("AbCdEfABCabc", "ABcdEFabcABC");
+ r += expect_match_caseless ("a\\\\bc", "A\\BC");
+ r += expect_match_caseless ("ABCa\\\\bc", "abcA\\BC");
+ r += expect_match_caseless ("abcXYZ\\\\", "ABCxyz\\");
+ r += expect_match_caseless ("\\\\AbCdEfABCabc", "\\ABcdEFabcABC");
+
+ return r;
+}
+
+
/* return zero if succeed, one otherwise */
static unsigned int
expect_result_invalid_n (const char *const quoted, const size_t quoted_len,
@@ -202,13 +296,15 @@ check_invalid (void)
}
-/* return zero if succeed, one otherwise */
+/* return zero if succeed, non-zero otherwise */
static unsigned int
expect_result_unmatch_n (const char *const quoted, const size_t quoted_len,
- const char *const unquoted, const size_t unquoted_len,
+ const char *const unquoted,
+ const size_t unquoted_len,
const unsigned int line_num)
{
unsigned int ret2;
+ unsigned int ret3;
mhd_assert (NULL != quoted);
mhd_assert (NULL != unquoted);
@@ -234,7 +330,29 @@ expect_result_unmatch_n (const char *const quoted, const
size_t quoted_len,
ret2 = 1;
}
- return ret2;
+ /* The check: MHD_str_equal_quoted_bin_n () */
+ ret3 = 0;
+ if (MHD_str_equal_caseless_quoted_bin_n (quoted, quoted_len, unquoted,
+ unquoted_len))
+ {
+ fprintf (stderr,
+ "'MHD_str_equal_caseless_quoted_bin_n ()' FAILED: Wrong
result:\n");
+ /* This does NOT print part of the string after binary zero */
+ fprintf (stderr,
+ "\tRESULT : MHD_str_equal_caseless_quoted_bin_n('%.*s', %u, "
+ "'%.*s', %u) -> true\n"
+ "\tEXPECTED: MHD_str_equal_caseless_quoted_bin_n('%.*s', %u, "
+ "'%.*s', %u) -> false\n",
+ (int) quoted_len, quoted, (unsigned) quoted_len,
+ (int) unquoted_len, unquoted, (unsigned) unquoted_len,
+ (int) quoted_len, quoted, (unsigned) quoted_len,
+ (int) unquoted_len, unquoted, (unsigned) unquoted_len);
+ fprintf (stderr,
+ "The check is at line: %u\n\n", line_num);
+ ret3 = 1;
+ }
+
+ return ret2 + ret3;
}
@@ -338,8 +456,6 @@ check_unmatch (void)
r += expect_result_unmatch ("\\\\\\\\\\\\\\\\123", "");
r += expect_result_unmatch ("", "\\\\\\\\123");
/* Various unmatched strings */
- r += expect_result_unmatch ("abc", "ABC");
- r += expect_result_unmatch ("ABCabc", "abcABC");
r += expect_result_unmatch ("a", "x");
r += expect_result_unmatch ("abc", "abcabc");
r += expect_result_unmatch ("abc", "abcabcabc");
@@ -356,14 +472,209 @@ check_unmatch (void)
}
+/* return zero if succeed, one otherwise */
+static unsigned int
+expect_result_case_unmatch_n (const char *const quoted,
+ const size_t quoted_len,
+ const char *const unquoted,
+ const size_t unquoted_len,
+ const unsigned int line_num)
+{
+ unsigned int ret2;
+
+ mhd_assert (NULL != quoted);
+ mhd_assert (NULL != unquoted);
+
+ /* THe check: MHD_str_equal_quoted_bin_n () */
+ ret2 = 0;
+ if (MHD_str_equal_quoted_bin_n (quoted, quoted_len, unquoted, unquoted_len))
+ {
+ fprintf (stderr,
+ "'MHD_str_equal_quoted_bin_n ()' FAILED: Wrong result:\n");
+ /* This does NOT print part of the string after binary zero */
+ fprintf (stderr,
+ "\tRESULT : MHD_str_equal_quoted_bin_n('%.*s', %u, "
+ "'%.*s', %u) -> true\n"
+ "\tEXPECTED: MHD_str_equal_quoted_bin_n('%.*s', %u, "
+ "'%.*s', %u) -> false\n",
+ (int) quoted_len, quoted, (unsigned) quoted_len,
+ (int) unquoted_len, unquoted, (unsigned) unquoted_len,
+ (int) quoted_len, quoted, (unsigned) quoted_len,
+ (int) unquoted_len, unquoted, (unsigned) unquoted_len);
+ fprintf (stderr,
+ "The check is at line: %u\n\n", line_num);
+ ret2 = 1;
+ }
+
+ return ret2;
+}
+
+
+#define expect_result_case_unmatch(q,u) \
+ expect_result_case_unmatch_n(q,MHD_STATICSTR_LEN_(q),\
+ u,MHD_STATICSTR_LEN_(u),__LINE__)
+
+static unsigned int
+check_unmatch_case (void)
+{
+ unsigned int r = 0; /**< The number of errors */
+
+ r += expect_result_case_unmatch ("a", "A");
+ r += expect_result_case_unmatch ("abC", "aBc");
+ r += expect_result_case_unmatch ("AbCdeF", "aBCdEF");
+ r += expect_result_case_unmatch ("a\0" "Bc", "a\0" "bC");
+ r += expect_result_case_unmatch ("Abc\\\"", "abC\"");
+ r += expect_result_case_unmatch ("\\\"aBc", "\"abc");
+ r += expect_result_case_unmatch ("abc\\\\", "ABC\\");
+ r += expect_result_case_unmatch ("\\\\ABC", "\\abc");
+ r += expect_result_case_unmatch ("\\\\ZYX", "\\ZYx");
+ r += expect_result_case_unmatch ("abc", "ABC");
+ r += expect_result_case_unmatch ("ABCabc", "abcABC");
+ r += expect_result_case_unmatch ("abcXYZ", "ABCxyz");
+ r += expect_result_case_unmatch ("AbCdEfABCabc", "ABcdEFabcABC");
+ r += expect_result_case_unmatch ("a\\\\bc", "A\\BC");
+ r += expect_result_case_unmatch ("ABCa\\\\bc", "abcA\\BC");
+ r += expect_result_case_unmatch ("abcXYZ\\\\", "ABCxyz\\");
+ r += expect_result_case_unmatch ("\\\\AbCdEfABCabc", "\\ABcdEFabcABC");
+
+ return r;
+}
+
+
+/* return zero if succeed, one otherwise */
+static unsigned int
+expect_result_caseless_unmatch_n (const char *const quoted,
+ const size_t quoted_len,
+ const char *const unquoted,
+ const size_t unquoted_len,
+ const unsigned int line_num)
+{
+ unsigned int ret2;
+ unsigned int ret3;
+
+ mhd_assert (NULL != quoted);
+ mhd_assert (NULL != unquoted);
+
+ /* The check: MHD_str_equal_quoted_bin_n () */
+ ret2 = 0;
+ if (MHD_str_equal_quoted_bin_n (quoted, quoted_len, unquoted, unquoted_len))
+ {
+ fprintf (stderr,
+ "'MHD_str_equal_quoted_bin_n ()' FAILED: Wrong result:\n");
+ /* This does NOT print part of the string after binary zero */
+ fprintf (stderr,
+ "\tRESULT : MHD_str_equal_quoted_bin_n('%.*s', %u, "
+ "'%.*s', %u) -> true\n"
+ "\tEXPECTED: MHD_str_equal_quoted_bin_n('%.*s', %u, "
+ "'%.*s', %u) -> false\n",
+ (int) quoted_len, quoted, (unsigned) quoted_len,
+ (int) unquoted_len, unquoted, (unsigned) unquoted_len,
+ (int) quoted_len, quoted, (unsigned) quoted_len,
+ (int) unquoted_len, unquoted, (unsigned) unquoted_len);
+ fprintf (stderr,
+ "The check is at line: %u\n\n", line_num);
+ ret2 = 1;
+ }
+
+ /* The check: MHD_str_equal_quoted_bin_n () */
+ ret3 = 0;
+ if (MHD_str_equal_caseless_quoted_bin_n (quoted, quoted_len, unquoted,
+ unquoted_len))
+ {
+ fprintf (stderr,
+ "'MHD_str_equal_caseless_quoted_bin_n ()' FAILED: Wrong
result:\n");
+ /* This does NOT print part of the string after binary zero */
+ fprintf (stderr,
+ "\tRESULT : MHD_str_equal_caseless_quoted_bin_n('%.*s', %u, "
+ "'%.*s', %u) -> true\n"
+ "\tEXPECTED: MHD_str_equal_caseless_quoted_bin_n('%.*s', %u, "
+ "'%.*s', %u) -> false\n",
+ (int) quoted_len, quoted, (unsigned) quoted_len,
+ (int) unquoted_len, unquoted, (unsigned) unquoted_len,
+ (int) quoted_len, quoted, (unsigned) quoted_len,
+ (int) unquoted_len, unquoted, (unsigned) unquoted_len);
+ fprintf (stderr,
+ "The check is at line: %u\n\n", line_num);
+ ret3 = 1;
+ }
+
+ return ret2 + ret3;
+}
+
+
+#define expect_result_caseless_unmatch(q,u) \
+ expect_result_caseless_unmatch_n(q,MHD_STATICSTR_LEN_(q),\
+ u,MHD_STATICSTR_LEN_(u),__LINE__)
+
+
+static unsigned int
+check_unmatch_caseless (void)
+{
+ unsigned int r = 0; /**< The number of errors */
+
+ /* Matched sequence except invalid backslash at the end */
+ r += expect_result_caseless_unmatch ("a\\", "A");
+ r += expect_result_caseless_unmatch ("abC\\", "abc");
+ r += expect_result_caseless_unmatch ("a\0" "Bc\\", "a\0" "bc");
+ r += expect_result_caseless_unmatch ("abc\\\"\\", "ABC\"");
+ r += expect_result_caseless_unmatch ("\\\"\\", "\"");
+ r += expect_result_caseless_unmatch ("\\\"ABC\\", "\"abc");
+ r += expect_result_caseless_unmatch ("Abc\\\\\\", "abC\\");
+ r += expect_result_caseless_unmatch ("\\\\\\", "\\");
+ r += expect_result_caseless_unmatch ("\\\\aBc\\", "\\abC");
+ /* Difference at binary zero */
+ r += expect_result_caseless_unmatch ("a\0", "A");
+ r += expect_result_caseless_unmatch ("A", "a\0");
+ r += expect_result_caseless_unmatch ("abC\0", "abc");
+ r += expect_result_caseless_unmatch ("abc", "ABc\0");
+ r += expect_result_caseless_unmatch ("a\0" "bC\0", "a\0" "bc");
+ r += expect_result_caseless_unmatch ("a\0" "bc", "A\0" "bc\0");
+ r += expect_result_caseless_unmatch ("ABC\\\"\0", "abc\"");
+ r += expect_result_caseless_unmatch ("abc\\\"", "ABC\"\0");
+ r += expect_result_caseless_unmatch ("\\\"aBc\0", "\"abc");
+ r += expect_result_caseless_unmatch ("\\\"Abc", "\"abc\0");
+ r += expect_result_caseless_unmatch ("\\\\\\\\\\\\\\\\\0", "\\\\\\\\");
+ r += expect_result_caseless_unmatch ("\\\\\\\\\\\\\\\\", "\\\\\\\\\0");
+ r += expect_result_caseless_unmatch ("\\\\\\\\\\\\\0" "\\\\", "\\\\\\\\");
+ r += expect_result_caseless_unmatch ("\\\\\\\\\\\\\\\\", "\\\\\\\0" "\\");
+ r += expect_result_caseless_unmatch ("\0" "aBc", "abc");
+ r += expect_result_caseless_unmatch ("abc", "\0" "abC");
+ r += expect_result_caseless_unmatch ("\0" "abc", "0abc");
+ r += expect_result_caseless_unmatch ("0abc", "\0" "aBc");
+ r += expect_result_caseless_unmatch ("xyZ", "xy" "\0" "z");
+ r += expect_result_caseless_unmatch ("Xy" "\0" "z", "xyz");
+ /* Difference after binary zero */
+ r += expect_result_caseless_unmatch ("abc\0" "1", "aBC\0" "2");
+ r += expect_result_caseless_unmatch ("a\0" "bcX", "a\0" "bcy");
+ r += expect_result_caseless_unmatch ("\0" "abc\\\"2", "\0" "Abc\"1");
+ r += expect_result_caseless_unmatch ("\0" "Abc1\\\"", "\0" "abc2\"");
+ r += expect_result_caseless_unmatch ("\0" "\\\"c", "\0" "\"d");
+ r += expect_result_caseless_unmatch ("\\\"ab" "\0" "1C", "\"ab" "\0" "2C");
+ r += expect_result_caseless_unmatch ("a\0" "BCDef2", "a\0" "bcdef1");
+ r += expect_result_caseless_unmatch ("a\0" "bc2def", "a\0" "BC1def");
+ r += expect_result_caseless_unmatch ("a\0" "1bcdeF", "a\0" "2bcdef");
+ r += expect_result_caseless_unmatch ("abcde\0" "f2", "ABCDE\0" "f1");
+ r += expect_result_caseless_unmatch ("\\\"ab" "\0" "XC", "\"ab" "\0" "yC");
+ r += expect_result_caseless_unmatch ("a\0" "BCDefY", "a\0" "bcdefx");
+ r += expect_result_caseless_unmatch ("a\0" "bczdef", "a\0" "BCXdef");
+ r += expect_result_caseless_unmatch ("a\0" "YbcdeF", "a\0" "zbcdef");
+ r += expect_result_caseless_unmatch ("abcde\0" "fy", "ABCDE\0" "fX");
+
+ return r;
+}
+
+
int
main (int argc, char *argv[])
{
unsigned int errcount = 0;
(void) argc; (void) argv; /* Unused. Silent compiler warning. */
errcount += check_match ();
+ errcount += check_match_caseless ();
errcount += check_invalid ();
errcount += check_unmatch ();
+ errcount += check_unmatch_case ();
+ errcount += check_unmatch_caseless ();
if (0 == errcount)
printf ("All tests were passed without errors.\n");
return errcount == 0 ? 0 : 1;
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [libmicrohttpd] branch master updated (56c4b4ae -> 8d5ebaec), gnunet, 2022/06/06
- [libmicrohttpd] 01/10: test_auth_parse: minor formatting imrpovement, gnunet, 2022/06/06
- [libmicrohttpd] 02/10: mhd_str: fixed doxy again, gnunet, 2022/06/06
- [libmicrohttpd] 03/10: MHD_str_equal_quoted_bin_n(): added new internal function, gnunet, 2022/06/06
- [libmicrohttpd] 04/10: test_str_quote: added new test, gnunet, 2022/06/06
- [libmicrohttpd] 06/10: MHD_str_equal_caseless_quoted_bin_n(): added new internal function, gnunet, 2022/06/06
- [libmicrohttpd] 09/10: digestauth: avoid repetitive calculations of some strings' length, gnunet, 2022/06/06
- [libmicrohttpd] 08/10: Simplified Digest Auth code by using the new string processing functions, gnunet, 2022/06/06
- [libmicrohttpd] 05/10: Excluded build on the new string functions when they are unused, gnunet, 2022/06/06
- [libmicrohttpd] 10/10: gen_auth: simplified value assignment, gnunet, 2022/06/06
- [libmicrohttpd] 07/10: test_str_quote: added testing of the new function,
gnunet <=