summaryrefslogtreecommitdiff
path: root/unittest/mysys
diff options
context:
space:
mode:
Diffstat (limited to 'unittest/mysys')
-rw-r--r--unittest/mysys/CMakeLists.txt3
-rw-r--r--unittest/mysys/base64-t.c2
-rw-r--r--unittest/mysys/bitmap-t.c10
-rw-r--r--unittest/mysys/ma_dyncol-t.c264
-rw-r--r--unittest/mysys/my_vsnprintf-t.c115
5 files changed, 242 insertions, 152 deletions
diff --git a/unittest/mysys/CMakeLists.txt b/unittest/mysys/CMakeLists.txt
index 95f54acf419..41822b1e195 100644
--- a/unittest/mysys/CMakeLists.txt
+++ b/unittest/mysys/CMakeLists.txt
@@ -17,6 +17,9 @@ MY_ADD_TESTS(bitmap base64 my_atomic my_rdtsc lf my_malloc my_getopt dynstring
LINK_LIBRARIES mysys)
MY_ADD_TESTS(my_vsnprintf LINK_LIBRARIES strings mysys)
+MY_ADD_TESTS(ma_dyncol
+ LINK_LIBRARIES mysqlclient)
+
IF(WIN32)
MY_ADD_TESTS(my_delete LINK_LIBRARIES mysys)
ENDIF()
diff --git a/unittest/mysys/base64-t.c b/unittest/mysys/base64-t.c
index f4496f570f9..60be4434150 100644
--- a/unittest/mysys/base64-t.c
+++ b/unittest/mysys/base64-t.c
@@ -60,7 +60,7 @@ main(int argc __attribute__((unused)),char *argv[])
/* Decode */
dst= (char *) malloc(base64_needed_decoded_length(strlen(str)));
- dst_len= base64_decode(str, strlen(str), dst, NULL);
+ dst_len= base64_decode(str, strlen(str), dst, NULL, 0);
ok(dst_len == src_len, "Comparing lengths");
cmp= memcmp(src, dst, src_len);
diff --git a/unittest/mysys/bitmap-t.c b/unittest/mysys/bitmap-t.c
index 0666f4eaa15..c4588779c9b 100644
--- a/unittest/mysys/bitmap-t.c
+++ b/unittest/mysys/bitmap-t.c
@@ -129,8 +129,8 @@ my_bool test_compare_operators(MY_BITMAP *map, uint bitsize)
MY_BITMAP *map2= &map2_obj, *map3= &map3_obj;
my_bitmap_map map2buf[MAX_TESTED_BITMAP_SIZE];
my_bitmap_map map3buf[MAX_TESTED_BITMAP_SIZE];
- bitmap_init(&map2_obj, map2buf, bitsize, FALSE);
- bitmap_init(&map3_obj, map3buf, bitsize, FALSE);
+ my_bitmap_init(&map2_obj, map2buf, bitsize, FALSE);
+ my_bitmap_init(&map3_obj, map3buf, bitsize, FALSE);
bitmap_clear_all(map2);
bitmap_clear_all(map3);
for (i=0; i < no_loops; i++)
@@ -374,7 +374,7 @@ my_bool test_compare(MY_BITMAP *map, uint bitsize)
uint32 map2buf[MAX_TESTED_BITMAP_SIZE];
uint i, test_bit;
uint no_loops= bitsize > 128 ? 128 : bitsize;
- if (bitmap_init(&map2, map2buf, bitsize, FALSE))
+ if (my_bitmap_init(&map2, map2buf, bitsize, FALSE))
{
diag("init error for bitsize %d", bitsize);
return TRUE;
@@ -433,7 +433,7 @@ my_bool test_intersect(MY_BITMAP *map, uint bitsize)
MY_BITMAP map2;
uint32 map2buf[MAX_TESTED_BITMAP_SIZE];
uint i, test_bit1, test_bit2, test_bit3;
- if (bitmap_init(&map2, map2buf, bitsize2, FALSE))
+ if (my_bitmap_init(&map2, map2buf, bitsize2, FALSE))
{
diag("init error for bitsize %d", bitsize2);
return TRUE;
@@ -481,7 +481,7 @@ my_bool do_test(uint bitsize)
{
MY_BITMAP map;
my_bitmap_map buf[MAX_TESTED_BITMAP_SIZE];
- if (bitmap_init(&map, buf, bitsize, FALSE))
+ if (my_bitmap_init(&map, buf, bitsize, FALSE))
{
diag("init error for bitsize %d", bitsize);
goto error;
diff --git a/unittest/mysys/ma_dyncol-t.c b/unittest/mysys/ma_dyncol-t.c
index 4a9b687bc08..3b43c10a6a8 100644
--- a/unittest/mysys/ma_dyncol-t.c
+++ b/unittest/mysys/ma_dyncol-t.c
@@ -35,96 +35,100 @@
void test_value_single_null()
{
int rc= FALSE;
+ uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
val.type= DYN_COL_NULL;
- dynamic_column_value_init(&res);
+ mariadb_dyncol_value_init(&res);
/* create column */
- if (dynamic_column_create(&str, 1, &val))
+ if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
- if (dynamic_column_get(&str, 1, &res))
+ if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= (res.type == DYN_COL_NULL);
err:
ok(rc, "%s", "NULL");
/* cleanup */
- dynamic_column_column_free(&str);
+ mariadb_dyncol_free(&str);
}
void test_value_single_uint(ulonglong num, const char *name)
{
int rc= FALSE;
+ uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
val.type= DYN_COL_UINT;
val.x.ulong_value= num;
- dynamic_column_value_init(&res);
+ mariadb_dyncol_value_init(&res);
/* create column */
- if (dynamic_column_create(&str, 1, &val))
+ if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
- if (dynamic_column_get(&str, 1, &res))
+ if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= (res.type == DYN_COL_UINT) && (res.x.ulong_value == num);
num= res.x.ulong_value;
err:
ok(rc, "%s - %llu", name, num);
/* cleanup */
- dynamic_column_column_free(&str);
+ mariadb_dyncol_free(&str);
}
void test_value_single_sint(longlong num, const char *name)
{
int rc= FALSE;
+ uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
val.type= DYN_COL_INT;
val.x.long_value= num;
- dynamic_column_value_init(&res);
+ mariadb_dyncol_value_init(&res);
/* create column */
- if (dynamic_column_create(&str, 1, &val))
+ if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
- if (dynamic_column_get(&str, 1, &res))
+ if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= (res.type == DYN_COL_INT) && (res.x.long_value == num);
num= res.x.ulong_value;
err:
ok(rc, "%s - %lld", name, num);
/* cleanup */
- dynamic_column_column_free(&str);
+ mariadb_dyncol_free(&str);
}
void test_value_single_double(double num, const char *name)
{
int rc= FALSE;
+ uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
val.type= DYN_COL_DOUBLE;
val.x.double_value= num;
- dynamic_column_value_init(&res);
+ mariadb_dyncol_value_init(&res);
/* create column */
- if (dynamic_column_create(&str, 1, &val))
+ if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
- if (dynamic_column_get(&str, 1, &res))
+ if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= (res.type == DYN_COL_DOUBLE) && (res.x.double_value == num);
num= res.x.ulong_value;
err:
ok(rc, "%s - %lf", name, num);
/* cleanup */
- dynamic_column_column_free(&str);
+ mariadb_dyncol_free(&str);
}
void test_value_single_decimal(const char *num)
@@ -133,21 +137,22 @@ void test_value_single_decimal(const char *num)
char buff[80];
int rc= FALSE;
int length= 80;
+ uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
- dynamic_column_prepare_decimal(&val); // special procedure for decimal!!!
+ mariadb_dyncol_prepare_decimal(&val); // special procedure for decimal!!!
if (string2decimal(num, &val.x.decimal.value, &end) != E_DEC_OK)
goto err;
- dynamic_column_value_init(&res);
+ mariadb_dyncol_value_init(&res);
/* create column */
- if (dynamic_column_create(&str, 1, &val))
+ if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
- if (dynamic_column_get(&str, 1, &res))
+ if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= ((res.type == DYN_COL_DECIMAL) &&
(decimal_cmp(&res.x.decimal.value, &val.x.decimal.value) == 0));
@@ -155,7 +160,7 @@ void test_value_single_decimal(const char *num)
err:
ok(rc, "%s - %s", num, buff);
/* cleanup */
- dynamic_column_column_free(&str);
+ mariadb_dyncol_free(&str);
}
static CHARSET_INFO *charset_list[]=
@@ -206,6 +211,7 @@ void test_value_single_string(const char *string, size_t len,
CHARSET_INFO *cs)
{
int rc= FALSE;
+ uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
@@ -214,14 +220,14 @@ void test_value_single_string(const char *string, size_t len,
val.x.string.value.str= (char*)string;
val.x.string.value.length= len;
val.x.string.charset= cs;
- dynamic_column_value_init(&res);
+ mariadb_dyncol_value_init(&res);
/* create column */
- if (dynamic_column_create(&str, 1, &val))
+ if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
- if (dynamic_column_get(&str, 1, &res))
+ if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= ((res.type == DYN_COL_STRING) &&
(res.x.string.value.length == len) &&
@@ -233,12 +239,13 @@ err:
(uint)res.x.string.charset->number, res.x.string.charset->name);
/* cleanup */
val.x.string.value.str= NULL; // we did not allocated it
- dynamic_column_column_free(&str);
+ mariadb_dyncol_free(&str);
}
void test_value_single_date(uint year, uint month, uint day, const char *name)
{
int rc= FALSE;
+ uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
@@ -247,13 +254,13 @@ void test_value_single_date(uint year, uint month, uint day, const char *name)
val.x.time_value.year= year;
val.x.time_value.month= month;
val.x.time_value.day= day;
- dynamic_column_value_init(&res);
+ mariadb_dyncol_value_init(&res);
/* create column */
- if (dynamic_column_create(&str, 1, &val))
+ if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
- if (dynamic_column_get(&str, 1, &res))
+ if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= ((res.type == DYN_COL_DATE) &&
(res.x.time_value.time_type == MYSQL_TIMESTAMP_DATE) &&
@@ -263,13 +270,14 @@ void test_value_single_date(uint year, uint month, uint day, const char *name)
err:
ok(rc, "%s - %04u-%02u-%02u", name, year, month, day);
/* cleanup */
- dynamic_column_column_free(&str);
+ mariadb_dyncol_free(&str);
}
void test_value_single_time(uint neg, uint hour, uint minute, uint second,
uint mic, const char *name)
{
int rc= FALSE;
+ uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
@@ -280,13 +288,13 @@ void test_value_single_time(uint neg, uint hour, uint minute, uint second,
val.x.time_value.minute= minute;
val.x.time_value.second= second;
val.x.time_value.second_part= mic;
- dynamic_column_value_init(&res);
+ mariadb_dyncol_value_init(&res);
/* create column */
- if (dynamic_column_create(&str, 1, &val))
+ if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
- if (dynamic_column_get(&str, 1, &res))
+ if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= ((res.type == DYN_COL_TIME) &&
(res.x.time_value.time_type == MYSQL_TIMESTAMP_TIME) &&
@@ -299,7 +307,7 @@ err:
ok(rc, "%s - %c%02u:%02u:%02u.%06u", name, (neg ? '-' : '+'),
hour, minute, second, mic);
/* cleanup */
- dynamic_column_column_free(&str);
+ mariadb_dyncol_free(&str);
}
@@ -308,6 +316,7 @@ void test_value_single_datetime(uint neg, uint year, uint month, uint day,
uint mic, const char *name)
{
int rc= FALSE;
+ uint ids[1]= {1};
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
/* init values */
@@ -321,13 +330,13 @@ void test_value_single_datetime(uint neg, uint year, uint month, uint day,
val.x.time_value.minute= minute;
val.x.time_value.second= second;
val.x.time_value.second_part= mic;
- dynamic_column_value_init(&res);
+ mariadb_dyncol_value_init(&res);
/* create column */
- if (dynamic_column_create(&str, 1, &val))
+ if (mariadb_dyncol_create_many_num(&str, 1, ids, &val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
- if (dynamic_column_get(&str, 1, &res))
+ if (mariadb_dyncol_get_num(&str, 1, &res))
goto err;
rc= ((res.type == DYN_COL_DATETIME) &&
(res.x.time_value.time_type == MYSQL_TIMESTAMP_DATETIME) &&
@@ -343,7 +352,7 @@ err:
ok(rc, "%s - %c %04u-%02u-%02u %02u:%02u:%02u.%06u", name, (neg ? '-' : '+'),
year, month, day, hour, minute, second, mic);
/* cleanup */
- dynamic_column_column_free(&str);
+ mariadb_dyncol_free(&str);
}
@@ -373,7 +382,7 @@ void test_value_multi(ulonglong num0,
val[1].x.long_value= num1;
val[2].type= DYN_COL_DOUBLE;
val[2].x.double_value= num2;
- dynamic_column_prepare_decimal(val + 3); // special procedure for decimal!!!
+ mariadb_dyncol_prepare_decimal(val + 3); // special procedure for decimal!!!
if (string2decimal(num3, &val[3].x.decimal.value, &end3) != E_DEC_OK)
goto err;
val[4].type= DYN_COL_STRING;
@@ -404,14 +413,14 @@ void test_value_multi(ulonglong num0,
val[7].x.time_value.second_part= mic7;
val[8].type= DYN_COL_NULL;
for (i= 0; i < 9; i++)
- dynamic_column_value_init(res + i);
+ mariadb_dyncol_value_init(res + i);
/* create column */
- if (dynamic_column_create_many(&str, 9, column_numbers, val))
+ if (mariadb_dyncol_create_many_num(&str, 9, column_numbers, val, 1))
goto err;
dynstr_append(&str, "\1"); str.length--; //check for overflow
/* read column */
for (i= 0; i < 9; i++)
- if (dynamic_column_get(&str, column_numbers[i], res + i))
+ if (mariadb_dyncol_get_num(&str, column_numbers[i], res + i))
goto err;
rc= ((res[0].type == DYN_COL_UINT) &&
(res[0].x.ulong_value == num0) &&
@@ -452,7 +461,7 @@ err:
ok(rc, "%s", name);
/* cleanup */
val[4].x.string.value.str= NULL; // we did not allocated it
- dynamic_column_column_free(&str);
+ mariadb_dyncol_free(&str);
}
@@ -467,13 +476,13 @@ void test_value_multi_same_num()
for (i= 0; i < 5; i++)
val[i].type= DYN_COL_NULL;
/* create column */
- if (!dynamic_column_create_many(&str, 5, column_numbers, val))
+ if (!mariadb_dyncol_create_many_num(&str, 5, column_numbers, val, 1))
goto err;
rc= TRUE;
err:
ok(rc, "%s", "same column numbers check");
/* cleanup */
- dynamic_column_column_free(&str);
+ mariadb_dyncol_free(&str);
}
@@ -487,68 +496,69 @@ void test_update_multi(uint *column_numbers, uint *column_values,
val.type= DYN_COL_UINT;
val.x.ulong_value= column_values[0];
- if (dynamic_column_create(&str, column_numbers[0], &val))
+ if (mariadb_dyncol_create_many_num(&str, 1, column_numbers, &val, 1))
goto err;
for (i= 1; i < all; i++)
{
val.type= (null_values[i] ? DYN_COL_NULL : DYN_COL_UINT);
val.x.ulong_value= column_values[i];
- if (dynamic_column_update(&str, column_numbers[i], &val))
+ if (mariadb_dyncol_update_many_num(&str, 1, column_numbers +i, &val))
goto err;
/* check value(s) */
for (j= i; j >= (i < only_add ? 0 : i); j--)
{
- if (dynamic_column_get(&str, column_numbers[j], &val))
+ if (mariadb_dyncol_get_num(&str, column_numbers[j], &val))
goto err;
if (null_values[j])
{
if (val.type != DYN_COL_NULL ||
- dynamic_column_exists(&str, column_numbers[j]) == ER_DYNCOL_YES)
+ mariadb_dyncol_exists_num(&str, column_numbers[j]) == ER_DYNCOL_YES)
goto err;
}
else
{
if (val.type != DYN_COL_UINT ||
val.x.ulong_value != column_values[j] ||
- dynamic_column_exists(&str, column_numbers[j]) == ER_DYNCOL_NO)
+ mariadb_dyncol_exists_num(&str, column_numbers[j]) == ER_DYNCOL_NO)
goto err;
}
}
if (i < only_add)
{
- DYNAMIC_ARRAY num;
- if (dynamic_column_list(&str, &num))
+ uint elements, *num;
+ if (mariadb_dyncol_list_num(&str, &elements, &num))
+ {
+ my_free(num);
goto err;
+ }
/* cross check arrays */
- if ((int)num.elements != i + 1)
+ if ((int)elements != i + 1)
{
- delete_dynamic(&num);
+ my_free(num);
goto err;
}
for(j= 0; j < i + 1; j++)
{
int k;
for(k= 0;
- k < i + 1 && column_numbers[j] !=
- *dynamic_element(&num, k, uint*);
+ k < i + 1 && column_numbers[j] != num[k];
k++);
if (k >= i + 1)
{
- delete_dynamic(&num);
+ my_free(num);
goto err;
}
for(k= 0;
- k < i + 1 && column_numbers[k] !=
- *dynamic_element(&num, j, uint*);
+ k < i + 1 && column_numbers[k] != num[j];
k++);
if (k >= i + 1)
{
- delete_dynamic(&num);
+ my_free(num);
goto err;
}
}
- delete_dynamic(&num);
+ my_free(num);
}
}
@@ -556,41 +566,72 @@ void test_update_multi(uint *column_numbers, uint *column_values,
err:
ok(rc, "%s", "add/delete/update");
/* cleanup */
- dynamic_column_column_free(&str);
+ mariadb_dyncol_free(&str);
}
void test_empty_string()
{
DYNAMIC_COLUMN_VALUE val, res;
DYNAMIC_COLUMN str;
- DYNAMIC_ARRAY array_of_uint;
+ uint *array_of_uint;
+ uint number_of_uint;
int rc;
+ uint ids[1]= {1};
+ DYNAMIC_COLUMN_VALUE vals[1];
/* empty string */
bzero(&str, sizeof(str));
- rc= dynamic_column_get(&str, 1, &res);
+ rc= mariadb_dyncol_get_num(&str, 1, &res);
ok( (rc == ER_DYNCOL_OK) && (res.type == DYN_COL_NULL), "%s", "empty get");
- rc= dynamic_column_delete(&str, 1);
- ok( (rc == ER_DYNCOL_OK), "%s", "empty delete");
+ vals[0].type= DYN_COL_NULL;
+ rc= mariadb_dyncol_update_many_num(&str, 1, ids, vals);
+ ok( (rc == ER_DYNCOL_OK) && (str.str == 0), "%s", "empty delete");
- rc= dynamic_column_exists(&str, 1);
+ rc= mariadb_dyncol_exists_num(&str, 1);
ok( (rc == ER_DYNCOL_NO), "%s", "empty exists");
- rc= dynamic_column_list(&str, &array_of_uint);
- ok( (rc == ER_DYNCOL_OK) && (array_of_uint.elements == 0),
+ rc= mariadb_dyncol_list_num(&str, &number_of_uint, &array_of_uint);
+ ok( (rc == ER_DYNCOL_OK) && (number_of_uint == 0) && (str.str == 0),
"%s", "empty list");
val.type= DYN_COL_UINT;
val.x.ulong_value= 1212;
- rc= dynamic_column_update(&str, 1, &val);
+ rc= mariadb_dyncol_update_many_num(&str, 1, ids, &val);
if (rc == ER_DYNCOL_OK)
- rc= dynamic_column_get(&str, 1, &res);
- ok( (rc == ER_DYNCOL_OK) &&
+ rc= mariadb_dyncol_get_num(&str, 1, &res);
+ ok( (rc == ER_DYNCOL_OK) && (str.str != 0) &&
(res.type == DYN_COL_UINT) && (res.x.ulong_value == val.x.ulong_value),
"%s", "empty update");
+ mariadb_dyncol_free(&str);
}
+static void test_mdev_4994()
+{
+ DYNAMIC_COLUMN dyncol;
+ LEX_STRING key= {0,0};
+ DYNAMIC_COLUMN_VALUE val;
+ int rc;
+
+ val.type= DYN_COL_NULL;
+
+ mariadb_dyncol_init(&dyncol);
+ rc= mariadb_dyncol_create_many_named(&dyncol, 1, &key, &val, 0); /* crash */
+ ok( (rc == ER_DYNCOL_OK), "%s", "test_mdev_4994");
+ mariadb_dyncol_free(&dyncol);
+}
+
+static void test_mdev_4995()
+{
+ DYNAMIC_COLUMN dyncol;
+ uint column_count= 5;
+ int rc;
+
+ mariadb_dyncol_init(&dyncol);
+ rc= mariadb_dyncol_column_count(&dyncol,&column_count);
+
+ ok( (rc == ER_DYNCOL_OK), "%s", "test_mdev_4995");
+}
void test_update_many(uint *column_numbers, uint *column_values,
uint column_count,
@@ -633,11 +674,11 @@ void test_update_many(uint *column_numbers, uint *column_values,
res[i].type= DYN_COL_UINT;
res[i].x.ulong_value= result_values[i];
}
- if (dynamic_column_create_many(&str1, column_count, column_numbers, val))
+ if (mariadb_dyncol_create_many_num(&str1, column_count, column_numbers, val, 1))
goto err;
- if (dynamic_column_update_many(&str1, update_count, update_numbers, upd))
+ if (mariadb_dyncol_update_many_num(&str1, update_count, update_numbers, upd))
goto err;
- if (dynamic_column_create_many(&str2, result_count, result_numbers, res))
+ if (mariadb_dyncol_create_many_num(&str2, result_count, result_numbers, res, 1))
goto err;
if (str1.length == str2.length &&
memcmp(str1.str, str2.str, str1.length) ==0)
@@ -646,8 +687,52 @@ void test_update_many(uint *column_numbers, uint *column_values,
err:
ok(rc, "%s", "update_many");
/* cleanup */
- dynamic_column_column_free(&str1);
- dynamic_column_column_free(&str2);
+ free(val);
+ free(upd);
+ free(res);
+ mariadb_dyncol_free(&str1);
+ mariadb_dyncol_free(&str2);
+}
+
+static void test_mdev_9773()
+{
+ int rc;
+ uint i;
+ uint num_keys[5]= {1,2,3,4,5};
+ char const *strval[]= {"Val1", "Val2", "Val3", "Val4", "Val5"};
+ DYNAMIC_COLUMN_VALUE vals[5];
+ DYNAMIC_COLUMN dynstr;
+ uint unpack_columns= 0;
+ MYSQL_LEX_STRING *unpack_keys= 0;
+ DYNAMIC_COLUMN_VALUE *unpack_vals= 0;
+
+ for (i = 0; i < 5; i++)
+ {
+ vals[i].type= DYN_COL_STRING;
+ vals[i].x.string.value.str= (char *)strval[i];
+ vals[i].x.string.value.length= strlen(strval[i]);
+ vals[i].x.string.charset= &my_charset_latin1;
+ }
+
+ mariadb_dyncol_init(&dynstr);
+
+ /* create numeric */
+ rc= mariadb_dyncol_create_many_num(&dynstr, 5, num_keys, vals, 1);
+
+ if (rc == ER_DYNCOL_OK)
+ rc= mariadb_dyncol_unpack(&dynstr, &unpack_columns, &unpack_keys,
+ &unpack_vals);
+ ok (rc == ER_DYNCOL_OK && unpack_columns == 5, "5 fields unpacked");
+ for (i = 0; i < unpack_columns; i++)
+ {
+ ok(memcmp(unpack_vals[i].x.string.value.str,
+ vals[i].x.string.value.str, vals[i].x.string.value.length) == 0,
+ "unpack %u", i);
+ }
+
+ my_free(unpack_keys);
+ my_free(unpack_vals);
+ mariadb_dyncol_free(&dynstr);
}
int main(int argc __attribute__((unused)), char **argv)
@@ -656,7 +741,7 @@ int main(int argc __attribute__((unused)), char **argv)
char *big_string= (char *)malloc(1024*1024);
MY_INIT(argv[0]);
- plan(60);
+ plan(68);
if (!big_string)
exit(1);
@@ -664,21 +749,17 @@ int main(int argc __attribute__((unused)), char **argv)
big_string[i]= ('0' + (i % 10));
test_value_single_null();
test_value_single_uint(0, "0");
- test_value_single_uint(ULL(0xffffffffffffffff), "0xffffffffffffffff");
- test_value_single_uint(ULL(0xaaaaaaaaaaaaaaaa), "0xaaaaaaaaaaaaaaaa");
- test_value_single_uint(ULL(0x5555555555555555), "0x5555555555555555");
+ test_value_single_uint(0xffffffffffffffffULL, "0xffffffffffffffff");
+ test_value_single_uint(0xaaaaaaaaaaaaaaaaULL, "0xaaaaaaaaaaaaaaaa");
+ test_value_single_uint(0x5555555555555555ULL, "0x5555555555555555");
test_value_single_uint(27652, "27652");
test_value_single_sint(0, "0");
test_value_single_sint(1, "1");
test_value_single_sint(-1, "-1");
- test_value_single_sint(LL(0x7fffffffffffffff),
- "0x7fffffffffffffff");
- test_value_single_sint(LL(0xaaaaaaaaaaaaaaaa),
- "0xaaaaaaaaaaaaaaaa");
- test_value_single_sint(LL(0x5555555555555555),
- "0x5555555555555555");
- test_value_single_sint(LL(0x8000000000000000),
- "0x8000000000000000");
+ test_value_single_sint(0x7fffffffffffffffLL, "0x7fffffffffffffff");
+ test_value_single_sint(0xaaaaaaaaaaaaaaaaLL, "0xaaaaaaaaaaaaaaaa");
+ test_value_single_sint(0x5555555555555555LL, "0x5555555555555555");
+ test_value_single_sint(0x8000000000000000LL, "0x8000000000000000");
test_value_single_double(0.0, "0.0");
test_value_single_double(1.0, "1.0");
test_value_single_double(-1.0, "-1.0");
@@ -735,7 +816,7 @@ int main(int argc __attribute__((unused)), char **argv)
}
{
uint column_numbers[]= {10,1,12,37,4,57,6,76,87};
- test_value_multi(ULL(0xffffffffffffffff), LL(0x7fffffffffffffff),
+ test_value_multi(0xffffffffffffffffULL, 0x7fffffffffffffffLL,
99999999.999e120, "9999999999999999999999999999999",
big_string, 1024*1024, charset_list[0],
9999, 12, 31,
@@ -791,5 +872,10 @@ int main(int argc __attribute__((unused)), char **argv)
update_numbers, update_values, update_nulls, 4,
result_numbers, result_values, 3);
}
+ test_mdev_4994();
+ test_mdev_4995();
+ test_mdev_9773();
+
+ my_end(0);
return exit_status();
}
diff --git a/unittest/mysys/my_vsnprintf-t.c b/unittest/mysys/my_vsnprintf-t.c
index 06f6878826a..45df97fbecd 100644
--- a/unittest/mysys/my_vsnprintf-t.c
+++ b/unittest/mysys/my_vsnprintf-t.c
@@ -19,7 +19,17 @@
char buf[1024]; /* let's hope that's enough */
-void test1(const char *res, const char *fmt, ...)
+static void test_w_len(const char *res, size_t buflen, const char *fmt, ...)
+{
+ va_list args;
+ size_t len;
+ va_start(args,fmt);
+ len= my_vsnprintf(buf, buflen, fmt, args);
+ va_end(args);
+ ok(strlen(res) == len && strcmp(buf, res) == 0, "\"%s\"", buf);
+}
+
+static void test1(const char *res, const char *fmt, ...)
{
va_list args;
size_t len;
@@ -29,9 +39,29 @@ void test1(const char *res, const char *fmt, ...)
ok(strlen(res) == len && strcmp(buf, res) == 0, "\"%s\"", buf);
}
+static void test_many(const char **res, const char *fmt, ...)
+{
+ va_list args;
+ size_t len;
+ va_start(args,fmt);
+ len= my_vsnprintf(buf, sizeof(buf)-1, fmt, args);
+ va_end(args);
+
+ for (; *res ; res++)
+ {
+ if (strlen(*res) == len && strcmp(buf, *res) == 0)
+ {
+ ok(1, "\"%s\"", buf);
+ return;
+ }
+ }
+ ok(0, "\"%s\"", buf);
+}
+
+
int main(void)
{
- plan(58);
+ plan(39);
test1("Constant string",
"Constant string");
@@ -121,61 +151,32 @@ int main(void)
test1("G with a width (ignored) and precision: <12.35>",
"G with a width (ignored) and precision: <%10.5g>", 12.3456789);
- diag("================================================================");
-
- test1("Hello",
- "Hello");
- test1("Hello int, 1",
- "Hello int, %d", 1);
- test1("Hello int, -1",
- "Hello int, %d", -1);
- test1("Hello int, 1",
- "Hello int, %i", 1);
- test1("Hello int, -1",
- "Hello int, %i", -1);
- test1("Hello string 'I am a string'",
- "Hello string '%s'", "I am a string");
- test1("Hello hack hack hack hack hack hack hack 1",
- "Hello hack hack hack hack hack hack hack %d", 1);
- test1("Hello 1 hack 4",
- "Hello %d hack %d", 1, 4);
- test1("Hello 1 hack hack hack hack hack 4",
- "Hello %d hack hack hack hack hack %d", 1, 4);
- test1("Hello 'hack' hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh",
- "Hello '%s' hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh", "hack");
- test1("Hello hhhhhhhhhhhhhh 1 sssssssssssssss",
- "Hello hhhhhhhhhhhhhh %d sssssssssssssss", 1);
- test1("Hello 1",
- "Hello %u", 1);
- test1("Hello 4294967295",
- "Hello %u", -1);
- test1("Hex: 20 ' 41'",
- "Hex: %lx '%6lx'", 32, 65);
- test1("conn 1 to: '(null)' user: '(null)' host: '(null)' ((null))",
- "conn %ld to: '%-.64s' user: '%-.32s' host: '%-.64s' (%-.64s)",
- 1L, NULL, NULL, NULL, NULL);
- test1("Hello string `I am a string`",
- "Hello string %`s", "I am a string");
- test1("Hello TEST",
- "Hello %05s", "TEST");
- test1("My `Q` test",
- "My %1$`-.1s test", "QQQQ");
- test1("My AAAA test done DDDD",
- "My %2$s test done %1$s", "DDDD", "AAAA");
- test1("My DDDD test CCCC, DDD",
- "My %1$s test %2$s, %1$-.3s", "DDDD", "CCCC");
- test1("My QQQQ test",
- "My %1$`-.4b test", "QQQQ");
- test1("My X test",
- "My %1$c test", 'X');
- test1("My <0000000010> test1 < a> test2 < A>",
- "My <%010d> test1 <%4x> test2 <%4X>", 10, 10, 10);
- test1("My <0000000010> test1 < a> test2 < a>",
- "My <%1$010d> test1 <%2$4x> test2 <%2$4x>", 10, 10);
- test1("My 00010 test",
- "My %1$*02$d test", 10, 5);
- test1("My `DDDD` test CCCC, `DDD`",
- "My %1$`s test %2$s, %1$`-.3s", "DDDD", "CCCC");
+ {
+ /* Test that %M works */
+ const char *results[]=
+ {
+ "Error 1 \"Operation not permitted\"", /* Linux */
+ "Error 1 \"Not owner\"", /* Solaris */
+ NullS
+ };
+ test_many(results, "Error %M", 1);
+ }
+
+ test1("M with 0 error code: 0 \"Internal error/check (Not system error)\"",
+ "M with 0 error code: %M", 0);
+
+ test1("M with positional: 0 \"Internal error/check (Not system error)\"",
+ "M with positional: %1$M", 0);
+
+ test1("M with width: 0 \"Internal error/ch",
+ "M with width: %.20M", 0);
+ test1("M with width positional: 0 \"Internal error/ch",
+ "M with width positional: %2$.*1$M", 20, 0);
+
+ test_w_len("M small buf: 0 \"In",
+ 19, "M small buf: %M", 0);
+ test_w_len("M small buf positional: 0 \"In",
+ 30, "M small buf positional: %1$M", 0);
return exit_status();
}