1 /*
2 * Copyright (c) 2021 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 "updaterkits_unittest.h"
17 #include <iostream>
18 #include <unistd.h>
19 #include "securec.h"
20 #include "updaterkits/updaterkits.h"
21
22 using namespace testing::ext;
23 using namespace UpdaterUt;
24 using namespace std;
25
26 namespace UpdaterUt {
27 const std::string MISC_FILE = "/data/updater/misc_ut";
28
SetUpTestCase(void)29 void UpdaterKitsUnitTest::SetUpTestCase(void)
30 {
31 cout << "Updater Unit UpdaterKitsUnitTest Begin!" << endl;
32 }
33
TearDownTestCase(void)34 void UpdaterKitsUnitTest::TearDownTestCase(void)
35 {
36 cout << "Updater Unit UpdaterKitsUnitTest End!" << endl;
37 }
38
39 HWTEST_F(UpdaterKitsUnitTest, updater_kits_test01, TestSize.Level1)
40 {
41 const std::vector<std::string> packageName1 = {""};
42 bool ret = RebootAndInstallUpgradePackage(MISC_FILE, packageName1);
43 EXPECT_EQ(ret, false);
44
45 const std::vector<std::string> packageName2 = {"/data/updater/updater/updater_without_updater_binary.zip"};
46 auto fp = std::unique_ptr<FILE, decltype(&fclose)>(fopen(MISC_FILE.c_str(), "wb+"), fclose);
47 EXPECT_NE(fp, nullptr);
48 ret = RebootAndInstallUpgradePackage(MISC_FILE, packageName2);
49 EXPECT_EQ(ret, true);
50 unlink(MISC_FILE.c_str());
51 }
52
53 HWTEST_F(UpdaterKitsUnitTest, updater_kits_test02, TestSize.Level1)
54 {
55 const std::string cmd1 = "";
56 bool ret = RebootAndCleanUserData(MISC_FILE, cmd1);
57 EXPECT_EQ(ret, false);
58
59 const std::string cmd2 = "--user_wipe_data";
60 auto fp = std::unique_ptr<FILE, decltype(&fclose)>(fopen(MISC_FILE.c_str(), "wb+"), fclose);
61 EXPECT_NE(fp, nullptr);
62 ret = RebootAndCleanUserData(MISC_FILE, cmd2);
63 EXPECT_EQ(ret, true);
64 unlink(MISC_FILE.c_str());
65 }
66 } // namespace updater_ut
67