[Cronet] Delay StartNetLog and StopNetLog until native request context is initialized
[chromium-blink-merge.git] / media / base / gmock_callback_support_unittest.cc
blobfb1beb9870d8de05ecf50dcc44a360b659087a7d
1 // Copyright (c) 2012 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.
5 #include "media/base/gmock_callback_support.h"
7 #include "base/bind.h"
8 #include "base/callback.h"
9 #include "testing/gmock/include/gmock/gmock.h"
10 #include "testing/gtest/include/gtest/gtest.h"
12 using testing::ByRef;
13 using testing::MockFunction;
15 namespace media {
17 typedef base::Callback<void(const bool& src, bool* dst)> TestCallback;
19 void SetBool(const bool& src, bool* dst) {
20 *dst = src;
23 TEST(GmockCallbackSupportTest, IsNullCallback) {
24 MockFunction<void(const TestCallback&)> check;
25 EXPECT_CALL(check, Call(IsNullCallback()));
26 check.Call(TestCallback());
29 TEST(GmockCallbackSupportTest, IsNotNullCallback) {
30 MockFunction<void(const TestCallback&)> check;
31 EXPECT_CALL(check, Call(IsNotNullCallback()));
32 check.Call(base::Bind(&SetBool));
35 TEST(GmockCallbackSupportTest, RunClosure) {
36 MockFunction<void(const base::Closure&)> check;
37 bool dst = false;
38 EXPECT_CALL(check, Call(IsNotNullCallback()))
39 .WillOnce(RunClosure<0>());
40 check.Call(base::Bind(&SetBool, true, &dst));
41 EXPECT_TRUE(dst);
44 TEST(GmockCallbackSupportTest, RunCallback0) {
45 MockFunction<void(const TestCallback&)> check;
46 bool dst = false;
47 EXPECT_CALL(check, Call(IsNotNullCallback()))
48 .WillOnce(RunCallback<0>(true, &dst));
49 check.Call(base::Bind(&SetBool));
50 EXPECT_TRUE(dst);
53 TEST(GmockCallbackSupportTest, RunCallback1) {
54 MockFunction<void(int, const TestCallback&)> check;
55 bool dst = false;
56 EXPECT_CALL(check, Call(0, IsNotNullCallback()))
57 .WillOnce(RunCallback<1>(true, &dst));
58 check.Call(0, base::Bind(&SetBool));
59 EXPECT_TRUE(dst);
62 TEST(GmockCallbackSupportTest, RunCallbackPassByRef) {
63 MockFunction<void(const TestCallback&)> check;
64 bool dst = false;
65 bool src = false;
66 EXPECT_CALL(check, Call(IsNotNullCallback()))
67 .WillOnce(RunCallback<0>(ByRef(src), &dst));
68 src = true;
69 check.Call(base::Bind(&SetBool));
70 EXPECT_TRUE(dst);
73 TEST(GmockCallbackSupportTest, RunCallbackPassByValue) {
74 MockFunction<void(const TestCallback&)> check;
75 bool dst = false;
76 bool src = true;
77 EXPECT_CALL(check, Call(IsNotNullCallback()))
78 .WillOnce(RunCallback<0>(src, &dst));
79 src = false;
80 check.Call(base::Bind(&SetBool));
81 EXPECT_TRUE(dst);
84 } // namespace media