2 * Copyright (c) 2020 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali-test-suite-utils.h>
21 #include <dali/public-api/images/pixel.h>
22 #include <dali/public-api/images/pixel-data.h>
23 #include <dali/public-api/common/dali-vector.h>
27 int UtcDaliPixelData01(void)
29 TestApplication application;
31 unsigned int width = 10u;
32 unsigned int height = 10u;
33 unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::RGB888 );
35 unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
36 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
38 DALI_TEST_CHECK( pixelData );
39 DALI_TEST_CHECK( pixelData.GetWidth() == width );
40 DALI_TEST_CHECK( pixelData.GetHeight() == height );
41 DALI_TEST_CHECK( pixelData.GetPixelFormat() == Pixel::RGB888 );
46 int UtcDaliPixelData02(void)
48 TestApplication application;
50 unsigned int width = 10u;
51 unsigned int height = 10u;
52 unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
53 unsigned char* buffer = new unsigned char [ bufferSize ];
56 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
58 DALI_TEST_CHECK( pixelData);
59 DALI_TEST_CHECK( pixelData.GetWidth() == width );
60 DALI_TEST_CHECK( pixelData.GetHeight() == height );
61 DALI_TEST_CHECK( pixelData.GetPixelFormat() == Pixel::L8 );
66 int UtcDaliPixelDataCopyConstructor(void)
68 TestApplication application;
70 unsigned int width = 10u;
71 unsigned int height = 10u;
72 unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
73 unsigned char* buffer = new unsigned char [ bufferSize ];
74 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
76 PixelData pixelDataCopy(pixelData);
78 DALI_TEST_EQUALS( (bool)pixelDataCopy, true, TEST_LOCATION );
82 int UtcDaliPixelDataAssignmentOperator(void)
84 TestApplication application;
86 unsigned int width = 10u;
87 unsigned int height = 10u;
88 unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
89 unsigned char* buffer = new unsigned char [ bufferSize ];
90 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
93 DALI_TEST_EQUALS( (bool)pixelData2, false, TEST_LOCATION );
95 pixelData2 = pixelData;
96 DALI_TEST_EQUALS( (bool)pixelData2, true, TEST_LOCATION );
101 int UtcDaliPixelDataMoveConstructor(void)
103 TestApplication application;
105 unsigned int width = 10u;
106 unsigned int height = 10u;
107 unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
108 unsigned char* buffer = new unsigned char [ bufferSize ];
110 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
111 DALI_TEST_CHECK( pixelData );
112 DALI_TEST_EQUALS( width, pixelData.GetWidth(), TEST_LOCATION );
113 DALI_TEST_EQUALS( height, pixelData.GetHeight(), TEST_LOCATION );
115 PixelData moved = std::move( pixelData);
116 DALI_TEST_CHECK( moved );
117 DALI_TEST_EQUALS( width, moved.GetWidth(), TEST_LOCATION );
118 DALI_TEST_EQUALS( height, moved.GetHeight(), TEST_LOCATION );
119 DALI_TEST_CHECK( !pixelData );
124 int UtcDaliPixelDataMoveAssignment(void)
126 TestApplication application;
128 unsigned int width = 10u;
129 unsigned int height = 10u;
130 unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
131 unsigned char* buffer = new unsigned char [ bufferSize ];
133 PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
134 DALI_TEST_CHECK( pixelData );
135 DALI_TEST_EQUALS( width, pixelData.GetWidth(), TEST_LOCATION );
136 DALI_TEST_EQUALS( height, pixelData.GetHeight(), TEST_LOCATION );
139 moved = std::move( pixelData);
140 DALI_TEST_CHECK( moved );
141 DALI_TEST_EQUALS( width, moved.GetWidth(), TEST_LOCATION );
142 DALI_TEST_EQUALS( height, moved.GetHeight(), TEST_LOCATION );
143 DALI_TEST_CHECK( !pixelData );