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 "idevmgr_hdi.h" 21 #include "v1_0/ipartition_slot.h" 22 23 namespace OHOS { 24 namespace PartitionSlot { 25 using namespace testing; 26 using namespace testing::ext; 27 using namespace OHOS::HDI::Partitionslot::V1_0; 28 using OHOS::HDI::DeviceManager::V1_0::IDeviceManager; 29 30 class HDFPartitionSlotTest : public testing::Test { 31 public: SetUpTestCase()32 static void SetUpTestCase() 33 { 34 auto devmgr = IDeviceManager::Get(); 35 if (devmgr != nullptr) { 36 devmgr->LoadDevice("partition_slot_service"); 37 } else { 38 std::cout << "Get devmgr failed" << std::endl; 39 } 40 } TearDownTestCase()41 static void TearDownTestCase() 42 { 43 auto devmgr = IDeviceManager::Get(); 44 if (devmgr != nullptr) { 45 devmgr->UnloadDevice("partition_slot_service"); 46 } else { 47 std::cout << "Get devmgr failed" << std::endl; 48 } 49 } SetUp()50 void SetUp() {} TearDown()51 void TearDown() {} 52 }; 53 54 HWTEST_F(HDFPartitionSlotTest, HdfPartitionSlotTest_001, TestSize.Level1) 55 { 56 std::cout << "begin get currentslot by service" << std::endl; 57 int numOfSlots = 0; 58 int currentSlot = -1; 59 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 60 ASSERT_TRUE(partitionslot != nullptr); 61 ASSERT_TRUE(partitionslot->GetCurrentSlot(currentSlot, numOfSlots) == 0); 62 } 63 64 HWTEST_F(HDFPartitionSlotTest, HdfPartitionSlotTest_002, TestSize.Level1) 65 { 66 std::cout << "begin get suffix by service" << std::endl; 67 std::string suffix = ""; 68 int slot = 2; 69 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 70 ASSERT_TRUE(partitionslot != nullptr); 71 ASSERT_TRUE(partitionslot->GetSlotSuffix(slot, suffix) == 0); 72 } 73 74 HWTEST_F(HDFPartitionSlotTest, HdfPartitionSlotTest_003, TestSize.Level1) 75 { 76 std::cout << "begin set active slot by service" << std::endl; 77 int numOfSlots = 0; 78 int currentSlot = 0; 79 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 80 ASSERT_TRUE(partitionslot != nullptr); 81 partitionslot->GetCurrentSlot(currentSlot, numOfSlots); 82 ASSERT_TRUE(partitionslot->SetActiveSlot(2) == 0); 83 partitionslot->SetActiveSlot(currentSlot); 84 } 85 86 HWTEST_F(HDFPartitionSlotTest, HdfPartitionSlotTest_004, TestSize.Level1) 87 { 88 std::cout << "begin set unbootable slot by service" << std::endl; 89 sptr<IPartitionSlot> partitionslot = IPartitionSlot::Get(); 90 ASSERT_TRUE(partitionslot != nullptr); 91 ASSERT_TRUE(partitionslot->SetSlotUnbootable(2) == 0); 92 } 93 } // PartitionSlot 94 } // OHOS 95