flutter_flutter/fml/synchronization/semaphore_unittest.cc
Chinmay Garde e356dbca2c
Merge flutter/synchronization contents into fml. (#8525)
When flutter/synchronization was first authored, we did not own fml (it was called fxl then). Now we do, so use a single spot for such utilities. The pipeline was meant to be a general purpose utility that was only ever used by the animator (it even has animator specific tracing), so move that to shell instead (where the animator resides).
2019-04-09 19:18:51 -07:00

28 lines
686 B
C++

// 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 <thread>
#include "flutter/fml/synchronization/semaphore.h"
#include "gtest/gtest.h"
TEST(SemaphoreTest, SimpleValidity) {
fml::Semaphore sem(100);
ASSERT_TRUE(sem.IsValid());
}
TEST(SemaphoreTest, WaitOnZero) {
fml::Semaphore sem(0);
ASSERT_FALSE(sem.TryWait());
}
TEST(SemaphoreTest, WaitOnZeroSignalThenWait) {
fml::Semaphore sem(0);
ASSERT_FALSE(sem.TryWait());
std::thread thread([&sem]() { sem.Signal(); });
thread.join();
ASSERT_TRUE(sem.TryWait());
ASSERT_FALSE(sem.TryWait());
}