From de63fcbc5dd7780c53d5e1c202905052cd7f0a71 Mon Sep 17 00:00:00 2001 From: John Wellbelove Date: Fri, 29 Nov 2024 18:53:44 +0000 Subject: [PATCH] Removed using directive in derived message router classes. --- .gitignore | 3 + .../QueuedMessageRouter.cpp | 2 - .../QueuedMessageRouter.sln | 0 .../QueuedMessageRouter.vcxproj | 8 +- test/test_message_router.cpp | 92 +++++++++++++++++++ 5 files changed, 99 insertions(+), 6 deletions(-) rename examples/QueuedMessageRouter/{vs2019 => vs2022}/QueuedMessageRouter.sln (100%) rename examples/QueuedMessageRouter/{vs2019 => vs2022}/QueuedMessageRouter.vcxproj (97%) diff --git a/.gitignore b/.gitignore index 8f313ddbc..6ca19e113 100644 --- a/.gitignore +++ b/.gitignore @@ -388,3 +388,6 @@ support/time remaining test.xlsx test/vs2022/Debug MSVC C++20 - Force C++03 test/vs2022/Release MSVC C++20 - No STL - Optimised -O2 - Sanitiser test/test_file_list.txt +examples/QueuedMessageRouter/vs2022/.vs/QueuedMessageRouter/CopilotIndices +examples/QueuedMessageRouter/vs2022/.vs/QueuedMessageRouter/FileContentIndex +examples/QueuedMessageRouter/vs2022/.vs/QueuedMessageRouter/v17 diff --git a/examples/QueuedMessageRouter/QueuedMessageRouter.cpp b/examples/QueuedMessageRouter/QueuedMessageRouter.cpp index d4f78f772..f4348e5e2 100644 --- a/examples/QueuedMessageRouter/QueuedMessageRouter.cpp +++ b/examples/QueuedMessageRouter/QueuedMessageRouter.cpp @@ -52,8 +52,6 @@ class Router : public etl::message_router typedef etl::message_router Base_t; - using Base_t::receive; - //*************************************************************************** Router() : message_router(1) diff --git a/examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.sln b/examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.sln similarity index 100% rename from examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.sln rename to examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.sln diff --git a/examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.vcxproj b/examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.vcxproj similarity index 97% rename from examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.vcxproj rename to examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.vcxproj index 65dad150f..eaacbe964 100644 --- a/examples/QueuedMessageRouter/vs2019/QueuedMessageRouter.vcxproj +++ b/examples/QueuedMessageRouter/vs2022/QueuedMessageRouter.vcxproj @@ -29,26 +29,26 @@ Application true - v142 + v143 Unicode Application false - v142 + v143 true Unicode Application true - v142 + v143 Unicode Application false - v142 + v143 true Unicode diff --git a/test/test_message_router.cpp b/test/test_message_router.cpp index b5936d629..938a0854f 100644 --- a/test/test_message_router.cpp +++ b/test/test_message_router.cpp @@ -253,6 +253,77 @@ namespace int sender_id; }; + //*************************************************************************** + // Router that handles messages 1, 2, 3. + // 'receive' is overridden. + //*************************************************************************** + class Router3 : public etl::message_router + { + public: + + using base = etl::message_router; + + Router3() + : message_router(ROUTER3) + , message1_received(false) + , message2_received(false) + , message3_received(false) + , unknown_message_received(false) + { + } + + void receive(const etl::imessage& msg) override + { + switch (msg.get_message_id()) + { + case MESSAGE1: + { + message1_received = true; + break; + } + + case MESSAGE2: + { + message2_received = true; + break; + } + + case MESSAGE3: + { + message3_received = true; + break; + } + + default: + { + unknown_message_received = true; + break; + } + } + } + + void on_receive(const Message1& msg) + { + } + + void on_receive(const Message2& msg) + { + } + + void on_receive(const Message3& msg) + { + } + + void on_receive_unknown(const etl::imessage&) + { + } + + bool message1_received; + bool message2_received; + bool message3_received; + bool unknown_message_received; + }; + etl::imessage_router* p_router; SUITE(test_message_router) @@ -641,5 +712,26 @@ namespace CHECK_EQUAL(0, r1.message4_count); CHECK_EQUAL(0, r1.message_unknown_count); } + + //************************************************************************* + TEST(message_router_with_overloaded_receive) + { + Router3 router; + + Message1 message1(router); + Message2 message2(router); + Message3 message3(router); + + router.receive(message1); + CHECK_TRUE(router.message1_received); + + router.receive(message2); + CHECK_TRUE(router.message2_received); + + router.receive(message3); + CHECK_TRUE(router.message3_received); + + CHECK_FALSE(router.unknown_message_received); + } }; }