| 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 <ctime> |
| 25 | |
| 26 | #include "gcs_base_test.h" |
| 27 | |
| 28 | #include "gcs_xcom_notification.h" |
| 29 | |
| 30 | namespace gcs_xcom_notification_unittest { |
| 31 | class XcomNotificationTest : public GcsBaseTest {}; |
| 32 | |
| 33 | void function(int &val) { val += 1; } |
| 34 | |
| 35 | class Dummy_notification : public Parameterized_notification<false> { |
| 36 | public: |
| 37 | Dummy_notification(void (*functor)(int &), int &val) |
| 38 | : m_functor(functor), m_val(val) {} |
| 39 | |
| 40 | ~Dummy_notification() override = default; |
| 41 | |
| 42 | void (*m_functor)(int &); |
| 43 | int &m_val; |
| 44 | |
| 45 | private: |
| 46 | void do_execute() override { (*m_functor)(m_val); } |
| 47 | }; |
| 48 | |
| 49 | static int var = 0; |
| 50 | static void cleanup() { var += 1; } |
| 51 | |
| 52 | TEST_F(XcomNotificationTest, ProcessDummyNotification) { |
| 53 | int val = 0; |
| 54 | Gcs_xcom_engine *engine = new Gcs_xcom_engine(); |
| 55 | |
| 56 | ASSERT_EQ(val, 0); |
| 57 | |
| 58 | engine->initialize(nullptr); |
| 59 | engine->push(new Dummy_notification(&function, val)); |
| 60 | engine->finalize(nullptr); |
| 61 | delete engine; |
| 62 | |
| 63 | ASSERT_EQ(val, 1); |
| 64 | } |
| 65 | |
| 66 | TEST_F(XcomNotificationTest, ProcessFinalizeNotification) { |
| 67 | Gcs_xcom_engine *engine = new Gcs_xcom_engine(); |
| 68 | |
| 69 | ASSERT_EQ(var, 0); |
| 70 | |
| 71 | engine->initialize(nullptr); |
| 72 | engine->finalize(cleanup); |
| 73 | delete engine; |
| 74 | |
| 75 | ASSERT_EQ(var, 1); |
| 76 | } |
| 77 | } // namespace gcs_xcom_notification_unittest |