mirror of
https://github.com/LizardByte/Sunshine.git
synced 2026-12-01 01:29:38 +00:00
refactor: clarify C++ declarations across 13 Sonar rules (#5934)
This commit is contained in:
1 parent
2e4d4f5ac0
commit
a36b9f8a9c
44 files changed
+342
-162
No files matched your search
@@ -15,6 +15,44 @@
|
||||
|
||||
static_assert(!std::is_convertible_v<std::uint32_t, safe::queue_t<int>>);
|
||||
|
||||
/**
|
||||
* @brief Const event inspection observes state transitions without consuming the pending value.
|
||||
*/
|
||||
TEST(ThreadSafeEvent, ConstPeekPreservesPendingValuesAcrossStateChanges) {
|
||||
safe::event_t<int> event;
|
||||
const auto &view = event;
|
||||
EXPECT_FALSE(view.peek());
|
||||
event.raise(42);
|
||||
EXPECT_TRUE(view.peek());
|
||||
EXPECT_TRUE(view.peek());
|
||||
EXPECT_EQ(event.try_pop(), 42);
|
||||
EXPECT_FALSE(view.peek());
|
||||
event.raise(7);
|
||||
event.stop();
|
||||
EXPECT_FALSE(view.peek());
|
||||
event.reset();
|
||||
EXPECT_FALSE(view.peek());
|
||||
event.raise(9);
|
||||
EXPECT_TRUE(view.peek());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Mail cleanup removes an expired post while preserving an active post's owner.
|
||||
*/
|
||||
TEST(ThreadSafeMail, CleanupPreservesLivePostsAndRemovesExpiredPosts) {
|
||||
safe::mail_raw_t mailbox;
|
||||
const auto live = std::make_shared<int>(7);
|
||||
mailbox.id_to_post.try_emplace("live", live);
|
||||
mailbox.id_to_post.try_emplace("expired", std::weak_ptr<void> {});
|
||||
|
||||
mailbox.cleanup();
|
||||
|
||||
EXPECT_EQ(mailbox.id_to_post.size(), 1);
|
||||
EXPECT_EQ(mailbox.id_to_post.at("live").lock(), live);
|
||||
mailbox.cleanup();
|
||||
EXPECT_EQ(mailbox.id_to_post.size(), 1);
|
||||
}
|
||||
|
||||
TEST(ThreadSafeQueue, RejectsNewestItemAtCapacity) {
|
||||
safe::queue_t<int> queue {1, safe::queue_t<int>::overflow_policy_e::reject};
|
||||
|
||||
|
||||
Reference in new issue
Block a user