Added New() function creating Renderer with RenderCallback
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-DrawableActor.cpp
1 /*
2  * Copyright (c) 2022 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/actors/drawable-actor.h>
20
21 struct DrawableObject
22 {
23   bool Render(const RenderCallbackInput& inputData)
24   {
25     // Store the size of rendered area
26     size = inputData.size;
27
28     return false;
29   }
30
31   Size size{};
32 };
33
34 int UtcDaliRendererSetRenderCallbackP(void)
35 {
36   tet_infoline("Testing Renderer:LSetRenderCallback()");
37   TestApplication application;
38
39   DrawableObject drawable{};
40
41   auto callback = RenderCallback::New<DrawableObject>(&drawable, &DrawableObject::Render);
42
43   Actor actor = Actor::New();
44   application.GetScene().Add(actor);
45
46   actor.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
47
48   auto renderer = Renderer::New(*callback);
49   actor.AddRenderer(renderer);
50
51   // flush the queue and render once
52   application.SendNotification();
53   application.Render();
54
55   // Check the size (whether callback has been called)
56   auto size(drawable.size);
57   DALI_TEST_EQUALS(drawable.size, Size(100, 100), TEST_LOCATION);
58
59   END_TEST;
60 }
61
62 int UtcDaliDrawableActor1P(void)
63 {
64   tet_infoline("Testing DrawableActor");
65   TestApplication application;
66
67   DrawableObject drawable{};
68
69   auto callback = RenderCallback::New<DrawableObject>(&drawable, &DrawableObject::Render);
70
71   DrawableActor drawableActor = DrawableActor::New(*callback);
72   application.GetScene().Add(drawableActor);
73
74   drawableActor.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
75
76   // flush the queue and render once
77   application.SendNotification();
78   application.Render();
79
80   // Check the size (whether callback has been called)
81   auto size(drawable.size);
82   DALI_TEST_EQUALS(drawable.size, Size(100, 100), TEST_LOCATION);
83
84   END_TEST;
85 }