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