2 * Copyright (c) 2014 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.
21 #include <dali/public-api/dali-core.h>
22 #include <dali/integration-api/bitmap.h>
23 #include <dali/devel-api/images/atlas.h>
24 #include <dali-test-suite-utils.h>
25 #include <test-native-image.h>
31 static const char* gTestImageFilename = "icon_wrt.png";
33 void PrepareResourceImage( TestApplication& application, unsigned int imageHeight, unsigned int imageWidth, Pixel::Format pixelFormat )
35 TestPlatformAbstraction& platform = application.GetPlatform();
36 platform.SetClosestImageSize(Vector2( 16, 16));
38 Integration::Bitmap* bitmap = Integration::Bitmap::New( Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, ResourcePolicy::RETAIN );
39 Integration::PixelBuffer* pixbuffer = bitmap->GetPackedPixelsProfile()->ReserveBuffer( pixelFormat, imageWidth, imageHeight, imageWidth, imageHeight );
40 unsigned int bytesPerPixel = GetBytesPerPixel( pixelFormat );
41 unsigned int initialColor = 0xFF;
42 memset( pixbuffer, initialColor, imageHeight*imageWidth*bytesPerPixel);
44 Integration::ResourcePointer resourcePtr(bitmap);
45 platform.SetResourceLoaded( 0, Dali::Integration::ResourceBitmap, resourcePtr );
50 void utc_dali_atlas_startup(void)
52 test_return_value = TET_UNDEF;
55 void utc_dali_atlas_cleanup(void)
57 test_return_value = TET_PASS;
61 int UtcDaliAtlasNew01(void)
63 TestApplication application;
65 // invoke default handle constructor
68 DALI_TEST_CHECK( !atlas );
71 atlas = Atlas::New( 16, 16 );
73 DALI_TEST_CHECK( atlas );
79 int UtcDaliAtlasUpload01(void)
81 TestApplication application;
83 Atlas atlas = Atlas::New( 16, 16, Pixel::RGBA8888 );
84 DALI_TEST_CHECK( atlas );
86 // Using correct pixel format
87 PixelBuffer* buffer = new PixelBuffer[16 * 16];
88 BufferImage image = BufferImage::New( buffer, 16, 16, Pixel::RGBA8888 );
89 DALI_TEST_CHECK( atlas.Upload( image, 0, 0 ) );
91 PrepareResourceImage( application, 16, 16, Pixel::RGBA8888 );
92 DALI_TEST_CHECK( atlas.Upload( gTestImageFilename, 0, 0 ) );
98 int UtcDaliAtlasUpload02(void)
100 TestApplication application;
102 Atlas atlas = Atlas::New( 10, 10, Pixel::RGBA8888 );
103 DALI_TEST_CHECK( atlas );
105 // Using INCORRECT pixel format
106 PixelBuffer* buffer = new PixelBuffer[16 * 16];
107 BufferImage image = BufferImage::New( buffer, 16, 16, Pixel::A8 );
108 DALI_TEST_CHECK( !atlas.Upload( image, 0, 0 ) );
110 PrepareResourceImage( application, 16, 16, Pixel::A8 );
111 DALI_TEST_CHECK( !atlas.Upload( gTestImageFilename, 0, 0 ) );
117 int UtcDaliAtlasUpload03(void)
119 TestApplication application;
121 Atlas atlas = Atlas::New( 10, 10, Pixel::RGBA8888 );
122 DALI_TEST_CHECK( atlas );
124 // Using image too big for atlas
125 PixelBuffer* buffer = new PixelBuffer[16 * 16];
126 BufferImage image = BufferImage::New( buffer, 16, 16, Pixel::RGBA8888 );
127 DALI_TEST_CHECK( !atlas.Upload( image, 0, 0 ) );
129 PrepareResourceImage( application, 16, 16, Pixel::RGBA8888 );
130 DALI_TEST_CHECK( !atlas.Upload( gTestImageFilename, 0, 0 ) );
136 int UtcDaliAtlasUpload04(void)
138 TestApplication application;
140 Atlas atlas = Atlas::New( 32, 32, Pixel::RGBA8888 );
141 DALI_TEST_CHECK( atlas );
143 // Using valid offsets
144 PixelBuffer* buffer = new PixelBuffer[16 * 16];
145 BufferImage image = BufferImage::New( buffer, 16, 16, Pixel::RGBA8888 );
147 DALI_TEST_CHECK( atlas.Upload( image, 0, 0 ) );
148 DALI_TEST_CHECK( atlas.Upload( image, 16, 0 ) );
149 DALI_TEST_CHECK( atlas.Upload( image, 0, 16 ) );
150 DALI_TEST_CHECK( atlas.Upload( image, 16, 16 ) );
152 PrepareResourceImage( application, 16, 16, Pixel::RGBA8888 );
153 DALI_TEST_CHECK( atlas.Upload( gTestImageFilename, 0, 0 ) );
154 DALI_TEST_CHECK( atlas.Upload( gTestImageFilename, 16, 0 ) );
155 DALI_TEST_CHECK( atlas.Upload( gTestImageFilename, 0, 16 ) );
156 DALI_TEST_CHECK( atlas.Upload( gTestImageFilename, 16, 16 ) );
162 int UtcDaliAtlasUpload05(void)
164 TestApplication application;
166 Atlas atlas = Atlas::New( 32, 32, Pixel::RGBA8888 );
167 DALI_TEST_CHECK( atlas );
169 // Using invalid offsets
170 PixelBuffer* buffer = new PixelBuffer[16 * 16];
171 BufferImage image = BufferImage::New( buffer, 16, 16, Pixel::RGBA8888 );
173 DALI_TEST_CHECK( !atlas.Upload( image, 0, 17 ) );
174 DALI_TEST_CHECK( !atlas.Upload( image, 17, 0 ) );
175 DALI_TEST_CHECK( !atlas.Upload( image, 17, 17 ) );
176 DALI_TEST_CHECK( !atlas.Upload( image, 99, 0 ) );
177 DALI_TEST_CHECK( !atlas.Upload( image, 0, 99 ) );
178 DALI_TEST_CHECK( !atlas.Upload( image, 99, 99 ) );
180 PrepareResourceImage( application, 16, 16, Pixel::RGBA8888 );
182 DALI_TEST_CHECK( !atlas.Upload( gTestImageFilename, 0, 17 ) );
183 DALI_TEST_CHECK( !atlas.Upload( gTestImageFilename, 17, 0 ) );
184 DALI_TEST_CHECK( !atlas.Upload( gTestImageFilename, 17, 17 ) );
185 DALI_TEST_CHECK( !atlas.Upload( gTestImageFilename, 99, 0 ) );
186 DALI_TEST_CHECK( !atlas.Upload( gTestImageFilename, 0, 99 ) );
187 DALI_TEST_CHECK( !atlas.Upload( gTestImageFilename, 99, 99 ) );