diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2025-04-10 23:50:51 -0500 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2025-04-30 14:31:51 -0500 |
| commit | e8b63fe09047146fa6624f600ded0987035ff98a (patch) | |
| tree | 8864baa9d5531ec9eeb2eaa3c633ac10fe919cfb /Source/UnitTests/Common/WorkQueueThreadTest.cpp | |
| parent | a149b9d62d795ef758f7ea09ea726c6a8bb0e089 (diff) | |
UnitTests: Add tests for WorkQueueThread.
Diffstat (limited to 'Source/UnitTests/Common/WorkQueueThreadTest.cpp')
| -rw-r--r-- | Source/UnitTests/Common/WorkQueueThreadTest.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/Source/UnitTests/Common/WorkQueueThreadTest.cpp b/Source/UnitTests/Common/WorkQueueThreadTest.cpp new file mode 100644 index 0000000000..a4bfc654f2 --- /dev/null +++ b/Source/UnitTests/Common/WorkQueueThreadTest.cpp @@ -0,0 +1,53 @@ +// Copyright 2025 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include <gtest/gtest.h> + +#include "Common/WorkQueueThread.h" + +TEST(WorkQueueThread, Simple) +{ + Common::WorkQueueThreadSP<int> worker; + + constexpr int BIG_VAL = 1000; + + int x = 0; + const auto func = [&](int value) { x = value; }; + + worker.Push(1); + worker.WaitForCompletion(); + // Still zero because it's not running. + EXPECT_EQ(x, 0); + + // Does nothing if not running. + worker.Shutdown(); + + worker.Reset("test worker", func); + worker.WaitForCompletion(); + // Items pushed before Reset are processed. + EXPECT_EQ(x, 1); + + worker.Shutdown(); + worker.Push(0); + worker.WaitForCompletion(); + // Still 1 because it's no longer running. + EXPECT_EQ(x, 1); + + worker.Cancel(); + worker.Reset("test worker", func); + worker.WaitForCompletion(); + // Still 1 because the work was canceled. + EXPECT_EQ(x, 1); + + for (int i = 0; i != BIG_VAL; ++i) + worker.Push(i); + worker.Cancel(); + // Could be any one of the pushed values. + EXPECT_LT(x, BIG_VAL); + GTEST_LOG_(INFO) << "Canceled work after item " << x; + + worker.Push(2); + worker.WaitForCompletion(); + // Still running after cancelation. + EXPECT_EQ(x, 2); +} |
