• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 "snapshot_controller.h"
18 #include "wm_common.h"
19 #include "iremote_object_mocker.h"
20 #include "common_test_utils.h"
21 
22 using namespace testing;
23 using namespace testing::ext;
24 
25 namespace OHOS {
26 namespace Rosen {
27 class WindowSnapshotTest : public testing::Test {
28 public:
29     static void SetUpTestCase();
30     static void TearDownTestCase();
31     virtual void SetUp() override;
32     virtual void TearDown() override;
33 };
34 
SetUpTestCase()35 void WindowSnapshotTest::SetUpTestCase()
36 {
37 }
38 
TearDownTestCase()39 void WindowSnapshotTest::TearDownTestCase()
40 {
41 }
42 
SetUp()43 void WindowSnapshotTest::SetUp()
44 {
45 }
46 
TearDown()47 void WindowSnapshotTest::TearDown()
48 {
49 }
50 
51 namespace {
52 /**
53  * @tc.name: GetSnapshot
54  * @tc.desc: GetSnapshot when parameter abilityToken is nullptr
55  * @tc.type: FUNC
56  */
57 HWTEST_F(WindowSnapshotTest, GetSnapshot01, Function | SmallTest | Level3)
58 {
59     sptr<WindowRoot> root = nullptr;
60     std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr;
61     sptr<SnapshotController> snapshotController_ = new SnapshotController(root, handler);
62     AAFwk::Snapshot snapshot_;
63     ASSERT_EQ(static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), snapshotController_->GetSnapshot(nullptr, snapshot_));
64 }
65 
66 /**
67  * @tc.name: GetSnapshot
68  * @tc.desc: GetSnapshot when parameter abilityToken is nullptr
69  * @tc.type: FUNC
70  */
71 HWTEST_F(WindowSnapshotTest, GetSnapshot02, Function | SmallTest | Level3)
72 {
73     sptr<WindowRoot> root = nullptr;
74     std::shared_ptr<AppExecFwk::EventHandler> handler = nullptr;
75     sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker();
76 
77     sptr<SnapshotController> snapshotController_ = new SnapshotController(root, handler);
78     AAFwk::Snapshot snapshot_;
79     ASSERT_EQ(static_cast<int32_t>(WMError::WM_ERROR_NULLPTR),
80         snapshotController_->GetSnapshot(iRemoteObjectMocker, snapshot_));
81 }
82 
83 /**
84  * @tc.name: GetSnapshot
85  * @tc.desc: GetSnapshot when parameter abilityToken is nullptr
86  * @tc.type: FUNC
87  */
88 HWTEST_F(WindowSnapshotTest, GetSnapshot03, Function | SmallTest | Level3)
89 {
90     auto runner = AppExecFwk::EventRunner::Create("TestRunner");
91     auto handler = std::make_shared<AppExecFwk::EventHandler>(runner);
92     sptr<WindowRoot> root = nullptr;
93     sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker();
94 
95     sptr<SnapshotController> snapshotController_ = new SnapshotController(root, handler);
96     AAFwk::Snapshot snapshot_;
97     ASSERT_EQ(static_cast<int32_t>(WMError::WM_ERROR_NULLPTR),
98         snapshotController_->GetSnapshot(iRemoteObjectMocker, snapshot_));
99 }
100 
101 /**
102  * @tc.name: GetSnapshot
103  * @tc.desc: GetSnapshot when parameter abilityToken is nullptr
104  * @tc.type: FUNC
105  */
106 HWTEST_F(WindowSnapshotTest, GetSnapshot04, Function | SmallTest | Level3)
107 {
108     auto runner = AppExecFwk::EventRunner::Create("TestRunner");
109     auto handler = std::make_shared<AppExecFwk::EventHandler>(runner);
110 
__anon5ce06ad60202(Event event, const sptr<IRemoteObject>& remoteObject) 111     sptr<WindowRoot> root = new WindowRoot([](Event event, const sptr<IRemoteObject>& remoteObject) {});
112     sptr<WindowNode> node = new WindowNode();
113     root->windowNodeMap_.insert(std::make_pair(0, node));
114 
115     sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker();
116     node->abilityToken_ = iRemoteObjectMocker;
117 
118     sptr<SnapshotController> snapshotController_ = new SnapshotController(root, handler);
119     AAFwk::Snapshot snapshot_;
120     ASSERT_EQ(static_cast<int32_t>(WMError::WM_ERROR_NULLPTR),
121         snapshotController_->GetSnapshot(iRemoteObjectMocker, snapshot_));
122 
123     sptr<IRemoteObject> iRemoteObjectMockerInvalid = new IRemoteObjectMocker();
124     ASSERT_EQ(static_cast<int32_t>(WMError::WM_ERROR_NULLPTR),
125         snapshotController_->GetSnapshot(iRemoteObjectMockerInvalid, snapshot_));
126 }
127 
128 /**
129  * @tc.name: GetSnapshot
130  * @tc.desc: GetSnapshot when parameter abilityToken is nullptr
131  * @tc.type: FUNC
132  */
133 HWTEST_F(WindowSnapshotTest, GetSnapshot05, Function | SmallTest | Level3)
134 {
135     auto runner = AppExecFwk::EventRunner::Create("TestRunner");
136     auto handler = std::make_shared<AppExecFwk::EventHandler>(runner);
137 
__anon5ce06ad60302(Event event, const sptr<IRemoteObject>& remoteObject) 138     sptr<WindowRoot> root = new WindowRoot([](Event event, const sptr<IRemoteObject>& remoteObject) {});
139     sptr<WindowNode> node = new WindowNode();
140     root->windowNodeMap_.insert(std::make_pair(0, node));
141 
142     sptr<IRemoteObject> iRemoteObjectMocker = new IRemoteObjectMocker();
143     node->abilityToken_ = iRemoteObjectMocker;
144     node->SetSnapshot(CommonTestUtils::CreatePixelMap());
145 
146     sptr<SnapshotController> snapshotController_ = new SnapshotController(root, handler);
147     AAFwk::Snapshot snapshot_;
148     ASSERT_EQ(static_cast<int32_t>(WMError::WM_OK), snapshotController_->GetSnapshot(iRemoteObjectMocker, snapshot_));
149 }
150 }
151 } // namespace Rosen
152 } // namespace OHOS
153