1 /*
2 * Copyright (c) 2024 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 "pixel_map_from_surface.h"
17 #include "iconsumer_surface.h"
18 #include <gtest/gtest.h>
19
20 using namespace testing;
21 using namespace testing::ext;
22
23 namespace OHOS {
24 namespace Rosen {
25 class PixelMapFromSurfaceTest : public testing::Test {
26 public:
27 static void SetUpTestCase();
28 static void TearDownTestCase();
29 };
30
SetUpTestCase()31 void PixelMapFromSurfaceTest::SetUpTestCase() {}
32
TearDownTestCase()33 void PixelMapFromSurfaceTest::TearDownTestCase() {}
34
35 namespace {
36 /*
37 * Function: CreatePixelMapFromSurface001
38 * Type: Function
39 * Rank: Important(2)
40 * EnvConditions: N/A
41 * CaseDescription:
42 1. call CreatePixelMapFromSurface with nullptr suface and should return nullptr
43 2. call CreatePixelMapFromSurface with incorrect rect.left and should return nullptr
44 3. call CreatePixelMapFromSurface with incorrect rect.top and should return nullptr
45 4. call CreatePixelMapFromSurface with incorrect rect.width and should return nullptr
46 5. call CreatePixelMapFromSurface with incorrect rect.height and should return nullptr
47 */
48 HWTEST_F(PixelMapFromSurfaceTest, CreatePixelMapFromSurface001, Function | MediumTest| Level3)
49 {
50 OHOS::Media::Rect srcRect = {0, 0, 100, 100};
51 ASSERT_EQ(OHOS::Rosen::CreatePixelMapFromSurface(nullptr, srcRect), nullptr);
52 auto cSurface = IConsumerSurface::Create();
53 ASSERT_NE(cSurface, nullptr);
54 auto producer = cSurface->GetProducer();
55 auto pSurface = Surface::CreateSurfaceAsProducer(producer);
56 ASSERT_NE(pSurface, nullptr);
57 srcRect = {-1, 0, 100, 100};
58 ASSERT_EQ(OHOS::Rosen::CreatePixelMapFromSurface(pSurface, srcRect), nullptr);
59 srcRect = {0, -1, 100, 100};
60 ASSERT_EQ(OHOS::Rosen::CreatePixelMapFromSurface(pSurface, srcRect), nullptr);
61 srcRect = {0, 0, 0, 100};
62 ASSERT_EQ(OHOS::Rosen::CreatePixelMapFromSurface(pSurface, srcRect), nullptr);
63 srcRect = {0, 0, 100, 0};
64 ASSERT_EQ(OHOS::Rosen::CreatePixelMapFromSurface(pSurface, srcRect), nullptr);
65 }
66 } // namespace
67 } // namespace Rosen
68 } // namespace OHOS