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