Make NPatchData receive LoadComplete call from TextureManager.
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / utc-Dali-AddOns.cpp
1 /*
2  * Copyright (c) 2020 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
21 #include <dali-toolkit-test-suite-utils.h>
22 #include <dali-toolkit/dali-toolkit.h>
23 #include "dali-toolkit-test-utils/test-addon-manager.h"
24 #include <toolkit-event-thread-callback.h>
25
26 using namespace Dali::Toolkit::Internal;
27
28 namespace
29 {
30
31 const char* TEST_IMAGE_FILE_NAME =  TEST_RESOURCE_DIR "/application-icon-20.png";
32 const char* TEST_IMAGE_FILE_NAME_9 =  TEST_RESOURCE_DIR "/heartsframe.9.png";
33 const char* TEST_IMAGE_FILE_NAME2_9 =  TEST_RESOURCE_DIR "/button-up.9.png";
34 int CountFunctionCalls( const std::vector<std::string>& callstack, const std::string& function )
35 {
36   int counter = 0;
37   std::find_if( callstack.begin(), callstack.end(), [&counter, &function]( const std::string& item )
38   {
39     if( item == function )
40     {
41       counter++;
42     }
43     return false;
44   });
45
46   return counter;
47 }
48
49 }
50
51 int UtcRenderingAddOnTestP(void)
52 {
53   Dali::Integration::AddOnManager* addOnManager = new Dali::Test::AddOnManager();
54
55   bool valid = addOnManager->Get() != nullptr;
56   DALI_TEST_EQUALS( valid, true, TEST_LOCATION );
57   auto addon = addOnManager->GetAddOn( "oo-rendering" );
58   auto GetCallStack = addOnManager->GetGlobalProc<std::vector<std::string>(bool)>( addon, "GetCallStack" );
59
60   ToolkitTestApplication application;
61   tet_infoline( "UtcRenderingAddOnTestP" );
62
63   // Load regular image view
64   auto imageView = Dali::Toolkit::ImageView::New( TEST_IMAGE_FILE_NAME );
65   imageView.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 60.f ) );
66   imageView.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
67   imageView.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
68
69   // Load npatch image view
70   auto imageView2 = Dali::Toolkit::ImageView::New( TEST_IMAGE_FILE_NAME_9 );
71   imageView2.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 60.f ) );
72   imageView2.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
73   imageView2.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
74
75   // Load npatch image view
76   auto imageView3 = Dali::Toolkit::ImageView::New( TEST_IMAGE_FILE_NAME2_9 );
77   imageView3.SetProperty( Actor::Property::SIZE, Vector2( 400.f, 60.f ) );
78   imageView3.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::TOP_LEFT );
79   imageView3.SetProperty( Actor::Property::ANCHOR_POINT, AnchorPoint::TOP_LEFT );
80
81   application.GetScene().Add( imageView );
82   application.GetScene().Add( imageView2 );
83   application.GetScene().Add( imageView3 );
84
85   application.SendNotification();
86   application.Render();
87
88   DALI_TEST_EQUALS( ::Test::WaitForEventThreadTrigger( 3 ), true, TEST_LOCATION );
89
90   application.SendNotification();
91   application.Render();
92
93   auto callstack = GetCallStack(true);
94
95   DALI_TEST_EQUALS( CountFunctionCalls( callstack, "GetGeometry" ), 2, TEST_LOCATION);
96   DALI_TEST_EQUALS( CountFunctionCalls( callstack, "CreateGeometry" ), 1, TEST_LOCATION);
97   DALI_TEST_EQUALS( CountFunctionCalls( callstack, "CreateGeometryGrid" ), 2, TEST_LOCATION);
98   DALI_TEST_EQUALS( CountFunctionCalls( callstack, "BuildNPatch" ), 2, TEST_LOCATION);
99
100   delete addOnManager;
101
102   END_TEST;
103 }