• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 
18 #include "extension_running_info.h"
19 #include "hilog_wrapper.h"
20 #include "iremote_object.h"
21 #include "want.h"
22 
23 using namespace testing::ext;
24 using OHOS::AppExecFwk::ElementName;
25 
26 namespace OHOS {
27 namespace AAFwk {
28 class AbilityExtensionRunningInfoTest : public testing::Test {
29 public:
30     static void SetUpTestCase();
31     static void TearDownTestCase();
32     void SetUp() override;
33     void TearDown() override;
34 };
35 
SetUpTestCase(void)36 void AbilityExtensionRunningInfoTest::SetUpTestCase(void)
37 {}
38 
TearDownTestCase(void)39 void AbilityExtensionRunningInfoTest::TearDownTestCase(void)
40 {}
41 
SetUp()42 void AbilityExtensionRunningInfoTest::SetUp()
43 {}
44 
TearDown()45 void AbilityExtensionRunningInfoTest::TearDown()
46 {}
47 
48 /**
49  * @tc.name: ReadFromParcel_0100
50  * @tc.desc: basic function test.
51  * @tc.type: FUNC
52  * @tc.require: issueI5TR35
53  */
54 HWTEST_F(AbilityExtensionRunningInfoTest, ReadFromParcel_0100, TestSize.Level1)
55 {
56     HILOG_INFO("ReadFromParcel start");
57 
58     Parcel parcel;
59     ExtensionRunningInfo extensionRunningInfo;
60     bool ret = extensionRunningInfo.ReadFromParcel(parcel);
61     EXPECT_FALSE(ret);
62 
63     HILOG_INFO("ReadFromParcel end");
64 }
65 
66 /**
67  * @tc.name: ReadFromParcel_0200
68  * @tc.desc: basic function test.
69  * @tc.type: FUNC
70  * @tc.require: issueI5TR35
71  */
72 HWTEST_F(AbilityExtensionRunningInfoTest, ReadFromParcel_0200, TestSize.Level1)
73 {
74     HILOG_INFO("ReadFromParcel start");
75 
76     std::string deviceId;
77     std::string bundleName = "ohos.test.bundle";
78     std::string abilityName = "TestAbility";
79     std::string moduleName = "entry";
80     ElementName elementName;
81     elementName.SetDeviceID(deviceId);
82     elementName.SetBundleName(bundleName);
83     elementName.SetAbilityName(abilityName);
84     elementName.SetModuleName(moduleName);
85     Parcel parcel;
86     parcel.WriteParcelable(&elementName);
87 
88     ExtensionRunningInfo extensionRunningInfo;
89     bool ret = extensionRunningInfo.ReadFromParcel(parcel);
90     EXPECT_TRUE(ret);
91 
92     HILOG_INFO("ReadFromParcel end");
93 }
94 
95 /**
96  * @tc.name: Unmarshalling_0100
97  * @tc.desc: basic function test.
98  * @tc.type: FUNC
99  * @tc.require: issueI5TR35
100  */
101 HWTEST_F(AbilityExtensionRunningInfoTest, Unmarshalling_0100, TestSize.Level1)
102 {
103     HILOG_INFO("Unmarshalling start");
104 
105     std::string deviceId;
106     std::string bundleName = "ohos.test.bundle";
107     std::string abilityName = "TestAbility";
108     std::string moduleName = "entry";
109     ElementName elementName;
110     elementName.SetDeviceID(deviceId);
111     elementName.SetBundleName(bundleName);
112     elementName.SetAbilityName(abilityName);
113     elementName.SetModuleName(moduleName);
114     Parcel parcel;
115     parcel.WriteParcelable(&elementName);
116 
117     ExtensionRunningInfo *extensionRunningInfo = ExtensionRunningInfo::Unmarshalling(parcel);
118     EXPECT_NE(extensionRunningInfo, nullptr);
119 
120     HILOG_INFO("Unmarshalling end");
121 }
122 
123 /**
124  * @tc.name: Unmarshalling_0200
125  * @tc.desc: basic function test.
126  * @tc.type: FUNC
127  * @tc.require: issueI5TR35
128  */
129 HWTEST_F(AbilityExtensionRunningInfoTest, Unmarshalling_0200, TestSize.Level1)
130 {
131     HILOG_INFO("Unmarshalling start");
132 
133     Parcel parcel;
134     ExtensionRunningInfo *extensionRunningInfo = ExtensionRunningInfo::Unmarshalling(parcel);
135     EXPECT_EQ(extensionRunningInfo, nullptr);
136 
137     HILOG_INFO("Unmarshalling end");
138 }
139 
140 /**
141  * @tc.name: Marshalling_0100
142  * @tc.desc: basic function test.
143  * @tc.type: FUNC
144  * @tc.require: issueI5TR35
145  */
146 HWTEST_F(AbilityExtensionRunningInfoTest, Marshalling_0100, TestSize.Level1)
147 {
148     HILOG_INFO("Marshalling start");
149 
150     Parcel parcel;
151     ExtensionRunningInfo extensionRunningInfo;
152     bool ret = extensionRunningInfo.Marshalling(parcel);
153     EXPECT_TRUE(ret);
154 
155     HILOG_INFO("Marshalling end");
156 }
157 
158 /**
159  * @tc.name: Marshalling_0200
160  * @tc.desc: basic function test.
161  * @tc.type: FUNC
162  * @tc.require: issueI5TR35
163  */
164 HWTEST_F(AbilityExtensionRunningInfoTest, Marshalling_0200, TestSize.Level1)
165 {
166     HILOG_INFO("Marshalling start");
167 
168     std::string deviceId;
169     std::string bundleName = "ohos.test.bundle";
170     std::string abilityName = "TestAbility";
171     std::string moduleName = "entry";
172     ElementName elementName;
173     elementName.SetDeviceID(deviceId);
174     elementName.SetBundleName(bundleName);
175     elementName.SetAbilityName(abilityName);
176     elementName.SetModuleName(moduleName);
177     Parcel parcel;
178 
179     ExtensionRunningInfo extensionRunningInfo;
180     extensionRunningInfo.ReadFromParcel(parcel);
181     extensionRunningInfo.clientPackage.push_back("client1");
182     extensionRunningInfo.clientPackage.push_back("client2");
183     extensionRunningInfo.clientPackage.push_back("client3");
184 
185     bool ret = extensionRunningInfo.Marshalling(parcel);
186     EXPECT_TRUE(ret);
187 
188     HILOG_INFO("Marshalling end");
189 }
190 } // namespace AAFwk
191 } // namespace OHOS