Debian Codegraph @

unittest/gunit/xplugin/xpl/mock/component_services.h

raw symbols SCIP
1 /*
2 * Copyright (c) 2020, 2026, Oracle and/or its affiliates.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License, version 2.0,
6 * as published by the Free Software Foundation.
7 *
8 * This program is designed to work with certain software (including
9 * but not limited to OpenSSL) that is licensed under separate terms,
10 * as designated in a particular file or component or in included license
11 * documentation. The authors of MySQL hereby grant you an additional
12 * permission to link the program and your derivative works with the
13 * separately licensed software that they have either included with
14 * the program or referenced in the documentation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License, version 2.0, for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 */
25
26 #ifndef UNITTEST_GUNIT_XPLUGIN_XPL_MOCK_COMPONENT_SERVICES_H_
27 #define UNITTEST_GUNIT_XPLUGIN_XPL_MOCK_COMPONENT_SERVICES_H_
28
29 #include <assert.h>
30 #include <gmock/gmock.h>
31 #include <gtest/gtest.h>
32
33 // NOLINT(build/include_subdir)
34 #include "mysql/components/services/mysql_admin_session.h"
35 #include "mysql/service_plugin_registry.h"
36
37 namespace xpl {
38 namespace test {
39 namespace mock {
40
41 class Mysql_plugin_registry {
42 public:
43 Mysql_plugin_registry();
44 ~Mysql_plugin_registry();
45
46 MOCK_METHOD(int, mysql_plugin_registry_release, (SERVICE_TYPE(registry) *));
47 MOCK_METHOD(SERVICE_TYPE(registry) *, mysql_plugin_registry_acquire, ());
48
49 static xpl::test::mock::Mysql_plugin_registry *m_mysql_plugin_registry;
50 };
51
52 class Service_registry {
53 public:
54 Service_registry();
55 ~Service_registry();
56
57 MOCK_METHOD2(acquire, mysql_service_status_t(const char *service_name,
58 my_h_service *out_service));
59 MOCK_METHOD3(acquire_related,
60 mysql_service_status_t(const char *service_name,
61 my_h_service service,
62 my_h_service *out_service));
63 MOCK_METHOD(mysql_service_status_t, release, (my_h_service service));
64
65 SERVICE_TYPE_NO_CONST(registry) * get() { return &m_registry; }
66
67 private:
68 static xpl::test::mock::Service_registry *m_this;
69
70 SERVICE_TYPE_NO_CONST(registry)
71 m_registry = {[](const char *service_name, my_h_service *out_service) {
72 return m_this->acquire(service_name, out_service);
73 },
74 [](const char *service_name, my_h_service service,
75 my_h_service *out_service) {
76 return m_this->acquire_related(service_name, service,
77 out_service);
78 },
79 [](my_h_service service) { return m_this->release(service); }};
80 };
81
82 class Service_admin_session {
83 public:
84 Service_admin_session();
85 ~Service_admin_session();
86
87 MOCK_METHOD(MYSQL_SESSION, open, (srv_session_error_cb, void *));
88 SERVICE_TYPE_NO_CONST(mysql_admin_session) * get() {
89 return &m_admin_session;
90 }
91
92 private:
93 static xpl::test::mock::Service_admin_session *m_this;
94
95 SERVICE_TYPE_NO_CONST(mysql_admin_session)
96 m_admin_session = {[](srv_session_error_cb error_cb, void *ctxt) {
97 return m_this->open(error_cb, ctxt);
98 }};
99 };
100
101 } // namespace mock
102 } // namespace test
103 } // namespace xpl
104
105 #endif // UNITTEST_GUNIT_XPLUGIN_XPL_MOCK_COMPONENT_SERVICES_H_