• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
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 <hwext/gtest-ext.h>
17 #include <hwext/gtest-tag.h>
18 
19 #include "export_test.h"
20 #include "file.h"
21 #include "log.h"
22 
23 using namespace testing::ext;
24 
25 namespace SysTuning {
26 namespace TraceStreamer {
27 namespace FileDataUnitTest {
28 class FileTest : public ::testing::Test {
29 public:
SetUp()30     void SetUp() {}
TearDown()31     void TearDown() {}
32 
33 public:
34     const std::string zlibPath_ = "../../test/resource/zlib.htrace";
35     const std::string zipPath_ = "../../test/resource/htrace.zip";
36     const std::string tempPath_ = "../../test/resource/ts_tmp";
37 };
38 
39 /**
40  * @tc.name: UnZlibFile Test
41  * @tc.desc: UnZlibFile Test
42  * @tc.type: FUNC
43  */
44 HWTEST_F(FileTest, UnZlibFile, TestSize.Level1)
45 {
46     TS_LOGE("test46-1");
47     std::string zlibFile("invalidpath");
48     std::string traceFile;
49     auto ret = base::UnZlibFile(zlibFile, traceFile);
50     EXPECT_FALSE(ret);
51     ret = base::UnZlibFile(zlibPath_, traceFile);
52     EXPECT_TRUE(ret);
53     RemoveDirectory(tempPath_);
54 }
55 
56 /**
57  * @tc.name: UnZipFile Test
58  * @tc.desc: UnZipFile Test
59  * @tc.type: FUNC
60  */
61 HWTEST_F(FileTest, UnZipFile, TestSize.Level1)
62 {
63     TS_LOGE("test46-2");
64     std::string zipFile("invalidpath");
65     std::string traceFile;
66     auto ret = base::UnZipFile(zipFile, traceFile);
67     EXPECT_FALSE(ret);
68     ret = base::UnZipFile(zipPath_, traceFile);
69     EXPECT_TRUE(ret);
70     RemoveDirectory(tempPath_);
71 }
72 } // namespace FileDataUnitTest
73 } // namespace TraceStreamer
74 } // namespace SysTuning