5#include "flutter/testing/testing.h"
36TEST(ThreadTest, CanCreateMutex) {
45TEST(ThreadTest, CanCreateMutexLock) {
53TEST(ThreadTest, CanCreateRWMutex) {
67TEST(ThreadTest, CanCreateRWMutexLock) {
86TEST(StringsTest, CanSPrintF) {
87 ASSERT_EQ(
SPrintF(
"%sx%d",
"Hello", 12),
"Hellox12");
89 ASSERT_EQ(
SPrintF(
"Hello"),
"Hello");
90 ASSERT_EQ(
SPrintF(
"%sx%.2f",
"Hello", 12.122222),
"Hellox12.12");
99TEST(ConditionVariableTest, WaitUntil) {
102 for (
size_t i = 0;
i < 2; ++
i) {
106 std::chrono::high_resolution_clock::now() +
107 std::chrono::milliseconds{10},
109 test.rando_ivar = 12;
119 ASSERT_EQ(
test.rando_ivar, 12u);
122TEST(ConditionVariableTest, WaitFor) {
125 for (
size_t i = 0;
i < 2; ++
i) {
128 test.mutex, std::chrono::milliseconds{10},
130 test.rando_ivar = 12;
140 ASSERT_EQ(
test.rando_ivar, 12u);
143TEST(ConditionVariableTest, WaitForever) {
146 for (
size_t i = 0;
i < 2; ++
i) {
149 test.rando_ivar = 12;
157 ASSERT_EQ(
test.rando_ivar, 12u);
160TEST(ConditionVariableTest, TestsCriticalSectionAfterWaitForUntil) {
161 std::vector<std::thread> threads;
168 std::condition_variable start_cv;
169 std::mutex start_mtx;
171 auto start_predicate = [&
start]() {
return start; };
172 auto thread_main = [&]() {
174 std::unique_lock start_lock(start_mtx);
175 start_cv.wait(start_lock, start_predicate);
179 cv.
WaitFor(mtx, std::chrono::milliseconds{0u}, []() {
return true; });
181 std::this_thread::sleep_for(std::chrono::milliseconds{100u});
187 threads.emplace_back(thread_main);
192 std::scoped_lock start_lock(start_mtx);
195 start_cv.notify_all();
205TEST(ConditionVariableTest, TestsCriticalSectionAfterWait) {
206 std::vector<std::thread> threads;
213 std::condition_variable start_cv;
214 std::mutex start_mtx;
216 auto start_predicate = [&
start]() {
return start; };
217 auto thread_main = [&]() {
219 std::unique_lock start_lock(start_mtx);
220 start_cv.wait(start_lock, start_predicate);
224 cv.
Wait(mtx, []() {
return true; });
226 std::this_thread::sleep_for(std::chrono::milliseconds{100u});
232 threads.emplace_back(thread_main);
237 std::scoped_lock start_lock(start_mtx);
240 start_cv.notify_all();
250TEST(BaseTest, NoExceptionPromiseValue) {
254 ASSERT_EQ(future.get(), 123);
257TEST(BaseTest, NoExceptionPromiseEmpty) {
258 auto wrapper = std::make_shared<NoExceptionPromise<int>>();
259 std::future future = wrapper->get_future();
266TEST(BaseTest, CanUseTypedMasks) {
269 ASSERT_EQ(
static_cast<uint32_t
>(mask), 0u);
275 ASSERT_EQ(
static_cast<uint32_t
>(mask), 1u);
282 ASSERT_EQ(
static_cast<uint32_t
>(mask), 1u);
289 ASSERT_EQ(
static_cast<uint32_t
>(mask), 1u);
303 ASSERT_EQ(
static_cast<uint32_t
>(m1 & m2), 0u);
304 ASSERT_FALSE(m1 & m2);
310 ASSERT_EQ(
static_cast<uint32_t
>(m1 | m2), ((1u << 0u) | (1u << 1u)));
311 ASSERT_TRUE(m1 | m2);
317 ASSERT_EQ(
static_cast<uint32_t
>(m1 ^ m2), ((1u << 0u) ^ (1u << 1u)));
318 ASSERT_TRUE(m1 ^ m2);
323 ASSERT_EQ(
static_cast<uint32_t
>(~m1), (~(1u << 0u)));
433 ASSERT_FALSE(
x ==
m);
446 ASSERT_FALSE(
x >=
m);
skvx::Vec< 2, uint32_t > mask2
A condition variable exactly similar to the one in libcxx with two major differences:
bool WaitFor(Mutex &mutex, const std::chrono::duration< Representation, Period > &duration, const Predicate &should_stop_waiting) IPLR_REQUIRES(mutex)
Atomically unlocks the mutex and waits on the condition variable for a designated duration....
void Wait(Mutex &mutex, const Predicate &should_stop_waiting) IPLR_REQUIRES(mutex)
Atomically unlocks the mutex and waits on the condition variable indefinitely till the predicate dete...
std::future< T > get_future()
void set_value(const T &value)
static constexpr uint64_t kThreadCount
#define FML_ALLOW_UNUSED_LOCAL(x)
TEST(AiksCanvasTest, EmptyCullRect)
std::string SPrintF(const char *format,...)
IMPELLER_ENUM_IS_MASK(MyMaskBits)
uint32_t rando_ivar IPLR_GUARDED_BY(mutex)=0
int a IPLR_GUARDED_BY(mtx)
int a IPLR_GUARDED_BY(mtx)
#define IPLR_REQUIRES(...)