1 /*
2 * Copyright (c) 2022 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 <gtest/gtest.h>
17 #include <memory>
18
19 #define private public
20 #define protected public
21 #include "device_profile_dumper.h"
22 #undef private
23 #undef protected
24 #include "ipc_skeleton.h"
25 #include "utils.h"
26
27 namespace OHOS {
28 namespace DeviceProfile {
29 using namespace testing;
30 using namespace testing::ext;
31
32 class DeviceProfileDFXTest : public testing::Test {
33 public:
34 static void SetUpTestCase();
35 static void TearDownTestCase();
36 void SetUp();
37 void TearDown();
38 };
39
40
SetUpTestCase()41 void DeviceProfileDFXTest::SetUpTestCase()
42 {
43 DTEST_LOG << "SetUpTestCase" << std::endl;
44 }
45
TearDownTestCase()46 void DeviceProfileDFXTest::TearDownTestCase()
47 {
48 DTEST_LOG << "TearDownTestCase" << std::endl;
49 }
50
SetUp()51 void DeviceProfileDFXTest::SetUp()
52 {
53 DTEST_LOG << "SetUp" << std::endl;
54 }
55
TearDown()56 void DeviceProfileDFXTest::TearDown()
57 {
58 DTEST_LOG << "TearDown" << std::endl;
59 }
60
61 /**
62 * @tc.name: DumpDefault_001
63 * @tc.desc: dfx dump default
64 * @tc.type: FUNC
65 * @tc.require: I4NY1T
66 */
67 HWTEST_F(DeviceProfileDFXTest, DumpDefault_001, TestSize.Level3)
68 {
69 auto dumper = std::make_shared<DeviceProfileDumper>();
70 std::string msg;
71 dumper->ShowHelp(msg);
72 dumper->IllegalInput(msg);
73 auto result = dumper->DumpDefault(msg);
74 EXPECT_EQ(true, result);
75 }
76
77 /**
78 * @tc.name: CanDump_002
79 * @tc.desc: CanDump
80 * @tc.type: FUNC
81 * @tc.require: I4NY1T
82 */
83 HWTEST_F(DeviceProfileDFXTest, CanDump_001, TestSize.Level3)
84 {
85 auto dumper = std::make_shared<DeviceProfileDumper>();
86 auto result = dumper->CanDump();
87 EXPECT_EQ(false, result);
88 }
89
90 /**
91 * @tc.name: Dump_002
92 * @tc.desc: Dump
93 * @tc.type: FUNC
94 * @tc.require: I4NY1T
95 */
96 HWTEST_F(DeviceProfileDFXTest, Dump_001, TestSize.Level3)
97 {
98 auto dumper = std::make_shared<DeviceProfileDumper>();
99 std::string msg;
100 const std::vector<std::string> args;
101 auto result = dumper->Dump(args, msg);
102 EXPECT_EQ(false, result);
103 }
104
105 /**
106 * @tc.name: CanDump_002
107 * @tc.desc: CanDump
108 * @tc.type: FUNC
109 * @tc.require: I4NY1T
110 */
111 HWTEST_F(DeviceProfileDFXTest, CanDump_002, TestSize.Level3)
112 {
113 setuid(1212);
114 auto dumper = std::make_shared<DeviceProfileDumper>();
115 auto result = dumper->CanDump();
116 EXPECT_EQ(true, result);
117 }
118
119 /**
120 * @tc.name: Dump_002
121 * @tc.desc: Dump
122 * @tc.type: FUNC
123 * @tc.require: I4NY1T
124 */
125 HWTEST_F(DeviceProfileDFXTest, Dump_002, TestSize.Level3)
126 {
127 auto dumper = std::make_shared<DeviceProfileDumper>();
128 std::string msg;
129 const std::vector<std::string> args;
130 auto result = dumper->Dump(args, msg);
131 EXPECT_EQ(true, result);
132 }
133
134 /**
135 * @tc.name: Dump_003
136 * @tc.desc: Dump
137 * @tc.type: FUNC
138 * @tc.require: I4NY1T
139 */
140 HWTEST_F(DeviceProfileDFXTest, Dump_003, TestSize.Level3)
141 {
142 auto dumper = std::make_shared<DeviceProfileDumper>();
143 std::string msg;
144 std::vector<std::string> args;
145 args.emplace_back("-h");
146 auto result = dumper->Dump(args, msg);
147 EXPECT_EQ(true, result);
148 }
149
150 /**
151 * @tc.name: Dump_004
152 * @tc.desc: Dump
153 * @tc.type: FUNC
154 * @tc.require: I4NY1T
155 */
156 HWTEST_F(DeviceProfileDFXTest, Dump_004, TestSize.Level3)
157 {
158 auto dumper = std::make_shared<DeviceProfileDumper>();
159 std::string msg;
160 std::vector<std::string> args;
161 args.emplace_back("-g");
162 auto result = dumper->Dump(args, msg);
163 EXPECT_EQ(false, result);
164 }
165
166 /**
167 * @tc.name: Dump_005
168 * @tc.desc: Dump
169 * @tc.type: FUNC
170 * @tc.require: I4NY1T
171 */
172 HWTEST_F(DeviceProfileDFXTest, Dump_005, TestSize.Level3)
173 {
174 auto dumper = std::make_shared<DeviceProfileDumper>();
175 std::string msg;
176 std::vector<std::string> args;
177 args.emplace_back("-h");
178 args.emplace_back("-g");
179 auto result = dumper->Dump(args, msg);
180 EXPECT_EQ(false, result);
181 }
182 }
183 }