• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 #define private public
17 #include <gtest/gtest.h>
18 #include "image_type.h"
19 #include "basic_transformer.h"
20 
21 using namespace testing::ext;
22 using namespace OHOS::Media;
23 namespace OHOS {
24 namespace Multimedia {
25 constexpr int32_t PIXEL_MAP_MAX_RAM_SIZE = 600 * 1024 * 1024;
26 class BasicTransformerTest : public testing::Test {
27 public:
BasicTransformerTest()28     BasicTransformerTest() {}
~BasicTransformerTest()29     ~BasicTransformerTest() {}
30 };
31 
32 /**
33  * @tc.name: CheckAllocateBufferTest001
34  * @tc.desc: CheckAllocateBuffer
35  * @tc.type: FUNC
36  */
37 HWTEST_F(BasicTransformerTest, CheckAllocateBufferTest001, TestSize.Level3)
38 {
39     GTEST_LOG_(INFO) << "BasicTransformerTest: CheckAllocateBufferTest001 start";
40     BasicTransformer basicTransformer;
41     PixmapInfo outPixmap;
42     BasicTransformer::AllocateMem allocate = nullptr;
43     int fd = 0;
44     uint64_t bufferSize = 0;
45     Size dstSize;
46     bool ret = basicTransformer.CheckAllocateBuffer(outPixmap, allocate, fd, bufferSize, dstSize);
47     ASSERT_EQ(ret, false);
48     bufferSize = 128;
49     ret = basicTransformer.CheckAllocateBuffer(outPixmap, allocate, fd, bufferSize, dstSize);
50     ASSERT_EQ(ret, true);
51     GTEST_LOG_(INFO) << "BasicTransformerTest: CheckAllocateBufferTest001 end";
52 }
53 
54 
55 /**
56  * @tc.name: ReleaseBufferTest001
57  * @tc.desc: ReleaseBuffer
58  * @tc.type: FUNC
59  */
60 HWTEST_F(BasicTransformerTest, ReleaseBufferTest001, TestSize.Level3)
61 {
62     GTEST_LOG_(INFO) << "BasicTransformerTest: ReleaseBufferTest001 start";
63     BasicTransformer basicTransformer;
64     AllocatorType allocatorType = AllocatorType::SHARE_MEM_ALLOC;
65     int fd = 0;
66     int dataSize = 2;
67     uint8_t *buffer = new uint8_t;
68     basicTransformer.ReleaseBuffer(allocatorType, fd, dataSize, buffer);
69     ASSERT_NE(buffer, nullptr);
70     buffer = new uint8_t;
71     allocatorType = AllocatorType::HEAP_ALLOC;
72     basicTransformer.ReleaseBuffer(allocatorType, fd, dataSize, buffer);
73     ASSERT_NE(buffer, nullptr);
74     GTEST_LOG_(INFO) << "BasicTransformerTest: ReleaseBufferTest001 end";
75 }
76 
77 /**
78  * @tc.name: TransformPixmapTest001
79  * @tc.desc: TransformPixmap
80  * @tc.type: FUNC
81  */
82 HWTEST_F(BasicTransformerTest, TransformPixmapTest001, TestSize.Level3)
83 {
84     GTEST_LOG_(INFO) << "BasicTransformerTest: TransformPixmapTest001 start";
85     BasicTransformer basicTransformer;
86     PixmapInfo inPixmap;
87     PixmapInfo outPixmap;
88     BasicTransformer::AllocateMem allocate = nullptr;
89     uint32_t ret = basicTransformer.TransformPixmap(inPixmap, outPixmap, allocate);
90     ASSERT_EQ(ret, ERR_IMAGE_GENERAL_ERROR);
91     inPixmap.data = new uint8_t;
92     ret = basicTransformer.TransformPixmap(inPixmap, outPixmap, allocate);
93     ASSERT_EQ(ret, ERR_IMAGE_INVALID_PIXEL);
94     inPixmap.imageInfo.pixelFormat = PixelFormat::ARGB_8888;
95     basicTransformer.matrix_.operType_ = 0x02;
96     basicTransformer.matrix_.fMat_[IMAGE_SCALEX] = 1;
97     inPixmap.imageInfo.size.width = -FHALF;
98     basicTransformer.matrix_.fMat_[IMAGE_SCALEY] = 1;
99     inPixmap.imageInfo.size.height = -FHALF;
100     ret = basicTransformer.TransformPixmap(inPixmap, outPixmap, allocate);
101     ASSERT_EQ(ret, ERR_IMAGE_ALLOC_MEMORY_FAILED);
102     GTEST_LOG_(INFO) << "BasicTransformerTest: TransformPixmapTest001 end";
103 }
104 
105 /**
106  * @tc.name: TransformPixmapTest002
107  * @tc.desc: TransformPixmap
108  * @tc.type: FUNC
109  */
110 HWTEST_F(BasicTransformerTest, TransformPixmapTest002, TestSize.Level3)
111 {
112     GTEST_LOG_(INFO) << "BasicTransformerTest: TransformPixmapTest002 start";
113     BasicTransformer basicTransformer;
114     PixmapInfo inPixmap;
115     PixmapInfo outPixmap;
116     BasicTransformer::AllocateMem allocate = nullptr;
117     inPixmap.data = new uint8_t;
118     inPixmap.imageInfo.pixelFormat = PixelFormat::ARGB_8888;
119     basicTransformer.matrix_.operType_ = 0x02;
120     basicTransformer.matrix_.fMat_[IMAGE_SCALEX] = 1;
121     inPixmap.imageInfo.size.width = PIXEL_MAP_MAX_RAM_SIZE;
122     basicTransformer.matrix_.fMat_[IMAGE_SCALEY] = 1;
123     inPixmap.imageInfo.size.height = 1;
124     uint32_t ret = basicTransformer.TransformPixmap(inPixmap, outPixmap, allocate);
125     ASSERT_EQ(ret, ERR_IMAGE_ALLOC_MEMORY_FAILED);
126     inPixmap.imageInfo.size.width = -FHALF;
127     inPixmap.imageInfo.size.height = -FHALF;
128     ret = basicTransformer.TransformPixmap(inPixmap, outPixmap, allocate);
129     ASSERT_EQ(ret, ERR_IMAGE_ALLOC_MEMORY_FAILED);
130     inPixmap.imageInfo.size.width = 1;
131     inPixmap.imageInfo.size.height = 1;
132     ret = basicTransformer.TransformPixmap(inPixmap, outPixmap, allocate);
133     ASSERT_EQ(ret, IMAGE_SUCCESS);
134     GTEST_LOG_(INFO) << "BasicTransformerTest: TransformPixmapTest002 end";
135 }
136 
137 /**
138  * @tc.name: GetAroundPixelRGB565Test001
139  * @tc.desc: GetAroundPixelRGB565
140  * @tc.type: FUNC
141  */
142 HWTEST_F(BasicTransformerTest, GetAroundPixelRGB565Test001, TestSize.Level3)
143 {
144     GTEST_LOG_(INFO) << "BasicTransformerTest: GetAroundPixelRGB565Test001 start";
145     BasicTransformer basicTransformer;
146     Media::BasicTransformer::AroundPos aroundPos;
147     uint32_t *color = new uint32_t(0);
148     uint8_t *data = reinterpret_cast<uint8_t*>(color);
149     uint32_t rb = 2;
150     Media::BasicTransformer::AroundPixels aroundPixels;
151     basicTransformer.GetAroundPixelRGB565(aroundPos, data, rb, aroundPixels);
152     ASSERT_EQ(aroundPixels.color11, 0);
153     delete color;
154     GTEST_LOG_(INFO) << "BasicTransformerTest: GetAroundPixelRGB565Test001 end";
155 }
156 }
157 }