New size negotiation
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-CarouselEffect.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 using namespace Dali;
24
25
26 void carousel_effect_startup(void)
27 {
28   test_return_value = TET_UNDEF;
29 }
30
31 void carousel_effect_cleanup(void)
32 {
33   test_return_value = TET_PASS;
34 }
35
36
37 int UtcDaliCarouselEffectUninitialized(void)
38 {
39   ToolkitTestApplication application;
40
41   Toolkit::CarouselEffect effect;
42
43   try
44   {
45     // New() must be called to create a CarouselEffect or it wont be valid.
46     effect.SetRadius( 100.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 UtcDaliCarouselEffectPropertyNames(void)
59 {
60   ToolkitTestApplication application;
61
62   Toolkit::CarouselEffect effect = Toolkit::CarouselEffect::New();
63
64   // Check the names, these names are used in the shaders code,
65   // if they change the shader code has to be updated
66   DALI_TEST_EQUALS( effect.GetRadiusPropertyName(), "uRadius", TEST_LOCATION );
67   DALI_TEST_EQUALS( effect.GetCenterPropertyName(), "uCenter", TEST_LOCATION );
68   DALI_TEST_EQUALS( effect.GetAnglePerUnitPropertyName(), "uAnglePerUnit", TEST_LOCATION );
69   END_TEST;
70 }
71
72 int UtcDaliCarouselEffectDefaultValues(void)
73 {
74   ToolkitTestApplication application;
75
76   Toolkit::CarouselEffect effect = Toolkit::CarouselEffect::New();
77   DALI_TEST_CHECK( effect );
78
79   BufferImage image = CreateBufferImage();
80
81   ImageActor actor = ImageActor::New( image );
82   actor.SetSize( 100.0f, 100.0f );
83
84   const float radiusValue(0.0f);
85   const Vector2 centerValue(0.0f, 0.0f);
86   const Vector2 anglePerUnitValue(0.0f, 0.0f);
87
88   actor.SetShaderEffect( effect );
89   Stage::GetCurrent().Add( actor );
90
91   application.SendNotification();
92   application.Render();
93
94   TestGlAbstraction& gl = application.GetGlAbstraction();
95   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetRadiusPropertyName().c_str(), radiusValue ) );
96   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), centerValue ) );
97   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAnglePerUnitPropertyName().c_str(), anglePerUnitValue ) );
98   END_TEST;
99 }
100
101 int UtcDaliCarouselEffectCustomValues(void)
102 {
103   ToolkitTestApplication application;
104
105   Toolkit::CarouselEffect effect = Toolkit::CarouselEffect::New();
106   DALI_TEST_CHECK( effect );
107
108   BufferImage image = CreateBufferImage();
109
110   ImageActor actor = ImageActor::New( image );
111   actor.SetSize( 100.0f, 100.0f );
112
113   const float radiusValue(100.0f);
114   const Vector2 centerValue(150.0f, 200.0f);
115   const Vector2 anglePerUnitValue(0.1f, 0.25f);
116
117   effect.SetRadius( radiusValue );
118   effect.SetCenter( centerValue );
119   effect.SetAnglePerUnit( anglePerUnitValue );
120
121   actor.SetShaderEffect(effect);
122   Stage::GetCurrent().Add(actor);
123
124   application.SendNotification();
125   application.Render();
126
127   TestGlAbstraction& gl = application.GetGlAbstraction();
128   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetRadiusPropertyName().c_str(), radiusValue ) );
129   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetCenterPropertyName().c_str(), centerValue ) );
130   DALI_TEST_CHECK( gl.CheckUniformValue( effect.GetAnglePerUnitPropertyName().c_str(), anglePerUnitValue ) );
131   END_TEST;
132 }