• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 "dlp_zip_file_test.h"
17 #include <cstdio>
18 #include <cstring>
19 #include <fcntl.h>
20 #include <iostream>
21 #include <fstream>
22 #include <thread>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #define private public
26 #include "dlp_file.h"
27 #include "dlp_raw_file.h"
28 #include "dlp_zip_file.h"
29 #include "dlp_file_manager.h"
30 #undef private
31 #include "dlp_permission.h"
32 #include "dlp_permission_log.h"
33 #include "dlp_zip.h"
34 #include "c_mock_common.h"
35 #include "nlohmann/json.hpp"
36 
37 using namespace testing::ext;
38 using namespace OHOS::Security::DlpPermission;
39 using namespace std;
40 
41 namespace {
42 static const std::string DLP_TEST_DIR = "/data/dlpTest/";
43 }
44 
SetUpTestCase()45 void DlpZipFileTest::SetUpTestCase() {}
46 
TearDownTestCase()47 void DlpZipFileTest::TearDownTestCase() {}
48 
SetUp()49 void DlpZipFileTest::SetUp() {}
50 
TearDown()51 void DlpZipFileTest::TearDown() {}
52 
53 /**
54  * @tc.name: AddFileContextToZip001
55  * @tc.desc: test AddFileContextToZip
56  * @tc.type: FUNC
57  * @tc.require:
58  */
59 HWTEST_F(DlpZipFileTest, IsZipFile, TestSize.Level0)
60 {
61     std::vector<uint8_t> cert;
62     DlpBlob certBlob = { 0, nullptr };
63     std::shared_ptr<DlpZipFile> filePtr = std::make_shared<DlpZipFile>(-1, DLP_TEST_DIR, 0, "txt");
64     ASSERT_EQ(filePtr->UpdateCertAndText(cert, certBlob), DLP_PARSE_ERROR_MEMORY_OPERATE_FAIL);
65 }
66 
67 /**
68  * @tc.name: GetOfflineCertSizeTest
69  * @tc.desc: test GetOfflineCertSize
70  * @tc.type: FUNC
71  * @tc.require:
72  */
73 HWTEST_F(DlpZipFileTest, GetOfflineCertSizeTest, TestSize.Level0)
74 {
75     std::vector<uint8_t> cert;
76     std::shared_ptr<DlpZipFile> filePtr = std::make_shared<DlpZipFile>(-1, DLP_TEST_DIR, 0, "txt");
77     ASSERT_EQ(filePtr->GetOfflineCertSize(), 0);
78 }