1 /*
2 * Copyright (c) 2023 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 #define private public
17 #define protected public
18 #include "gtest/gtest.h"
19 #include "device_profile_dumper.h"
20 #undef private
21 #undef protected
22
23 namespace OHOS {
24 namespace DistributedDeviceProfile {
25 using namespace testing;
26 using namespace testing::ext;
27
28 class DpDumperTest : public testing::Test {
29 public:
30 static void SetUpTestCase();
31 static void TearDownTestCase();
32 void SetUp();
33 void TearDown();
34 };
35
SetUpTestCase()36 void DpDumperTest::SetUpTestCase() {
37 }
38
TearDownTestCase()39 void DpDumperTest::TearDownTestCase() {
40 }
41
SetUp()42 void DpDumperTest::SetUp() {
43 }
44
TearDown()45 void DpDumperTest::TearDown() {
46 }
47
48 HWTEST_F(DpDumperTest, Dump_001, TestSize.Level1)
49 {
50 std::vector<std::string> args;
51 std::string result;
52 auto dumper = std::make_shared<DeviceProfileDumper>();
53 bool ret = dumper->Dump(args, result);
54 EXPECT_EQ(false, ret);
55 }
56
57 HWTEST_F(DpDumperTest, Dump_002, TestSize.Level1)
58 {
59 setuid(1212);
60 std::string result;
61 std::vector<std::string> args;
62 auto dumper = std::make_shared<DeviceProfileDumper>();
63 bool ret = dumper->Dump(args, result);
64 EXPECT_EQ(true, ret);
65 }
66
67 HWTEST_F(DpDumperTest, Dump_003, TestSize.Level1)
68 {
69 setuid(1212);
70 std::string result;
71 std::vector<std::string> args;
72 args.emplace_back("-h");
73 auto dumper = std::make_shared<DeviceProfileDumper>();
74 bool ret = dumper->Dump(args, result);
75 EXPECT_EQ(true, ret);
76 }
77
78 HWTEST_F(DpDumperTest, Dump_004, TestSize.Level1)
79 {
80 setuid(1212);
81 std::string result;
82 std::vector<std::string> args;
83 args.emplace_back("-g");
84 auto dumper = std::make_shared<DeviceProfileDumper>();
85 bool ret = dumper->Dump(args, result);
86 EXPECT_EQ(false, ret);
87 }
88 }
89 }
90