• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 <memory>
19 #include <thread>
20 #include <vector>
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Security {
27 namespace DslmUnitTest {
DslmRequestCallbackMock()28 DslmRequestCallbackMock::DslmRequestCallbackMock()
29 {
30     std::lock_guard<std::mutex> lock(mutex_);
31     EXPECT_EQ(obj_, nullptr);
32     obj_ = this;
33 }
34 
~DslmRequestCallbackMock()35 DslmRequestCallbackMock::~DslmRequestCallbackMock()
36 {
37     std::lock_guard<std::mutex> lock(mutex_);
38     EXPECT_EQ(obj_, this);
39     obj_ = nullptr;
40 }
41 
MockedCallback(uint32_t owner,uint32_t cookie,uint32_t result,const DslmCallbackInfo * info)42 void DslmRequestCallbackMock::MockedCallback(uint32_t owner, uint32_t cookie, uint32_t result,
43     const DslmCallbackInfo *info)
44 {
45     std::lock_guard<std::mutex> lock(mutex_);
46     if (obj_ != nullptr) {
47         obj_->RequestCallback(cookie, result, info);
48     }
49 }
50 
51 DslmRequestCallback *DslmRequestCallbackMock::obj_ = nullptr;
52 std::mutex DslmRequestCallbackMock::mutex_ {};
53 } // namespace DslmUnitTest
54 } // namespace Security
55 } // namespace OHOS
56