mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-14 19:05:46 -04:00
Common: Remove Event
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
add_executable(common-tests
|
||||
bitutils_tests.cpp
|
||||
event_tests.cpp
|
||||
file_system_tests.cpp
|
||||
path_tests.cpp
|
||||
rectangle_tests.cpp
|
||||
|
@ -4,7 +4,6 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\dep\googletest\src\gtest_main.cc" />
|
||||
<ClCompile Include="bitutils_tests.cpp" />
|
||||
<ClCompile Include="event_tests.cpp" />
|
||||
<ClCompile Include="file_system_tests.cpp" />
|
||||
<ClCompile Include="path_tests.cpp" />
|
||||
<ClCompile Include="rectangle_tests.cpp" />
|
||||
|
@ -3,7 +3,6 @@
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\dep\googletest\src\gtest_main.cc" />
|
||||
<ClCompile Include="rectangle_tests.cpp" />
|
||||
<ClCompile Include="event_tests.cpp" />
|
||||
<ClCompile Include="bitutils_tests.cpp" />
|
||||
<ClCompile Include="file_system_tests.cpp" />
|
||||
<ClCompile Include="path_tests.cpp" />
|
||||
|
@ -1,79 +0,0 @@
|
||||
#include "common/event.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
TEST(Event, InitialStateUnsignaled)
|
||||
{
|
||||
Common::Event e;
|
||||
ASSERT_FALSE(e.TryWait(1));
|
||||
}
|
||||
|
||||
TEST(Event, SignalOnSameThread)
|
||||
{
|
||||
Common::Event e;
|
||||
e.Signal();
|
||||
ASSERT_TRUE(e.TryWait(1));
|
||||
}
|
||||
|
||||
TEST(Event, SignalOnSecondThread)
|
||||
{
|
||||
Common::Event e;
|
||||
|
||||
std::thread thr([&e]() { e.Signal(); });
|
||||
e.Wait();
|
||||
thr.join();
|
||||
}
|
||||
|
||||
TEST(Event, SignalOnSecondThreadWithDelay)
|
||||
{
|
||||
Common::Event e;
|
||||
std::atomic_bool fl{false};
|
||||
|
||||
std::thread thr([&e, &fl]() {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||
e.Signal();
|
||||
fl.store(true);
|
||||
});
|
||||
ASSERT_FALSE(fl.load());
|
||||
e.Wait();
|
||||
ASSERT_TRUE(fl.load());
|
||||
thr.join();
|
||||
}
|
||||
|
||||
TEST(Event, ResetAfterSignaling)
|
||||
{
|
||||
Common::Event e;
|
||||
|
||||
e.Signal();
|
||||
e.Reset();
|
||||
|
||||
ASSERT_FALSE(e.TryWait(1));
|
||||
}
|
||||
|
||||
TEST(Event, WaitForMultiple)
|
||||
{
|
||||
Common::Event e1, e2;
|
||||
e1.Signal();
|
||||
e2.Signal();
|
||||
|
||||
Common::Event* events[] = { &e1, &e2 };
|
||||
Common::Event::WaitForMultiple(events, countof(events));
|
||||
}
|
||||
|
||||
TEST(Event, AutoReset)
|
||||
{
|
||||
Common::Event e(true);
|
||||
e.Signal();
|
||||
ASSERT_TRUE(e.TryWait(1));
|
||||
ASSERT_FALSE(e.TryWait(1));
|
||||
}
|
||||
|
||||
TEST(Event, NoAutoReset)
|
||||
{
|
||||
Common::Event e(false);
|
||||
e.Signal();
|
||||
ASSERT_TRUE(e.TryWait(1));
|
||||
ASSERT_TRUE(e.TryWait(1));
|
||||
}
|
Reference in New Issue
Block a user