diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2026-11-12 13:53:24 -0600 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2026-11-21 15:28:29 -0600 |
| commit | 17d24c62d8808bd27994886aa753924538f7bcd6 (patch) | |
| tree | ecad4c0e36b898d7b297e9f7159e6fb6be625c2b /Source/UnitTests/Common/SPSCQueueTest.cpp | |
| parent | d393f794742eef5cecb5235527795bee47cc04be (diff) | |
Common/SPSCQueue: Hold an array of values in each linked node to make SPSCQueue of u8 practical.
Diffstat (limited to 'Source/UnitTests/Common/SPSCQueueTest.cpp')
| -rw-r--r-- | Source/UnitTests/Common/SPSCQueueTest.cpp | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/Source/UnitTests/Common/SPSCQueueTest.cpp b/Source/UnitTests/Common/SPSCQueueTest.cpp index ddc57c8d1a..751d43809b 100644 --- a/Source/UnitTests/Common/SPSCQueueTest.cpp +++ b/Source/UnitTests/Common/SPSCQueueTest.cpp @@ -89,3 +89,43 @@ TEST(SPSCQueue, MultiThreaded) queue_ptr.reset(); EXPECT_EQ(sptr.use_count(), 1); } + +TEST(SPSCQueue, MoveOnlyElement) +{ + Common::SPSCQueue<std::unique_ptr<int>> q; + q.Push(std::make_unique<int>(42)); + + EXPECT_EQ(*std::as_const(q).Front(), 42); + + auto x2 = std::move(q.Front()); + EXPECT_EQ(*x2, 42); + q.Pop(); +} + +TEST(SPSCQueue, LargeElement) +{ + Common::SPSCQueue<std::array<u32, 4096>> q; + q.Emplace(); + q.Pop(); +} + +TEST(SPSCQueue, SmallElement) +{ + Common::WaitableSPSCQueue<u8> q; + + constexpr u32 reps = 100000; + + std::jthread pusher{[&] { + for (u32 i = 0; i != reps; ++i) + q.Push(u8(i)); + }}; + + std::jthread popper{[&] { + for (u32 i = 0; i != reps; ++i) + { + q.WaitForData(); + EXPECT_EQ(u8(i), q.Front()); + q.Pop(); + } + }}; +} |
