1 /* 2 * Copyright (c) 2024-2024 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 #include <memory> 16 #include <gtest/gtest.h> 17 #include "hap_signer_block_utils.h" 18 #include "sign_block_data.h" 19 20 namespace OHOS { 21 namespace SignatureTools { 22 23 /* 24 * 测试套件,固定写法 25 */ 26 class SignBlockDataTest : public testing::Test { 27 public: SetUpTestCase(void)28 static void SetUpTestCase(void) 29 { 30 }; TearDownTestCase()31 static void TearDownTestCase() 32 { 33 }; SetUp()34 void SetUp() 35 { 36 }; TearDown()37 void TearDown() 38 { 39 }; 40 }; 41 42 /** 43 * @tc.name: getBlockHead 44 * @tc.desc: Test get block head for SUCCESS. 45 * @tc.size: MEDIUM 46 * @tc.type: FUNC 47 * @tc.level Level 1 48 * @tc.require: SR000H63TL 49 */ 50 HWTEST_F(SignBlockDataTest, getBlockHead, testing::ext::TestSize.Level1) 51 { 52 std::vector<int8_t> signData(std::vector<int8_t>(32, 0)); 53 std::vector<int8_t> blockHead(std::vector<int8_t>(32, 0)); 54 std::shared_ptr<SignBlockData> api = std::make_shared<SignBlockData>(signData, 3); 55 api->SetBlockHead(blockHead); 56 std::vector<int8_t> head = api->GetBlockHead(); 57 EXPECT_EQ(head.size(), blockHead.size()); 58 } 59 60 /** 61 * @tc.name: getByte 62 * @tc.desc: Test get byte for SUCCESS. 63 * @tc.size: MEDIUM 64 * @tc.type: FUNC 65 * @tc.level Level 1 66 * @tc.require: SR000H63TL 67 */ 68 HWTEST_F(SignBlockDataTest, getByte, testing::ext::TestSize.Level1) 69 { 70 std::vector<int8_t> signData(std::vector<int8_t>(32, 0)); 71 std::shared_ptr<SignBlockData> api = std::make_shared<SignBlockData>(signData, 3); 72 bool byte = api->GetByte(); 73 EXPECT_EQ(byte, true); 74 } 75 76 /** 77 * @tc.name: getLen 78 * @tc.desc: Test get length for SUCCESS. 79 * @tc.size: MEDIUM 80 * @tc.type: FUNC 81 * @tc.level Level 1 82 * @tc.require: SR000H63TL 83 */ 84 HWTEST_F(SignBlockDataTest, getLen, testing::ext::TestSize.Level1) 85 { 86 std::vector<int8_t> signData(std::vector<int8_t>(32, 0)); 87 std::shared_ptr<SignBlockData> api = std::make_shared<SignBlockData>(signData, 3); 88 long len = api->GetLen(); 89 EXPECT_EQ(len, 32); 90 } 91 92 /** 93 * @tc.name: getSignData 94 * @tc.desc: Test get sign data for SUCCESS. 95 * @tc.size: MEDIUM 96 * @tc.type: FUNC 97 * @tc.level Level 1 98 * @tc.require: SR000H63TL 99 */ 100 HWTEST_F(SignBlockDataTest, getSignData, testing::ext::TestSize.Level1) 101 { 102 std::vector<int8_t> signData(std::vector<int8_t>(32, 0)); 103 std::shared_ptr<SignBlockData> api = std::make_shared<SignBlockData>(signData, 3); 104 std::vector<int8_t> retSignData = api->GetSignData(); 105 EXPECT_EQ(retSignData.size(), 32); 106 } 107 108 /** 109 * @tc.name: getSignFile 110 * @tc.desc: Test get sign file for SUCCESS. 111 * @tc.size: MEDIUM 112 * @tc.type: FUNC 113 * @tc.level Level 1 114 * @tc.require: SR000H63TL 115 */ 116 HWTEST_F(SignBlockDataTest, getSignFile, testing::ext::TestSize.Level1) 117 { 118 std::vector<int8_t> signData(std::vector<int8_t>(32, 0)); 119 std::shared_ptr<SignBlockData> api = std::make_shared<SignBlockData>(signData, 3); 120 std::string signFile = api->GetSignFile(); 121 EXPECT_EQ(signFile.size(), 0); 122 } 123 124 /** 125 * @tc.name: getType 126 * @tc.desc: Test get sign type for SUCCESS. 127 * @tc.size: MEDIUM 128 * @tc.type: FUNC 129 * @tc.level Level 1 130 * @tc.require: SR000H63TL 131 */ 132 HWTEST_F(SignBlockDataTest, getType, testing::ext::TestSize.Level1) 133 { 134 std::vector<int8_t> signData(std::vector<int8_t>(32, 0)); 135 std::shared_ptr<SignBlockData> api = std::make_shared<SignBlockData>(signData, 3); 136 char type = api->GetType(); 137 EXPECT_EQ(type, 3); 138 } 139 140 /** 141 * @tc.name: setBlockHead 142 * @tc.desc: Test get data block head for SUCCESS. 143 * @tc.size: MEDIUM 144 * @tc.type: FUNC 145 * @tc.level Level 1 146 * @tc.require: SR000H63TL 147 */ 148 HWTEST_F(SignBlockDataTest, setBlockHead, testing::ext::TestSize.Level1) 149 { 150 std::vector<int8_t> signData(std::vector<int8_t>(32, 0)); 151 std::shared_ptr<SignBlockData> api = std::make_shared<SignBlockData>(signData, 3); 152 api->SetBlockHead(signData); 153 std::vector<int8_t> head = api->GetBlockHead(); 154 EXPECT_EQ(head.size(), signData.size()); 155 } 156 157 /** 158 * @tc.name: GetOptionalBlockIndex 159 * @tc.desc: Test get optional block index for SUCCESS. 160 * @tc.size: MEDIUM 161 * @tc.type: FUNC 162 * @tc.level Level 1 163 * @tc.require: SR000H63TL 164 */ 165 HWTEST_F(SignBlockDataTest, GetOptionalBlockIndex, testing::ext::TestSize.Level1) 166 { 167 std::vector<OptionalBlock> optionBlocks; 168 int32_t type = 0; 169 int index = 0; 170 bool flag = HapSignerBlockUtils::GetOptionalBlockIndex(optionBlocks, type, index); 171 EXPECT_NE(flag, -1); 172 } 173 } // namespace SignatureTools 174 } // namespace OHOS