| 1 | /* Copyright (c) 2016, 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 | class PumpObjectParserTest : public ::testing::Test { |
| 27 | protected: |
| 28 | PumpObjectParserTest() = default; |
| 29 | |
| 30 | std::vector<std::pair<std::string, std::string>> list; |
| 31 | std::string err; |
| 32 | }; |
| 33 | |
| 34 | #define UNITTEST_OBJECT_FILTER_PARSER |
| 35 | #include "../client/dump/object_filter.cc" |
| 36 | |
| 37 | TEST_F(PumpObjectParserTest, empty) { |
| 38 | err = parse_inclusion_string("", list, true, false); |
| 39 | EXPECT_EQ(err.length(), 0U); |
| 40 | } |
| 41 | |
| 42 | TEST_F(PumpObjectParserTest, singe) { |
| 43 | err = parse_inclusion_string(" t1 ", list, true, false); |
| 44 | EXPECT_EQ(err.length(), 0U) << "returned '" << err << "'"; |
| 45 | EXPECT_EQ(list.size(), 1U); |
| 46 | EXPECT_EQ(list[0].first, "%"); |
| 47 | EXPECT_EQ(list[0].second, "t1"); |
| 48 | } |
| 49 | |
| 50 | TEST_F(PumpObjectParserTest, two_tables) { |
| 51 | err = parse_inclusion_string(" t1 , foo . bar ", list, true, false); |
| 52 | EXPECT_EQ(err.length(), 0U) << "returned '" << err << "'"; |
| 53 | EXPECT_EQ(list.size(), 2U); |
| 54 | EXPECT_EQ(list[0].first, "%"); |
| 55 | EXPECT_EQ(list[0].second, "t1"); |
| 56 | EXPECT_EQ(list[1].first, "foo"); |
| 57 | EXPECT_EQ(list[1].second, "bar"); |
| 58 | } |
| 59 | |
| 60 | TEST_F(PumpObjectParserTest, table_with_a_dot) { |
| 61 | err = parse_inclusion_string(" t1\\\\.t2 ", list, true, false); |
| 62 | EXPECT_EQ(err.length(), 0U) << "returned '" << err << "'"; |
| 63 | EXPECT_EQ(list.size(), 1U); |
| 64 | EXPECT_EQ(list[0].first, "%"); |
| 65 | EXPECT_EQ(list[0].second, "t1.t2"); |
| 66 | } |
| 67 | |
| 68 | TEST_F(PumpObjectParserTest, bad_list_escape) { |
| 69 | err = parse_inclusion_string(" t1\\.t2 ", list, true, false); |
| 70 | EXPECT_NE(err.length(), 0U) << "returned '" << err << "'"; |
| 71 | EXPECT_EQ(list.size(), 0U); |
| 72 | } |
| 73 | |
| 74 | TEST_F(PumpObjectParserTest, bad_table_name_escape) { |
| 75 | err = parse_inclusion_string(" t1\\\\,t2 ", list, true, false); |
| 76 | EXPECT_NE(err.length(), 0U) << "returned '" << err << "'"; |
| 77 | EXPECT_EQ(list.size(), 0U); |
| 78 | } |
| 79 | |
| 80 | TEST_F(PumpObjectParserTest, table_with_a_comma) { |
| 81 | err = parse_inclusion_string(" t1\\,t2 ", list, true, false); |
| 82 | EXPECT_EQ(err.length(), 0U) << "returned '" << err << "'"; |
| 83 | EXPECT_EQ(list.size(), 1U); |
| 84 | EXPECT_EQ(list[0].first, "%"); |
| 85 | EXPECT_EQ(list[0].second, "t1,t2"); |
| 86 | } |
| 87 | |
| 88 | TEST_F(PumpObjectParserTest, user_with_an_at) { |
| 89 | err = parse_inclusion_string(" t1\\\\@t2 ", list, true, true); |
| 90 | EXPECT_EQ(err.length(), 0U) << "returned '" << err << "'"; |
| 91 | EXPECT_EQ(list.size(), 1U); |
| 92 | EXPECT_EQ(list[0].first, "'t1@t2'"); |
| 93 | EXPECT_EQ(list[0].second, "%"); |
| 94 | } |