From 809f347389ae06d09fcf83e0b37bd77a83931abc Mon Sep 17 00:00:00 2001 From: David Cozens Date: Sun, 10 May 2026 21:01:15 +0100 Subject: [PATCH 01/10] chore: S24.02 rename SenderFake *Count getters to *CallCount Pure rename ahead of the upcoming CALLED_FUNCTION test macro sweep. Aligns SenderFake_SendCount / DisconnectCount with the *CallCount naming rule that the new token-paste macros enforce. No behaviour change; 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- Tests/SenderFake.c | 4 +- Tests/SenderFake.h | 4 +- Tests/SenderFakeTest.cpp | 24 +++---- Tests/SolidSyslogNullBufferTest.cpp | 6 +- ...SolidSyslogPosixMessageQueueBufferTest.cpp | 2 +- Tests/SolidSyslogSwitchingSenderTest.cpp | 72 +++++++++---------- Tests/SolidSyslogTest.cpp | 20 +++--- Tests/TestUtils.h | 2 +- 8 files changed, 67 insertions(+), 67 deletions(-) diff --git a/Tests/SenderFake.c b/Tests/SenderFake.c index 3cf12b54..4b42958d 100644 --- a/Tests/SenderFake.c +++ b/Tests/SenderFake.c @@ -64,12 +64,12 @@ void SenderFake_Reset(struct SolidSyslogSender* sender) fake->failNextSend = false; } -int SenderFake_SendCount(struct SolidSyslogSender* sender) +int SenderFake_SendCallCount(struct SolidSyslogSender* sender) { return ((struct SenderFake*) sender)->sendCount; } -int SenderFake_DisconnectCount(struct SolidSyslogSender* sender) +int SenderFake_DisconnectCallCount(struct SolidSyslogSender* sender) { return ((struct SenderFake*) sender)->disconnectCount; } diff --git a/Tests/SenderFake.h b/Tests/SenderFake.h index 918a05ef..306ac646 100644 --- a/Tests/SenderFake.h +++ b/Tests/SenderFake.h @@ -12,8 +12,8 @@ EXTERN_C_BEGIN struct SolidSyslogSender* SenderFake_Create(void); void SenderFake_Destroy(struct SolidSyslogSender * sender); void SenderFake_Reset(struct SolidSyslogSender * sender); - int SenderFake_SendCount(struct SolidSyslogSender * sender); - int SenderFake_DisconnectCount(struct SolidSyslogSender * sender); + int SenderFake_SendCallCount(struct SolidSyslogSender * sender); + int SenderFake_DisconnectCallCount(struct SolidSyslogSender * sender); const char* SenderFake_LastBufferAsString(struct SolidSyslogSender * sender); size_t SenderFake_LastSize(struct SolidSyslogSender * sender); void SenderFake_FailNextSend(struct SolidSyslogSender * sender); diff --git a/Tests/SenderFakeTest.cpp b/Tests/SenderFakeTest.cpp index f0940fb9..9bef18fb 100644 --- a/Tests/SenderFakeTest.cpp +++ b/Tests/SenderFakeTest.cpp @@ -23,38 +23,38 @@ TEST_GROUP(SenderFake) TEST(SenderFake, SendCountIsZeroAfterCreate) { - LONGS_EQUAL(0, SenderFake_SendCount(sender)); + LONGS_EQUAL(0, SenderFake_SendCallCount(sender)); } TEST(SenderFake, DisconnectCountIsZeroAfterCreate) { - LONGS_EQUAL(0, SenderFake_DisconnectCount(sender)); + LONGS_EQUAL(0, SenderFake_DisconnectCallCount(sender)); } TEST(SenderFake, SendCountIncrementsOnSend) { SolidSyslogSender_Send(sender, "a", 1); - LONGS_EQUAL(1, SenderFake_SendCount(sender)); + LONGS_EQUAL(1, SenderFake_SendCallCount(sender)); } TEST(SenderFake, SendCountIncrementsTwiceOnTwoSends) { SolidSyslogSender_Send(sender, "a", 1); SolidSyslogSender_Send(sender, "b", 1); - LONGS_EQUAL(2, SenderFake_SendCount(sender)); + LONGS_EQUAL(2, SenderFake_SendCallCount(sender)); } TEST(SenderFake, DisconnectCountIncrementsOnDisconnect) { SolidSyslogSender_Disconnect(sender); - LONGS_EQUAL(1, SenderFake_DisconnectCount(sender)); + LONGS_EQUAL(1, SenderFake_DisconnectCallCount(sender)); } TEST(SenderFake, DisconnectCountIncrementsTwiceOnTwoDisconnects) { SolidSyslogSender_Disconnect(sender); SolidSyslogSender_Disconnect(sender); - LONGS_EQUAL(2, SenderFake_DisconnectCount(sender)); + LONGS_EQUAL(2, SenderFake_DisconnectCallCount(sender)); } TEST(SenderFake, LastBufferCapturesMessage) @@ -92,14 +92,14 @@ TEST(SenderFake, ResetClearsSendCount) { SolidSyslogSender_Send(sender, "a", 1); SenderFake_Reset(sender); - LONGS_EQUAL(0, SenderFake_SendCount(sender)); + LONGS_EQUAL(0, SenderFake_SendCallCount(sender)); } TEST(SenderFake, ResetClearsDisconnectCount) { SolidSyslogSender_Disconnect(sender); SenderFake_Reset(sender); - LONGS_EQUAL(0, SenderFake_DisconnectCount(sender)); + LONGS_EQUAL(0, SenderFake_DisconnectCallCount(sender)); } TEST(SenderFake, FailNextSendReturnsFalse) @@ -153,15 +153,15 @@ TEST(SenderFakeInstances, TwoInstancesHaveDistinctHandles) TEST(SenderFakeInstances, SendCountsAreIndependent) { SolidSyslogSender_Send(a, "x", 1); - LONGS_EQUAL(1, SenderFake_SendCount(a)); - LONGS_EQUAL(0, SenderFake_SendCount(b)); + LONGS_EQUAL(1, SenderFake_SendCallCount(a)); + LONGS_EQUAL(0, SenderFake_SendCallCount(b)); } TEST(SenderFakeInstances, DisconnectCountsAreIndependent) { SolidSyslogSender_Disconnect(a); - LONGS_EQUAL(1, SenderFake_DisconnectCount(a)); - LONGS_EQUAL(0, SenderFake_DisconnectCount(b)); + LONGS_EQUAL(1, SenderFake_DisconnectCallCount(a)); + LONGS_EQUAL(0, SenderFake_DisconnectCallCount(b)); } TEST(SenderFakeInstances, LastBuffersAreIndependent) diff --git a/Tests/SolidSyslogNullBufferTest.cpp b/Tests/SolidSyslogNullBufferTest.cpp index b3432585..bd673237 100644 --- a/Tests/SolidSyslogNullBufferTest.cpp +++ b/Tests/SolidSyslogNullBufferTest.cpp @@ -54,19 +54,19 @@ TEST(SolidSyslogNullBuffer, WriteForwardsSizeToSender) TEST(SolidSyslogNullBuffer, WriteResultsInOneSend) { Write(); - LONGS_EQUAL(1, SenderFake_SendCount(fakeSender)); + LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); } TEST(SolidSyslogNullBuffer, TwoWritesResultInTwoSends) { Write(); Write(); - LONGS_EQUAL(2, SenderFake_SendCount(fakeSender)); + LONGS_EQUAL(2, SenderFake_SendCallCount(fakeSender)); } TEST(SolidSyslogNullBuffer, NoWritesResultInNoSends) { - LONGS_EQUAL(0, SenderFake_SendCount(fakeSender)); + LONGS_EQUAL(0, SenderFake_SendCallCount(fakeSender)); } TEST(SolidSyslogNullBuffer, ReadReturnsNothingToSend) diff --git a/Tests/SolidSyslogPosixMessageQueueBufferTest.cpp b/Tests/SolidSyslogPosixMessageQueueBufferTest.cpp index 4f9639c8..61b70502 100644 --- a/Tests/SolidSyslogPosixMessageQueueBufferTest.cpp +++ b/Tests/SolidSyslogPosixMessageQueueBufferTest.cpp @@ -103,7 +103,7 @@ TEST(SolidSyslogPosixMessageQueueBuffer, ServiceSendsMessageWrittenViaLog) SolidSyslogMessage message = {SOLIDSYSLOG_FACILITY_LOCAL0, SOLIDSYSLOG_SEVERITY_INFO, nullptr, nullptr}; SolidSyslog_Log(&message); SolidSyslog_Service(); - LONGS_EQUAL(1, SenderFake_SendCount(fakeSender)); + LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); SolidSyslog_Destroy(); SolidSyslogNullStore_Destroy(); diff --git a/Tests/SolidSyslogSwitchingSenderTest.cpp b/Tests/SolidSyslogSwitchingSenderTest.cpp index ed28647a..3eb88032 100644 --- a/Tests/SolidSyslogSwitchingSenderTest.cpp +++ b/Tests/SolidSyslogSwitchingSenderTest.cpp @@ -86,30 +86,30 @@ TEST(SolidSyslogSwitchingSender, CreateDestroyWorksWithoutCrashing) TEST(SolidSyslogSwitchingSender, DestroyDoesNotSendToInnerSenders) { SolidSyslogSwitchingSender_Destroy(); - CALLED_FUNCTION(SenderFake_SendCount(innerA), NEVER); - CALLED_FUNCTION(SenderFake_SendCount(innerB), NEVER); + CALLED_FUNCTION(SenderFake_SendCallCount(innerA), NEVER); + CALLED_FUNCTION(SenderFake_SendCallCount(innerB), NEVER); } TEST(SolidSyslogSwitchingSender, DestroyDoesNotDisconnectInnerSenders) { SolidSyslogSwitchingSender_Destroy(); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerA), NEVER); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerB), NEVER); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), NEVER); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); } TEST(SolidSyslogSwitchingSender, SendDelegatesToSenderAtSelectedIndex) { Send("x", 1); - CALLED_FUNCTION(SenderFake_SendCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_SendCount(innerB), NEVER); + CALLED_FUNCTION(SenderFake_SendCallCount(innerA), ONCE); + CALLED_FUNCTION(SenderFake_SendCallCount(innerB), NEVER); } TEST(SolidSyslogSwitchingSender, SecondSendAtSameIndexDoesNotDisconnect) { Send("x", 1); Send("y", 1); - CALLED_FUNCTION(SenderFake_SendCount(innerA), TWICE); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerA), NEVER); + CALLED_FUNCTION(SenderFake_SendCallCount(innerA), TWICE); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), NEVER); } TEST(SolidSyslogSwitchingSender, SelectorChangeDisconnectsOutgoingAndSendsOnIncoming) @@ -117,10 +117,10 @@ TEST(SolidSyslogSwitchingSender, SelectorChangeDisconnectsOutgoingAndSendsOnInco Send("x", 1); selectorReturn = INNER_B; Send("y", 1); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_SendCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_SendCount(innerB), ONCE); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerB), NEVER); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), ONCE); + CALLED_FUNCTION(SenderFake_SendCallCount(innerA), ONCE); + CALLED_FUNCTION(SenderFake_SendCallCount(innerB), ONCE); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); } TEST(SolidSyslogSwitchingSender, SteadyStateAfterSwitchDoesNotDisconnectAgain) @@ -129,24 +129,24 @@ TEST(SolidSyslogSwitchingSender, SteadyStateAfterSwitchDoesNotDisconnectAgain) selectorReturn = INNER_B; Send("y", 1); Send("z", 1); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerB), NEVER); - CALLED_FUNCTION(SenderFake_SendCount(innerB), TWICE); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), ONCE); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); + CALLED_FUNCTION(SenderFake_SendCallCount(innerB), TWICE); } TEST(SolidSyslogSwitchingSender, DisconnectBeforeAnySendDoesNotTouchInnerSenders) { SolidSyslogSender_Disconnect(sender); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerA), NEVER); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerB), NEVER); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), NEVER); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); } TEST(SolidSyslogSwitchingSender, DisconnectForwardsToCurrentSender) { Send("x", 1); SolidSyslogSender_Disconnect(sender); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerB), NEVER); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), ONCE); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); } TEST(SolidSyslogSwitchingSender, DisconnectAfterSwitchForwardsToNewActive) @@ -155,8 +155,8 @@ TEST(SolidSyslogSwitchingSender, DisconnectAfterSwitchForwardsToNewActive) selectorReturn = INNER_B; Send("y", 1); SolidSyslogSender_Disconnect(sender); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerB), ONCE); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), ONCE); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), ONCE); } TEST(SolidSyslogSwitchingSender, DisconnectAfterSelectorChangeWithoutSendForwardsToPreviouslyActive) @@ -166,16 +166,16 @@ TEST(SolidSyslogSwitchingSender, DisconnectAfterSelectorChangeWithoutSendForward SolidSyslogSender_Disconnect(sender); // Disconnect does not re-consult the selector — it forwards to the // currently-held sender, so innerA receives the Disconnect. - CALLED_FUNCTION(SenderFake_DisconnectCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerB), NEVER); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), ONCE); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); } TEST(SolidSyslogSwitchingSender, SelectorReturningNonZeroOnFirstSendLandsOnThatIndex) { selectorReturn = INNER_B; Send("x", 1); - CALLED_FUNCTION(SenderFake_SendCount(innerA), NEVER); - CALLED_FUNCTION(SenderFake_SendCount(innerB), ONCE); + CALLED_FUNCTION(SenderFake_SendCallCount(innerA), NEVER); + CALLED_FUNCTION(SenderFake_SendCallCount(innerB), ONCE); } TEST(SolidSyslogSwitchingSender, SendForwardsBufferVerbatimToActive) @@ -197,9 +197,9 @@ TEST(SolidSyslogSwitchingSender, SelectorAtLastValidIndexDelegatesToThatSender) CreateSwitchingSender(3); selectorReturn = INNER_C; Send("x", 1); - CALLED_FUNCTION(SenderFake_SendCount(innerA), NEVER); - CALLED_FUNCTION(SenderFake_SendCount(innerB), NEVER); - CALLED_FUNCTION(SenderFake_SendCount(innerC), ONCE); + CALLED_FUNCTION(SenderFake_SendCallCount(innerA), NEVER); + CALLED_FUNCTION(SenderFake_SendCallCount(innerB), NEVER); + CALLED_FUNCTION(SenderFake_SendCallCount(innerC), ONCE); } TEST(SolidSyslogSwitchingSender, ZeroSenderCountSendReturnsFalse) @@ -218,8 +218,8 @@ TEST(SolidSyslogSwitchingSender, SelectorBeyondEndSendReturnsFalseAndDoesNotTouc { selectorReturn = BEYOND_END; CHECK_FALSE(SolidSyslogSender_Send(sender, "x", 1)); - CALLED_FUNCTION(SenderFake_SendCount(innerA), NEVER); - CALLED_FUNCTION(SenderFake_SendCount(innerB), NEVER); + CALLED_FUNCTION(SenderFake_SendCallCount(innerA), NEVER); + CALLED_FUNCTION(SenderFake_SendCallCount(innerB), NEVER); } TEST(SolidSyslogSwitchingSender, DisconnectAfterSwitchingBeyondEndIsNilSafe) @@ -228,18 +228,18 @@ TEST(SolidSyslogSwitchingSender, DisconnectAfterSwitchingBeyondEndIsNilSafe) selectorReturn = BEYOND_END; Send("y", 1); // innerA was active, switched away — one Disconnect from the switch - CALLED_FUNCTION(SenderFake_DisconnectCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerB), NEVER); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), ONCE); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); // explicit Disconnect now resolves to nil — no inner sender touched SolidSyslogSender_Disconnect(sender); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerB), NEVER); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), ONCE); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); } TEST(SolidSyslogSwitchingSender, SelectorBeyondEndDisconnectBeforeSendDoesNotTouchInnerSenders) { selectorReturn = BEYOND_END; SolidSyslogSender_Disconnect(sender); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerA), NEVER); - CALLED_FUNCTION(SenderFake_DisconnectCount(innerB), NEVER); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), NEVER); + CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); } diff --git a/Tests/SolidSyslogTest.cpp b/Tests/SolidSyslogTest.cpp index b4a2d7fb..552f0a28 100644 --- a/Tests/SolidSyslogTest.cpp +++ b/Tests/SolidSyslogTest.cpp @@ -364,13 +364,13 @@ TEST(SolidSyslog, CreateDestroyWorksWithoutCrashing) TEST(SolidSyslog, NoMessagesAreSentWhenLogIsNotCalled) { - LONGS_EQUAL(0, SenderFake_SendCount(fakeSender)); + LONGS_EQUAL(0, SenderFake_SendCallCount(fakeSender)); } TEST(SolidSyslog, SingleLogCallResultsInOneSend) { Log(); - LONGS_EQUAL(1, SenderFake_SendCount(fakeSender)); + LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); } TEST(SolidSyslog, PriValIs134) @@ -1264,7 +1264,7 @@ TEST(SolidSyslog, ServiceSendsMessageReadFromBuffer) SenderFake_Reset(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(1, SenderFake_SendCount(fakeSender)); + LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); STRCMP_EQUAL("test", SenderFake_LastBufferAsString(fakeSender)); SolidSyslog_Destroy(); @@ -1285,7 +1285,7 @@ TEST(SolidSyslog, ServiceSendsBufferedMessageWithNullStore) SenderFake_Reset(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(1, SenderFake_SendCount(fakeSender)); + LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); STRCMP_EQUAL("test", SenderFake_LastBufferAsString(fakeSender)); SolidSyslog_Destroy(); @@ -1307,7 +1307,7 @@ TEST(SolidSyslog, ServiceSendsFromStoreWhenHasUnsent) SenderFake_Reset(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(1, SenderFake_SendCount(fakeSender)); + LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); STRCMP_EQUAL("stored", SenderFake_LastBufferAsString(fakeSender)); SolidSyslog_Destroy(); @@ -1418,7 +1418,7 @@ TEST(SolidSyslog, ServiceSendsDirectlyWhenStoreWriteFails) SenderFake_Reset(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(1, SenderFake_SendCount(fakeSender)); + LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); STRCMP_EQUAL("direct", SenderFake_LastBufferAsString(fakeSender)); SolidSyslog_Destroy(); @@ -1441,7 +1441,7 @@ TEST(SolidSyslog, ServiceDoesNotSendWhenStoreReadFails) SenderFake_Reset(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(0, SenderFake_SendCount(fakeSender)); + LONGS_EQUAL(0, SenderFake_SendCallCount(fakeSender)); SolidSyslog_Destroy(); SolidSyslog_Create(&config); @@ -1464,7 +1464,7 @@ TEST(SolidSyslog, ServiceDoesNotMarkSentWhenSendingFromBuffer) SenderFake_Reset(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(1, SenderFake_SendCount(fakeSender)); + LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); STRCMP_EQUAL("from-buffer", SenderFake_LastBufferAsString(fakeSender)); SolidSyslog_Destroy(); @@ -1539,7 +1539,7 @@ TEST(SolidSyslogServiceEagerDrain, StoredMessagesDrainInFifoOrderAcrossTicks) STRCMP_EQUAL("m2", SenderFake_LastBufferAsString(fakeSender)); SolidSyslog_Service(); STRCMP_EQUAL("m3", SenderFake_LastBufferAsString(fakeSender)); - LONGS_EQUAL(3, SenderFake_SendCount(fakeSender)); + LONGS_EQUAL(3, SenderFake_SendCallCount(fakeSender)); } TEST(SolidSyslog, ServiceDoesNothingWhenStoreIsHalted) @@ -1556,7 +1556,7 @@ TEST(SolidSyslog, ServiceDoesNothingWhenStoreIsHalted) SenderFake_Reset(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(0, SenderFake_SendCount(fakeSender)); + LONGS_EQUAL(0, SenderFake_SendCallCount(fakeSender)); SolidSyslog_Destroy(); SolidSyslog_Create(&config); diff --git a/Tests/TestUtils.h b/Tests/TestUtils.h index ae279a22..47ea87de 100644 --- a/Tests/TestUtils.h +++ b/Tests/TestUtils.h @@ -27,7 +27,7 @@ enum } // namespace CososoTesting /* Assert that a call-count expression equals an expected count. - * Reads as: CALLED_FUNCTION(SenderFake_SendCount(inner), ONCE); + * Reads as: CALLED_FUNCTION(SenderFake_SendCallCount(inner), ONCE); * (with `using namespace CososoTesting;` in scope). */ /* NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -- CppUTest assertions are macro-based */ #define CALLED_FUNCTION(f, n) LONGS_EQUAL((n), (f)) From 5e867cfcb528c82e4eb6cf4ff0209fc3dbd0f494 Mon Sep 17 00:00:00 2001 From: David Cozens Date: Sun, 10 May 2026 21:05:12 +0100 Subject: [PATCH 02/10] chore: S24.02 swap CALLED_FUNCTION for the three-macro design MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces TestUtils.h's single expression-based CALLED_FUNCTION with three token-paste macros that enforce the CallCount naming rule at compile time: CALLED_FUNCTION(name, count) for local static counters CALLED_FAKE(getter, count) for global-state fake getters CALLED_FAKE_ON(getter, instance, count) for instance-parameter getters Migrates the two pre-existing call sites: - SolidSyslogSwitchingSenderTest.cpp — was the only consumer of the old expression form; every site fits CALLED_FAKE_ON cleanly after the SenderFake *Count -> *CallCount rename. - SolidSyslogErrorTest.cpp — the bespoke CHECK_HANDLER_INVOKED_ONCE / CHECK_HANDLER_NOT_INVOKED macros are now redundant; replaced with CALLED_FUNCTION(handler, ...). CososoTesting namespace + NEVER/ONCE/TWICE/THRICE enum unchanged. 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- Tests/SolidSyslogErrorTest.cpp | 11 ++-- Tests/SolidSyslogSwitchingSenderTest.cpp | 74 ++++++++++++------------ Tests/TestUtils.h | 25 ++++++-- 3 files changed, 63 insertions(+), 47 deletions(-) diff --git a/Tests/SolidSyslogErrorTest.cpp b/Tests/SolidSyslogErrorTest.cpp index 803057aa..01b86387 100644 --- a/Tests/SolidSyslogErrorTest.cpp +++ b/Tests/SolidSyslogErrorTest.cpp @@ -4,6 +4,9 @@ #include "SolidSyslogError.h" #include "SolidSyslogErrorMessages.h" #include "SolidSyslogPrival.h" +#include "TestUtils.h" + +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros static int handlerCallCount; static enum SolidSyslog_Severity capturedSeverity; @@ -19,8 +22,6 @@ static void TestErrorHandler(void* context, enum SolidSyslog_Severity severity, } // NOLINTBEGIN(cppcoreguidelines-macro-usage) -- macros preserve __FILE__/__LINE__ in test failure output -#define CHECK_HANDLER_INVOKED_ONCE() LONGS_EQUAL(1, handlerCallCount) -#define CHECK_HANDLER_NOT_INVOKED() LONGS_EQUAL(0, handlerCallCount) #define CHECK_EXPECTED_SEVERITY(expected) LONGS_EQUAL((expected), capturedSeverity) #define CHECK_EXPECTED_MESSAGE(expected) STRCMP_EQUAL((expected), capturedMessage) #define CHECK_EXPECTED_CONTEXT(expected) POINTERS_EQUAL((expected), capturedContext) @@ -63,7 +64,7 @@ TEST(SolidSyslogError, InstalledHandlerReceivesSeverityMessageAndContext) installHandler(); SolidSyslog_Error(SOLIDSYSLOG_SEVERITY_WARNING, "warning message"); - CHECK_HANDLER_INVOKED_ONCE(); + CALLED_FUNCTION(handler, ONCE); CHECK_EXPECTED_SEVERITY(SOLIDSYSLOG_SEVERITY_WARNING); CHECK_EXPECTED_MESSAGE("warning message"); CHECK_EXPECTED_CONTEXT(&sentinel); @@ -76,7 +77,7 @@ TEST(SolidSyslogError, SetErrorHandlerWithNullHandlerRestoresDefault) SolidSyslog_SetErrorHandler(nullptr, &sentinel); SolidSyslog_Error(SOLIDSYSLOG_SEVERITY_ERR, "should not be observed"); - CHECK_HANDLER_NOT_INVOKED(); + CALLED_FUNCTION(handler, NEVER); } TEST(SolidSyslogError, SolidSyslogCreateWithNullConfigReportsError) @@ -85,7 +86,7 @@ TEST(SolidSyslogError, SolidSyslogCreateWithNullConfigReportsError) SolidSyslog_Create(nullptr); - CHECK_HANDLER_INVOKED_ONCE(); + CALLED_FUNCTION(handler, ONCE); CHECK_EXPECTED_SEVERITY(SOLIDSYSLOG_SEVERITY_ERR); CHECK_EXPECTED_MESSAGE(SOLIDSYSLOG_ERROR_MSG_CREATE_NULL_CONFIG); } diff --git a/Tests/SolidSyslogSwitchingSenderTest.cpp b/Tests/SolidSyslogSwitchingSenderTest.cpp index 3eb88032..1fc928af 100644 --- a/Tests/SolidSyslogSwitchingSenderTest.cpp +++ b/Tests/SolidSyslogSwitchingSenderTest.cpp @@ -7,7 +7,7 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for CALLED_FUNCTION +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros /* Selector return values — named for the inner sender they select, so tests * read as `selectorReturn = INNER_B`. */ @@ -86,30 +86,30 @@ TEST(SolidSyslogSwitchingSender, CreateDestroyWorksWithoutCrashing) TEST(SolidSyslogSwitchingSender, DestroyDoesNotSendToInnerSenders) { SolidSyslogSwitchingSender_Destroy(); - CALLED_FUNCTION(SenderFake_SendCallCount(innerA), NEVER); - CALLED_FUNCTION(SenderFake_SendCallCount(innerB), NEVER); + CALLED_FAKE_ON(SenderFake_Send, innerA, NEVER); + CALLED_FAKE_ON(SenderFake_Send, innerB, NEVER); } TEST(SolidSyslogSwitchingSender, DestroyDoesNotDisconnectInnerSenders) { SolidSyslogSwitchingSender_Destroy(); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), NEVER); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); + CALLED_FAKE_ON(SenderFake_Disconnect, innerA, NEVER); + CALLED_FAKE_ON(SenderFake_Disconnect, innerB, NEVER); } TEST(SolidSyslogSwitchingSender, SendDelegatesToSenderAtSelectedIndex) { Send("x", 1); - CALLED_FUNCTION(SenderFake_SendCallCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_SendCallCount(innerB), NEVER); + CALLED_FAKE_ON(SenderFake_Send, innerA, ONCE); + CALLED_FAKE_ON(SenderFake_Send, innerB, NEVER); } TEST(SolidSyslogSwitchingSender, SecondSendAtSameIndexDoesNotDisconnect) { Send("x", 1); Send("y", 1); - CALLED_FUNCTION(SenderFake_SendCallCount(innerA), TWICE); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), NEVER); + CALLED_FAKE_ON(SenderFake_Send, innerA, TWICE); + CALLED_FAKE_ON(SenderFake_Disconnect, innerA, NEVER); } TEST(SolidSyslogSwitchingSender, SelectorChangeDisconnectsOutgoingAndSendsOnIncoming) @@ -117,10 +117,10 @@ TEST(SolidSyslogSwitchingSender, SelectorChangeDisconnectsOutgoingAndSendsOnInco Send("x", 1); selectorReturn = INNER_B; Send("y", 1); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_SendCallCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_SendCallCount(innerB), ONCE); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); + CALLED_FAKE_ON(SenderFake_Disconnect, innerA, ONCE); + CALLED_FAKE_ON(SenderFake_Send, innerA, ONCE); + CALLED_FAKE_ON(SenderFake_Send, innerB, ONCE); + CALLED_FAKE_ON(SenderFake_Disconnect, innerB, NEVER); } TEST(SolidSyslogSwitchingSender, SteadyStateAfterSwitchDoesNotDisconnectAgain) @@ -129,24 +129,24 @@ TEST(SolidSyslogSwitchingSender, SteadyStateAfterSwitchDoesNotDisconnectAgain) selectorReturn = INNER_B; Send("y", 1); Send("z", 1); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); - CALLED_FUNCTION(SenderFake_SendCallCount(innerB), TWICE); + CALLED_FAKE_ON(SenderFake_Disconnect, innerA, ONCE); + CALLED_FAKE_ON(SenderFake_Disconnect, innerB, NEVER); + CALLED_FAKE_ON(SenderFake_Send, innerB, TWICE); } TEST(SolidSyslogSwitchingSender, DisconnectBeforeAnySendDoesNotTouchInnerSenders) { SolidSyslogSender_Disconnect(sender); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), NEVER); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); + CALLED_FAKE_ON(SenderFake_Disconnect, innerA, NEVER); + CALLED_FAKE_ON(SenderFake_Disconnect, innerB, NEVER); } TEST(SolidSyslogSwitchingSender, DisconnectForwardsToCurrentSender) { Send("x", 1); SolidSyslogSender_Disconnect(sender); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); + CALLED_FAKE_ON(SenderFake_Disconnect, innerA, ONCE); + CALLED_FAKE_ON(SenderFake_Disconnect, innerB, NEVER); } TEST(SolidSyslogSwitchingSender, DisconnectAfterSwitchForwardsToNewActive) @@ -155,8 +155,8 @@ TEST(SolidSyslogSwitchingSender, DisconnectAfterSwitchForwardsToNewActive) selectorReturn = INNER_B; Send("y", 1); SolidSyslogSender_Disconnect(sender); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), ONCE); + CALLED_FAKE_ON(SenderFake_Disconnect, innerA, ONCE); + CALLED_FAKE_ON(SenderFake_Disconnect, innerB, ONCE); } TEST(SolidSyslogSwitchingSender, DisconnectAfterSelectorChangeWithoutSendForwardsToPreviouslyActive) @@ -166,16 +166,16 @@ TEST(SolidSyslogSwitchingSender, DisconnectAfterSelectorChangeWithoutSendForward SolidSyslogSender_Disconnect(sender); // Disconnect does not re-consult the selector — it forwards to the // currently-held sender, so innerA receives the Disconnect. - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); + CALLED_FAKE_ON(SenderFake_Disconnect, innerA, ONCE); + CALLED_FAKE_ON(SenderFake_Disconnect, innerB, NEVER); } TEST(SolidSyslogSwitchingSender, SelectorReturningNonZeroOnFirstSendLandsOnThatIndex) { selectorReturn = INNER_B; Send("x", 1); - CALLED_FUNCTION(SenderFake_SendCallCount(innerA), NEVER); - CALLED_FUNCTION(SenderFake_SendCallCount(innerB), ONCE); + CALLED_FAKE_ON(SenderFake_Send, innerA, NEVER); + CALLED_FAKE_ON(SenderFake_Send, innerB, ONCE); } TEST(SolidSyslogSwitchingSender, SendForwardsBufferVerbatimToActive) @@ -197,9 +197,9 @@ TEST(SolidSyslogSwitchingSender, SelectorAtLastValidIndexDelegatesToThatSender) CreateSwitchingSender(3); selectorReturn = INNER_C; Send("x", 1); - CALLED_FUNCTION(SenderFake_SendCallCount(innerA), NEVER); - CALLED_FUNCTION(SenderFake_SendCallCount(innerB), NEVER); - CALLED_FUNCTION(SenderFake_SendCallCount(innerC), ONCE); + CALLED_FAKE_ON(SenderFake_Send, innerA, NEVER); + CALLED_FAKE_ON(SenderFake_Send, innerB, NEVER); + CALLED_FAKE_ON(SenderFake_Send, innerC, ONCE); } TEST(SolidSyslogSwitchingSender, ZeroSenderCountSendReturnsFalse) @@ -218,8 +218,8 @@ TEST(SolidSyslogSwitchingSender, SelectorBeyondEndSendReturnsFalseAndDoesNotTouc { selectorReturn = BEYOND_END; CHECK_FALSE(SolidSyslogSender_Send(sender, "x", 1)); - CALLED_FUNCTION(SenderFake_SendCallCount(innerA), NEVER); - CALLED_FUNCTION(SenderFake_SendCallCount(innerB), NEVER); + CALLED_FAKE_ON(SenderFake_Send, innerA, NEVER); + CALLED_FAKE_ON(SenderFake_Send, innerB, NEVER); } TEST(SolidSyslogSwitchingSender, DisconnectAfterSwitchingBeyondEndIsNilSafe) @@ -228,18 +228,18 @@ TEST(SolidSyslogSwitchingSender, DisconnectAfterSwitchingBeyondEndIsNilSafe) selectorReturn = BEYOND_END; Send("y", 1); // innerA was active, switched away — one Disconnect from the switch - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); + CALLED_FAKE_ON(SenderFake_Disconnect, innerA, ONCE); + CALLED_FAKE_ON(SenderFake_Disconnect, innerB, NEVER); // explicit Disconnect now resolves to nil — no inner sender touched SolidSyslogSender_Disconnect(sender); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), ONCE); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); + CALLED_FAKE_ON(SenderFake_Disconnect, innerA, ONCE); + CALLED_FAKE_ON(SenderFake_Disconnect, innerB, NEVER); } TEST(SolidSyslogSwitchingSender, SelectorBeyondEndDisconnectBeforeSendDoesNotTouchInnerSenders) { selectorReturn = BEYOND_END; SolidSyslogSender_Disconnect(sender); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerA), NEVER); - CALLED_FUNCTION(SenderFake_DisconnectCallCount(innerB), NEVER); + CALLED_FAKE_ON(SenderFake_Disconnect, innerA, NEVER); + CALLED_FAKE_ON(SenderFake_Disconnect, innerB, NEVER); } diff --git a/Tests/TestUtils.h b/Tests/TestUtils.h index 47ea87de..111835de 100644 --- a/Tests/TestUtils.h +++ b/Tests/TestUtils.h @@ -26,11 +26,26 @@ enum }; } // namespace CososoTesting -/* Assert that a call-count expression equals an expected count. - * Reads as: CALLED_FUNCTION(SenderFake_SendCallCount(inner), ONCE); - * (with `using namespace CososoTesting;` in scope). */ -/* NOLINTNEXTLINE(cppcoreguidelines-macro-usage) -- CppUTest assertions are macro-based */ -#define CALLED_FUNCTION(f, n) LONGS_EQUAL((n), (f)) +/* Assert that a fake/spy was called the expected number of times. + * Token paste enforces the CallCount naming rule at compile time. + * Tests opt in to NEVER/ONCE/... via `using namespace CososoTesting;`. + * + * Use CALLED_FUNCTION for local static int counters in test files, + * CALLED_FAKE for fake-library getters with no parameters, and + * CALLED_FAKE_ON for fake-library getters that take an instance pointer. + * + * CALLED_FUNCTION(handler, ONCE) + * -> LONGS_EQUAL(1, handlerCallCount) + * CALLED_FAKE(SocketFake_Send, TWICE) + * -> LONGS_EQUAL(2, SocketFake_SendCallCount()) + * CALLED_FAKE_ON(SenderFake_Send, inner, ONCE) + * -> LONGS_EQUAL(1, SenderFake_SendCallCount(inner)) + */ +// NOLINTBEGIN(cppcoreguidelines-macro-usage) -- token paste enforces the 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)) +// NOLINTEND(cppcoreguidelines-macro-usage) #endif /* __cplusplus */ From 83abbb31e4e1f0339721b89d8ff0b95ecd1c3c62 Mon Sep 17 00:00:00 2001 From: David Cozens Date: Sun, 10 May 2026 21:05:54 +0100 Subject: [PATCH 03/10] chore: S24.02 rename StoreFake_WriteCount to StoreFake_WriteCallCount Aligns the last non-conforming fake-library getter with the *CallCount naming rule. Pure rename; 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- Tests/SolidSyslogTest.cpp | 2 +- Tests/StoreFake.c | 2 +- Tests/StoreFake.h | 2 +- Tests/StoreFakeTest.cpp | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/SolidSyslogTest.cpp b/Tests/SolidSyslogTest.cpp index 552f0a28..c4621983 100644 --- a/Tests/SolidSyslogTest.cpp +++ b/Tests/SolidSyslogTest.cpp @@ -1524,7 +1524,7 @@ TEST(SolidSyslogServiceEagerDrain, AllBufferedMessagesReachStoreInOneTickWhenSen SenderFake_FailNextSend(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(3, StoreFake_WriteCount(fakeStore)); + LONGS_EQUAL(3, StoreFake_WriteCallCount(fakeStore)); } TEST(SolidSyslogServiceEagerDrain, StoredMessagesDrainInFifoOrderAcrossTicks) diff --git a/Tests/StoreFake.c b/Tests/StoreFake.c index 806a257e..a6ea233b 100644 --- a/Tests/StoreFake.c +++ b/Tests/StoreFake.c @@ -58,7 +58,7 @@ void StoreFake_FailNextRead(void) instance.failNextRead = true; } -int StoreFake_WriteCount(struct SolidSyslogStore* store) +int StoreFake_WriteCallCount(struct SolidSyslogStore* store) { return ((struct StoreFake*) store)->writeCount; } diff --git a/Tests/StoreFake.h b/Tests/StoreFake.h index dccf5ae2..b5958d55 100644 --- a/Tests/StoreFake.h +++ b/Tests/StoreFake.h @@ -10,7 +10,7 @@ EXTERN_C_BEGIN void StoreFake_FailNextWrite(void); void StoreFake_FailNextRead(void); void StoreFake_SetHalted(void); - int StoreFake_WriteCount(struct SolidSyslogStore * store); + int StoreFake_WriteCallCount(struct SolidSyslogStore * store); EXTERN_C_END diff --git a/Tests/StoreFakeTest.cpp b/Tests/StoreFakeTest.cpp index 1ac595a0..4b90dfab 100644 --- a/Tests/StoreFakeTest.cpp +++ b/Tests/StoreFakeTest.cpp @@ -115,7 +115,7 @@ TEST(StoreFake, WriteCountReportsSuccessfulWrites) { SolidSyslogStore_Write(store, "a", 1); SolidSyslogStore_Write(store, "b", 1); - LONGS_EQUAL(2, StoreFake_WriteCount(store)); + LONGS_EQUAL(2, StoreFake_WriteCallCount(store)); } TEST(StoreFake, WriteCountIgnoresFailedWrite) @@ -123,5 +123,5 @@ TEST(StoreFake, WriteCountIgnoresFailedWrite) SolidSyslogStore_Write(store, "a", 1); StoreFake_FailNextWrite(); SolidSyslogStore_Write(store, "b", 1); - LONGS_EQUAL(1, StoreFake_WriteCount(store)); + LONGS_EQUAL(1, StoreFake_WriteCallCount(store)); } From eb0a0ddeeb1537f3f5d1cf1faaee08d0e3f5c210 Mon Sep 17 00:00:00 2001 From: David Cozens Date: Sun, 10 May 2026 21:10:51 +0100 Subject: [PATCH 04/10] chore: S24.02 convert TlsStreamTest to CALLED_* macros Renames g_sleepCallCount to NoOpSleepCallCount (matches the function that increments it), and converts every call-count assertion in the file (50 sites) to the new macros: CALLED_FAKE for global-state OpenSslFake getters, CALLED_FAKE_ON for instance-parameter StreamFake getters, CALLED_FUNCTION for the local sleep counter. 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- Tests/SolidSyslogTlsStreamTest.cpp | 109 +++++++++++++++-------------- 1 file changed, 56 insertions(+), 53 deletions(-) diff --git a/Tests/SolidSyslogTlsStreamTest.cpp b/Tests/SolidSyslogTlsStreamTest.cpp index 7e778908..8b0318b2 100644 --- a/Tests/SolidSyslogTlsStreamTest.cpp +++ b/Tests/SolidSyslogTlsStreamTest.cpp @@ -10,18 +10,21 @@ #include "SolidSyslogTlsStream.h" #include "SolidSyslogTransport.h" #include "StreamFake.h" +#include "TestUtils.h" #include "CppUTest/TestHarness.h" +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + class TEST_SolidSyslogTlsStream_ReadReturnsNegativeOneOnHardErrorAndClosesSsl_Test; class TEST_SolidSyslogTlsStream_ReadReturnsNegativeOneOnZeroReturnAndClosesSsl_Test; class TEST_SolidSyslogTlsStream_SendClosesTransportOnWriteFailure_Test; -static int g_sleepCallCount; +static int NoOpSleepCallCount; static int g_lastSleepMs; static void NoOpSleep(int milliseconds) { - g_sleepCallCount++; + NoOpSleepCallCount++; g_lastSleepMs = milliseconds; } @@ -38,7 +41,7 @@ TEST_GROUP(SolidSyslogTlsStream) void setup() override { OpenSslFake_Reset(); - g_sleepCallCount = 0; + NoOpSleepCallCount = 0; g_lastSleepMs = 0; transport = StreamFake_Create(); config.transport = transport; @@ -129,28 +132,28 @@ TEST_GROUP(SolidSyslogTlsStream) #define CHECK_BIO_READ_RETRY_SIGNALLED() \ do \ { \ - LONGS_EQUAL(1, OpenSslFake_BioSetFlagsCallCount()); \ + CALLED_FAKE(OpenSslFake_BioSetFlags, ONCE); \ } while (0) #define CHECK_BIO_READ_RETRY_NOT_SIGNALLED() \ do \ { \ - LONGS_EQUAL(0, OpenSslFake_BioSetFlagsCallCount()); \ + CALLED_FAKE(OpenSslFake_BioSetFlags, NEVER); \ } while (0) #define CHECK_BIO_RETRY_FLAGS_CLEARED() \ do \ { \ - LONGS_EQUAL(1, OpenSslFake_BioClearFlagsCallCount()); \ + CALLED_FAKE(OpenSslFake_BioClearFlags, ONCE); \ } while (0) #define CHECK_SSL_SESSION_CLOSED() \ do \ { \ - LONGS_EQUAL(1, OpenSslFake_ShutdownCallCount()); \ - LONGS_EQUAL(1, OpenSslFake_FreeCallCount()); \ + CALLED_FAKE(OpenSslFake_Shutdown, ONCE); \ + CALLED_FAKE(OpenSslFake_Free, ONCE); \ } while (0) #define CHECK_TRANSPORT_CLOSED_ONCE() \ do \ { \ - LONGS_EQUAL(1, StreamFake_CloseCallCount(transport)); \ + CALLED_FAKE_ON(StreamFake_Close, transport, ONCE); \ } while (0) // NOLINTEND(cppcoreguidelines-macro-usage,cppcoreguidelines-avoid-do-while) @@ -173,7 +176,7 @@ TEST(SolidSyslogTlsStream, CreateReturnsHandleInsideCallerSuppliedStorage) TEST(SolidSyslogTlsStream, OpenOpensTransport) { SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, StreamFake_OpenCallCount(transport)); + CALLED_FAKE_ON(StreamFake_Open, transport, ONCE); } TEST(SolidSyslogTlsStream, OpenPassesAddressToTransport) @@ -185,7 +188,7 @@ TEST(SolidSyslogTlsStream, OpenPassesAddressToTransport) TEST(SolidSyslogTlsStream, OpenCreatesSslContext) { SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, OpenSslFake_CtxNewCallCount()); + CALLED_FAKE(OpenSslFake_CtxNew, ONCE); } TEST(SolidSyslogTlsStream, OpenLoadsCaBundleFromConfig) @@ -221,7 +224,7 @@ TEST(SolidSyslogTlsStream, OpenPassesCipherListToSslCtx) TEST(SolidSyslogTlsStream, OpenSkipsCipherListSetupWhenNotConfigured) { SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(0, OpenSslFake_SetCipherListCallCount()); + CALLED_FAKE(OpenSslFake_SetCipherList, NEVER); } TEST(SolidSyslogTlsStream, OpenReturnsFalseWhenCipherListRejected) @@ -240,13 +243,13 @@ TEST(SolidSyslogTlsStream, CipherListFailureFreesCtx) stream = SolidSyslogTlsStream_Create(&streamStorage, &config); OpenSslFake_SetCipherListFails(true); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, OpenSslFake_CtxFreeCallCount()); + CALLED_FAKE(OpenSslFake_CtxFree, ONCE); } TEST(SolidSyslogTlsStream, OpenCreatesSslSession) { SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, OpenSslFake_SslNewCallCount()); + CALLED_FAKE(OpenSslFake_SslNew, ONCE); } TEST(SolidSyslogTlsStream, OpenPassesCtxFromCtxNewToSslNew) @@ -258,13 +261,13 @@ TEST(SolidSyslogTlsStream, OpenPassesCtxFromCtxNewToSslNew) TEST(SolidSyslogTlsStream, OpenCreatesBio) { SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, OpenSslFake_BioNewCallCount()); + CALLED_FAKE(OpenSslFake_BioNew, ONCE); } TEST(SolidSyslogTlsStream, OpenSetsBioOnSsl) { SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, OpenSslFake_SetBioCallCount()); + CALLED_FAKE(OpenSslFake_SetBio, ONCE); } TEST(SolidSyslogTlsStream, OpenPassesSslFromNewToSetBio) @@ -282,7 +285,7 @@ TEST(SolidSyslogTlsStream, OpenPassesBioFromNewToSetBio) TEST(SolidSyslogTlsStream, OpenPerformsHandshake) { SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, OpenSslFake_ConnectCallCount()); + CALLED_FAKE(OpenSslFake_Connect, ONCE); } TEST(SolidSyslogTlsStream, OpenPassesSslToConnect) @@ -333,7 +336,7 @@ TEST(SolidSyslogTlsStream, BioReadCallbackDelegatesToTransportRead) } char buf[16]; readFn(OpenSslFake_LastBioReturned(), buf, sizeof(buf)); - LONGS_EQUAL(1, StreamFake_ReadCallCount(transport)); + CALLED_FAKE_ON(StreamFake_Read, transport, ONCE); } TEST(SolidSyslogTlsStream, BioWriteCallbackDelegatesToTransportSend) @@ -347,7 +350,7 @@ TEST(SolidSyslogTlsStream, BioWriteCallbackDelegatesToTransportSend) } const char msg[] = "hi"; writeFn(OpenSslFake_LastBioReturned(), msg, (int) sizeof(msg)); - LONGS_EQUAL(1, StreamFake_SendCallCount(transport)); + CALLED_FAKE_ON(StreamFake_Send, transport, ONCE); } TEST(SolidSyslogTlsStream, SendWritesToSsl) @@ -355,7 +358,7 @@ TEST(SolidSyslogTlsStream, SendWritesToSsl) SolidSyslogStream_Open(stream, addr); const char msg[] = "hello"; SolidSyslogStream_Send(stream, msg, sizeof(msg)); - LONGS_EQUAL(1, OpenSslFake_WriteCallCount()); + CALLED_FAKE(OpenSslFake_Write, ONCE); } TEST(SolidSyslogTlsStream, SendPassesBufferToSslWrite) @@ -387,7 +390,7 @@ TEST(SolidSyslogTlsStream, ReadReadsFromSsl) SolidSyslogStream_Open(stream, addr); char buf[16]; SolidSyslogStream_Read(stream, buf, sizeof(buf)); - LONGS_EQUAL(1, OpenSslFake_SslReadCallCount()); + CALLED_FAKE(OpenSslFake_SslRead, ONCE); } TEST(SolidSyslogTlsStream, ReadPassesSslFromNewToSslRead) @@ -418,35 +421,35 @@ TEST(SolidSyslogTlsStream, CloseShutsDownSsl) { SolidSyslogStream_Open(stream, addr); SolidSyslogStream_Close(stream); - LONGS_EQUAL(1, OpenSslFake_ShutdownCallCount()); + CALLED_FAKE(OpenSslFake_Shutdown, ONCE); } TEST(SolidSyslogTlsStream, CloseFreesSsl) { SolidSyslogStream_Open(stream, addr); SolidSyslogStream_Close(stream); - LONGS_EQUAL(1, OpenSslFake_FreeCallCount()); + CALLED_FAKE(OpenSslFake_Free, ONCE); } TEST(SolidSyslogTlsStream, CloseClosesTransport) { SolidSyslogStream_Open(stream, addr); SolidSyslogStream_Close(stream); - LONGS_EQUAL(1, StreamFake_CloseCallCount(transport)); + CALLED_FAKE_ON(StreamFake_Close, transport, ONCE); } TEST(SolidSyslogTlsStream, CloseFreesBioMethod) { SolidSyslogStream_Open(stream, addr); SolidSyslogStream_Close(stream); - LONGS_EQUAL(1, OpenSslFake_BioMethFreeCallCount()); + CALLED_FAKE(OpenSslFake_BioMethFree, ONCE); } TEST(SolidSyslogTlsStream, DestroyFreesSslContext) { SolidSyslogStream_Open(stream, addr); SolidSyslogTlsStream_Destroy(stream); - LONGS_EQUAL(1, OpenSslFake_CtxFreeCallCount()); + CALLED_FAKE(OpenSslFake_CtxFree, ONCE); /* teardown re-Destroys safely */ } @@ -454,7 +457,7 @@ TEST(SolidSyslogTlsStream, DestroyFreesBioMethodWhenCloseNotCalled) { SolidSyslogStream_Open(stream, addr); SolidSyslogTlsStream_Destroy(stream); - LONGS_EQUAL(1, OpenSslFake_BioMethFreeCallCount()); + CALLED_FAKE(OpenSslFake_BioMethFree, ONCE); /* teardown re-Destroys safely */ } @@ -463,14 +466,14 @@ TEST(SolidSyslogTlsStream, DestroyAfterCloseDoesNotDoubleFreeBioMethod) SolidSyslogStream_Open(stream, addr); SolidSyslogStream_Close(stream); SolidSyslogTlsStream_Destroy(stream); - LONGS_EQUAL(1, OpenSslFake_BioMethFreeCallCount()); + CALLED_FAKE(OpenSslFake_BioMethFree, ONCE); } TEST(SolidSyslogTlsStream, DestroyFreesSslWhenCloseNotCalled) { SolidSyslogStream_Open(stream, addr); SolidSyslogTlsStream_Destroy(stream); - LONGS_EQUAL(1, OpenSslFake_FreeCallCount()); + CALLED_FAKE(OpenSslFake_Free, ONCE); } TEST(SolidSyslogTlsStream, DestroyAfterCloseDoesNotDoubleFreeSsl) @@ -478,7 +481,7 @@ TEST(SolidSyslogTlsStream, DestroyAfterCloseDoesNotDoubleFreeSsl) SolidSyslogStream_Open(stream, addr); SolidSyslogStream_Close(stream); SolidSyslogTlsStream_Destroy(stream); - LONGS_EQUAL(1, OpenSslFake_FreeCallCount()); + CALLED_FAKE(OpenSslFake_Free, ONCE); } /* ------------------------------------------------------------------------- @@ -643,7 +646,7 @@ TEST(SolidSyslogTlsStream, LoadVerifyLocationsFailureFreesCtx) { OpenSslFake_SetLoadVerifyLocationsFails(true); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, OpenSslFake_CtxFreeCallCount()); + CALLED_FAKE(OpenSslFake_CtxFree, ONCE); } TEST(SolidSyslogTlsStream, OpenReturnsFalseWhenMinProtoVersionFails) @@ -656,7 +659,7 @@ TEST(SolidSyslogTlsStream, MinProtoVersionFailureFreesCtx) { OpenSslFake_SetMinProtoVersionFails(true); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, OpenSslFake_CtxFreeCallCount()); + CALLED_FAKE(OpenSslFake_CtxFree, ONCE); } TEST(SolidSyslogTlsStream, OpenReturnsFalseWhenBioMethNewFails) @@ -675,7 +678,7 @@ TEST(SolidSyslogTlsStream, BioNewFailureFreesBioMethodInline) { OpenSslFake_SetBioNewFails(true); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, OpenSslFake_BioMethFreeCallCount()); + CALLED_FAKE(OpenSslFake_BioMethFree, ONCE); /* teardown re-Destroys safely — bioMethod already cleared */ } @@ -704,7 +707,7 @@ TEST(SolidSyslogTlsStream, OpenSkipsSslSetupWhenTransportOpenFails) { StreamFake_SetOpenFails(transport, true); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(0, OpenSslFake_CtxNewCallCount()); + CALLED_FAKE(OpenSslFake_CtxNew, NEVER); } TEST(SolidSyslogTlsStream, OpenWiresBioCtrlCallback) @@ -759,9 +762,9 @@ TEST(SolidSyslogTlsStream, OpenSkipsClientIdentityWhenBothPathsAreNull) { /* Default config: clientCertChainPath and clientKeyPath both NULL. */ SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(0, OpenSslFake_UseCertChainFileCallCount()); - LONGS_EQUAL(0, OpenSslFake_UsePrivateKeyFileCallCount()); - LONGS_EQUAL(0, OpenSslFake_CheckPrivateKeyCallCount()); + CALLED_FAKE(OpenSslFake_UseCertChainFile, NEVER); + CALLED_FAKE(OpenSslFake_UsePrivateKeyFile, NEVER); + CALLED_FAKE(OpenSslFake_CheckPrivateKey, NEVER); } TEST(SolidSyslogTlsStream, OpenLoadsClientCertChainFromConfig) @@ -792,7 +795,7 @@ TEST(SolidSyslogTlsStream, OpenChecksClientKeyMatchesCert) config.clientKeyPath = "/some/path/client.key"; stream = SolidSyslogTlsStream_Create(&streamStorage, &config); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, OpenSslFake_CheckPrivateKeyCallCount()); + CALLED_FAKE(OpenSslFake_CheckPrivateKey, ONCE); } TEST(SolidSyslogTlsStream, OpenFailsWhenOnlyClientCertIsSet) @@ -811,9 +814,9 @@ TEST(SolidSyslogTlsStream, OpenMakesNoClientIdentityCallsWhenOnlyClientCertIsSet config.clientKeyPath = nullptr; stream = SolidSyslogTlsStream_Create(&streamStorage, &config); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(0, OpenSslFake_UseCertChainFileCallCount()); - LONGS_EQUAL(0, OpenSslFake_UsePrivateKeyFileCallCount()); - LONGS_EQUAL(0, OpenSslFake_CheckPrivateKeyCallCount()); + CALLED_FAKE(OpenSslFake_UseCertChainFile, NEVER); + CALLED_FAKE(OpenSslFake_UsePrivateKeyFile, NEVER); + CALLED_FAKE(OpenSslFake_CheckPrivateKey, NEVER); } TEST(SolidSyslogTlsStream, OpenFailsWhenOnlyClientKeyIsSet) @@ -832,9 +835,9 @@ TEST(SolidSyslogTlsStream, OpenMakesNoClientIdentityCallsWhenOnlyClientKeyIsSet) config.clientKeyPath = "/some/path/client.key"; stream = SolidSyslogTlsStream_Create(&streamStorage, &config); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(0, OpenSslFake_UseCertChainFileCallCount()); - LONGS_EQUAL(0, OpenSslFake_UsePrivateKeyFileCallCount()); - LONGS_EQUAL(0, OpenSslFake_CheckPrivateKeyCallCount()); + CALLED_FAKE(OpenSslFake_UseCertChainFile, NEVER); + CALLED_FAKE(OpenSslFake_UsePrivateKeyFile, NEVER); + CALLED_FAKE(OpenSslFake_CheckPrivateKey, NEVER); } TEST(SolidSyslogTlsStream, PartialClientIdentityConfigFreesCtx) @@ -844,7 +847,7 @@ TEST(SolidSyslogTlsStream, PartialClientIdentityConfigFreesCtx) config.clientKeyPath = nullptr; stream = SolidSyslogTlsStream_Create(&streamStorage, &config); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, OpenSslFake_CtxFreeCallCount()); + CALLED_FAKE(OpenSslFake_CtxFree, ONCE); } TEST(SolidSyslogTlsStream, OpenReturnsFalseWhenUseCertChainFileFails) @@ -865,7 +868,7 @@ TEST(SolidSyslogTlsStream, UseCertChainFileFailureFreesCtx) stream = SolidSyslogTlsStream_Create(&streamStorage, &config); OpenSslFake_SetUseCertChainFileFails(true); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, OpenSslFake_CtxFreeCallCount()); + CALLED_FAKE(OpenSslFake_CtxFree, ONCE); } TEST(SolidSyslogTlsStream, OpenReturnsFalseWhenUsePrivateKeyFileFails) @@ -886,7 +889,7 @@ TEST(SolidSyslogTlsStream, UsePrivateKeyFileFailureFreesCtx) stream = SolidSyslogTlsStream_Create(&streamStorage, &config); OpenSslFake_SetUsePrivateKeyFileFails(true); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, OpenSslFake_CtxFreeCallCount()); + CALLED_FAKE(OpenSslFake_CtxFree, ONCE); } TEST(SolidSyslogTlsStream, OpenReturnsFalseWhenCheckPrivateKeyFails) @@ -907,7 +910,7 @@ TEST(SolidSyslogTlsStream, CheckPrivateKeyFailureFreesCtx) stream = SolidSyslogTlsStream_Create(&streamStorage, &config); OpenSslFake_SetCheckPrivateKeyFails(true); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, OpenSslFake_CtxFreeCallCount()); + CALLED_FAKE(OpenSslFake_CtxFree, ONCE); } TEST(SolidSyslogTlsStream, OpenPassesCtxFromNewToUseCertChainFile) @@ -989,14 +992,14 @@ TEST(SolidSyslogTlsStream, OpenRetriesHandshakeOnWantRead) { ArrangeHandshakeRetryThenSucceed(SSL_ERROR_WANT_READ); CHECK_TRUE(SolidSyslogStream_Open(stream, addr)); - LONGS_EQUAL(2, OpenSslFake_ConnectCallCount()); + CALLED_FAKE(OpenSslFake_Connect, TWICE); } TEST(SolidSyslogTlsStream, OpenSleepsBetweenHandshakeRetries) { ArrangeHandshakeRetryThenSucceed(SSL_ERROR_WANT_READ); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, g_sleepCallCount); + CALLED_FUNCTION(NoOpSleep, ONCE); } TEST(SolidSyslogTlsStream, OpenRetriesHandshakeOnWantWrite) @@ -1006,7 +1009,7 @@ TEST(SolidSyslogTlsStream, OpenRetriesHandshakeOnWantWrite) send buffer). Same retry treatment as WANT_READ. */ ArrangeHandshakeRetryThenSucceed(SSL_ERROR_WANT_WRITE); CHECK_TRUE(SolidSyslogStream_Open(stream, addr)); - LONGS_EQUAL(2, OpenSslFake_ConnectCallCount()); + CALLED_FAKE(OpenSslFake_Connect, TWICE); } TEST(SolidSyslogTlsStream, OpenFailsWhenHandshakeNeverCompletes) @@ -1022,8 +1025,8 @@ TEST(SolidSyslogTlsStream, OpenFailsImmediatelyOnHardSslError) /* Non-WANT error (e.g. SSL_ERROR_SSL) is fail-fast — no retry budget burn. */ ArrangePersistentHandshakeError(SSL_ERROR_SSL); CHECK_FALSE(SolidSyslogStream_Open(stream, addr)); - LONGS_EQUAL(1, OpenSslFake_ConnectCallCount()); - LONGS_EQUAL(0, g_sleepCallCount); + CALLED_FAKE(OpenSslFake_Connect, ONCE); + CALLED_FUNCTION(NoOpSleep, NEVER); } /* ------------------------------------------------------------------------- From 1f8a74488a897bd65642f689c404b17dbe32db66 Mon Sep 17 00:00:00 2001 From: David Cozens Date: Sun, 10 May 2026 21:20:45 +0100 Subject: [PATCH 05/10] chore: S24.02 convert UdpSenderTest and StreamSenderTest to CALLED_* macros Renames the local SpyGetHost / SpyGetPort callback counters from get*CallCount to Spy*CallCount (matches the function names) and sweeps every call-count assertion in both files: CALLED_FAKE for global-state SocketFake getters, CALLED_FUNCTION for the local spy counters, with a single explicit-literal site for the reconnect-relative count expression. 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- Tests/SolidSyslogStreamSenderTest.cpp | 79 +++++++++++++------------ Tests/SolidSyslogUdpSenderTest.cpp | 85 ++++++++++++++------------- 2 files changed, 85 insertions(+), 79 deletions(-) diff --git a/Tests/SolidSyslogStreamSenderTest.cpp b/Tests/SolidSyslogStreamSenderTest.cpp index a8dd2790..ea79a3b2 100644 --- a/Tests/SolidSyslogStreamSenderTest.cpp +++ b/Tests/SolidSyslogStreamSenderTest.cpp @@ -11,8 +11,11 @@ #include "SolidSyslogSender.h" #include "SolidSyslogStreamSender.h" #include "SocketFake.h" +#include "TestUtils.h" #include "CppUTest/TestHarness.h" +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + // clang-format off static const char* const TEST_HOST = "127.0.0.1"; static const int TEST_PORT = 514; @@ -42,19 +45,19 @@ static const char* GetAlternateHost() return TEST_ALTERNATE_HOST; } -static int getPortCallCount; +static int SpyGetPortCallCount; static int SpyGetPort() { - getPortCallCount++; + SpyGetPortCallCount++; return TEST_PORT; } -static int getHostCallCount; +static int SpyGetHostCallCount; static const char* SpyGetHost() { - getHostCallCount++; + SpyGetHostCallCount++; return TEST_HOST; } @@ -134,13 +137,13 @@ TEST(SolidSyslogStreamSender, CreateReturnsHandleInsideCallerSuppliedStorage) TEST(SolidSyslogStreamSender, CreateDoesNotOpenSocket) { - LONGS_EQUAL(0, SocketFake_SocketCallCount()); + CALLED_FAKE(SocketFake_Socket, NEVER); } TEST(SolidSyslogStreamSender, FirstSendOpensStreamSocket) { Send(); - LONGS_EQUAL(1, SocketFake_SocketCallCount()); + CALLED_FAKE(SocketFake_Socket, ONCE); LONGS_EQUAL(AF_INET, SocketFake_SocketDomain()); LONGS_EQUAL(SOCK_STREAM, SocketFake_SocketType()); } @@ -190,7 +193,7 @@ TEST_GROUP(SolidSyslogStreamSenderDestroy) TEST(SolidSyslogStreamSenderDestroy, DestroyWithoutSendDoesNotClose) { CreateAndDestroy(); - LONGS_EQUAL(0, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, NEVER); } TEST(SolidSyslogStreamSenderDestroy, DestroyAfterSendClosesSocket) @@ -198,7 +201,7 @@ TEST(SolidSyslogStreamSenderDestroy, DestroyAfterSendClosesSocket) struct SolidSyslogSender* sender = SolidSyslogStreamSender_Create(&senderStorage, &config); SolidSyslogSender_Send(sender, "x", 1); SolidSyslogStreamSender_Destroy(sender); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); LONGS_EQUAL(SocketFake_SocketFd(), SocketFake_LastClosedFd()); } @@ -208,13 +211,13 @@ TEST(SolidSyslogStreamSenderDestroy, DestroyAfterDisconnectDoesNotDoubleClose) SolidSyslogSender_Send(sender, "x", 1); SolidSyslogSender_Disconnect(sender); SolidSyslogStreamSender_Destroy(sender); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogStreamSender, SendConnectsOnFirstCall) { Send(); - LONGS_EQUAL(1, SocketFake_ConnectCallCount()); + CALLED_FAKE(SocketFake_Connect, ONCE); } TEST(SolidSyslogStreamSender, SendConnectsWithCorrectPort) @@ -239,7 +242,7 @@ TEST(SolidSyslogStreamSender, SecondSendDoesNotReconnect) { Send(); Send(); - LONGS_EQUAL(1, SocketFake_ConnectCallCount()); + CALLED_FAKE(SocketFake_Connect, ONCE); } TEST(SolidSyslogStreamSender, SendTransmitsOctetCountingPrefix) @@ -257,7 +260,7 @@ TEST(SolidSyslogStreamSender, SendTransmitsMessageBody) TEST(SolidSyslogStreamSender, SendMakesTwoSendCalls) { Send(); - LONGS_EQUAL(2, SocketFake_SendCallCount()); + CALLED_FAKE(SocketFake_Send, TWICE); } TEST(SolidSyslogStreamSender, SendUsesSocketFd) @@ -275,7 +278,7 @@ TEST(SolidSyslogStreamSender, DisconnectAfterSendClosesSocket) { Send(); SolidSyslogSender_Disconnect(sender); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogStreamSender, DisconnectIsIdempotent) @@ -283,7 +286,7 @@ TEST(SolidSyslogStreamSender, DisconnectIsIdempotent) Send(); SolidSyslogSender_Disconnect(sender); SolidSyslogSender_Disconnect(sender); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogStreamSender, SendAfterDisconnectReopensSocket) @@ -291,7 +294,7 @@ TEST(SolidSyslogStreamSender, SendAfterDisconnectReopensSocket) Send(); SolidSyslogSender_Disconnect(sender); Send(); - LONGS_EQUAL(2, SocketFake_SocketCallCount()); + CALLED_FAKE(SocketFake_Socket, TWICE); } TEST(SolidSyslogStreamSender, SendAfterDisconnectResolves) @@ -299,13 +302,13 @@ TEST(SolidSyslogStreamSender, SendAfterDisconnectResolves) Send(); SolidSyslogSender_Disconnect(sender); Send(); - LONGS_EQUAL(2, SocketFake_GetAddrInfoCallCount()); + CALLED_FAKE(SocketFake_GetAddrInfo, TWICE); } TEST(SolidSyslogStreamSender, DisconnectWithoutSendDoesNotClose) { SolidSyslogSender_Disconnect(sender); - LONGS_EQUAL(0, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, NEVER); } TEST(SolidSyslogStreamSender, EndpointVersionChangeBetweenSendsTriggersReconnect) @@ -313,7 +316,7 @@ TEST(SolidSyslogStreamSender, EndpointVersionChangeBetweenSendsTriggersReconnect Send(); endpointVersion = 1; Send(); - LONGS_EQUAL(2, SocketFake_ConnectCallCount()); + CALLED_FAKE(SocketFake_Connect, TWICE); } TEST(SolidSyslogStreamSender, EndpointVersionChangeUsesNewPortOnReconnect) @@ -342,8 +345,8 @@ TEST_GROUP(SolidSyslogStreamSenderConfig) void setup() override { SocketFake_Reset(); - getPortCallCount = 0; - getHostCallCount = 0; + SpyGetPortCallCount = 0; + SpyGetHostCallCount = 0; endpointGetHost = GetHost; endpointVersion = 0; endpointGetPort = GetPort; @@ -379,9 +382,9 @@ TEST(SolidSyslogStreamSenderConfig, GetPortCalledOnFirstSend) { getPortFn = SpyGetPort; CreateSender(); - LONGS_EQUAL(0, getPortCallCount); + CALLED_FUNCTION(SpyGetPort, NEVER); Send(); - LONGS_EQUAL(1, getPortCallCount); + CALLED_FUNCTION(SpyGetPort, ONCE); } TEST(SolidSyslogStreamSenderConfig, GetPortNotCalledOnSecondSend) @@ -390,7 +393,7 @@ TEST(SolidSyslogStreamSenderConfig, GetPortNotCalledOnSecondSend) CreateSender(); Send(); Send(); - LONGS_EQUAL(1, getPortCallCount); + CALLED_FUNCTION(SpyGetPort, ONCE); } TEST(SolidSyslogStreamSenderConfig, ConnectsWithAlternatePort) @@ -405,9 +408,9 @@ TEST(SolidSyslogStreamSenderConfig, GetHostCalledOnFirstSend) { getHostFn = SpyGetHost; CreateSender(); - LONGS_EQUAL(0, getHostCallCount); + CALLED_FUNCTION(SpyGetHost, NEVER); Send(); - LONGS_EQUAL(1, getHostCallCount); + CALLED_FUNCTION(SpyGetHost, ONCE); } TEST(SolidSyslogStreamSenderConfig, GetHostNotCalledOnSecondSend) @@ -416,7 +419,7 @@ TEST(SolidSyslogStreamSenderConfig, GetHostNotCalledOnSecondSend) CreateSender(); Send(); Send(); - LONGS_EQUAL(1, getHostCallCount); + CALLED_FUNCTION(SpyGetHost, ONCE); } TEST(SolidSyslogStreamSenderConfig, ConnectsWithAlternateHost) @@ -486,7 +489,7 @@ TEST(SolidSyslogStreamSenderFailure, ConnectFailureClosesSocket) { SocketFake_SetConnectFails(true); Send(); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogStreamSenderFailure, SendReturnsFalseWhenSendFails) @@ -499,7 +502,7 @@ TEST(SolidSyslogStreamSenderFailure, SendFailureClosesSocket) { SocketFake_SetSendFails(true); Send(); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogStreamSenderFailure, DestroyAfterSendFailureDoesNotDoubleClose) @@ -507,18 +510,18 @@ TEST(SolidSyslogStreamSenderFailure, DestroyAfterSendFailureDoesNotDoubleClose) SocketFake_SetSendFails(true); Send(); SolidSyslogStreamSender_Destroy(sender); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogStreamSenderFailure, SendFailureMarksDisconnected) { Send(); - LONGS_EQUAL(1, SocketFake_ConnectCallCount()); + CALLED_FAKE(SocketFake_Connect, ONCE); SocketFake_SetSendFails(true); Send(); SocketFake_SetSendFails(false); Send(); - LONGS_EQUAL(2, SocketFake_ConnectCallCount()); + CALLED_FAKE(SocketFake_Connect, TWICE); } TEST(SolidSyslogStreamSenderFailure, ReconnectCreatesNewSocket) @@ -529,7 +532,7 @@ TEST(SolidSyslogStreamSenderFailure, ReconnectCreatesNewSocket) Send(); SocketFake_SetSendFails(false); Send(); - LONGS_EQUAL(firstSocketCallCount + 1, SocketFake_SocketCallCount()); + CALLED_FAKE(SocketFake_Socket, firstSocketCallCount + 1); } TEST(SolidSyslogStreamSenderFailure, ReconnectSetsTcpNoDelay) @@ -542,7 +545,7 @@ TEST(SolidSyslogStreamSenderFailure, ReconnectSetsTcpNoDelay) /* Two opens (initial + reconnect); each runs the full ConfigureSocket sequence: TCP_NODELAY + SO_KEEPALIVE + TCP_KEEPIDLE + TCP_KEEPINTVL + TCP_KEEPCNT + TCP_USER_TIMEOUT = 6 setsockopt calls per Open. */ - LONGS_EQUAL(12, SocketFake_SetSockOptCallCount()); + CALLED_FAKE(SocketFake_SetSockOpt, 12); CHECK_TRUE(SocketFake_HasSetSockOpt(IPPROTO_TCP, TCP_NODELAY)); } @@ -553,7 +556,7 @@ TEST(SolidSyslogStreamSenderFailure, ReconnectResolvesDns) Send(); SocketFake_SetSendFails(false); Send(); - LONGS_EQUAL(2, SocketFake_GetAddrInfoCallCount()); + CALLED_FAKE(SocketFake_GetAddrInfo, TWICE); } TEST(SolidSyslogStreamSenderFailure, ReconnectConnectsWithNewFd) @@ -592,7 +595,7 @@ TEST(SolidSyslogStreamSenderFailure, BodySendFailureClosesSocket) { SocketFake_FailSendOnCall(1); Send(); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogStreamSenderFailure, SendReturnsFalseWhenResolverFails) @@ -605,8 +608,8 @@ TEST(SolidSyslogStreamSenderFailure, SendDoesNotOpenStreamWhenResolverFails) { SocketFake_SetGetAddrInfoFails(true); Send(); - LONGS_EQUAL(0, SocketFake_SocketCallCount()); - LONGS_EQUAL(0, SocketFake_ConnectCallCount()); + CALLED_FAKE(SocketFake_Socket, NEVER); + CALLED_FAKE(SocketFake_Connect, NEVER); } TEST(SolidSyslogStreamSenderFailure, SendReturnsTrueWhenResolverSucceeds) @@ -628,6 +631,6 @@ TEST(SolidSyslogStreamSenderFailure, NoEndpointConfiguredConnectsToPortZero) struct SolidSyslogStreamSenderConfig configNoEndpoint = {resolver, stream, nullptr, nullptr}; struct SolidSyslogSender* senderNoEndpoint = SolidSyslogStreamSender_Create(&senderStorage, &configNoEndpoint); SolidSyslogSender_Send(senderNoEndpoint, TEST_MESSAGE, TEST_MESSAGE_LEN); - LONGS_EQUAL(1, SocketFake_ConnectCallCount()); + CALLED_FAKE(SocketFake_Connect, ONCE); LONGS_EQUAL(0, SocketFake_LastConnectPort()); } diff --git a/Tests/SolidSyslogUdpSenderTest.cpp b/Tests/SolidSyslogUdpSenderTest.cpp index d009355f..d320ef5e 100644 --- a/Tests/SolidSyslogUdpSenderTest.cpp +++ b/Tests/SolidSyslogUdpSenderTest.cpp @@ -13,8 +13,11 @@ #include "SolidSyslogSender.h" #include "SocketFake.h" #include "SolidSyslogDatagram.h" +#include "TestUtils.h" #include "CppUTest/TestHarness.h" +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + // clang-format off static const char* const TEST_MESSAGE = "hello"; static const size_t TEST_MESSAGE_LEN = 5; @@ -39,19 +42,19 @@ static const char* GetDefaultHost() return TEST_DEFAULT_HOST; } -static int getHostCallCount; +static int SpyGetHostCallCount; static const char* SpyGetHost() { - getHostCallCount++; + SpyGetHostCallCount++; return TEST_DEFAULT_HOST; } -static int getPortCallCount; +static int SpyGetPortCallCount; static int SpyGetPort() { - getPortCallCount++; + SpyGetPortCallCount++; return TEST_DEFAULT_PORT; } @@ -124,7 +127,7 @@ TEST(SolidSyslogUdpSender, CreateDestroyWorksWithoutCrashing) TEST(SolidSyslogUdpSender, CreateDoesNotOpenSocket) { - LONGS_EQUAL(0, SocketFake_SocketCallCount()); + CALLED_FAKE(SocketFake_Socket, NEVER); } TEST(SolidSyslogUdpSender, SendReturnsTrueOnSuccess) @@ -141,7 +144,7 @@ TEST(SolidSyslogUdpSender, SendReturnsFalseOnSendtoFailure) TEST(SolidSyslogUdpSender, SingleSendResultsInOneSendtoCall) { Send(); - LONGS_EQUAL(1, SocketFake_SendtoCallCount()); + CALLED_FAKE(SocketFake_Sendto, ONCE); } TEST(SolidSyslogUdpSender, SendtoReceivesBuffer) @@ -192,7 +195,7 @@ TEST(SolidSyslogUdpSender, SendtoCalledWithAddrlenOfSockaddrIn) TEST(SolidSyslogUdpSender, FirstSendOpensDatagramSocket) { Send(); - LONGS_EQUAL(1, SocketFake_SocketCallCount()); + CALLED_FAKE(SocketFake_Socket, ONCE); LONGS_EQUAL(AF_INET, SocketFake_SocketDomain()); LONGS_EQUAL(SOCK_DGRAM, SocketFake_SocketType()); } @@ -200,21 +203,21 @@ TEST(SolidSyslogUdpSender, FirstSendOpensDatagramSocket) TEST(SolidSyslogUdpSender, FirstSendResolves) { Send(); - LONGS_EQUAL(1, SocketFake_GetAddrInfoCallCount()); + CALLED_FAKE(SocketFake_GetAddrInfo, ONCE); } TEST(SolidSyslogUdpSender, SecondSendDoesNotReopenSocket) { Send(); Send(); - LONGS_EQUAL(1, SocketFake_SocketCallCount()); + CALLED_FAKE(SocketFake_Socket, ONCE); } TEST(SolidSyslogUdpSender, SecondSendDoesNotResolve) { Send(); Send(); - LONGS_EQUAL(1, SocketFake_GetAddrInfoCallCount()); + CALLED_FAKE(SocketFake_GetAddrInfo, ONCE); } TEST(SolidSyslogUdpSender, SendtoCalledWithSocketFd) @@ -227,7 +230,7 @@ TEST(SolidSyslogUdpSender, DisconnectAfterSendClosesSocket) { Send(); SolidSyslogSender_Disconnect(sender); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogUdpSender, DisconnectIsIdempotent) @@ -235,7 +238,7 @@ TEST(SolidSyslogUdpSender, DisconnectIsIdempotent) Send(); SolidSyslogSender_Disconnect(sender); SolidSyslogSender_Disconnect(sender); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogUdpSender, SendAfterDisconnectReopensSocket) @@ -243,7 +246,7 @@ TEST(SolidSyslogUdpSender, SendAfterDisconnectReopensSocket) Send(); SolidSyslogSender_Disconnect(sender); Send(); - LONGS_EQUAL(2, SocketFake_SocketCallCount()); + CALLED_FAKE(SocketFake_Socket, TWICE); } TEST(SolidSyslogUdpSender, SendAfterDisconnectResolves) @@ -251,13 +254,13 @@ TEST(SolidSyslogUdpSender, SendAfterDisconnectResolves) Send(); SolidSyslogSender_Disconnect(sender); Send(); - LONGS_EQUAL(2, SocketFake_GetAddrInfoCallCount()); + CALLED_FAKE(SocketFake_GetAddrInfo, TWICE); } TEST(SolidSyslogUdpSender, DisconnectWithoutSendDoesNotClose) { SolidSyslogSender_Disconnect(sender); - LONGS_EQUAL(0, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, NEVER); } TEST(SolidSyslogUdpSender, EndpointVersionChangeBetweenSendsTriggersReconnect) @@ -265,7 +268,7 @@ TEST(SolidSyslogUdpSender, EndpointVersionChangeBetweenSendsTriggersReconnect) Send(); endpointVersion = 1; Send(); - LONGS_EQUAL(2, SocketFake_SocketCallCount()); + CALLED_FAKE(SocketFake_Socket, TWICE); } TEST(SolidSyslogUdpSender, EndpointVersionChangeUsesNewPortOnReconnect) @@ -330,7 +333,7 @@ TEST_GROUP(SolidSyslogUdpSenderDestroy) TEST(SolidSyslogUdpSenderDestroy, DestroyWithoutSendDoesNotClose) { CreateAndDestroy(); - LONGS_EQUAL(0, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, NEVER); } TEST(SolidSyslogUdpSenderDestroy, DestroyAfterSendClosesSocket) @@ -338,7 +341,7 @@ TEST(SolidSyslogUdpSenderDestroy, DestroyAfterSendClosesSocket) struct SolidSyslogSender* sender = SolidSyslogUdpSender_Create(&config); SolidSyslogSender_Send(sender, TEST_MESSAGE, TEST_MESSAGE_LEN); SolidSyslogUdpSender_Destroy(); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); LONGS_EQUAL(SocketFake_SocketFd(), SocketFake_LastClosedFd()); } @@ -348,7 +351,7 @@ TEST(SolidSyslogUdpSenderDestroy, DestroyAfterDisconnectDoesNotDoubleClose) SolidSyslogSender_Send(sender, TEST_MESSAGE, TEST_MESSAGE_LEN); SolidSyslogSender_Disconnect(sender); SolidSyslogUdpSender_Destroy(); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogUdpSenderDestroy, SimpleScenario) @@ -357,13 +360,13 @@ TEST(SolidSyslogUdpSenderDestroy, SimpleScenario) SolidSyslogSender_Send(sender, TEST_MESSAGE, TEST_MESSAGE_LEN); SolidSyslogUdpSender_Destroy(); - LONGS_EQUAL(1, SocketFake_SocketCallCount()); + CALLED_FAKE(SocketFake_Socket, ONCE); LONGS_EQUAL(AF_INET, SocketFake_SocketDomain()); LONGS_EQUAL(SOCK_DGRAM, SocketFake_SocketType()); - LONGS_EQUAL(1, SocketFake_SendtoCallCount()); + CALLED_FAKE(SocketFake_Sendto, ONCE); LONGS_EQUAL(AF_INET, SocketFake_LastAddrFamily()); LONGS_EQUAL(TEST_DEFAULT_PORT, SocketFake_LastPort()); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } // clang-format off @@ -380,8 +383,8 @@ TEST_GROUP(SolidSyslogUdpSenderConfig) void setup() override { SocketFake_Reset(); - getPortCallCount = 0; - getHostCallCount = 0; + SpyGetPortCallCount = 0; + SpyGetHostCallCount = 0; endpointGetHost = GetDefaultHost; endpointVersion = 0; endpointGetPort = GetDefaultPort; @@ -416,9 +419,9 @@ TEST(SolidSyslogUdpSenderConfig, GetPortCalledOnFirstSend) { getPortFn = SpyGetPort; CreateSender(); - LONGS_EQUAL(0, getPortCallCount); + CALLED_FUNCTION(SpyGetPort, NEVER); Send(); - LONGS_EQUAL(1, getPortCallCount); + CALLED_FUNCTION(SpyGetPort, ONCE); } TEST(SolidSyslogUdpSenderConfig, GetPortNotCalledOnSecondSend) @@ -427,7 +430,7 @@ TEST(SolidSyslogUdpSenderConfig, GetPortNotCalledOnSecondSend) CreateSender(); Send(); Send(); - LONGS_EQUAL(1, getPortCallCount); + CALLED_FUNCTION(SpyGetPort, ONCE); } TEST(SolidSyslogUdpSenderConfig, SendtoCalledWithConfiguredPort) @@ -442,9 +445,9 @@ TEST(SolidSyslogUdpSenderConfig, GetHostCalledOnFirstSend) { getHostFn = SpyGetHost; CreateSender(); - LONGS_EQUAL(0, getHostCallCount); + CALLED_FUNCTION(SpyGetHost, NEVER); Send(); - LONGS_EQUAL(1, getHostCallCount); + CALLED_FUNCTION(SpyGetHost, ONCE); } TEST(SolidSyslogUdpSenderConfig, GetHostNotCalledOnSecondSend) @@ -453,7 +456,7 @@ TEST(SolidSyslogUdpSenderConfig, GetHostNotCalledOnSecondSend) CreateSender(); Send(); Send(); - LONGS_EQUAL(1, getHostCallCount); + CALLED_FUNCTION(SpyGetHost, ONCE); } TEST(SolidSyslogUdpSenderConfig, GetAddrInfoCalledWithHostnameFromGetHost) @@ -461,7 +464,7 @@ TEST(SolidSyslogUdpSenderConfig, GetAddrInfoCalledWithHostnameFromGetHost) getHostFn = SpyGetHost; CreateSender(); Send(); - LONGS_EQUAL(1, SocketFake_GetAddrInfoCallCount()); + CALLED_FAKE(SocketFake_GetAddrInfo, ONCE); STRCMP_EQUAL(TEST_DEFAULT_HOST, SocketFake_LastGetAddrInfoHostname()); } @@ -528,7 +531,7 @@ TEST(SolidSyslogUdpSenderFailure, DoesNotResolveWhenSocketFails) SocketFake_SetSocketFails(true); CreateSender(); SolidSyslogSender_Send(sender, TEST_MESSAGE, TEST_MESSAGE_LEN); - LONGS_EQUAL(0, SocketFake_GetAddrInfoCallCount()); + CALLED_FAKE(SocketFake_GetAddrInfo, NEVER); } TEST(SolidSyslogUdpSenderFailure, SendDoesNotCallSendtoWhenResolverFailed) @@ -536,7 +539,7 @@ TEST(SolidSyslogUdpSenderFailure, SendDoesNotCallSendtoWhenResolverFailed) SocketFake_SetGetAddrInfoFails(true); CreateSender(); SolidSyslogSender_Send(sender, TEST_MESSAGE, TEST_MESSAGE_LEN); - LONGS_EQUAL(0, SocketFake_SendtoCallCount()); + CALLED_FAKE(SocketFake_Sendto, NEVER); } TEST(SolidSyslogUdpSenderFailure, SendReturnsTrueWhenResolverAndSocketSucceed) @@ -561,7 +564,7 @@ TEST(SolidSyslogUdpSenderFailure, NoEndpointConfiguredSendsToPortZero) struct SolidSyslogUdpSenderConfig configNoEndpoint = {resolver, datagram, nullptr, nullptr}; sender = SolidSyslogUdpSender_Create(&configNoEndpoint); SolidSyslogSender_Send(sender, TEST_MESSAGE, TEST_MESSAGE_LEN); - LONGS_EQUAL(1, SocketFake_SendtoCallCount()); + CALLED_FAKE(SocketFake_Sendto, ONCE); LONGS_EQUAL(0, SocketFake_LastPort()); } @@ -600,7 +603,7 @@ TEST_GROUP(SolidSyslogUdpSenderRetry) TEST(SolidSyslogUdpSenderRetry, SuccessfulSendDoesNotQueryMaxPayload) { SolidSyslogSender_Send(sender, TEST_MESSAGE, TEST_MESSAGE_LEN); - LONGS_EQUAL(0, DatagramFake_MaxPayloadCallCount(datagram)); + CALLED_FAKE_ON(DatagramFake_MaxPayload, datagram, NEVER); } TEST(SolidSyslogUdpSenderRetry, OversizeQueriesMaxPayloadAndRetries) @@ -609,8 +612,8 @@ TEST(SolidSyslogUdpSenderRetry, OversizeQueriesMaxPayloadAndRetries) DatagramFake_SetSendResult(datagram, 1, SOLIDSYSLOG_DATAGRAM_SENT); DatagramFake_SetMaxPayload(datagram, 3); SolidSyslogSender_Send(sender, TEST_MESSAGE, TEST_MESSAGE_LEN); - LONGS_EQUAL(1, DatagramFake_MaxPayloadCallCount(datagram)); - LONGS_EQUAL(2, DatagramFake_SendCallCount(datagram)); + CALLED_FAKE_ON(DatagramFake_MaxPayload, datagram, ONCE); + CALLED_FAKE_ON(DatagramFake_Send, datagram, TWICE); } TEST(SolidSyslogUdpSenderRetry, OversizeRetryTrimsBufferToMaxPayload) @@ -660,7 +663,7 @@ TEST(SolidSyslogUdpSenderRetry, DoubleOversizeDoesNotSendThird) DatagramFake_SetSendResult(datagram, 1, SOLIDSYSLOG_DATAGRAM_OVERSIZE); DatagramFake_SetMaxPayload(datagram, 3); SolidSyslogSender_Send(sender, TEST_MESSAGE, TEST_MESSAGE_LEN); - LONGS_EQUAL(2, DatagramFake_SendCallCount(datagram)); + CALLED_FAKE_ON(DatagramFake_Send, datagram, TWICE); } TEST(SolidSyslogUdpSenderRetry, ZeroMaxPayloadSkipsRetrySend) @@ -668,7 +671,7 @@ TEST(SolidSyslogUdpSenderRetry, ZeroMaxPayloadSkipsRetrySend) DatagramFake_SetSendResult(datagram, 0, SOLIDSYSLOG_DATAGRAM_OVERSIZE); DatagramFake_SetMaxPayload(datagram, 0); SolidSyslogSender_Send(sender, TEST_MESSAGE, TEST_MESSAGE_LEN); - LONGS_EQUAL(1, DatagramFake_SendCallCount(datagram)); + CALLED_FAKE_ON(DatagramFake_Send, datagram, ONCE); } /* Trimmed length 0 means the message physically can't fit the path — @@ -710,8 +713,8 @@ TEST(SolidSyslogUdpSenderRetry, NonOversizeFailureDoesNotRetry) { DatagramFake_SetSendResult(datagram, 0, SOLIDSYSLOG_DATAGRAM_FAILED); SolidSyslogSender_Send(sender, TEST_MESSAGE, TEST_MESSAGE_LEN); - LONGS_EQUAL(1, DatagramFake_SendCallCount(datagram)); - LONGS_EQUAL(0, DatagramFake_MaxPayloadCallCount(datagram)); + CALLED_FAKE_ON(DatagramFake_Send, datagram, ONCE); + CALLED_FAKE_ON(DatagramFake_MaxPayload, datagram, NEVER); } TEST(SolidSyslogUdpSenderRetry, NonOversizeFailureReturnsFalse) From 26802b580f7dc42bac5ecf336ec75e52d27d74c7 Mon Sep 17 00:00:00 2001 From: David Cozens Date: Sun, 10 May 2026 21:21:38 +0100 Subject: [PATCH 06/10] chore: S24.02 move TestUtils.h into Tests/Support Test utilities header was reachable from files in Tests/ via the implicit-source-dir lookup, but not from Tests/Example/ or Tests/FreeRtos/ where the upcoming sweep will need it. Tests/Support is the established home for shared test infrastructure (SafeString, TestAtomicOps, fake libraries) and is already on the include path of SolidSyslogTests and ExampleTests via the PosixFakes/WinsockFakes PUBLIC include directory. Adds Tests/Support to the FreeRtos test include paths preemptively so the call-count macro sweep can reach TestUtils.h there too. 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- Tests/FreeRtos/CMakeLists.txt | 3 +++ Tests/{ => Support}/TestUtils.h | 0 2 files changed, 3 insertions(+) rename Tests/{ => Support}/TestUtils.h (100%) diff --git a/Tests/FreeRtos/CMakeLists.txt b/Tests/FreeRtos/CMakeLists.txt index a30ad145..c0c45b3a 100644 --- a/Tests/FreeRtos/CMakeLists.txt +++ b/Tests/FreeRtos/CMakeLists.txt @@ -30,6 +30,7 @@ else() ${CMAKE_SOURCE_DIR}/Platform/FreeRtos/Interface ${CMAKE_SOURCE_DIR}/Core/Interface ${CMAKE_SOURCE_DIR}/Core/Source + ${CMAKE_SOURCE_DIR}/Tests/Support ${CMAKE_SOURCE_DIR}/Tests/Support/FreeRtosFakes/Interface $ENV{FREERTOS_KERNEL_PATH}/include $ENV{FREERTOS_PLUS_TCP_PATH}/source/include @@ -53,6 +54,7 @@ else() ${CMAKE_SOURCE_DIR}/Platform/FreeRtos/Interface ${CMAKE_SOURCE_DIR}/Core/Interface ${CMAKE_SOURCE_DIR}/Core/Source + ${CMAKE_SOURCE_DIR}/Tests/Support ${CMAKE_SOURCE_DIR}/Tests/Support/FreeRtosFakes/Interface $ENV{FREERTOS_KERNEL_PATH}/include $ENV{FREERTOS_PLUS_TCP_PATH}/source/include @@ -104,6 +106,7 @@ target_link_libraries(CmsdkUartTest PRIVATE target_include_directories(CmsdkUartTest PRIVATE ${CMAKE_SOURCE_DIR}/Example/FreeRtos/Common + ${CMAKE_SOURCE_DIR}/Tests/Support ) add_test(NAME CmsdkUartTest COMMAND CmsdkUartTest) diff --git a/Tests/TestUtils.h b/Tests/Support/TestUtils.h similarity index 100% rename from Tests/TestUtils.h rename to Tests/Support/TestUtils.h From 82887e374f7585da014a962eed72960b4691fa31 Mon Sep 17 00:00:00 2001 From: David Cozens Date: Sun, 10 May 2026 21:34:42 +0100 Subject: [PATCH 07/10] chore: S24.02 convert ExampleServiceThreadTest and BlockStoreTest ExampleServiceThreadTest: - Renames sleepCallCount -> SleepFakeCallCount (matches the function that increments it). - Converts the call-count assertion to CALLED_FUNCTION; the unrelated lastSleepMs assertion stays as LONGS_EQUAL (it tracks the captured argument, not a count). BlockStoreTest (the substantial site): - Converts three bool flags to int counters following the *CallCount rule: storeFullCallbackInvoked -> StoreFullCallbackCallCount, computeIntegrityCalled -> SpyComputeIntegrityCallCount, verifyIntegrityCalled -> SpyVerifyIntegrityCallCount. Now catches unexpected double-calls. - Renames storeFullCallbackCount -> CountStoreFullInvocationsCallCount and thresholdCallbackCount -> CountThresholdCrossingsCallCount (matches the existing function names). - All call-count assertions in both files migrated to CALLED_FUNCTION / CALLED_FAKE / CALLED_FAKE_ON; CHECK_TRUE/CHECK_FALSE on the converted flags become CALLED_FUNCTION(..., ONCE/NEVER). 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- Tests/Example/ExampleServiceThreadTest.cpp | 13 +++-- Tests/SolidSyslogBlockStoreTest.cpp | 65 +++++++++++----------- 2 files changed, 42 insertions(+), 36 deletions(-) diff --git a/Tests/Example/ExampleServiceThreadTest.cpp b/Tests/Example/ExampleServiceThreadTest.cpp index ba4ab22b..3814c9c5 100644 --- a/Tests/Example/ExampleServiceThreadTest.cpp +++ b/Tests/Example/ExampleServiceThreadTest.cpp @@ -14,15 +14,18 @@ #include "SocketFake.h" #include "ClockFake.h" #include "SolidSyslogPrival.h" +#include "TestUtils.h" #include "CppUTest/TestHarness.h" -static int sleepCallCount; +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + +static int SleepFakeCallCount; static int lastSleepMs; static volatile bool* sleepShutdownFlag; static void SleepFake(int milliseconds) { - sleepCallCount++; + SleepFakeCallCount++; lastSleepMs = milliseconds; if (sleepShutdownFlag != nullptr) { @@ -56,7 +59,7 @@ TEST_GROUP(ExampleServiceThread) ClockFake_Reset(); ClockFake_SetTime(1743768600, 0); shutdown = true; - sleepCallCount = 0; + SleepFakeCallCount = 0; lastSleepMs = 0; sleepShutdownFlag = nullptr; @@ -91,7 +94,7 @@ TEST_GROUP(ExampleServiceThread) TEST(ExampleServiceThread, DoesNotSendWhenBufferEmpty) { ExampleServiceThread_Run(&shutdown, SleepFake); - LONGS_EQUAL(0, SocketFake_SendtoCallCount()); + CALLED_FAKE(SocketFake_Sendto, NEVER); } TEST(ExampleServiceThread, YieldsOneMillisecondAfterEachServiceTick) @@ -101,6 +104,6 @@ TEST(ExampleServiceThread, YieldsOneMillisecondAfterEachServiceTick) ExampleServiceThread_Run(&shutdown, SleepFake); - LONGS_EQUAL(1, sleepCallCount); + CALLED_FUNCTION(SleepFake, ONCE); LONGS_EQUAL(1, lastSleepMs); } diff --git a/Tests/SolidSyslogBlockStoreTest.cpp b/Tests/SolidSyslogBlockStoreTest.cpp index 6c447f79..53b59bd9 100644 --- a/Tests/SolidSyslogBlockStoreTest.cpp +++ b/Tests/SolidSyslogBlockStoreTest.cpp @@ -11,6 +11,9 @@ #include "SolidSyslogStore.h" #include "SolidSyslog.h" #include "FileFake.h" +#include "TestUtils.h" + +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros static const char* const TEST_PATH_PREFIX = "/tmp/test_store"; static const char* const TEST_DATA = "hello"; @@ -876,24 +879,24 @@ TEST(SolidSyslogBlockStoreRotation, DiscardNewestReturnsFalseWhenAtMaxFiles) CHECK_FALSE(SolidSyslogStore_Write(store, maxMsg, sizeof(maxMsg))); } -static bool storeFullCallbackInvoked; +static int StoreFullCallbackCallCount; static void StoreFullCallback(void* context) { (void) context; - storeFullCallbackInvoked = true; + StoreFullCallbackCallCount++; } TEST(SolidSyslogBlockStoreRotation, HaltInvokesCallbackWhenStoreFull) { - storeFullCallbackInvoked = false; + StoreFullCallbackCallCount = 0; CreateWithMaxBlockSize(ONE_MAX_MSG_RECORD, SOLIDSYSLOG_HALT, 2, StoreFullCallback); WriteMaxMsg(); /* file 00 */ WriteMaxMsg(); /* file 01 — now at maxBlocks=2 */ CHECK_FALSE(SolidSyslogStore_Write(store, maxMsg, sizeof(maxMsg))); - CHECK_TRUE(storeFullCallbackInvoked); + CALLED_FUNCTION(StoreFullCallback, ONCE); } TEST(SolidSyslogBlockStoreRotation, HaltWithNullCallbackDoesNotCrash) @@ -920,27 +923,27 @@ TEST(SolidSyslogBlockStoreRotation, HaltSetsIsHaltedTrue) TEST(SolidSyslogBlockStoreRotation, DiscardNewestDoesNotInvokeCallback) { - storeFullCallbackInvoked = false; + StoreFullCallbackCallCount = 0; CreateWithMaxBlockSize(ONE_MAX_MSG_RECORD, SOLIDSYSLOG_DISCARD_NEWEST, 2, StoreFullCallback); WriteMaxMsg(); /* file 00 */ WriteMaxMsg(); /* file 01 — now at maxBlocks=2 */ CHECK_FALSE(SolidSyslogStore_Write(store, maxMsg, sizeof(maxMsg))); - CHECK_FALSE(storeFullCallbackInvoked); + CALLED_FUNCTION(StoreFullCallback, NEVER); } -static int storeFullCallbackCount; +static int CountStoreFullInvocationsCallCount; static void CountStoreFullInvocations(void* context) { (void) context; - storeFullCallbackCount++; + CountStoreFullInvocationsCallCount++; } TEST(SolidSyslogBlockStoreRotation, HaltOnStoreFullFiresOncePerRisingEdge) { - storeFullCallbackCount = 0; + CountStoreFullInvocationsCallCount = 0; CreateWithMaxBlockSize(ONE_MAX_MSG_RECORD, SOLIDSYSLOG_HALT, 2, CountStoreFullInvocations); WriteMaxMsg(); /* file 00 */ @@ -951,7 +954,7 @@ TEST(SolidSyslogBlockStoreRotation, HaltOnStoreFullFiresOncePerRisingEdge) CHECK_FALSE(SolidSyslogStore_Write(store, maxMsg, sizeof(maxMsg))); CHECK_FALSE(SolidSyslogStore_Write(store, maxMsg, sizeof(maxMsg))); - LONGS_EQUAL(1, storeFullCallbackCount); + CALLED_FUNCTION(CountStoreFullInvocations, ONCE); } static void* storeFullCallbackContext; @@ -1359,7 +1362,7 @@ enum INTEGRITY_REGION_MAX = 2 + 2 + SOLIDSYSLOG_MAX_MESSAGE_SIZE /* magic + length + body */ }; -static bool computeIntegrityCalled; +static int SpyComputeIntegrityCallCount; static uint8_t computeIntegrityData[INTEGRITY_REGION_MAX]; static uint16_t computeIntegrityLength; @@ -1367,19 +1370,19 @@ static uint16_t computeIntegrityLength; static void SpyComputeIntegrity(const uint8_t* data, uint16_t length, uint8_t* integrityOut) { (void) integrityOut; - computeIntegrityCalled = true; + SpyComputeIntegrityCallCount++; computeIntegrityLength = length; memcpy(computeIntegrityData, data, length); } -static bool verifyIntegrityCalled; +static int SpyVerifyIntegrityCallCount; static uint8_t verifyIntegrityData[INTEGRITY_REGION_MAX]; static uint16_t verifyIntegrityLength; static bool SpyVerifyIntegrity(const uint8_t* data, uint16_t length, const uint8_t* integrityIn) { (void) integrityIn; - verifyIntegrityCalled = true; + SpyVerifyIntegrityCallCount++; verifyIntegrityLength = length; memcpy(verifyIntegrityData, data, length); return true; @@ -1399,10 +1402,10 @@ TEST_GROUP_BASE(SolidSyslogBlockStoreIntegrity, BlockDeviceTestBase) void setup() override { setupBlockDeviceFakes(); - computeIntegrityCalled = false; + SpyComputeIntegrityCallCount = 0; computeIntegrityLength = 0; memset(computeIntegrityData, 0, sizeof(computeIntegrityData)); - verifyIntegrityCalled = false; + SpyVerifyIntegrityCallCount = 0; verifyIntegrityLength = 0; memset(verifyIntegrityData, 0, sizeof(verifyIntegrityData)); @@ -1425,7 +1428,7 @@ TEST_GROUP_BASE(SolidSyslogBlockStoreIntegrity, BlockDeviceTestBase) TEST(SolidSyslogBlockStoreIntegrity, WriteCallsComputeIntegrity) { SolidSyslogStore_Write(store, TEST_DATA, TEST_DATA_LEN); - CHECK_TRUE(computeIntegrityCalled); + CALLED_FUNCTION(SpyComputeIntegrity, ONCE); } TEST(SolidSyslogBlockStoreIntegrity, ComputeIntegrityReceivesIntegrityRegion) @@ -1454,7 +1457,7 @@ TEST(SolidSyslogBlockStoreIntegrity, ReadCallsVerifyIntegrity) char buf[TEST_BUF_SIZE]; size_t bytesRead = 0; SolidSyslogStore_ReadNextUnsent(store, buf, sizeof(buf), &bytesRead); - CHECK_TRUE(verifyIntegrityCalled); + CALLED_FUNCTION(SpyVerifyIntegrity, ONCE); } TEST(SolidSyslogBlockStoreIntegrity, VerifyIntegrityReceivesIntegrityRegion) @@ -1866,7 +1869,7 @@ TEST(SolidSyslogBlockStoreCapacity, GetUsedBytesIsStickyAtTotalAfterSizeFailure) * Capacity threshold alert (S05.09) * ----------------------------------------------------------------*/ -static int thresholdCallbackCount; +static int CountThresholdCrossingsCallCount; static size_t thresholdReturnValue; static size_t ReturnsConfiguredThreshold(void* context) @@ -1878,7 +1881,7 @@ static size_t ReturnsConfiguredThreshold(void* context) static void CountThresholdCrossings(void* context) { (void) context; - thresholdCallbackCount++; + CountThresholdCrossingsCallCount++; } // clang-format off @@ -1890,7 +1893,7 @@ TEST_GROUP_BASE(SolidSyslogBlockStoreCapacityThreshold, BlockDeviceTestBase) void setup() override { setupBlockDeviceFakes(); - thresholdCallbackCount = 0; + CountThresholdCrossingsCallCount = 0; thresholdReturnValue = 0; } @@ -1919,7 +1922,7 @@ TEST(SolidSyslogBlockStoreCapacityThreshold, FiresOnRisingEdgeCrossing) { CreateWithThreshold(TEST_DATA_LEN); SolidSyslogStore_Write(store, TEST_DATA, TEST_DATA_LEN); - LONGS_EQUAL(1, thresholdCallbackCount); + CALLED_FUNCTION(CountThresholdCrossings, ONCE); } /* Given usage already above threshold, @@ -1931,7 +1934,7 @@ TEST(SolidSyslogBlockStoreCapacityThreshold, FiresOnceWhileUsageStaysAbove) SolidSyslogStore_Write(store, TEST_DATA, TEST_DATA_LEN); /* crosses */ SolidSyslogStore_Write(store, TEST_DATA, TEST_DATA_LEN); /* still above */ SolidSyslogStore_Write(store, TEST_DATA, TEST_DATA_LEN); /* still above */ - LONGS_EQUAL(1, thresholdCallbackCount); + CALLED_FUNCTION(CountThresholdCrossings, ONCE); } /* Given DISCARD_OLDEST and a threshold sitting in the last block, @@ -1962,7 +1965,7 @@ TEST(SolidSyslogBlockStoreCapacityThreshold, ReArmsAfterFallingEdgeOnDiscardOlde SolidSyslogStore_Write(store, maxMsg, sizeof(maxMsg)); /* rotate+discard block 0 → 3 records (below) */ SolidSyslogStore_Write(store, maxMsg, sizeof(maxMsg)); /* block 2: 2 records (4 total) — fires again */ - LONGS_EQUAL(2, thresholdCallbackCount); + CALLED_FUNCTION(CountThresholdCrossings, TWICE); } /* Given getCapacityThreshold returns 0, @@ -1973,7 +1976,7 @@ TEST(SolidSyslogBlockStoreCapacityThreshold, DoesNotFireWhenThresholdIsZero) CreateWithThreshold(0); SolidSyslogStore_Write(store, TEST_DATA, TEST_DATA_LEN); SolidSyslogStore_Write(store, TEST_DATA, TEST_DATA_LEN); - LONGS_EQUAL(0, thresholdCallbackCount); + CALLED_FUNCTION(CountThresholdCrossings, NEVER); } /* Given getCapacityThreshold is NULL but onThresholdCrossed is configured, @@ -1988,7 +1991,7 @@ TEST(SolidSyslogBlockStoreCapacityThreshold, DoesNotFireWhenThresholdFunctionIsN SolidSyslogStore_Write(store, TEST_DATA, TEST_DATA_LEN); - LONGS_EQUAL(0, thresholdCallbackCount); + CALLED_FUNCTION(CountThresholdCrossings, NEVER); } static void* capturedThresholdFunctionContext; @@ -2103,7 +2106,7 @@ TEST(SolidSyslogBlockStoreCapacityThreshold, StickyHundredPercentDoesNotRefireTh SolidSyslogStore_Write(store, maxMsg, sizeof(maxMsg)); /* fails again — must not refire */ SolidSyslogStore_Write(store, maxMsg, sizeof(maxMsg)); /* fails again — must not refire */ - LONGS_EQUAL(1, thresholdCallbackCount); + CALLED_FUNCTION(CountThresholdCrossings, ONCE); } /* Given current usage well below threshold, @@ -2116,12 +2119,12 @@ TEST(SolidSyslogBlockStoreCapacityThreshold, FiresWhenThresholdDropsBelowCurrent CreateWithThreshold(HIGH_THRESHOLD); SolidSyslogStore_Write(store, TEST_DATA, TEST_DATA_LEN); - LONGS_EQUAL(0, thresholdCallbackCount); /* still well below threshold */ + CALLED_FUNCTION(CountThresholdCrossings, NEVER); /* still well below threshold */ thresholdReturnValue = LOW_THRESHOLD; /* threshold drops below current usage */ SolidSyslogStore_Write(store, TEST_DATA, TEST_DATA_LEN); - LONGS_EQUAL(1, thresholdCallbackCount); + CALLED_FUNCTION(CountThresholdCrossings, ONCE); } /* Given persisted store contents already at-or-above threshold, @@ -2136,8 +2139,8 @@ TEST(SolidSyslogBlockStoreCapacityThreshold, FiresOnCreateWhenResumedUsageAboveT SolidSyslogBlockStore_Destroy(preStore); } - /* setup() reset thresholdCallbackCount to 0 — any fire here is from this Create. */ + /* setup() reset CountThresholdCrossingsCallCount to 0 — any fire here is from this Create. */ CreateWithThreshold(TEST_DATA_LEN); - LONGS_EQUAL(1, thresholdCallbackCount); + CALLED_FUNCTION(CountThresholdCrossings, ONCE); } From 8bec729267422efb25c0586f4a30c5fb9790a580 Mon Sep 17 00:00:00 2001 From: David Cozens Date: Sun, 10 May 2026 21:38:07 +0100 Subject: [PATCH 08/10] chore: S24.02 sweep remaining tests to use CALLED_* macros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Final conversion pass across the test base. Mechanical sed: - LONGS_EQUAL(N, Foo_BarCallCount()) -> CALLED_FAKE(Foo_Bar, N) - LONGS_EQUAL(N, Foo_BarCallCount(inst)) -> CALLED_FAKE_ON(Foo_Bar, inst, N) - LONGS_EQUAL(N, fooCallCount) -> CALLED_FUNCTION(foo, N) where N is mapped to NEVER/ONCE/TWICE/THRICE for 0..3, otherwise passed through as a literal. Adds #include "TestUtils.h" + `using namespace CososoTesting;` to each newly-affected file. Files swept (19): DatagramFakeTest, OpenSslFakeTest, SenderFakeTest, SocketFakeTest, StoreFakeTest, StreamFakeTest, WinsockFakeTest, SolidSyslogTest, SolidSyslogNullBufferTest, SolidSyslogPosixDatagramTest, SolidSyslogPosixMessageQueueBufferTest, SolidSyslogPosixTcpStreamTest, SolidSyslogGetAddrInfoResolverTest, SolidSyslogWinsockDatagramTest, SolidSyslogWinsockResolverTest, SolidSyslogWinsockTcpStreamTest, Example/SolidSyslogExampleTest, FreeRtos/CmsdkUartTest, FreeRtos/SolidSyslogFreeRtosDatagramTest. Verified: - gcc preset: 1088 tests pass. - freertos-host build: SolidSyslogFreeRtosDatagramTest (21), CmsdkUartTest (15), SolidSyslogFreeRtosSysUpTimeTest (4), SolidSyslogFreeRtosStaticResolverTest (10) — all green. - Winsock variants converted but compile-checked via CI only. Co-Authored-By: Claude Opus 4.7 (1M context) --- Tests/DatagramFakeTest.cpp | 11 +++-- Tests/Example/SolidSyslogExampleTest.cpp | 9 ++-- Tests/FreeRtos/CmsdkUartTest.cpp | 5 ++- .../SolidSyslogFreeRtosDatagramTest.cpp | 41 ++++++++++--------- Tests/OpenSslFakeTest.cpp | 23 ++++++----- Tests/SenderFakeTest.cpp | 27 ++++++------ Tests/SocketFakeTest.cpp | 5 ++- Tests/SolidSyslogGetAddrInfoResolverTest.cpp | 9 ++-- Tests/SolidSyslogNullBufferTest.cpp | 9 ++-- Tests/SolidSyslogPosixDatagramTest.cpp | 17 ++++---- ...SolidSyslogPosixMessageQueueBufferTest.cpp | 5 ++- Tests/SolidSyslogPosixTcpStreamTest.cpp | 35 ++++++++-------- Tests/SolidSyslogTest.cpp | 25 ++++++----- Tests/SolidSyslogWinsockDatagramTest.cpp | 17 ++++---- Tests/SolidSyslogWinsockResolverTest.cpp | 9 ++-- Tests/SolidSyslogWinsockTcpStreamTest.cpp | 37 +++++++++-------- Tests/StoreFakeTest.cpp | 7 +++- Tests/StreamFakeTest.cpp | 11 +++-- Tests/WinsockFakeTest.cpp | 39 ++++++++++-------- 19 files changed, 199 insertions(+), 142 deletions(-) diff --git a/Tests/DatagramFakeTest.cpp b/Tests/DatagramFakeTest.cpp index 42ef0e53..38c0aaf2 100644 --- a/Tests/DatagramFakeTest.cpp +++ b/Tests/DatagramFakeTest.cpp @@ -1,7 +1,10 @@ #include "DatagramFake.h" #include "SolidSyslogDatagram.h" +#include "TestUtils.h" #include "CppUTest/TestHarness.h" +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + // clang-format off TEST_GROUP(DatagramFake) { @@ -23,7 +26,7 @@ TEST(DatagramFake, CreateSucceeds) TEST(DatagramFake, OpenIncrementsCount) { SolidSyslogDatagram_Open(datagram); - LONGS_EQUAL(1, DatagramFake_OpenCallCount(datagram)); + CALLED_FAKE_ON(DatagramFake_Open, datagram, ONCE); } TEST(DatagramFake, OpenReturnsTrue) @@ -35,7 +38,7 @@ TEST(DatagramFake, SendIncrementsCount) { const char payload[] = "hi"; SolidSyslogDatagram_SendTo(datagram, payload, sizeof(payload), nullptr); - LONGS_EQUAL(1, DatagramFake_SendCallCount(datagram)); + CALLED_FAKE_ON(DatagramFake_Send, datagram, ONCE); } TEST(DatagramFake, SendDefaultsToSent) @@ -64,7 +67,7 @@ TEST(DatagramFake, SendCapturesBufferAndSize) TEST(DatagramFake, MaxPayloadIncrementsCount) { SolidSyslogDatagram_MaxPayload(datagram); - LONGS_EQUAL(1, DatagramFake_MaxPayloadCallCount(datagram)); + CALLED_FAKE_ON(DatagramFake_MaxPayload, datagram, ONCE); } TEST(DatagramFake, MaxPayloadReturnsConfiguredValue) @@ -76,5 +79,5 @@ TEST(DatagramFake, MaxPayloadReturnsConfiguredValue) TEST(DatagramFake, CloseIncrementsCount) { SolidSyslogDatagram_Close(datagram); - LONGS_EQUAL(1, DatagramFake_CloseCallCount(datagram)); + CALLED_FAKE_ON(DatagramFake_Close, datagram, ONCE); } diff --git a/Tests/Example/SolidSyslogExampleTest.cpp b/Tests/Example/SolidSyslogExampleTest.cpp index 362d6152..70e27bb8 100644 --- a/Tests/Example/SolidSyslogExampleTest.cpp +++ b/Tests/Example/SolidSyslogExampleTest.cpp @@ -6,8 +6,11 @@ #include "SolidSyslogExample.h" #include "ClockFake.h" #include "SocketFake.h" +#include "TestUtils.h" #include "CppUTest/TestHarness.h" +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + static const char* const STDIN_SEND_ONE = "/tmp/solidsyslog_test_send1.txt"; static const char* const STDIN_SEND_THREE = "/tmp/solidsyslog_test_send3.txt"; @@ -84,7 +87,7 @@ TEST(SolidSyslogExample, RunWithNoArgsReturnsZero) TEST(SolidSyslogExample, RunSendsOneMessage) { RunWithNoArgs(); - LONGS_EQUAL(1, SocketFake_SendtoCallCount()); + CALLED_FAKE(SocketFake_Sendto, ONCE); } TEST(SolidSyslogExample, DefaultMessageContainsLocal0InfoPrival) @@ -147,7 +150,7 @@ TEST(SolidSyslogExample, SocketCreatedWithUdpDgram) TEST(SolidSyslogExample, SocketClosedAfterRun) { RunWithNoArgs(); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogExample, MsgIdFlagAppearsInMessage) @@ -167,7 +170,7 @@ TEST(SolidSyslogExample, SendCommandSendsMultipleMessages) char arg0[] = "SolidSyslogExample"; char* argv[] = {arg0, nullptr}; Run(1, argv); - LONGS_EQUAL(3, SocketFake_SendtoCallCount()); + CALLED_FAKE(SocketFake_Sendto, THRICE); } TEST(SolidSyslogExample, MessageFlagAppearsInMessage) diff --git a/Tests/FreeRtos/CmsdkUartTest.cpp b/Tests/FreeRtos/CmsdkUartTest.cpp index 2d288b42..a410e5c3 100644 --- a/Tests/FreeRtos/CmsdkUartTest.cpp +++ b/Tests/FreeRtos/CmsdkUartTest.cpp @@ -1,5 +1,8 @@ +#include "TestUtils.h" #include "CppUTest/TestHarness.h" +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + #include "CmsdkUart.h" #include "CmsdkUartFake.h" @@ -106,7 +109,7 @@ TEST(CmsdkUart, GetCharReturnsImmediatelyWhenReceiverHasByte) CmsdkUartFake_SetReadsBeforeRxReady(0); CmsdkUartFake_SetReceivedByte('X'); LONGS_EQUAL('X', CmsdkUart_GetChar()); - LONGS_EQUAL(0, CmsdkUartFake_SleepCallCount()); + CALLED_FAKE(CmsdkUartFake_Sleep, NEVER); } TEST(CmsdkUart, GetCharSpinsAfterReArmFromImmediateReadyToDelayedReady) diff --git a/Tests/FreeRtos/SolidSyslogFreeRtosDatagramTest.cpp b/Tests/FreeRtos/SolidSyslogFreeRtosDatagramTest.cpp index cadb2bf6..f423e116 100644 --- a/Tests/FreeRtos/SolidSyslogFreeRtosDatagramTest.cpp +++ b/Tests/FreeRtos/SolidSyslogFreeRtosDatagramTest.cpp @@ -1,5 +1,8 @@ +#include "TestUtils.h" #include "CppUTest/TestHarness.h" +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + #include "SolidSyslogAddress.h" #include "SolidSyslogDatagram.h" #include "SolidSyslogFreeRtosDatagram.h" @@ -53,7 +56,7 @@ TEST(SolidSyslogFreeRtosDatagram, CreateReturnsNonNullDatagram) TEST(SolidSyslogFreeRtosDatagram, OpenCreatesUdpSocket) { SolidSyslogDatagram_Open(datagram); - LONGS_EQUAL(1, FreeRtosSocketsFake_SocketCallCount()); + CALLED_FAKE(FreeRtosSocketsFake_Socket, ONCE); LONGS_EQUAL(FREERTOS_AF_INET, FreeRtosSocketsFake_LastSocketDomain()); LONGS_EQUAL(FREERTOS_SOCK_DGRAM, FreeRtosSocketsFake_LastSocketType()); LONGS_EQUAL(FREERTOS_IPPROTO_UDP, FreeRtosSocketsFake_LastSocketProtocol()); @@ -74,7 +77,7 @@ TEST(SolidSyslogFreeRtosDatagram, OpenIsIdempotent) { SolidSyslogDatagram_Open(datagram); CHECK_TRUE(SolidSyslogDatagram_Open(datagram)); - LONGS_EQUAL(1, FreeRtosSocketsFake_SocketCallCount()); + CALLED_FAKE(FreeRtosSocketsFake_Socket, ONCE); } TEST(SolidSyslogFreeRtosDatagram, MaxPayloadReturnsIpv6SafeDefault) @@ -86,7 +89,7 @@ TEST(SolidSyslogFreeRtosDatagram, SendToFailsBeforeOpen) { enum SolidSyslogDatagramSendResult result = SolidSyslogDatagram_SendTo(datagram, "x", 1, addr); LONGS_EQUAL(SOLIDSYSLOG_DATAGRAM_FAILED, result); - LONGS_EQUAL(0, FreeRtosSocketsFake_SendtoCallCount()); + CALLED_FAKE(FreeRtosSocketsFake_Sendto, NEVER); } TEST(SolidSyslogFreeRtosDatagram, SendToFailsWhenSendtoErrors) @@ -100,7 +103,7 @@ TEST(SolidSyslogFreeRtosDatagram, CloseClosesSocket) { SolidSyslogDatagram_Open(datagram); SolidSyslogDatagram_Close(datagram); - LONGS_EQUAL(1, FreeRtosSocketsFake_ClosesocketCallCount()); + CALLED_FAKE(FreeRtosSocketsFake_Closesocket, ONCE); POINTERS_EQUAL(FreeRtosSocketsFake_LastSocketReturned(), FreeRtosSocketsFake_LastClosesocketSocket()); } @@ -110,14 +113,14 @@ TEST(SolidSyslogFreeRtosDatagram, SendToFailsAfterClose) SolidSyslogDatagram_Close(datagram); enum SolidSyslogDatagramSendResult result = SolidSyslogDatagram_SendTo(datagram, "x", 1, addr); LONGS_EQUAL(SOLIDSYSLOG_DATAGRAM_FAILED, result); - LONGS_EQUAL(0, FreeRtosSocketsFake_SendtoCallCount()); + CALLED_FAKE(FreeRtosSocketsFake_Sendto, NEVER); } TEST(SolidSyslogFreeRtosDatagram, DestroyClosesOpenSocket) { SolidSyslogDatagram_Open(datagram); SolidSyslogFreeRtosDatagram_Destroy(datagram); - LONGS_EQUAL(1, FreeRtosSocketsFake_ClosesocketCallCount()); + CALLED_FAKE(FreeRtosSocketsFake_Closesocket, ONCE); } TEST(SolidSyslogFreeRtosDatagram, CloseIsIdempotent) @@ -125,13 +128,13 @@ TEST(SolidSyslogFreeRtosDatagram, CloseIsIdempotent) SolidSyslogDatagram_Open(datagram); SolidSyslogDatagram_Close(datagram); SolidSyslogDatagram_Close(datagram); - LONGS_EQUAL(1, FreeRtosSocketsFake_ClosesocketCallCount()); + CALLED_FAKE(FreeRtosSocketsFake_Closesocket, ONCE); } TEST(SolidSyslogFreeRtosDatagram, CloseWithoutOpenIsNoOp) { SolidSyslogDatagram_Close(datagram); - LONGS_EQUAL(0, FreeRtosSocketsFake_ClosesocketCallCount()); + CALLED_FAKE(FreeRtosSocketsFake_Closesocket, NEVER); } TEST(SolidSyslogFreeRtosDatagram, DestroyAfterCloseDoesNotCloseAgain) @@ -139,7 +142,7 @@ TEST(SolidSyslogFreeRtosDatagram, DestroyAfterCloseDoesNotCloseAgain) SolidSyslogDatagram_Open(datagram); SolidSyslogDatagram_Close(datagram); SolidSyslogFreeRtosDatagram_Destroy(datagram); - LONGS_EQUAL(1, FreeRtosSocketsFake_ClosesocketCallCount()); + CALLED_FAKE(FreeRtosSocketsFake_Closesocket, ONCE); } TEST(SolidSyslogFreeRtosDatagram, SendToSendsBufferToDestinationAfterOpen) @@ -151,7 +154,7 @@ TEST(SolidSyslogFreeRtosDatagram, SendToSendsBufferToDestinationAfterOpen) enum SolidSyslogDatagramSendResult result = SolidSyslogDatagram_SendTo(datagram, TEST_MESSAGE, TEST_MESSAGE_LEN, addr); LONGS_EQUAL(SOLIDSYSLOG_DATAGRAM_SENT, result); - LONGS_EQUAL(1, FreeRtosSocketsFake_SendtoCallCount()); + CALLED_FAKE(FreeRtosSocketsFake_Sendto, ONCE); POINTERS_EQUAL(FreeRtosSocketsFake_LastSocketReturned(), FreeRtosSocketsFake_LastSendtoSocket()); POINTERS_EQUAL(TEST_MESSAGE, FreeRtosSocketsFake_LastSendtoBuffer()); LONGS_EQUAL(TEST_MESSAGE_LEN, FreeRtosSocketsFake_LastSendtoLength()); @@ -165,7 +168,7 @@ TEST(SolidSyslogFreeRtosDatagram, SendToChecksIfIpIsInArpCache) { openAndSendOnce(); - LONGS_EQUAL(1, FreeRtosArpFake_IsIpInArpCacheCallCount()); + CALLED_FAKE(FreeRtosArpFake_IsIpInArpCache, ONCE); LONGS_EQUAL(FreeRTOS_inet_addr_quick(127, 0, 0, 1), FreeRtosArpFake_LastIsIpInArpCacheArg()); } @@ -173,7 +176,7 @@ TEST(SolidSyslogFreeRtosDatagram, SendToFiresArpProbeOnCacheMiss) { openAndSendOnce(); - LONGS_EQUAL(1, FreeRtosArpFake_OutputArpRequestCallCount()); + CALLED_FAKE(FreeRtosArpFake_OutputArpRequest, ONCE); LONGS_EQUAL(FreeRTOS_inet_addr_quick(127, 0, 0, 1), FreeRtosArpFake_LastOutputArpRequestArg()); } @@ -181,7 +184,7 @@ TEST(SolidSyslogFreeRtosDatagram, SendToYieldsAfterArpProbeOnCacheMiss) { openAndSendOnce(); - LONGS_EQUAL(1, FreeRtosTaskFake_VTaskDelayCallCount()); + CALLED_FAKE(FreeRtosTaskFake_VTaskDelay, ONCE); } TEST(SolidSyslogFreeRtosDatagram, SendToSkipsArpProbeAndYieldOnCacheHit) @@ -191,9 +194,9 @@ TEST(SolidSyslogFreeRtosDatagram, SendToSkipsArpProbeAndYieldOnCacheHit) SolidSyslogDatagram_SendTo(datagram, "x", 1, addr); - LONGS_EQUAL(0, FreeRtosArpFake_OutputArpRequestCallCount()); - LONGS_EQUAL(0, FreeRtosTaskFake_VTaskDelayCallCount()); - LONGS_EQUAL(1, FreeRtosSocketsFake_SendtoCallCount()); + CALLED_FAKE(FreeRtosArpFake_OutputArpRequest, NEVER); + CALLED_FAKE(FreeRtosTaskFake_VTaskDelay, NEVER); + CALLED_FAKE(FreeRtosSocketsFake_Sendto, ONCE); } TEST(SolidSyslogFreeRtosDatagram, SendToReChecksArpCacheOnEachCall) @@ -202,15 +205,15 @@ TEST(SolidSyslogFreeRtosDatagram, SendToReChecksArpCacheOnEachCall) FreeRtosArpFake_SetCacheHit(true); SolidSyslogDatagram_SendTo(datagram, "x", 1, addr); - LONGS_EQUAL(0, FreeRtosArpFake_OutputArpRequestCallCount()); + CALLED_FAKE(FreeRtosArpFake_OutputArpRequest, NEVER); FreeRtosArpFake_SetCacheHit(false); SolidSyslogDatagram_SendTo(datagram, "x", 1, addr); - LONGS_EQUAL(1, FreeRtosArpFake_OutputArpRequestCallCount()); + CALLED_FAKE(FreeRtosArpFake_OutputArpRequest, ONCE); FreeRtosArpFake_SetCacheHit(true); SolidSyslogDatagram_SendTo(datagram, "x", 1, addr); - LONGS_EQUAL(1, FreeRtosArpFake_OutputArpRequestCallCount()); + CALLED_FAKE(FreeRtosArpFake_OutputArpRequest, ONCE); } TEST(SolidSyslogFreeRtosDatagram, SendToForwardsLengthVerbatim) diff --git a/Tests/OpenSslFakeTest.cpp b/Tests/OpenSslFakeTest.cpp index d7368bd8..ade5adc2 100644 --- a/Tests/OpenSslFakeTest.cpp +++ b/Tests/OpenSslFakeTest.cpp @@ -4,8 +4,11 @@ #include #include "OpenSslFake.h" +#include "TestUtils.h" #include "CppUTest/TestHarness.h" +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + // clang-format off TEST_GROUP(OpenSslFake) { @@ -15,13 +18,13 @@ TEST_GROUP(OpenSslFake) TEST(OpenSslFake, CtxNewCountIsZeroAfterReset) { - LONGS_EQUAL(0, OpenSslFake_CtxNewCallCount()); + CALLED_FAKE(OpenSslFake_CtxNew, NEVER); } TEST(OpenSslFake, CtxNewIncrementsCount) { SSL_CTX_new(TLS_client_method()); - LONGS_EQUAL(1, OpenSslFake_CtxNewCallCount()); + CALLED_FAKE(OpenSslFake_CtxNew, ONCE); } TEST(OpenSslFake, CtxNewReturnsNonNull) @@ -60,7 +63,7 @@ TEST(OpenSslFake, SslNewIncrementsCount) { SSL_CTX* ctx = SSL_CTX_new(TLS_client_method()); SSL_new(ctx); - LONGS_EQUAL(1, OpenSslFake_SslNewCallCount()); + CALLED_FAKE(OpenSslFake_SslNew, ONCE); } TEST(OpenSslFake, SslNewReturnsNonNull) @@ -80,7 +83,7 @@ TEST(OpenSslFake, BioNewIncrementsCount) { BIO_METHOD* method = BIO_meth_new(0, "fake"); BIO_new(method); - LONGS_EQUAL(1, OpenSslFake_BioNewCallCount()); + CALLED_FAKE(OpenSslFake_BioNew, ONCE); } TEST(OpenSslFake, BioNewReturnsNonNull) @@ -103,7 +106,7 @@ TEST(OpenSslFake, SetBioIncrementsCount) BIO_METHOD* method = BIO_meth_new(0, "fake"); BIO* bio = BIO_new(method); SSL_set_bio(ssl, bio, bio); - LONGS_EQUAL(1, OpenSslFake_SetBioCallCount()); + CALLED_FAKE(OpenSslFake_SetBio, ONCE); } TEST(OpenSslFake, SetBioCapturesSslArg) @@ -131,7 +134,7 @@ TEST(OpenSslFake, ConnectIncrementsCount) SSL_CTX* ctx = SSL_CTX_new(TLS_client_method()); SSL* ssl = SSL_new(ctx); SSL_connect(ssl); - LONGS_EQUAL(1, OpenSslFake_ConnectCallCount()); + CALLED_FAKE(OpenSslFake_Connect, ONCE); } TEST(OpenSslFake, ConnectCapturesSslArg) @@ -262,7 +265,7 @@ TEST(OpenSslFake, WriteIncrementsCount) SSL_CTX* ctx = SSL_CTX_new(TLS_client_method()); SSL* ssl = SSL_new(ctx); SSL_write(ssl, "x", 1); - LONGS_EQUAL(1, OpenSslFake_WriteCallCount()); + CALLED_FAKE(OpenSslFake_Write, ONCE); } TEST(OpenSslFake, WriteCapturesSslArg) @@ -302,7 +305,7 @@ TEST(OpenSslFake, ShutdownIncrementsCount) SSL_CTX* ctx = SSL_CTX_new(TLS_client_method()); SSL* ssl = SSL_new(ctx); SSL_shutdown(ssl); - LONGS_EQUAL(1, OpenSslFake_ShutdownCallCount()); + CALLED_FAKE(OpenSslFake_Shutdown, ONCE); } TEST(OpenSslFake, FreeIncrementsCount) @@ -310,14 +313,14 @@ TEST(OpenSslFake, FreeIncrementsCount) SSL_CTX* ctx = SSL_CTX_new(TLS_client_method()); SSL* ssl = SSL_new(ctx); SSL_free(ssl); - LONGS_EQUAL(1, OpenSslFake_FreeCallCount()); + CALLED_FAKE(OpenSslFake_Free, ONCE); } TEST(OpenSslFake, CtxFreeIncrementsCount) { SSL_CTX* ctx = SSL_CTX_new(TLS_client_method()); SSL_CTX_free(ctx); - LONGS_EQUAL(1, OpenSslFake_CtxFreeCallCount()); + CALLED_FAKE(OpenSslFake_CtxFree, ONCE); } /* ------------------------------------------------------------------------- diff --git a/Tests/SenderFakeTest.cpp b/Tests/SenderFakeTest.cpp index 9bef18fb..2177e74a 100644 --- a/Tests/SenderFakeTest.cpp +++ b/Tests/SenderFakeTest.cpp @@ -1,7 +1,10 @@ #include "SenderFake.h" #include "SolidSyslogSender.h" +#include "TestUtils.h" #include "CppUTest/TestHarness.h" +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + // clang-format off TEST_GROUP(SenderFake) { @@ -23,38 +26,38 @@ TEST_GROUP(SenderFake) TEST(SenderFake, SendCountIsZeroAfterCreate) { - LONGS_EQUAL(0, SenderFake_SendCallCount(sender)); + CALLED_FAKE_ON(SenderFake_Send, sender, NEVER); } TEST(SenderFake, DisconnectCountIsZeroAfterCreate) { - LONGS_EQUAL(0, SenderFake_DisconnectCallCount(sender)); + CALLED_FAKE_ON(SenderFake_Disconnect, sender, NEVER); } TEST(SenderFake, SendCountIncrementsOnSend) { SolidSyslogSender_Send(sender, "a", 1); - LONGS_EQUAL(1, SenderFake_SendCallCount(sender)); + CALLED_FAKE_ON(SenderFake_Send, sender, ONCE); } TEST(SenderFake, SendCountIncrementsTwiceOnTwoSends) { SolidSyslogSender_Send(sender, "a", 1); SolidSyslogSender_Send(sender, "b", 1); - LONGS_EQUAL(2, SenderFake_SendCallCount(sender)); + CALLED_FAKE_ON(SenderFake_Send, sender, TWICE); } TEST(SenderFake, DisconnectCountIncrementsOnDisconnect) { SolidSyslogSender_Disconnect(sender); - LONGS_EQUAL(1, SenderFake_DisconnectCallCount(sender)); + CALLED_FAKE_ON(SenderFake_Disconnect, sender, ONCE); } TEST(SenderFake, DisconnectCountIncrementsTwiceOnTwoDisconnects) { SolidSyslogSender_Disconnect(sender); SolidSyslogSender_Disconnect(sender); - LONGS_EQUAL(2, SenderFake_DisconnectCallCount(sender)); + CALLED_FAKE_ON(SenderFake_Disconnect, sender, TWICE); } TEST(SenderFake, LastBufferCapturesMessage) @@ -92,14 +95,14 @@ TEST(SenderFake, ResetClearsSendCount) { SolidSyslogSender_Send(sender, "a", 1); SenderFake_Reset(sender); - LONGS_EQUAL(0, SenderFake_SendCallCount(sender)); + CALLED_FAKE_ON(SenderFake_Send, sender, NEVER); } TEST(SenderFake, ResetClearsDisconnectCount) { SolidSyslogSender_Disconnect(sender); SenderFake_Reset(sender); - LONGS_EQUAL(0, SenderFake_DisconnectCallCount(sender)); + CALLED_FAKE_ON(SenderFake_Disconnect, sender, NEVER); } TEST(SenderFake, FailNextSendReturnsFalse) @@ -153,15 +156,15 @@ TEST(SenderFakeInstances, TwoInstancesHaveDistinctHandles) TEST(SenderFakeInstances, SendCountsAreIndependent) { SolidSyslogSender_Send(a, "x", 1); - LONGS_EQUAL(1, SenderFake_SendCallCount(a)); - LONGS_EQUAL(0, SenderFake_SendCallCount(b)); + CALLED_FAKE_ON(SenderFake_Send, a, ONCE); + CALLED_FAKE_ON(SenderFake_Send, b, NEVER); } TEST(SenderFakeInstances, DisconnectCountsAreIndependent) { SolidSyslogSender_Disconnect(a); - LONGS_EQUAL(1, SenderFake_DisconnectCallCount(a)); - LONGS_EQUAL(0, SenderFake_DisconnectCallCount(b)); + CALLED_FAKE_ON(SenderFake_Disconnect, a, ONCE); + CALLED_FAKE_ON(SenderFake_Disconnect, b, NEVER); } TEST(SenderFakeInstances, LastBuffersAreIndependent) diff --git a/Tests/SocketFakeTest.cpp b/Tests/SocketFakeTest.cpp index 16c47baf..bc94941f 100644 --- a/Tests/SocketFakeTest.cpp +++ b/Tests/SocketFakeTest.cpp @@ -1,8 +1,11 @@ #include #include "SocketFake.h" +#include "TestUtils.h" #include "CppUTest/TestHarness.h" +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + // clang-format off TEST_GROUP(SocketFake) { @@ -14,7 +17,7 @@ TEST(SocketFake, RecvIncrementsCount) { char buf[16]; recv(3, buf, sizeof(buf), 0); - LONGS_EQUAL(1, SocketFake_RecvCallCount()); + CALLED_FAKE(SocketFake_Recv, ONCE); } TEST(SocketFake, RecvCapturesFd) diff --git a/Tests/SolidSyslogGetAddrInfoResolverTest.cpp b/Tests/SolidSyslogGetAddrInfoResolverTest.cpp index 5cb15487..de744b7e 100644 --- a/Tests/SolidSyslogGetAddrInfoResolverTest.cpp +++ b/Tests/SolidSyslogGetAddrInfoResolverTest.cpp @@ -8,8 +8,11 @@ #include "SolidSyslogResolver.h" #include "SocketFake.h" #include "SolidSyslogTransport.h" +#include "TestUtils.h" #include "CppUTest/TestHarness.h" +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + // clang-format off static const char* const TEST_HOST = "127.0.0.1"; static const uint16_t TEST_PORT = 514; @@ -84,7 +87,7 @@ TEST(SolidSyslogGetAddrInfoResolver, PopulatesPortFromPortArgument) TEST(SolidSyslogGetAddrInfoResolver, GetAddrInfoCalledWithHostArgument) { Resolve(TEST_ALTERNATE_HOST, TEST_PORT); - LONGS_EQUAL(1, SocketFake_GetAddrInfoCallCount()); + CALLED_FAKE(SocketFake_GetAddrInfo, ONCE); STRCMP_EQUAL(TEST_ALTERNATE_HOST, SocketFake_LastGetAddrInfoHostname()); } @@ -110,11 +113,11 @@ TEST(SolidSyslogGetAddrInfoResolver, DoesNotFreeAddrInfoWhenGetAddrInfoFails) { SocketFake_SetGetAddrInfoFails(true); Resolve(TEST_HOST, TEST_PORT); - LONGS_EQUAL(0, SocketFake_FreeAddrInfoCallCount()); + CALLED_FAKE(SocketFake_FreeAddrInfo, NEVER); } TEST(SolidSyslogGetAddrInfoResolver, FreesAddrInfoOnSuccess) { Resolve(TEST_HOST, TEST_PORT); - LONGS_EQUAL(1, SocketFake_FreeAddrInfoCallCount()); + CALLED_FAKE(SocketFake_FreeAddrInfo, ONCE); } diff --git a/Tests/SolidSyslogNullBufferTest.cpp b/Tests/SolidSyslogNullBufferTest.cpp index bd673237..f56f6c9c 100644 --- a/Tests/SolidSyslogNullBufferTest.cpp +++ b/Tests/SolidSyslogNullBufferTest.cpp @@ -1,6 +1,9 @@ #include +#include "TestUtils.h" #include "CppUTest/TestHarness.h" + +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros #include "SolidSyslogBuffer.h" #include "SolidSyslogNullBuffer.h" #include "SenderFake.h" @@ -54,19 +57,19 @@ TEST(SolidSyslogNullBuffer, WriteForwardsSizeToSender) TEST(SolidSyslogNullBuffer, WriteResultsInOneSend) { Write(); - LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); + CALLED_FAKE_ON(SenderFake_Send, fakeSender, ONCE); } TEST(SolidSyslogNullBuffer, TwoWritesResultInTwoSends) { Write(); Write(); - LONGS_EQUAL(2, SenderFake_SendCallCount(fakeSender)); + CALLED_FAKE_ON(SenderFake_Send, fakeSender, TWICE); } TEST(SolidSyslogNullBuffer, NoWritesResultInNoSends) { - LONGS_EQUAL(0, SenderFake_SendCallCount(fakeSender)); + CALLED_FAKE_ON(SenderFake_Send, fakeSender, NEVER); } TEST(SolidSyslogNullBuffer, ReadReturnsNothingToSend) diff --git a/Tests/SolidSyslogPosixDatagramTest.cpp b/Tests/SolidSyslogPosixDatagramTest.cpp index 4084a385..553bb291 100644 --- a/Tests/SolidSyslogPosixDatagramTest.cpp +++ b/Tests/SolidSyslogPosixDatagramTest.cpp @@ -1,4 +1,7 @@ +#include "TestUtils.h" #include "CppUTest/TestHarness.h" + +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros #include "SolidSyslogAddress.h" #include "SolidSyslogDatagram.h" #include "SolidSyslogPosixDatagram.h" @@ -56,7 +59,7 @@ TEST(SolidSyslogPosixDatagram, CreateDestroyWorksWithoutCrashing) TEST(SolidSyslogPosixDatagram, OpenCallsSocketOnce) { SolidSyslogDatagram_Open(datagram); - LONGS_EQUAL(1, SocketFake_SocketCallCount()); + CALLED_FAKE(SocketFake_Socket, ONCE); } TEST(SolidSyslogPosixDatagram, OpenCallsSocketWithAF_INET) @@ -86,7 +89,7 @@ TEST(SolidSyslogPosixDatagram, SendToCallsSendtoOnce) { SolidSyslogDatagram_Open(datagram); SolidSyslogDatagram_SendTo(datagram, TEST_MESSAGE, TEST_MESSAGE_LEN, addr); - LONGS_EQUAL(1, SocketFake_SendtoCallCount()); + CALLED_FAKE(SocketFake_Sendto, ONCE); } TEST(SolidSyslogPosixDatagram, SendToPassesBuffer) @@ -155,7 +158,7 @@ TEST(SolidSyslogPosixDatagram, CloseCallsCloseOnce) { SolidSyslogDatagram_Open(datagram); SolidSyslogDatagram_Close(datagram); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogPosixDatagram, CloseCalledWithSocketFd) @@ -173,14 +176,14 @@ TEST(SolidSyslogPosixDatagram, MaxPayloadFallsBackToIpv6SafePayload) TEST(SolidSyslogPosixDatagram, OpenDoesNotConnect) { SolidSyslogDatagram_Open(datagram); - LONGS_EQUAL(0, SocketFake_ConnectCallCount()); + CALLED_FAKE(SocketFake_Connect, NEVER); } TEST(SolidSyslogPosixDatagram, SendToConnectsOnFirstCall) { SolidSyslogDatagram_Open(datagram); SolidSyslogDatagram_SendTo(datagram, TEST_MESSAGE, TEST_MESSAGE_LEN, addr); - LONGS_EQUAL(1, SocketFake_ConnectCallCount()); + CALLED_FAKE(SocketFake_Connect, ONCE); } TEST(SolidSyslogPosixDatagram, SendToConnectsOnceAcrossMultipleCalls) @@ -188,7 +191,7 @@ TEST(SolidSyslogPosixDatagram, SendToConnectsOnceAcrossMultipleCalls) SolidSyslogDatagram_Open(datagram); SolidSyslogDatagram_SendTo(datagram, TEST_MESSAGE, TEST_MESSAGE_LEN, addr); SolidSyslogDatagram_SendTo(datagram, TEST_MESSAGE, TEST_MESSAGE_LEN, addr); - LONGS_EQUAL(1, SocketFake_ConnectCallCount()); + CALLED_FAKE(SocketFake_Connect, ONCE); } TEST(SolidSyslogPosixDatagram, FirstSendEnablesPmtuDiscovery) @@ -210,7 +213,7 @@ TEST(SolidSyslogPosixDatagram, MaxPayloadAfterConnectQueriesIpMtu) SolidSyslogDatagram_Open(datagram); SolidSyslogDatagram_SendTo(datagram, TEST_MESSAGE, TEST_MESSAGE_LEN, addr); SolidSyslogDatagram_MaxPayload(datagram); - LONGS_EQUAL(1, SocketFake_GetSockOptCallCount()); + CALLED_FAKE(SocketFake_GetSockOpt, ONCE); } TEST(SolidSyslogPosixDatagram, MaxPayloadConvertsIpMtuViaFromMtu) diff --git a/Tests/SolidSyslogPosixMessageQueueBufferTest.cpp b/Tests/SolidSyslogPosixMessageQueueBufferTest.cpp index 61b70502..afd8c2e0 100644 --- a/Tests/SolidSyslogPosixMessageQueueBufferTest.cpp +++ b/Tests/SolidSyslogPosixMessageQueueBufferTest.cpp @@ -1,6 +1,9 @@ #include +#include "TestUtils.h" #include "CppUTest/TestHarness.h" + +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros #include "SolidSyslogBuffer.h" #include "SolidSyslogPosixMessageQueueBuffer.h" #include "SolidSyslog.h" @@ -103,7 +106,7 @@ TEST(SolidSyslogPosixMessageQueueBuffer, ServiceSendsMessageWrittenViaLog) SolidSyslogMessage message = {SOLIDSYSLOG_FACILITY_LOCAL0, SOLIDSYSLOG_SEVERITY_INFO, nullptr, nullptr}; SolidSyslog_Log(&message); SolidSyslog_Service(); - LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); + CALLED_FAKE_ON(SenderFake_Send, fakeSender, ONCE); SolidSyslog_Destroy(); SolidSyslogNullStore_Destroy(); diff --git a/Tests/SolidSyslogPosixTcpStreamTest.cpp b/Tests/SolidSyslogPosixTcpStreamTest.cpp index 4115b72f..d8a539da 100644 --- a/Tests/SolidSyslogPosixTcpStreamTest.cpp +++ b/Tests/SolidSyslogPosixTcpStreamTest.cpp @@ -6,7 +6,10 @@ #include #include +#include "TestUtils.h" #include "CppUTest/TestHarness.h" + +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros #include "SolidSyslogAddress.h" #include "SolidSyslogPosixTcpStream.h" #include "SolidSyslogStream.h" @@ -62,7 +65,7 @@ TEST_GROUP(SolidSyslogPosixTcpStream) #define CHECK_SOCKET_CLOSED_ONCE() \ do \ { \ - LONGS_EQUAL(1, SocketFake_CloseCallCount()); \ + CALLED_FAKE(SocketFake_Close, ONCE); \ LONGS_EQUAL(SocketFake_SocketFd(), SocketFake_LastClosedFd()); \ } while (0) @@ -83,7 +86,7 @@ TEST(SolidSyslogPosixTcpStream, CreateReturnsHandleInsideCallerSuppliedStorage) TEST(SolidSyslogPosixTcpStream, OpenCallsSocketOnce) { SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, SocketFake_SocketCallCount()); + CALLED_FAKE(SocketFake_Socket, ONCE); } TEST(SolidSyslogPosixTcpStream, OpenCallsSocketWithAF_INET) @@ -153,13 +156,13 @@ TEST(SolidSyslogPosixTcpStream, OpenFailsWhenFcntlSetFlFails) caller cannot bound the connect wait — fail fast. */ SocketFake_SetFcntlSetFlFails(true); CHECK_FALSE(SolidSyslogStream_Open(stream, addr)); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogPosixTcpStream, OpenCallsConnectWithSocketFd) { SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, SocketFake_ConnectCallCount()); + CALLED_FAKE(SocketFake_Connect, ONCE); LONGS_EQUAL(SocketFake_SocketFd(), SocketFake_LastConnectFd()); } @@ -191,8 +194,8 @@ TEST(SolidSyslogPosixTcpStream, OpenSkipsConnectAndSetsockoptWhenSocketFails) { SocketFake_SetSocketFails(true); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(0, SocketFake_ConnectCallCount()); - LONGS_EQUAL(0, SocketFake_SetSockOptCallCount()); + CALLED_FAKE(SocketFake_Connect, NEVER); + CALLED_FAKE(SocketFake_SetSockOpt, NEVER); } TEST(SolidSyslogPosixTcpStream, SendReturnsFalseOnShortWrite) @@ -207,7 +210,7 @@ TEST(SolidSyslogPosixTcpStream, SendDoesNotRetryAfterShortWrite) SolidSyslogStream_Open(stream, addr); SocketFake_SetSendReturn(3); SolidSyslogStream_Send(stream, TEST_MESSAGE, TEST_MESSAGE_LEN); - LONGS_EQUAL(1, SocketFake_SendCallCount()); + CALLED_FAKE(SocketFake_Send, ONCE); } TEST(SolidSyslogPosixTcpStream, SendReturnsFalseOnEintr) @@ -238,7 +241,7 @@ TEST(SolidSyslogPosixTcpStream, OpenClosesSocketOnConnectFailure) { SocketFake_SetConnectFails(true); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); LONGS_EQUAL(SocketFake_SocketFd(), SocketFake_LastClosedFd()); } @@ -246,7 +249,7 @@ TEST(SolidSyslogPosixTcpStream, SendCallsSendOnce) { SolidSyslogStream_Open(stream, addr); SolidSyslogStream_Send(stream, TEST_MESSAGE, TEST_MESSAGE_LEN); - LONGS_EQUAL(1, SocketFake_SendCallCount()); + CALLED_FAKE(SocketFake_Send, ONCE); } TEST(SolidSyslogPosixTcpStream, SendPassesBuffer) @@ -294,7 +297,7 @@ TEST(SolidSyslogPosixTcpStream, CloseCallsCloseOnce) { SolidSyslogStream_Open(stream, addr); SolidSyslogStream_Close(stream); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogPosixTcpStream, CloseCalledWithSocketFd) @@ -307,7 +310,7 @@ TEST(SolidSyslogPosixTcpStream, CloseCalledWithSocketFd) TEST(SolidSyslogPosixTcpStream, CloseIsNoOpWhenNotOpen) { SolidSyslogStream_Close(stream); - LONGS_EQUAL(0, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, NEVER); } TEST(SolidSyslogPosixTcpStream, ReadCallsRecvOnce) @@ -315,7 +318,7 @@ TEST(SolidSyslogPosixTcpStream, ReadCallsRecvOnce) SolidSyslogStream_Open(stream, addr); char buf[16]; SolidSyslogStream_Read(stream, buf, sizeof(buf)); - LONGS_EQUAL(1, SocketFake_RecvCallCount()); + CALLED_FAKE(SocketFake_Recv, ONCE); } TEST(SolidSyslogPosixTcpStream, ReadPassesSocketFdToRecv) @@ -363,7 +366,7 @@ TEST(SolidSyslogPosixTcpStream, DestroyClosesOpenSocket) { SolidSyslogStream_Open(stream, addr); SolidSyslogPosixTcpStream_Destroy(stream); - LONGS_EQUAL(1, SocketFake_CloseCallCount()); + CALLED_FAKE(SocketFake_Close, ONCE); } TEST(SolidSyslogPosixTcpStream, DestroyClosesWithSocketFd) @@ -388,14 +391,14 @@ TEST(SolidSyslogPosixTcpStream, OpenSkipsSelectWhenConnectReturnsImmediately) /* Default fake connect returns 0 (immediate success); select must not be reached because connect short-circuits the wait. */ SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(0, SocketFake_SelectCallCount()); + CALLED_FAKE(SocketFake_Select, NEVER); } TEST(SolidSyslogPosixTcpStream, OpenInvokesSelectWhenConnectReturnsEinprogress) { SocketFake_SetConnectFailsWithErrno(EINPROGRESS); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, SocketFake_SelectCallCount()); + CALLED_FAKE(SocketFake_Select, ONCE); } TEST(SolidSyslogPosixTcpStream, OpenPassesBoundedConnectTimeoutToSelect) @@ -464,7 +467,7 @@ TEST(SolidSyslogPosixTcpStream, OpenFailsWhenConnectFailsImmediatelyWithRefused) SO_ERROR check, just fail fast. */ SocketFake_SetConnectFailsWithErrno(ECONNREFUSED); CHECK_FALSE(SolidSyslogStream_Open(stream, addr)); - LONGS_EQUAL(0, SocketFake_SelectCallCount()); + CALLED_FAKE(SocketFake_Select, NEVER); } TEST(SolidSyslogPosixTcpStream, OpenFailsWhenSO_ERRORLookupFails) diff --git a/Tests/SolidSyslogTest.cpp b/Tests/SolidSyslogTest.cpp index c4621983..7398af31 100644 --- a/Tests/SolidSyslogTest.cpp +++ b/Tests/SolidSyslogTest.cpp @@ -23,8 +23,11 @@ #include "SolidSyslogStore.h" #include "SolidSyslogTimeQuality.h" #include "SolidSyslogTimestamp.h" +#include "TestUtils.h" #include "CppUTest/TestHarness.h" +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + class TEST_SolidSyslogTimestamp_Day0ProducesNilvalue_Test; class TEST_SolidSyslogTimestamp_Day1FormatsAs01_Test; class TEST_SolidSyslogTimestamp_Day31FormatsAs31_Test; @@ -364,13 +367,13 @@ TEST(SolidSyslog, CreateDestroyWorksWithoutCrashing) TEST(SolidSyslog, NoMessagesAreSentWhenLogIsNotCalled) { - LONGS_EQUAL(0, SenderFake_SendCallCount(fakeSender)); + CALLED_FAKE_ON(SenderFake_Send, fakeSender, NEVER); } TEST(SolidSyslog, SingleLogCallResultsInOneSend) { Log(); - LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); + CALLED_FAKE_ON(SenderFake_Send, fakeSender, ONCE); } TEST(SolidSyslog, PriValIs134) @@ -1264,7 +1267,7 @@ TEST(SolidSyslog, ServiceSendsMessageReadFromBuffer) SenderFake_Reset(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); + CALLED_FAKE_ON(SenderFake_Send, fakeSender, ONCE); STRCMP_EQUAL("test", SenderFake_LastBufferAsString(fakeSender)); SolidSyslog_Destroy(); @@ -1285,7 +1288,7 @@ TEST(SolidSyslog, ServiceSendsBufferedMessageWithNullStore) SenderFake_Reset(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); + CALLED_FAKE_ON(SenderFake_Send, fakeSender, ONCE); STRCMP_EQUAL("test", SenderFake_LastBufferAsString(fakeSender)); SolidSyslog_Destroy(); @@ -1307,7 +1310,7 @@ TEST(SolidSyslog, ServiceSendsFromStoreWhenHasUnsent) SenderFake_Reset(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); + CALLED_FAKE_ON(SenderFake_Send, fakeSender, ONCE); STRCMP_EQUAL("stored", SenderFake_LastBufferAsString(fakeSender)); SolidSyslog_Destroy(); @@ -1418,7 +1421,7 @@ TEST(SolidSyslog, ServiceSendsDirectlyWhenStoreWriteFails) SenderFake_Reset(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); + CALLED_FAKE_ON(SenderFake_Send, fakeSender, ONCE); STRCMP_EQUAL("direct", SenderFake_LastBufferAsString(fakeSender)); SolidSyslog_Destroy(); @@ -1441,7 +1444,7 @@ TEST(SolidSyslog, ServiceDoesNotSendWhenStoreReadFails) SenderFake_Reset(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(0, SenderFake_SendCallCount(fakeSender)); + CALLED_FAKE_ON(SenderFake_Send, fakeSender, NEVER); SolidSyslog_Destroy(); SolidSyslog_Create(&config); @@ -1464,7 +1467,7 @@ TEST(SolidSyslog, ServiceDoesNotMarkSentWhenSendingFromBuffer) SenderFake_Reset(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(1, SenderFake_SendCallCount(fakeSender)); + CALLED_FAKE_ON(SenderFake_Send, fakeSender, ONCE); STRCMP_EQUAL("from-buffer", SenderFake_LastBufferAsString(fakeSender)); SolidSyslog_Destroy(); @@ -1524,7 +1527,7 @@ TEST(SolidSyslogServiceEagerDrain, AllBufferedMessagesReachStoreInOneTickWhenSen SenderFake_FailNextSend(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(3, StoreFake_WriteCallCount(fakeStore)); + CALLED_FAKE_ON(StoreFake_Write, fakeStore, THRICE); } TEST(SolidSyslogServiceEagerDrain, StoredMessagesDrainInFifoOrderAcrossTicks) @@ -1539,7 +1542,7 @@ TEST(SolidSyslogServiceEagerDrain, StoredMessagesDrainInFifoOrderAcrossTicks) STRCMP_EQUAL("m2", SenderFake_LastBufferAsString(fakeSender)); SolidSyslog_Service(); STRCMP_EQUAL("m3", SenderFake_LastBufferAsString(fakeSender)); - LONGS_EQUAL(3, SenderFake_SendCallCount(fakeSender)); + CALLED_FAKE_ON(SenderFake_Send, fakeSender, THRICE); } TEST(SolidSyslog, ServiceDoesNothingWhenStoreIsHalted) @@ -1556,7 +1559,7 @@ TEST(SolidSyslog, ServiceDoesNothingWhenStoreIsHalted) SenderFake_Reset(fakeSender); SolidSyslog_Service(); - LONGS_EQUAL(0, SenderFake_SendCallCount(fakeSender)); + CALLED_FAKE_ON(SenderFake_Send, fakeSender, NEVER); SolidSyslog_Destroy(); SolidSyslog_Create(&config); diff --git a/Tests/SolidSyslogWinsockDatagramTest.cpp b/Tests/SolidSyslogWinsockDatagramTest.cpp index f82cb876..0ecbed6b 100644 --- a/Tests/SolidSyslogWinsockDatagramTest.cpp +++ b/Tests/SolidSyslogWinsockDatagramTest.cpp @@ -1,4 +1,7 @@ +#include "TestUtils.h" #include "CppUTest/TestHarness.h" + +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros #include "SolidSyslogAddress.h" #include "SolidSyslogDatagram.h" #include "SolidSyslogUdpPayload.h" @@ -60,7 +63,7 @@ TEST(SolidSyslogWinsockDatagram, CreateDestroyWorksWithoutCrashing) TEST(SolidSyslogWinsockDatagram, OpenCallsSocketOnce) { SolidSyslogDatagram_Open(datagram); - LONGS_EQUAL(1, WinsockFake_SocketCallCount()); + CALLED_FAKE(WinsockFake_Socket, ONCE); } TEST(SolidSyslogWinsockDatagram, OpenCallsSocketWithAF_INET) @@ -90,7 +93,7 @@ TEST(SolidSyslogWinsockDatagram, SendToCallsSendtoOnce) { SolidSyslogDatagram_Open(datagram); SolidSyslogDatagram_SendTo(datagram, TEST_MESSAGE, TEST_MESSAGE_LEN, addr); - LONGS_EQUAL(1, WinsockFake_SendtoCallCount()); + CALLED_FAKE(WinsockFake_Sendto, ONCE); } TEST(SolidSyslogWinsockDatagram, SendToPassesBuffer) @@ -159,7 +162,7 @@ TEST(SolidSyslogWinsockDatagram, CloseCallsCloseOnce) { SolidSyslogDatagram_Open(datagram); SolidSyslogDatagram_Close(datagram); - LONGS_EQUAL(1, WinsockFake_CloseCallCount()); + CALLED_FAKE(WinsockFake_Close, ONCE); } TEST(SolidSyslogWinsockDatagram, CloseCalledWithSocketFd) @@ -177,14 +180,14 @@ TEST(SolidSyslogWinsockDatagram, MaxPayloadFallsBackToIpv6SafePayload) TEST(SolidSyslogWinsockDatagram, OpenDoesNotConnect) { SolidSyslogDatagram_Open(datagram); - LONGS_EQUAL(0, WinsockFake_ConnectCallCount()); + CALLED_FAKE(WinsockFake_Connect, NEVER); } TEST(SolidSyslogWinsockDatagram, SendToConnectsOnFirstCall) { SolidSyslogDatagram_Open(datagram); SolidSyslogDatagram_SendTo(datagram, TEST_MESSAGE, TEST_MESSAGE_LEN, addr); - LONGS_EQUAL(1, WinsockFake_ConnectCallCount()); + CALLED_FAKE(WinsockFake_Connect, ONCE); } TEST(SolidSyslogWinsockDatagram, SendToConnectsOnceAcrossMultipleCalls) @@ -192,7 +195,7 @@ TEST(SolidSyslogWinsockDatagram, SendToConnectsOnceAcrossMultipleCalls) SolidSyslogDatagram_Open(datagram); SolidSyslogDatagram_SendTo(datagram, TEST_MESSAGE, TEST_MESSAGE_LEN, addr); SolidSyslogDatagram_SendTo(datagram, TEST_MESSAGE, TEST_MESSAGE_LEN, addr); - LONGS_EQUAL(1, WinsockFake_ConnectCallCount()); + CALLED_FAKE(WinsockFake_Connect, ONCE); } TEST(SolidSyslogWinsockDatagram, FirstSendEnablesPmtuDiscovery) @@ -221,7 +224,7 @@ TEST(SolidSyslogWinsockDatagram, MaxPayloadAfterConnectQueriesIpMtu) SolidSyslogDatagram_Open(datagram); SolidSyslogDatagram_SendTo(datagram, TEST_MESSAGE, TEST_MESSAGE_LEN, addr); SolidSyslogDatagram_MaxPayload(datagram); - LONGS_EQUAL(1, WinsockFake_GetSockOptCallCount()); + CALLED_FAKE(WinsockFake_GetSockOpt, ONCE); } TEST(SolidSyslogWinsockDatagram, MaxPayloadConvertsIpMtuViaFromMtu) diff --git a/Tests/SolidSyslogWinsockResolverTest.cpp b/Tests/SolidSyslogWinsockResolverTest.cpp index adf88efc..6e05abf5 100644 --- a/Tests/SolidSyslogWinsockResolverTest.cpp +++ b/Tests/SolidSyslogWinsockResolverTest.cpp @@ -1,4 +1,7 @@ +#include "TestUtils.h" #include "CppUTest/TestHarness.h" + +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros #include "SolidSyslogAddress.h" #include "SolidSyslogResolver.h" #include "SolidSyslogWinsockResolver.h" @@ -84,7 +87,7 @@ TEST(SolidSyslogWinsockResolver, PopulatesPortFromPortArgument) TEST(SolidSyslogWinsockResolver, GetAddrInfoCalledWithHostArgument) { Resolve(TEST_ALTERNATE_HOST, TEST_PORT); - LONGS_EQUAL(1, WinsockFake_GetAddrInfoCallCount()); + CALLED_FAKE(WinsockFake_GetAddrInfo, ONCE); STRCMP_EQUAL(TEST_ALTERNATE_HOST, WinsockFake_LastGetAddrInfoHostname()); } @@ -110,11 +113,11 @@ TEST(SolidSyslogWinsockResolver, DoesNotFreeAddrInfoWhenGetAddrInfoFails) { WinsockFake_SetGetAddrInfoFails(true); Resolve(TEST_HOST, TEST_PORT); - LONGS_EQUAL(0, WinsockFake_FreeAddrInfoCallCount()); + CALLED_FAKE(WinsockFake_FreeAddrInfo, NEVER); } TEST(SolidSyslogWinsockResolver, FreesAddrInfoOnSuccess) { Resolve(TEST_HOST, TEST_PORT); - LONGS_EQUAL(1, WinsockFake_FreeAddrInfoCallCount()); + CALLED_FAKE(WinsockFake_FreeAddrInfo, ONCE); } diff --git a/Tests/SolidSyslogWinsockTcpStreamTest.cpp b/Tests/SolidSyslogWinsockTcpStreamTest.cpp index f0af7fad..fc2b5b4d 100644 --- a/Tests/SolidSyslogWinsockTcpStreamTest.cpp +++ b/Tests/SolidSyslogWinsockTcpStreamTest.cpp @@ -1,4 +1,7 @@ +#include "TestUtils.h" #include "CppUTest/TestHarness.h" + +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros #include "SolidSyslogAddress.h" #include "SolidSyslogStream.h" #include "SolidSyslogTransport.h" @@ -68,7 +71,7 @@ TEST_GROUP(SolidSyslogWinsockTcpStream) #define CHECK_SOCKET_CLOSED_ONCE() \ do \ { \ - LONGS_EQUAL(1, WinsockFake_CloseCallCount()); \ + CALLED_FAKE(WinsockFake_Close, ONCE); \ CHECK(WinsockFake_SocketFd() == WinsockFake_LastClosedFd()); \ } while (0) @@ -89,7 +92,7 @@ TEST(SolidSyslogWinsockTcpStream, CreateReturnsHandleInsideCallerSuppliedStorage TEST(SolidSyslogWinsockTcpStream, OpenCallsSocketOnce) { SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, WinsockFake_SocketCallCount()); + CALLED_FAKE(WinsockFake_Socket, ONCE); } TEST(SolidSyslogWinsockTcpStream, OpenCallsSocketWithAF_INET) @@ -141,7 +144,7 @@ TEST(SolidSyslogWinsockTcpStream, OpenSetsTcpKeepCntTo4) TEST(SolidSyslogWinsockTcpStream, OpenCallsConnectWithSocketFd) { SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, WinsockFake_ConnectCallCount()); + CALLED_FAKE(WinsockFake_Connect, ONCE); CHECK(WinsockFake_SocketFd() == WinsockFake_LastConnectFd()); } @@ -173,15 +176,15 @@ TEST(SolidSyslogWinsockTcpStream, OpenSkipsConnectAndSetsockoptWhenSocketFails) { WinsockFake_SetSocketFails(true); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(0, WinsockFake_ConnectCallCount()); - LONGS_EQUAL(0, WinsockFake_SetSockOptCallCount()); + CALLED_FAKE(WinsockFake_Connect, NEVER); + CALLED_FAKE(WinsockFake_SetSockOpt, NEVER); } TEST(SolidSyslogWinsockTcpStream, OpenClosesSocketOnConnectFailure) { WinsockFake_SetConnectFails(true); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, WinsockFake_CloseCallCount()); + CALLED_FAKE(WinsockFake_Close, ONCE); CHECK(WinsockFake_SocketFd() == WinsockFake_LastClosedFd()); } @@ -196,7 +199,7 @@ TEST(SolidSyslogWinsockTcpStream, OpenSetsNonBlockingMode) SolidSyslogStream_Open(stream, addr); /* Single FIONBIO call: non-blocking on (1). The socket stays non-blocking so Send/Read are also fail-fast — no SO_SNDTIMEO needed. */ - LONGS_EQUAL(1, WinsockFake_FionbioCallCount()); + CALLED_FAKE(WinsockFake_Fionbio, ONCE); LONGS_EQUAL(1, WinsockFake_FionbioArgAt(0)); } @@ -205,14 +208,14 @@ TEST(SolidSyslogWinsockTcpStream, OpenSkipsSelectWhenConnectReturnsImmediately) /* Default fake connect returns 0 (immediate success); select must not be reached because connect short-circuits the wait. */ SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(0, WinsockFake_SelectCallCount()); + CALLED_FAKE(WinsockFake_Select, NEVER); } TEST(SolidSyslogWinsockTcpStream, OpenInvokesSelectWhenConnectReturnsWouldBlock) { WinsockFake_SetConnectFailsWithLastError(WSAEWOULDBLOCK); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, WinsockFake_SelectCallCount()); + CALLED_FAKE(WinsockFake_Select, ONCE); } TEST(SolidSyslogWinsockTcpStream, OpenPassesBoundedConnectTimeoutToSelect) @@ -247,7 +250,7 @@ TEST(SolidSyslogWinsockTcpStream, OpenClosesSocketOnSelectTimeout) WinsockFake_SetSelectWritable(false); WinsockFake_SetSelectReturn(0); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, WinsockFake_CloseCallCount()); + CALLED_FAKE(WinsockFake_Close, ONCE); CHECK(WinsockFake_SocketFd() == WinsockFake_LastClosedFd()); } @@ -292,14 +295,14 @@ TEST(SolidSyslogWinsockTcpStream, OpenFailsWhenConnectFailsImmediatelyWithRefuse no select wait, no SO_ERROR check, just fail fast. */ WinsockFake_SetConnectFailsWithLastError(WSAECONNREFUSED); CHECK_FALSE(SolidSyslogStream_Open(stream, addr)); - LONGS_EQUAL(0, WinsockFake_SelectCallCount()); + CALLED_FAKE(WinsockFake_Select, NEVER); } TEST(SolidSyslogWinsockTcpStream, SendCallsSendOnce) { SolidSyslogStream_Open(stream, addr); SolidSyslogStream_Send(stream, TEST_MESSAGE, TEST_MESSAGE_LEN); - LONGS_EQUAL(1, WinsockFake_SendCallCount()); + CALLED_FAKE(WinsockFake_Send, ONCE); } TEST(SolidSyslogWinsockTcpStream, SendPassesBuffer) @@ -355,7 +358,7 @@ TEST(SolidSyslogWinsockTcpStream, SendDoesNotRetryAfterShortWrite) SolidSyslogStream_Open(stream, addr); WinsockFake_SetSendReturn(3); SolidSyslogStream_Send(stream, TEST_MESSAGE, TEST_MESSAGE_LEN); - LONGS_EQUAL(1, WinsockFake_SendCallCount()); + CALLED_FAKE(WinsockFake_Send, ONCE); } TEST(SolidSyslogWinsockTcpStream, SendClosesSocketOnFailure) @@ -370,7 +373,7 @@ TEST(SolidSyslogWinsockTcpStream, CloseCallsCloseOnce) { SolidSyslogStream_Open(stream, addr); SolidSyslogStream_Close(stream); - LONGS_EQUAL(1, WinsockFake_CloseCallCount()); + CALLED_FAKE(WinsockFake_Close, ONCE); } TEST(SolidSyslogWinsockTcpStream, CloseCalledWithSocketFd) @@ -383,7 +386,7 @@ TEST(SolidSyslogWinsockTcpStream, CloseCalledWithSocketFd) TEST(SolidSyslogWinsockTcpStream, CloseIsNoOpWhenNotOpen) { SolidSyslogStream_Close(stream); - LONGS_EQUAL(0, WinsockFake_CloseCallCount()); + CALLED_FAKE(WinsockFake_Close, NEVER); } TEST(SolidSyslogWinsockTcpStream, ReadCallsRecvOnce) @@ -391,7 +394,7 @@ TEST(SolidSyslogWinsockTcpStream, ReadCallsRecvOnce) SolidSyslogStream_Open(stream, addr); char buf[16]; SolidSyslogStream_Read(stream, buf, sizeof(buf)); - LONGS_EQUAL(1, WinsockFake_RecvCallCount()); + CALLED_FAKE(WinsockFake_Recv, ONCE); } TEST(SolidSyslogWinsockTcpStream, ReadPassesSocketFdToRecv) @@ -462,7 +465,7 @@ TEST(SolidSyslogWinsockTcpStream, DestroyClosesOpenSocket) { SolidSyslogStream_Open(stream, addr); SolidSyslogWinsockTcpStream_Destroy(stream); - LONGS_EQUAL(1, WinsockFake_CloseCallCount()); + CALLED_FAKE(WinsockFake_Close, ONCE); } TEST(SolidSyslogWinsockTcpStream, DestroyClosesWithSocketFd) diff --git a/Tests/StoreFakeTest.cpp b/Tests/StoreFakeTest.cpp index 4b90dfab..9afd2e22 100644 --- a/Tests/StoreFakeTest.cpp +++ b/Tests/StoreFakeTest.cpp @@ -2,8 +2,11 @@ #include "StoreFake.h" #include "SolidSyslogStore.h" +#include "TestUtils.h" #include "CppUTest/TestHarness.h" +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + static const char* const TEST_MESSAGE = "hello"; static const size_t TEST_MESSAGE_LEN = 5; @@ -115,7 +118,7 @@ TEST(StoreFake, WriteCountReportsSuccessfulWrites) { SolidSyslogStore_Write(store, "a", 1); SolidSyslogStore_Write(store, "b", 1); - LONGS_EQUAL(2, StoreFake_WriteCallCount(store)); + CALLED_FAKE_ON(StoreFake_Write, store, TWICE); } TEST(StoreFake, WriteCountIgnoresFailedWrite) @@ -123,5 +126,5 @@ TEST(StoreFake, WriteCountIgnoresFailedWrite) SolidSyslogStore_Write(store, "a", 1); StoreFake_FailNextWrite(); SolidSyslogStore_Write(store, "b", 1); - LONGS_EQUAL(1, StoreFake_WriteCallCount(store)); + CALLED_FAKE_ON(StoreFake_Write, store, ONCE); } diff --git a/Tests/StreamFakeTest.cpp b/Tests/StreamFakeTest.cpp index 141523ce..85f0cd71 100644 --- a/Tests/StreamFakeTest.cpp +++ b/Tests/StreamFakeTest.cpp @@ -1,8 +1,11 @@ #include "SolidSyslogAddress.h" #include "SolidSyslogStream.h" #include "StreamFake.h" +#include "TestUtils.h" #include "CppUTest/TestHarness.h" +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros + // clang-format off TEST_GROUP(StreamFake) { @@ -26,7 +29,7 @@ TEST(StreamFake, OpenIncrementsCount) SolidSyslogAddressStorage storage = {0}; struct SolidSyslogAddress* addr = SolidSyslogAddress_FromStorage(&storage); SolidSyslogStream_Open(stream, addr); - LONGS_EQUAL(1, StreamFake_OpenCallCount(stream)); + CALLED_FAKE_ON(StreamFake_Open, stream, ONCE); } TEST(StreamFake, OpenCapturesAddr) @@ -41,7 +44,7 @@ TEST(StreamFake, SendIncrementsCount) { const char payload[] = "hi"; SolidSyslogStream_Send(stream, payload, sizeof(payload)); - LONGS_EQUAL(1, StreamFake_SendCallCount(stream)); + CALLED_FAKE_ON(StreamFake_Send, stream, ONCE); } TEST(StreamFake, SendCapturesBuffer) @@ -62,7 +65,7 @@ TEST(StreamFake, ReadIncrementsCount) { char buf[16]; SolidSyslogStream_Read(stream, buf, sizeof(buf)); - LONGS_EQUAL(1, StreamFake_ReadCallCount(stream)); + CALLED_FAKE_ON(StreamFake_Read, stream, ONCE); } TEST(StreamFake, ReadCapturesBuffer) @@ -90,7 +93,7 @@ TEST(StreamFake, ReadReturnsConfiguredValue) TEST(StreamFake, CloseIncrementsCount) { SolidSyslogStream_Close(stream); - LONGS_EQUAL(1, StreamFake_CloseCallCount(stream)); + CALLED_FAKE_ON(StreamFake_Close, stream, ONCE); } TEST(StreamFake, OpenDefaultsToSuccess) diff --git a/Tests/WinsockFakeTest.cpp b/Tests/WinsockFakeTest.cpp index c2007848..b01027f7 100644 --- a/Tests/WinsockFakeTest.cpp +++ b/Tests/WinsockFakeTest.cpp @@ -1,4 +1,7 @@ +#include "TestUtils.h" #include "CppUTest/TestHarness.h" + +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros #include "WinsockFake.h" #include #include @@ -28,7 +31,7 @@ TEST_GROUP(WinsockFake) TEST(WinsockFake, SocketRecordsCall) { WinsockFake_socket(AF_INET, SOCK_DGRAM, 0); - LONGS_EQUAL(1, WinsockFake_SocketCallCount()); + CALLED_FAKE(WinsockFake_Socket, ONCE); LONGS_EQUAL(AF_INET, WinsockFake_SocketDomain()); LONGS_EQUAL(SOCK_DGRAM, WinsockFake_SocketType()); } @@ -50,7 +53,7 @@ TEST(WinsockFake, SendtoRecordsBufferAndAddress) { SOCKET fd = WinsockFake_socket(AF_INET, SOCK_DGRAM, 0); WinsockFake_sendto(fd, TEST_MESSAGE, TEST_MESSAGE_LEN, 0, (const struct sockaddr*) &destination, sizeof(destination)); - LONGS_EQUAL(1, WinsockFake_SendtoCallCount()); + CALLED_FAKE(WinsockFake_Sendto, ONCE); STRCMP_EQUAL(TEST_MESSAGE, WinsockFake_LastBufAsString()); LONGS_EQUAL(TEST_MESSAGE_LEN, (int) WinsockFake_LastLen()); LONGS_EQUAL(TEST_PORT, WinsockFake_LastPort()); @@ -75,7 +78,7 @@ TEST(WinsockFake, ClosesocketRecordsCall) { SOCKET fd = WinsockFake_socket(AF_INET, SOCK_DGRAM, 0); WinsockFake_closesocket(fd); - LONGS_EQUAL(1, WinsockFake_CloseCallCount()); + CALLED_FAKE(WinsockFake_Close, ONCE); CHECK(WinsockFake_LastClosedFd() == fd); } @@ -85,7 +88,7 @@ TEST(WinsockFake, GetAddrInfoRecordsHostnameAndSocktype) hints.ai_socktype = SOCK_DGRAM; struct addrinfo* res = nullptr; WinsockFake_getaddrinfo(TEST_HOST, nullptr, &hints, &res); - LONGS_EQUAL(1, WinsockFake_GetAddrInfoCallCount()); + CALLED_FAKE(WinsockFake_GetAddrInfo, ONCE); STRCMP_EQUAL(TEST_HOST, WinsockFake_LastGetAddrInfoHostname()); LONGS_EQUAL(SOCK_DGRAM, WinsockFake_LastGetAddrInfoSocktype()); CHECK(res != nullptr); @@ -104,14 +107,14 @@ TEST(WinsockFake, FreeAddrInfoRecordsCall) struct addrinfo* res = nullptr; WinsockFake_getaddrinfo(TEST_HOST, nullptr, nullptr, &res); WinsockFake_freeaddrinfo(res); - LONGS_EQUAL(1, WinsockFake_FreeAddrInfoCallCount()); + CALLED_FAKE(WinsockFake_FreeAddrInfo, ONCE); } TEST(WinsockFake, ConnectRecordsCallAndAddress) { SOCKET fd = WinsockFake_socket(AF_INET, SOCK_STREAM, 0); WinsockFake_connect(fd, (const struct sockaddr*) &destination, sizeof(destination)); - LONGS_EQUAL(1, WinsockFake_ConnectCallCount()); + CALLED_FAKE(WinsockFake_Connect, ONCE); CHECK(WinsockFake_LastConnectFd() == fd); LONGS_EQUAL(TEST_PORT, WinsockFake_LastConnectPort()); STRCMP_EQUAL(TEST_HOST, WinsockFake_LastConnectAddrAsString()); @@ -134,7 +137,7 @@ TEST(WinsockFake, SendRecordsBufferAndFlags) { SOCKET fd = WinsockFake_socket(AF_INET, SOCK_STREAM, 0); WinsockFake_send(fd, TEST_MESSAGE, TEST_MESSAGE_LEN, 0); - LONGS_EQUAL(1, WinsockFake_SendCallCount()); + CALLED_FAKE(WinsockFake_Send, ONCE); STRCMP_EQUAL(TEST_MESSAGE, WinsockFake_SendBufAsString(0)); LONGS_EQUAL(TEST_MESSAGE_LEN, (int) WinsockFake_SendLen(0)); LONGS_EQUAL(0, WinsockFake_SendFlags(0)); @@ -176,7 +179,7 @@ TEST(WinsockFake, RecvRecordsCall) char buf[16]; SOCKET fd = WinsockFake_socket(AF_INET, SOCK_STREAM, 0); WinsockFake_recv(fd, buf, sizeof(buf), 0); - LONGS_EQUAL(1, WinsockFake_RecvCallCount()); + CALLED_FAKE(WinsockFake_Recv, ONCE); CHECK(WinsockFake_LastRecvFd() == fd); POINTERS_EQUAL(buf, WinsockFake_LastRecvBuf()); LONGS_EQUAL(sizeof(buf), WinsockFake_LastRecvLen()); @@ -195,7 +198,7 @@ TEST(WinsockFake, SetSockOptRecordsLevelAndOptname) { int enable = 1; WinsockFake_setsockopt(INVALID_SOCKET, IPPROTO_TCP, TCP_NODELAY, (const char*) &enable, sizeof(enable)); - LONGS_EQUAL(1, WinsockFake_SetSockOptCallCount()); + CALLED_FAKE(WinsockFake_SetSockOpt, ONCE); LONGS_EQUAL(IPPROTO_TCP, WinsockFake_LastSetSockOptLevel()); LONGS_EQUAL(TCP_NODELAY, WinsockFake_LastSetSockOptOptname()); } @@ -228,13 +231,13 @@ TEST(WinsockFake, ResetClearsCounters) { WinsockFake_socket(AF_INET, SOCK_DGRAM, 0); WinsockFake_Reset(); - LONGS_EQUAL(0, WinsockFake_SocketCallCount()); - LONGS_EQUAL(0, WinsockFake_SendtoCallCount()); - LONGS_EQUAL(0, WinsockFake_ConnectCallCount()); - LONGS_EQUAL(0, WinsockFake_SendCallCount()); - LONGS_EQUAL(0, WinsockFake_RecvCallCount()); - LONGS_EQUAL(0, WinsockFake_SetSockOptCallCount()); - LONGS_EQUAL(0, WinsockFake_CloseCallCount()); - LONGS_EQUAL(0, WinsockFake_GetAddrInfoCallCount()); - LONGS_EQUAL(0, WinsockFake_FreeAddrInfoCallCount()); + CALLED_FAKE(WinsockFake_Socket, NEVER); + CALLED_FAKE(WinsockFake_Sendto, NEVER); + CALLED_FAKE(WinsockFake_Connect, NEVER); + CALLED_FAKE(WinsockFake_Send, NEVER); + CALLED_FAKE(WinsockFake_Recv, NEVER); + CALLED_FAKE(WinsockFake_SetSockOpt, NEVER); + CALLED_FAKE(WinsockFake_Close, NEVER); + CALLED_FAKE(WinsockFake_GetAddrInfo, NEVER); + CALLED_FAKE(WinsockFake_FreeAddrInfo, NEVER); } From 2182ac9c35f9ec0e5f8b16cb92c3020585acf7aa Mon Sep 17 00:00:00 2001 From: David Cozens Date: Sun, 10 May 2026 21:40:56 +0100 Subject: [PATCH 09/10] chore: S24.02 apply clang-format clang-format -i across the touched test files. Picks up: - a small alignment shift on the bool->int fields in BlockStoreTest - the long `using namespace CososoTesting;` NOLINT comment wraps onto two lines under the 160-col limit - minor indentation tweaks in TlsStreamTest macro definitions No behaviour change; 1088 tests still pass. Co-Authored-By: Claude Opus 4.7 (1M context) --- Tests/DatagramFakeTest.cpp | 3 +- Tests/Example/ExampleServiceThreadTest.cpp | 3 +- Tests/Example/SolidSyslogExampleTest.cpp | 3 +- Tests/FreeRtos/CmsdkUartTest.cpp | 3 +- .../SolidSyslogFreeRtosDatagramTest.cpp | 3 +- Tests/OpenSslFakeTest.cpp | 3 +- Tests/SenderFakeTest.cpp | 3 +- Tests/SocketFakeTest.cpp | 3 +- Tests/SolidSyslogBlockStoreTest.cpp | 9 ++--- Tests/SolidSyslogErrorTest.cpp | 3 +- Tests/SolidSyslogGetAddrInfoResolverTest.cpp | 3 +- Tests/SolidSyslogNullBufferTest.cpp | 3 +- Tests/SolidSyslogPosixDatagramTest.cpp | 3 +- ...SolidSyslogPosixMessageQueueBufferTest.cpp | 3 +- Tests/SolidSyslogPosixTcpStreamTest.cpp | 5 +-- Tests/SolidSyslogStreamSenderTest.cpp | 3 +- Tests/SolidSyslogSwitchingSenderTest.cpp | 3 +- Tests/SolidSyslogTest.cpp | 3 +- Tests/SolidSyslogTlsStreamTest.cpp | 33 ++++++++++--------- Tests/SolidSyslogUdpSenderTest.cpp | 3 +- Tests/SolidSyslogWinsockDatagramTest.cpp | 3 +- Tests/SolidSyslogWinsockResolverTest.cpp | 3 +- Tests/SolidSyslogWinsockTcpStreamTest.cpp | 5 +-- Tests/StoreFakeTest.cpp | 3 +- Tests/StreamFakeTest.cpp | 3 +- Tests/Support/TestUtils.h | 4 +-- Tests/WinsockFakeTest.cpp | 3 +- 27 files changed, 74 insertions(+), 48 deletions(-) diff --git a/Tests/DatagramFakeTest.cpp b/Tests/DatagramFakeTest.cpp index 38c0aaf2..155861d0 100644 --- a/Tests/DatagramFakeTest.cpp +++ b/Tests/DatagramFakeTest.cpp @@ -3,7 +3,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros // clang-format off TEST_GROUP(DatagramFake) diff --git a/Tests/Example/ExampleServiceThreadTest.cpp b/Tests/Example/ExampleServiceThreadTest.cpp index 3814c9c5..e52f51f7 100644 --- a/Tests/Example/ExampleServiceThreadTest.cpp +++ b/Tests/Example/ExampleServiceThreadTest.cpp @@ -17,7 +17,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros static int SleepFakeCallCount; static int lastSleepMs; diff --git a/Tests/Example/SolidSyslogExampleTest.cpp b/Tests/Example/SolidSyslogExampleTest.cpp index 70e27bb8..47e1d844 100644 --- a/Tests/Example/SolidSyslogExampleTest.cpp +++ b/Tests/Example/SolidSyslogExampleTest.cpp @@ -9,7 +9,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros static const char* const STDIN_SEND_ONE = "/tmp/solidsyslog_test_send1.txt"; static const char* const STDIN_SEND_THREE = "/tmp/solidsyslog_test_send3.txt"; diff --git a/Tests/FreeRtos/CmsdkUartTest.cpp b/Tests/FreeRtos/CmsdkUartTest.cpp index a410e5c3..0dfa9866 100644 --- a/Tests/FreeRtos/CmsdkUartTest.cpp +++ b/Tests/FreeRtos/CmsdkUartTest.cpp @@ -1,7 +1,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros #include "CmsdkUart.h" #include "CmsdkUartFake.h" diff --git a/Tests/FreeRtos/SolidSyslogFreeRtosDatagramTest.cpp b/Tests/FreeRtos/SolidSyslogFreeRtosDatagramTest.cpp index f423e116..f405c253 100644 --- a/Tests/FreeRtos/SolidSyslogFreeRtosDatagramTest.cpp +++ b/Tests/FreeRtos/SolidSyslogFreeRtosDatagramTest.cpp @@ -1,7 +1,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros #include "SolidSyslogAddress.h" #include "SolidSyslogDatagram.h" diff --git a/Tests/OpenSslFakeTest.cpp b/Tests/OpenSslFakeTest.cpp index ade5adc2..4d5f22ca 100644 --- a/Tests/OpenSslFakeTest.cpp +++ b/Tests/OpenSslFakeTest.cpp @@ -7,7 +7,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros // clang-format off TEST_GROUP(OpenSslFake) diff --git a/Tests/SenderFakeTest.cpp b/Tests/SenderFakeTest.cpp index 2177e74a..d37c582a 100644 --- a/Tests/SenderFakeTest.cpp +++ b/Tests/SenderFakeTest.cpp @@ -3,7 +3,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros // clang-format off TEST_GROUP(SenderFake) diff --git a/Tests/SocketFakeTest.cpp b/Tests/SocketFakeTest.cpp index bc94941f..3c4f6c03 100644 --- a/Tests/SocketFakeTest.cpp +++ b/Tests/SocketFakeTest.cpp @@ -4,7 +4,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros // clang-format off TEST_GROUP(SocketFake) diff --git a/Tests/SolidSyslogBlockStoreTest.cpp b/Tests/SolidSyslogBlockStoreTest.cpp index 53b59bd9..035f3747 100644 --- a/Tests/SolidSyslogBlockStoreTest.cpp +++ b/Tests/SolidSyslogBlockStoreTest.cpp @@ -13,7 +13,8 @@ #include "FileFake.h" #include "TestUtils.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros static const char* const TEST_PATH_PREFIX = "/tmp/test_store"; static const char* const TEST_DATA = "hello"; @@ -879,7 +880,7 @@ TEST(SolidSyslogBlockStoreRotation, DiscardNewestReturnsFalseWhenAtMaxFiles) CHECK_FALSE(SolidSyslogStore_Write(store, maxMsg, sizeof(maxMsg))); } -static int StoreFullCallbackCallCount; +static int StoreFullCallbackCallCount; static void StoreFullCallback(void* context) { @@ -1362,7 +1363,7 @@ enum INTEGRITY_REGION_MAX = 2 + 2 + SOLIDSYSLOG_MAX_MESSAGE_SIZE /* magic + length + body */ }; -static int SpyComputeIntegrityCallCount; +static int SpyComputeIntegrityCallCount; static uint8_t computeIntegrityData[INTEGRITY_REGION_MAX]; static uint16_t computeIntegrityLength; @@ -1375,7 +1376,7 @@ static void SpyComputeIntegrity(const uint8_t* data, uint16_t length, uint8_t* i memcpy(computeIntegrityData, data, length); } -static int SpyVerifyIntegrityCallCount; +static int SpyVerifyIntegrityCallCount; static uint8_t verifyIntegrityData[INTEGRITY_REGION_MAX]; static uint16_t verifyIntegrityLength; diff --git a/Tests/SolidSyslogErrorTest.cpp b/Tests/SolidSyslogErrorTest.cpp index 01b86387..2d3ae702 100644 --- a/Tests/SolidSyslogErrorTest.cpp +++ b/Tests/SolidSyslogErrorTest.cpp @@ -6,7 +6,8 @@ #include "SolidSyslogPrival.h" #include "TestUtils.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros static int handlerCallCount; static enum SolidSyslog_Severity capturedSeverity; diff --git a/Tests/SolidSyslogGetAddrInfoResolverTest.cpp b/Tests/SolidSyslogGetAddrInfoResolverTest.cpp index de744b7e..95ea241a 100644 --- a/Tests/SolidSyslogGetAddrInfoResolverTest.cpp +++ b/Tests/SolidSyslogGetAddrInfoResolverTest.cpp @@ -11,7 +11,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros // clang-format off static const char* const TEST_HOST = "127.0.0.1"; diff --git a/Tests/SolidSyslogNullBufferTest.cpp b/Tests/SolidSyslogNullBufferTest.cpp index f56f6c9c..087fd39a 100644 --- a/Tests/SolidSyslogNullBufferTest.cpp +++ b/Tests/SolidSyslogNullBufferTest.cpp @@ -3,7 +3,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros #include "SolidSyslogBuffer.h" #include "SolidSyslogNullBuffer.h" #include "SenderFake.h" diff --git a/Tests/SolidSyslogPosixDatagramTest.cpp b/Tests/SolidSyslogPosixDatagramTest.cpp index 553bb291..a8cfb0b6 100644 --- a/Tests/SolidSyslogPosixDatagramTest.cpp +++ b/Tests/SolidSyslogPosixDatagramTest.cpp @@ -1,7 +1,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros #include "SolidSyslogAddress.h" #include "SolidSyslogDatagram.h" #include "SolidSyslogPosixDatagram.h" diff --git a/Tests/SolidSyslogPosixMessageQueueBufferTest.cpp b/Tests/SolidSyslogPosixMessageQueueBufferTest.cpp index afd8c2e0..6013eab0 100644 --- a/Tests/SolidSyslogPosixMessageQueueBufferTest.cpp +++ b/Tests/SolidSyslogPosixMessageQueueBufferTest.cpp @@ -3,7 +3,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros #include "SolidSyslogBuffer.h" #include "SolidSyslogPosixMessageQueueBuffer.h" #include "SolidSyslog.h" diff --git a/Tests/SolidSyslogPosixTcpStreamTest.cpp b/Tests/SolidSyslogPosixTcpStreamTest.cpp index d8a539da..0ad456d0 100644 --- a/Tests/SolidSyslogPosixTcpStreamTest.cpp +++ b/Tests/SolidSyslogPosixTcpStreamTest.cpp @@ -9,7 +9,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros #include "SolidSyslogAddress.h" #include "SolidSyslogPosixTcpStream.h" #include "SolidSyslogStream.h" @@ -65,7 +66,7 @@ TEST_GROUP(SolidSyslogPosixTcpStream) #define CHECK_SOCKET_CLOSED_ONCE() \ do \ { \ - CALLED_FAKE(SocketFake_Close, ONCE); \ + CALLED_FAKE(SocketFake_Close, ONCE); \ LONGS_EQUAL(SocketFake_SocketFd(), SocketFake_LastClosedFd()); \ } while (0) diff --git a/Tests/SolidSyslogStreamSenderTest.cpp b/Tests/SolidSyslogStreamSenderTest.cpp index ea79a3b2..15344e8b 100644 --- a/Tests/SolidSyslogStreamSenderTest.cpp +++ b/Tests/SolidSyslogStreamSenderTest.cpp @@ -14,7 +14,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros // clang-format off static const char* const TEST_HOST = "127.0.0.1"; diff --git a/Tests/SolidSyslogSwitchingSenderTest.cpp b/Tests/SolidSyslogSwitchingSenderTest.cpp index 1fc928af..a3c6a760 100644 --- a/Tests/SolidSyslogSwitchingSenderTest.cpp +++ b/Tests/SolidSyslogSwitchingSenderTest.cpp @@ -7,7 +7,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros /* Selector return values — named for the inner sender they select, so tests * read as `selectorReturn = INNER_B`. */ diff --git a/Tests/SolidSyslogTest.cpp b/Tests/SolidSyslogTest.cpp index 7398af31..cfa8218b 100644 --- a/Tests/SolidSyslogTest.cpp +++ b/Tests/SolidSyslogTest.cpp @@ -26,7 +26,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros class TEST_SolidSyslogTimestamp_Day0ProducesNilvalue_Test; class TEST_SolidSyslogTimestamp_Day1FormatsAs01_Test; diff --git a/Tests/SolidSyslogTlsStreamTest.cpp b/Tests/SolidSyslogTlsStreamTest.cpp index 8b0318b2..71938b0b 100644 --- a/Tests/SolidSyslogTlsStreamTest.cpp +++ b/Tests/SolidSyslogTlsStreamTest.cpp @@ -13,7 +13,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros class TEST_SolidSyslogTlsStream_ReadReturnsNegativeOneOnHardErrorAndClosesSsl_Test; class TEST_SolidSyslogTlsStream_ReadReturnsNegativeOneOnZeroReturnAndClosesSsl_Test; @@ -129,30 +130,30 @@ TEST_GROUP(SolidSyslogTlsStream) // clang-format on // NOLINTBEGIN(cppcoreguidelines-macro-usage,cppcoreguidelines-avoid-do-while) -#define CHECK_BIO_READ_RETRY_SIGNALLED() \ - do \ - { \ +#define CHECK_BIO_READ_RETRY_SIGNALLED() \ + do \ + { \ CALLED_FAKE(OpenSslFake_BioSetFlags, ONCE); \ } while (0) -#define CHECK_BIO_READ_RETRY_NOT_SIGNALLED() \ - do \ - { \ +#define CHECK_BIO_READ_RETRY_NOT_SIGNALLED() \ + do \ + { \ CALLED_FAKE(OpenSslFake_BioSetFlags, NEVER); \ } while (0) -#define CHECK_BIO_RETRY_FLAGS_CLEARED() \ - do \ - { \ +#define CHECK_BIO_RETRY_FLAGS_CLEARED() \ + do \ + { \ CALLED_FAKE(OpenSslFake_BioClearFlags, ONCE); \ } while (0) -#define CHECK_SSL_SESSION_CLOSED() \ - do \ - { \ +#define CHECK_SSL_SESSION_CLOSED() \ + do \ + { \ CALLED_FAKE(OpenSslFake_Shutdown, ONCE); \ CALLED_FAKE(OpenSslFake_Free, ONCE); \ } while (0) -#define CHECK_TRANSPORT_CLOSED_ONCE() \ - do \ - { \ +#define CHECK_TRANSPORT_CLOSED_ONCE() \ + do \ + { \ CALLED_FAKE_ON(StreamFake_Close, transport, ONCE); \ } while (0) diff --git a/Tests/SolidSyslogUdpSenderTest.cpp b/Tests/SolidSyslogUdpSenderTest.cpp index d320ef5e..3de392db 100644 --- a/Tests/SolidSyslogUdpSenderTest.cpp +++ b/Tests/SolidSyslogUdpSenderTest.cpp @@ -16,7 +16,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros // clang-format off static const char* const TEST_MESSAGE = "hello"; diff --git a/Tests/SolidSyslogWinsockDatagramTest.cpp b/Tests/SolidSyslogWinsockDatagramTest.cpp index 0ecbed6b..c05776ec 100644 --- a/Tests/SolidSyslogWinsockDatagramTest.cpp +++ b/Tests/SolidSyslogWinsockDatagramTest.cpp @@ -1,7 +1,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros #include "SolidSyslogAddress.h" #include "SolidSyslogDatagram.h" #include "SolidSyslogUdpPayload.h" diff --git a/Tests/SolidSyslogWinsockResolverTest.cpp b/Tests/SolidSyslogWinsockResolverTest.cpp index 6e05abf5..863ad0a7 100644 --- a/Tests/SolidSyslogWinsockResolverTest.cpp +++ b/Tests/SolidSyslogWinsockResolverTest.cpp @@ -1,7 +1,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros #include "SolidSyslogAddress.h" #include "SolidSyslogResolver.h" #include "SolidSyslogWinsockResolver.h" diff --git a/Tests/SolidSyslogWinsockTcpStreamTest.cpp b/Tests/SolidSyslogWinsockTcpStreamTest.cpp index fc2b5b4d..f46e3072 100644 --- a/Tests/SolidSyslogWinsockTcpStreamTest.cpp +++ b/Tests/SolidSyslogWinsockTcpStreamTest.cpp @@ -1,7 +1,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros #include "SolidSyslogAddress.h" #include "SolidSyslogStream.h" #include "SolidSyslogTransport.h" @@ -71,7 +72,7 @@ TEST_GROUP(SolidSyslogWinsockTcpStream) #define CHECK_SOCKET_CLOSED_ONCE() \ do \ { \ - CALLED_FAKE(WinsockFake_Close, ONCE); \ + CALLED_FAKE(WinsockFake_Close, ONCE); \ CHECK(WinsockFake_SocketFd() == WinsockFake_LastClosedFd()); \ } while (0) diff --git a/Tests/StoreFakeTest.cpp b/Tests/StoreFakeTest.cpp index 9afd2e22..543f4b3a 100644 --- a/Tests/StoreFakeTest.cpp +++ b/Tests/StoreFakeTest.cpp @@ -5,7 +5,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros static const char* const TEST_MESSAGE = "hello"; static const size_t TEST_MESSAGE_LEN = 5; diff --git a/Tests/StreamFakeTest.cpp b/Tests/StreamFakeTest.cpp index 85f0cd71..227cd12d 100644 --- a/Tests/StreamFakeTest.cpp +++ b/Tests/StreamFakeTest.cpp @@ -4,7 +4,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros // clang-format off TEST_GROUP(StreamFake) diff --git a/Tests/Support/TestUtils.h b/Tests/Support/TestUtils.h index 111835de..67a2594e 100644 --- a/Tests/Support/TestUtils.h +++ b/Tests/Support/TestUtils.h @@ -42,8 +42,8 @@ enum * -> LONGS_EQUAL(1, SenderFake_SendCallCount(inner)) */ // NOLINTBEGIN(cppcoreguidelines-macro-usage) -- token paste enforces the 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_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)) // NOLINTEND(cppcoreguidelines-macro-usage) diff --git a/Tests/WinsockFakeTest.cpp b/Tests/WinsockFakeTest.cpp index b01027f7..18e3e875 100644 --- a/Tests/WinsockFakeTest.cpp +++ b/Tests/WinsockFakeTest.cpp @@ -1,7 +1,8 @@ #include "TestUtils.h" #include "CppUTest/TestHarness.h" -using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* macros +using namespace CososoTesting; // NOLINT(google-build-using-namespace) -- test-file scope only; brings NEVER/ONCE/TWICE/THRICE into scope for the CALLED_* + // macros #include "WinsockFake.h" #include #include From 28363e04e605b33ca25641457624ab19f3a6a152 Mon Sep 17 00:00:00 2001 From: David Cozens Date: Sun, 10 May 2026 21:44:48 +0100 Subject: [PATCH 10/10] docs: update DEVLOG for S24.02 + E24 rename Co-Authored-By: Claude Opus 4.7 (1M context) --- DEVLOG.md | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/DEVLOG.md b/DEVLOG.md index 10d4f0ff..7abf4a9f 100644 --- a/DEVLOG.md +++ b/DEVLOG.md @@ -5334,3 +5334,116 @@ NULL-callback / IP-stack-introspection paths were already in place. -o -name '*.h'` which is the canonical safe form; restrict the glob explicitly when batch-formatting, never trust extension filtering inside the tool. + +## 2026-05-10 — S24.02 CALLED_* test macro sweep + E24 rename + +### Summary + +Test-hygiene chore deferred from S12.18: every call-count assertion +across the test base now uses one of three intent-named macros backed +by a `CallCount` token-paste rule. `Tests/Support/TestUtils.h` +hosts the macros; the enum stays in `CososoTesting` to ringfence the +NEVER/ONCE/TWICE/THRICE identifiers. + +```c +CALLED_FUNCTION(handler, ONCE) // local static int counter +CALLED_FAKE(SocketFake_Send, TWICE) // global-state fake getter +CALLED_FAKE_ON(SenderFake_Send, inner, ONCE) // instance-parameter getter +``` + +Three pre-existing implementations folded into the new design: + +- `CHECK_HANDLER_INVOKED_ONCE` / `CHECK_HANDLER_NOT_INVOKED` in + `SolidSyslogErrorTest.cpp` (tiny, hard-coded to one variable). +- The single expression-form `CALLED_FUNCTION(f, n)` already in + `Tests/TestUtils.h` and used by `SolidSyslogSwitchingSenderTest.cpp` + (every call site there was structurally a `CALLED_FAKE_ON` after the + SenderFake `*Count` → `*CallCount` rename). +- The bool flags `storeFullCallbackInvoked` / + `computeIntegrityCalled` / `verifyIntegrityCalled` in + `SolidSyslogBlockStoreTest.cpp` converted to int counters, so tests + now also catch unexpected double-fires. + +Final per-file shape: every test executable (`SolidSyslogTests`, +`ExampleTests`, `SolidSyslogFreeRtosDatagramTest`, `CmsdkUartTest`, +`SolidSyslogFreeRtosSysUpTimeTest`, `SolidSyslogFreeRtosStaticResolverTest`, +plus the Winsock variants compiled in CI only) opts in via +`#include "TestUtils.h"` + `using namespace CososoTesting;`. 1088 host +tests + 50 FreeRtos host tests green; coverage 100% lines/functions +unchanged. + +### Decisions + +- **E24 renamed from "Hardening" to "Code Hygiene".** The epic body + was already written for cross-cutting non-functional sweeps; only + the title was wrong. Robustness-style "hardening" work lives in + E12 / E25 / E26 and didn't need its own home. S24.01 (IWYU) and + S24.02 (this story) both fit the renamed scope cleanly. +- **Reuse `TestUtils.h`, don't add a separate `CallCount.h`.** The + `CososoTesting` namespace + NEVER/ONCE/TWICE/THRICE enum already + lived there to ringfence common identifiers; introducing a parallel + header would have duplicated the enum or risked ODR drift. Moved + `TestUtils.h` from `Tests/` to `Tests/Support/` so non-`Tests/`-root + executables (Example, FreeRtos) inherit it through the established + Support include path rather than via implicit-source-dir lookup. +- **Three macros, not one.** A single macro can't both token-paste a + bare name (`fooCallCount`) and accept an arbitrary expression + (`fake.callCount()`) — the existing flexible expression form was + effectively `CALLED_FAKE_ON` with the rename done. Splitting into + CALLED_FUNCTION / CALLED_FAKE / CALLED_FAKE_ON keeps each call-site + declarative about whether it's a local counter, global getter, or + instance getter, and the token paste enforces the naming rule at + compile time. +- **Counter rename rule: `CallCount`.** Functions keep + their existing names; counters are derived. This preferred renaming + the variable (`getPortCallCount` → `SpyGetPortCallCount`, + `storeFullCallbackCount` → `CountStoreFullInvocationsCallCount`) + over renaming the function. Verbose in a couple of places but + consistent — and `CALLED_FUNCTION(, ONCE)` reads the same + way regardless of how long the function name is. +- **Bool → int even where the test only cared "was it called".** + Cheap upgrade in test power: a future double-fire bug now fails the + existing assertion rather than slipping through. +- **Skipped a `CountStoreFull/CountThresholdCrossings` rename.** The + function names already encode the intent ("count store-full + invocations"); the variable suffix mirroring is enough. Renaming + the function would have widened the diff for no reader benefit. + +### Deferred + +- **`spy.callCount` struct member in `ExampleInteractiveTest.cpp`.** + Different shape (member of a struct), low payoff to convert. Left + as raw `LONGS_EQUAL`; not a counter source the macro family is + designed to address. Out of scope per the story body. +- **`firstSocketCallCount` snapshot variable in + `SolidSyslogStreamSenderTest.cpp`.** It's a *snapshot* of a fake + getter's value at one point in time, not a counter that increments. + Name happens to end in `CallCount` but it doesn't fit the macro's + contract; left alone (and the assertion that uses it now passes the + expression as `count` to `CALLED_FAKE`, which works because the + macro accepts any integral expression). + +### Open questions + +- None. CI on the PR will exercise the Windows / OpenSSL integration + / BDD jobs that aren't run locally; if the Winsock variants need a + follow-up tweak we'll see it on the PR check run. + +### Process notes + +- Per-file conversion was mechanical sed: literal counts 0/1/2/3 + mapped to NEVER/ONCE/TWICE/THRICE, anything higher (e.g. the + 12-setsockopt-calls site in `SolidSyslogStreamSenderTest`) passed + through as a numeric literal. Order matters in the sed cascade — + function-call-form patterns must run before bare-variable-form + patterns, otherwise the bare-variable regex eats the `CallCount\)` + inside `CallCount()\)`. +- Discovered partway through that `Tests/TestUtils.h` already had a + `CALLED_FUNCTION` macro (different signature) and a `CososoTesting` + namespace. The audit had missed it because the search was for + `*CallCount` patterns and the existing implementation took an + arbitrary expression. Surfaced and re-planned mid-stream rather + than blowing past it. +- Rebased onto main after the S12.18 DEVLOG (#320) squash-merged, and + pruned five `[gone]`-tracking local branches that survived earlier + squash merges.