Dali-Text: Keyboard Shortcuts
[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
26 using namespace Dali;
27 using namespace Dali::Toolkit;
28
29 namespace
30 {
31 } // namespace
32
33
34 void dali_image_startup(void)
35 {
36   test_return_value = TET_UNDEF;
37 }
38
39 void dali_image_cleanup(void)
40 {
41   test_return_value = TET_PASS;
42 }
43
44 int UtcDaliImageConvertFrameBufferToUrl1(void)
45 {
46   ToolkitTestApplication application;
47   tet_infoline( "UtcDaliImageConvertFrameBufferToUrl1" );
48
49   unsigned int width(64);
50   unsigned int height(64);
51   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
52
53   DALI_TEST_CHECK( frameBuffer );
54   std::string url = Dali::Toolkit::Image::GenerateUrl( frameBuffer, Pixel::Format::RGBA8888, width, height );
55
56   DALI_TEST_CHECK( url.size() > 0u );
57
58   END_TEST;
59 }
60
61
62 int UtcDaliImageConvertFrameBufferToUrl2(void)
63 {
64   ToolkitTestApplication application;
65   tet_infoline( "UtcDaliImageConvertFrameBufferToUrl2" );
66
67   unsigned int width(64);
68   unsigned int height(64);
69   FrameBuffer frameBuffer = FrameBuffer::New( width, height, FrameBuffer::Attachment::NONE );
70
71   Texture texture = Texture::New( TextureType::TEXTURE_2D, Pixel::RGBA8888, width, height );
72   frameBuffer.AttachColorTexture( texture );
73
74   DALI_TEST_CHECK( Dali::Toolkit::Image::GenerateUrl( frameBuffer, 0 ).size() > 0u );
75
76   END_TEST;
77 }
78
79
80 int UtcDaliImageConvertPixelDataToUrl(void)
81 {
82   ToolkitTestApplication application;
83   tet_infoline( "UtcDaliImageConvertPixelDataToUrl" );
84
85   unsigned int width(64);
86   unsigned int height(64);
87   unsigned int bufferSize = width*height*Pixel::GetBytesPerPixel( Pixel::RGB888 );
88
89   unsigned char* buffer= reinterpret_cast<unsigned char*>( malloc( bufferSize ) );
90   PixelData pixelData = PixelData::New( buffer, bufferSize, width, height, Pixel::RGB888, PixelData::FREE );
91
92   DALI_TEST_CHECK( Dali::Toolkit::Image::GenerateUrl( pixelData ).size() > 0u );
93
94   END_TEST;
95 }
96
97
98 int UtcDaliImageConvertNativeImageSourceToUrl(void)
99 {
100   ToolkitTestApplication application;
101   tet_infoline( "UtcDaliImageConvertNativeImageSourceToUrl" );
102
103   unsigned int width(64);
104   unsigned int height(64);
105   try
106   {
107     NativeImageSourcePtr nativeImageSource = NativeImageSource::New(width, height, NativeImageSource::COLOR_DEPTH_DEFAULT );
108
109     DALI_TEST_CHECK( Dali::Toolkit::Image::GenerateUrl( nativeImageSource ).size() > 0u );
110   }
111   catch(Dali::DaliException& e)
112   {
113     DALI_TEST_PRINT_ASSERT( e );
114     DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
115   }
116   catch(...)
117   {
118     tet_printf("Assertion test failed - wrong Exception\n" );
119     tet_result(TET_FAIL);
120   }
121
122   END_TEST;
123 }