1 /*
2 * Copyright (c) 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 "loglibrary_agent_test.h"
17
18 #include <string>
19 #include <vector>
20
21 #include "accesstoken_kit.h"
22 #include "adapter_loglibrary_test_tools.h"
23 #include "file_util.h"
24 #include "hiview_service_ability_proxy.h"
25 #include "hiview_service_agent.h"
26 #include "nativetoken_kit.h"
27 #include "token_setproc.h"
28
29 namespace OHOS {
30 namespace HiviewDFX {
31 namespace {
32 const std::string DEST_PATH = "";
33 const std::string SOURCE_PATH = "/data/log/logpack/remotelog/";
34 const std::string LOG_TYPE = "REMOTELOG";
35 }
SetUpTestCase()36 void LoglibraryAgentTest::SetUpTestCase() {}
37
TearDownTestCase()38 void LoglibraryAgentTest::TearDownTestCase() {}
39
SetUp()40 void LoglibraryAgentTest::SetUp()
41 {
42 AdapterLoglibraryTestTools::ApplyPermissionAccess();
43 AdapterLoglibraryTestTools::CreateDir(SOURCE_PATH);
44 }
45
TearDown()46 void LoglibraryAgentTest::TearDown()
47 {
48 AdapterLoglibraryTestTools::RemoveDir(SOURCE_PATH);
49 }
50
51 HWTEST_F(LoglibraryAgentTest, LoglibraryAgentListTest001, testing::ext::TestSize.Level1)
52 {
53 std::string fileName = "List.txt";
54 FileUtil::SaveStringToFile(SOURCE_PATH + fileName, "listtestcontent", true);
55 std::vector<HiviewFileInfo> fileInfos;
56 int32_t result = HiviewServiceAgent::GetInstance().List(LOG_TYPE, fileInfos);
57 ASSERT_EQ(result, 0);
58 }
59
60 HWTEST_F(LoglibraryAgentTest, LoglibraryAgentCopyTest001, testing::ext::TestSize.Level1)
61 {
62 std::string fileName = "Copy.txt";
63 FileUtil::SaveStringToFile(SOURCE_PATH + fileName, "copytestcontent", true);
64 int32_t result = HiviewServiceAgent::GetInstance().Copy(LOG_TYPE, fileName, DEST_PATH);
65 ASSERT_EQ(result, -1);
66 }
67
68 HWTEST_F(LoglibraryAgentTest, LoglibraryAgentMoveTest001, testing::ext::TestSize.Level1)
69 {
70 std::string fileName = "Move.txt";
71 FileUtil::SaveStringToFile(SOURCE_PATH + fileName, "movetestcontent", true);
72 int32_t result = HiviewServiceAgent::GetInstance().Move(LOG_TYPE, fileName, DEST_PATH);
73 ASSERT_EQ(result, -1);
74 }
75
76 HWTEST_F(LoglibraryAgentTest, LoglibraryAgentRemoveTest001, testing::ext::TestSize.Level1)
77 {
78 std::string fileName = "Reove.txt";
79 FileUtil::SaveStringToFile(SOURCE_PATH + fileName, "removetestcontent", true);
80 int32_t result = HiviewServiceAgent::GetInstance().Remove(LOG_TYPE, fileName);
81 ASSERT_EQ(result, 0);
82 }
83 }
84 }