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 <thread> 6 7 #include "flutter/fml/synchronization/semaphore.h" 8 #include "gtest/gtest.h" 9 TEST(SemaphoreTest,SimpleValidity)10TEST(SemaphoreTest, SimpleValidity) { 11 fml::Semaphore sem(100); 12 ASSERT_TRUE(sem.IsValid()); 13 } 14 TEST(SemaphoreTest,WaitOnZero)15TEST(SemaphoreTest, WaitOnZero) { 16 fml::Semaphore sem(0); 17 ASSERT_FALSE(sem.TryWait()); 18 } 19 TEST(SemaphoreTest,WaitOnZeroSignalThenWait)20TEST(SemaphoreTest, WaitOnZeroSignalThenWait) { 21 fml::Semaphore sem(0); 22 ASSERT_FALSE(sem.TryWait()); 23 std::thread thread([&sem]() { sem.Signal(); }); 24 thread.join(); 25 ASSERT_TRUE(sem.TryWait()); 26 ASSERT_FALSE(sem.TryWait()); 27 } 28