Skip to content

Commit 173fc43

Browse files
add version accessor and associated unit test.
Fix bug in the teardown function found during above.
1 parent 4132006 commit 173fc43

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

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

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

98+
/// Get the internal library version string.
99+
/// Uses semantic versioning.
100+
const char * GetVersion();
101+
98102
} //namespace qf_ctrl
99103
} //namespace test
100104
} //namespace cms

cpputest-for-qpcpp-lib/src/cms_cpputest_qf_ctrl.cpp

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,19 @@ void Teardown()
109109
// Instead, we modified the QF port stop() method, which
110110
// internally will perform the memory check, as it has
111111
// friend access.
112-
if (l_memPoolOption == MemPoolTeardownOption::CHECK_FOR_LEAKS) {
113-
for (size_t i = 0; i < l_pubSubEventMemPoolConfigs->size(); ++i) {
112+
if (l_pubSubEventMemPoolConfigs != nullptr) {
113+
if (l_memPoolOption == MemPoolTeardownOption::CHECK_FOR_LEAKS) {
114+
for (size_t i = 0; i < l_pubSubEventMemPoolConfigs->size(); ++i) {
114115

115-
const size_t poolNumOfEvents = l_pubSubEventMemPoolConfigs->at(i).config.numberOfEvents;
116+
const size_t poolNumOfEvents =
117+
l_pubSubEventMemPoolConfigs->at(i).config.numberOfEvents;
116118

117-
CHECK_TRUE_TEXT(poolNumOfEvents == QP::QF::ePool_[i].getNFree(),
118-
"A leak was detected in an internal QF event pool!");
119+
CHECK_TRUE_TEXT(
120+
poolNumOfEvents == QP::QF::ePool_[i].getNFree(),
121+
"A leak was detected in an internal QF event pool!");
122+
}
119123
}
120-
}
121124

122-
if (l_pubSubEventMemPoolConfigs != nullptr) {
123125
delete l_pubSubEventMemPoolConfigs;
124126
l_pubSubEventMemPoolConfigs = nullptr;
125127
}
@@ -202,6 +204,11 @@ void CreatePoolConfigsFromArg(const MemPoolConfigs& pubSubEventMemPoolConfigs)
202204
}
203205
}
204206

207+
const char * GetVersion()
208+
{
209+
return CPPUTEST_FOR_QPCPP_LIB_VERSION;
210+
}
211+
205212
} // namespace qf_ctrl
206213
} // namespace test
207214
} // namespace cms

cpputest-for-qpcpp-lib/tests/cms_cpputest_qf_ctrlTests.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,13 @@ TEST(qf_ctrlTests,
138138

139139
CHECK_EQUAL(1, sigOneCount);
140140
CHECK_EQUAL(3, sigTwoCount);
141+
}
142+
143+
TEST(qf_ctrlTests, qf_ctrl_provides_cpputest_for_qpcpp_lib_version)
144+
{
145+
auto version = qf_ctrl::GetVersion();
146+
CHECK_TRUE(version != nullptr);
147+
148+
std::string version_str(version);
149+
CHECK_FALSE(version_str.empty());
141150
}

0 commit comments

Comments
 (0)