• 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_proxy.h"
21 #include "ui_service_extension_module_loader.h"
22 #include "js_ui_service_extension_context.cpp"
23 
24 #include "js_runtime_lite.h"
25 #include "mock_ability_token.h"
26 #include "ability_handler.h"
27 #include "ohos_application.h"
28 #include "runtime.h"
29 #include "ui_service_extension_connection_constants.h"
30 
31 using namespace testing::ext;
32 
33 namespace OHOS {
34 namespace AbilityRuntime {
35 class UIServiceProxyTest : 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 UIServiceProxyTest::SetUpTestCase()
46 {}
47 
TearDownTestCase()48 void UIServiceProxyTest::TearDownTestCase()
49 {}
50 
SetUp()51 void UIServiceProxyTest::SetUp()
52 {}
53 
TearDown()54 void UIServiceProxyTest::TearDown()
55 {}
56 
57 class IRemoteObjectMocker : public IRemoteObject {
58 public:
IRemoteObjectMocker()59     IRemoteObjectMocker() : IRemoteObject {u"IRemoteObjectMocker"}
60     {
61     }
62 
~IRemoteObjectMocker()63     ~IRemoteObjectMocker()
64     {
65     }
66 
GetObjectRefCount()67     int32_t GetObjectRefCount()
68     {
69         return 0;
70     }
71 
SendRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)72     int SendRequest(uint32_t code, MessageParcel& data, MessageParcel& reply, MessageOption& option)
73     {
74         return 0;
75     }
76 
IsProxyObject() const77     bool IsProxyObject() const
78     {
79         return true;
80     }
81 
CheckObjectLegality() const82     bool CheckObjectLegality() const
83     {
84         return true;
85     }
86 
AddDeathRecipient(const sptr<DeathRecipient> & recipient)87     bool AddDeathRecipient(const sptr<DeathRecipient>& recipient)
88     {
89         return true;
90     }
91 
RemoveDeathRecipient(const sptr<DeathRecipient> & recipient)92     bool RemoveDeathRecipient(const sptr<DeathRecipient>& recipient)
93     {
94         return true;
95     }
96 
AsInterface()97     sptr<IRemoteBroker> AsInterface()
98     {
99         return nullptr;
100     }
101 
Dump(int fd,const std::vector<std::u16string> & args)102     int Dump(int fd, const std::vector<std::u16string>& args)
103     {
104         return 0;
105     }
106 };
107 
108 /**
109  * @tc.number: SendData_0100
110  * @tc.name: SendData
111  * @tc.desc: SystemAbilityStatusChangeListener SendData
112  */
113 HWTEST_F(UIServiceProxyTest, SendData_0100, TestSize.Level1)
114 {
115     TAG_LOGI(AAFwkTag::TEST, "SendData_0100 start");
116     sptr<IRemoteObject> impl;
117     std::shared_ptr<AAFwk::UIServiceProxy> Info = std::make_shared<AAFwk::UIServiceProxy>(impl);
118     OHOS::AAFwk::WantParams data;
119     sptr<IRemoteObject> hostProxy = nullptr;
120     int32_t res = Info->SendData(hostProxy, 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(UIServiceProxyTest, SendData_0200, TestSize.Level1)
131 {
132     TAG_LOGI(AAFwkTag::TEST, "SendData_0200 start");
133     sptr<IRemoteObject> impl;
134     std::shared_ptr<AAFwk::UIServiceProxy> Info = std::make_shared<AAFwk::UIServiceProxy>(impl);
135     OHOS::AAFwk::WantParams data;
136     sptr<IRemoteObject> hostProxy = new IRemoteObjectMocker();
137     int32_t res = Info->SendData(hostProxy, data);
138     EXPECT_EQ(res, static_cast<int32_t>(AbilityErrorCode::ERROR_CODE_INNER));
139     TAG_LOGI(AAFwkTag::TEST, "SendData_0200 end");
140 }
141 
142 /**
143  * @tc.number: SendData_0300
144  * @tc.name: SendData
145  * @tc.desc: SystemAbilityStatusChangeListener SendData
146  */
147 HWTEST_F(UIServiceProxyTest, SendData_0300, TestSize.Level1)
148 {
149     TAG_LOGI(AAFwkTag::TEST, "SendData_0300 start");
150     sptr<IRemoteObject> impl = new IRemoteObjectMocker();
151     std::shared_ptr<AAFwk::UIServiceProxy> Info = std::make_shared<AAFwk::UIServiceProxy>(impl);
152     OHOS::AAFwk::WantParams data;
153     sptr<IRemoteObject> hostProxy = new IRemoteObjectMocker();
154     int32_t res = Info->SendData(hostProxy, data);
155     EXPECT_EQ(res, ERR_OK);
156     TAG_LOGI(AAFwkTag::TEST, "SendData_0300 end");
157 }
158 
159 } // namespace AbilityRuntime
160 } // namespace OHOS
161