• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <gtest/gtest.h>
17 
18 #define private public
19 #define protected public
20 #include "app_launch_data.h"
21 #undef private
22 #undef protected
23 
24 using namespace testing;
25 using namespace testing::ext;
26 namespace OHOS {
27 namespace AppExecFwk {
28 namespace {
29     constexpr bool isDebugApp = true;
30     constexpr bool noDebugApp = false;
31 }
32 class AppLaunchDataTest : public testing::Test {
33 public:
34     static void SetUpTestCase();
35     static void TearDownTestCase();
36     void SetUp();
37     void TearDown();
38     sptr<AppLaunchData> launchData_;
39 };
40 
SetUpTestCase()41 void AppLaunchDataTest::SetUpTestCase()
42 {}
43 
TearDownTestCase()44 void AppLaunchDataTest::TearDownTestCase()
45 {}
46 
SetUp()47 void AppLaunchDataTest::SetUp()
48 {
49     launchData_ = new AppLaunchData();
50 }
51 
TearDown()52 void AppLaunchDataTest::TearDown()
53 {}
54 
55 /**
56  * @tc.name: SetDebugApp_0100
57  * @tc.desc: AppLaunchData SetDebugApp, verify if AppLaunchData startup successfully.
58  * @tc.type: FUNC
59  */
60 HWTEST_F(AppLaunchDataTest, SetDebugApp_0100, TestSize.Level1)
61 {
62     EXPECT_NE(launchData_, nullptr);
63     launchData_->SetDebugApp(isDebugApp);
64     EXPECT_EQ(launchData_->debugApp_, isDebugApp);
65     launchData_->SetDebugApp(noDebugApp);
66     EXPECT_EQ(launchData_->debugApp_, noDebugApp);
67 }
68 
69 /**
70  * @tc.name: GetDebugApp_0100
71  * @tc.desc: AppLaunchData GetDebugApp, verify if AppLaunchData startup successfully.
72  * @tc.type: FUNC
73  */
74 HWTEST_F(AppLaunchDataTest, GetDebugApp_0100, TestSize.Level1)
75 {
76     EXPECT_NE(launchData_, nullptr);
77     launchData_->debugApp_ = isDebugApp;
78     EXPECT_EQ(launchData_->GetDebugApp(), isDebugApp);
79     launchData_->debugApp_ = noDebugApp;
80     EXPECT_EQ(launchData_->GetDebugApp(), noDebugApp);
81 }
82 
83 /**
84  * @tc.name: Marshalling_0100
85  * @tc.desc: Verify if launchData marshalls Sequenceable object into Parcel normally.
86  * @tc.type: FUNC
87  */
88 HWTEST_F(AppLaunchDataTest, Marshalling_0100, TestSize.Level1)
89 {
90     EXPECT_NE(launchData_, nullptr);
91     Parcel parcel;
92     int32_t recordId = 0;
93     int32_t uId = 0;
94     int32_t appIndex = 0;
95     launchData_->recordId_ = recordId;
96     launchData_->uId_ = uId;
97     launchData_->appIndex_ = appIndex;
98     launchData_->userTestRecord_ = nullptr;
99     launchData_->debugApp_ = false;
100     launchData_->startupTaskData_ = std::make_shared<StartupTaskData>();
101 
102     EXPECT_TRUE(launchData_->Marshalling(parcel));
103 
104     parcel.ReadParcelable<ApplicationInfo>();
105     parcel.ReadParcelable<Profile>();
106     parcel.ReadParcelable<ProcessInfo>();
107 
108     // respectively: recordId, uId, appIndex, valid_, debugApp_
109     EXPECT_EQ(parcel.ReadInt32(), recordId);
110     EXPECT_EQ(parcel.ReadInt32(), uId);
111     EXPECT_EQ(parcel.ReadInt32(), appIndex);
112     EXPECT_FALSE(parcel.ReadBool());
113     EXPECT_FALSE(parcel.ReadBool());
114     EXPECT_TRUE(launchData_->ReadStartupTaskDataFromParcel(parcel));
115 }
116 
117 /**
118  * @tc.name: ReadFromParcel_0100
119  * @tc.desc: Verify if launchData reads Sequenceable object from Parcel normally.
120  * @tc.type: FUNC
121  */
122 HWTEST_F(AppLaunchDataTest, ReadFromParcel_0100, TestSize.Level1)
123 {
124     EXPECT_NE(launchData_, nullptr);
125     Parcel parcel;
126     sptr<ApplicationInfo> applicationInfo = new ApplicationInfo();
127     sptr<Profile> profile = new Profile();
128     sptr<ProcessInfo> processInfo = new ProcessInfo();
129     int32_t recordId = 0;
130     int32_t uId = 0;
131     int32_t appIndex = 0;
132     bool valid = false;
133     bool isDebug = true;
134 
135     parcel.WriteParcelable(applicationInfo);
136     parcel.WriteParcelable(profile);
137     parcel.WriteParcelable(processInfo);
138     parcel.WriteInt32(recordId);
139     parcel.WriteInt32(uId);
140     parcel.WriteInt32(appIndex);
141     parcel.WriteBool(valid);
142     parcel.WriteBool(isDebug);
143 
144     EXPECT_TRUE(launchData_->ReadFromParcel(parcel));
145     EXPECT_EQ(launchData_->recordId_, recordId);
146     EXPECT_EQ(launchData_->uId_, uId);
147     EXPECT_EQ(launchData_->appIndex_, appIndex);
148     EXPECT_EQ(launchData_->debugApp_, isDebug);
149 }
150 
151 /**
152  * @tc.name: GetAppPreloadMode_0100
153  * @tc.desc: AppLaunchData SetAppPreloadMode, verify if AppLaunchData startup successfully.
154  * @tc.type: FUNC
155  */
156 HWTEST_F(AppLaunchDataTest, GetAppPreloadMode_0100, TestSize.Level1)
157 {
158     EXPECT_NE(launchData_, nullptr);
159     PreloadMode premakeMode = PreloadMode::PRE_MAKE;
160     launchData_->SetAppPreloadMode(premakeMode);
161     EXPECT_EQ(premakeMode, launchData_->GetAppPreloadMode());
162 
163     launchData_->SetAppPreloadMode(PreloadMode::PRELOAD_MODULE);
164     EXPECT_NE(premakeMode, launchData_->GetAppPreloadMode());
165 }
166 } // namespace AppExecFwk
167 } // namespace OHOS
168