First public contribution.
1 // Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "testgceharness.h"
18 static TAny* globalGCEHarness = NULL;
20 CTestGCEHarness* CTestGCEHarness::NewL(TInt aNumBuffers)
22 CTestGCEHarness* self = static_cast <CTestGCEHarness*>(globalGCEHarness);
25 self = new (ELeave) CTestGCEHarness;
26 CleanupStack::PushL(self);
27 self->ConstructL(aNumBuffers);
28 globalGCEHarness = self;
29 CleanupStack::Pop(self);
34 void CTestGCEHarness::Remove()
36 CTestGCEHarness* self = static_cast <CTestGCEHarness*>(globalGCEHarness);
40 globalGCEHarness = NULL;
44 /* Use with care. Will leak memory if use inappropriately. Only use if objected pointed to has been
45 * deleted ro otherwise removed. Required for panic testing where pointer is left hanging when thread
48 void CTestGCEHarness::ResetGlobalPointer()
50 globalGCEHarness = NULL;
53 void CTestGCEHarness::SetBufferEventProcessingDelay(TRendererEvent aEventType, TTimeIntervalMicroSeconds32 aDelay)
55 CTestGCEHarness* self = static_cast <CTestGCEHarness*>(globalGCEHarness);
61 TInt count = self->iUpdateArray.Count();
67 // Get current value of buffers.
68 // Processing delays are for all buffers. This function will need to change
69 // if delays are to be set on a per buffer basis.
70 TTimeIntervalMicroSeconds32 displayDelay = self->iUpdateArray[0].iDisplayedProcessingDelay;
71 TTimeIntervalMicroSeconds32 availableDelay = self->iUpdateArray[0].iAvailableProcessingDelay;
73 // set new values for delay
74 if(aEventType == EEventDisplayed || aEventType == EEventAll)
76 displayDelay = aDelay;
79 if(aEventType == EEventAvailable || aEventType == EEventAll)
81 availableDelay = aDelay;
84 for(TInt i=0; i < count; i++)
86 self->iUpdateArray[i].iDisplayedProcessingDelay = displayDelay;
87 self->iUpdateArray[i].iAvailableProcessingDelay = availableDelay;
92 * Use with care. It results in a reset of the harness on the next
93 * call to RetrieveL(). This is necessary when the Video Renderer is in timed mode. i.e.
94 * The thread that creates an AO must also delete it.
96 void CTestGCEHarness::ResetBuffersL(TInt aNumBuffers)
98 CTestGCEHarness* self = static_cast <CTestGCEHarness*>(globalGCEHarness);
101 User::Leave(KErrNotReady);
104 self->iResetBuffers = aNumBuffers;
107 CTestGCEHarness* CTestGCEHarness::RetrieveL()
109 CTestGCEHarness* self = static_cast <CTestGCEHarness*>(globalGCEHarness);
112 User::Leave(KErrNotReady);
115 // This code is necessary for the replace tests as the timer active objects must be
116 // created and deleted in the same thread, which is not always the test thread. When the
117 // Video Renderer is in timed mode the thread the harness is executed in is not
118 // the same as the test thread.
119 if(self->iResetBuffers)
121 TInt buffers = self->iResetBuffers;
122 self->Close(); // resets self->iResetBuffers
123 self->ConstructL(buffers);
129 TInt CTestGCEHarness::Connect()
131 CTestGCEHarness* self = static_cast <CTestGCEHarness*>(globalGCEHarness);
137 TInt count = self->iUpdateArray.Count();
138 for(TInt i=0; i < count; i++)
140 if(self->iUpdateArray[i].iAvailableTimer == NULL)
142 self->iUpdateArray[i].iAvailableTimer = CTestTimer::NewL(*self, i, EEventAvailable);
144 if(self->iUpdateArray[i].iDisplayedTimer == NULL)
146 self->iUpdateArray[i].iDisplayedTimer = CTestTimer::NewL(*self, i, EEventDisplayed);
152 void CTestGCEHarness::Close()
154 CTestGCEHarness* self = static_cast <CTestGCEHarness*>(globalGCEHarness);
160 TInt count = self->iUpdateArray.Count();
161 for(TInt i=0; i < count; i++)
163 if(self->iUpdateArray[i].iAvailableTimer != NULL)
165 self->iUpdateArray[i].iAvailableTimer->Cancel();
166 delete self->iUpdateArray[i].iAvailableTimer;
167 self->iUpdateArray[i].iAvailableTimer = NULL;
169 if(self->iUpdateArray[i].iDisplayedTimer != NULL)
171 self->iUpdateArray[i].iDisplayedTimer->Cancel();
172 delete self->iUpdateArray[i].iDisplayedTimer;
173 self->iUpdateArray[i].iDisplayedTimer = NULL;
176 self->iUpdateArray.Reset();
177 self->iLastPosted = -1;
178 self->iResetBuffers = 0;
181 void CTestGCEHarness::CancelAllNotifications()
183 CTestGCEHarness* self = static_cast <CTestGCEHarness*>(globalGCEHarness);
189 if(self->iStatusDisplayed)
191 User::RequestComplete(self->iStatusDisplayed, KErrCancel);
192 self->iStatusDisplayed = NULL;
195 TInt count = self->iUpdateArray.Count();
196 for(TInt i=0; i < count; i++)
198 if(self->iUpdateArray[i].iAvailableTimer != NULL)
200 self->iUpdateArray[i].iAvailableTimer->Cancel();
202 if(self->iUpdateArray[i].iDisplayedTimer != NULL)
204 self->iUpdateArray[i].iDisplayedTimer->Cancel();
206 if(self->iUpdateArray[i].iStatusAvailable)
208 User::RequestComplete(self->iUpdateArray[i].iStatusAvailable, KErrCancel);
209 self->iUpdateArray[i].iStatusAvailable = NULL;
214 CTestGCEHarness::CTestGCEHarness()
219 CTestGCEHarness::~CTestGCEHarness()
221 iUpdateArray.Close();
224 void CTestGCEHarness::ConstructL(TInt aNumBuffers)
226 TBufferUpdateData data;
227 for(TInt i=0; i < aNumBuffers; i++)
229 iUpdateArray.AppendL(data);
230 iUpdateArray[i].iAvailableProcessingDelay = KDefaultAvailableProcessingDelay;
231 iUpdateArray[i].iDisplayedProcessingDelay = KDefaultDisplayedProcessingDelay;
232 iUpdateArray[i].iDisplayedCompleteReason = KErrNone;
233 iUpdateArray[i].iAvailableCompleteReason = KErrNone;
234 iUpdateArray[i].iDisplayedInProgress = EFalse;
235 iUpdateArray[i].iAvailableInProgress = EFalse;
236 iUpdateArray[i].iAvailableTimer = NULL;
237 iUpdateArray[i].iDisplayedTimer = NULL;
238 iUpdateArray[i].iStatusAvailable = NULL;
242 TInt CTestGCEHarness::SubmitUpdate(TInt aBuffer)
244 if(aBuffer < 0 || aBuffer > iUpdateArray.Count()-1)
249 if(iUpdateArray[aBuffer].iDisplayedInProgress || iUpdateArray[aBuffer].iAvailableInProgress)
254 iUpdateArray[aBuffer].iDisplayedTimer->After(iUpdateArray[aBuffer].iDisplayedProcessingDelay);
255 iUpdateArray[aBuffer].iDisplayedInProgress = ETrue;
257 iUpdateArray[aBuffer].iStatusAvailable = iStatusAvailable;
258 iStatusAvailable = NULL;
260 if(iUpdateArray.Count() == 1)
262 // set off available timer - this buffer
263 iUpdateArray[aBuffer].iAvailableTimer->After(iUpdateArray[aBuffer].iAvailableProcessingDelay);
264 iUpdateArray[aBuffer].iAvailableInProgress = ETrue;
266 else if(iLastPosted > -1)
268 // set off available timer for iLastPosted
269 iUpdateArray[iLastPosted].iAvailableTimer->After(iUpdateArray[iLastPosted].iAvailableProcessingDelay);
270 iUpdateArray[iLastPosted].iAvailableInProgress = ETrue;
271 // set last posted to this buffer so that it is kicked off on next submit
272 iLastPosted = aBuffer;
276 iLastPosted = aBuffer;
282 void CTestGCEHarness::NotifyWhenAvailable(TRequestStatus& aStatus)
284 iStatusAvailable = &aStatus;
285 *iStatusAvailable = KRequestPending;
288 void CTestGCEHarness::NotifyWhenDisplayed(TRequestStatus& aStatus, TTimeStamp& aTimeStamp)
290 iStatusDisplayed = &aStatus;
291 iTimeStamp = &aTimeStamp;
292 *iStatusDisplayed = KRequestPending;
295 void CTestGCEHarness::OnTimer(TInt aBufferId, TRendererEvent aEvent)
297 if(aEvent == EEventDisplayed)
299 iUpdateArray[aBufferId].iDisplayedInProgress = EFalse;
302 *iTimeStamp = User::FastCounter();
303 User::RequestComplete(iStatusDisplayed, iUpdateArray[aBufferId].iDisplayedCompleteReason);
305 iStatusDisplayed = NULL;
308 else if(aEvent == EEventAvailable)
310 iUpdateArray[aBufferId].iAvailableInProgress = EFalse;
311 if(iUpdateArray[aBufferId].iStatusAvailable)
313 User::RequestComplete(iUpdateArray[aBufferId].iStatusAvailable, iUpdateArray[aBufferId].iAvailableCompleteReason);
314 iUpdateArray[aBufferId].iStatusAvailable = NULL;
319 CTestGCEHarness::CTestTimer*
320 CTestGCEHarness::CTestTimer::NewL(CTestGCEHarness& aContainer, TInt aBufferId, TRendererEvent aEvent)
322 CTestTimer* self = new(ELeave)CTestTimer(aContainer, aBufferId, aEvent);
323 CleanupStack::PushL(self);