• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "window_dumper.h"
18 #include "window_manager_service.h"
19 #include "window_impl.h"
20 #include "window_agent.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 class WindowDumperTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     void SetUp() override;
32     void TearDown() override;
33 };
34 
SetUpTestCase()35 void WindowDumperTest::SetUpTestCase()
36 {
37 }
38 
TearDownTestCase()39 void WindowDumperTest::TearDownTestCase()
40 {
41 }
42 
SetUp()43 void WindowDumperTest::SetUp()
44 {
45 }
46 
TearDown()47 void WindowDumperTest::TearDown()
48 {
49 }
50 
51 namespace {
52 /**
53  * @tc.name: Dump01
54  * @tc.desc: Dump
55  * @tc.type: FUNC
56  */
57 HWTEST_F(WindowDumperTest, Dump01, Function | SmallTest | Level1)
58 {
59     sptr<WindowDumper> windowDumper;
60     windowDumper = new WindowDumper(WindowManagerService::GetInstance().windowRoot_);
61     int fd = 0;
62     std::vector<std::u16string> args;
63     WMError ret = windowDumper->Dump(fd, args);
64     ASSERT_EQ(ret, WMError::WM_OK);
65 }
66 
67 /**
68  * @tc.name: Dump02
69  * @tc.desc: Dump fd less 0
70  * @tc.type: FUNC
71  */
72 HWTEST_F(WindowDumperTest, Dump02, Function | SmallTest | Level1)
73 {
74     sptr<WindowDumper> windowDumper;
75     windowDumper = new WindowDumper(WindowManagerService::GetInstance().windowRoot_);
76     int fd = -1;
77     std::vector<std::u16string> args;
78     WMError ret = windowDumper->Dump(fd, args);
79     ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_PARAM);
80 }
81 
82 /**
83  * @tc.name: Dump03
84  * @tc.desc: Dump one param with '-h'
85  * @tc.type: FUNC
86  */
87 HWTEST_F(WindowDumperTest, Dump03, Function | SmallTest | Level1)
88 {
89     sptr<WindowDumper> windowDumper;
90     windowDumper = new WindowDumper(WindowManagerService::GetInstance().windowRoot_);
91     int fd = 1;
92     std::vector<std::u16string> args;
93     const std::u16string DUMP_HELP = u"-h";
94     args.emplace_back(DUMP_HELP);
95     WMError ret = windowDumper->Dump(fd, args);
96     ASSERT_EQ(ret, WMError::WM_OK);
97 }
98 
99 /**
100  * @tc.name: Dump04
101  * @tc.desc: Dump one param with '-x'
102  * @tc.type: FUNC
103  */
104 HWTEST_F(WindowDumperTest, Dump04, Function | SmallTest | Level1)
105 {
106     sptr<WindowDumper> windowDumper;
107     windowDumper = new WindowDumper(WindowManagerService::GetInstance().windowRoot_);
108     int fd = 2;
109     std::vector<std::u16string> args;
110     const std::u16string DUMP_HELP = u"-x";
111     args.emplace_back(DUMP_HELP);
112     WMError ret = windowDumper->Dump(fd, args);
113     ASSERT_EQ(ret, WMError::WM_OK);
114 }
115 
116 /**
117  * @tc.name: Dump05
118  * @tc.desc: Dump two param with '-a'
119  * @tc.type: FUNC
120  */
121 HWTEST_F(WindowDumperTest, Dump05, Function | SmallTest | Level1)
122 {
123     sptr<WindowDumper> windowDumper;
124     windowDumper = new WindowDumper(WindowManagerService::GetInstance().windowRoot_);
125     int fd = 3;
126     std::vector<std::u16string> args;
127     const std::u16string DUMP_ALL = u"-a";
128     args.emplace_back(DUMP_ALL);
129     WMError ret = windowDumper->Dump(fd, args);
130     ASSERT_TRUE(ret == WMError::WM_OK || ret == WMError::WM_ERROR_INVALID_OPERATION);
131 }
132 
133 /**
134  * @tc.name: Dump06
135  * @tc.desc: Dump two param with '-w 1'
136  * @tc.type: FUNC
137  */
138 HWTEST_F(WindowDumperTest, Dump06, Function | SmallTest | Level1)
139 {
140     sptr<WindowDumper> windowDumper;
141     windowDumper = new WindowDumper(WindowManagerService::GetInstance().windowRoot_);
142     int fd = 4;
143     std::vector<std::u16string> args;
144     const std::u16string DUMP_WINDOW = u"-w";
145     const std::u16string DUMP_WINDOW_ID = u"3";
146     args.emplace_back(DUMP_WINDOW);
147     args.emplace_back(DUMP_WINDOW_ID);
148     WMError ret = windowDumper->Dump(fd, args);
149     ASSERT_TRUE(ret == WMError::WM_OK || ret == WMError::WM_ERROR_INVALID_OPERATION);
150 }
151 
152 /**
153  * @tc.name: Dump07
154  * @tc.desc: Dump two param with '-w n'
155  * @tc.type: FUNC
156  */
157 HWTEST_F(WindowDumperTest, Dump07, Function | SmallTest | Level1)
158 {
159     sptr<WindowDumper> windowDumper;
160     windowDumper = new WindowDumper(WindowManagerService::GetInstance().windowRoot_);
161     int fd = 5;
162     std::vector<std::u16string> args;
163     const std::u16string DUMP_WINDOW = u"-w";
164     const std::u16string DUMP_WINDOW_ID = u"n";
165     args.emplace_back(DUMP_WINDOW);
166     args.emplace_back(DUMP_WINDOW_ID);
167     WMError ret = windowDumper->Dump(fd, args);
168     ASSERT_EQ(ret, WMError::WM_ERROR_INVALID_OPERATION);
169 }
170 
171 /**
172  * @tc.name: ShowAceDumpHelp02
173  * @tc.desc: ShowAceDumpHelp
174  * @tc.type: FUNC
175  */
176 HWTEST_F(WindowDumperTest, ShowAceDumpHelp02, Function | SmallTest | Level1)
177 {
178     sptr<WindowDumper> windowDumper;
179     sptr<WindowNode> node = new WindowNode();
180     uint32_t id = 102;
181     node->property_->SetWindowId(id);
182     node->property_->SetWindowType(WindowType::WINDOW_TYPE_KEYGUARD);
183     WindowManagerService::GetInstance().windowRoot_->windowNodeMap_.insert(std::make_pair(id, node));
184     windowDumper = new WindowDumper(WindowManagerService::GetInstance().windowRoot_);
185     std::string dumpInfo;
186     windowDumper->ShowAceDumpHelp(dumpInfo);
187     WindowManagerService::GetInstance().windowRoot_->windowNodeMap_.clear();
188     ASSERT_TRUE(dumpInfo.empty());
189 }
190 }
191 }
192 }