diff options
author | Sergei Golubchik <serg@mariadb.org> | 2015-12-13 00:10:40 +0100 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2015-12-13 00:10:40 +0100 |
commit | 162399515813a4e23c8735473f9d2dd622a6679b (patch) | |
tree | 39077fdabea60983c59899ce3d28e84c4d97c7e6 /unittest | |
parent | 5908d7ebb81bc2d52c67e519a4643372cb9f08bd (diff) | |
parent | 0ed474484c037a32bea32abaecd3ff770f40bd49 (diff) | |
download | mariadb-git-162399515813a4e23c8735473f9d2dd622a6679b.tar.gz |
Merge branch '5.5' into 10.0
Diffstat (limited to 'unittest')
-rw-r--r-- | unittest/my_decimal/my_decimal-t.cc | 34 | ||||
-rw-r--r-- | unittest/mysys/CMakeLists.txt | 1 | ||||
-rw-r--r-- | unittest/mysys/my_getopt-t.c | 71 |
3 files changed, 104 insertions, 2 deletions
diff --git a/unittest/my_decimal/my_decimal-t.cc b/unittest/my_decimal/my_decimal-t.cc index 48d00465af9..92c4bdee8e4 100644 --- a/unittest/my_decimal/my_decimal-t.cc +++ b/unittest/my_decimal/my_decimal-t.cc @@ -61,12 +61,42 @@ test_copy_and_compare() } +static int +test_decimal2string() +{ + decimal_t d1; + decimal_digit_t buffer[DECIMAL_BUFF_LENGTH+2]; + char *str_end; + const char strnum[]= "0.1234567890123456789012345678901234567890123467"; + char strbuff[50]; + int len= 40; + int i; + + bzero(strbuff, sizeof(strbuff)); + str_end= (char *)(strnum + (sizeof(strnum) - 1)); + + d1.len= DECIMAL_BUFF_LENGTH + 2; + d1.buf= buffer; + + string2decimal(strnum, &d1, &str_end); + decimal2string(&d1, strbuff, &len, 0, 0, 'X'); + + /* last digit is not checked due to possible rounding */ + for (i= 0; i < 38 && strbuff[i] == strnum[i]; i++); + ok(i == 38, "Number"); + for (i= 39; i < 50 && strbuff[i] == 0; i++); + ok(i == 50, "No overrun"); + + return 0; + +} int main() { - plan(13); + plan(15); diag("Testing my_decimal constructor and assignment operators"); test_copy_and_compare(); - + test_decimal2string(); + return exit_status(); } diff --git a/unittest/mysys/CMakeLists.txt b/unittest/mysys/CMakeLists.txt index 8c09a466451..b209da39edc 100644 --- a/unittest/mysys/CMakeLists.txt +++ b/unittest/mysys/CMakeLists.txt @@ -14,6 +14,7 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA MY_ADD_TESTS(bitmap base64 my_vsnprintf my_atomic my_rdtsc lf my_malloc + my_getopt LINK_LIBRARIES mysys) MY_ADD_TESTS(ma_dyncol diff --git a/unittest/mysys/my_getopt-t.c b/unittest/mysys/my_getopt-t.c new file mode 100644 index 00000000000..afdb5e8b3b8 --- /dev/null +++ b/unittest/mysys/my_getopt-t.c @@ -0,0 +1,71 @@ +/* Copyright (C) 2015 MariaDB + + 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-1301 USA */ + +#include <tap.h> +#include <my_getopt.h> +#include <stdarg.h> + +ulonglong opt_ull; +ulong opt_ul; +int argc, res; +char **argv, *args[100]; + +struct my_option my_long_options[]= +{ + {"ull", 0, "ull", &opt_ull, &opt_ull, + 0, GET_ULL, REQUIRED_ARG, 1, 0, ~0ULL, 0, 0, 0}, + {"ul", 0, "ul", &opt_ul, &opt_ul, + 0, GET_ULONG, REQUIRED_ARG, 1, 0, 0xFFFFFFFF, 0, 0, 0}, + {0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0} +}; + +void run(const char *arg, ...) +{ + va_list ap; + va_start(ap, arg); + argv= args; + *argv++= (char*)"<skipped>"; + while (arg) + { + *argv++= (char*)arg; + arg= va_arg(ap, char*); + } + va_end(ap); + argc= argv - args; + argv= args; + res= handle_options(&argc, &argv, my_long_options, 0); +} + +int main() { + plan(3); + + run("--ull=100", NULL); + ok(res==0 && argc==0 && opt_ull==100, + "res:%d, argc:%d, opt_ull:%llu", res, argc, opt_ull); + + /* + negative numbers are wrapped. this is kinda questionable, + we might want to fix it eventually. but it'd be a change in behavior, + users might've got used to "-1" meaning "max possible value" + */ + run("--ull=-100", NULL); + ok(res==0 && argc==0 && opt_ull==18446744073709551516ULL, + "res:%d, argc:%d, opt_ull:%llu", res, argc, opt_ull); + run("--ul=-100", NULL); + ok(res==0 && argc==0 && opt_ul==4294967295UL, + "res:%d, argc:%d, opt_ul:%lu", res, argc, opt_ul); + return exit_status(); +} + |