Emscripten workarounds and llvm syntax fixes
[platform/core/uifw/dali-core.git] / automated-tests / dali-test-suite-utils / test-application.h
1 #ifndef __DALI_TEST_APPLICATION_H__
2 #define __DALI_TEST_APPLICATION_H__
3
4 //
5 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 //
7 // Licensed under the Flora License, Version 1.0 (the License);
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //     http://floralicense.org/license/
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an AS IS BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19
20 // INTERNAL INCLUDES
21 #include "test-platform-abstraction.h"
22 #include "test-gesture-manager.h"
23 #include "test-gl-sync-abstraction.h"
24 #include "test-gl-abstraction.h"
25 #include "test-render-controller.h"
26 #include <dali/integration-api/events/notification-event.h>
27 #include <dali/public-api/common/dali-common.h>
28
29 namespace Dali
30 {
31
32 class DALI_IMPORT_API TestApplication : public ConnectionTracker
33 {
34 public:
35
36   // Default values derived from H2 device.
37   static const unsigned int DEFAULT_SURFACE_WIDTH = 480;
38   static const unsigned int DEFAULT_SURFACE_HEIGHT = 800;
39
40 #ifdef _CPP11
41   static constexpr float DEFAULT_HORIZONTAL_DPI = 220.0f;
42   static constexpr float DEFAULT_VERTICAL_DPI   = 217.0f;
43 #else
44   static const float DEFAULT_HORIZONTAL_DPI     = 220.0f;
45   static const float DEFAULT_VERTICAL_DPI       = 217.0f;
46 #endif
47
48   static const unsigned int DEFAULT_RENDER_INTERVAL = 1;
49
50   TestApplication( size_t surfaceWidth  = DEFAULT_SURFACE_WIDTH,
51                    size_t surfaceHeight = DEFAULT_SURFACE_HEIGHT,
52                    float  horizontalDpi = DEFAULT_HORIZONTAL_DPI,
53                    float  verticalDpi   = DEFAULT_VERTICAL_DPI )
54   : mCore( NULL ),
55     mSurfaceWidth( surfaceWidth ),
56     mSurfaceHeight( surfaceHeight ),
57     mFrame( 0u ),
58     mDpi( horizontalDpi, verticalDpi )
59   {
60     Initialize();
61   }
62
63   TestApplication( bool   initialize,
64                    size_t surfaceWidth  = DEFAULT_SURFACE_WIDTH,
65                    size_t surfaceHeight = DEFAULT_SURFACE_HEIGHT,
66                    float  horizontalDpi = DEFAULT_HORIZONTAL_DPI,
67                    float  verticalDpi   = DEFAULT_VERTICAL_DPI )
68   : mCore( NULL ),
69     mSurfaceWidth( surfaceWidth ),
70     mSurfaceHeight( surfaceHeight ),
71     mFrame( 0u ),
72     mDpi( horizontalDpi, verticalDpi )
73   {
74     if ( initialize )
75     {
76       Initialize();
77     }
78   }
79
80   void Initialize()
81   {
82     mCore = Dali::Integration::Core::New(
83         mRenderController,
84         mPlatformAbstraction,
85         mGlAbstraction,
86         mGlSyncAbstraction,
87         mGestureManager );
88
89     mCore->ContextCreated();
90     mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
91     mCore->SetDpi( mDpi.x, mDpi.y );
92
93     Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
94     unsigned int logOpts = Dali::Integration::Log::ParseLogOptions("");
95     Dali::Integration::Log::InstallLogFunction(logFunction, logOpts);
96   }
97
98   virtual ~TestApplication()
99   {
100     Dali::Integration::Log::UninstallLogFunction();
101     delete mCore;
102   }
103
104   static void LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
105   {
106     switch(level)
107     {
108       case Dali::Integration::Log::DebugInfo:
109         tet_printf("INFO: %s", message.c_str());
110         break;
111       case Dali::Integration::Log::DebugWarning:
112         tet_printf("WARN: %s", message.c_str());
113         break;
114       case Dali::Integration::Log::DebugError:
115         tet_printf("ERROR: %s", message.c_str());
116         break;
117       case Dali::Integration::Log::DebugResources:
118         tet_printf("INFO: %s", message.c_str());
119         break;
120       default:
121         tet_printf("DEFAULT: %s", message.c_str());
122         break;
123     }
124   }
125
126   Dali::Integration::Core& GetCore()
127   {
128     return *mCore;
129   }
130
131   TestPlatformAbstraction& GetPlatform()
132   {
133     return mPlatformAbstraction;
134   }
135
136   TestRenderController& GetRenderController()
137   {
138     return mRenderController;
139   }
140
141   TestGlAbstraction& GetGlAbstraction()
142   {
143     return mGlAbstraction;
144   }
145
146   TestGlSyncAbstraction& GetGlSyncAbstraction()
147   {
148     return mGlSyncAbstraction;
149   }
150
151   TestGestureManager& GetGestureManager()
152   {
153     return mGestureManager;
154   }
155
156   void SendNotification()
157   {
158     Integration::NotificationEvent event;
159     mCore->SendEvent(event);
160   }
161
162   void SetSurfaceWidth( unsigned int width, unsigned height )
163   {
164     mSurfaceWidth = width;
165     mSurfaceHeight = height;
166
167     mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
168   }
169
170   bool Render( unsigned int intervalMilliseconds = DEFAULT_RENDER_INTERVAL )
171   {
172     // Update Time values
173     mPlatformAbstraction.IncrementGetTimeResult( intervalMilliseconds );
174     unsigned int seconds(0u), microseconds(0u);
175     mPlatformAbstraction.GetTimeMicroseconds( seconds, microseconds );
176
177     mCore->VSync( mFrame, seconds, microseconds );
178     mCore->Update( mStatus );
179     mCore->Render( mRenderStatus );
180
181     mFrame++;
182
183     return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
184   }
185
186   unsigned int GetUpdateStatus()
187   {
188     return mStatus.KeepUpdating();
189   }
190
191   bool UpdateOnly( unsigned int intervalMilliseconds = DEFAULT_RENDER_INTERVAL )
192   {
193     // Update Time values
194     mPlatformAbstraction.IncrementGetTimeResult( intervalMilliseconds );
195     unsigned int seconds(0u), microseconds(0u);
196     mPlatformAbstraction.GetTimeMicroseconds( seconds, microseconds );
197
198     mCore->VSync( mFrame, seconds, microseconds );
199     mCore->Update( mStatus );
200
201     return mStatus.KeepUpdating();
202   }
203
204   bool RenderOnly( )
205   {
206     // Update Time values
207     mCore->Render( mRenderStatus );
208
209     mFrame++;
210
211     return mRenderStatus.NeedsUpdate();
212   }
213
214   void ResetContext()
215   {
216     mCore->ContextToBeDestroyed();
217     mCore->ContextCreated();
218   }
219
220 protected:
221   TestPlatformAbstraction   mPlatformAbstraction;
222   TestRenderController      mRenderController;
223   TestGlAbstraction         mGlAbstraction;
224   TestGlSyncAbstraction     mGlSyncAbstraction;
225   TestGestureManager        mGestureManager;
226
227   Integration::UpdateStatus mStatus;
228   Integration::RenderStatus mRenderStatus;
229
230   Integration::Core* mCore;
231
232   unsigned int mSurfaceWidth;
233   unsigned int mSurfaceHeight;
234   unsigned int mFrame;
235
236   Vector2 mDpi;
237 };
238
239 } // Dali
240
241 #endif