License conversion from Flora to Apache 2.0
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / shader-effects / utc-Dali-SquareDissolveEffect.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
20 #include <stdlib.h>
21 #include <tet_api.h>
22
23 #include <dali/public-api/dali-core.h>
24 #include <dali-toolkit/dali-toolkit.h>
25
26 #include <dali-toolkit-test-suite-utils.h>
27
28 using namespace Dali;
29
30 static void Startup();
31 static void Cleanup();
32
33 extern "C" {
34   void (*tet_startup)() = Startup;
35   void (*tet_cleanup)() = Cleanup;
36 }
37
38 static void UtcDaliSquareDissolveEffectUninitialized();
39 static void UtcDaliSquareDissolveEffectPropertyNames();
40 static void UtcDaliSquareDissolveEffectDefaultValues();
41 static void UtcDaliSquareDissolveEffectCustomValues();
42
43 enum {
44   POSITIVE_TC_IDX = 0x01,
45   NEGATIVE_TC_IDX,
46 };
47
48 // Add test functionality for all APIs in the class (Positive and Negative)
49 extern "C" {
50   struct tet_testlist tet_testlist[] = {
51     { UtcDaliSquareDissolveEffectUninitialized, NEGATIVE_TC_IDX },
52     { UtcDaliSquareDissolveEffectPropertyNames, POSITIVE_TC_IDX },
53     { UtcDaliSquareDissolveEffectDefaultValues, POSITIVE_TC_IDX },
54     { UtcDaliSquareDissolveEffectCustomValues, POSITIVE_TC_IDX },
55     { NULL, 0 }
56   };
57 }
58
59 // Called only once before first test is run.
60 static void Startup()
61 {
62 }
63
64 // Called only once after last test is run
65 static void Cleanup()
66 {
67 }
68
69 // Create bitmap image
70 BitmapImage CreateBitmapImage()
71 {
72   BitmapImage image = BitmapImage::New(4,4,Pixel::RGBA8888);
73
74   PixelBuffer* pixbuf = image.GetBuffer();
75
76   // Using a 4x4 image gives a better blend with the GL implementation
77   // than a 3x3 image
78   for(size_t i=0; i<16; i++)
79   {
80     pixbuf[i*4+0] = 0xFF;
81     pixbuf[i*4+1] = 0xFF;
82     pixbuf[i*4+2] = 0xFF;
83     pixbuf[i*4+3] = 0xFF;
84   }
85
86   return image;
87 }
88
89 static void UtcDaliSquareDissolveEffectUninitialized()
90 {
91   ToolkitTestApplication application;
92
93   Toolkit::SquareDissolveEffect effect;
94
95   try
96   {
97     // New() must be called to create a SquareDissolveEffect or it wont be valid.
98     effect.SetStep( 2.0f );
99     DALI_TEST_CHECK( false );
100   }
101   catch (Dali::DaliException& e)
102   {
103     // Tests that a negative test of an assertion succeeds
104     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
105     DALI_TEST_CHECK(!effect);
106   }
107 }
108
109 static void UtcDaliSquareDissolveEffectPropertyNames()
110 {
111   ToolkitTestApplication application;
112
113   Toolkit::SquareDissolveEffect effect = Toolkit::SquareDissolveEffect::New();
114
115   // Check the names, this names are used in the shaders code,
116   // if they change the shader code has to be updated
117   DALI_TEST_EQUALS( effect.GetStepPropertyName(), "uStep", TEST_LOCATION );
118   DALI_TEST_EQUALS( effect.GetRowsPropertyName(), "uRows", TEST_LOCATION );
119   DALI_TEST_EQUALS( effect.GetColumnsPropertyName(), "uColumns", TEST_LOCATION );
120   DALI_TEST_EQUALS( effect.GetTexSizePropertyName(), "texSize", TEST_LOCATION );
121 }
122
123 static void UtcDaliSquareDissolveEffectDefaultValues()
124 {
125   ToolkitTestApplication application;
126
127   Toolkit::SquareDissolveEffect effect = Toolkit::SquareDissolveEffect::New();
128   DALI_TEST_CHECK( effect );
129
130   BitmapImage image = CreateBitmapImage();
131
132   ImageActor actor = ImageActor::New( image );
133   actor.SetSize( 100.0f, 100.0f );
134   actor.SetShaderEffect( effect );
135   Stage::GetCurrent().Add( actor );
136
137   application.SendNotification();
138   application.Render();
139
140   // Gets converted to opengl viewport coordinates
141   DALI_TEST_CHECK(
142       application.GetGlAbstraction().CheckUniformValue(
143           effect.GetStepPropertyName().c_str(),
144           0.1f ) );
145
146   DALI_TEST_CHECK(
147       application.GetGlAbstraction().CheckUniformValue(
148           effect.GetRowsPropertyName().c_str(),
149           25.0f ) );
150
151   DALI_TEST_CHECK(
152       application.GetGlAbstraction().CheckUniformValue(
153           effect.GetColumnsPropertyName().c_str(),
154           25.0f ) );
155
156   DALI_TEST_CHECK(
157       application.GetGlAbstraction().CheckUniformValue(
158           effect.GetTexSizePropertyName().c_str(),
159           Vector2(1.0f, 1.0f) ) );
160 }
161
162 static void UtcDaliSquareDissolveEffectCustomValues()
163 {
164   ToolkitTestApplication application;
165
166   Toolkit::SquareDissolveEffect effect = Toolkit::SquareDissolveEffect::New();
167   DALI_TEST_CHECK( effect );
168
169   BitmapImage image = CreateBitmapImage();
170
171   ImageActor actor = ImageActor::New( image );
172   actor.SetSize( 100.0f, 100.0f );
173
174   effect.SetStep( 2.0f );
175   effect.SetRows( 3.0f );
176   effect.SetColumns( 4.0f );
177   effect.SetTextureSize( Vector2(12.0f, 13.0f) );
178
179   actor.SetShaderEffect(effect);
180   Stage::GetCurrent().Add(actor);
181
182   application.SendNotification();
183   application.Render();
184
185   // Gets converted to opengl viewport coordinates
186   DALI_TEST_CHECK(
187       application.GetGlAbstraction().CheckUniformValue(
188           effect.GetStepPropertyName().c_str(),
189           2.0f ) );
190
191   DALI_TEST_CHECK(
192       application.GetGlAbstraction().CheckUniformValue(
193           effect.GetRowsPropertyName().c_str(),
194           3.0f ) );
195
196   DALI_TEST_CHECK(
197       application.GetGlAbstraction().CheckUniformValue(
198           effect.GetColumnsPropertyName().c_str(),
199           4.0f ) );
200
201   DALI_TEST_CHECK(
202       application.GetGlAbstraction().CheckUniformValue(
203           effect.GetTexSizePropertyName().c_str(),
204           Vector2(12.0f, 13.0f) ) );
205 }