• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 #include <gtest/hwext/gtest-multithread.h>
18 #include <gmock/gmock.h>
19 
20 #include "ui_service_host_proxy.h"
21 #include "ui_service_extension_module_loader.h"
22 #include "js_ui_service_extension_context.cpp"
23 
24 #include "mock_ability_token.h"
25 #include "ability_handler.h"
26 #include "ohos_application.h"
27 #include "runtime.h"
28 #include "ui_service_extension_connection_constants.h"
29 #include "ui_service_proxy.h"
30 
31 using namespace testing::ext;
32 
33 namespace OHOS {
34 namespace AbilityRuntime {
35 class UIServiceHostProxyTest : public testing::Test {
36 public:
37     static void SetUpTestCase();
38     static void TearDownTestCase();
39     void SetUp() override;
40     void TearDown() override;
41 
42     std::unique_ptr<Runtime> runtime;
43 };
44 
SetUpTestCase()45 void UIServiceHostProxyTest::SetUpTestCase()
46 {}
47 
TearDownTestCase()48 void UIServiceHostProxyTest::TearDownTestCase()
49 {}
50 
SetUp()51 void UIServiceHostProxyTest::SetUp()
52 {}
53 
TearDown()54 void UIServiceHostProxyTest::TearDown()
55 {}
56 
57 
58 class IRemoteObjectMocker : public IRemoteObject {
59 public:
IRemoteObjectMocker()60     IRemoteObjectMocker() : IRemoteObject {u"IRemoteObjectMocker"}
61     {
62     }
63 
~IRemoteObjectMocker()64     ~IRemoteObjectMocker()
65     {
66     }
67 
GetObjectRefCount()68     int32_t GetObjectRefCount()
69     {
70         return 0;
71     }
72 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)73     int SendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
74     {
75         return 0;
76     }
77 
IsProxyObject() const78     bool IsProxyObject() const
79     {
80         return true;
81     }
82 
CheckObjectLegality() const83     bool CheckObjectLegality() const
84     {
85         return true;
86     }
87 
AddDeathRecipient(const sptr<DeathRecipient> & recipient)88     bool AddDeathRecipient(const sptr<DeathRecipient>& recipient)
89     {
90         return true;
91     }
92 
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)93     bool RemoveDeathRecipient(const sptr<DeathRecipient>& recipient)
94     {
95         return true;
96     }
97 
AsInterface()98     sptr<IRemoteBroker> AsInterface()
99     {
100         return nullptr;
101     }
102 
Dump(int fd,const std::vector<std::u16string> & args)103     int Dump(int fd, const std::vector<std::u16string>& args)
104     {
105         return 0;
106     }
107 };
108 
109 /**
110  * @tc.number: SendData_0100
111  * @tc.name: SendData
112  * @tc.desc: SystemAbilityStatusChangeListener SendData
113  */
114 HWTEST_F(UIServiceHostProxyTest, SendData_0100, TestSize.Level1)
115 {
116     TAG_LOGI(AAFwkTag::TEST, "SendData_0100 start");
117     sptr<IRemoteObject> impl;
118     std::shared_ptr<AAFwk::UIServiceHostProxy> Info = std::make_shared<AAFwk::UIServiceHostProxy>(impl);
119     OHOS::AAFwk::WantParams data;
120     int32_t res = Info->SendData(data);
121     EXPECT_EQ(res, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER));
122     TAG_LOGI(AAFwkTag::TEST, "SendData_0100 end");
123 }
124 
125 /**
126  * @tc.number: SendData_0200
127  * @tc.name: SendData
128  * @tc.desc: SystemAbilityStatusChangeListener SendData
129  */
130 HWTEST_F(UIServiceHostProxyTest, SendData_0200, TestSize.Level1)
131 {
132     TAG_LOGI(AAFwkTag::TEST, "SendData_0200 start");
133     sptr<IRemoteObject> impl = new IRemoteObjectMocker();
134     std::shared_ptr<AAFwk::UIServiceHostProxy> Info = std::make_shared<AAFwk::UIServiceHostProxy>(impl);
135     OHOS::AAFwk::WantParams data;
136     int32_t res = Info->SendData(data);
137     EXPECT_EQ(res, ERR_OK);
138     TAG_LOGI(AAFwkTag::TEST, "SendData_0200 end");
139 }
140 
141 } // namespace AbilityRuntime
142 } // namespace OHOS
143