Adding new test harness
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-unmanaged / utc-Dali-SquareDissolveEffect.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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-toolkit/dali-toolkit.h>
21
22
23 using namespace Dali;
24
25 void square_dissolve_effect_startup(void)
26 {
27   test_return_value = TET_UNDEF;
28 }
29
30 void square_dissolve_effect_cleanup(void)
31 {
32   test_return_value = TET_PASS;
33 }
34
35
36 int UtcDaliSquareDissolveEffectUninitialized(void)
37 {
38   ToolkitTestApplication application;
39
40   Toolkit::SquareDissolveEffect effect;
41
42   try
43   {
44     // New() must be called to create a SquareDissolveEffect or it wont be valid.
45     effect.SetStep( 2.0f );
46     DALI_TEST_CHECK( false );
47   }
48   catch (Dali::DaliException& e)
49   {
50     // Tests that a negative test of an assertion succeeds
51     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
52     DALI_TEST_CHECK(!effect);
53   }
54   END_TEST;
55 }
56
57 int UtcDaliSquareDissolveEffectPropertyNames(void)
58 {
59   ToolkitTestApplication application;
60
61   Toolkit::SquareDissolveEffect effect = Toolkit::SquareDissolveEffect::New();
62
63   // Check the names, this names are used in the shaders code,
64   // if they change the shader code has to be updated
65   DALI_TEST_EQUALS( effect.GetStepPropertyName(), "uStep", TEST_LOCATION );
66   DALI_TEST_EQUALS( effect.GetRowsPropertyName(), "uRows", TEST_LOCATION );
67   DALI_TEST_EQUALS( effect.GetColumnsPropertyName(), "uColumns", TEST_LOCATION );
68   DALI_TEST_EQUALS( effect.GetTexSizePropertyName(), "texSize", TEST_LOCATION );
69   END_TEST;
70 }
71
72 int UtcDaliSquareDissolveEffectDefaultValues(void)
73 {
74   ToolkitTestApplication application;
75
76   Toolkit::SquareDissolveEffect effect = Toolkit::SquareDissolveEffect::New();
77   DALI_TEST_CHECK( effect );
78
79   BitmapImage image = CreateBitmapImage();
80
81   ImageActor actor = ImageActor::New( image );
82   actor.SetSize( 100.0f, 100.0f );
83   actor.SetShaderEffect( effect );
84   Stage::GetCurrent().Add( actor );
85
86   application.SendNotification();
87   application.Render();
88
89   // Gets converted to opengl viewport coordinates
90   DALI_TEST_CHECK(
91       application.GetGlAbstraction().CheckUniformValue(
92           effect.GetStepPropertyName().c_str(),
93           0.1f ) );
94
95   DALI_TEST_CHECK(
96       application.GetGlAbstraction().CheckUniformValue(
97           effect.GetRowsPropertyName().c_str(),
98           25.0f ) );
99
100   DALI_TEST_CHECK(
101       application.GetGlAbstraction().CheckUniformValue(
102           effect.GetColumnsPropertyName().c_str(),
103           25.0f ) );
104
105   DALI_TEST_CHECK(
106       application.GetGlAbstraction().CheckUniformValue(
107           effect.GetTexSizePropertyName().c_str(),
108           Vector2(1.0f, 1.0f) ) );
109   END_TEST;
110 }
111
112 int UtcDaliSquareDissolveEffectCustomValues(void)
113 {
114   ToolkitTestApplication application;
115
116   Toolkit::SquareDissolveEffect effect = Toolkit::SquareDissolveEffect::New();
117   DALI_TEST_CHECK( effect );
118
119   BitmapImage image = CreateBitmapImage();
120
121   ImageActor actor = ImageActor::New( image );
122   actor.SetSize( 100.0f, 100.0f );
123
124   effect.SetStep( 2.0f );
125   effect.SetRows( 3.0f );
126   effect.SetColumns( 4.0f );
127   effect.SetTextureSize( Vector2(12.0f, 13.0f) );
128
129   actor.SetShaderEffect(effect);
130   Stage::GetCurrent().Add(actor);
131
132   application.SendNotification();
133   application.Render();
134
135   // Gets converted to opengl viewport coordinates
136   DALI_TEST_CHECK(
137       application.GetGlAbstraction().CheckUniformValue(
138           effect.GetStepPropertyName().c_str(),
139           2.0f ) );
140
141   DALI_TEST_CHECK(
142       application.GetGlAbstraction().CheckUniformValue(
143           effect.GetRowsPropertyName().c_str(),
144           3.0f ) );
145
146   DALI_TEST_CHECK(
147       application.GetGlAbstraction().CheckUniformValue(
148           effect.GetColumnsPropertyName().c_str(),
149           4.0f ) );
150
151   DALI_TEST_CHECK(
152       application.GetGlAbstraction().CheckUniformValue(
153           effect.GetTexSizePropertyName().c_str(),
154           Vector2(12.0f, 13.0f) ) );
155   END_TEST;
156 }