unit_str.c (6130B)
1 /* SPDX-License-Identifier: LGPL-2.1-or-later OR (GPL-2.0-or-later WITH eCos-exception-2.0) */ 2 /* 3 This file is part of GNU libmicrohttpd. 4 Copyright (C) 2025 Christian Grothoff 5 Copyright (C) 2025 Evgeny Grin (Karlson2k) 6 7 GNU libmicrohttpd is free software; you can redistribute it and/or 8 modify it under the terms of the GNU Lesser General Public 9 License as published by the Free Software Foundation; either 10 version 2.1 of the License, or (at your option) any later version. 11 12 GNU libmicrohttpd is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 Lesser General Public License for more details. 16 17 Alternatively, you can redistribute GNU libmicrohttpd and/or 18 modify it under the terms of the GNU General Public License as 19 published by the Free Software Foundation; either version 2 of 20 the License, or (at your option) any later version, together 21 with the eCos exception, as follows: 22 23 As a special exception, if other files instantiate templates or 24 use macros or inline functions from this file, or you compile this 25 file and link it with other works to produce a work based on this 26 file, this file does not by itself cause the resulting work to be 27 covered by the GNU General Public License. However the source code 28 for this file must still be made available in accordance with 29 section (3) of the GNU General Public License v2. 30 31 This exception does not invalidate any other reasons why a work 32 based on this file might be covered by the GNU General Public 33 License. 34 35 You should have received copies of the GNU Lesser General Public 36 License and the GNU General Public License along with this library; 37 if not, see <https://www.gnu.org/licenses/>. 38 */ 39 40 /** 41 * @file src/test/unit/unit_str.c 42 * @brief Unit tests for string functions 43 * @author Christian Grothoff 44 * @author Karlson2k (Evgeny Grin) 45 */ 46 47 #include "mhd_sys_options.h" 48 49 #include "../mhd2/mhd_str.h" 50 #include "../mhd2/mhd_str.c" 51 #include "mhdt_checks.h" 52 53 #include "mhdt_has_param.h" 54 55 int 56 main (int argc, 57 char *const *argv) 58 { 59 if (mhdt_has_param (argc, argv, "-s") || 60 mhdt_has_param (argc, argv, "--silent")) 61 MHDT_set_verbosity (MHDT_VERB_LVL_SILENT); 62 else 63 MHDT_set_verbosity (MHDT_VERB_LVL_VERBOSE); 64 65 MHDT_EXPECT_TRUE (mhd_str_equal_caseless ("ab", 66 "AB")); 67 MHDT_EXPECT_TRUE (mhd_str_equal_caseless ("ab", 68 "ab")); 69 MHDT_EXPECT_TRUE (mhd_str_equal_caseless ("", 70 "")); 71 MHDT_EXPECT_FALSE (mhd_str_equal_caseless ("ab", 72 "ABc")); 73 MHDT_EXPECT_FALSE (mhd_str_equal_caseless ("a b", 74 "ab")); 75 MHDT_EXPECT_FALSE (mhd_str_equal_caseless ("", 76 " ")); 77 /* Note: our caseless ONLY refers to US-ASCII */ 78 MHDT_EXPECT_FALSE (mhd_str_equal_caseless ("Ä", 79 "ä")); 80 81 MHDT_EXPECT_TRUE (mhd_str_equal_caseless_n ("ab\0x", 82 "AB\0y", 83 4)); 84 MHDT_EXPECT_TRUE (mhd_str_equal_caseless_n ("abc", 85 "abd", 86 2)); 87 MHDT_EXPECT_TRUE (mhd_str_equal_caseless_n ("", 88 "", 89 0)); 90 MHDT_EXPECT_FALSE (mhd_str_equal_caseless_n ("ab", 91 "ABc", 92 3)); 93 MHDT_EXPECT_FALSE (mhd_str_equal_caseless_n ("a b", 94 "ab", 95 2)); 96 MHDT_EXPECT_FALSE (mhd_str_equal_caseless_n ("", 97 " ", 98 1)); 99 /* Note: our caseless ONLY refers to US-ASCII, 100 Need 3 here because Umlaut is equal in first 101 byte and diffes in 2nd byte. */ 102 MHDT_EXPECT_FALSE (mhd_str_equal_caseless_n ("xÄbb", 103 "xäbb", 104 3)); 105 MHDT_EXPECT_TRUE (mhd_str_equal_caseless_n ("ab\0x", 106 "AB\0y", 107 4)); 108 109 MHDT_EXPECT_TRUE (mhd_str_equal_caseless_bin_n ("ab\0x", 110 "AB\0x", 111 4)); 112 MHDT_EXPECT_FALSE (mhd_str_equal_caseless_bin_n ("ab\0x", 113 "AB\0y", 114 4)); 115 MHDT_EXPECT_FALSE (mhd_str_equal_caseless_bin_n ("ab\0x", 116 "AB\0y", 117 4)); 118 119 MHDT_EXPECT_TRUE (mhd_str_equal_lowercase_bin_n ("AB", 120 "ab", 121 2)); 122 MHDT_EXPECT_TRUE (mhd_str_equal_lowercase_bin_n ("aB", 123 "ab", 124 2)); 125 MHDT_EXPECT_TRUE (mhd_str_is_lowercase_bin_n (0, 126 "")); 127 MHDT_EXPECT_TRUE (mhd_str_is_lowercase_bin_n (2, 128 "ab")); 129 MHDT_EXPECT_TRUE (mhd_str_is_lowercase_bin_n (2, 130 "abC")); 131 MHDT_EXPECT_TRUE (mhd_str_is_lowercase_bin_n (2, 132 "xä")); 133 MHDT_EXPECT_TRUE (mhd_str_is_lowercase_bin_n (2, 134 "xÄ")); 135 MHDT_EXPECT_FALSE (mhd_str_is_lowercase_bin_n (2, 136 "aB")); 137 138 MHDT_TEST_RESULT (); 139 140 return MHDT_FINAL_RESULT (argv[0]); 141 }