| 1 | /* Copyright (c) 2018, 2026, Oracle and/or its affiliates. |
| 2 | |
| 3 | This program is free software; you can redistribute it and/or modify |
| 4 | it under the terms of the GNU General Public License, version 2.0, |
| 5 | as published by the Free Software Foundation. |
| 6 | |
| 7 | This program is designed to work with certain software (including |
| 8 | but not limited to OpenSSL) that is licensed under separate terms, |
| 9 | as designated in a particular file or component or in included license |
| 10 | documentation. The authors of MySQL hereby grant you an additional |
| 11 | permission to link the program and your derivative works with the |
| 12 | separately licensed software that they have either included with |
| 13 | the program or referenced in the documentation. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License, version 2.0, for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program; if not, write to the Free Software |
| 22 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ |
| 23 | |
| 24 | #include <gtest/gtest.h> |
| 25 | |
| 26 | #include "plugin/x/src/json_utils.h" |
| 27 | |
| 28 | namespace xpl { |
| 29 | namespace test { |
| 30 | |
| 31 | struct Param_is_id_in_json { |
| 32 | bool expect; |
| 33 | std::string json; |
| 34 | }; |
| 35 | |
| 36 | class Is_id_in_json_test : public testing::TestWithParam<Param_is_id_in_json> { |
| 37 | }; |
| 38 | |
| 39 | TEST_P(Is_id_in_json_test, is_id_in_json) { |
| 40 | const Param_is_id_in_json ¶m = GetParam(); |
| 41 | EXPECT_EQ(param.expect, is_id_in_json(param.json)); |
| 42 | } |
| 43 | |
| 44 | Param_is_id_in_json is_id_in_json_param[] = { |
| 45 | {true, ""}, |
| 46 | {true, "a, b, c"}, |
| 47 | {true, "1, 2, 3"}, |
| 48 | {false, "{}"}, |
| 49 | {true, "{a, b, c}"}, |
| 50 | {false, "[]"}, |
| 51 | {false, "[1,2,3]"}, |
| 52 | {true, "{\"_id\": 1}"}, |
| 53 | {false, "{\"a\": 1}"}, |
| 54 | {true, "{\"a\": 1, \"_id\": 2}"}, |
| 55 | {false, "{\"a\": {\"_id\": 2}}"}, |
| 56 | {false, "{\"a\": [1,{\"_id\": 2},3]}"}, |
| 57 | {true, "{\"a\": {\"_id\": 2}, \"_id\": 3}"}, |
| 58 | {false, "{\"a\": [1,{\"_id\": 2},3]}"}, |
| 59 | {true, "{\"a\": {\"_id\": 2}, \"_id\": 3, \"b\": {\"_id\": 4}}"}, |
| 60 | }; |
| 61 | |
| 62 | INSTANTIATE_TEST_SUITE_P(is_id_in_json, Is_id_in_json_test, |
| 63 | testing::ValuesIn(is_id_in_json_param)); |
| 64 | |
| 65 | } // namespace test |
| 66 | } // namespace xpl |