1 /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3  *     Copyright 2017 Couchbase, Inc
4  *
5  *   Licensed under the Apache License, Version 2.0 (the "License");
6  *   you may not use this file except in compliance with the License.
7  *   You may obtain a copy of the License at
8  *
9  *       http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *   Unless required by applicable law or agreed to in writing, software
12  *   distributed under the License is distributed on an "AS IS" BASIS,
13  *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *   See the License for the specific language governing permissions and
15  *   limitations under the License.
16  */
17 
18 #pragma once
19 
20 #include <gtest/gtest.h>
21 #include <gmock/gmock.h>
22 
23 #include <phosphor/stats_callback.h>
24 
25 class MockStatsCallback : public phosphor::StatsCallback {
26 public:
27     // Giving mockable names, also not overloading
28     // as it makes it easier to add expectations
29     MOCK_CONST_METHOD2(callS, void(gsl_p::cstring_span, gsl_p::cstring_span));
30     MOCK_CONST_METHOD2(callB, void(gsl_p::cstring_span, bool));
31     MOCK_CONST_METHOD2(callU, void(gsl_p::cstring_span, size_t));
32     MOCK_CONST_METHOD2(callI, void(gsl_p::cstring_span, phosphor::ssize_t));
33     MOCK_CONST_METHOD2(callD, void(gsl_p::cstring_span, double));
34 
operator ()(gsl_p::cstring_span key, gsl_p::cstring_span value)35     virtual void operator()(gsl_p::cstring_span key,
36                             gsl_p::cstring_span value) {
37         callS(key, value);
38     }
operator ()(gsl_p::cstring_span key, bool value)39     virtual void operator()(gsl_p::cstring_span key, bool value) {
40         callB(key, value);
41     }
operator ()(gsl_p::cstring_span key, size_t value)42     virtual void operator()(gsl_p::cstring_span key, size_t value) {
43         callU(key, value);
44     }
operator ()(gsl_p::cstring_span key, phosphor::ssize_t value)45     virtual void operator()(gsl_p::cstring_span key, phosphor::ssize_t value) {
46         callI(key, value);
47     }
operator ()(gsl_p::cstring_span key, double value)48     virtual void operator()(gsl_p::cstring_span key, double value) {
49         callD(key, value);
50     }
51 
expectAny()52     void expectAny() {
53         using namespace testing;
54         EXPECT_CALL(*this, callS(_, _)).Times(AnyNumber());
55         EXPECT_CALL(*this, callB(_, _)).Times(AnyNumber());
56         EXPECT_CALL(*this, callU(_, _)).Times(AnyNumber());
57         EXPECT_CALL(*this, callI(_, _)).Times(AnyNumber());
58         EXPECT_CALL(*this, callD(_, _)).Times(AnyNumber());
59     }
60 };
61