Skip to content

Commit

Permalink
add PostAndProcess helper convenience methods
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheweshleman committed Jun 22, 2024
1 parent 06d62a7 commit 566fc02
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cpputest-for-qpc-lib/include/cms_cpputest_qf_ctrl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,27 @@ void PublishAndProcess(enum_t sig,
void PublishAndProcess(QEvt const * e,
PublishedEventRecorder* recorder = nullptr);

/// Helper method to Post an event to an active object
/// followed internally by ProcessEvents().
/// \param e
/// \param dest
inline void PostAndProcess(QEvt const * e, QActive* dest)
{
QACTIVE_POST(dest, e, nullptr);
ProcessEvents();
}

/// Helper method to Post a static const QEvt to an active object
/// followed internally by ProcessEvents().
/// \param sig (template param): the signal value of the const event to post
/// \param dest : the active object to post to.
template <enum_t sig>
inline void PostAndProcess(QActive* dest)
{
static const QEvt constEvent = QEVT_INITIALIZER(sig);
PostAndProcess(&constEvent, dest);
}

/// Get the internal library version string.
/// Uses semantic versioning.
const char * GetVersion();
Expand Down
1 change: 1 addition & 0 deletions cpputest-for-qpc-lib/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(TEST_SOURCES
qassertTests.cpp
cms_cpputest_qf_ctrlTests.cpp
cms_cpputest_qf_ctrlPublishTests.cpp
cms_cpputest_qf_ctrl_post_tests.cpp
publishedEventRecorderTests.cpp
backedQueueTests.cpp
)
Expand Down
74 changes: 74 additions & 0 deletions cpputest-for-qpc-lib/tests/cms_cpputest_qf_ctrl_post_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//// @brief Tests for the qf_ctrl post related functions for the QF cpputest port.
/// @ingroup
/// @cond
///***************************************************************************
///
/// Copyright (C) 2024 Matthew Eshleman. All rights reserved.
///
/// This program is open source software: you can redistribute it and/or
/// modify it under the terms of the GNU General Public License as published
/// by the Free Software Foundation, either version 3 of the License, or
/// (at your option) any later version.
///
/// Alternatively, upon written permission from Matthew Eshleman, this program
/// may be distributed and modified under the terms of a Commercial
/// License. For further details, see the Contact Information below.
///
/// Contact Information:
/// Matthew Eshleman
/// https://covemountainsoftware.com
/// [email protected]
///***************************************************************************
/// @endcond

#include "cmsDummyActiveObject.hpp"
#include "cms_cpputest_qf_ctrl.hpp"
#include "qpc.h"

//cpputest header include must always be last
#include "CppUTest/TestHarness.h"

using namespace cms::test;

TEST_GROUP(qf_ctrl_post_tests)
{
cms::DefaultDummyActiveObject* mDummy = nullptr;

void setup() final
{
qf_ctrl::Setup(Q_USER_SIG, 100);
mDummy = new cms::DefaultDummyActiveObject();
mDummy->dummyStart();
}

void teardown() final
{
delete mDummy;
cms::test::qf_ctrl::Teardown();
}
};

TEST(qf_ctrl_post_tests,
provides_a_post_and_process_helper_func_with_trivial_signal_enum)
{
static constexpr enum_t TEST1_SIG = Q_USER_SIG + 1;
enum_t capturedSig = -1;
mDummy->SetPostedEventHandler([&](const QEvt* e){
capturedSig = e->sig;
});
qf_ctrl::PostAndProcess<TEST1_SIG>(mDummy->getQActive());
CHECK_EQUAL(TEST1_SIG, capturedSig);
}

TEST(qf_ctrl_post_tests,
provides_a_post_and_process_helper_func)
{
static constexpr enum_t TEST2_SIG = Q_USER_SIG + 111;
static const QEvt testEvent = QEVT_INITIALIZER(TEST2_SIG);
enum_t capturedSig = -1;
mDummy->SetPostedEventHandler([&](const QEvt* e){
capturedSig = e->sig;
});
qf_ctrl::PostAndProcess(&testEvent, mDummy->getQActive());
CHECK_EQUAL(TEST2_SIG, capturedSig);
}

0 comments on commit 566fc02

Please sign in to comment.