• 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 "png.h"
18 #include "display_manager.h"
19 #include "pixel_map.h"
20 
21 #include <securec.h>
22 
23 #include "mock_display_manager_adapter.h"
24 #include "singleton_mocker.h"
25 #include "common_test_utils.h"
26 
27 using namespace testing;
28 using namespace testing::ext;
29 
30 namespace OHOS {
31 namespace Rosen {
32 using Mocker = SingletonMocker<DisplayManagerAdapter, MockDisplayManagerAdapter>;
33 class ScreenshotTest : public testing::Test {
34 public:
35     static void SetUpTestCase();
36     static void TearDownTestCase();
37     virtual void SetUp() override;
38     virtual void TearDown() override;
39 };
SetUpTestCase()40 void ScreenshotTest::SetUpTestCase()
41 {
42     CommonTestUtils::InjectTokenInfoByHapName(0, "com.ohos.systemui", 0);
43 }
44 
TearDownTestCase()45 void ScreenshotTest::TearDownTestCase()
46 {
47 }
48 
SetUp()49 void ScreenshotTest::SetUp()
50 {
51 }
52 
TearDown()53 void ScreenshotTest::TearDown()
54 {
55 }
56 
57 namespace {
58 /**
59  * @tc.name: GetScreenshot_default
60  * @tc.desc: SetWindowRect/GetWindowRect
61  * @tc.type: FUNC
62  */
63 HWTEST_F(ScreenshotTest, GetScreenshot_default, Function | SmallTest | Level2)
64 {
65     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
66 
67     EXPECT_CALL(m->Mock(), GetDefaultDisplayInfo()).Times(1).WillOnce(Return(nullptr));
68 
69     DisplayManager::GetInstance().GetDefaultDisplayId();
70 
71     EXPECT_CALL(m->Mock(), GetDisplaySnapshot(_)).Times(1).WillOnce(Return(nullptr));
72 
73     ASSERT_EQ(nullptr, DisplayManager::GetInstance().GetScreenshot(0));
74 }
75 
76 HWTEST_F(ScreenshotTest, GetScreenshot_01, Function | MediumTest | Level2)
77 {
78     std::unique_ptr<Mocker> m = std::make_unique<Mocker>();
79 
80     EXPECT_CALL(m->Mock(), GetDefaultDisplayInfo()).Times(1).WillOnce(Return(nullptr));
81     DisplayManager::GetInstance().GetDefaultDisplayId();
82 
83     EXPECT_CALL(m->Mock(), GetDisplaySnapshot(_)).Times(1).WillOnce(Return(CommonTestUtils::CreatePixelMap()));
84     auto screenshot = DisplayManager::GetInstance().GetScreenshot(0);
85     ASSERT_NE(nullptr, screenshot);
86 
87     uint32_t width = screenshot->GetWidth();
88     uint32_t height = screenshot->GetHeight();
89     ASSERT_EQ(width, CommonTestUtils::TEST_IMAGE_WIDTH);
90     ASSERT_EQ(height, CommonTestUtils::TEST_IMAGE_HEIGHT);
91 }
92 }
93 } // namespace Rosen
94 } // namespace OHOS
95