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 "ability_manager_client.h"
17 #include "ui_extension_ability_connection.h"
18
19 #include <future>
20
21 #include "mock_authentication.h"
22 #include "mock_context.h"
23 #include "mock_remote_object.h"
24 #include "mock_resource_node.h"
25 #include "mock_schedule_node.h"
26 #include "user_auth_callback_proxy.h"
27
28 using namespace testing;
29 using namespace testing::ext;
30 namespace OHOS {
31 namespace UserIam {
32 namespace UserAuth {
33 class UIExtensionAbilityConnectionTest : public testing::Test {
34 public:
35 static void SetUpTestCase();
36
37 static void TearDownTestCase();
38
39 void SetUp() override;
40
41 void TearDown() override;
42 };
43
SetUpTestCase()44 void UIExtensionAbilityConnectionTest::SetUpTestCase()
45 {
46 }
47
TearDownTestCase()48 void UIExtensionAbilityConnectionTest::TearDownTestCase()
49 {
50 }
51
SetUp()52 void UIExtensionAbilityConnectionTest::SetUp()
53 {
54 }
55
TearDown()56 void UIExtensionAbilityConnectionTest::TearDown()
57 {
58 }
59
60 HWTEST_F(UIExtensionAbilityConnectionTest, UIExtensionAbilityConnectionTestOnAbilityDisconnectDone, TestSize.Level0)
61 {
62 auto connection = new UIExtensionAbilityConnection("connection");
63 AppExecFwk::ElementName element;
64 int32_t resultCode = 1;
65 connection->OnAbilityDisconnectDone(element, resultCode);
66 EXPECT_NE(connection, nullptr);
67 }
68
69 HWTEST_F(UIExtensionAbilityConnectionTest, UIExtensionAbilityConnectionTestOnAbilityConnectDone, TestSize.Level0)
70 {
71 sptr<MockRemoteObject> obj(new (std::nothrow) MockRemoteObject());
72 uint32_t onAbilityConnectDone = 1;
73 EXPECT_NE(obj, nullptr);
74 EXPECT_CALL(*obj, SendRequest(_, _, _, _))
75 .WillRepeatedly(
__anon54d1b2aa0102(uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) 76 [&onAbilityConnectDone](uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option) {
77 EXPECT_TRUE(reply.WriteInt32(SUCCESS));
78 return GENERAL_ERROR;
79 }
80 );
81 auto connection = new UIExtensionAbilityConnection("connection");
82 AppExecFwk::ElementName element;
83 int32_t resultCode = 0;
84 connection->OnAbilityConnectDone(element, obj, resultCode);
85 EXPECT_NE(connection, nullptr);
86 }
87 } // namespace UserAuth
88 } // namespace UserIam
89 } // namespace OHOS