#include "flutter/fml/synchronization/sync_switch.h"
#include <thread>
#include "gtest/gtest.h"
Go to the source code of this file.
|
| TEST (SyncSwitchTest, Basic) |
|
| TEST (SyncSwitchTest, NoopIfUndefined) |
|
| TEST (SyncSwitchTest, SharedLock) |
|
◆ TEST() [1/3]
TEST |
( |
SyncSwitchTest |
, |
|
|
Basic |
|
|
) |
| |
Definition at line 13 of file sync_switch_unittest.cc.
13 {
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; }));
25}
void Execute(const Handlers &handlers) const
void SetSwitch(bool value)
#define EXPECT_TRUE(handle)
◆ TEST() [2/3]
TEST |
( |
SyncSwitchTest |
, |
|
|
NoopIfUndefined |
|
|
) |
| |
Definition at line 27 of file sync_switch_unittest.cc.
27 {
29 bool switch_value = false;
30 sync_switch.
Execute(SyncSwitch::Handlers());
31 EXPECT_FALSE(switch_value);
32}
◆ TEST() [3/3]
TEST |
( |
SyncSwitchTest |
, |
|
|
SharedLock |
|
|
) |
| |
Definition at line 34 of file sync_switch_unittest.cc.
34 {
37 bool switch_value1 = false;
38 bool switch_value2 = false;
39
40 std::thread thread1([&] {
42 SyncSwitch::Handlers()
43 .SetIfTrue([&] {
44 switch_value1 = true;
45
46 std::thread thread2([&]() {
48 SyncSwitch::Handlers()
49 .SetIfTrue([&] { switch_value2 = true; })
50 .SetIfFalse([&] { switch_value2 = false; }));
51 });
52 thread2.join();
53 })
54 .SetIfFalse([&] { switch_value1 = false; }));
55 });
56 thread1.join();
59}