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