• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "media/base/gmock_callback_support.h"
6 
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"
11 
12 using testing::ByRef;
13 using testing::MockFunction;
14 
15 namespace media {
16 
17 typedef base::Callback<void(const bool& src, bool* dst)> TestCallback;
18 
SetBool(const bool & src,bool * dst)19 void SetBool(const bool& src, bool* dst) {
20   *dst = src;
21 }
22 
TEST(GmockCallbackSupportTest,IsNullCallback)23 TEST(GmockCallbackSupportTest, IsNullCallback) {
24   MockFunction<void(const TestCallback&)> check;
25   EXPECT_CALL(check, Call(IsNullCallback()));
26   check.Call(TestCallback());
27 }
28 
TEST(GmockCallbackSupportTest,IsNotNullCallback)29 TEST(GmockCallbackSupportTest, IsNotNullCallback) {
30   MockFunction<void(const TestCallback&)> check;
31   EXPECT_CALL(check, Call(IsNotNullCallback()));
32   check.Call(base::Bind(&SetBool));
33 }
34 
TEST(GmockCallbackSupportTest,RunClosure)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);
42 }
43 
TEST(GmockCallbackSupportTest,RunCallback0)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);
51 }
52 
TEST(GmockCallbackSupportTest,RunCallback1)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);
60 }
61 
TEST(GmockCallbackSupportTest,RunCallbackPassByRef)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);
71 }
72 
TEST(GmockCallbackSupportTest,RunCallbackPassByValue)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);
82 }
83 
84 }  // namespace media
85