1 /*
2  * Copyright (C) 2023 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 "widget_callback_stub_test.h"
17 
18 #include "iam_ptr.h"
19 #include "mock_widget_callback_service_test.h"
20 #include "user_auth_interface_ipc_interface_code.h"
21 
22 namespace OHOS {
23 namespace UserIam {
24 namespace UserAuth {
25 using namespace testing;
26 using namespace testing::ext;
27 
SetUpTestCase()28 void WidgetCallbackStubTest::SetUpTestCase()
29 {
30 }
31 
TearDownTestCase()32 void WidgetCallbackStubTest::TearDownTestCase()
33 {
34 }
35 
SetUp()36 void WidgetCallbackStubTest::SetUp()
37 {
38 }
39 
TearDown()40 void WidgetCallbackStubTest::TearDown()
41 {
42 }
43 
44 HWTEST_F(WidgetCallbackStubTest, WidgetCallbackStubOnRemoteRequest001, TestSize.Level0)
45 {
46     MessageParcel data;
47     MessageParcel reply;
48     MessageOption option(MessageOption::TF_SYNC);
49     uint32_t code = UserAuthInterfaceCode::USER_AUTH_ON_SEND_COMMAND;
50     EXPECT_TRUE(data.WriteInterfaceToken(WidgetCallbackInterface::GetDescriptor()));
51     auto service = Common::MakeShared<MockWidgetCallbackService>();
52     EXPECT_NE(service, nullptr);
53     EXPECT_CALL(*service, SendCommand(_)).Times(1);
54     EXPECT_EQ(service->OnRemoteRequest(code, data, reply, option), SUCCESS);
55 }
56 
57 HWTEST_F(WidgetCallbackStubTest, WidgetCallbackStubOnRemoteRequest002, TestSize.Level0)
58 {
59     MessageParcel data;
60     MessageParcel reply;
61     MessageOption option(MessageOption::TF_SYNC);
62     uint32_t code = 0;
63     EXPECT_TRUE(data.WriteInterfaceToken(WidgetCallbackInterface::GetDescriptor()));
64     auto service = Common::MakeShared<MockWidgetCallbackService>();
65     EXPECT_NE(service, nullptr);
66     EXPECT_NE(service->OnRemoteRequest(code, data, reply, option), SUCCESS);
67 }
68 } // namespace UserAuth
69 } // namespace UserIam
70 } // namespace OHOS