Skip to content

Commit 566fc02

Browse files
add PostAndProcess helper convenience methods
1 parent 06d62a7 commit 566fc02

File tree

3 files changed

+96
-0
lines changed

3 files changed

+96
-0
lines changed

cpputest-for-qpc-lib/include/cms_cpputest_qf_ctrl.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,27 @@ void PublishAndProcess(enum_t sig,
9595
void PublishAndProcess(QEvt const * e,
9696
PublishedEventRecorder* recorder = nullptr);
9797

98+
/// Helper method to Post an event to an active object
99+
/// followed internally by ProcessEvents().
100+
/// \param e
101+
/// \param dest
102+
inline void PostAndProcess(QEvt const * e, QActive* dest)
103+
{
104+
QACTIVE_POST(dest, e, nullptr);
105+
ProcessEvents();
106+
}
107+
108+
/// Helper method to Post a static const QEvt to an active object
109+
/// followed internally by ProcessEvents().
110+
/// \param sig (template param): the signal value of the const event to post
111+
/// \param dest : the active object to post to.
112+
template <enum_t sig>
113+
inline void PostAndProcess(QActive* dest)
114+
{
115+
static const QEvt constEvent = QEVT_INITIALIZER(sig);
116+
PostAndProcess(&constEvent, dest);
117+
}
118+
98119
/// Get the internal library version string.
99120
/// Uses semantic versioning.
100121
const char * GetVersion();

cpputest-for-qpc-lib/tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(TEST_SOURCES
44
qassertTests.cpp
55
cms_cpputest_qf_ctrlTests.cpp
66
cms_cpputest_qf_ctrlPublishTests.cpp
7+
cms_cpputest_qf_ctrl_post_tests.cpp
78
publishedEventRecorderTests.cpp
89
backedQueueTests.cpp
910
)
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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

Comments
 (0)