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 16 #include <memory> 17 #include <gtest/gtest.h> 18 #include "sign_info.h" 19 #include "byte_buffer.h" 20 21 namespace OHOS { 22 namespace SignatureTools { 23 24 /* 25 * 测试套件,固定写法 26 */ 27 class SignInfoTest : public testing::Test { 28 public: SetUpTestCase(void)29 static void SetUpTestCase(void) {}; TearDownTestCase()30 static void TearDownTestCase() {}; SetUp()31 void SetUp() {}; TearDown()32 void TearDown() {}; 33 }; 34 35 /** 36 * @tc.name: fromByteArray 37 * @tc.desc: Test function of SignInfoTest::FromByteArray() interface for SUCCESS. 38 * @tc.size: MEDIUM 39 * @tc.type: FUNC 40 * @tc.level Level 1 41 * @tc.require: SR000H63TL 42 */ 43 HWTEST_F(SignInfoTest, fromByteArray, testing::ext::TestSize.Level1) 44 { 45 std::shared_ptr<SignInfo> api = std::make_shared<SignInfo>(); 46 47 std::vector<int8_t> bytes = { 11, -93, 88, 107, -121, 96, 121, 23, -64, -58, -95, 48 -71, -126, 60, 116, 60, 10, 15, -125, 107, 127, -123, 81, 68, 28, -121, -20, 49 -42, -116, -81, -6, 118, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 50 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 51 SignInfo signInfo = api->FromByteArray(bytes); 52 53 EXPECT_NE(signInfo.GetSize(), 0); 54 } 55 56 /** 57 * @tc.name: getDataSize 58 * @tc.desc: Test function of SignInfoTest::GetDataSize() interface for SUCCESS. 59 * @tc.size: MEDIUM 60 * @tc.type: FUNC 61 * @tc.level Level 1 62 * @tc.require: SR000H63TL 63 */ 64 HWTEST_F(SignInfoTest, getDataSize, testing::ext::TestSize.Level1) 65 { 66 std::shared_ptr<SignInfo> api = std::make_shared<SignInfo>(); 67 68 int64_t dataSize = api->GetDataSize(); 69 70 EXPECT_EQ(dataSize, 0); 71 } 72 73 /** 74 * @tc.name: getExtensionByType 75 * @tc.desc: Test function of SignInfoTest::getExtensionByType() interface for nullptr. 76 * @tc.size: MEDIUM 77 * @tc.type: FUNC 78 * @tc.level Level 1 79 * @tc.require: SR000H63TL 80 */ 81 HWTEST_F(SignInfoTest, getExtensionByType, testing::ext::TestSize.Level1) 82 { 83 std::shared_ptr<SignInfo> api = std::make_shared<SignInfo>(); 84 85 int32_t type = 1; 86 Extension* pExtension = api->GetExtensionByType(type); 87 88 EXPECT_EQ(pExtension, nullptr); 89 } 90 91 /** 92 * @tc.name: getExtensionNum 93 * @tc.desc: Test function of SignInfoTest::GetExtensionNum() interface for SUCCESS. 94 * @tc.size: MEDIUM 95 * @tc.type: FUNC 96 * @tc.level Level 1 97 * @tc.require: SR000H63TL 98 */ 99 HWTEST_F(SignInfoTest, getExtensionNum, testing::ext::TestSize.Level1) 100 { 101 std::shared_ptr<SignInfo> api = std::make_shared<SignInfo>(); 102 103 int32_t extensionNum = api->GetExtensionNum(); 104 105 EXPECT_EQ(extensionNum, 0); 106 } 107 108 /** 109 * @tc.name: getSignature 110 * @tc.desc: Test function of SignInfoTest::getSignature() interface for SUCCESS. 111 * @tc.size: MEDIUM 112 * @tc.type: FUNC 113 * @tc.level Level 1 114 * @tc.require: SR000H63TL 115 */ 116 HWTEST_F(SignInfoTest, getSignature, testing::ext::TestSize.Level1) 117 { 118 std::shared_ptr<SignInfo> api = std::make_shared<SignInfo>(); 119 120 std::vector<int8_t> signatureVec = api->GetSignature(); 121 122 EXPECT_EQ(signatureVec.size(), 0); 123 } 124 125 /** 126 * @tc.name: getSize 127 * @tc.desc: Test function of SignInfoTest::GetSize() interface for SUCCESS. 128 * @tc.size: MEDIUM 129 * @tc.type: FUNC 130 * @tc.level Level 1 131 * @tc.require: SR000H63TL 132 */ 133 HWTEST_F(SignInfoTest, getSize, testing::ext::TestSize.Level1) 134 { 135 std::shared_ptr<SignInfo> api = std::make_shared<SignInfo>(); 136 137 int32_t sizeInt = api->GetSize(); 138 139 EXPECT_EQ(sizeInt, 60); 140 } 141 142 /** 143 * @tc.name: parseMerkleTreeExtension 144 * @tc.desc: The data has the wrong extensionType in the SignInfo 145 * @tc.size: MEDIUM 146 * @tc.type: FUNC 147 * @tc.level Level 1 148 * @tc.require: SR000H63TL 149 */ 150 HWTEST_F(SignInfoTest, parseMerkleTreeExtension, testing::ext::TestSize.Level1) 151 { 152 std::shared_ptr<SignInfo> api = std::make_shared<SignInfo>(); 153 154 std::vector<int8_t> bytes = std::vector<int8_t>{ 1, 0, 0, 0, 80, 0, 0, 0, 0, 16, 0, 0, 155 0, 0, 0, 0, 0, 96, 21, 0, 0, 0, 0, 0, 75, 43, 18, -27, 86, 118, 101, 64, -128, -112, 156 84, 68, 4, -107, 110, 92, 33, -118, 113, -65, -79, -103, 40, 59, 82, -90, -87, -115, 157 27, 77, 3, 95, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 158 0, 0, 0, 0, 0, 0, 0, 0, 0 }; 159 ByteBuffer bf((int32_t)bytes.size()); 160 bf.PutData((char*)bytes.data(), bytes.size()); 161 162 std::vector<MerkleTreeExtension*> extensionVec = api->ParseMerkleTreeExtension(&bf, 1); 163 164 EXPECT_EQ(extensionVec.size(), 0); 165 } 166 167 /** 168 * @tc.name: toByteArray 169 * @tc.desc: Test function of SignInfoTest::ToByteArray() interface for SUCCESS. 170 * @tc.size: MEDIUM 171 * @tc.type: FUNC 172 * @tc.level Level 1 173 * @tc.require: SR000H63TL 174 */ 175 HWTEST_F(SignInfoTest, toByteArray, testing::ext::TestSize.Level1) 176 { 177 std::shared_ptr<SignInfo> api = std::make_shared<SignInfo>(); 178 179 std::vector<int8_t> bytes; 180 api->ToByteArray(bytes); 181 182 EXPECT_EQ(bytes.size(), 60); 183 } 184 } // namespace SignatureTools 185 } // namespace OHOS