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