• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "test/common/mock_functions.h"
18 
19 #include <map>
20 
21 #include "osi/include/log.h"
22 
_get_func_call_count_map()23 static std::map<std::string, int>& _get_func_call_count_map() {
24   static std::map<std::string, int> mock_function_count_map;
25   return mock_function_count_map;
26 }
27 
get_func_call_count(const char * fn)28 int get_func_call_count(const char* fn) {
29   return _get_func_call_count_map()[fn];
30 }
inc_func_call_count(const char * fn)31 void inc_func_call_count(const char* fn) { _get_func_call_count_map()[fn]++; }
32 
reset_mock_function_count_map()33 void reset_mock_function_count_map() { _get_func_call_count_map().clear(); }
34 
get_func_call_size()35 int get_func_call_size() { return _get_func_call_count_map().size(); }
36 
dump_mock_function_count_map()37 void dump_mock_function_count_map() {
38   LOG_INFO("Mock function count map size:%zu",
39            _get_func_call_count_map().size());
40 
41   for (const auto& it : _get_func_call_count_map()) {
42     LOG_INFO("function:%s: call_count:%d", it.first.c_str(), it.second);
43   }
44 }
45