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 <fstream>
18 #include <gtest/gtest.h>
19
20 #include "hap_utils.h"
21 #include "byte_buffer.h"
22
23 namespace OHOS {
24 namespace SignatureTools {
25
26 class HapUtilsTest : 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: GetAppIdentifier
36 * @tc.desc: Test function of HapUtilsTest::GetAppIdentifier() interface for SUCCESS.
37 * @tc.size: MEDIUM
38 * @tc.type: FUNC
39 * @tc.level Level 1
40 * @tc.require: SR000H63TL
41 */
HWTEST_F(HapUtilsTest, GetAppIdentifier, testing::ext::TestSize.Level1)42 HWTEST_F(HapUtilsTest, GetAppIdentifier, testing::ext::TestSize.Level1)
43 {
44 std::string content = "{\"type\":\"xxx\",\"bundle-info\":{\"app-identifier\":\"123\"}}";
45 std::string result = HapUtils::GetAppIdentifier(content);
46 int length = result.length();
47
48 EXPECT_NE(length, 0);
49 }
50
51 /**
52 * @tc.name: GetHapSigningBlockMagic
53 * @tc.desc: Test function of HapUtilsTest::GetHapSigningBlockMagic() interface for SUCCESS.
54 * @tc.size: MEDIUM
55 * @tc.type: FUNC
56 * @tc.level Level 1
57 * @tc.require: SR000H63TL
58 */
HWTEST_F(HapUtilsTest, GetHapSigningBlockMagic, testing::ext::TestSize.Level1)59 HWTEST_F(HapUtilsTest, GetHapSigningBlockMagic, testing::ext::TestSize.Level1)
60 {
61 std::vector<int8_t> result = HapUtils::GetHapSigningBlockMagic(4);
62 int size = result.size();
63
64 EXPECT_NE(size, 0);
65 }
66
67 /**
68 * @tc.name: GetHapSigningBlockVersion
69 * @tc.desc: Test function of HapUtilsTest::GetHapSigningBlockVersion() interface for SUCCESS.
70 * @tc.size: MEDIUM
71 * @tc.type: FUNC
72 * @tc.level Level 1
73 * @tc.require: SR000H63TL
74 */
HWTEST_F(HapUtilsTest, GetHapSigningBlockVersion, testing::ext::TestSize.Level1)75 HWTEST_F(HapUtilsTest, GetHapSigningBlockVersion, testing::ext::TestSize.Level1)
76 {
77 int result = HapUtils::GetHapSigningBlockVersion(4);
78
79 EXPECT_NE(result, 0);
80 }
81
82 /**
83 * @tc.name: ReadFileToByteBuffer
84 * @tc.desc: Test function of HapUtilsTest::ReadFileToByteBuffer() interface for FAILED.
85 * @tc.size: MEDIUM
86 * @tc.type: FUNC
87 * @tc.level Level 1
88 * @tc.require: SR000H63TL
89 */
HWTEST_F(HapUtilsTest, ReadFileToByteBuffer, testing::ext::TestSize.Level1)90 HWTEST_F(HapUtilsTest, ReadFileToByteBuffer, testing::ext::TestSize.Level1)
91 {
92 std::string file;
93 ByteBuffer buffer;
94 bool result = HapUtils::ReadFileToByteBuffer(file, buffer);
95
96 EXPECT_EQ(result, false);
97 }
98 } // namespace SignatureTools
99 } // namespace OHOS