5aa928e2a3dffa2d183171f212ffeb942ebb6e9e
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / dali-toolkit-test-utils / test-application.cpp
1 //
2 // Copyright (c) 2014 Samsung Electronics Co., Ltd.
3 //
4 // Licensed under the Flora License, Version 1.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://floralicense.org/license/
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 #include "test-application.h"
18
19 namespace Dali
20 {
21
22
23 TestApplication::TestApplication( size_t surfaceWidth,
24                                   size_t surfaceHeight,
25                                   float  horizontalDpi,
26                                   float  verticalDpi)
27 : mCore( NULL ),
28   mSurfaceWidth( surfaceWidth ),
29   mSurfaceHeight( surfaceHeight ),
30   mFrame( 0u ),
31   mDpi( horizontalDpi, verticalDpi )
32 {
33   Initialize();
34 }
35
36 TestApplication::TestApplication( bool   initialize,
37                                   size_t surfaceWidth,
38                                   size_t surfaceHeight,
39                                   float  horizontalDpi,
40                                   float  verticalDpi )
41 : mCore( NULL ),
42   mSurfaceWidth( surfaceWidth ),
43   mSurfaceHeight( surfaceHeight ),
44   mFrame( 0u ),
45   mDpi( horizontalDpi, verticalDpi )
46 {
47   if ( initialize )
48   {
49     Initialize();
50   }
51 }
52
53 void TestApplication::Initialize()
54 {
55   mCore = Dali::Integration::Core::New(
56     mRenderController,
57     mPlatformAbstraction,
58     mGlAbstraction,
59     mGlSyncAbstraction,
60     mGestureManager );
61
62   mCore->ContextCreated();
63   mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
64   mCore->SetDpi( mDpi.x, mDpi.y );
65
66   Dali::Integration::Log::LogFunction logFunction(&TestApplication::LogMessage);
67   Dali::Integration::Log::InstallLogFunction(logFunction);
68 }
69
70 TestApplication::~TestApplication()
71 {
72   Dali::Integration::Log::UninstallLogFunction();
73   delete mCore;
74 }
75
76 void TestApplication::LogMessage(Dali::Integration::Log::DebugPriority level, std::string& message)
77 {
78   switch(level)
79   {
80     case Dali::Integration::Log::DebugInfo:
81       fprintf(stderr, "INFO: %s", message.c_str());
82       break;
83     case Dali::Integration::Log::DebugWarning:
84       fprintf(stderr, "WARN: %s", message.c_str());
85       break;
86     case Dali::Integration::Log::DebugError:
87       fprintf(stderr, "ERROR: %s", message.c_str());
88       break;
89     default:
90       fprintf(stderr, "DEFAULT: %s", message.c_str());
91       break;
92   }
93 }
94
95 Dali::Integration::Core& TestApplication::GetCore()
96 {
97   return *mCore;
98 }
99
100 TestPlatformAbstraction& TestApplication::GetPlatform()
101 {
102   return mPlatformAbstraction;
103 }
104
105 TestRenderController& TestApplication::GetRenderController()
106 {
107   return mRenderController;
108 }
109
110 TestGlAbstraction& TestApplication::GetGlAbstraction()
111 {
112   return mGlAbstraction;
113 }
114
115 TestGlSyncAbstraction& TestApplication::GetGlSyncAbstraction()
116 {
117   return mGlSyncAbstraction;
118 }
119
120 TestGestureManager& TestApplication::GetGestureManager()
121 {
122   return mGestureManager;
123 }
124
125 void TestApplication::ProcessEvent(const Integration::Event& event)
126 {
127   mCore->QueueEvent(event);
128   mCore->ProcessEvents();
129 }
130
131 void TestApplication::SendNotification()
132 {
133   mCore->ProcessEvents();
134 }
135
136 void TestApplication::SetSurfaceWidth( unsigned int width, unsigned height )
137 {
138   mSurfaceWidth = width;
139   mSurfaceHeight = height;
140
141   mCore->SurfaceResized( mSurfaceWidth, mSurfaceHeight );
142 }
143
144 bool TestApplication::Render( unsigned int intervalMilliseconds  )
145 {
146   // Update Time values
147   mPlatformAbstraction.IncrementGetTimeResult( intervalMilliseconds );
148   unsigned int seconds(0u), microseconds(0u);
149   mPlatformAbstraction.GetTimeMicroseconds( seconds, microseconds );
150
151   mCore->VSync( mFrame, seconds, microseconds );
152   mCore->Update( mStatus );
153   mCore->Render( mRenderStatus );
154
155   mFrame++;
156
157   return mStatus.KeepUpdating() || mRenderStatus.NeedsUpdate();
158 }
159
160 unsigned int TestApplication::GetUpdateStatus()
161 {
162   return mStatus.KeepUpdating();
163 }
164
165 bool TestApplication::UpdateOnly( unsigned int intervalMilliseconds  )
166 {
167   // Update Time values
168   mPlatformAbstraction.IncrementGetTimeResult( intervalMilliseconds );
169   unsigned int seconds(0u), microseconds(0u);
170   mPlatformAbstraction.GetTimeMicroseconds( seconds, microseconds );
171
172   mCore->VSync( mFrame, seconds, microseconds );
173   mCore->Update( mStatus );
174
175   return mStatus.KeepUpdating();
176 }
177
178 bool TestApplication::RenderOnly( )
179 {
180   // Update Time values
181   mCore->Render( mRenderStatus );
182
183   mFrame++;
184
185   return mRenderStatus.NeedsUpdate();
186 }
187
188 void TestApplication::ResetContext()
189 {
190   mCore->ContextToBeDestroyed();
191   mCore->ContextCreated();
192 }
193
194
195 } // Namespace dali