mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / unittest / strings / strings-t.c
blobba1e625b35854d3f974c7d6b6ebe60fed14d3ec7
1 /* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
16 #include <tap.h>
17 #include <my_global.h>
18 #include <my_sys.h>
22 Test that like_range() returns well-formed results.
24 static int
25 test_like_range_for_charset(CHARSET_INFO *cs, const char *src, size_t src_len)
27 char min_str[32], max_str[32];
28 size_t min_len, max_len, min_well_formed_len, max_well_formed_len;
29 int error= 0;
31 cs->coll->like_range(cs, src, src_len, '\\', '_', '%',
32 sizeof(min_str), min_str, max_str, &min_len, &max_len);
33 diag("min_len=%d\tmax_len=%d\t%s", (int) min_len, (int) max_len, cs->name);
34 min_well_formed_len= cs->cset->well_formed_len(cs,
35 min_str, min_str + min_len,
36 10000, &error);
37 max_well_formed_len= cs->cset->well_formed_len(cs,
38 max_str, max_str + max_len,
39 10000, &error);
40 if (min_len != min_well_formed_len)
41 diag("Bad min_str: min_well_formed_len=%d min_str[%d]=0x%02X",
42 (int) min_well_formed_len, (int) min_well_formed_len,
43 (uchar) min_str[min_well_formed_len]);
44 if (max_len != max_well_formed_len)
45 diag("Bad max_str: max_well_formed_len=%d max_str[%d]=0x%02X",
46 (int) max_well_formed_len, (int) max_well_formed_len,
47 (uchar) max_str[max_well_formed_len]);
48 return
49 min_len == min_well_formed_len &&
50 max_len == max_well_formed_len ? 0 : 1;
54 static CHARSET_INFO *charset_list[]=
56 #ifdef HAVE_CHARSET_big5
57 &my_charset_big5_chinese_ci,
58 &my_charset_big5_bin,
59 #endif
60 #ifdef HAVE_CHARSET_euckr
61 &my_charset_euckr_korean_ci,
62 &my_charset_euckr_bin,
63 #endif
64 #ifdef HAVE_CHARSET_gb2312
65 &my_charset_gb2312_chinese_ci,
66 &my_charset_gb2312_bin,
67 #endif
68 #ifdef HAVE_CHARSET_gbk
69 &my_charset_gbk_chinese_ci,
70 &my_charset_gbk_bin,
71 #endif
72 #ifdef HAVE_CHARSET_latin1
73 &my_charset_latin1,
74 &my_charset_latin1_bin,
75 #endif
76 #ifdef HAVE_CHARSET_sjis
77 &my_charset_sjis_japanese_ci,
78 &my_charset_sjis_bin,
79 #endif
80 #ifdef HAVE_CHARSET_tis620
81 &my_charset_tis620_thai_ci,
82 &my_charset_tis620_bin,
83 #endif
84 #ifdef HAVE_CHARSET_ujis
85 &my_charset_ujis_japanese_ci,
86 &my_charset_ujis_bin,
87 #endif
88 #ifdef HAVE_CHARSET_utf8
89 &my_charset_utf8_general_ci,
90 &my_charset_utf8_unicode_ci,
91 &my_charset_utf8_bin,
92 #endif
96 int main()
98 size_t i, failed= 0;
100 plan(1);
101 diag("Testing my_like_range_xxx() functions");
103 for (i= 0; i < array_elements(charset_list); i++)
105 CHARSET_INFO *cs= charset_list[i];
106 if (test_like_range_for_charset(cs, "abc%", 4))
108 ++failed;
109 diag("Failed for %s", cs->name);
112 ok(failed == 0, "Testing my_like_range_xxx() functions");
113 return exit_status();