1 1.1 mrg /* 2 1.1 mrg * Copyright (c) 2022, 2023, Oracle and/or its affiliates. 3 1.1 mrg * 4 1.1 mrg * Permission is hereby granted, free of charge, to any person obtaining a 5 1.1 mrg * copy of this software and associated documentation files (the "Software"), 6 1.1 mrg * to deal in the Software without restriction, including without limitation 7 1.1 mrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 1.1 mrg * and/or sell copies of the Software, and to permit persons to whom the 9 1.1 mrg * Software is furnished to do so, subject to the following conditions: 10 1.1 mrg * 11 1.1 mrg * The above copyright notice and this permission notice (including the next 12 1.1 mrg * paragraph) shall be included in all copies or substantial portions of the 13 1.1 mrg * Software. 14 1.1 mrg * 15 1.1 mrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 1.1 mrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 1.1 mrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 1.1 mrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 1.1 mrg * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 20 1.1 mrg * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 21 1.1 mrg * DEALINGS IN THE SOFTWARE. 22 1.1 mrg */ 23 1.1 mrg 24 1.1 mrg /* Test code for functions in src/Lower.c */ 25 1.1 mrg #include "config.h" 26 1.1 mrg #include <X11/Xmu/CharSet.h> 27 1.1 mrg #include <X11/Xmu/SysUtil.h> 28 1.1 mrg #define XK_LATIN1 29 1.1 mrg #include <X11/keysymdef.h> 30 1.1 mrg #include <glib.h> 31 1.1 mrg #include <string.h> 32 1.1 mrg 33 1.1 mrg static const char upper[] = { 34 1.1 mrg XK_space, XK_exclam, XK_quotedbl, XK_numbersign, XK_dollar, XK_percent, 35 1.1 mrg XK_ampersand, XK_apostrophe, XK_quoteright, XK_parenleft, XK_parenright, 36 1.1 mrg XK_asterisk, XK_plus, XK_comma, XK_minus, XK_period, XK_slash, 37 1.1 mrg XK_0, XK_1, XK_2, XK_3, XK_4, XK_5, XK_6, XK_7, XK_8, XK_9, 38 1.1 mrg XK_colon, XK_semicolon, XK_less, XK_equal, XK_greater, XK_question, XK_at, 39 1.1 mrg XK_A, XK_B, XK_C, XK_D, XK_E, XK_F, XK_G, XK_H, XK_I, XK_J, XK_K, XK_L, XK_M, 40 1.1 mrg XK_N, XK_O, XK_P, XK_Q, XK_R, XK_S, XK_T, XK_U, XK_V, XK_W, XK_X, XK_Y, XK_Z, 41 1.1 mrg XK_bracketleft, XK_backslash, XK_bracketright, XK_asciicircum, XK_underscore, 42 1.1 mrg XK_grave, XK_quoteleft, XK_braceleft, XK_bar, XK_braceright, XK_asciitilde, 43 1.1 mrg XK_exclamdown, XK_cent, XK_sterling, XK_currency, XK_yen, XK_brokenbar, 44 1.1 mrg XK_section, XK_diaeresis, XK_copyright, XK_ordfeminine, XK_guillemotleft, 45 1.1 mrg XK_notsign, XK_hyphen, XK_registered, XK_macron, XK_degree, XK_plusminus, 46 1.1 mrg XK_twosuperior, XK_threesuperior, XK_acute, XK_mu, XK_paragraph, 47 1.1 mrg XK_periodcentered, XK_cedilla, XK_onesuperior, XK_masculine, 48 1.1 mrg XK_guillemotright, XK_onequarter, XK_onehalf, XK_threequarters, 49 1.1 mrg XK_questiondown, XK_multiply, XK_division, 50 1.1 mrg XK_Agrave, XK_Aacute, XK_Acircumflex, XK_Atilde, XK_Adiaeresis, XK_Aring, 51 1.1 mrg XK_AE, XK_Ccedilla, XK_Egrave, XK_Eacute, XK_Ecircumflex, XK_Ediaeresis, 52 1.1 mrg XK_Igrave, XK_Iacute, XK_Icircumflex, XK_Idiaeresis, XK_ETH, XK_Ntilde, 53 1.1 mrg XK_Ograve, XK_Oacute, XK_Ocircumflex, XK_Otilde, XK_Odiaeresis, XK_Oslash, 54 1.1 mrg XK_Ooblique, XK_Ugrave, XK_Uacute, XK_Ucircumflex, XK_Udiaeresis, XK_Yacute, 55 1.1 mrg XK_THORN, XK_ydiaeresis, '\0' 56 1.1 mrg }; 57 1.1 mrg 58 1.1 mrg static const char lower[] = { 59 1.1 mrg XK_space, XK_exclam, XK_quotedbl, XK_numbersign, XK_dollar, XK_percent, 60 1.1 mrg XK_ampersand, XK_apostrophe, XK_quoteright, XK_parenleft, XK_parenright, 61 1.1 mrg XK_asterisk, XK_plus, XK_comma, XK_minus, XK_period, XK_slash, 62 1.1 mrg XK_0, XK_1, XK_2, XK_3, XK_4, XK_5, XK_6, XK_7, XK_8, XK_9, 63 1.1 mrg XK_colon, XK_semicolon, XK_less, XK_equal, XK_greater, XK_question, XK_at, 64 1.1 mrg XK_a, XK_b, XK_c, XK_d, XK_e, XK_f, XK_g, XK_h, XK_i, XK_j, XK_k, XK_l, XK_m, 65 1.1 mrg XK_n, XK_o, XK_p, XK_q, XK_r, XK_s, XK_t, XK_u, XK_v, XK_w, XK_x, XK_y, XK_z, 66 1.1 mrg XK_bracketleft, XK_backslash, XK_bracketright, XK_asciicircum, XK_underscore, 67 1.1 mrg XK_grave, XK_quoteleft, XK_braceleft, XK_bar, XK_braceright, XK_asciitilde, 68 1.1 mrg XK_exclamdown, XK_cent, XK_sterling, XK_currency, XK_yen, XK_brokenbar, 69 1.1 mrg XK_section, XK_diaeresis, XK_copyright, XK_ordfeminine, XK_guillemotleft, 70 1.1 mrg XK_notsign, XK_hyphen, XK_registered, XK_macron, XK_degree, XK_plusminus, 71 1.1 mrg XK_twosuperior, XK_threesuperior, XK_acute, XK_mu, XK_paragraph, 72 1.1 mrg XK_periodcentered, XK_cedilla, XK_onesuperior, XK_masculine, 73 1.1 mrg XK_guillemotright, XK_onequarter, XK_onehalf, XK_threequarters, 74 1.1 mrg XK_questiondown, XK_multiply, XK_division, 75 1.1 mrg XK_agrave, XK_aacute, XK_acircumflex, XK_atilde, XK_adiaeresis, XK_aring, 76 1.1 mrg XK_ae, XK_ccedilla, XK_egrave, XK_eacute, XK_ecircumflex, XK_ediaeresis, 77 1.1 mrg XK_igrave, XK_iacute, XK_icircumflex, XK_idiaeresis, XK_eth, XK_ntilde, 78 1.1 mrg XK_ograve, XK_oacute, XK_ocircumflex, XK_otilde, XK_odiaeresis, XK_oslash, 79 1.1 mrg XK_ooblique, XK_ugrave, XK_uacute, XK_ucircumflex, XK_udiaeresis, XK_yacute, 80 1.1 mrg XK_thorn, XK_ydiaeresis, '\0' 81 1.1 mrg }; 82 1.1 mrg 83 1.1 mrg static const char mixed[] = { 84 1.1 mrg XK_space, XK_exclam, XK_quotedbl, XK_numbersign, XK_dollar, XK_percent, 85 1.1 mrg XK_ampersand, XK_apostrophe, XK_quoteright, XK_parenleft, XK_parenright, 86 1.1 mrg XK_asterisk, XK_plus, XK_comma, XK_minus, XK_period, XK_slash, 87 1.1 mrg XK_0, XK_1, XK_2, XK_3, XK_4, XK_5, XK_6, XK_7, XK_8, XK_9, 88 1.1 mrg XK_colon, XK_semicolon, XK_less, XK_equal, XK_greater, XK_question, XK_at, 89 1.1 mrg XK_a, XK_b, XK_c, XK_d, XK_e, XK_f, XK_g, XK_h, XK_i, XK_j, XK_k, XK_l, XK_m, 90 1.1 mrg XK_N, XK_O, XK_P, XK_Q, XK_R, XK_S, XK_T, XK_U, XK_V, XK_W, XK_X, XK_Y, XK_Z, 91 1.1 mrg XK_bracketleft, XK_backslash, XK_bracketright, XK_asciicircum, XK_underscore, 92 1.1 mrg XK_grave, XK_quoteleft, XK_braceleft, XK_bar, XK_braceright, XK_asciitilde, 93 1.1 mrg XK_exclamdown, XK_cent, XK_sterling, XK_currency, XK_yen, XK_brokenbar, 94 1.1 mrg XK_section, XK_diaeresis, XK_copyright, XK_ordfeminine, XK_guillemotleft, 95 1.1 mrg XK_notsign, XK_hyphen, XK_registered, XK_macron, XK_degree, XK_plusminus, 96 1.1 mrg XK_twosuperior, XK_threesuperior, XK_acute, XK_mu, XK_paragraph, 97 1.1 mrg XK_periodcentered, XK_cedilla, XK_onesuperior, XK_masculine, 98 1.1 mrg XK_guillemotright, XK_onequarter, XK_onehalf, XK_threequarters, 99 1.1 mrg XK_questiondown, XK_multiply, XK_division, 100 1.1 mrg XK_agrave, XK_aacute, XK_acircumflex, XK_atilde, XK_adiaeresis, XK_aring, 101 1.1 mrg XK_AE, XK_Ccedilla, XK_Egrave, XK_Eacute, XK_Ecircumflex, XK_Ediaeresis, 102 1.1 mrg XK_igrave, XK_iacute, XK_icircumflex, XK_idiaeresis, XK_eth, XK_ntilde, 103 1.1 mrg XK_Ograve, XK_Oacute, XK_Ocircumflex, XK_Otilde, XK_Odiaeresis, XK_Oslash, 104 1.1 mrg XK_ooblique, XK_ugrave, XK_uacute, XK_ucircumflex, XK_udiaeresis, XK_yacute, 105 1.1 mrg XK_THORN, XK_ydiaeresis, '\0' 106 1.1 mrg }; 107 1.1 mrg 108 1.1 mrg #define DATA_LEN sizeof(upper) 109 1.1 mrg 110 1.1 mrg static void 111 1.1 mrg test_XmuCopyISOLatin1Lowered(void) 112 1.1 mrg { 113 1.1 mrg char buf[DATA_LEN]; 114 1.1 mrg 115 1.1 mrg XmuCopyISOLatin1Lowered(buf, upper); 116 1.1 mrg g_assert_cmpstr(buf, ==, lower); 117 1.1 mrg 118 1.1 mrg XmuCopyISOLatin1Lowered(buf, lower); 119 1.1 mrg g_assert_cmpstr(buf, ==, lower); 120 1.1 mrg 121 1.1 mrg XmuCopyISOLatin1Lowered(buf, mixed); 122 1.1 mrg g_assert_cmpstr(buf, ==, lower); 123 1.1 mrg } 124 1.1 mrg 125 1.1 mrg static void 126 1.1 mrg test_XmuCopyISOLatin1Uppered(void) 127 1.1 mrg { 128 1.1 mrg char buf[DATA_LEN]; 129 1.1 mrg 130 1.1 mrg XmuCopyISOLatin1Uppered(buf, upper); 131 1.1 mrg g_assert_cmpstr(buf, ==, upper); 132 1.1 mrg 133 1.1 mrg XmuCopyISOLatin1Uppered(buf, lower); 134 1.1 mrg g_assert_cmpstr(buf, ==, upper); 135 1.1 mrg 136 1.1 mrg XmuCopyISOLatin1Uppered(buf, mixed); 137 1.1 mrg g_assert_cmpstr(buf, ==, upper); 138 1.1 mrg } 139 1.1 mrg 140 1.1 mrg static void 141 1.1 mrg test_XmuNCopyISOLatin1Lowered(void) 142 1.1 mrg { 143 1.1 mrg char buf[DATA_LEN]; 144 1.1 mrg 145 1.1 mrg XmuNCopyISOLatin1Lowered(buf, upper, DATA_LEN); 146 1.1 mrg g_assert_cmpstr(buf, ==, lower); 147 1.1 mrg 148 1.1 mrg XmuNCopyISOLatin1Lowered(buf, lower, DATA_LEN); 149 1.1 mrg g_assert_cmpstr(buf, ==, lower); 150 1.1 mrg 151 1.1 mrg XmuNCopyISOLatin1Lowered(buf, mixed, DATA_LEN); 152 1.1 mrg g_assert_cmpstr(buf, ==, lower); 153 1.1 mrg } 154 1.1 mrg 155 1.1 mrg static void 156 1.1 mrg test_XmuNCopyISOLatin1Uppered(void) 157 1.1 mrg { 158 1.1 mrg char buf[DATA_LEN]; 159 1.1 mrg 160 1.1 mrg XmuNCopyISOLatin1Uppered(buf, upper, DATA_LEN); 161 1.1 mrg g_assert_cmpstr(buf, ==, upper); 162 1.1 mrg 163 1.1 mrg XmuNCopyISOLatin1Uppered(buf, lower, DATA_LEN); 164 1.1 mrg g_assert_cmpstr(buf, ==, upper); 165 1.1 mrg 166 1.1 mrg XmuNCopyISOLatin1Uppered(buf, mixed, DATA_LEN); 167 1.1 mrg g_assert_cmpstr(buf, ==, upper); 168 1.1 mrg } 169 1.1 mrg 170 1.1 mrg static void 171 1.1 mrg test_XmuCompareISOLatin1(void) 172 1.1 mrg { 173 1.1 mrg int cmp; 174 1.1 mrg 175 1.1 mrg cmp = XmuCompareISOLatin1(upper, lower); 176 1.1 mrg g_assert_cmpint(cmp, ==, 0); 177 1.1 mrg 178 1.1 mrg cmp = XmuCompareISOLatin1(upper, mixed); 179 1.1 mrg g_assert_cmpint(cmp, ==, 0); 180 1.1 mrg 181 1.1 mrg cmp = XmuCompareISOLatin1(lower, mixed); 182 1.1 mrg g_assert_cmpint(cmp, ==, 0); 183 1.1 mrg 184 1.1 mrg cmp = XmuCompareISOLatin1(upper + 1, lower); 185 1.1 mrg g_assert_cmpint(cmp, >, 0); 186 1.1 mrg 187 1.1 mrg cmp = XmuCompareISOLatin1(mixed, lower + 1); 188 1.1 mrg g_assert_cmpint(cmp, <, 0); 189 1.1 mrg } 190 1.1 mrg 191 1.1 mrg static void 192 1.1 mrg test_XmuSnprintf(void) 193 1.1 mrg { 194 1.1 mrg char buf[DATA_LEN]; 195 1.1 mrg int ret; 196 1.1 mrg 197 1.1 mrg g_assert_cmpint(DATA_LEN, >, 40); 198 1.1 mrg ret = XmuSnprintf(buf, 40, "%s", upper); 199 1.1 mrg g_assert_cmpint(ret, ==, sizeof(upper) - 1); 200 1.1 mrg g_assert_cmpint(buf[39], ==, 0); 201 1.1 mrg g_assert_cmpmem(buf, 39, upper, 39); 202 1.1 mrg 203 1.1 mrg ret = XmuSnprintf(buf, sizeof(buf), "%s", upper); 204 1.1 mrg g_assert_cmpint(ret, ==, sizeof(upper) - 1); 205 1.1 mrg g_assert_cmpstr(buf, ==, upper); 206 1.1 mrg 207 1.1 mrg ret = XmuSnprintf(buf, sizeof(buf), "%d", 12345678); 208 1.1 mrg g_assert_cmpint(ret, ==, 8); 209 1.1 mrg g_assert_cmpstr(buf, ==, "12345678"); 210 1.1 mrg } 211 1.1 mrg 212 1.1 mrg int 213 1.1 mrg main(int argc, char** argv) 214 1.1 mrg { 215 1.1 mrg g_test_init(&argc, &argv, NULL); 216 1.1 mrg g_test_bug_base(PACKAGE_BUGREPORT); 217 1.1 mrg 218 1.1 mrg g_assert_cmpuint(sizeof(upper), ==, sizeof(lower)); 219 1.1 mrg g_assert_cmpuint(sizeof(upper), ==, sizeof(mixed)); 220 1.1 mrg 221 1.1 mrg g_test_add_func("/Lower/XmuCopyISOLatin1Lowered", 222 1.1 mrg test_XmuCopyISOLatin1Lowered); 223 1.1 mrg g_test_add_func("/Lower/XmuCopyISOLatin1Uppered", 224 1.1 mrg test_XmuCopyISOLatin1Uppered); 225 1.1 mrg 226 1.1 mrg g_test_add_func("/Lower/XmuNCopyISOLatin1Lowered", 227 1.1 mrg test_XmuNCopyISOLatin1Lowered); 228 1.1 mrg g_test_add_func("/Lower/XmuNCopyISOLatin1Uppered", 229 1.1 mrg test_XmuNCopyISOLatin1Uppered); 230 1.1 mrg 231 1.1 mrg g_test_add_func("/Lower/XmuCompareISOLatin1", 232 1.1 mrg test_XmuCompareISOLatin1); 233 1.1 mrg g_test_add_func("/Lower/XmuSnprintf", 234 1.1 mrg test_XmuSnprintf); 235 1.1 mrg 236 1.1 mrg 237 1.1 mrg return g_test_run(); 238 1.1 mrg } 239