Repository navigation
S24.02: Adopt CALLED_FUNCTION test macro and standardise *CallCount naming #321
Description
Overview
Replace ad-hoc call-count assertions across the test base with a small set
of named macros, and standardise the <name>CallCount variable/getter
naming so the macros work uniformly. Pure test refactor; no production
code touched.
Why
- The test base mixes several call-count assertion shapes —
LONGS_EQUAL(N, fooCallCount),LONGS_EQUAL(N, FakeFoo_BarCount()),
CHECK_TRUE(barCalled)— with inconsistent naming
(SenderFake_SendCount,StoreFake_WriteCount,g_sleepCallCount,
storeFullCallbackCount). - A single intent-named macro family makes test bodies read as English
and centralises the naming contract via token paste, so future drift
is caught at compile time rather than in review. - Partial implementations already exist:
- The bespoke
CHECK_HANDLER_INVOKED_ONCE/
CHECK_HANDLER_NOT_INVOKEDmacros inTests/SolidSyslogErrorTest.cpp. - A more substantial expression-form
CALLED_FUNCTION(f, n)in
Tests/TestUtils.hplus aCososoTesting::NEVER/ONCE/...namespace,
used today only inTests/SolidSyslogSwitchingSenderTest.cpp. - This story generalises both into one consistent token-paste design
so the naming rule is enforced at compile time.
- The bespoke
In scope
Extend Tests/TestUtils.h (move into Tests/Support/TestUtils.h so
non-Tests/-root test executables — Tests/Example, Tests/FreeRtos —
can include it via the established Support include path), keeping the
existing CososoTesting namespace + NEVER/ONCE/TWICE/THRICE enum.
Replace the single existing CALLED_FUNCTION(f, n) macro with three
token-paste macros that enforce the <name>CallCount naming rule:
#define CALLED_FUNCTION(name, count) LONGS_EQUAL((count), name##CallCount)
#define CALLED_FAKE(getter, count) LONGS_EQUAL((count), getter##CallCount())
#define CALLED_FAKE_ON(getter, instance, count) LONGS_EQUAL((count), getter##CallCount(instance))Migrate the pre-existing CALLED_FUNCTION(SenderFake_…(inner), N) call
sites in Tests/SolidSyslogSwitchingSenderTest.cpp to CALLED_FAKE_ON.
Rename non-conforming counters/getters to the <name>CallCount rule:
SenderFake_SendCount→SenderFake_SendCallCountSenderFake_DisconnectCount→SenderFake_DisconnectCallCountStoreFake_WriteCount→StoreFake_WriteCallCountg_sleepCallCount→NoOpSleepCallCount(SolidSyslogTlsStreamTest.cpp)getPortCallCount/getHostCallCount→SpyGetPortCallCount/
SpyGetHostCallCount(UDP and Stream sender tests)sleepCallCount→SleepFakeCallCount
(Tests/Example/ExampleServiceThreadTest.cpp)storeFullCallbackCount→CountStoreFullInvocationsCallCountthresholdCallbackCount→CountThresholdCrossingsCallCount
Convert boolean call-flags to int counters so they route through
CALLED_FUNCTION:
storeFullCallbackInvoked→StoreFullCallbackCallCountcomputeIntegrityCalled→SpyComputeIntegrityCallCountverifyIntegrityCalled→SpyVerifyIntegrityCallCount
Replace the bespoke macros in Tests/SolidSyslogErrorTest.cpp with the
generic form (CALLED_FUNCTION(handler, ONCE) /
CALLED_FUNCTION(handler, NEVER)).
Sweep every existing call-count assertion site (LONGS_EQUAL with a
CallCount operand; CHECK_TRUE/CHECK_FALSE on the converted bool flags)
to use the new macros across all test executables — main test exe,
ExampleTests, FreeRtos host tests, and the Winsock-build variants.
Out of scope
- Production code (Tier 1/2) — no production changes at all.
lastCountinTests/SolidSyslogBlockDeviceTest.cpp(byte count, not
call count).spy.callCountstruct member in
Tests/Example/ExampleInteractiveTest.cpp(different shape, low
payoff).- Adding new tests or coverage — pure refactor of existing assertions.
Acceptance criteria
Tests/Support/TestUtils.hdefines the three macros and is reachable
from every test executable that asserts on call counts.- All
*Count/ call-flag variables and getters follow the
<name>CallCountrule (onlylastCountexception noted above
remains). - All call-count assertions use
CALLED_FUNCTION,CALLED_FAKE, or
CALLED_FAKE_ON— noLONGS_EQUAL/CHECK_TRUEagainst a counter
or call-flag remains. - Bespoke macros in
SolidSyslogErrorTest.cppremoved. - All CI checks pass; coverage unchanged within noise.
Notes
- Single PR, pure test refactor — large diff but mechanical.
- Pre-PR check list (per CLAUDE.md): build-linux-gcc, build-linux-clang,
sanitize-linux-gcc, coverage-linux-gcc, analyze-tidy, analyze-cppcheck,
analyze-format.
Parent epic: #254
Activity