1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "dslm_request_callback_mock.h"
17 
18 #include <gmock/gmock.h>
19 
20 using namespace testing;
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Security {
25 namespace DslmUnitTest {
DslmRequestCallbackMock()26 DslmRequestCallbackMock::DslmRequestCallbackMock()
27 {
28     std::lock_guard<std::mutex> lock(mutex_);
29     EXPECT_EQ(obj_, nullptr);
30     obj_ = this;
31 }
32 
~DslmRequestCallbackMock()33 DslmRequestCallbackMock::~DslmRequestCallbackMock()
34 {
35     std::lock_guard<std::mutex> lock(mutex_);
36     EXPECT_EQ(obj_, this);
37     obj_ = nullptr;
38 }
39 
MockedCallback(uint32_t owner,uint32_t cookie,uint32_t result,const DslmCallbackInfo * info)40 void DslmRequestCallbackMock::MockedCallback(uint32_t owner, uint32_t cookie, uint32_t result,
41     const DslmCallbackInfo *info)
42 {
43     std::lock_guard<std::mutex> lock(mutex_);
44     if (obj_ != nullptr) {
45         obj_->RequestCallback(cookie, result, info);
46     }
47 }
48 
49 DslmRequestCallback *DslmRequestCallbackMock::obj_ = nullptr;
50 std::mutex DslmRequestCallbackMock::mutex_ {};
51 } // namespace DslmUnitTest
52 } // namespace Security
53 } // namespace OHOS
54