5#include "flutter/fml/synchronization/sync_switch.h"
9#include "gtest/gtest.h"
13TEST(SyncSwitchTest, Basic) {
15 bool switch_value =
false;
16 sync_switch.
Execute(SyncSwitch::Handlers()
17 .SetIfTrue([&] { switch_value =
true; })
18 .SetIfFalse([&] { switch_value =
false; }));
19 EXPECT_FALSE(switch_value);
21 sync_switch.
Execute(SyncSwitch::Handlers()
22 .SetIfTrue([&] { switch_value =
true; })
23 .SetIfFalse([&] { switch_value =
false; }));
27TEST(SyncSwitchTest, NoopIfUndefined) {
29 bool switch_value =
false;
30 sync_switch.
Execute(SyncSwitch::Handlers());
31 EXPECT_FALSE(switch_value);
34TEST(SyncSwitchTest, SharedLock) {
37 bool switch_value1 =
false;
38 bool switch_value2 =
false;
40 std::thread thread1([&] {
42 SyncSwitch::Handlers()
46 std::thread thread2([&]() {
48 SyncSwitch::Handlers()
49 .SetIfTrue([&] { switch_value2 =
true; })
50 .SetIfFalse([&] { switch_value2 =
false; }));
54 .SetIfFalse([&] { switch_value1 =
false; }));
void Execute(const Handlers &handlers) const
void SetSwitch(bool value)
TEST(SyncSwitchTest, Basic)
#define EXPECT_TRUE(handle)