Refactoring ImageVisualShaderFactory::GetShader
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Image.cpp
1 /*
2  * Copyright (c) 2019 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 #include <iostream>
18 #include <stdlib.h>
19 #include <dali-toolkit-test-suite-utils.h>
20 #include <dali/public-api/rendering/texture.h>
21 #include <dali/public-api/images/pixel-data.h>
22 #include <dali/public-api/rendering/frame-buffer.h>
23 #include <dali/public-api/adaptor-framework/native-image-source.h>
24 #include <dali-toolkit/public-api/image-loader/image.h>
25 #include <dali-toolkit/public-api/image-loader/image-url.h>
26
27 using namespace Dali;
28 using namespace Dali::Toolkit;
29
30 namespace
31 {
32 } // namespace
33
34
35 void dali_image_startup(void)
36 {
37   test_return_value = TET_UNDEF;
38 }
39
40 void dali_image_cleanup(void)
41 {
42   test_return_value = TET_PASS;
43 }
44
45 int UtcDaliImageConvertFrameBufferToUrl1(void)
46 {
47   ToolkitTestApplication application;
48   tet_infoline( "UtcDaliImageConvertFrameBufferToUrl1" );
49
50   unsigned int width(64);
51   unsigned int height(64);
52   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
53
54   DALI_TEST_CHECK( frameBuffer );
55   ImageUrl url = Dali::Toolkit::Image::GenerateUrl( frameBuffer, Pixel::Format::RGBA8888, width, height );
56
57   DALI_TEST_CHECK( url.GetUrl().size() > 0u );
58
59   END_TEST;
60 }
61
62
63 int UtcDaliImageConvertFrameBufferToUrl2(void)
64 {
65   ToolkitTestApplication application;
66   tet_infoline( "UtcDaliImageConvertFrameBufferToUrl2" );
67
68   unsigned int width(64);
69   unsigned int height(64);
70   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
71
72   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
73   frameBuffer.AttachColorTexture( texture );
74
75   DALI_TEST_CHECK( Dali::Toolkit::Image::GenerateUrl( frameBuffer, 0 ).GetUrl().size() > 0u );
76
77   END_TEST;
78 }
79
80
81 int UtcDaliImageConvertPixelDataToUrl(void)
82 {
83   ToolkitTestApplication application;
84   tet_infoline( "UtcDaliImageConvertPixelDataToUrl" );
85
86   unsigned int width(64);
87   unsigned int height(64);
88   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::RGB888 );
89
90   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
91   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
92
93   DALI_TEST_CHECK( Dali::Toolkit::Image::GenerateUrl( pixelData ).GetUrl().size() > 0u );
94
95   END_TEST;
96 }
97
98
99 int UtcDaliImageConvertNativeImageSourceToUrl(void)
100 {
101   ToolkitTestApplication application;
102   tet_infoline( "UtcDaliImageConvertNativeImageSourceToUrl" );
103
104   unsigned int width(64);
105   unsigned int height(64);
106   try
107   {
108     NativeImageSourcePtr nativeImageSource = NativeImageSource::New(width, height, NativeImageSource::COLOR_DEPTH_DEFAULT );
109
110     DALI_TEST_CHECK( Dali::Toolkit::Image::GenerateUrl( nativeImageSource ).GetUrl().size() > 0u );
111   }
112   catch(Dali::DaliException& e)
113   {
114     DALI_TEST_PRINT_ASSERT( e );
115     DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
116   }
117   catch(...)
118   {
119     tet_printf("Assertion test failed - wrong Exception\n" );
120     tet_result(TET_FAIL);
121   }
122
123   END_TEST;
124 }
125
126 int UtcDaliImageConvertEncodedImageBufferToUrl(void)
127 {
128   ToolkitTestApplication application;
129   tet_infoline( "UtcDaliImageConvertEncodedImageBufferToUrl" );
130
131   Dali::Vector<uint8_t> buffer;
132   buffer.PushBack(0x11);
133   buffer.PushBack(0x22);
134   buffer.PushBack(0x33);
135
136   DALI_TEST_CHECK( Dali::Toolkit::Image::GenerateUrl( EncodedImageBuffer::New(buffer) ).GetUrl().size() > 0u );
137
138   END_TEST;
139 }