Index: base/barrier_closure_unittest.cc |
diff --git a/base/barrier_closure_unittest.cc b/base/barrier_closure_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..da381b130e4e16075d22844afae053457a2c841a |
--- /dev/null |
+++ b/base/barrier_closure_unittest.cc |
@@ -0,0 +1,36 @@ |
+// Copyright (c) 2013 The Chromium 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 "base/barrier_closure.h" |
+ |
+#include "base/bind.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace { |
+ |
+void Increment(int* count) { (*count)++; } |
+ |
+TEST(BarrierClosureTest, RunImmediatelyForZeroClosures) { |
+ int count = 0; |
+ base::Closure doneClosure(base::Bind(&Increment, base::Unretained(&count))); |
+ |
+ base::Closure barrierClosure = base::BarrierClosure(0, doneClosure); |
+ EXPECT_EQ(1, count); |
+} |
+ |
+TEST(BarrierClosureTest, RunAfterNumClosures) { |
+ int count = 0; |
+ base::Closure doneClosure(base::Bind(&Increment, base::Unretained(&count))); |
+ |
+ base::Closure barrierClosure = base::BarrierClosure(2, doneClosure); |
+ EXPECT_EQ(0, count); |
+ |
+ barrierClosure.Run(); |
+ EXPECT_EQ(0, count); |
+ |
+ barrierClosure.Run(); |
+ EXPECT_EQ(1, count); |
+} |
+ |
+} // namespace |