1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 3 */ 4 /* 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 #include <stdio.h> 19 #include "gtest/gtest.h" 20 #include "hota_updater.h" 21 #include "ohos_types.h" 22 23 const int USE_HOS_PKG = 1; 24 const int NOT_HOS_PKG = 0; 25 const int ERR_PAK_FALG = 2; 26 const int DATA_LENGTH = 190; 27 const int DATA_OFFSET = 0; 28 29 using namespace std; 30 using namespace testing::ext; 31 32 class UpdateTest : public testing::Test { 33 protected: SetUpTestCase(void)34 static void SetUpTestCase(void) {} TearDownTestCase(void)35 static void TearDownTestCase(void) {} SetUp()36 virtual void SetUp() {} TearDown()37 virtual void TearDown() {} 38 }; 39 40 /** 41 * @tc.number : SUB_Upgrade_API_0200 42 * @tc.name : Sets the switch for using the default upgrade package format 43 * @tc.desc : [C- SOFTWARE -0200] 44 */ 45 HWTEST_F(UpdateTest, subUpgradeAPI0200, Function | MediumTest | Level1) 46 { 47 unsigned int ret; 48 ret = HotaSetPackageType(USE_HOS_PKG); 49 printf("use package flag = %d\r\n, return = %d\r\n", USE_HOS_PKG, ret); 50 EXPECT_EQ(OHOS_SUCCESS, ret); 51 }; 52 53 /** 54 * @tc.number : SUB_Upgrade_API_0300 55 * @tc.name : Sets the switch for using the non default upgrade package format 56 * @tc.desc : [C- SOFTWARE -0200] 57 */ 58 HWTEST_F(UpdateTest, subUpgradeAPI0300, Function | MediumTest | Level1) 59 { 60 unsigned int ret; 61 ret = HotaSetPackageType(NOT_HOS_PKG); 62 printf("use package flag = %d\r\n, return = %d\r\n", NOT_HOS_PKG, ret); 63 EXPECT_EQ(OHOS_SUCCESS, ret); 64 }; 65 66 /** 67 * @tc.number : SUB_Upgrade_API_0400 68 * @tc.name : Sets the switch for using the default upgrade package format fail 69 * @tc.desc : [C- SOFTWARE -0200] 70 */ 71 HWTEST_F(UpdateTest, subUpgradeAPI0400, Function | MediumTest | Level1) 72 { 73 unsigned int ret; 74 ret = HotaSetPackageType(ERR_PAK_FALG); 75 printf("use package flag = %d, return = %d\r\n", ERR_PAK_FALG, ret); 76 EXPECT_EQ(OHOS_FAILURE, ret); 77 }; 78 79 /** 80 * @tc.number : SUB_Upgrade_API_0500 81 * @tc.name : Obtains the index of the A or B partition to be upgraded 82 * @tc.desc : [C- SOFTWARE -0200] 83 */ 84 HWTEST_F(UpdateTest, subUpgradeAPI0500, Function | MediumTest | Level1) 85 { 86 unsigned int ret; 87 unsigned int index = 0; 88 ret = HotaGetUpdateIndex(&index); 89 printf("index = %d\r\n, get index return = %d\r\n", index, ret); 90 EXPECT_EQ(OHOS_SUCCESS, ret); 91 };