Merge "(AutomatedTests) Ensure warnings are shown as errors" into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-FrameBufferImage.cpp
1 /*
2  * Copyright (c) 2014 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 <iostream>
19 #include <algorithm>
20
21 #include <stdlib.h>
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
24 #include <test-native-image.h>
25 #include <dali/integration-api/gl-abstraction.h>
26
27 using std::max;
28 using namespace Dali;
29
30 void utc_dali_framebuffer_startup(void)
31 {
32   test_return_value = TET_UNDEF;
33 }
34
35 void utc_dali_framebuffer_cleanup(void)
36 {
37   test_return_value = TET_PASS;
38 }
39
40 int UtcDaliFrameBufferImageNew01(void)
41 {
42   TestApplication application;
43
44   tet_infoline("UtcDaliFrameBufferImageNew01 - FrameBufferImage::New(unsigned int, unsigned int, Pixel::Format)");
45
46   // invoke default handle constructor
47   FrameBufferImage image;
48   Vector2 stageSize = Stage::GetCurrent().GetSize();
49
50   // initialise handle
51   image = FrameBufferImage::New();            // create framebuffer with the same dimensions as the stage
52   ImageActor actor=ImageActor::New(image);
53   Stage::GetCurrent().Add(actor);
54
55   application.SendNotification();
56   application.Render();
57   application.Render();
58   application.SendNotification();
59
60   DALI_TEST_CHECK( image );
61   DALI_TEST_EQUALS((float)image.GetWidth(), stageSize.width, TEST_LOCATION);
62   DALI_TEST_EQUALS((float)image.GetHeight(), stageSize.height, TEST_LOCATION);
63
64   image = FrameBufferImage::New(16, 16);      // create framebuffer with dimensions of 16x16
65   actor.SetImage(image);
66
67   application.SendNotification();
68   application.Render();
69   application.Render();
70   application.SendNotification();
71
72   DALI_TEST_CHECK( image );
73   DALI_TEST_EQUALS(image.GetWidth(), 16u, TEST_LOCATION);
74   DALI_TEST_EQUALS(image.GetHeight(), 16u, TEST_LOCATION);
75   END_TEST;
76 }
77
78 int UtcDaliFrameBufferImageNew02(void)
79 {
80   TestApplication application;
81
82   tet_infoline("UtcDaliFrameBufferImageNew02 - FrameBufferImage::New(NativeImageInterface&)");
83
84   // invoke default handle constructor
85   FrameBufferImage image;
86   TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
87
88   DALI_TEST_CHECK( !image );
89
90   // initialise handle
91   image = FrameBufferImage::New(*(nativeImage.Get()));
92
93   DALI_TEST_CHECK( image );
94   END_TEST;
95 }
96
97 int UtcDaliFrameBufferImageNew03(void)
98 {
99   TestApplication application;
100
101   tet_infoline("UtcDaliFrameBufferImageNew03 - FrameBufferImage::New(NativeImageInterface&, ReleasePolicy)");
102
103   // invoke default handle constructor
104   FrameBufferImage image;
105   TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
106
107   DALI_TEST_CHECK( !image );
108
109   // initialise handle with UNUSED release policy
110   image = FrameBufferImage::New(*(nativeImage.Get()), Image::UNUSED);
111
112   DALI_TEST_CHECK( image );
113   DALI_TEST_EQUALS( image.GetReleasePolicy(), Image::UNUSED, TEST_LOCATION );
114
115   // initialise handle with NEVER release policy
116   image.Reset();
117   DALI_TEST_CHECK( !image );
118
119   image = FrameBufferImage::New(*(nativeImage.Get()), Image::NEVER);
120
121   DALI_TEST_CHECK( image );
122   DALI_TEST_EQUALS( image.GetReleasePolicy(), Image::NEVER, TEST_LOCATION );
123
124   END_TEST;
125 }
126
127 int UtcDaliFrameBufferImageAttachments01(void)
128 {
129   TestApplication application;
130
131   tet_infoline("UtcDaliFrameBufferImageAttachments01 - FrameBufferImage::New(unsigned int, unsigned int, Pixel::Format, RenderBuffer::Format)");
132
133   // invoke default handle constructor
134   FrameBufferImage image;
135
136   // initialise handle
137   image = FrameBufferImage::New(64, 64, Pixel::RGBA8888, RenderBuffer::COLOR);       // create framebuffer with Color buffer
138   ImageActor actor=ImageActor::New(image);
139   Stage::GetCurrent().Add(actor);
140
141   application.SendNotification();
142   application.Render();
143   application.Render();
144   application.SendNotification();
145
146   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
147   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
148   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
149
150   END_TEST;
151 }
152
153 int UtcDaliFrameBufferImageAttachments02(void)
154 {
155   TestApplication application;
156
157   tet_infoline("UtcDaliFrameBufferImageAttachments02 - FrameBufferImage::New(unsigned int, unsigned int, Pixel::Format, RenderBuffer::Format)");
158
159   // invoke default handle constructor
160   FrameBufferImage image;
161
162   // initialise handle
163   image = FrameBufferImage::New(64, 64, Pixel::RGBA8888, RenderBuffer::COLOR_DEPTH); // create framebuffer with Color and Depth buffer
164   ImageActor actor=ImageActor::New(image);
165   Stage::GetCurrent().Add(actor);
166
167   application.SendNotification();
168   application.Render();
169   application.Render();
170   application.SendNotification();
171
172   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
173   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
174   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
175
176   END_TEST;
177 }
178
179 int UtcDaliFrameBufferImageAttachments03(void)
180 {
181   TestApplication application;
182
183   tet_infoline("UtcDaliFrameBufferImageAttachments03 - FrameBufferImage::New(unsigned int, unsigned int, Pixel::Format, RenderBuffer::Format)");
184
185   // invoke default handle constructor
186   FrameBufferImage image;
187
188   // initialise handle
189   image = FrameBufferImage::New(64, 64, Pixel::RGBA8888, RenderBuffer::COLOR_STENCIL);  // create framebuffer with Color and Stencil
190   ImageActor actor=ImageActor::New(image);
191   Stage::GetCurrent().Add(actor);
192
193   application.SendNotification();
194   application.Render();
195   application.Render();
196   application.SendNotification();
197
198   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
199   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_FALSE, TEST_LOCATION);
200   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
201
202   END_TEST;
203 }
204
205 int UtcDaliFrameBufferImageAttachments04(void)
206 {
207   TestApplication application;
208
209   tet_infoline("UtcDaliFrameBufferImageAttachments04 - FrameBufferImage::New(unsigned int, unsigned int, Pixel::Format, RenderBuffer::Format)");
210
211   // invoke default handle constructor
212   FrameBufferImage image;
213
214   // initialise handle
215   image = FrameBufferImage::New(64, 64, Pixel::RGBA8888, RenderBuffer::COLOR_DEPTH_STENCIL);  // create framebuffer with Color, Depth and Stencil buffers
216   ImageActor actor=ImageActor::New(image);
217   Stage::GetCurrent().Add(actor);
218
219   application.SendNotification();
220   application.Render();
221   application.Render();
222   application.SendNotification();
223
224   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferColorAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
225   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferDepthAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
226   DALI_TEST_EQUALS(application.GetGlAbstraction().CheckFramebufferStencilAttachment(), (GLenum)GL_TRUE, TEST_LOCATION);
227
228   END_TEST;
229 }
230
231 int UtcDaliFrameBufferImageDownCast(void)
232 {
233   TestApplication application;
234   tet_infoline("Testing Dali::FrameBufferImage::DownCast()");
235
236   FrameBufferImage image = FrameBufferImage::New();
237
238   BaseHandle object(image);
239
240   FrameBufferImage image2 = FrameBufferImage::DownCast(object);
241   DALI_TEST_CHECK(image2);
242
243   FrameBufferImage image3 = DownCast< FrameBufferImage >(object);
244   DALI_TEST_CHECK(image3);
245
246   BaseHandle unInitializedObject;
247   FrameBufferImage image4 = FrameBufferImage::DownCast(unInitializedObject);
248   DALI_TEST_CHECK(!image4);
249
250   FrameBufferImage image5 = DownCast< FrameBufferImage >(unInitializedObject);
251   DALI_TEST_CHECK(!image5);
252
253   Image image6 = FrameBufferImage::New();
254   FrameBufferImage image7 = FrameBufferImage::DownCast(image6);
255   DALI_TEST_CHECK(image7);
256   END_TEST;
257 }