Updating code formatting
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Image.cpp
1 /*
2  * Copyright (c) 2022 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 <stdlib.h>
18 #include <iostream>
19
20 #include <dali-toolkit-test-suite-utils.h>
21
22 #include <dali-toolkit/public-api/image-loader/image-url.h>
23 #include <dali-toolkit/public-api/image-loader/image.h>
24 #include <dali/public-api/adaptor-framework/native-image-source.h>
25 #include <dali/public-api/images/pixel-data.h>
26 #include <dali/public-api/rendering/frame-buffer.h>
27 #include <dali/public-api/rendering/texture.h>
28
29 using namespace Dali;
30 using namespace Dali::Toolkit;
31
32 namespace
33 {
34 } // namespace
35
36 void dali_image_startup(void)
37 {
38   test_return_value = TET_UNDEF;
39 }
40
41 void dali_image_cleanup(void)
42 {
43   test_return_value = TET_PASS;
44 }
45
46 int UtcDaliImageConvertFrameBufferToUrl1(void)
47 {
48   ToolkitTestApplication application;
49   tet_infoline("UtcDaliImageConvertFrameBufferToUrl1");
50
51   unsigned int width(64);
52   unsigned int height(64);
53   FrameBuffer  frameBuffer = FrameBuffer::New(width, height, FrameBuffer::Attachment::NONE);
54
55   DALI_TEST_CHECK(frameBuffer);
56   ImageUrl url = Dali::Toolkit::Image::GenerateUrl(frameBuffer, Pixel::Format::RGBA8888, width, height);
57
58   DALI_TEST_CHECK(url.GetUrl().size() > 0u);
59
60   END_TEST;
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 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).GetUrl().size() > 0u);
93
94   END_TEST;
95 }
96
97 int UtcDaliImageConvertNativeImageSourceToUrl(void)
98 {
99   ToolkitTestApplication application;
100   tet_infoline("UtcDaliImageConvertNativeImageSourceToUrl");
101
102   unsigned int width(64);
103   unsigned int height(64);
104   try
105   {
106     NativeImageSourcePtr nativeImageSource = NativeImageSource::New(width, height, NativeImageSource::COLOR_DEPTH_DEFAULT);
107
108     DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(nativeImageSource).GetUrl().size() > 0u);
109   }
110   catch(Dali::DaliException& e)
111   {
112     DALI_TEST_PRINT_ASSERT(e);
113     DALI_TEST_ASSERT(e, "Adaptor::IsAvailable()", TEST_LOCATION);
114   }
115   catch(...)
116   {
117     tet_printf("Assertion test failed - wrong Exception\n");
118     tet_result(TET_FAIL);
119   }
120
121   END_TEST;
122 }
123
124 int UtcDaliImageConvertEncodedImageBufferToUrl(void)
125 {
126   ToolkitTestApplication application;
127   tet_infoline("UtcDaliImageConvertEncodedImageBufferToUrl");
128
129   Dali::Vector<uint8_t> buffer;
130   buffer.PushBack(0x11);
131   buffer.PushBack(0x22);
132   buffer.PushBack(0x33);
133
134   DALI_TEST_CHECK(Dali::Toolkit::Image::GenerateUrl(EncodedImageBuffer::New(buffer)).GetUrl().size() > 0u);
135
136   END_TEST;
137 }