Flutter Engine
The Flutter Engine
count_down_latch_unittests.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/count_down_latch.h"
6
7#include <chrono>
8#include <thread>
9
10#include "flutter/fml/build_config.h"
11#include "flutter/fml/thread.h"
12#include "flutter/testing/testing.h"
13
14namespace fml {
15
16TEST(CountDownLatchTest, CanWaitOnZero) {
17 CountDownLatch latch(0);
18 latch.Wait();
19}
20
21TEST(CountDownLatchTest, CanWait) {
22 fml::Thread thread("test_thread");
23 const size_t count = 100;
24 size_t current_count = 0;
25 CountDownLatch latch(count);
26 auto decrement_latch_on_thread = [runner = thread.GetTaskRunner(), &latch,
27 &current_count]() {
28 runner->PostTask([&latch, &current_count]() {
29 std::this_thread::sleep_for(std::chrono::microseconds(100));
30 current_count++;
31 latch.CountDown();
32 });
33 };
34 for (size_t i = 0; i < count; ++i) {
35 decrement_latch_on_thread();
36 }
37 latch.Wait();
38 ASSERT_EQ(current_count, count);
39}
40
41} // namespace fml
int count
Definition: FontMgrTest.cpp:50
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition: thread.cc:164
Definition: ascii_trie.cc:9
TEST(MallocMapping, EmptyContructor)