• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "gtest/gtest.h"
17 
18 #include "render_environment.h"
19 #include "effect_context.h"
20 
21 using namespace testing::ext;
22 
23 namespace OHOS {
24 namespace Media {
25 namespace Effect {
26 namespace Test {
27 
28 constexpr uint32_t WIDTH = 960;
29 constexpr uint32_t HEIGHT = 1280;
30 constexpr IEffectFormat FORMATE_TYPE = IEffectFormat::RGBA8888;
31 constexpr uint32_t ROW_STRIDE = WIDTH * 4;
32 constexpr uint32_t LEN = ROW_STRIDE * HEIGHT;
33 
34 class TestRenderEnvironment : public testing::Test {
35 public:
36     TestRenderEnvironment() = default;
37 
38     ~TestRenderEnvironment() override = default;
SetUpTestCase()39     static void SetUpTestCase() {}
40 
TearDownTestCase()41     static void TearDownTestCase() {}
42 
SetUp()43     void SetUp() override
44     {
45         renderEnvironment = std::make_shared<RenderEnvironment>();
46         renderEnvironment->Init();
47         renderEnvironment->Prepare();
48 
49         std::shared_ptr<BufferInfo> bufferInfo = std::make_unique<BufferInfo>();
50         bufferInfo->width_ = WIDTH;
51         bufferInfo->height_ = HEIGHT;
52         bufferInfo->rowStride_ = ROW_STRIDE;
53         bufferInfo->len_ = LEN;
54         bufferInfo->formatType_ = FORMATE_TYPE;
55         void *addr = malloc(bufferInfo->len_);
56 
57         std::shared_ptr<ExtraInfo> extraInfo = std::make_unique<ExtraInfo>();
58         extraInfo->dataType = DataType::PIXEL_MAP;
59         extraInfo->bufferType = BufferType::HEAP_MEMORY;
60         extraInfo->pixelMap = nullptr;
61         extraInfo->surfaceBuffer = nullptr;
62         effectBuffer = std::make_shared<EffectBuffer>(bufferInfo, addr, extraInfo);
63 
64         free(addr);
65         addr = nullptr;
66     }
67 
TearDown()68     void TearDown() override
69     {
70         effectBuffer = nullptr;
71         if (renderEnvironment == nullptr) {
72             return;
73         }
74         renderEnvironment->ReleaseParam();
75         renderEnvironment->Release();
76     }
77 
78     std::shared_ptr<EffectBuffer> effectBuffer;
79     std::shared_ptr<RenderEnvironment> renderEnvironment;
80 };
81 
82 }
83 }
84 }
85 }
86