blob: 09994496cf9079e91adb9401a4e4f5bde1ac744e [file] [log] [blame]
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "flutter/fml/synchronization/sync_switch.h"
#include "gtest/gtest.h"
using fml::SyncSwitch;
TEST(SyncSwitchTest, Basic) {
SyncSwitch syncSwitch;
bool switchValue = false;
syncSwitch.Execute(SyncSwitch::Handlers()
.SetIfTrue([&] { switchValue = true; })
.SetIfFalse([&] { switchValue = false; }));
EXPECT_FALSE(switchValue);
syncSwitch.SetSwitch(true);
syncSwitch.Execute(SyncSwitch::Handlers()
.SetIfTrue([&] { switchValue = true; })
.SetIfFalse([&] { switchValue = false; }));
EXPECT_TRUE(switchValue);
}
TEST(SyncSwitchTest, NoopIfUndefined) {
SyncSwitch syncSwitch;
bool switchValue = false;
syncSwitch.Execute(SyncSwitch::Handlers());
EXPECT_FALSE(switchValue);
}