• 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 
16 #include <memory>
17 #include <gtest/gtest.h>
18 #include "signed_file_pos.h"
19 
20 namespace OHOS {
21 namespace SignatureTools {
22 
23 /*
24  * 测试套件,固定写法
25  */
26 class SignedFilePosTest : public testing::Test {
27 public:
SetUpTestCase(void)28     static void SetUpTestCase(void) {};
TearDownTestCase()29     static void TearDownTestCase() {};
SetUp()30     void SetUp() {};
TearDown()31     void TearDown() {};
32 };
33 
34 /**
35  * @tc.name: fromByteArray
36  * @tc.desc: Test function of SignedFilePosTest::FromByteArray() interface for SUCCESS.
37  * @tc.size: MEDIUM
38  * @tc.type: FUNC
39  * @tc.level Level 1
40  * @tc.require: SR000H63TL
41  */
42 HWTEST_F(SignedFilePosTest, fromByteArray, testing::ext::TestSize.Level1)
43 {
44     std::shared_ptr<SignedFilePos> api = std::make_shared<SignedFilePos>(108, 31, 280, 2068);
45 
46     std::vector<int8_t> bytes = { 11, -93, 88, 107, -121, 96, 121, 23, -64, -58, -95, -71,
47         -126, 60, 116, 60, 10, 15, -125, 107, 127, -123, 81, 68, 28, -121, -20, -42, -116,
48         -81, -6, 118, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
49         0, 0, 0, 0, 0, 0, 0, 0, 0 };
50     SignedFilePos pos = api->FromByteArray(bytes);
51 
52     EXPECT_NE(pos.GetFileNameOffset(), 0);
53 }
54 
55 /**
56  * @tc.name: getFileNameOffset
57  * @tc.desc: Test function of SignedFilePosTest::GetFileNameOffset() interface for SUCCESS.
58  * @tc.size: MEDIUM
59  * @tc.type: FUNC
60  * @tc.level Level 1
61  * @tc.require: SR000H63TL
62  */
63 HWTEST_F(SignedFilePosTest, getFileNameOffset, testing::ext::TestSize.Level1)
64 {
65     std::shared_ptr<SignedFilePos> api = std::make_shared<SignedFilePos>(108, 31, 280, 2068);
66 
67     int32_t offset = api->GetFileNameOffset();
68 
69     EXPECT_EQ(offset, 108);
70 }
71 
72 /**
73  * @tc.name: getFileNameSize
74  * @tc.desc: Test function of SignedFilePosTest::GetFileNameSize() interface for SUCCESS.
75  * @tc.size: MEDIUM
76  * @tc.type: FUNC
77  * @tc.level Level 1
78  * @tc.require: SR000H63TL
79  */
80 HWTEST_F(SignedFilePosTest, getFileNameSize, testing::ext::TestSize.Level1)
81 {
82     std::shared_ptr<SignedFilePos> api = std::make_shared<SignedFilePos>(108, 31, 280, 2068);
83 
84     int32_t fileNameSize = api->GetFileNameSize();
85 
86     EXPECT_EQ(fileNameSize, 31);
87 }
88 
89 /**
90  * @tc.name: getSignInfoOffset
91  * @tc.desc: Test function of SignedFilePosTest::GetSignInfoOffset() interface for SUCCESS.
92  * @tc.size: MEDIUM
93  * @tc.type: FUNC
94  * @tc.level Level 1
95  * @tc.require: SR000H63TL
96  */
97 HWTEST_F(SignedFilePosTest, getSignInfoOffset, testing::ext::TestSize.Level1)
98 {
99     std::shared_ptr<SignedFilePos> api = std::make_shared<SignedFilePos>(108, 31, 280, 2068);
100 
101     int32_t signInfoOffset = api->GetSignInfoOffset();
102 
103     EXPECT_EQ(signInfoOffset, 280);
104 }
105 
106 /**
107  * @tc.name: getSignInfoSize
108  * @tc.desc: Test function of SignedFilePosTest::GetSignInfoSize() interface for SUCCESS.
109  * @tc.size: MEDIUM
110  * @tc.type: FUNC
111  * @tc.level Level 1
112  * @tc.require: SR000H63TL
113  */
114 HWTEST_F(SignedFilePosTest, getSignInfoSize, testing::ext::TestSize.Level1)
115 {
116     std::shared_ptr<SignedFilePos> api = std::make_shared<SignedFilePos>(108, 31, 280, 2068);
117 
118     int32_t signInfoSize = api->GetSignInfoSize();
119 
120     EXPECT_EQ(signInfoSize, 2068);
121 }
122 
123 /**
124  * @tc.name: increaseFileNameOffset
125  * @tc.desc: Test function of SignedFilePosTest::IncreaseFileNameOffset() interface for SUCCESS.
126  * @tc.size: MEDIUM
127  * @tc.type: FUNC
128  * @tc.level Level 1
129  * @tc.require: SR000H63TL
130  */
131 HWTEST_F(SignedFilePosTest, increaseFileNameOffset, testing::ext::TestSize.Level1)
132 {
133     std::shared_ptr<SignedFilePos> api = std::make_shared<SignedFilePos>(108, 31, 280, 2068);
134 
135     api->IncreaseFileNameOffset(1);
136     int32_t offset = api->GetFileNameOffset();
137 
138     EXPECT_EQ(offset, 109);
139 }
140 
141 /**
142  * @tc.name: increaseSignInfoOffset
143  * @tc.desc: Test function of SignedFilePosTest::IncreaseSignInfoOffset() interface for SUCCESS.
144  * @tc.size: MEDIUM
145  * @tc.type: FUNC
146  * @tc.level Level 1
147  * @tc.require: SR000H63TL
148  */
149 HWTEST_F(SignedFilePosTest, increaseSignInfoOffset, testing::ext::TestSize.Level1)
150 {
151     std::shared_ptr<SignedFilePos> api = std::make_shared<SignedFilePos>(108, 31, 280, 2068);
152 
153     api->IncreaseSignInfoOffset(2);
154     int32_t offset = api->GetSignInfoOffset();
155 
156     EXPECT_EQ(offset, 282);
157 }
158 } // namespace SignatureTools
159 } // namespace OHOS