1fb299fa2Sopenharmony_ci/* 2fb299fa2Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. 3fb299fa2Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4fb299fa2Sopenharmony_ci * you may not use this file except in compliance with the License. 5fb299fa2Sopenharmony_ci * You may obtain a copy of the License at 6fb299fa2Sopenharmony_ci * 7fb299fa2Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8fb299fa2Sopenharmony_ci * 9fb299fa2Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10fb299fa2Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11fb299fa2Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12fb299fa2Sopenharmony_ci * See the License for the specific language governing permissions and 13fb299fa2Sopenharmony_ci * limitations under the License. 14fb299fa2Sopenharmony_ci */ 15fb299fa2Sopenharmony_ci 16fb299fa2Sopenharmony_ci#include <fcntl.h> 17fb299fa2Sopenharmony_ci#include <gtest/gtest.h> 18fb299fa2Sopenharmony_ci#include <memory> 19fb299fa2Sopenharmony_ci#include <sys/ioctl.h> 20fb299fa2Sopenharmony_ci#include "log/log.h" 21fb299fa2Sopenharmony_ci#include "securec.h" 22fb299fa2Sopenharmony_ci#include "updater/updater_const.h" 23fb299fa2Sopenharmony_ci#include "updater/updater.h" 24fb299fa2Sopenharmony_ci#include "sdcard_update/sdcard_update.h" 25fb299fa2Sopenharmony_ci#include "fs_manager/mount.h" 26fb299fa2Sopenharmony_ci#include "misc_info/misc_info.h" 27fb299fa2Sopenharmony_ci#include "updater_main.h" 28fb299fa2Sopenharmony_ci#include "updater_ui_stub.h" 29fb299fa2Sopenharmony_ci#include "utils.h" 30fb299fa2Sopenharmony_ci 31fb299fa2Sopenharmony_ciusing namespace Updater; 32fb299fa2Sopenharmony_ciusing namespace std; 33fb299fa2Sopenharmony_ciusing namespace testing::ext; 34fb299fa2Sopenharmony_ci 35fb299fa2Sopenharmony_cinamespace { 36fb299fa2Sopenharmony_ciconstexpr uint32_t MAX_ARG_SIZE = 24; 37fb299fa2Sopenharmony_ciclass UpdaterUtilUnitTest : public testing::Test { 38fb299fa2Sopenharmony_cipublic: 39fb299fa2Sopenharmony_ci UpdaterUtilUnitTest() 40fb299fa2Sopenharmony_ci { 41fb299fa2Sopenharmony_ci InitUpdaterLogger("UPDATER", TMP_LOG, TMP_STAGE_LOG, TMP_ERROR_CODE_PATH); 42fb299fa2Sopenharmony_ci } 43fb299fa2Sopenharmony_ci ~UpdaterUtilUnitTest() {} 44fb299fa2Sopenharmony_ci 45fb299fa2Sopenharmony_ci static void SetUpTestCase(void) {} 46fb299fa2Sopenharmony_ci static void TearDownTestCase(void) {} 47fb299fa2Sopenharmony_ci void SetUp() {} 48fb299fa2Sopenharmony_ci void TearDown() {} 49fb299fa2Sopenharmony_ci void TestBody() {} 50fb299fa2Sopenharmony_ci}; 51fb299fa2Sopenharmony_ci 52fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, DeleteUpdaterPath, TestSize.Level1) 53fb299fa2Sopenharmony_ci{ 54fb299fa2Sopenharmony_ci std::string path = "/data/test/test/test"; 55fb299fa2Sopenharmony_ci bool ret = DeleteUpdaterPath(path); 56fb299fa2Sopenharmony_ci EXPECT_EQ(ret, true); 57fb299fa2Sopenharmony_ci 58fb299fa2Sopenharmony_ci path = "/data/test"; 59fb299fa2Sopenharmony_ci ret = DeleteUpdaterPath(path); 60fb299fa2Sopenharmony_ci EXPECT_EQ(ret, true); 61fb299fa2Sopenharmony_ci} 62fb299fa2Sopenharmony_ci 63fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, ClearMisc, TestSize.Level1) 64fb299fa2Sopenharmony_ci{ 65fb299fa2Sopenharmony_ci bool ret = ClearMisc(); 66fb299fa2Sopenharmony_ci EXPECT_EQ(ret, true); 67fb299fa2Sopenharmony_ci} 68fb299fa2Sopenharmony_ci 69fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, IsSDCardExist, TestSize.Level1) 70fb299fa2Sopenharmony_ci{ 71fb299fa2Sopenharmony_ci std::string sdcardStr = ""; 72fb299fa2Sopenharmony_ci bool ret = IsSDCardExist(sdcardStr); 73fb299fa2Sopenharmony_ci EXPECT_EQ(ret, false); 74fb299fa2Sopenharmony_ci} 75fb299fa2Sopenharmony_ci 76fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, IsFlashd, TestSize.Level1) 77fb299fa2Sopenharmony_ci{ 78fb299fa2Sopenharmony_ci EXPECT_EQ(IsFlashd({"boot_updater", "", "boot_flash"}), true); 79fb299fa2Sopenharmony_ci EXPECT_EQ(IsFlashd({"boot_updater", "", ""}), false); 80fb299fa2Sopenharmony_ci} 81fb299fa2Sopenharmony_ci 82fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, IsUpdater, TestSize.Level1) 83fb299fa2Sopenharmony_ci{ 84fb299fa2Sopenharmony_ci EXPECT_EQ(IsUpdater({"boot_updater", "", ""}), true); 85fb299fa2Sopenharmony_ci EXPECT_EQ(IsUpdater({"boot_updater", "", "boot_flash"}), false); 86fb299fa2Sopenharmony_ci EXPECT_EQ(IsUpdater({"boot_updater", "", "xxx"}), true); 87fb299fa2Sopenharmony_ci} 88fb299fa2Sopenharmony_ci 89fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, SelectMode, TestSize.Level1) 90fb299fa2Sopenharmony_ci{ 91fb299fa2Sopenharmony_ci // clear already registered mode 92fb299fa2Sopenharmony_ci GetBootModes().clear(); 93fb299fa2Sopenharmony_ci 94fb299fa2Sopenharmony_ci auto dummyEntry = [] (int argc, char **argv) -> int { return 0; }; 95fb299fa2Sopenharmony_ci // register modes 96fb299fa2Sopenharmony_ci RegisterMode({ IsFlashd, "FLASHD", "", dummyEntry }); 97fb299fa2Sopenharmony_ci RegisterMode({ IsUpdater, "UPDATER", "", dummyEntry }); 98fb299fa2Sopenharmony_ci 99fb299fa2Sopenharmony_ci // test select mode 100fb299fa2Sopenharmony_ci auto mode = SelectMode({"boot_updater", "", ""}); 101fb299fa2Sopenharmony_ci ASSERT_NE(mode, std::nullopt); 102fb299fa2Sopenharmony_ci EXPECT_EQ(mode->modeName, "UPDATER"); 103fb299fa2Sopenharmony_ci 104fb299fa2Sopenharmony_ci mode = SelectMode({"boot_updater", "", "boot_flash"}); 105fb299fa2Sopenharmony_ci ASSERT_NE(mode, std::nullopt); 106fb299fa2Sopenharmony_ci EXPECT_EQ(mode->modeName, "FLASHD"); 107fb299fa2Sopenharmony_ci 108fb299fa2Sopenharmony_ci mode = SelectMode({"invalid_command", "", ""}); 109fb299fa2Sopenharmony_ci EXPECT_EQ(mode, std::nullopt); 110fb299fa2Sopenharmony_ci} 111fb299fa2Sopenharmony_ci 112fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, ParseParams, TestSize.Level1) 113fb299fa2Sopenharmony_ci{ 114fb299fa2Sopenharmony_ci UpdateMessage boot {}; 115fb299fa2Sopenharmony_ci std::string commandMsg = ""; 116fb299fa2Sopenharmony_ci std::string updateMsg = ""; 117fb299fa2Sopenharmony_ci const std::string commandFile = "/data/updater/command"; 118fb299fa2Sopenharmony_ci auto fp = std::unique_ptr<FILE, decltype(&fclose)>(fopen(commandFile.c_str(), "wb"), fclose); 119fb299fa2Sopenharmony_ci EXPECT_NE(fp, nullptr); 120fb299fa2Sopenharmony_ci EXPECT_EQ(strncpy_s(boot.command, sizeof(boot.command) - 1, commandMsg.c_str(), commandMsg.size()), 0); 121fb299fa2Sopenharmony_ci EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update) - 1, updateMsg.c_str(), updateMsg.size()), 0); 122fb299fa2Sopenharmony_ci bool bRet = WriteUpdaterMessage(commandFile, boot); 123fb299fa2Sopenharmony_ci EXPECT_EQ(bRet, true); 124fb299fa2Sopenharmony_ci char **argv = new char*[1]; 125fb299fa2Sopenharmony_ci argv[0] = new char[MAX_ARG_SIZE]; 126fb299fa2Sopenharmony_ci std::string str = "./UpdaterMain"; 127fb299fa2Sopenharmony_ci EXPECT_EQ(strncpy_s(argv[0], MAX_ARG_SIZE, str.c_str(), str.size()), 0); 128fb299fa2Sopenharmony_ci int argc = 1; 129fb299fa2Sopenharmony_ci std::vector<std::string> args = Utils::ParseParams(argc, argv); 130fb299fa2Sopenharmony_ci std::string res = ""; 131fb299fa2Sopenharmony_ci for (auto s : args) { 132fb299fa2Sopenharmony_ci res += s; 133fb299fa2Sopenharmony_ci } 134fb299fa2Sopenharmony_ci EXPECT_EQ("./UpdaterMain", res); 135fb299fa2Sopenharmony_ci 136fb299fa2Sopenharmony_ci commandMsg = "boot_updater"; 137fb299fa2Sopenharmony_ci updateMsg = "--update_package=updater_full.zip"; 138fb299fa2Sopenharmony_ci EXPECT_EQ(strncpy_s(boot.command, sizeof(boot.command) - 1, commandMsg.c_str(), commandMsg.size()), 0); 139fb299fa2Sopenharmony_ci EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update) - 1, updateMsg.c_str(), updateMsg.size()), 0); 140fb299fa2Sopenharmony_ci bRet = WriteUpdaterMessage(commandFile, boot); 141fb299fa2Sopenharmony_ci EXPECT_EQ(bRet, true); 142fb299fa2Sopenharmony_ci 143fb299fa2Sopenharmony_ci args = Utils::ParseParams(argc, argv); 144fb299fa2Sopenharmony_ci res = ""; 145fb299fa2Sopenharmony_ci for (auto s : args) { 146fb299fa2Sopenharmony_ci res += s; 147fb299fa2Sopenharmony_ci } 148fb299fa2Sopenharmony_ci EXPECT_EQ("./UpdaterMain--update_package=updater_full.zip", res); 149fb299fa2Sopenharmony_ci} 150fb299fa2Sopenharmony_ci 151fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, UpdaterMain, TestSize.Level1) 152fb299fa2Sopenharmony_ci{ 153fb299fa2Sopenharmony_ci UpdateMessage boot {}; 154fb299fa2Sopenharmony_ci if (access("/data/updater/", 0)) { 155fb299fa2Sopenharmony_ci int ret = mkdir("/data/updater/", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); 156fb299fa2Sopenharmony_ci ASSERT_EQ(ret, 0); 157fb299fa2Sopenharmony_ci } 158fb299fa2Sopenharmony_ci const std::string commandFile = "/data/updater/command"; 159fb299fa2Sopenharmony_ci auto fp = std::unique_ptr<FILE, decltype(&fclose)>(fopen(commandFile.c_str(), "wb"), fclose); 160fb299fa2Sopenharmony_ci EXPECT_NE(fp, nullptr); 161fb299fa2Sopenharmony_ci const std::string commandMsg = "boot_updater"; 162fb299fa2Sopenharmony_ci const std::string updateMsg = "--update_package=/data/updater/updater/updater_full.zip"; 163fb299fa2Sopenharmony_ci EXPECT_EQ(strncpy_s(boot.command, sizeof(boot.command) - 1, commandMsg.c_str(), commandMsg.size()), 0); 164fb299fa2Sopenharmony_ci EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update) - 1, updateMsg.c_str(), updateMsg.size()), 0); 165fb299fa2Sopenharmony_ci bool bRet = WriteUpdaterMessage(commandFile, boot); 166fb299fa2Sopenharmony_ci EXPECT_EQ(bRet, true); 167fb299fa2Sopenharmony_ci char **argv = new char*[1]; 168fb299fa2Sopenharmony_ci argv[0] = new char[MAX_ARG_SIZE]; 169fb299fa2Sopenharmony_ci EXPECT_EQ(strncpy_s(argv[0], MAX_ARG_SIZE, "./UpdaterMain", MAX_ARG_SIZE), 0); 170fb299fa2Sopenharmony_ci int argc = 1; 171fb299fa2Sopenharmony_ci 172fb299fa2Sopenharmony_ci int ret = UpdaterMain(argc, argv); 173fb299fa2Sopenharmony_ci EXPECT_EQ(ret, 0); 174fb299fa2Sopenharmony_ci PostUpdater(true); 175fb299fa2Sopenharmony_ci delete argv[0]; 176fb299fa2Sopenharmony_ci delete []argv; 177fb299fa2Sopenharmony_ci} 178fb299fa2Sopenharmony_ci 179fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, UpdaterFromSdcardTest, TestSize.Level1) 180fb299fa2Sopenharmony_ci{ 181fb299fa2Sopenharmony_ci UpdateMessage boot {}; 182fb299fa2Sopenharmony_ci if (access("/data/updater/", 0)) { 183fb299fa2Sopenharmony_ci int ret = mkdir("/data/updater/", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); 184fb299fa2Sopenharmony_ci ASSERT_EQ(ret, 0); 185fb299fa2Sopenharmony_ci } 186fb299fa2Sopenharmony_ci const std::string commandFile = "/data/updater/command"; 187fb299fa2Sopenharmony_ci auto fp = std::unique_ptr<FILE, decltype(&fclose)>(fopen(commandFile.c_str(), "wb"), fclose); 188fb299fa2Sopenharmony_ci EXPECT_NE(fp, nullptr); 189fb299fa2Sopenharmony_ci const std::string commandMsg = "boot_updater"; 190fb299fa2Sopenharmony_ci const std::string updateMsg = "--sdcard_update"; 191fb299fa2Sopenharmony_ci EXPECT_EQ(strncpy_s(boot.command, sizeof(boot.command) - 1, commandMsg.c_str(), commandMsg.size()), 0); 192fb299fa2Sopenharmony_ci EXPECT_EQ(strncpy_s(boot.update, sizeof(boot.update) - 1, updateMsg.c_str(), updateMsg.size()), 0); 193fb299fa2Sopenharmony_ci bool bRet = WriteUpdaterMessage(commandFile, boot); 194fb299fa2Sopenharmony_ci EXPECT_EQ(bRet, true); 195fb299fa2Sopenharmony_ci char **argv = new char*[1]; 196fb299fa2Sopenharmony_ci argv[0] = new char[MAX_ARG_SIZE]; 197fb299fa2Sopenharmony_ci EXPECT_EQ(strncpy_s(argv[0], MAX_ARG_SIZE, "./UpdaterMain", MAX_ARG_SIZE), 0); 198fb299fa2Sopenharmony_ci int argc = 1; 199fb299fa2Sopenharmony_ci EXPECT_EQ(UpdaterMain(argc, argv), 0); 200fb299fa2Sopenharmony_ci delete argv[0]; 201fb299fa2Sopenharmony_ci delete []argv; 202fb299fa2Sopenharmony_ci} 203fb299fa2Sopenharmony_ci 204fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, DoInstallUpdaterPackageTest, TestSize.Level1) 205fb299fa2Sopenharmony_ci{ 206fb299fa2Sopenharmony_ci UpdaterParams upParams; 207fb299fa2Sopenharmony_ci upParams.callbackProgress = nullptr; 208fb299fa2Sopenharmony_ci std::vector<std::string> output; 209fb299fa2Sopenharmony_ci EXPECT_EQ(DoInstallUpdaterPackage(nullptr, upParams, HOTA_UPDATE), UPDATE_CORRUPT); 210fb299fa2Sopenharmony_ci upParams.callbackProgress = [] (float value) {}; 211fb299fa2Sopenharmony_ci EXPECT_EQ(DoInstallUpdaterPackage(nullptr, upParams, HOTA_UPDATE), UPDATE_CORRUPT); 212fb299fa2Sopenharmony_ci upParams.retryCount = 0; 213fb299fa2Sopenharmony_ci EXPECT_EQ(DoInstallUpdaterPackage(nullptr, upParams, HOTA_UPDATE), UPDATE_CORRUPT); 214fb299fa2Sopenharmony_ci upParams.retryCount = 1; 215fb299fa2Sopenharmony_ci EXPECT_EQ(DoInstallUpdaterPackage(nullptr, upParams, HOTA_UPDATE), UPDATE_CORRUPT); 216fb299fa2Sopenharmony_ci} 217fb299fa2Sopenharmony_ci 218fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, updater_ExtractUpdaterBinary, TestSize.Level1) 219fb299fa2Sopenharmony_ci{ 220fb299fa2Sopenharmony_ci Hpackage::PkgManager::PkgManagerPtr pkgManager = Hpackage::PkgManager::CreatePackageInstance(); 221fb299fa2Sopenharmony_ci std::string path = "xxx"; 222fb299fa2Sopenharmony_ci int32_t ret = ExtractUpdaterBinary(pkgManager, path, UPDATER_BINARY); 223fb299fa2Sopenharmony_ci EXPECT_EQ(ret, 1); 224fb299fa2Sopenharmony_ci path = "/data/updater/updater/updater_full.zip"; 225fb299fa2Sopenharmony_ci ret = ExtractUpdaterBinary(pkgManager, path, UPDATER_BINARY); 226fb299fa2Sopenharmony_ci Hpackage::PkgManager::ReleasePackageInstance(pkgManager); 227fb299fa2Sopenharmony_ci EXPECT_EQ(ret, 1); 228fb299fa2Sopenharmony_ci} 229fb299fa2Sopenharmony_ci 230fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, updater_IsSpaceCapacitySufficient, TestSize.Level1) 231fb299fa2Sopenharmony_ci{ 232fb299fa2Sopenharmony_ci UpdaterParams upParams {}; 233fb299fa2Sopenharmony_ci UpdaterStatus status = IsSpaceCapacitySufficient(upParams); 234fb299fa2Sopenharmony_ci EXPECT_EQ(status, UPDATE_ERROR); 235fb299fa2Sopenharmony_ci upParams.updatePackage.push_back("/data/updater/updater/updater_full.zip"); 236fb299fa2Sopenharmony_ci status = IsSpaceCapacitySufficient(upParams); 237fb299fa2Sopenharmony_ci EXPECT_EQ(status, UPDATE_SUCCESS); 238fb299fa2Sopenharmony_ci upParams.updatePackage.push_back("xxx"); 239fb299fa2Sopenharmony_ci ProgressSmoothHandler(0, 0); 240fb299fa2Sopenharmony_ci ProgressSmoothHandler(-1, 0); 241fb299fa2Sopenharmony_ci ProgressSmoothHandler(0, 1); 242fb299fa2Sopenharmony_ci status = IsSpaceCapacitySufficient(upParams); 243fb299fa2Sopenharmony_ci EXPECT_EQ(status, UPDATE_ERROR); 244fb299fa2Sopenharmony_ci} 245fb299fa2Sopenharmony_ci 246fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, updater_HandleChildOutput, TestSize.Level1) 247fb299fa2Sopenharmony_ci{ 248fb299fa2Sopenharmony_ci std::string buf = "xxx"; 249fb299fa2Sopenharmony_ci bool retryUpdate = false; 250fb299fa2Sopenharmony_ci UpdaterParams upParams; 251fb299fa2Sopenharmony_ci HandleChildOutput(buf, 0, retryUpdate, upParams); 252fb299fa2Sopenharmony_ci EXPECT_EQ(retryUpdate, false); 253fb299fa2Sopenharmony_ci HandleChildOutput(buf, buf.size(), retryUpdate, upParams); 254fb299fa2Sopenharmony_ci EXPECT_EQ(retryUpdate, false); 255fb299fa2Sopenharmony_ci buf = "write_log:xxx"; 256fb299fa2Sopenharmony_ci HandleChildOutput(buf, buf.size(), retryUpdate, upParams); 257fb299fa2Sopenharmony_ci EXPECT_EQ(retryUpdate, false); 258fb299fa2Sopenharmony_ci buf = "retry_update:xxx"; 259fb299fa2Sopenharmony_ci HandleChildOutput(buf, buf.size(), retryUpdate, upParams); 260fb299fa2Sopenharmony_ci EXPECT_EQ(retryUpdate, true); 261fb299fa2Sopenharmony_ci buf = "ui_log:xxx"; 262fb299fa2Sopenharmony_ci HandleChildOutput(buf, buf.size(), retryUpdate, upParams); 263fb299fa2Sopenharmony_ci EXPECT_EQ(retryUpdate, true); 264fb299fa2Sopenharmony_ci buf = "show_progress:xxx"; 265fb299fa2Sopenharmony_ci HandleChildOutput(buf, buf.size(), retryUpdate, upParams); 266fb299fa2Sopenharmony_ci EXPECT_EQ(retryUpdate, true); 267fb299fa2Sopenharmony_ci buf = "show_progress:xxx:xxx"; 268fb299fa2Sopenharmony_ci HandleChildOutput(buf, buf.size(), retryUpdate, upParams); 269fb299fa2Sopenharmony_ci EXPECT_EQ(retryUpdate, true); 270fb299fa2Sopenharmony_ci buf = "set_progress:xxx"; 271fb299fa2Sopenharmony_ci HandleChildOutput(buf, buf.size(), retryUpdate, upParams); 272fb299fa2Sopenharmony_ci EXPECT_EQ(retryUpdate, true); 273fb299fa2Sopenharmony_ci buf = "xxx:xxx"; 274fb299fa2Sopenharmony_ci HandleChildOutput(buf, buf.size(), retryUpdate, upParams); 275fb299fa2Sopenharmony_ci EXPECT_EQ(retryUpdate, true); 276fb299fa2Sopenharmony_ci} 277fb299fa2Sopenharmony_ci 278fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, InstallUpdaterPackageTest, TestSize.Level1) 279fb299fa2Sopenharmony_ci{ 280fb299fa2Sopenharmony_ci UpdaterParams upParams; 281fb299fa2Sopenharmony_ci upParams.retryCount = 0; 282fb299fa2Sopenharmony_ci upParams.callbackProgress = [] (float value) { UPDATER_UI_INSTANCE.ShowProgress(value); }; 283fb299fa2Sopenharmony_ci upParams.updatePackage.push_back("/data/updater/updater/updater_full.zip"); 284fb299fa2Sopenharmony_ci Hpackage::PkgManager::PkgManagerPtr pkgManager = Hpackage::PkgManager::CreatePackageInstance(); 285fb299fa2Sopenharmony_ci EXPECT_EQ(InstallUpdaterPackage(upParams, pkgManager), UPDATE_ERROR); 286fb299fa2Sopenharmony_ci upParams.updateMode = SDCARD_UPDATE; 287fb299fa2Sopenharmony_ci upParams.retryCount = 1; 288fb299fa2Sopenharmony_ci EXPECT_EQ(InstallUpdaterPackage(upParams, pkgManager), UPDATE_ERROR); 289fb299fa2Sopenharmony_ci} 290fb299fa2Sopenharmony_ci 291fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, DoUpdatePackagesTest, TestSize.Level1) 292fb299fa2Sopenharmony_ci{ 293fb299fa2Sopenharmony_ci UpdaterParams upParams; 294fb299fa2Sopenharmony_ci EXPECT_EQ(DoUpdatePackages(upParams), UPDATE_CORRUPT); 295fb299fa2Sopenharmony_ci upParams.updatePackage.push_back("/data/updater/updater/updater_full.zip"); 296fb299fa2Sopenharmony_ci EXPECT_EQ(DoUpdatePackages(upParams), UPDATE_CORRUPT); 297fb299fa2Sopenharmony_ci upParams.callbackProgress = [] (float value) { UPDATER_UI_INSTANCE.ShowProgress(value); }; 298fb299fa2Sopenharmony_ci upParams.installTime.push_back(std::chrono::duration<double>(0)); 299fb299fa2Sopenharmony_ci EXPECT_EQ(DoUpdatePackages(upParams), UPDATE_ERROR); 300fb299fa2Sopenharmony_ci} 301fb299fa2Sopenharmony_ci 302fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, StartUpdaterEntryTest, TestSize.Level1) 303fb299fa2Sopenharmony_ci{ 304fb299fa2Sopenharmony_ci UpdaterParams upParams; 305fb299fa2Sopenharmony_ci upParams.factoryResetMode = "factory_wipe_data"; 306fb299fa2Sopenharmony_ci EXPECT_EQ(DoUpdatePackages(upParams), UPDATE_CORRUPT); 307fb299fa2Sopenharmony_ci upParams.factoryResetMode = "user_wipe_data"; 308fb299fa2Sopenharmony_ci EXPECT_EQ(DoUpdatePackages(upParams), UPDATE_CORRUPT); 309fb299fa2Sopenharmony_ci upParams.factoryResetMode = "menu_wipe_data"; 310fb299fa2Sopenharmony_ci EXPECT_EQ(DoUpdatePackages(upParams), UPDATE_CORRUPT); 311fb299fa2Sopenharmony_ci upParams.factoryResetMode = ""; 312fb299fa2Sopenharmony_ci EXPECT_EQ(DoUpdatePackages(upParams), UPDATE_CORRUPT); 313fb299fa2Sopenharmony_ci} 314fb299fa2Sopenharmony_ci 315fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, StartUpdaterProcTest, TestSize.Level1) 316fb299fa2Sopenharmony_ci{ 317fb299fa2Sopenharmony_ci Hpackage::PkgManager::PkgManagerPtr pkgManager = Hpackage::PkgManager::CreatePackageInstance(); 318fb299fa2Sopenharmony_ci UpdaterParams upParams; 319fb299fa2Sopenharmony_ci EXPECT_EQ(StartUpdaterProc(nullptr, upParams), UPDATE_CORRUPT); 320fb299fa2Sopenharmony_ci EXPECT_EQ(StartUpdaterProc(pkgManager, upParams), UPDATE_ERROR); 321fb299fa2Sopenharmony_ci} 322fb299fa2Sopenharmony_ci 323fb299fa2Sopenharmony_ciHWTEST_F(UpdaterUtilUnitTest, CheckPathNeedMountSD, TestSize.Level0) 324fb299fa2Sopenharmony_ci{ 325fb299fa2Sopenharmony_ci UpdaterParams upParams; 326fb299fa2Sopenharmony_ci upParams.updatePackage.push_back("/data/updater/updater_full.zip"); 327fb299fa2Sopenharmony_ci EXPECT_EQ(CheckPathNeedMountSD(upParams), false); 328fb299fa2Sopenharmony_ci upParams.updatePackage.clear(); 329fb299fa2Sopenharmony_ci upParams.updatePackage.push_back("/sdcard/updater/updater_full.zip"); 330fb299fa2Sopenharmony_ci EXPECT_EQ(CheckPathNeedMountSD(upParams), true); 331fb299fa2Sopenharmony_ci upParams.updatePackage.clear(); 332fb299fa2Sopenharmony_ci upParams.updatePackage.push_back("/data/sdcard/updater_full.zip"); 333fb299fa2Sopenharmony_ci EXPECT_EQ(CheckPathNeedMountSD(upParams), false); 334fb299fa2Sopenharmony_ci} 335fb299fa2Sopenharmony_ci} 336