1 /* 2 * Copyright (c) 2022 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 #include <osal_mem.h> 18 #include <unistd.h> 19 #include "hdf_log.h" 20 #include "hdi/idevmgr_hdi.h" 21 #include "v1_0/ipartition_slot.h" 22 23 using namespace testing; 24 using namespace testing::ext; 25 using namespace OHOS::HDI::Partitionslot::V1_0; 26 using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; 27 28 class StartupPartitionSlotTest : public testing::Test { 29 public: SetUpTestCase()30 static void SetUpTestCase() 31 { 32 auto devmgr = IDeviceManager::Get(); 33 if (devmgr != nullptr) { 34 devmgr->LoadDevice("partition_slot_service"); 35 } else { 36 std::cout << "Get devmgr failed" << std::endl; 37 } 38 } TearDownTestCase()39 static void TearDownTestCase() 40 { 41 auto devmgr = IDeviceManager::Get(); 42 if (devmgr != nullptr) { 43 devmgr->UnloadDevice("partition_slot_service"); 44 } else { 45 std::cout << "Get devmgr failed" << std::endl; 46 } 47 } SetUp()48 void SetUp() {} TearDown()49 void TearDown() {} 50 }; 51 52 /** 53 * @tc.number: StartupPartitionSlotTest_001 54 * @tc.name: testGetCurrentSlotFun001 55 * @tc.desc: NA 56 */ 57 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_001, Function | MediumTest | Level1) { 58 std::cout << "begin get currentslot by service" << std::endl; 59 int numOfSlots = 0; 60 int currentSlot = -1; 61 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 62 ASSERT_TRUE(partitionslot != nullptr); 63 ASSERT_TRUE(partitionslot->GetCurrentSlot(currentSlot, numOfSlots) == 0); 64 } 65 66 /** 67 * @tc.number: StartupPartitionSlotTest_002 68 * @tc.name: testGetSlotSuffixFun001 69 * @tc.desc: NA 70 */ 71 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_002, Function | MediumTest | Level1) { 72 std::cout << "begin get suffix by service" << std::endl; 73 std::string suffix = ""; 74 int slot = 2; 75 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 76 ASSERT_TRUE(partitionslot != nullptr); 77 ASSERT_TRUE(partitionslot->GetSlotSuffix(slot, suffix) == 0); 78 } 79 80 /** 81 * @tc.number: StartupPartitionSlotTest_003 82 * @tc.name: testGetCurrentSlotFun001 83 * @tc.desc: NA 84 */ 85 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_003, Function | MediumTest | Level1) { 86 std::cout << "begin set active slot by service" << std::endl; 87 int numOfSlots = 0; 88 int currentSlot = 0; 89 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 90 ASSERT_TRUE(partitionslot != nullptr); 91 partitionslot->GetCurrentSlot(currentSlot, numOfSlots); 92 ASSERT_TRUE(partitionslot->SetActiveSlot(2) == 0); 93 partitionslot->SetActiveSlot(currentSlot); 94 } 95 96 /** 97 * @tc.number: StartupPartitionSlotTest_004 98 * @tc.name: testSetSlotUnbootableFun001 99 * @tc.desc: NA 100 */ 101 HWTEST_F(StartupPartitionSlotTest, StartupPartitionSlotTest_004, Function | MediumTest | Level1) { 102 std::cout << "begin set unbootable slot by service" << std::endl; 103 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 104 ASSERT_TRUE(partitionslot != nullptr); 105 ASSERT_TRUE(partitionslot->SetSlotUnbootable(2) == 0); 106 } 107