void CDummyUsbDevice::DoCheck() { UpdatePluginInfo(); switch (iCheck) { case EUsbChargingTestCheckNone: { // do nothing } break; case EUsbChargingTestCheckPluginState: { iTest(iInfo.iPluginState == iCheckValue); } break; case EUsbChargingTestCheckMilliAmps: { iTest(iInfo.iRequestedCurrentValue == iCheckValue); } break; case EUsbChargingTestCheckCharging: { TInt current; TInt err = GetChargingCurrentFromProperty(current); iTest(err == KErrNone); iTest(current == iCheckValue); } break; default: User::Panic(KUsbChargingTestPanic, EUsbChargingTestPanicBadCheck); } }
//************************************************************************************* EXPORT_C void ASTstAlarmTest::TestClearStoreL() // // Clear any settings that may have been stored // Method could leave when trying to get list of all alarm categories in use within the alarm server. // { iTest(iAlarmServer.Handle() != KNullHandle); // Delete all alarms RArray<TAlarmCategory> categories; iAlarmServer.GetAvailableCategoryListL(categories); TInt count = categories.Count(); for(TInt i=0; i<count; i++) { const TAlarmCategory category = categories[i]; iTest(iAlarmServer.AlarmDeleteAllByCategory(category, EFalse) == KErrNone); } categories.Close(); // Restore alarm sound iAlarmServer.SetAlarmSoundState(EAlarmGlobalSoundStateOn); // Check there aren't any queued alarms (not a particularly good // test, but better than nothing). count = iAlarmServer.NumberOfAlarmsActiveInQueue(); iTest(!count); }
void CDummyUsbDevice::DoCommand() { switch (iCommand) { case EUsbChargingTestCommandNone: { // do nothing } break; case EUsbChargingTestCommandDeviceState: { iObservers[0]->UsbDeviceStateChange(KErrNone, iDeviceState, TUsbDeviceState(iCommandValue)); iDeviceState = TUsbDeviceState(iCommandValue); } break; case EUsbChargingTestCommandUserSetting: { TInt err = WriteToRepositoryProperty(iCommandValue); iTest(err == KErrNone); } break; default: User::Panic(KUsbChargingTestPanic, EUsbChargingTestPanicBadCommand); } }
CollisionData iTest_data(const AABB2D &ac, const Plane2D &bc) { if (iTest(ac, bc)) { CollisionData r; r.collisionNormal = bc.normal; r.penDepth = dot(bc.normal, (ac.pos() - bc.position)); if (r.penDepth < 0) r.penDepth = 0; return r; } else return CollisionData{ 0,0 }; }
void CFindTest::DoFindL(const TDesC& aTextToFind,const CContactItemFieldDef& aFieldDef, const TInt aNumExpectedFinds) { CContactIdArray* matchList=iDb->FindLC(aTextToFind,&aFieldDef); const TInt numIds=matchList->Count(); iLog->LogLine(_L("Matched %d contact(s) of %d expected"),numIds,aNumExpectedFinds); if(numIds!=aNumExpectedFinds) { iLog->LogLine(_L("%S FAILED!"),&KTestName); } iTest(numIds==aNumExpectedFinds); CleanupStack::PopAndDestroy(); // matchList. }
void CSchSendTestWaitForState::DoStartL(const CMsvEntrySelection& aSelection, TTimeIntervalMicroSeconds32 aAfter, TBool aWaitForever) { iTest(iSendingStates.Count() != 0); iAfter = aAfter; iWaitForever = aWaitForever; delete iSelection; iSelection = NULL; iSelection = aSelection.CopyL(); iTimer.After(iStatus, iAfter); SetActive(); CActiveScheduler::Start(); }
CollisionData iTest_data(const AABB2D &ac, const Ray2D &bc) { if (iTest(ac, bc)) { ConvexHull2D a; a.size = 4; a.verts[0] = ac.min; a.verts[1] = Vector2{ ac.min.x, ac.max.y }; a.verts[2] = ac.max; a.verts[3] = Vector2{ ac.max.y, ac.min.y }; return iTest_data(a, bc); } else return CollisionData{ 0,0 }; }
void CFindTest::DoFindAsyncL(const TDesC& aTextToFind,const CContactItemFieldDef& aFieldDef, const TInt aNumExpectedFinds) { iIdleFinder=iDb->FindAsyncL(aTextToFind,&aFieldDef,this); CleanupStack::PushL(iIdleFinder); // Handle on cleanup stack because object is very temporary. CActiveScheduler::Start(); CContactIdArray* matchList=iIdleFinder->TakeContactIds(); CleanupStack::PushL(matchList); const TInt numIds=matchList->Count(); iLog->LogLine(_L("Matched %d contact(s) of %d expected"),numIds,aNumExpectedFinds); if(numIds!=aNumExpectedFinds) { iLog->LogLine(_L("%S FAILED!"),&KTestName); } iTest(numIds==aNumExpectedFinds); CleanupStack::PopAndDestroy(2); // matchList. iIdleFinder. }
//************************************************************************************* EXPORT_C void ASTstAlarmTest::WaitForNotificationBufferToBeEmptied(TRequestStatus& aStatus, TAlarmId& aAlarmId) { if (aStatus == KRequestPending) return; iAlarmServer.NotifyChange(aStatus, aAlarmId); User::After(KTimeToWait); if (aStatus == KRequestPending) return; User::WaitForRequest(aStatus); // Because of event bufferring inside the Alarm Server // We need to wait until there aren't any more events // in the buffer, and then attempt to cancel the request. // // Trying to cancel a request when the server has // already completed the message (because something // was in the buffer) results in the server panicking // the client. FOREVER { iTest(aStatus >= EAlarmChangeEventState && aStatus <= EAlarmChangeEventLast); iAlarmServer.NotifyChange(aStatus, aAlarmId); // // Wait a second so that we can tell if this really is // waiting for an event, or just for the Alarm Server // process to be given some scheduling time by the // kernel User::After(KTimeToWait); // If its still pending, then we should attempt // to cancel the request. Otherwise, if its not // pending, then the Alarm Server probably just // completed the request based upon the contents // of the event buffer. if (aStatus == KRequestPending) break; else { // Eat the request and try again User::WaitForRequest(aStatus); } } }
CollisionData iTest_data(const AABB2D &ac, const AABB2D &bc) { if (iTest(ac, bc)) { ConvexHull2D a, b; a.size = 4; b.size = 4; a.verts[1] = Vector2{ ac.min.x, ac.min.y }; a.verts[0] = Vector2{ ac.min.x, ac.max.y }; a.verts[3] = Vector2{ ac.max.x, ac.max.y }; a.verts[2] = Vector2{ ac.max.x, ac.min.y }; b.verts[1] = Vector2{ bc.min.x, bc.min.y }; b.verts[0] = Vector2{ bc.min.x, bc.max.y }; b.verts[3] = Vector2{ bc.max.x, bc.max.y }; b.verts[2] = Vector2{ bc.max.x, bc.min.y }; return iTest_data(Matrix3::rotate(DEG2RAD(2)) * a, b); } else return CollisionData{ 0,0 }; }
bool iTest (const AABB2D &ac, const Circle &bc) { return iTest(Circle{ clamp(bc.position, ac.min, ac.max) , 0 }, bc); }
void DebugAABB2D() { #pragma region TestShapes AABB2D ab(Vector2{ 10 , 10 }, Vector2{ 20 , 20 }); AABB2D bb(Vector2{ 15 , 15 }, Vector2{ 25 , 25 }); AABB2D cb(Vector2{ 25 , 25 }, Vector2{ 35 , 35 }); Circle ac{ Vector2{10 , 15 }, 5 }; Circle bc{ Vector2{0 , 0 }, 1 }; Circle cc{ Vector2{25 , 25 }, 5 }; Plane2D ap{ Vector2{15 ,15 } , Vector2{0 ,1 } }; Plane2D bp{ Vector2{15 ,15 } , Vector2{1 ,0 } }; Plane2D cp{ Vector2{0 ,0 } , Vector2{0 ,1 } }; Ray2D ar{ Vector2{0,0 }, normal(Vector2{0.5,0.5}), 50 }; Ray2D br{ Vector2{14.9f,1}, Vector2{0,1}, 50 }; Ray2D cr{ Vector2{1,13}, Vector2{1,0}, 50 }; ConvexHull2D chull; chull.size = 4; chull.verts[0] = Vector2{ 20,22 }; chull.verts[1] = Vector2{ 23,18 }; chull.verts[2] = Vector2{ 26,22 }; chull.verts[3] = Vector2{ 23,28 }; #pragma endregion //AABB2D VS AABB2D assert( iTest(ab, bb)); assert(!iTest(ab, cb)); assert( iTest(bb, cb)); //AABB2D VS CIRCLE assert( iTest(ab, ac)); assert(!iTest(ab, bc)); assert(!iTest(ab, cc)); assert( iTest(bb, ac)); assert(!iTest(bb, bc)); assert( iTest(bb, cc)); assert(!iTest(cb, ac)); assert(!iTest(cb, bc)); assert( iTest(cb, cc)); //AABB2D VS PLANE assert( iTest(ab, ap)); assert( iTest(ab, bp)); assert(!iTest(ab, cp)); assert( iTest(bb, ap)); assert( iTest(bb, bp)); assert(!iTest(bb, cp)); assert(!iTest(cb, ap)); assert(!iTest(cb, bp)); assert(!iTest(cb, cp)); //AABB2D VS RAY2D assert( iTest(ab, ar)); assert( iTest(ab, br)); assert( iTest(ab, cr)); assert( iTest(bb, ar)); assert(!iTest(bb, br)); assert(!iTest(bb, cr)); assert( iTest(cb, ar)); assert(!iTest(cb, br)); assert(!iTest(cb, cr)); //AABB VS CONVEX2D assert(iTest_data(chull, ab).penDepth <= 0); assert(iTest_data(chull, bb).penDepth > 0); assert(iTest_data(chull, cb).penDepth <= 0); }
void CViewTester::HandleContactViewEvent(const CContactViewBase& aView,const TContactViewEvent& aEvent) /** * for each of the Remote and Filtered Views we wait for certain events * iState Event * EWait_RemoteView Named Remote View to become EReady * EWait_FilteredView Filtered View to become EReady * EWait_SortViewEvents Named Remote View to become EUnavailable, and then ESortOrderChanged * Filtered View to become EUnavailable, and then ESortOrderChanged * The last expected event in each state calls NextState() for the test state machine. * Any other event, or any event in another test state, is an error. */ { // view reference is correct? if(&aView != iNamedRemoteView && &aView != iFilteredView) { iTest.Printf(_L("test error: event for unknown View\n")); User::Invariant(); } TBool expectedEvent = EFalse; // assume this is not the event we are looking for // is this the/an event we are expecting now? switch(aEvent.iEventType) { case TContactViewEvent::EReady: if(iState == EWait_RemoteView && &aView == iNamedRemoteView) { // Remote View is now ready, go to next test state iRemoteViewEvent = aEvent.iEventType; iTest.Printf(_L("event: Remote View ready\n")); expectedEvent = ETrue; NextState(); } else if(iState == EWait_FilteredView && &aView == iFilteredView) { // Filter View is now ready, go to next test state iFilteredViewEvent = aEvent.iEventType; iTest.Printf(_L("event: Filtered View ready\n")); expectedEvent = ETrue; NextState(); } break; case TContactViewEvent::EUnavailable: if(iState == EWait_SortViewEvents && &aView == iNamedRemoteView) { // Remote View, but correct event? if(iRemoteViewEvent == TContactViewEvent::EReady) { iRemoteViewEvent = aEvent.iEventType; iTest.Printf(_L("event: Remote View unavailable\n")); expectedEvent = ETrue; } } else if(iState == EWait_SortViewEvents && &aView == iFilteredView) { if(iFilteredViewEvent == TContactViewEvent::EReady) { iFilteredViewEvent = aEvent.iEventType; iTest.Printf(_L("event: Filtered View unavailable\n")); expectedEvent = ETrue; } } break; case TContactViewEvent::ESortOrderChanged: if(iState == EWait_SortViewEvents) { if(&aView == iNamedRemoteView && iRemoteViewEvent == TContactViewEvent::EUnavailable) { iRemoteViewEvent = aEvent.iEventType; iTest.Printf(_L("event: Remote View sort order changed\n")); expectedEvent = ETrue; } else if(&aView == iFilteredView && iFilteredViewEvent == TContactViewEvent::EUnavailable) { iFilteredViewEvent = aEvent.iEventType; iTest.Printf(_L("event: Filtered View sort order changed\n")); expectedEvent = ETrue; } // both views now Re-Sorted ? if(iRemoteViewEvent == TContactViewEvent::ESortOrderChanged && iFilteredViewEvent == TContactViewEvent::ESortOrderChanged) { NextState(); } } break; default: // unexpected event break; } if(!expectedEvent) { // valid View, but unexpected event iTest.Printf(_L("test error: unexpected View event\n")); TRAP_IGNORE(CleanupFilesL() ); iTest( EFalse ); } return; }
EXPORT_C void CIpuTestHarness::operator()(TInt aResult,TInt aLineNum) // // Overload operator () { iTest(aResult, aLineNum); }
void CViewTester::RunL() { switch (iState) { case ECreate_RemoteView: iTest.Next(_L("Named Remote View creation View Ready event")); iNamedRemoteView = CContactNamedRemoteView::NewL( *this, KViewName, iDb, iSortOrder[0], EContactsOnly ); // Wait for view to be created iTimer.After( iStatus, KViewWaitTimeout ); SetActive(); NextState(); break; // It is an error for the RTimer to trigger before the state has changed. case EWait_RemoteView: iTest.Printf(_L("Timeout waiting for Remote View to be created")); TRAP_IGNORE(CleanupFilesL() ); iTest( EFalse); // failed break; case ECreate_FilteredView: iTest.Next(_L("Filtered View creation View Ready event")); iFilteredView = CContactFilteredView::NewL( *this, iDb, *iNamedRemoteView, CContactDatabase::ESmsable ); // Wait for view to be created iTimer.After( iStatus, KViewWaitTimeout ); SetActive(); NextState(); break; // It is an error for the RTimer to trigger before the state has changed. case EWait_FilteredView: iTest.Printf(_L("Timeout waiting for Filtered View to be created")); TRAP_IGNORE(CleanupFilesL() ); iTest( EFalse ); // failed break; case EChangeSortOrder: iTest.Next(_L("Re-sort Remote View and Filtered View, wait for view events")); iNamedRemoteView->ChangeSortOrderL( iSortOrder[1] ); // Wait for views to be resorted iTimer.After( iStatus, KViewWaitTimeout ); SetActive(); NextState(); break; // It is an error for the RTimer to trigger before the state has changed. case EWait_SortViewEvents: // Give information on what went wrong: iTest.Printf(_L("Test Timeout waiting for Filtered and Remote View to be resorted:\n")); switch(iRemoteViewEvent) { case TContactViewEvent::EReady: iTest.Printf(_L(" Named Remote View; sort not started\n")); break; case TContactViewEvent::EUnavailable: iTest.Printf(_L(" Named Remote View; sort not finished\n")); break; case TContactViewEvent::ESortOrderChanged: // Remote View Sorted & Ready break; default: // error in test User::Invariant(); } switch(iFilteredViewEvent) { case TContactViewEvent::EReady: iTest.Printf(_L(" Filtered View; sort not started\n")); break; case TContactViewEvent::EUnavailable: iTest.Printf(_L(" Filtered View; sort not finished\n")); break; case TContactViewEvent::ESortOrderChanged: // Filtered View Sorted & Ready break; default: // error in test User::Invariant(); } TRAP_IGNORE(CleanupFilesL() ); iTest( EFalse ); // failed break; case EFinished: CActiveScheduler::Stop(); // we're done. break; default: ASSERT(EFalse); break; } }
void DebugRay2D() { #pragma region TestShapes AABB2D ab(Vector2{ 10 , 10 }, Vector2{ 20 , 20 }); AABB2D bb(Vector2{ 15 , 15 }, Vector2{ 25 , 25 }); AABB2D cb(Vector2{ 25 , 25 }, Vector2{ 35 , 35 }); Circle ac{ Vector2{ 20, 20 }, 5 }; Circle bc{ Vector2{ 10 , 10 }, 8 }; Circle cc{ Vector2{ 25 , 25 }, 5 }; Plane2D ap{ Vector2{ 15 ,15 } , Vector2{ 0 ,1 } }; Plane2D bp{ Vector2{ 15 ,15 } , Vector2{ 1 ,0 } }; Plane2D cp{ Vector2{ 1 ,1 } , Vector2{ 0 ,-1 } }; Ray2D ar{ Vector2{ 0,0 }, normal(Vector2{ 0.5,0.5 }), 50 }; Ray2D br{ Vector2{ 14.9f,1 }, Vector2{ 0,1 }, 50 }; Ray2D cr{ Vector2{ 1,13 }, Vector2{ 1,0 }, 50 }; Ray2D dr{ Vector2{ -15,8 }, Vector2{ 1,0 }, 50 }; ConvexHull2D achull, bchull, cchull; achull.size = 4; achull.verts[0] = Vector2{ 26,22 }; achull.verts[1] = Vector2{ 23,28 }; achull.verts[2] = Vector2{ 20,22 }; achull.verts[3] = Vector2{ 23,18 }; bchull.size = 3; bchull.verts[0] = Vector2{ 30,10 }; bchull.verts[1] = Vector2{ 20,20 }; bchull.verts[2] = Vector2{ 12,10 }; cchull.size = 5; cchull.verts[0] = Vector2{ -5 , 10 }; cchull.verts[1] = Vector2{ -10 , 20 }; cchull.verts[2] = Vector2{ -15 , 10 }; cchull.verts[3] = Vector2{ -12.5 , 5 }; cchull.verts[4] = Vector2{ -7.5 , 5 }; #pragma endregion //RAY2D VS AABB2D assert(iTest(ab, ar)); assert(iTest(ab, br)); assert(iTest(ab, cr)); assert(iTest(bb, ar)); assert(!iTest(bb, br)); assert(!iTest(bb, cr)); assert(iTest(cb, ar)); assert(!iTest(cb, br)); assert(!iTest(cb, cr)); //RAY2D VS CIRCLE assert(iTest(ac, ar)); assert(!iTest(ac, br)); assert(!iTest(ac, cr)); assert(iTest(bc, ar)); assert(iTest(bc, br)); assert(iTest(bc, cr)); assert(iTest(cc, ar)); assert(!iTest(cc, br)); assert(!iTest(cc, cr)); //RAY2D VS PLANE assert(!iTest(ap, ar)); assert(!iTest(ap, br)); assert(!iTest(ap, cr)); assert(!iTest(bp, ar)); assert(!iTest(bp, br)); assert(!iTest(bp, cr)); assert(iTest(cp, ar)); assert(iTest(cp, br)); assert(!iTest(cp, cr)); //RAY2D VS CONVEX2D assert(iTest_data(achull, ar).penDepth > 0); assert(iTest_data(achull, br).penDepth <= 0); assert(iTest_data(achull, cr).penDepth <= 0); assert(iTest_data(bchull, ar).penDepth <= 0); assert(iTest_data(bchull, br).penDepth > 0); assert(iTest_data(bchull, cr).penDepth > 0); assert(iTest_data(cchull, dr).penDepth > 0); }
bool iTest(const Ray2D &ac, const Circle &bc) { return iTest(bc, ac); }
bool iTest(const Ray2D &ac, const AABB2D &bc) { return iTest(bc, ac); }
EXPORT_C void CIpuTestHarness::operator()(TInt aResult) // // Overload operator () { iTest(aResult); }