[dali_2.3.21] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-SvgVisual.cpp
1 /*
2  * Copyright (c) 2023 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 #include <dali-toolkit-test-suite-utils.h>
18 #include <dummy-control.h>
19 #include <toolkit-event-thread-callback.h>
20
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
23
24 using namespace Dali;
25 using namespace Dali::Toolkit;
26
27 void dali_svg_visual_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void dali_svg_visual_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 namespace
38 {
39 const char* TEST_SVG_FILE_NAME = TEST_RESOURCE_DIR "/svg1.svg";
40 } // namespace
41
42 int UtcDaliSvgVisualChageSize(void)
43 {
44   tet_infoline("Test change transform");
45
46   ToolkitTestApplication application;
47
48   TraceCallStack& textureTrace = application.GetGlAbstraction().GetTextureTrace();
49   textureTrace.Enable(true);
50
51   Visual::Base visual = VisualFactory::Get().CreateVisual(Property::Map().Add(ImageVisual::Property::URL, TEST_SVG_FILE_NAME));
52   DALI_TEST_CHECK(visual);
53
54   DummyControl      control   = DummyControl::New();
55   DummyControlImpl& dummyImpl = static_cast<DummyControlImpl&>(control.GetImplementation());
56   dummyImpl.RegisterVisual(DummyControl::Property::TEST_VISUAL, visual);
57
58   application.SendNotification();
59
60   // Wait for loading
61   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
62
63   control.SetProperty(Actor::Property::SIZE, Vector2(100, 100));
64   application.GetScene().Add(control);
65
66   visual.SetTransformAndSize(Property::Map(), Vector2(100, 100));
67
68   // Wait for rasterization but not execute the callback
69   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1, 30, false), true, TEST_LOCATION);
70
71   // Change actor size before finishing rasterization
72   control.SetProperty(Actor::Property::SIZE, Vector2(300, 300));
73   visual.SetTransformAndSize(Property::Map(), Vector2(300, 300));
74
75   application.SendNotification();
76
77   // Wait for rasterization
78   DALI_TEST_EQUALS(Test::WaitForEventThreadTrigger(1), true, TEST_LOCATION);
79
80   application.SendNotification();
81   application.Render();
82
83   TraceCallStack::NamedParams params;
84   params["width"] << 300;
85   params["height"] << 300;
86   // Should be the final size
87   DALI_TEST_EQUALS(textureTrace.FindMethodAndParams("TexImage2D", params), true, TEST_LOCATION);
88
89   END_TEST;
90 }