summaryrefslogtreecommitdiff
path: root/unittest
diff options
context:
space:
mode:
Diffstat (limited to 'unittest')
-rw-r--r--unittest/json_lib/CMakeLists.txt23
-rw-r--r--unittest/json_lib/json_lib-t.c186
-rw-r--r--unittest/mysys/CMakeLists.txt3
-rw-r--r--unittest/mysys/base64-t.c12
-rw-r--r--unittest/mysys/ma_dyncol-t.c2
-rw-r--r--unittest/mysys/my_getopt-t.c2
-rw-r--r--unittest/sql/explain_filename-t.cc61
-rw-r--r--unittest/sql/mf_iocache-t.cc21
-rw-r--r--unittest/strings/strings-t.c16
9 files changed, 268 insertions, 58 deletions
diff --git a/unittest/json_lib/CMakeLists.txt b/unittest/json_lib/CMakeLists.txt
new file mode 100644
index 00000000000..2d04025e93e
--- /dev/null
+++ b/unittest/json_lib/CMakeLists.txt
@@ -0,0 +1,23 @@
+# Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved.
+#
+# 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_DIRECTORIES(${CMAKE_SOURCE_DIR}/include
+ ${CMAKE_SOURCE_DIR}/sql
+ ${CMAKE_SOURCE_DIR}/regex
+ ${CMAKE_SOURCE_DIR}/extra/yassl/include
+ ${CMAKE_SOURCE_DIR}/unittest/mytap)
+
+#
+MY_ADD_TESTS(json_lib LINK_LIBRARIES strings dbug)
diff --git a/unittest/json_lib/json_lib-t.c b/unittest/json_lib/json_lib-t.c
new file mode 100644
index 00000000000..11f02b204f8
--- /dev/null
+++ b/unittest/json_lib/json_lib-t.c
@@ -0,0 +1,186 @@
+/* Copyright (c) 2016, MariaDB Corp. All rights reserved.
+
+ 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_config.h"
+#include "config.h"
+#include <tap.h>
+#include <my_global.h>
+#include <my_sys.h>
+#include <json_lib.h>
+
+/* The character set used for JSON all over this test. */
+static CHARSET_INFO *ci;
+
+#define s_e(j) j, j + strlen((const char *) j)
+
+
+struct st_parse_result
+{
+ int n_keys;
+ int n_values;
+ int n_arrays;
+ int n_objects;
+ int n_steps;
+ int error;
+ uchar keyname_csum;
+};
+
+
+static void parse_json(const uchar *j, struct st_parse_result *result)
+{
+ json_engine_t je;
+
+ bzero(result, sizeof(*result));
+
+ if (json_scan_start(&je, ci, s_e(j)))
+ return;
+
+ do
+ {
+ result->n_steps++;
+ switch (je.state)
+ {
+ case JST_KEY:
+ result->n_keys++;
+ while (json_read_keyname_chr(&je) == 0)
+ {
+ result->keyname_csum^= je.s.c_next;
+ }
+ if (je.s.error)
+ return;
+ break;
+ case JST_VALUE:
+ result->n_values++;
+ break;
+ case JST_OBJ_START:
+ result->n_objects++;
+ break;
+ case JST_ARRAY_START:
+ result->n_arrays++;
+ break;
+ default:
+ break;
+ };
+ } while (json_scan_next(&je) == 0);
+
+ result->error= je.s.error;
+}
+
+
+static const uchar *js0= (const uchar *) "123";
+static const uchar *js1= (const uchar *) "[123, \"text\"]";
+static const uchar *js2= (const uchar *) "{\"key1\":123, \"key2\":\"text\"}";
+static const uchar *js3= (const uchar *) "{\"key1\":{\"ikey1\":321},"
+ "\"key2\":[\"text\", 321]}";
+
+/*
+ Test json_lib functions to parse JSON.
+*/
+static void
+test_json_parsing()
+{
+ struct st_parse_result r;
+ parse_json(js0, &r);
+ ok(r.n_steps == 1 && r.n_values == 1, "simple value");
+ parse_json(js1, &r);
+ ok(r.n_steps == 5 && r.n_values == 3 && r.n_arrays == 1, "array");
+ parse_json(js2, &r);
+ ok(r.n_steps == 5 && r.n_keys == 2 && r.n_objects == 1 && r.keyname_csum == 3,
+ "object");
+ parse_json(js3, &r);
+ ok(r.n_steps == 12 && r.n_keys == 3 && r.n_objects == 2 &&
+ r.n_arrays == 1 && r.keyname_csum == 44,
+ "complex json");
+}
+
+
+static const uchar *p0= (const uchar *) "$.key1[12].*[*]";
+/*
+ Test json_lib functions to parse JSON path.
+*/
+static void
+test_path_parsing()
+{
+ json_path_t p;
+ if (json_path_setup(&p, ci, s_e(p0)))
+ return;
+ ok(p.last_step - p.steps == 4 &&
+ p.steps[0].type == JSON_PATH_ARRAY_WILD &&
+ p.steps[1].type == JSON_PATH_KEY &&
+ p.steps[2].type == JSON_PATH_ARRAY && p.steps[2].n_item == 12 &&
+ p.steps[3].type == JSON_PATH_KEY_WILD &&
+ p.steps[4].type == JSON_PATH_ARRAY_WILD,
+ "path");
+}
+
+
+static const uchar *fj0=(const uchar *) "[{\"k0\":123, \"k1\":123, \"k1\":123},"
+ " {\"k3\":321, \"k4\":\"text\"},"
+ " {\"k1\":[\"text\"], \"k2\":123}]";
+static const uchar *fp0= (const uchar *) "$[*].k1";
+/*
+ Test json_lib functions to search through JSON.
+*/
+static void
+test_search()
+{
+ json_engine_t je;
+ json_path_t p;
+ json_path_step_t *cur_step;
+ int n_matches, scal_values;
+ uint array_counters[JSON_DEPTH_LIMIT];
+
+ if (json_scan_start(&je, ci, s_e(fj0)) ||
+ json_path_setup(&p, ci, s_e(fp0)))
+ return;
+
+ cur_step= p.steps;
+ n_matches= scal_values= 0;
+ while (json_find_path(&je, &p, &cur_step, array_counters) == 0)
+ {
+ n_matches++;
+ if (json_read_value(&je))
+ return;
+ if (json_value_scalar(&je))
+ {
+ scal_values++;
+ if (json_scan_next(&je))
+ return;
+ }
+ else
+ {
+ if (json_skip_level(&je) || json_scan_next(&je))
+ return;
+ }
+
+ }
+
+ ok(n_matches == 3, "search");
+}
+
+
+int main()
+{
+ ci= &my_charset_utf8_general_ci;
+
+ plan(6);
+ diag("Testing json_lib functions.");
+
+ test_json_parsing();
+ test_path_parsing();
+ test_search();
+
+ return exit_status();
+}
diff --git a/unittest/mysys/CMakeLists.txt b/unittest/mysys/CMakeLists.txt
index ad5195a843e..0c61ff09af2 100644
--- a/unittest/mysys/CMakeLists.txt
+++ b/unittest/mysys/CMakeLists.txt
@@ -20,8 +20,7 @@ MY_ADD_TESTS(my_vsnprintf LINK_LIBRARIES strings mysys)
ADD_DEFINITIONS(${SSL_DEFINES})
-MY_ADD_TESTS(ma_dyncol
- LINK_LIBRARIES mysqlclient)
+MY_ADD_TESTS(ma_dyncol LINK_LIBRARIES mysys)
IF(WIN32)
MY_ADD_TESTS(my_delete LINK_LIBRARIES mysys)
diff --git a/unittest/mysys/base64-t.c b/unittest/mysys/base64-t.c
index a3a37976da6..abbc028917d 100644
--- a/unittest/mysys/base64-t.c
+++ b/unittest/mysys/base64-t.c
@@ -48,18 +48,18 @@ main(int argc __attribute__((unused)),char *argv[])
}
/* Encode */
- needed_length= base64_needed_encoded_length(src_len);
+ needed_length= my_base64_needed_encoded_length(src_len);
str= (char *) malloc(needed_length);
for (k= 0; k < needed_length; k++)
str[k]= 0xff; /* Fill memory to check correct NUL termination */
- ok(base64_encode(src, src_len, str) == 0,
- "base64_encode: size %d", i);
+ ok(my_base64_encode(src, src_len, str) == 0,
+ "my_base64_encode: size %d", i);
ok(needed_length == strlen(str) + 1,
- "base64_needed_encoded_length: size %d", i);
+ "my_base64_needed_encoded_length: size %d", i);
/* Decode */
- dst= (char *) malloc(base64_needed_decoded_length(strlen(str)));
- dst_len= base64_decode(str, strlen(str), dst, NULL, 0);
+ dst= (char *) malloc(my_base64_needed_decoded_length(strlen(str)));
+ dst_len= my_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/ma_dyncol-t.c b/unittest/mysys/ma_dyncol-t.c
index 3b43c10a6a8..124f16e15be 100644
--- a/unittest/mysys/ma_dyncol-t.c
+++ b/unittest/mysys/ma_dyncol-t.c
@@ -124,7 +124,7 @@ void test_value_single_double(double num, const char *name)
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;
+ num= res.x.double_value;
err:
ok(rc, "%s - %lf", name, num);
/* cleanup */
diff --git a/unittest/mysys/my_getopt-t.c b/unittest/mysys/my_getopt-t.c
index 39814d76690..3e16d79424e 100644
--- a/unittest/mysys/my_getopt-t.c
+++ b/unittest/mysys/my_getopt-t.c
@@ -72,7 +72,7 @@ void run(const char *arg, ...)
arg= va_arg(ap, char*);
}
va_end(ap);
- arg_c= arg_v - arg_s;
+ arg_c= (int)(arg_v - arg_s);
arg_v= arg_s;
res= handle_options(&arg_c, &arg_v, mopts_options, 0);
}
diff --git a/unittest/sql/explain_filename-t.cc b/unittest/sql/explain_filename-t.cc
index 69ce51c0446..5f2e165d6ff 100644
--- a/unittest/sql/explain_filename-t.cc
+++ b/unittest/sql/explain_filename-t.cc
@@ -26,7 +26,8 @@
char to[BUFLEN];
char from[BUFLEN];
-const char *error_messages[1000];
+static const char *error_messages_txt[1000];
+static const char **error_messages[1]= { error_messages_txt };
int setup()
{
@@ -34,12 +35,12 @@ int setup()
my_default_lc_messages = &my_locale_en_US;
/* Populate the necessary error messages */
- error_messages[ER_DATABASE_NAME - ER_ERROR_FIRST] = "Database";
- error_messages[ER_TABLE_NAME - ER_ERROR_FIRST] = "Table";
- error_messages[ER_PARTITION_NAME - ER_ERROR_FIRST] = "Partition";
- error_messages[ER_SUBPARTITION_NAME - ER_ERROR_FIRST] = "Subpartition";
- error_messages[ER_TEMPORARY_NAME - ER_ERROR_FIRST] = "Temporary";
- error_messages[ER_RENAMED_NAME - ER_ERROR_FIRST] = "Renamed";
+ error_messages[0][ER_DATABASE_NAME - ER_ERROR_FIRST] = "Database";
+ error_messages[0][ER_TABLE_NAME - ER_ERROR_FIRST] = "Table";
+ error_messages[0][ER_PARTITION_NAME - ER_ERROR_FIRST] = "Partition";
+ error_messages[0][ER_SUBPARTITION_NAME - ER_ERROR_FIRST] = "Subpartition";
+ error_messages[0][ER_TEMPORARY_NAME - ER_ERROR_FIRST] = "Temporary";
+ error_messages[0][ER_RENAMED_NAME - ER_ERROR_FIRST] = "Renamed";
my_default_lc_messages->errmsgs->errmsgs = error_messages;
@@ -58,7 +59,7 @@ void test_1(const char *in, const char *exp, enum_explain_filename_mode mode)
/* length returned by explain_filename is fine */
bool length = (len1 == strlen(exp));
- ok( (pass && length) , "(%d): %s => %s\n", mode, in, out);
+ ok( (pass && length) , "(%d): %s => %s", mode, in, out);
}
int main(int argc __attribute__((unused)),char *argv[])
@@ -68,87 +69,87 @@ int main(int argc __attribute__((unused)),char *argv[])
plan(22);
test_1("test/t1.ibd",
- "Database \"test\", Table \"t1.ibd\"",
+ "Database `test`, Table `t1.ibd`",
EXPLAIN_ALL_VERBOSE);
test_1("test/t1.ibd",
- "\"test\".\"t1.ibd\"",
+ "`test`.`t1.ibd`",
EXPLAIN_PARTITIONS_VERBOSE);
test_1("test/t1.ibd",
- "\"test\".\"t1.ibd\"",
+ "`test`.`t1.ibd`",
EXPLAIN_PARTITIONS_AS_COMMENT);
test_1("test/t1#TMP#",
- "Database \"test\", Table \"t1#TMP#\"",
+ "Database `test`, Table `t1#TMP#`",
EXPLAIN_ALL_VERBOSE);
test_1("test/#sql-2882.ibd",
- "Database \"test\", Table \"#sql-2882.ibd\"",
+ "Database `test`, Table `#sql-2882.ibd`",
EXPLAIN_ALL_VERBOSE);
test_1("test/t1#REN#",
- "Database \"test\", Table \"t1#REN#\"",
+ "Database `test`, Table `t1#REN#`",
EXPLAIN_ALL_VERBOSE);
test_1("test/t1@0023REN@0023",
- "Database \"test\", Table \"t1#REN#\"",
+ "Database `test`, Table `t1#REN#`",
EXPLAIN_ALL_VERBOSE);
test_1("test/t1#p#p1",
- "Database \"test\", Table \"t1\", Partition \"p1\"",
+ "Database `test`, Table `t1`, Partition `p1`",
EXPLAIN_ALL_VERBOSE);
test_1("test/t1#P#p1",
- "\"test\".\"t1\" /* Partition \"p1\" */",
+ "`test`.`t1` /* Partition `p1` */",
EXPLAIN_PARTITIONS_AS_COMMENT);
test_1("test/t1#P#p1@00231",
- "\"test\".\"t1\" /* Partition \"p1#1\" */",
+ "`test`.`t1` /* Partition `p1#1` */",
EXPLAIN_PARTITIONS_AS_COMMENT);
test_1("test/t1#P#p1#SP#sp1",
- "\"test\".\"t1\" /* Partition \"p1\", Subpartition \"sp1\" */",
+ "`test`.`t1` /* Partition `p1`, Subpartition `sp1` */",
EXPLAIN_PARTITIONS_AS_COMMENT);
test_1("test/t1#p1#SP#sp1",
- "\"test\".\"t1#p1#SP#sp1\"",
+ "`test`.`t1#p1#SP#sp1`",
EXPLAIN_PARTITIONS_AS_COMMENT);
test_1("test/t1#p#p1@00232#SP#sp1@00231#REN#",
- "\"test\".\"t1\" /* Renamed Partition \"p1#2\", Subpartition \"sp1#1\" */",
+ "`test`.`t1` /* Renamed Partition `p1#2`, Subpartition `sp1#1` */",
EXPLAIN_PARTITIONS_AS_COMMENT);
test_1("test/t1#p#p1#SP#sp1#TMP#",
- "\"test\".\"t1\" /* Temporary Partition \"p1\", Subpartition \"sp1\" */",
+ "`test`.`t1` /* Temporary Partition `p1`, Subpartition `sp1` */",
EXPLAIN_PARTITIONS_AS_COMMENT);
test_1("test/#sql-t1#P#p1#SP#sp1#TMP#",
- "\"test\".\"#sql-t1#P#p1#SP#sp1#TMP#\" /* Temporary Partition \"p1\", Subpartition \"sp1\" */",
+ "`test`.`#sql-t1#P#p1#SP#sp1#TMP#` /* Temporary Partition `p1`, Subpartition `sp1` */",
EXPLAIN_PARTITIONS_AS_COMMENT);
test_1("test/#sql-t1#P#p1#SP#sp1",
- "\"test\".\"#sql-t1#P#p1#SP#sp1\" /* Partition \"p1\", Subpartition \"sp1\" */",
+ "`test`.`#sql-t1#P#p1#SP#sp1` /* Partition `p1`, Subpartition `sp1` */",
EXPLAIN_PARTITIONS_AS_COMMENT);
test_1("test/#sqlx-33",
- "\"test\".\"#sqlx-33\"",
+ "`test`.`#sqlx-33`",
EXPLAIN_PARTITIONS_AS_COMMENT);
test_1("test/#mysql50#t",
- "\"test\".\"#mysql50#t\"",
+ "`test`.`#mysql50#t`",
EXPLAIN_PARTITIONS_AS_COMMENT);
test_1("#mysql50#t",
- "\"#mysql50#t\"",
+ "`#mysql50#t`",
EXPLAIN_PARTITIONS_AS_COMMENT);
test_1("@0023t",
- "\"#t\"",
+ "`#t`",
EXPLAIN_PARTITIONS_AS_COMMENT);
test_1("test/t@0023",
- "\"test\".\"t#\"",
+ "`test`.`t#`",
EXPLAIN_PARTITIONS_AS_COMMENT);
/*
@@ -156,7 +157,7 @@ int main(int argc __attribute__((unused)),char *argv[])
then it will not be converted to system_charset_info!
*/
test_1("test/t@0023#",
- "\"test\".\"t@0023#\"",
+ "`test`.`t@0023#`",
EXPLAIN_PARTITIONS_AS_COMMENT);
my_end(0);
diff --git a/unittest/sql/mf_iocache-t.cc b/unittest/sql/mf_iocache-t.cc
index fca5ec5014d..9e7ab23933d 100644
--- a/unittest/sql/mf_iocache-t.cc
+++ b/unittest/sql/mf_iocache-t.cc
@@ -92,8 +92,8 @@ void sql_print_error(const char *format, ...)
IO_CACHE info;
#define CACHE_SIZE 16384
-#define INFO_TAIL ", pos_in_file = %llu, pos_in_mem = %td", \
- info.pos_in_file, *info.current_pos - info.request_pos
+#define INFO_TAIL ", pos_in_file = %llu, pos_in_mem = %lu", \
+ info.pos_in_file, (ulong) ((info.type == READ_CACHE ? info.read_pos : info.write_pos) - info.request_pos)
#define FILL 0x5A
@@ -208,7 +208,7 @@ void mdev10259()
res= my_b_flush_io_cache(&info, 1);
ok(res == 0, "flush" INFO_TAIL);
- ulong saved_pos= my_b_tell(&info);
+ my_off_t saved_pos= my_b_tell(&info);
res= reinit_io_cache(&info, READ_CACHE, 0, 0, 0);
ok(res == 0, "reinit READ_CACHE" INFO_TAIL);
@@ -287,7 +287,8 @@ void mdev14014()
void mdev17133()
{
- int res, k;
+ my_off_t res;
+ int k;
const int eof_iter=4, read_iter= 4;
uchar buf_i[1024*256]; // read
uchar buf_o[sizeof(buf_i)]; // write
@@ -333,11 +334,11 @@ void mdev17133()
for (i= 0; i < read_iter; i++, total += curr_read_size)
{
char buf_check[eof_block_size];
- uint a,b;
+ size_t a,b;
- a= info.end_of_file - total;
+ a= (size_t)(info.end_of_file - total);
b= read_size + read_size/4 - rand() % (read_size/2);
- curr_read_size= (i == read_iter - 1) ? info.end_of_file - total :
+ curr_read_size= (i == read_iter - 1) ? a :
MY_MIN(a, b);
DBUG_ASSERT(curr_read_size <= info.end_of_file - total);
@@ -391,7 +392,7 @@ void mdev10963()
ok(res == 0, "open_cached_file" INFO_TAIL);
res= my_b_write(&info, buf, sizeof(buf));
- ulong total_size= my_b_tell(&info);
+ ulonglong total_size= my_b_tell(&info);
ok(res == 0 && total_size == sizeof(buf), "cache is written");
/* destination */
@@ -424,8 +425,8 @@ void mdev10963()
when total_size < copied_size the huge overflowed value of the last
argument is ignored because nothing already left uncopied in the cache.
*/
- res= my_b_copy_to_file(&info, file, total_size - copied_size);
- ok(res == 0, "%lu of the cache copied to file", total_size - copied_size);
+ res= my_b_copy_to_file(&info, file, (size_t) total_size - copied_size);
+ ok(res == 0, "%llu of the cache copied to file", total_size - copied_size);
ok(my_ftell(file, my_flags) == sizeof(buf),
"file written in %d fragments", n_frag+1);
diff --git a/unittest/strings/strings-t.c b/unittest/strings/strings-t.c
index fe595a5c303..fadcb4c768d 100644
--- a/unittest/strings/strings-t.c
+++ b/unittest/strings/strings-t.c
@@ -31,12 +31,12 @@ test_like_range_for_charset(CHARSET_INFO *cs, const char *src, size_t src_len)
cs->coll->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= cs->cset->well_formed_len(cs,
- min_str, min_str + min_len,
- 10000, &error);
- max_well_formed_len= cs->cset->well_formed_len(cs,
- max_str, max_str + max_len,
- 10000, &error);
+ min_well_formed_len= my_well_formed_length(cs,
+ min_str, min_str + min_len,
+ 10000, &error);
+ max_well_formed_len= my_well_formed_length(cs,
+ max_str, max_str + max_len,
+ 10000, &error);
if (min_len != min_well_formed_len)
diag("Bad min_str: min_well_formed_len=%d min_str[%d]=0x%02X",
(int) min_well_formed_len, (int) min_well_formed_len,
@@ -627,7 +627,7 @@ strcollsp(CHARSET_INFO *cs, const STRNNCOLL_PARAM *param)
{
char ahex[64], bhex[64];
int res= cs->coll->strnncollsp(cs, (uchar *) p->a, p->alen,
- (uchar *) p->b, p->blen, 0);
+ (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",
@@ -641,7 +641,7 @@ strcollsp(CHARSET_INFO *cs, const STRNNCOLL_PARAM *param)
{
/* Test in reverse order */
res= cs->coll->strnncollsp(cs, (uchar *) p->b, p->blen,
- (uchar *) p->a, p->alen, 0);
+ (uchar *) p->a, p->alen);
if (!eqres(res, -p->res))
{
diag("Comparison in reverse order failed. Expected %d, got %d",