1 /*
2 * Copyright (c) 2024 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 "sec_comp_stub_mock_test.h"
17
18 #include "sec_comp_dialog_callback.h"
19 #include "sec_comp_enhance_adapter.h"
20 #include "sec_comp_err.h"
21 #include "sec_comp_log.h"
22 #include "sec_comp_click_event_parcel.h"
23 #include "service_test_common.h"
24
25 using namespace testing::ext;
26 using namespace OHOS;
27 using namespace OHOS::Security::SecurityComponent;
28
29 namespace {
30 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {
31 LOG_CORE, SECURITY_DOMAIN_SECURITY_COMPONENT, "SecCompStubMockTest"};
32 }
33
SetUpTestCase()34 void SecCompStubMockTest::SetUpTestCase()
35 {}
36
TearDownTestCase()37 void SecCompStubMockTest::TearDownTestCase()
38 {}
39
SetUp()40 void SecCompStubMockTest::SetUp()
41 {
42 SC_LOG_INFO(LABEL, "setup");
43 if (stub_ != nullptr) {
44 return;
45 }
46
47 stub_ = new (std::nothrow) SecCompStubMock();
48 ASSERT_NE(nullptr, stub_);
49 }
50
TearDown()51 void SecCompStubMockTest::TearDown()
52 {
53 stub_ = nullptr;
54 }
55
56 /**
57 * @tc.name: OnRemoteRequestMock001
58 * @tc.desc: Test on remote request
59 * @tc.type: FUNC
60 * @tc.require:
61 */
62 HWTEST_F(SecCompStubMockTest, OnRemoteRequestMock001, TestSize.Level0)
63 {
64 MessageParcel data;
65 MessageParcel reply;
66 MessageOption option;
67
68 data.WriteInterfaceToken(u"wrong");
69 ASSERT_EQ(ERR_TRANSACTION_FAILED, stub_->OnRemoteRequest(static_cast<uint32_t>(
70 ISecCompServiceIpcCode::COMMAND_REGISTER_SECURITY_COMPONENT), data, reply, option));
71 data.FlushBuffer();
72 reply.FlushBuffer();
73
74 data.WriteInterfaceToken(u"OHOS.Security.SecurityComponent.ISecCompService");
75 ASSERT_EQ(305, stub_->OnRemoteRequest(1000, data, reply, option));
76 }