1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
---|---|
2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. |
4 | |
5 | #include "flutter/fml/synchronization/sync_switch.h" |
6 | |
7 | #include "gtest/gtest.h" |
8 | |
9 | using fml::SyncSwitch; |
10 | |
11 | TEST(SyncSwitchTest, Basic) { |
12 | SyncSwitch syncSwitch; |
13 | bool switchValue = false; |
14 | syncSwitch.Execute(SyncSwitch::Handlers() |
15 | .SetIfTrue([&] { switchValue = true; }) |
16 | .SetIfFalse([&] { switchValue = false; })); |
17 | EXPECT_FALSE(switchValue); |
18 | syncSwitch.SetSwitch(true); |
19 | syncSwitch.Execute(SyncSwitch::Handlers() |
20 | .SetIfTrue([&] { switchValue = true; }) |
21 | .SetIfFalse([&] { switchValue = false; })); |
22 | EXPECT_TRUE(switchValue); |
23 | } |
24 | |
25 | TEST(SyncSwitchTest, NoopIfUndefined) { |
26 | SyncSwitch syncSwitch; |
27 | bool switchValue = false; |
28 | syncSwitch.Execute(SyncSwitch::Handlers()); |
29 | EXPECT_FALSE(switchValue); |
30 | } |
31 |