summaryrefslogtreecommitdiff
path: root/unittest
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2015-12-21 21:24:22 +0100
committerSergei Golubchik <serg@mariadb.org>2015-12-21 21:24:22 +0100
commita2bcee626d4ef2836e38e4932305871390164644 (patch)
treeb41e357427318bad8985078b91bbd2b0360defc8 /unittest
parent1788bfe93a745582d938a608d5959b7d2e6b2f23 (diff)
parent4fdf25afa8188905653a83e08fc387243e584600 (diff)
downloadmariadb-git-a2bcee626d4ef2836e38e4932305871390164644.tar.gz
Merge branch '10.0' into 10.1
Diffstat (limited to 'unittest')
-rw-r--r--unittest/my_decimal/my_decimal-t.cc34
-rw-r--r--unittest/mysys/my_getopt-t.c45
2 files changed, 76 insertions, 3 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/my_getopt-t.c b/unittest/mysys/my_getopt-t.c
index c4c26e88624..39814d76690 100644
--- a/unittest/mysys/my_getopt-t.c
+++ b/unittest/mysys/my_getopt-t.c
@@ -28,8 +28,14 @@
#include <my_global.h>
#include <my_getopt.h>
#include <mysys_err.h>
+#include <stdarg.h>
#include <tap.h>
+ulonglong opt_ull;
+ulong opt_ul;
+int arg_c, res;
+char **arg_v, *arg_s[100];
+
ulong mopts_num;
char *mopts_str;
my_bool mopts_bool;
@@ -47,9 +53,30 @@ static struct my_option mopts_options[]=
"Something numeric.",
&mopts_num, &mopts_num, 0, GET_ULONG,
REQUIRED_ARG, 1000000L, 1, ULONG_MAX, 0, 2, 0},
+ {"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);
+ arg_v= arg_s;
+ *arg_v++= (char*)"<skipped>";
+ while (arg)
+ {
+ *arg_v++= (char*)arg;
+ arg= va_arg(ap, char*);
+ }
+ va_end(ap);
+ arg_c= arg_v - arg_s;
+ arg_v= arg_s;
+ res= handle_options(&arg_c, &arg_v, mopts_options, 0);
+}
+
int mopts1_argc= 4;
const char *mopts1_argv[]= {"mopts1", "--num=123", "--str=str", "--bool"};
void test_mopts1()
@@ -324,7 +351,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);
+ plan(4*8 + 1*4 + 3*4 + 3*2 + 3);
/* 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";
@@ -351,6 +378,22 @@ int main(int argc __attribute__((unused)), char **argv)
test_max1();
test_max2();
+ run("--ull=100", NULL);
+ ok(res==0 && arg_c==0 && opt_ull==100,
+ "res:%d, argc:%d, opt_ull:%llu", res, arg_c, 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 && arg_c==0 && opt_ull==18446744073709551516ULL,
+ "res:%d, argc:%d, opt_ull:%llu", res, arg_c, opt_ull);
+ run("--ul=-100", NULL);
+ ok(res==0 && arg_c==0 && opt_ul==4294967295UL,
+ "res:%d, argc:%d, opt_ul:%lu", res, arg_c, opt_ul);
+
my_end(0);
return exit_status();
}