|
| 1 | +//// @brief Tests for the qf_ctrl post related functions for the QF cpputest port. |
| 2 | +/// @ingroup |
| 3 | +/// @cond |
| 4 | +///*************************************************************************** |
| 5 | +/// |
| 6 | +/// Copyright (C) 2024 Matthew Eshleman. All rights reserved. |
| 7 | +/// |
| 8 | +/// This program is open source software: you can redistribute it and/or |
| 9 | +/// modify it under the terms of the GNU General Public License as published |
| 10 | +/// by the Free Software Foundation, either version 3 of the License, or |
| 11 | +/// (at your option) any later version. |
| 12 | +/// |
| 13 | +/// Alternatively, upon written permission from Matthew Eshleman, this program |
| 14 | +/// may be distributed and modified under the terms of a Commercial |
| 15 | +/// License. For further details, see the Contact Information below. |
| 16 | +/// |
| 17 | +/// Contact Information: |
| 18 | +/// Matthew Eshleman |
| 19 | +/// https://covemountainsoftware.com |
| 20 | +/// info@covemountainsoftware.com |
| 21 | +///*************************************************************************** |
| 22 | +/// @endcond |
| 23 | + |
| 24 | +#include "cmsDummyActiveObject.hpp" |
| 25 | +#include "cms_cpputest_qf_ctrl.hpp" |
| 26 | +#include "qpc.h" |
| 27 | + |
| 28 | +//cpputest header include must always be last |
| 29 | +#include "CppUTest/TestHarness.h" |
| 30 | + |
| 31 | +using namespace cms::test; |
| 32 | + |
| 33 | +TEST_GROUP(qf_ctrl_post_tests) |
| 34 | +{ |
| 35 | + cms::DefaultDummyActiveObject* mDummy = nullptr; |
| 36 | + |
| 37 | + void setup() final |
| 38 | + { |
| 39 | + qf_ctrl::Setup(Q_USER_SIG, 100); |
| 40 | + mDummy = new cms::DefaultDummyActiveObject(); |
| 41 | + mDummy->dummyStart(); |
| 42 | + } |
| 43 | + |
| 44 | + void teardown() final |
| 45 | + { |
| 46 | + delete mDummy; |
| 47 | + cms::test::qf_ctrl::Teardown(); |
| 48 | + } |
| 49 | +}; |
| 50 | + |
| 51 | +TEST(qf_ctrl_post_tests, |
| 52 | + provides_a_post_and_process_helper_func_with_trivial_signal_enum) |
| 53 | +{ |
| 54 | + static constexpr enum_t TEST1_SIG = Q_USER_SIG + 1; |
| 55 | + enum_t capturedSig = -1; |
| 56 | + mDummy->SetPostedEventHandler([&](const QEvt* e){ |
| 57 | + capturedSig = e->sig; |
| 58 | + }); |
| 59 | + qf_ctrl::PostAndProcess<TEST1_SIG>(mDummy->getQActive()); |
| 60 | + CHECK_EQUAL(TEST1_SIG, capturedSig); |
| 61 | +} |
| 62 | + |
| 63 | +TEST(qf_ctrl_post_tests, |
| 64 | + provides_a_post_and_process_helper_func) |
| 65 | +{ |
| 66 | + static constexpr enum_t TEST2_SIG = Q_USER_SIG + 111; |
| 67 | + static const QEvt testEvent = QEVT_INITIALIZER(TEST2_SIG); |
| 68 | + enum_t capturedSig = -1; |
| 69 | + mDummy->SetPostedEventHandler([&](const QEvt* e){ |
| 70 | + capturedSig = e->sig; |
| 71 | + }); |
| 72 | + qf_ctrl::PostAndProcess(&testEvent, mDummy->getQActive()); |
| 73 | + CHECK_EQUAL(TEST2_SIG, capturedSig); |
| 74 | +} |
0 commit comments