AnimatableProperty Set/Bake now resets properly.
[platform/core/uifw/dali-core.git] / automated-tests / src / dali-internal / utc-Dali-Internal-Handles.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 <dali-test-suite-utils.h>
19 #include <dali/public-api/dali-core.h>
20 #include <mesh-builder.h>
21
22 #include <stdlib.h>
23 #include <iostream>
24
25 // Internal headers are allowed here
26 #include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
27 #include <dali/internal/event/rendering/renderer-impl.h>
28 #include <dali/internal/update/manager/update-manager.h>
29 #include <dali/internal/update/rendering/scene-graph-renderer.h>
30
31 using namespace Dali;
32
33 void utc_dali_internal_handles_startup()
34 {
35   test_return_value = TET_UNDEF;
36 }
37
38 void utc_dali_internal_handles_cleanup()
39 {
40   test_return_value = TET_PASS;
41 }
42
43 int UtcDaliCameraActorConstructorRefObject(void)
44 {
45   TestApplication application;
46   tet_infoline("Testing Dali::CameraActor::CameraActor(Internal::CameraActor*)");
47
48   CameraActor actor(NULL);
49
50   DALI_TEST_CHECK(!actor);
51   END_TEST;
52 }
53
54 namespace Impl
55 {
56 struct DerivedRenderer : public Dali::Internal::Renderer
57 {
58   static IntrusivePtr<DerivedRenderer> New()
59   {
60     auto                          sceneObjectKey = Dali::Internal::SceneGraph::Renderer::NewKey();
61     IntrusivePtr<DerivedRenderer> impl           = new DerivedRenderer(sceneObjectKey.Get());
62
63     // transfer scene object ownership to update manager
64     Internal::EventThreadServices&       eventThreadServices = impl->GetEventThreadServices();
65     Internal::SceneGraph::UpdateManager& updateManager       = eventThreadServices.GetUpdateManager();
66     AddRendererMessage(updateManager, sceneObjectKey);
67     eventThreadServices.RegisterObject(impl.Get());
68     return impl;
69   }
70
71   DerivedRenderer(const Dali::Internal::SceneGraph::Renderer* sceneObject)
72   : Internal::Renderer(sceneObject)
73   {
74   }
75   ~DerivedRenderer()
76   {
77   }
78 };
79 } // namespace Impl
80
81 struct DerivedRenderer : public Renderer
82 {
83   static DerivedRenderer New(Geometry geometry, Shader shader)
84   {
85     IntrusivePtr<Impl::DerivedRenderer> impl = Impl::DerivedRenderer::New();
86     impl->SetGeometry(GetImplementation(geometry));
87     impl->SetShader(GetImplementation(shader));
88     DerivedRenderer custom(impl.Get());
89     return custom;
90   }
91   DerivedRenderer()  = default;
92   ~DerivedRenderer() = default;
93   DerivedRenderer(Impl::DerivedRenderer* impl)
94   : Renderer(impl)
95   {
96   }
97 };
98
99 int UtcDaliInternalHandleRendererPropertyComponents(void)
100 {
101   TestApplication application;
102
103   Dali::TypeRegistration typeRegistration(typeid(DerivedRenderer), typeid(Dali::Renderer), nullptr);
104
105   Shader   shader   = Shader::New("VertexSource", "FragmentSource");
106   Geometry geometry = CreateQuadGeometry();
107   auto     derived  = DerivedRenderer::New(geometry, shader);
108   Actor    actor    = Actor::New();
109   actor.AddRenderer(derived);
110   application.GetScene().Add(actor);
111
112   const Property::Index foobarIndex = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX;
113   const Property::Index fooIndex    = foobarIndex + 1;
114   const Property::Index barIndex    = foobarIndex + 2;
115
116   const Property::Index rgbIndex   = foobarIndex + 3;
117   const Property::Index redIndex   = rgbIndex + 1;
118   const Property::Index greenIndex = rgbIndex + 2;
119   const Property::Index blueIndex  = rgbIndex + 3;
120
121   const Property::Index rgbaIndex   = rgbIndex + 4;
122   const Property::Index red2Index   = rgbaIndex + 1;
123   const Property::Index green2Index = rgbaIndex + 2;
124   const Property::Index blue2Index  = rgbaIndex + 3;
125   const Property::Index alphaIndex  = rgbaIndex + 4;
126
127   // If we don't properly register a scene graph property for the "parent" type,
128   // then Object::GetSceneGraphProperty registers a float type for the child...
129
130   AnimatablePropertyRegistration(typeRegistration, "Foobar", foobarIndex, Vector2(10.0f, 20.0f));
131   AnimatablePropertyComponentRegistration(typeRegistration, "Foobar.x", fooIndex, foobarIndex, 0);
132   AnimatablePropertyComponentRegistration(typeRegistration, "Foobar.y", barIndex, foobarIndex, 1);
133
134   AnimatablePropertyRegistration(typeRegistration, "RGB", rgbIndex, Vector3(0.5f, 0.5, 1.0f));
135   AnimatablePropertyComponentRegistration(typeRegistration, "RGB.red", redIndex, rgbIndex, 0);
136   AnimatablePropertyComponentRegistration(typeRegistration, "RGB.green", greenIndex, rgbIndex, 1);
137   AnimatablePropertyComponentRegistration(typeRegistration, "RGB.blue", blueIndex, rgbIndex, 2);
138
139   AnimatablePropertyRegistration(typeRegistration, "RGBA", rgbaIndex, Vector4(0.5f, 0.5, 1.0f, 1.0f));
140   AnimatablePropertyComponentRegistration(typeRegistration, "RGBA.red", red2Index, rgbaIndex, 0);
141   AnimatablePropertyComponentRegistration(typeRegistration, "RGBA.green", green2Index, rgbaIndex, 1);
142   AnimatablePropertyComponentRegistration(typeRegistration, "RGBA.blue", blue2Index, rgbaIndex, 2);
143   AnimatablePropertyComponentRegistration(typeRegistration, "RGBA.alpha", alphaIndex, rgbaIndex, 3);
144
145   derived.SetProperty(foobarIndex, Vector2(9.0f, 10.0f));
146   derived.SetProperty(fooIndex, 100.0f);
147   derived.SetProperty(barIndex, 200.0f);
148
149   derived.SetProperty(rgbIndex, Vector3(0.9f, 0.9f, 0.1f));
150   derived.SetProperty(redIndex, 1.0f);
151   derived.SetProperty(greenIndex, 1.0f);
152   derived.SetProperty(blueIndex, 1.0f);
153
154   derived.SetProperty(rgbaIndex, Color::WHITE * 0.5f);
155   derived.SetProperty(red2Index, Color::SEA_GREEN.r);
156   derived.SetProperty(green2Index, Color::SEA_GREEN.g);
157   derived.SetProperty(blue2Index, Color::SEA_GREEN.b);
158   derived.SetProperty(alphaIndex, Color::SEA_GREEN.a);
159
160   application.SendNotification();
161   application.Render(16);
162
163   Vector2 foobar = derived.GetCurrentProperty<Vector2>(foobarIndex);
164   DALI_TEST_EQUALS(foobar, Vector2(100.0f, 200.0f), 0.0001f, TEST_LOCATION);
165
166   Vector3 colour = derived.GetCurrentProperty<Vector3>(rgbIndex);
167   DALI_TEST_EQUALS(colour, Vector3(1.0f, 1.0f, 1.0f), 0.0001f, TEST_LOCATION);
168
169   Vector4 col2 = derived.GetCurrentProperty<Vector4>(rgbaIndex);
170   DALI_TEST_EQUALS(col2, Color::SEA_GREEN, 0.0001f, TEST_LOCATION);
171
172   END_TEST;
173 }