Updates for const->constexpr
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit-internal / addons / test-sample-addon.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 <cstring>
19 #include <dali/devel-api/addons/addon-base.h>
20 #include <dali-test-suite-utils.h>
21
22 namespace
23 {
24 bool gIsPaused = false;
25 const auto ANSWER_TO_EVERYTHING = 42;
26 }
27
28 int StringLen( const char* str )
29 {
30   return strlen( str );
31 }
32
33 int DoSum( int a, int b )
34 {
35   return a+b;
36 }
37
38 bool GetLifecycleStatus()
39 {
40   return gIsPaused;
41 }
42
43 struct AddOnDataInstance
44 {
45   int GetValue()
46   {
47     return ANSWER_TO_EVERYTHING;
48   }
49
50   static int GetValueWithInstance( AddOnDataInstance* instance )
51   {
52     return instance->GetValue();
53   }
54 };
55
56 AddOnDataInstance* CreateInstance()
57 {
58   return new AddOnDataInstance();
59 }
60
61 class TestDummyAddOn : public Dali::AddOns::AddOnBase
62 {
63 public:
64
65   void GetAddOnInfo( Dali::AddOnInfo& info ) override
66   {
67     info.type = Dali::AddOnType::GENERIC;
68     info.name = "SampleAddOn";
69     info.version = Dali::DALI_ADDON_VERSION( 1, 0, 0 );
70     info.next = nullptr;
71     tet_printf( "SampleAddOn: GetAddOnInfo() : name = %s\n", info.name.c_str());
72   }
73
74   /**
75    * Dispatch table for global functions
76    * @return
77    */
78   Dali::AddOns::DispatchTable* GetGlobalDispatchTable() override
79   {
80     static Dali::AddOns::DispatchTable dispatchTable{};
81     if( dispatchTable.Empty() )
82     {
83       dispatchTable["DoSum"]                     = DoSum;
84       dispatchTable["StringLen"]                 = StringLen;
85       dispatchTable["GetLifecycleStatus"]        = GetLifecycleStatus;
86       dispatchTable["CreateInstance"]            = CreateInstance;
87
88     }
89     return &dispatchTable;
90   }
91
92   /**
93    * Lifecycle
94    */
95   void OnStart() override
96   {
97     gIsPaused = false;
98   }
99
100   void OnStop() override
101   {
102     gIsPaused = true;
103   }
104
105   void OnPause() override
106   {
107     gIsPaused = true;
108   }
109
110   void OnResume() override
111   {
112     gIsPaused = false;
113   }
114
115   /**
116    * Dispatch table for instance functions
117    */
118   Dali::AddOns::DispatchTable* GetInstanceDispatchTable() override
119   {
120     static Dali::AddOns::DispatchTable dispatchTable{};
121     if( dispatchTable.Empty() )
122     {
123       dispatchTable["InstanceCall"] = AddOnDataInstance::GetValueWithInstance;
124     }
125     return &dispatchTable;
126   }
127 };
128
129 REGISTER_ADDON_CLASS( TestDummyAddOn );