Removed legacy resource tracking / logging
[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/public-api/common/dali-common.h>
27
28 namespace Dali
29 {
30
31 class DALI_IMPORT_API TestApplication : public ConnectionTracker
32 {
33 public:
34
35   // Default values derived from H2 device.
36   static const unsigned int DEFAULT_SURFACE_WIDTH = 480;
37   static const unsigned int DEFAULT_SURFACE_HEIGHT = 800;
38
39 #ifdef _CPP11
40   static constexpr float DEFAULT_HORIZONTAL_DPI = 220.0f;
41   static constexpr float DEFAULT_VERTICAL_DPI   = 217.0f;
42 #else
43   static const float DEFAULT_HORIZONTAL_DPI     = 220.0f;
44   static const float DEFAULT_VERTICAL_DPI       = 217.0f;
45 #endif
46
47   static const unsigned int DEFAULT_RENDER_INTERVAL = 1;
48
49   TestApplication( size_t surfaceWidth  = DEFAULT_SURFACE_WIDTH,
50                    size_t surfaceHeight = DEFAULT_SURFACE_HEIGHT,
51                    float  horizontalDpi = DEFAULT_HORIZONTAL_DPI,
52                    float  verticalDpi   = DEFAULT_VERTICAL_DPI )
53   : mCore( NULL ),
54     mSurfaceWidth( surfaceWidth ),
55     mSurfaceHeight( surfaceHeight ),
56     mFrame( 0u ),
57     mDpi( horizontalDpi, verticalDpi )
58   {
59     Initialize();
60   }
61
62   TestApplication( bool   initialize,
63                    size_t surfaceWidth  = DEFAULT_SURFACE_WIDTH,
64                    size_t surfaceHeight = DEFAULT_SURFACE_HEIGHT,
65                    float  horizontalDpi = DEFAULT_HORIZONTAL_DPI,
66                    float  verticalDpi   = DEFAULT_VERTICAL_DPI )
67   : mCore( NULL ),
68     mSurfaceWidth( surfaceWidth ),
69     mSurfaceHeight( surfaceHeight ),
70     mFrame( 0u ),
71     mDpi( horizontalDpi, verticalDpi )
72   {
73     if ( initialize )
74     {
75       Initialize();
76     }
77   }
78
79   void Initialize()
80   {
81     mCore = Dali::Integration::Core::New(
82         mRenderController,
83         mPlatformAbstraction,
84         mGlAbstraction,
85         mGlSyncAbstraction,
86         mGestureManager );
87
88     mCore->ContextCreated();
89     mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
90     mCore->SetDpi( mDpi.x, mDpi.y );
91
92     Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
93     Dali::Integration::Log::InstallLogFunction(logFunction);
94   }
95
96   virtual ~TestApplication()
97   {
98     Dali::Integration::Log::UninstallLogFunction();
99     delete mCore;
100   }
101
102   static void LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
103   {
104     switch(level)
105     {
106       case Dali::Integration::Log::DebugInfo:
107         tet_printf("INFO: %s", message.c_str());
108         break;
109       case Dali::Integration::Log::DebugWarning:
110         tet_printf("WARN: %s", message.c_str());
111         break;
112       case Dali::Integration::Log::DebugError:
113         tet_printf("ERROR: %s", message.c_str());
114         break;
115       default:
116         tet_printf("DEFAULT: %s", message.c_str());
117         break;
118     }
119   }
120
121   Dali::Integration::Core& GetCore()
122   {
123     return *mCore;
124   }
125
126   TestPlatformAbstraction& GetPlatform()
127   {
128     return mPlatformAbstraction;
129   }
130
131   TestRenderController& GetRenderController()
132   {
133     return mRenderController;
134   }
135
136   TestGlAbstraction& GetGlAbstraction()
137   {
138     return mGlAbstraction;
139   }
140
141   TestGlSyncAbstraction& GetGlSyncAbstraction()
142   {
143     return mGlSyncAbstraction;
144   }
145
146   TestGestureManager& GetGestureManager()
147   {
148     return mGestureManager;
149   }
150
151   void ProcessEvent(const Integration::Event& event)
152   {
153     mCore->QueueEvent(event);
154     mCore->ProcessEvents();
155   }
156
157   void SendNotification()
158   {
159     mCore->ProcessEvents();
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