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 
18 #include "app_preloader.h"
19 #include "hilog_tag_wrapper.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 class AppPreloaderTest : public testing::Test {
27 public:
28     void SetUp();
29     void TearDown();
30 
31 protected:
32     std::shared_ptr<RemoteClientManager> remoteClientManager_ = nullptr;
33 };
34 
SetUp()35 void AppPreloaderTest::SetUp()
36 {
37     remoteClientManager_ = std::make_shared<RemoteClientManager>();
38     auto bundleMgrHelper = std::make_shared<BundleMgrHelper>();
39     remoteClientManager_->SetBundleManagerHelper(bundleMgrHelper);
40 }
41 
TearDown()42 void AppPreloaderTest::TearDown()
43 {}
44 
45 /**
46  * @tc.number: AppPreloaderTest_GeneratePreloadRequest_0100
47  * @tc.desc: Test GeneratePreloadRequest works
48  * @tc.type: FUNC
49  */
50 HWTEST_F(AppPreloaderTest, AppPreloaderTest_GeneratePreloadRequest_0100, TestSize.Level0)
51 {
52     TAG_LOGD(AAFwkTag::TEST, "AppPreloaderTest_GeneratePreloadRequest_0100 start.");
53     auto manager = std::make_shared<AppPreloader>(remoteClientManager_);
54     EXPECT_NE(manager, nullptr);
55 
56     std::string bundleName = "com.acts.preloadtest";
57     int32_t userId = 100;
58     int32_t appIndex = 0;
59     PreloadRequest request;
60     auto ret = manager->GeneratePreloadRequest(bundleName, userId, appIndex, request);
61     EXPECT_EQ(ret, ERR_OK);
62 }
63 
64 /**
65  * @tc.number: AppPreloaderTest_PreCheck_0100
66  * @tc.desc: Test PreCheck works
67  * @tc.type: FUNC
68  */
69 HWTEST_F(AppPreloaderTest, AppPreloaderTest_PreCheck_0100, TestSize.Level0)
70 {
71     TAG_LOGD(AAFwkTag::TEST, "AppPreloaderTest_PreCheck_0100 start.");
72     auto manager = std::make_shared<AppPreloader>(remoteClientManager_);
73     EXPECT_NE(manager, nullptr);
74 
75     std::string bundleName = "com.acts.preloadtest";
76     auto ret = manager->PreCheck(bundleName, PreloadMode::PRE_MAKE);
77     EXPECT_EQ(ret, true);
78 }
79 }  // namespace AppExecFwk
80 }  // namespace OHOS
81