• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "byte_array_utils.h"
18 
19 namespace OHOS {
20 namespace SignatureTools {
21 /*
22 * 测试套件,固定写法
23 */
24 class ByteArrayUtilsTest : public testing::Test {
25 public:
SetUpTestCase(void)26     static void SetUpTestCase(void)
27     {
28     };
TearDownTestCase()29     static void TearDownTestCase()
30     {
31     };
SetUp()32     void SetUp()
33     {
34     };
TearDown()35     void TearDown()
36     {
37     };
38 };
39 
40 /**
41  * @tc.name: InsertIntToByteArray
42  * @tc.desc: insert int number to byte array
43  * @tc.size: MEDIUM
44  * @tc.type: FUNC
45  * @tc.level Level 1
46  * @tc.require: SR000H63TL
47  */
48 HWTEST_F(ByteArrayUtilsTest, InsertIntToByteArray, testing::ext::TestSize.Level1)
49 {
50     std::vector<int8_t> ret = { 49, 48, 48, 48, 0, 48, 0, 1, 0, -120, 0, 6, 0, 0, 0, 0 };
51     int result = ByteArrayUtils::InsertIntToByteArray(ret, 16, 32);
52     EXPECT_EQ(result, -1);
53 }
54 
55 /**
56  * @tc.name: InsertShortToByteArray
57  * @tc.desc: insert short number to byte array
58  * @tc.size: MEDIUM
59  * @tc.type: FUNC
60  * @tc.level Level 1
61  * @tc.require: SR000H63TL
62  */
63 HWTEST_F(ByteArrayUtilsTest, InsertShortToByteArray, testing::ext::TestSize.Level1)
64 {
65     std::vector<int8_t> ret = { 49, 48, 48, 48, 0, 48, 0, 1, 0, -120, 0, 0, 0, 0, 0, 0 };
66     int result = ByteArrayUtils::InsertShortToByteArray(ret, 16, 16, 6);
67     EXPECT_EQ(result, -1);
68 }
69 
70 /**
71  * @tc.name: InsertByteToByteArray
72  * @tc.desc: insert byte data to byte array
73  * @tc.size: MEDIUM
74  * @tc.type: FUNC
75  * @tc.level Level 1
76  * @tc.require: SR000H63TL
77  */
78 HWTEST_F(ByteArrayUtilsTest, InsertByteToByteArray, testing::ext::TestSize.Level1)
79 {
80     std::vector<int8_t> ret = { 49, 48, 48, 48, 0, 48, 0, 1, 0, -120, 0, 6, 0, 0, 0, 32 };
81     std::vector<int8_t> hashValue = { -114, -19, -78, 49, 26, 23, 116, -70, 72, 35,
82 -41, -43, 43, -115, -2, -93, -91, -67, -76, 77,
83 100, -83, -69, -36, -18, 59, -12, -64, -118, 123, 48, -99 };
84     int result = ByteArrayUtils::InsertByteToByteArray(ret, 16, hashValue, 33);
85     EXPECT_EQ(result, -1);
86 }
87 
88 /**
89  * @tc.name: InsertCharToByteArray
90  * @tc.desc: insert charactor to byte array
91  * @tc.size: MEDIUM
92  * @tc.type: FUNC
93  * @tc.level Level 1
94  * @tc.require: SR000H63TL
95  */
96 HWTEST_F(ByteArrayUtilsTest, InsertCharToByteArray, testing::ext::TestSize.Level1)
97 {
98     std::vector<int8_t> ret(48, 0);
99     int result = ByteArrayUtils::InsertCharToByteArray(ret, 45, "1000");
100     EXPECT_EQ(result, -1);
101 }
102 
103 } // namespace SignatureTools
104 } // namespace OHOS