diff options
author | Nirbhay Choubey <nirbhay@mariadb.com> | 2016-02-13 18:28:36 -0500 |
---|---|---|
committer | Nirbhay Choubey <nirbhay@mariadb.com> | 2016-02-13 18:28:36 -0500 |
commit | d23bd26bec787ebbdbd41be0204e9cb83baf4dbd (patch) | |
tree | dda05b0ebb3858e913b0ca3b864705e989bb7661 /unittest | |
parent | b83de1151aab6dcc9f300159e31198364000de70 (diff) | |
parent | a9a08b1e2f5b7a9e3ab7c7f75c768389b1d8238f (diff) | |
download | mariadb-git-d23bd26bec787ebbdbd41be0204e9cb83baf4dbd.tar.gz |
Merge tag 'mariadb-5.5.48' into 5.5-galera
Diffstat (limited to 'unittest')
-rw-r--r-- | unittest/my_decimal/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittest/my_decimal/my_decimal-t.cc | 34 | ||||
-rw-r--r-- | unittest/mysys/CMakeLists.txt | 2 | ||||
-rw-r--r-- | unittest/mysys/dynstring-t.c | 74 |
4 files changed, 108 insertions, 4 deletions
diff --git a/unittest/my_decimal/CMakeLists.txt b/unittest/my_decimal/CMakeLists.txt index 0a38a18b7ba..85d203e8f47 100644 --- a/unittest/my_decimal/CMakeLists.txt +++ b/unittest/my_decimal/CMakeLists.txt @@ -20,4 +20,4 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/unittest/mytap) # -MY_ADD_TESTS(my_decimal EXT "cc" LINK_LIBRARIES mysys) +MY_ADD_TESTS(my_decimal EXT "cc" LINK_LIBRARIES strings dbug) 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 c4af7828e42..5a46efc8e5a 100644 --- a/unittest/mysys/CMakeLists.txt +++ b/unittest/mysys/CMakeLists.txt @@ -14,7 +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 + my_getopt dynstring LINK_LIBRARIES mysys) IF(WIN32) diff --git a/unittest/mysys/dynstring-t.c b/unittest/mysys/dynstring-t.c new file mode 100644 index 00000000000..fed8488da2c --- /dev/null +++ b/unittest/mysys/dynstring-t.c @@ -0,0 +1,74 @@ +/* Copyright (c) 2016, 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 <my_global.h> +#include <m_string.h> +#include <my_sys.h> +#include <tap.h> + +DYNAMIC_STRING str1; + +static void check(const char *res) +{ + ok(strcmp(str1.str, res) == 0, "strcmp: %s", str1.str); + str1.length= 0; +} + +int main(void) +{ + plan(23); + + IF_WIN(skip_all("Test of POSIX shell escaping rules, not for CMD.EXE\n"), ); + + ok(init_dynamic_string(&str1, NULL, 0, 32) == 0, "init"); + + ok(dynstr_append_os_quoted(&str1, "test1", NULL) == 0, "append"); + check("'test1'"); + + ok(dynstr_append_os_quoted(&str1, "con", "cat", NULL) == 0, "append"); + check("'concat'"); + + ok(dynstr_append_os_quoted(&str1, "", NULL) == 0, "append"); + check("''"); + + ok(dynstr_append_os_quoted(&str1, "space inside", NULL) == 0, "append"); + check("'space inside'"); + + ok(dynstr_append_os_quoted(&str1, "single'quote", NULL) == 0, "append"); + check("'single'\"'\"'quote'"); + + ok(dynstr_append_os_quoted(&str1, "many'single'quotes", NULL) == 0, "append"); + check("'many'\"'\"'single'\"'\"'quotes'"); + + ok(dynstr_append_os_quoted(&str1, "'single quoted'", NULL) == 0, "append"); + check("''\"'\"'single quoted'\"'\"''"); + + ok(dynstr_append_os_quoted(&str1, "double\"quote", NULL) == 0, "append"); + check("'double\"quote'"); + + ok(dynstr_append_os_quoted(&str1, "mixed\"single'and\"double'quotes", NULL) == 0, "append"); + check("'mixed\"single'\"'\"'and\"double'\"'\"'quotes'"); + + ok(dynstr_append_os_quoted(&str1, "back\\space", NULL) == 0, "append"); + check("'back\\space'"); + + ok(dynstr_append_os_quoted(&str1, "backspace\\'and\\\"quote", NULL) == 0, "append"); + check("'backspace\\'\"'\"'and\\\"quote'"); + + dynstr_free(&str1); + + return exit_status(); +} + |