• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Chromium 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 "base/barrier_closure.h"
6 
7 #include "base/bind.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9 
10 namespace {
11 
Increment(int * count)12 void Increment(int* count) { (*count)++; }
13 
TEST(BarrierClosureTest,RunImmediatelyForZeroClosures)14 TEST(BarrierClosureTest, RunImmediatelyForZeroClosures) {
15   int count = 0;
16   base::Closure doneClosure(base::Bind(&Increment, base::Unretained(&count)));
17 
18   base::Closure barrierClosure = base::BarrierClosure(0, doneClosure);
19   EXPECT_EQ(1, count);
20 }
21 
TEST(BarrierClosureTest,RunAfterNumClosures)22 TEST(BarrierClosureTest, RunAfterNumClosures) {
23   int count = 0;
24   base::Closure doneClosure(base::Bind(&Increment, base::Unretained(&count)));
25 
26   base::Closure barrierClosure = base::BarrierClosure(2, doneClosure);
27   EXPECT_EQ(0, count);
28 
29   barrierClosure.Run();
30   EXPECT_EQ(0, count);
31 
32   barrierClosure.Run();
33   EXPECT_EQ(1, count);
34 }
35 
36 }  // namespace
37