diff options
Diffstat (limited to 'unittest')
-rw-r--r-- | unittest/json_lib/json_lib-t.c | 2 | ||||
-rw-r--r-- | unittest/mysys/CMakeLists.txt | 4 | ||||
-rw-r--r-- | unittest/mysys/crc32-t.c | 69 | ||||
-rw-r--r-- | unittest/mysys/ma_dyncol-t.c | 8 | ||||
-rw-r--r-- | unittest/mysys/my_getopt-t.c | 53 | ||||
-rw-r--r-- | unittest/mysys/my_malloc-t.c | 6 | ||||
-rw-r--r-- | unittest/sql/explain_filename-t.cc | 2 | ||||
-rw-r--r-- | unittest/strings/strings-t.c | 31 |
8 files changed, 120 insertions, 55 deletions
diff --git a/unittest/json_lib/json_lib-t.c b/unittest/json_lib/json_lib-t.c index 11f02b204f8..378ebe201f5 100644 --- a/unittest/json_lib/json_lib-t.c +++ b/unittest/json_lib/json_lib-t.c @@ -173,7 +173,7 @@ test_search() int main() { - ci= &my_charset_utf8_general_ci; + ci= &my_charset_utf8mb3_general_ci; plan(6); diag("Testing json_lib functions."); diff --git a/unittest/mysys/CMakeLists.txt b/unittest/mysys/CMakeLists.txt index 984b033e7aa..4b947ab780f 100644 --- a/unittest/mysys/CMakeLists.txt +++ b/unittest/mysys/CMakeLists.txt @@ -15,11 +15,11 @@ MY_ADD_TESTS(bitmap base64 my_atomic my_rdtsc lf my_malloc my_getopt dynstring byte_order - queues stacktrace LINK_LIBRARIES mysys) + queues stacktrace crc32 LINK_LIBRARIES mysys) MY_ADD_TESTS(my_vsnprintf LINK_LIBRARIES strings mysys) MY_ADD_TESTS(aes LINK_LIBRARIES mysys mysys_ssl) ADD_DEFINITIONS(${SSL_DEFINES}) - +INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIR}) MY_ADD_TESTS(ma_dyncol LINK_LIBRARIES mysys) IF(WIN32) diff --git a/unittest/mysys/crc32-t.c b/unittest/mysys/crc32-t.c new file mode 100644 index 00000000000..9834d21769b --- /dev/null +++ b/unittest/mysys/crc32-t.c @@ -0,0 +1,69 @@ +/* Copyright (c) MariaDB 2020 + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; version 2 of the License. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */ + +#include <my_global.h> +#include <my_sys.h> +#include <my_crypt.h> +#include <tap.h> +#include <string.h> +#include <ctype.h> +#include <zlib.h> + +/* + Check that optimized crc32 (ieee, or ethernet polynomical) returns the same + result as zlib (not so well optimized, yet, but trustworthy) +*/ +#define DO_TEST_CRC32(crc,str) \ + ok(crc32(crc,(const Bytef *)str,(uint)(sizeof(str)-1)) == my_checksum(crc, str, sizeof(str)-1), "crc32 '%s'",str) + +/* Check that CRC32-C calculation returns correct result*/ +#define DO_TEST_CRC32C(crc,str,expected) \ + do { \ + unsigned int v = my_crc32c(crc, str, sizeof(str)-1); \ + printf("crc32(%u,'%s',%zu)=%u\n",crc,str,sizeof(str)-1,v); \ + ok(expected == my_crc32c(crc, str, sizeof(str)-1),"crc32c '%s'",str); \ + }while(0) + + +#define LONG_STR "1234567890234568900212345678901231213123321212123123123123123"\ + "............................................................................." \ + "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" \ + "yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy" \ + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" + +int main(int argc __attribute__((unused)),char *argv[]) +{ + MY_INIT(argv[0]); + plan(14); + printf("%s\n",my_crc32c_implementation()); + DO_TEST_CRC32(0,""); + DO_TEST_CRC32(1,""); + DO_TEST_CRC32(0,"12345"); + DO_TEST_CRC32(1,"12345"); + DO_TEST_CRC32(0,"1234567890123456789"); + DO_TEST_CRC32(0, LONG_STR); + ok(0 == my_checksum(0, NULL, 0) , "crc32 data = NULL, length = 0"); + + DO_TEST_CRC32C(0,"", 0); + DO_TEST_CRC32C(1,"", 1); + DO_TEST_CRC32C(0, "12345", 416359221); + DO_TEST_CRC32C(1, "12345", 549473433); + DO_TEST_CRC32C(0, "1234567890123456789", 2366987449U); + DO_TEST_CRC32C(0, LONG_STR, 3009234172U); + ok(0 == my_crc32c(0, NULL, 0), "crc32c data = NULL, length = 0"); + + my_end(0); + return exit_status(); +} diff --git a/unittest/mysys/ma_dyncol-t.c b/unittest/mysys/ma_dyncol-t.c index 124f16e15be..d76f1b49f8f 100644 --- a/unittest/mysys/ma_dyncol-t.c +++ b/unittest/mysys/ma_dyncol-t.c @@ -197,12 +197,12 @@ static CHARSET_INFO *charset_list[]= &my_charset_ujis_japanese_ci, &my_charset_ujis_bin, #endif -#ifdef HAVE_CHARSET_utf8 - &my_charset_utf8_general_ci, +#ifdef HAVE_CHARSET_utf8mb3 + &my_charset_utf8mb3_general_ci, #ifdef HAVE_UCA_COLLATIONS - &my_charset_utf8_unicode_ci, + &my_charset_utf8mb3_unicode_ci, #endif - &my_charset_utf8_bin, + &my_charset_utf8mb3_bin, #endif }; diff --git a/unittest/mysys/my_getopt-t.c b/unittest/mysys/my_getopt-t.c index 3e16d79424e..4b50468ac3f 100644 --- a/unittest/mysys/my_getopt-t.c +++ b/unittest/mysys/my_getopt-t.c @@ -60,6 +60,13 @@ static struct my_option mopts_options[]= { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} }; +my_bool dummy_get_one_option(const struct my_option *opt __attribute__((unused)), + const char *argument __attribute__((unused)), + const char *filename __attribute__((unused))) +{ + return FALSE; +} + void run(const char *arg, ...) { va_list ap; @@ -74,7 +81,7 @@ void run(const char *arg, ...) va_end(ap); arg_c= (int)(arg_v - arg_s); arg_v= arg_s; - res= handle_options(&arg_c, &arg_v, mopts_options, 0); + res= handle_options(&arg_c, &arg_v, mopts_options, &dummy_get_one_option); } int mopts1_argc= 4; @@ -84,7 +91,7 @@ void test_mopts1() int rc; char **av= (char **)mopts1_argv; - rc= handle_options(&mopts1_argc, &av, mopts_options, NULL); + rc= handle_options(&mopts1_argc, &av, mopts_options, &dummy_get_one_option); ok( (rc == 0), "%s", "test_mopts1 call"); ok( (mopts_num == 122), "%s", "test_mopts1 num"); ok( (strncmp(mopts_str, "str", 4) == 0), "%s", "test_mopts1 str"); @@ -98,7 +105,7 @@ void test_mopts2() int rc; char **av= (char **)mopts2_argv; - rc= handle_options(&mopts2_argc, &av, mopts_options, NULL); + rc= handle_options(&mopts2_argc, &av, mopts_options, &dummy_get_one_option); ok( (rc == 0), "%s", "test_mopts2 call"); ok( (mopts_num == 124), "%s", "test_mopts2 num"); ok( (strncmp(mopts_str, "ddd", 4) == 0), "%s", "test_mopts2 str"); @@ -112,7 +119,7 @@ void test_mopts3() int rc; char **av= (char **)mopts3_argv; - rc= handle_options(&mopts3_argc, &av, mopts_options, NULL); + rc= handle_options(&mopts3_argc, &av, mopts_options, &dummy_get_one_option); ok( (rc == 0), "%s", "test_mopts3 call"); ok( (mopts_num == 1000000L), "%s", "test_mopts3 num"); ok( (strncmp(mopts_str, "ddd", 4) == 0), "%s", "test_mopts3 str"); @@ -126,7 +133,7 @@ void test_mopts4() int rc; char **av= (char **)mopts4_argv; - rc= handle_options(&mopts4_argc, &av, mopts_options, NULL); + rc= handle_options(&mopts4_argc, &av, mopts_options, &dummy_get_one_option); ok( (rc == 0), "%s", "test_mopts4 call"); ok( (mopts_num == 1000000L), "%s", "test_mopts4 num"); ok( (strncmp(mopts_str, "aa", 3) == 0), "%s", "test_mopts4 str"); @@ -140,7 +147,7 @@ void test_mopts5() int rc; char **av= (char **)mopts5_argv; - rc= handle_options(&mopts5_argc, &av, mopts_options, NULL); + rc= handle_options(&mopts5_argc, &av, mopts_options, &dummy_get_one_option); ok( (rc == 0), "%s", "test_mopts5 call"); ok( (mopts_num == 1000000L), "%s", "test_mopts5 num"); ok( (strncmp(mopts_str, "ddd", 4) == 0), "%s", "test_mopts5 str"); @@ -154,7 +161,7 @@ void test_mopts6() int rc; char **av= (char **)mopts6_argv; - rc= handle_options(&mopts6_argc, &av, mopts_options, NULL); + rc= handle_options(&mopts6_argc, &av, mopts_options, &dummy_get_one_option); ok( (rc == 0), "%s", "test_mopts6 call"); ok( (mopts_num == 1000000L), "%s", "test_mopts6 num"); ok( (strncmp(mopts_str, "ddd", 4) == 0), "%s", "test_mopts6 str"); @@ -168,7 +175,7 @@ void test_mopts7() int rc; char **av= (char **)mopts7_argv; - rc= handle_options(&mopts7_argc, &av, mopts_options, NULL); + rc= handle_options(&mopts7_argc, &av, mopts_options, &dummy_get_one_option); ok( (rc == 0), "%s", "test_mopts7 call"); ok( (mopts_num == 1000000L), "%s", "test_mopts7 num"); ok( (strncmp(mopts_str, "ddd", 4) == 0), "%s", "test_mopts7 str"); @@ -182,7 +189,7 @@ void test_mopts8() int rc; char **av= (char **)mopts8_argv; - rc= handle_options(&mopts8_argc, &av, mopts_options, NULL); + rc= handle_options(&mopts8_argc, &av, mopts_options, &dummy_get_one_option); ok( (rc == 0), "%s", "test_mopts8 call"); ok( (mopts_num == 1000000L), "%s", "test_mopts7 num"); ok( (strncmp(mopts_str, "ddd", 4) == 0), "%s", "test_mopts7 str"); @@ -196,7 +203,7 @@ void test_mopts9() int rc; char **av= (char **)mopts9_argv; - rc= handle_options(&mopts9_argc, &av, mopts_options, NULL); + rc= handle_options(&mopts9_argc, &av, mopts_options, &dummy_get_one_option); ok( (rc != 0), "%s", "test_mopts9 call"); } @@ -207,7 +214,7 @@ void test_mopts10() int rc; char **av= (char **)mopts10_argv; - rc= handle_options(&mopts10_argc, &av, mopts_options, NULL); + rc= handle_options(&mopts10_argc, &av, mopts_options, &dummy_get_one_option); ok( (rc != 0), "%s", "test_mopts10 call"); } @@ -227,9 +234,9 @@ static struct my_option auto_options[]= -my_bool auto_get_one_option(int optid __attribute__((unused)), - const struct my_option *opt, - char *argument) +my_bool auto_get_one_option(const struct my_option *opt, + const char *argument, + const char *filename __attribute__((unused))) { if (argument == autoset_my_option) { @@ -238,17 +245,6 @@ my_bool auto_get_one_option(int optid __attribute__((unused)), return FALSE; } -int auto1_argc= 3; -const char *auto1_argv[]= {"auto1", "--anum=123", "--autoset-anum"}; -void test_auto1() -{ - int rc; - char **av= (char **)auto1_argv; - - rc= handle_options(&auto1_argc, &av, auto_options, NULL); - ok( (rc == EXIT_ARGUMENT_INVALID), "%s", "test_auto1 call"); -} - int auto2_argc= 3; const char *auto2_argv[]= {"auto2", "--num=123", "--autoset-num"}; void test_auto2() @@ -330,7 +326,7 @@ void test_max1() int rc; char **av= (char **)max1_argv; - rc= handle_options(&max1_argc, &av, max_options, NULL); + rc= handle_options(&max1_argc, &av, max_options, &dummy_get_one_option); ok( (rc == 0), "%s", "test_max1 call"); ok( (mopts_num == 200), "%s", "test_max1 num"); ok( (max_num == 1000001L), "%s", "test_max1 max_num"); @@ -342,7 +338,7 @@ void test_max2() int rc; char **av= (char **)max2_argv; - rc= handle_options(&max2_argc, &av, max_options, NULL); + rc= handle_options(&max2_argc, &av, max_options, &dummy_get_one_option); ok( (rc == 0), "%s", "test_max2 call"); ok( (mopts_num == 200), "%s", "test_max2 num"); ok( (max_num == 100), "%s", "test_max2 max_num"); @@ -351,7 +347,7 @@ void test_max2() int main(int argc __attribute__((unused)), char **argv) { MY_INIT(argv[0]); - plan(4*8 + 1*4 + 3*4 + 3*2 + 3); + plan(4*8 + 1*4 + 3*4 + 3*2 + 2); /* gcc 4.1.2 doesn't want it in the initializer, we have to do it run-time */ mopts_options[0].def_value= (intptr)"ddd"; @@ -367,7 +363,6 @@ int main(int argc __attribute__((unused)), char **argv) test_mopts9(); test_mopts10(); - test_auto1(); test_auto2(); test_auto3(); diff --git a/unittest/mysys/my_malloc-t.c b/unittest/mysys/my_malloc-t.c index d20ef052380..0ee6b2b9191 100644 --- a/unittest/mysys/my_malloc-t.c +++ b/unittest/mysys/my_malloc-t.c @@ -24,13 +24,13 @@ int main(int argc __attribute__((unused)),char *argv[]) plan(4); - p= my_malloc(0, MYF(0)); + p= my_malloc(PSI_NOT_INSTRUMENTED, 0, MYF(0)); ok(p != NULL, "Zero-sized block allocation."); - p= my_realloc(p, 32, MYF(0)); + p= my_realloc(PSI_NOT_INSTRUMENTED, p, 32, MYF(0)); ok(p != NULL, "Reallocated zero-sized block."); - p= my_realloc(p, 16, MYF(0)); + p= my_realloc(PSI_NOT_INSTRUMENTED, p, 16, MYF(0)); ok(p != NULL, "Trimmed block."); my_free(p); diff --git a/unittest/sql/explain_filename-t.cc b/unittest/sql/explain_filename-t.cc index 859cb0cdaa4..32291d5e621 100644 --- a/unittest/sql/explain_filename-t.cc +++ b/unittest/sql/explain_filename-t.cc @@ -31,7 +31,7 @@ static const char **error_messages[1]= { error_messages_txt }; int setup() { - system_charset_info = &my_charset_utf8_bin; + system_charset_info = &my_charset_utf8mb3_bin; my_default_lc_messages = &my_locale_en_US; /* Populate the necessary error messages */ diff --git a/unittest/strings/strings-t.c b/unittest/strings/strings-t.c index 00d49971595..768f0ba6b65 100644 --- a/unittest/strings/strings-t.c +++ b/unittest/strings/strings-t.c @@ -1,4 +1,5 @@ /* Copyright (c) 2010, Oracle and/or its affiliates + Copyright (c) 2009, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -28,8 +29,8 @@ test_like_range_for_charset(CHARSET_INFO *cs, const char *src, size_t src_len) size_t min_len, max_len, min_well_formed_len, max_well_formed_len; int error= 0; - cs->coll->like_range(cs, src, src_len, '\\', '_', '%', - sizeof(min_str), min_str, max_str, &min_len, &max_len); + my_ci_like_range(cs, src, src_len, '\\', '_', '%', + sizeof(min_str), min_str, max_str, &min_len, &max_len); diag("min_len=%d\tmax_len=%d\t%s", (int) min_len, (int) max_len, cs->name); min_well_formed_len= my_well_formed_length(cs, min_str, min_str + min_len, @@ -85,12 +86,12 @@ static CHARSET_INFO *charset_list[]= &my_charset_ujis_japanese_ci, &my_charset_ujis_bin, #endif -#ifdef HAVE_CHARSET_utf8 - &my_charset_utf8_general_ci, +#ifdef HAVE_CHARSET_utf8mb3 + &my_charset_utf8mb3_general_ci, #ifdef HAVE_UCA_COLLATIONS - &my_charset_utf8_unicode_ci, + &my_charset_utf8mb3_unicode_ci, #endif - &my_charset_utf8_bin, + &my_charset_utf8mb3_bin, #endif }; @@ -626,8 +627,8 @@ strcollsp(CHARSET_INFO *cs, const STRNNCOLL_PARAM *param) for (p= param; p->a; p++) { char ahex[64], bhex[64]; - int res= cs->coll->strnncollsp(cs, (uchar *) p->a, p->alen, - (uchar *) p->b, p->blen); + int res= my_ci_strnncollsp(cs, (const uchar *) p->a, p->alen, + (const uchar *) p->b, p->blen); str2hex(ahex, sizeof(ahex), p->a, p->alen); str2hex(bhex, sizeof(bhex), p->b, p->blen); diag("%-20s %-10s %-10s %10d %10d%s", @@ -640,8 +641,8 @@ strcollsp(CHARSET_INFO *cs, const STRNNCOLL_PARAM *param) else { /* Test in reverse order */ - res= cs->coll->strnncollsp(cs, (uchar *) p->b, p->blen, - (uchar *) p->a, p->alen); + res= my_ci_strnncollsp(cs, (const uchar *) p->b, p->blen, + (const uchar *) p->a, p->alen); if (!eqres(res, -p->res)) { diag("Comparison in reverse order failed. Expected %d, got %d", @@ -743,9 +744,9 @@ test_strcollsp() failed+= strcollsp(&my_charset_utf32_bin, strcoll_utf32_common); #endif #ifdef HAVE_CHARSET_utf8 - failed+= strcollsp(&my_charset_utf8_general_ci, strcoll_utf8mb3_common); - failed+= strcollsp(&my_charset_utf8_general_mysql500_ci, strcoll_utf8mb3_common); - failed+= strcollsp(&my_charset_utf8_bin, strcoll_utf8mb3_common); + failed+= strcollsp(&my_charset_utf8mb3_general_ci, strcoll_utf8mb3_common); + failed+= strcollsp(&my_charset_utf8mb3_general_mysql500_ci, strcoll_utf8mb3_common); + failed+= strcollsp(&my_charset_utf8mb3_bin, strcoll_utf8mb3_common); #endif #ifdef HAVE_CHARSET_utf8mb4 failed+= strcollsp(&my_charset_utf8mb4_general_ci, strcoll_utf8mb3_common); @@ -776,9 +777,9 @@ int main() } ok(failed == 0, "Testing my_like_range_xxx() functions"); - diag("Testing cs->coll->strnncollsp()"); + diag("my_ci_strnncollsp()"); failed= test_strcollsp(); - ok(failed == 0, "Testing cs->coll->strnncollsp()"); + ok(failed == 0, "Testing my_ci_strnncollsp()"); return exit_status(); } |