From 1a3570dec35733e725cc6000a06ec666facf4235 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Fri, 28 Jun 2019 13:21:39 +0200 Subject: improve build, allow sql library to be built in parallel with builtins --- unittest/sql/CMakeLists.txt | 8 +++++--- unittest/sql/dummy_builtins.cc | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 unittest/sql/dummy_builtins.cc (limited to 'unittest') diff --git a/unittest/sql/CMakeLists.txt b/unittest/sql/CMakeLists.txt index a4ba1019e49..987e78433a4 100644 --- a/unittest/sql/CMakeLists.txt +++ b/unittest/sql/CMakeLists.txt @@ -21,10 +21,12 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql ${CMAKE_SOURCE_DIR}/extra/yassl/include) IF(WIN32) - ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc - ../../sql/nt_servc.cc) + ADD_EXECUTABLE(explain_filename-t + explain_filename-t.cc + dummy_builtins.cc + ../../sql/nt_servc.cc) ELSE() - ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc) + ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc dummy_builtins.cc) ENDIF() TARGET_LINK_LIBRARIES(explain_filename-t sql mytap) diff --git a/unittest/sql/dummy_builtins.cc b/unittest/sql/dummy_builtins.cc new file mode 100644 index 00000000000..31d043d19ec --- /dev/null +++ b/unittest/sql/dummy_builtins.cc @@ -0,0 +1,26 @@ +/* 2018 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-1335 USA */ + +#include +#include +struct st_maria_plugin *mysql_optional_plugins[]= +{ + 0 +}; + +struct st_maria_plugin *mysql_mandatory_plugins[]= +{ + 0 +}; -- cgit v1.2.1 From 5e988ff80f51e80f4d74477c4a22a065472317d4 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 5 Nov 2021 20:01:43 +0300 Subject: MDEV-23766: Make Json_writer assert when one tries to author invalid JSON - Add unit test. --- unittest/sql/CMakeLists.txt | 5 ++ unittest/sql/my_json_writer-t.cc | 130 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 unittest/sql/my_json_writer-t.cc (limited to 'unittest') diff --git a/unittest/sql/CMakeLists.txt b/unittest/sql/CMakeLists.txt index 987e78433a4..ab174680fab 100644 --- a/unittest/sql/CMakeLists.txt +++ b/unittest/sql/CMakeLists.txt @@ -36,3 +36,8 @@ ADD_EXECUTABLE(mf_iocache-t mf_iocache-t.cc ../../sql/mf_iocache_encr.cc) TARGET_LINK_LIBRARIES(mf_iocache-t mysys mytap mysys_ssl) ADD_DEPENDENCIES(mf_iocache-t GenError) MY_ADD_TEST(mf_iocache) + +# Json writer needs String which needs sql library +ADD_EXECUTABLE(my_json_writer-t my_json_writer-t.cc dummy_builtins.cc) +TARGET_LINK_LIBRARIES(my_json_writer-t sql mytap) +MY_ADD_TEST(my_json_writer) diff --git a/unittest/sql/my_json_writer-t.cc b/unittest/sql/my_json_writer-t.cc new file mode 100644 index 00000000000..46c3f4dc967 --- /dev/null +++ b/unittest/sql/my_json_writer-t.cc @@ -0,0 +1,130 @@ +/* + Copyright (c) 2021, MariaDB Corporation. + + 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 Street, Fifth Floor, Boston, MA 02110-1335 USA */ + +#include +#include +#include +#include +#include + +/* + Unit tests for class Json_writer. At the moment there are only tests for the + "Fail an assertion if one attempts to produce invalid JSON" feature. +*/ + +struct TABLE; +struct JOIN_TAB; +class Json_writer; + + +/* Several fake objects */ +class Opt_trace +{ +public: + void enable_tracing_if_required() {} + void disable_tracing_if_required() {} + Json_writer *get_current_json() { return nullptr; } +}; + +class THD +{ +public: + Opt_trace opt_trace; +}; + +#define JSON_WRITER_UNIT_TEST +#include "../sql/my_json_writer.h" +#include "../sql/my_json_writer.cc" + +int main(int args, char **argv) +{ + plan(NO_PLAN); + diag("Testing Json_writer checks"); + + { + Json_writer w; + w.start_object(); + w.add_member("foo"); + w.end_object(); + ok(w.invalid_json, "Started a name but didn't add a value"); + } + + { + Json_writer w; + w.start_object(); + w.add_ull(123); + ok(w.invalid_json, "Unnamed value in an object"); + } + + { + Json_writer w; + w.start_array(); + w.add_member("bebebe").add_ull(345); + ok(w.invalid_json, "Named member in array"); + } + + { + Json_writer w; + w.start_object(); + w.start_array(); + ok(w.invalid_json, "Unnamed array in an object"); + } + + { + Json_writer w; + w.start_object(); + w.start_object(); + ok(w.invalid_json, "Unnamed object in an object"); + } + + { + Json_writer w; + w.start_array(); + w.add_member("zzz"); + w.start_object(); + ok(w.invalid_json, "Named object in an array"); + } + { + Json_writer w; + w.start_array(); + w.add_member("zzz"); + w.start_array(); + ok(w.invalid_json, "Named array in an array"); + } + + // BAD: + { + Json_writer w; + w.start_array(); + w.end_object(); + ok(!w.invalid_json, "BAD: not checked!"); + } + + // BAD: + { + Json_writer w; + w.start_object(); + w.end_array(); + ok(!w.invalid_json, "BAD: not checked!"); + } + + + + diag("Done"); + + return exit_status(); +} + -- cgit v1.2.1 From e9b76b896a5cec9804e653f7df117c49284cabba Mon Sep 17 00:00:00 2001 From: Sergei Krivonos Date: Mon, 8 Nov 2021 21:11:05 +0200 Subject: MDEV-23766: fix by my_json_writer test --- unittest/sql/my_json_writer-t.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'unittest') diff --git a/unittest/sql/my_json_writer-t.cc b/unittest/sql/my_json_writer-t.cc index 46c3f4dc967..3d23c2f021e 100644 --- a/unittest/sql/my_json_writer-t.cc +++ b/unittest/sql/my_json_writer-t.cc @@ -110,7 +110,7 @@ int main(int args, char **argv) Json_writer w; w.start_array(); w.end_object(); - ok(!w.invalid_json, "BAD: not checked!"); + ok(w.invalid_json, "JSON object end of array"); } // BAD: @@ -118,7 +118,7 @@ int main(int args, char **argv) Json_writer w; w.start_object(); w.end_array(); - ok(!w.invalid_json, "BAD: not checked!"); + ok(w.invalid_json, "JSON array end of object"); } -- cgit v1.2.1 From 9960b98267d3952e30c09c9816364304deb3a242 Mon Sep 17 00:00:00 2001 From: Sergei Krivonos Date: Tue, 9 Nov 2021 15:42:57 +0200 Subject: MDEV-23766: buildfix: postpone new unittest until its dependency resolution --- unittest/sql/CMakeLists.txt | 4 ---- 1 file changed, 4 deletions(-) (limited to 'unittest') diff --git a/unittest/sql/CMakeLists.txt b/unittest/sql/CMakeLists.txt index ab174680fab..caeac841a5c 100644 --- a/unittest/sql/CMakeLists.txt +++ b/unittest/sql/CMakeLists.txt @@ -37,7 +37,3 @@ TARGET_LINK_LIBRARIES(mf_iocache-t mysys mytap mysys_ssl) ADD_DEPENDENCIES(mf_iocache-t GenError) MY_ADD_TEST(mf_iocache) -# Json writer needs String which needs sql library -ADD_EXECUTABLE(my_json_writer-t my_json_writer-t.cc dummy_builtins.cc) -TARGET_LINK_LIBRARIES(my_json_writer-t sql mytap) -MY_ADD_TEST(my_json_writer) -- cgit v1.2.1 From f7c6c02a06149aa4f41dd01173f2020a0756f8db Mon Sep 17 00:00:00 2001 From: Sergei Krivonos Date: Tue, 9 Nov 2021 15:43:10 +0200 Subject: Revert "improve build, allow sql library to be built in parallel with builtins" This reverts commit 1a3570dec35733e725cc6000a06ec666facf4235. --- unittest/sql/CMakeLists.txt | 8 +++----- unittest/sql/dummy_builtins.cc | 26 -------------------------- 2 files changed, 3 insertions(+), 31 deletions(-) delete mode 100644 unittest/sql/dummy_builtins.cc (limited to 'unittest') diff --git a/unittest/sql/CMakeLists.txt b/unittest/sql/CMakeLists.txt index caeac841a5c..2a765c44cb1 100644 --- a/unittest/sql/CMakeLists.txt +++ b/unittest/sql/CMakeLists.txt @@ -21,12 +21,10 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql ${CMAKE_SOURCE_DIR}/extra/yassl/include) IF(WIN32) - ADD_EXECUTABLE(explain_filename-t - explain_filename-t.cc - dummy_builtins.cc - ../../sql/nt_servc.cc) + ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc + ../../sql/nt_servc.cc) ELSE() - ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc dummy_builtins.cc) + ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc) ENDIF() TARGET_LINK_LIBRARIES(explain_filename-t sql mytap) diff --git a/unittest/sql/dummy_builtins.cc b/unittest/sql/dummy_builtins.cc deleted file mode 100644 index 31d043d19ec..00000000000 --- a/unittest/sql/dummy_builtins.cc +++ /dev/null @@ -1,26 +0,0 @@ -/* 2018 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-1335 USA */ - -#include -#include -struct st_maria_plugin *mysql_optional_plugins[]= -{ - 0 -}; - -struct st_maria_plugin *mysql_mandatory_plugins[]= -{ - 0 -}; -- cgit v1.2.1 From 009f3e06f3e74303559df59db404b300a12241d3 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Fri, 28 Jun 2019 13:21:39 +0200 Subject: improve build, allow sql library to be built in parallel with builtins --- unittest/sql/CMakeLists.txt | 8 +++++--- unittest/sql/dummy_builtins.cc | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 unittest/sql/dummy_builtins.cc (limited to 'unittest') diff --git a/unittest/sql/CMakeLists.txt b/unittest/sql/CMakeLists.txt index 2a765c44cb1..caeac841a5c 100644 --- a/unittest/sql/CMakeLists.txt +++ b/unittest/sql/CMakeLists.txt @@ -21,10 +21,12 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/sql ${CMAKE_SOURCE_DIR}/extra/yassl/include) IF(WIN32) - ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc - ../../sql/nt_servc.cc) + ADD_EXECUTABLE(explain_filename-t + explain_filename-t.cc + dummy_builtins.cc + ../../sql/nt_servc.cc) ELSE() - ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc) + ADD_EXECUTABLE(explain_filename-t explain_filename-t.cc dummy_builtins.cc) ENDIF() TARGET_LINK_LIBRARIES(explain_filename-t sql mytap) diff --git a/unittest/sql/dummy_builtins.cc b/unittest/sql/dummy_builtins.cc new file mode 100644 index 00000000000..31d043d19ec --- /dev/null +++ b/unittest/sql/dummy_builtins.cc @@ -0,0 +1,26 @@ +/* 2018 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-1335 USA */ + +#include +#include +struct st_maria_plugin *mysql_optional_plugins[]= +{ + 0 +}; + +struct st_maria_plugin *mysql_mandatory_plugins[]= +{ + 0 +}; -- cgit v1.2.1 From 04ad98b5001eafea537d3c655d0021ffb2f5ef06 Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Fri, 5 Nov 2021 19:01:43 +0200 Subject: MDEV-23766: Re-add Json_writer unit test. --- unittest/sql/CMakeLists.txt | 4 ++++ unittest/sql/my_json_writer-t.cc | 2 -- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'unittest') diff --git a/unittest/sql/CMakeLists.txt b/unittest/sql/CMakeLists.txt index caeac841a5c..ab174680fab 100644 --- a/unittest/sql/CMakeLists.txt +++ b/unittest/sql/CMakeLists.txt @@ -37,3 +37,7 @@ TARGET_LINK_LIBRARIES(mf_iocache-t mysys mytap mysys_ssl) ADD_DEPENDENCIES(mf_iocache-t GenError) MY_ADD_TEST(mf_iocache) +# Json writer needs String which needs sql library +ADD_EXECUTABLE(my_json_writer-t my_json_writer-t.cc dummy_builtins.cc) +TARGET_LINK_LIBRARIES(my_json_writer-t sql mytap) +MY_ADD_TEST(my_json_writer) diff --git a/unittest/sql/my_json_writer-t.cc b/unittest/sql/my_json_writer-t.cc index 3d23c2f021e..6398a589c33 100644 --- a/unittest/sql/my_json_writer-t.cc +++ b/unittest/sql/my_json_writer-t.cc @@ -105,7 +105,6 @@ int main(int args, char **argv) ok(w.invalid_json, "Named array in an array"); } - // BAD: { Json_writer w; w.start_array(); @@ -113,7 +112,6 @@ int main(int args, char **argv) ok(w.invalid_json, "JSON object end of array"); } - // BAD: { Json_writer w; w.start_object(); -- cgit v1.2.1