flutter_flutter/fml/synchronization/semaphore_unittest.cc
Chris Bracken 08dabe9601
Clean up C++ includes (#21127)
Cleans up header order/grouping for consistency: associated header, C/C++ system/standard library headers, library headers, platform-specific #includes.

Adds <cstring> where strlen, memcpy are being used: there are a bunch of places we use them transitively.

Applies linter-required cleanups. Disables linter on one file due to included RapidJson header. See https://github.com/flutter/flutter/issues/65676

This patch does not cover flutter/shell/platform/darwin. There's a separate, slightly more intensive cleanup for those in progress.
2020-09-11 21:18:35 -07:00

29 lines
687 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 "flutter/fml/synchronization/semaphore.h"
#include <thread>
#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());
}