Flutter Engine
semaphore_unittest.cc
Go to the documentation of this file.
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/semaphore.h"
6 
7 #include <thread>
8 
9 #include "gtest/gtest.h"
10 
11 TEST(SemaphoreTest, SimpleValidity) {
12  fml::Semaphore sem(100);
13  ASSERT_TRUE(sem.IsValid());
14 }
15 
16 TEST(SemaphoreTest, WaitOnZero) {
17  fml::Semaphore sem(0);
18  ASSERT_FALSE(sem.TryWait());
19 }
20 
21 TEST(SemaphoreTest, WaitOnZeroSignalThenWait) {
22  fml::Semaphore sem(0);
23  ASSERT_FALSE(sem.TryWait());
24  std::thread thread([&sem]() { sem.Signal(); });
25  thread.join();
26  ASSERT_TRUE(sem.TryWait());
27  ASSERT_FALSE(sem.TryWait());
28 }
TEST(SemaphoreTest, SimpleValidity)
bool IsValid() const
Definition: semaphore.cc:153
bool TryWait()
Definition: semaphore.cc:157