Merge "New DepthTestMode API in Renderer" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-devel / utc-Dali-PixelData.cpp
1 /*
2  * Copyright (c) 2015 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/devel-api/images/pixel-data.h>
22 #include <dali/public-api/images/pixel.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   PixelDataPtr pixelData = PixelData::New( buffer, 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   DALI_TEST_CHECK( pixelData->GetBuffer() == buffer );
43
44   END_TEST;
45 }
46
47 int UtcDaliPixelData02(void)
48 {
49   TestApplication application;
50
51   unsigned int width = 10u;
52   unsigned int height = 10u;
53   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::L8 );
54   unsigned char* buffer = new unsigned char [ bufferSize ];
55   buffer[0] = 'a';
56
57   PixelDataPtr pixelData2 = PixelData::New( buffer, width, height, Pixel::L8, PixelData::DELETE_ARRAY );
58
59   DALI_TEST_CHECK( pixelData2 );
60   DALI_TEST_CHECK( pixelData2->GetBuffer()[0] == 'a' );
61
62   buffer[0] = 'b';
63   DALI_TEST_CHECK( pixelData2->GetBuffer()[0] == 'b' );
64
65   END_TEST;
66 }
67
68 int UtcDaliPixelDataNonCopyable(void)
69 {
70   // we want to make sure that PixelData is not copyable (its copy constructor is not defined)
71   // this test will stop compiling if PixelData has compiler generated copy constructor
72   DALI_COMPILE_TIME_ASSERT( !__has_trivial_copy( PixelData ) );
73
74   DALI_TEST_CHECK( true );
75   END_TEST;
76 }