1 /*
2 * Copyright (c) 2023 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 <cstdlib>
17 #include <cstdio>
18 #include <ctime>
19 #include <dlfcn.h>
20 #include <fstream>
21 #include <memory>
22 #include <string>
23
24 #include <gtest/gtest.h>
25
26 #include "algorithm_common.h"
27 #include "algorithm_errors.h"
28 #include "graphic_common_c.h"
29 #include "aihdr_enhancer_fwk.h"
30
31 using namespace std;
32 using namespace testing::ext;
33
34 namespace OHOS {
35 namespace Media {
36 namespace VideoProcessingEngine {
37
CreateSurfaceBuffer(uint32_t pixelFormat,int32_t width,int32_t height)38 sptr<SurfaceBuffer> CreateSurfaceBuffer(uint32_t pixelFormat, int32_t width, int32_t height)
39 {
40 auto buffer = SurfaceBuffer::Create();
41 if (nullptr == buffer) {
42 printf("Create surface buffer failed\n");
43 return nullptr;
44 }
45 BufferRequestConfig inputCfg;
46 inputCfg.width = width;
47 inputCfg.height = height;
48 inputCfg.strideAlignment = width;
49 inputCfg.usage = BUFFER_USAGE_CPU_READ | BUFFER_USAGE_CPU_WRITE
50 | BUFFER_USAGE_HW_RENDER | BUFFER_USAGE_HW_TEXTURE | BUFFER_USAGE_MEM_MMZ_CACHE;
51 inputCfg.format = pixelFormat;
52 inputCfg.timeout = 0;
53 GSError err = buffer->Alloc(inputCfg);
54 if (GSERROR_OK != err) {
55 printf("Alloc surface buffer failed\n");
56 return nullptr;
57 }
58 return buffer;
59 }
60
61 class AihdrEnhancerUnitTest : public testing::Test {
62 public:
63 static void SetUpTestCase(void);
64 static void TearDownTestCase(void);
65 void SetUp();
66 void TearDown();
67 };
68
SetUpTestCase(void)69 void AihdrEnhancerUnitTest::SetUpTestCase(void)
70 {
71 cout << "[SetUpTestCase]: " << endl;
72 }
73
TearDownTestCase(void)74 void AihdrEnhancerUnitTest::TearDownTestCase(void)
75 {
76 cout << "[TearDownTestCase]: " << endl;
77 }
78
SetUp(void)79 void AihdrEnhancerUnitTest::SetUp(void)
80 {
81 cout << "[SetUp]: SetUp!!!" << endl;
82 }
83
TearDown(void)84 void AihdrEnhancerUnitTest::TearDown(void)
85 {
86 cout << "[TearDown]: over!!!" << endl;
87 }
88
89 // aihdr enhancer create
90 HWTEST_F(AihdrEnhancerUnitTest, aihdrenhancer_create_01, TestSize.Level1)
91 {
92 auto aihdrEnh = AihdrEnhancer::Create();
93 EXPECT_NE(aihdrEnh, nullptr);
94 }
95
96 // aihdr enhancer create meultiple times
97 HWTEST_F(AihdrEnhancerUnitTest, aihdrenhancer_create_02, TestSize.Level1)
98 {
99 auto aihdrEnh = AihdrEnhancer::Create();
100 aihdrEnh = AihdrEnhancer::Create();
101 aihdrEnh = AihdrEnhancer::Create();
102 aihdrEnh = AihdrEnhancer::Create();
103 aihdrEnh = AihdrEnhancer::Create();
104 EXPECT_NE(aihdrEnh, nullptr);
105 }
106
107 // set parameter
108 HWTEST_F(AihdrEnhancerUnitTest, aihdrenhancer_setparameter_01, TestSize.Level1)
109 {
110 auto aihdrEnh = AihdrEnhancer::Create();
111 int param = 1;
112 auto res = aihdrEnh->SetParameter(param);
113 EXPECT_EQ(res, VPE_ALGO_ERR_OK);
114 }
115
116 // get parameter
117 HWTEST_F(AihdrEnhancerUnitTest, aihdrenhancer_getparameter_01, TestSize.Level1)
118 {
119 auto aihdrEnh = AihdrEnhancer::Create();
120 int param = 1;
121 int paramTemp = 0;
122 auto resSet = aihdrEnh->SetParameter(param);
123 auto resGet = aihdrEnh->GetParameter(paramTemp);
124 EXPECT_EQ(resSet, VPE_ALGO_ERR_OK);
125 EXPECT_EQ(resGet, VPE_ALGO_ERR_OK);
126 EXPECT_EQ(param, paramTemp);
127 }
128
129 // process
130 HWTEST_F(AihdrEnhancerUnitTest, aihdrenhancer_process_01, TestSize.Level1)
131 {
132 auto aihdrEnh = AihdrEnhancer::Create();
133 int param = 1;
134 aihdrEnh->SetParameter(param);
135 int32_t inputFormat = OHOS::GRAPHIC_PIXEL_FMT_YCBCR_420_SP;
136 sptr<SurfaceBuffer> input = CreateSurfaceBuffer(inputFormat, 1024, 768);
137 auto ret = aihdrEnh->Process(input);
138 EXPECT_EQ(ret, VPE_ALGO_ERR_OK);
139 }
140
141 // process
142 HWTEST_F(AihdrEnhancerUnitTest, aihdrenhancer_process_02, TestSize.Level1)
143 {
144 auto aihdrEnh = AihdrEnhancer::Create();
145 int param = 1;
146 aihdrEnh->SetParameter(param);
147 int32_t inputFormat = OHOS::GRAPHIC_PIXEL_FMT_YCBCR_420_SP;
148 sptr<SurfaceBuffer> input = CreateSurfaceBuffer(inputFormat, 1024, 768);
149 input = nullptr;
150 auto ret = aihdrEnh->Process(input);
151 EXPECT_EQ(ret, VPE_ALGO_ERR_INVALID_VAL);
152 }
153 } // namespace VideoProcessingEngine
154 } // namespace Media
155 } // namespace OHOS
156