385a56992ce83e4aa5673cadecf83ac592ba323e
[platform/core/uifw/dali-toolkit.git] / automated-tests / TET / dali-test-suite / shader-effects / utc-Dali-ShadowView.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
19 #include <stdlib.h>
20 #include <tet_api.h>
21
22 #include <dali/public-api/dali-core.h>
23 #include <dali-toolkit/dali-toolkit.h>
24
25 #include <dali-toolkit-test-suite-utils.h>
26
27 using namespace Dali;
28 using namespace Dali::Toolkit;
29
30
31 static void Startup();
32 static void Cleanup();
33
34 extern "C" {
35   void (*tet_startup)() = Startup;
36   void (*tet_cleanup)() = Cleanup;
37 }
38
39 static void UtcDaliShadowViewUninitialized();
40 static void UtcDaliShadowViewNew();
41 static void UtcDaliShadowViewDownCast();
42 static void UtcDaliShadowViewPropertyNames();
43 static void UtcDaliShadowViewAddRemove();
44 static void UtcDaliShadowViewActivateDeactivate();
45
46
47 enum {
48   POSITIVE_TC_IDX = 0x01,
49   NEGATIVE_TC_IDX,
50 };
51
52 // Add test functionality for all APIs in the class (Positive and Negative)
53 extern "C" {
54   struct tet_testlist tet_testlist[] = {
55       { UtcDaliShadowViewUninitialized, NEGATIVE_TC_IDX },
56       { UtcDaliShadowViewNew, POSITIVE_TC_IDX },
57       { UtcDaliShadowViewDownCast, POSITIVE_TC_IDX },
58       { UtcDaliShadowViewPropertyNames, POSITIVE_TC_IDX },
59       { UtcDaliShadowViewAddRemove, POSITIVE_TC_IDX },
60       { UtcDaliShadowViewActivateDeactivate, POSITIVE_TC_IDX },
61     { NULL, 0 }
62   };
63 }
64
65 // Called only once before first test is run.
66 static void Startup()
67 {
68 }
69
70 // Called only once after last test is run
71 static void Cleanup()
72 {
73 }
74
75 // Negative test case for a method
76 static void UtcDaliShadowViewUninitialized()
77 {
78   ToolkitTestApplication application;
79   tet_infoline("UtcDaliShadowViewUninitialized");
80
81   Toolkit::ShadowView view;
82   try
83   {
84     // New() must be called to create a GaussianBlurView or it wont be valid.
85     Actor a = Actor::New();
86     view.Add( a );
87     DALI_TEST_CHECK( false );
88   }
89   catch (Dali::DaliException& e)
90   {
91     // Tests that a negative test of an assertion succeeds
92     tet_printf("Assertion %s failed at %s\n", e.mCondition.c_str(), e.mLocation.c_str());
93     DALI_TEST_CHECK(!view);
94   }
95 }
96
97 // Positive test case for a method
98 static void UtcDaliShadowViewNew()
99 {
100   ToolkitTestApplication application;
101   tet_infoline("UtcDaliShadowViewNew");
102
103   Toolkit::ShadowView view = Toolkit::ShadowView::New();
104   DALI_TEST_CHECK( view );
105
106   Toolkit::ShadowView view2 = Toolkit::ShadowView::New(1.0f, 1.0f);
107   DALI_TEST_CHECK( view2 );
108 }
109
110 // Positive test case for a method
111 static void UtcDaliShadowViewDownCast()
112 {
113   ToolkitTestApplication application;
114   tet_infoline("UtcDaliShadowViewDownCast");
115
116   Toolkit::ShadowView view = Toolkit::ShadowView::New();
117   BaseHandle handle(view);
118
119   Toolkit::ShadowView shadowView = Toolkit::ShadowView::DownCast( handle );
120   DALI_TEST_CHECK( view );
121   DALI_TEST_CHECK( shadowView );
122   DALI_TEST_CHECK( shadowView == view );
123 }
124
125 // Positive test case for a method
126 static void UtcDaliShadowViewPropertyNames()
127 {
128   ToolkitTestApplication application;
129   tet_infoline("UtcDaliShadowViewPropertyNames");
130
131   Toolkit::ShadowView view = Toolkit::ShadowView::New();
132   DALI_TEST_CHECK( view );
133
134   // Check the names, this names are used in the shader code,
135   // if they change in the shader code, then it has to be updated here.
136   DALI_TEST_EQUALS( view.GetBlurStrengthPropertyIndex(), view.GetPropertyIndex("BlurStrengthProperty"), TEST_LOCATION );
137   DALI_TEST_EQUALS( view.GetShadowColorPropertyIndex(), view.GetPropertyIndex("ShadowColorProperty"), TEST_LOCATION );
138 }
139
140 // Positive test case for a method
141 static void UtcDaliShadowViewAddRemove()
142 {
143   ToolkitTestApplication application;
144   tet_infoline("UtcDaliShadowViewAddRemove");
145
146   Toolkit::ShadowView view = Toolkit::ShadowView::New();
147   DALI_TEST_CHECK( view );
148
149   Actor actor = Actor::New();
150   DALI_TEST_CHECK( !actor.OnStage() );
151
152
153   view.SetParentOrigin(ParentOrigin::CENTER);
154   view.SetSize(Stage::GetCurrent().GetSize());
155   view.Add(actor);
156   Stage::GetCurrent().Add(view);
157
158   DALI_TEST_CHECK( actor.OnStage() );
159
160   view.Remove(actor);
161
162   DALI_TEST_CHECK( !actor.OnStage() );
163 }
164
165 // Positive test case for a method
166 static void UtcDaliShadowViewActivateDeactivate()
167 {
168   ToolkitTestApplication application;
169   tet_infoline("UtcDaliShadowViewActivateDeactivate");
170
171   Toolkit::ShadowView view = Toolkit::ShadowView::New();
172   DALI_TEST_CHECK( view );
173
174   RenderTaskList taskList = Stage::GetCurrent().GetRenderTaskList();
175   DALI_TEST_CHECK( 1u == taskList.GetTaskCount() );
176
177   view.SetParentOrigin(ParentOrigin::CENTER);
178   view.SetSize(Stage::GetCurrent().GetSize());
179   view.Add(Actor::New());
180   Stage::GetCurrent().Add(view);
181   view.Activate();
182
183   RenderTaskList taskList2 = Stage::GetCurrent().GetRenderTaskList();
184   DALI_TEST_CHECK( 1u != taskList2.GetTaskCount() );
185
186   view.Deactivate();
187
188   RenderTaskList taskList3 = Stage::GetCurrent().GetRenderTaskList();
189   DALI_TEST_CHECK( 1u == taskList3.GetTaskCount() );
190 }