[dali_2.3.24] Merge branch 'devel/master'
[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   bool RenderWithTextures(const RenderCallbackInput& inputData)
32   {
33     // Store the size of rendered area
34     size = inputData.size;
35
36     auto count = inputData.textureBindings.size();
37
38     // test whether number of textures matches 1
39     DALI_TEST_EQUALS(count, 1, TEST_LOCATION);
40
41     return false;
42   }
43
44   Size size{};
45 };
46
47 int UtcDaliRendererSetRenderCallbackP(void)
48 {
49   tet_infoline("Testing Renderer:LSetRenderCallback()");
50   TestApplication application;
51
52   DrawableObject drawable{};
53
54   auto callback = RenderCallback::New<DrawableObject>(&drawable, &DrawableObject::Render);
55
56   Actor actor = Actor::New();
57   application.GetScene().Add(actor);
58
59   actor.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
60
61   auto renderer = Renderer::New(*callback);
62   actor.AddRenderer(renderer);
63
64   // flush the queue and render once
65   application.SendNotification();
66   application.Render();
67
68   // Check the size (whether callback has been called)
69   auto size(drawable.size);
70   DALI_TEST_EQUALS(drawable.size, Size(100, 100), TEST_LOCATION);
71
72   END_TEST;
73 }
74
75 int UtcDaliDrawableActor1P(void)
76 {
77   tet_infoline("Testing DrawableActor");
78   TestApplication application;
79
80   DrawableObject drawable{};
81
82   auto callback = RenderCallback::New<DrawableObject>(&drawable, &DrawableObject::Render);
83
84   DrawableActor drawableActor = DrawableActor::New(*callback);
85   application.GetScene().Add(drawableActor);
86
87   drawableActor.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
88
89   // flush the queue and render once
90   application.SendNotification();
91   application.Render();
92
93   // Check the size (whether callback has been called)
94   DALI_TEST_EQUALS(drawable.size, Size(100, 100), TEST_LOCATION);
95
96   END_TEST;
97 }
98
99 int UtcRenderCallbackTextureBindingP(void)
100 {
101   tet_infoline("Testing RenderCallback texture bindings");
102   TestApplication application;
103
104   DrawableObject drawable{};
105
106   auto callback = RenderCallback::New<DrawableObject>(&drawable, &DrawableObject::RenderWithTextures);
107
108   // Prepare texture
109   Texture   texture   = Texture::New(Dali::TextureType::TEXTURE_2D, Pixel::Format::RGBA8888, 512, 512);
110   auto*     data      = reinterpret_cast<uint8_t*>(malloc(512 * 512 * 4));
111   PixelData pixelData = PixelData::New(data, 512 * 512 * 4, 512, 512, Pixel::Format::RGBA8888, PixelData::ReleaseFunction::FREE);
112   texture.Upload(pixelData);
113
114   std::vector<Texture> texturesToBind;
115   texturesToBind.push_back(texture);
116   callback->BindTextureResources(texturesToBind);
117
118   DrawableActor drawableActor = DrawableActor::New(*callback);
119   application.GetScene().Add(drawableActor);
120
121   drawableActor.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
122
123   // flush the queue and render once
124   application.SendNotification();
125   application.Render();
126
127   // Check the size (whether callback has been called)
128   DALI_TEST_EQUALS(drawable.size, Size(100, 100), TEST_LOCATION);
129
130   END_TEST;
131 }