| 1 | /* Copyright (c) 2012, 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 | #ifndef HANDLER_T_INCLUDED |
| 25 | #define HANDLER_T_INCLUDED |
| 26 | |
| 27 | #include <gmock/gmock.h> |
| 28 | #include <gtest/gtest.h> |
| 29 | |
| 30 | #include "my_inttypes.h" |
| 31 | #include "sql/handler.h" |
| 32 | #include "unittest/gunit/base_mock_handler.h" |
| 33 | |
| 34 | /** |
| 35 | A mock handler extending Base_mock_HANDLER |
| 36 | */ |
| 37 | class Mock_HANDLER : public Base_mock_HANDLER { |
| 38 | public: |
| 39 | // Declare the members we actually want to test. |
| 40 | MOCK_METHOD(void, print_error, (int error, myf errflag), (override)); |
| 41 | MOCK_METHOD(bool, primary_key_is_clustered, (), (const override)); |
| 42 | MOCK_METHOD(ha_rows, records_in_range, |
| 43 | (unsigned index, key_range *min_key, key_range *max_key), |
| 44 | (override)); |
| 45 | |
| 46 | Mock_HANDLER(handlerton *ht_arg, TABLE_SHARE *share_arg) |
| 47 | : Base_mock_HANDLER(ht_arg, share_arg) { |
| 48 | // By default, estimate all ranges to have 10 records, just like the default |
| 49 | // implementation in handler. |
| 50 | ON_CALL(*this, records_in_range).WillByDefault(testing::Return(10)); |
| 51 | } |
| 52 | |
| 53 | void set_ha_table_flags(Table_flags flags) { cached_table_flags = flags; } |
| 54 | }; |
| 55 | |
| 56 | /** |
| 57 | A mock handler for testing the sampling handler. |
| 58 | */ |
| 59 | class Mock_SAMPLING_HANDLER : public Base_mock_HANDLER { |
| 60 | public: |
| 61 | /* |
| 62 | Declare the members we actually want to test. These are the members that |
| 63 | should be called by the "default" sampling implementation. |
| 64 | */ |
| 65 | MOCK_METHOD1(rnd_init, int(bool scan)); |
| 66 | MOCK_METHOD1(rnd_next, int(::uchar *buf)); |
| 67 | MOCK_METHOD0(rnd_end, int()); |
| 68 | |
| 69 | Mock_SAMPLING_HANDLER(handlerton *ht_arg, TABLE *table_arg, |
| 70 | TABLE_SHARE *share) |
| 71 | : Base_mock_HANDLER(ht_arg, share) { |
| 72 | table = table_arg; |
| 73 | } |
| 74 | }; |
| 75 | |
| 76 | /** |
| 77 | A mock for the handlerton struct |
| 78 | */ |
| 79 | class Fake_handlerton : public handlerton { |
| 80 | public: |
| 81 | /// Minimal initialization of the handlerton |
| 82 | Fake_handlerton() { |
| 83 | slot = 0; |
| 84 | db_type = DB_TYPE_UNKNOWN; |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | #endif // HANDLER_T_INCLUDED |