Revert "Implemented basic CPU image masking"
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-PixelData.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <cstdlib>
19 #include <dali-test-suite-utils.h>
20
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>
24
25 using namespace Dali;
26
27 int UtcDaliPixelData01(void)
28 {
29   TestApplication application;
30
31   unsigned int width = 10u;
32   unsigned int height = 10u;
33   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::RGB888 );
34
35   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
36   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
37
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 );
42
43   END_TEST;
44 }
45
46 int UtcDaliPixelData02(void)
47 {
48   TestApplication application;
49
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 ];
54   buffer[0] = 'a';
55
56   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
57
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 );
62
63   END_TEST;
64 }
65
66 int UtcDaliPixelDataCopyConstructor(void)
67 {
68   TestApplication application;
69
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 );
75
76   PixelData pixelDataCopy(pixelData);
77
78   DALI_TEST_EQUALS( (bool)pixelDataCopy, true, TEST_LOCATION );
79   END_TEST;
80 }
81
82 int UtcDaliPixelDataAssignmentOperator(void)
83 {
84   TestApplication application;
85
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 );
91
92   PixelData pixelData2;
93   DALI_TEST_EQUALS( (bool)pixelData2, false, TEST_LOCATION );
94
95   pixelData2 = pixelData;
96   DALI_TEST_EQUALS( (bool)pixelData2, true, TEST_LOCATION );
97
98   END_TEST;
99 }
100