void CTest_Downloader::testDownloadOfflineL() { TCountingObserver o(2); auto_ptr<CDownloader> d(CDownloader::NewL( AppContext(), iDb->Db(), _L("c:\\unitttestdl"), o, KNullDesC, &CDummyHttp::NewL)); d->DownloadL( MAKE_TINT64(0, 1), _L("url1") ); d->SetLevelL(1); d->DownloadL( MAKE_TINT64(0, 2), _L("url2") ); d->SetDownloadLimitLevelL(1); TInt dl=d->IsDownloadable(MAKE_TINT64(0, 1)); TS_ASSERT_EQUALS ( dl, (TInt)CDownloader::ENotQueued ); dl=d->IsDownloadable(MAKE_TINT64(0, 2)); TS_ASSERT_EQUALS ( dl, (TInt)CDownloader::ENotDownloadable ); TestUtils::WaitForActiveSchedulerStopL(3); TS_ASSERT_EQUALS ( o.finished, 0 ); TS_ASSERT_EQUALS ( o.dequeued, 0 ); TS_ASSERT_EQUALS ( o.started, 0 ); TS_ASSERT_EQUALS ( o.error, 0 ); d->SetNoDownloadLimitLevelL(); TestUtils::WaitForActiveSchedulerStopL(10); TS_ASSERT_EQUALS ( o.finished, 1 ); TS_ASSERT_EQUALS ( o.dequeued, 1 ); TS_ASSERT_EQUALS ( o.started, o.finished+o.error+o.retriable_error ); TS_ASSERT_EQUALS ( o.error, 0 ); }
LOCAL_C void Test2() { // Invalid clamp requests test.Next(_L("T_DENYCLAMP - Test2()")); // Test attempt to clamp empty file is rejected RFileClamp handle2; TBuf<256> file2Name; file2Name = _L("clampFile2.tst"); RFile testFile2; TInt r=testFile2.Replace(TheFs,file2Name,EFileWrite); test(r==KErrNone); r=handle2.Clamp(testFile2); test(r==KErrPermissionDenied); // Try to unclamp non-existant file // Using a invalid-content cookie is OK - the request should // be rejected before the content is examined handle2.iCookie[0] = MAKE_TINT64(-1,-1); // iCookie[0] holds the unique ID handle2.iCookie[1] = MAKE_TINT64(-1,-1); r=handle2.Close(TheFs); test (r==KErrPermissionDenied); // Tidy up testFile2.Close(); r=TheFs.Delete(_L("clampFile2.tst")); test (r==KErrNone); }
LOCAL_C TInt32 GetSpeed(TInt aOps, TInt64 aDtime) /// Calculate and return the throughput from the umber of blocks transferred /// and the elapsed time. { TInt64 dsize = MAKE_TINT64(0, aOps) * MAKE_TINT64(0, KBufLen) * MAKE_TINT64(0, KSecond); TInt32 speed = I64LOW((dsize + aDtime/2) / aDtime); return speed; }
void CTest_Downloader::testDownloadFailL() { TCountingObserver o(2); auto_ptr<CDownloader> d(CDownloader::NewL( AppContext(), iDb->Db(), _L("c:\\unitttestdl"), o, KNullDesC, &CDummyHttp::NewL)); d->DownloadL( MAKE_TINT64(0, 1), _L("url1") ); d->DownloadL( MAKE_TINT64(0, 2), KFailUrl ); TestUtils::WaitForActiveSchedulerStopL(300); TS_ASSERT_EQUALS ( o.finished, 1 ); TS_ASSERT_EQUALS ( o.started, o.finished+o.error+o.retriable_error ); TS_ASSERT_EQUALS ( o.error, 1 ); }
void CTest_Downloader::testDownloadNetworkSeveralL() { TCountingObserver o(3); auto_ptr<CDownloader> d(CDownloader::NewL( AppContext(), iDb->Db(), _L("c:\\unitttestdl"), o, KNullDesC)); d->DownloadL( MAKE_TINT64(0, 1), _L("http://farm3.static.flickr.com/2416/2069068288_8dc58d03de_m.jpg") ); d->DownloadL( MAKE_TINT64(0, 2), _L("http://jaiku.com/") ); d->DownloadL( MAKE_TINT64(0, 3), _L("http://jaiku.com/") ); TestUtils::WaitForActiveSchedulerStopL(20); TS_ASSERT_EQUALS ( o.finished, 3 ); TS_ASSERT_EQUALS ( o.started, 3 ); TS_ASSERT_EQUALS ( o.error, 0 ); }
// --------------------------------------------------------------------------- // Starts the periodic timer. 32-bit delay and interval parameters. // --------------------------------------------------------------------------- // EXPORT_C void CFlexPeriodic::Start( TTimeIntervalMicroSeconds32 aDelay, TTimeIntervalMicroSeconds32 anInterval, TCallBack aCallBack, TCallBack aCallBackError ) { OstTraceExt4( TRACE_NORMAL, CFLEXPERIODIC_START32, "CFlexPeriodic::Start32;this=%x;aDelay=%d;" "anInterval=%d;aCallBack=%x", ( TUint )this, aDelay.Int(), anInterval.Int(), ( TUint )&( aCallBack ) ); TTimeIntervalMicroSeconds32 zero( 0 ); __ASSERT_ALWAYS(aDelay >= zero, User::Panic(KCFlexPeriodicPanicCat, EFlexPeriodicDelayLessThanZero)); __ASSERT_ALWAYS(anInterval > zero, User::Panic(KCFlexPeriodicPanicCat, EFlexPeriodicIntervalTooSmall)); __ASSERT_ALWAYS( aCallBack.iFunction != NULL, User::Panic(KCFlexPeriodicPanicCat, EFlexPeriodicCallbackFunctionIsNull)); // aCallBackError is left unasserted on purpose. // if error occurs and callback is null client is paniced. // Interval value is saved for later use, delay is sent immediately // to the server. iInterval = MAKE_TINT64( 0, anInterval.Int() ); iCallBack = aCallBack; iCallBackError = aCallBackError; CFlexTimer::After( aDelay ); }
// --------------------------------------------------------------------------- // // --------------------------------------------------------------------------- // CMRCalendarInfoImpl::CMRCalendarInfoImpl() : CMRCalendarInfo( KMailboxExtMrCalInfo ) { NM_FUNCTION; iDatabaseId = MAKE_TINT64(0,0); }
LOCAL_C void Test1() { // Basic clamp operation test.Next(_L("T_DENYCLAMP - Test1()")); TBuf<256> fileName; TBuf<256> buf(_L("buffer for file used")); fileName = _L("clampFile.tst"); RFile testFile; TInt r=testFile.Replace(TheFs,fileName,EFileWrite); test(r==KErrNone); TPtrC8 pBuf((TUint8*)&buf); testFile.Write(pBuf); testFile.Flush(); // Attempt to clamp file should be rejected RFileClamp handle; r=handle.Clamp(testFile); test(r==KErrPermissionDenied); // Attempt to unclamp a file should be rejected // Using an invalid-content cookie is OK - the request should // be rejected before the content is examined handle.iCookie[0]=MAKE_TINT64(-1,-1); handle.iCookie[1]=0; r=handle.Close(TheFs); test (r==KErrPermissionDenied); // Tidy up testFile.Close(); r=TheFs.Delete(_L("clampFile.tst")); test (r==KErrNone); }
// ----------------------------------------------------------------------------- void CPresenceCacheBuddyInfo::InternalizeL( RReadStream& aStream ) { iAvailability = (MPresenceBuddyInfo2::TAvailabilityValues)aStream.ReadInt32L( ); HBufC* temp = InternalizeFieldL( aStream ); iBuddyId = temp; iIds.ResetAndDestroy(); iValues.ResetAndDestroy(); HBufC* key = NULL; HBufC8* value = NULL; // internalize expiry time TUint32 time_high = aStream.ReadUint32L(); TUint32 time_low = aStream.ReadUint32L(); iExpiryTime = MAKE_TINT64( time_high, time_low ); TInt count = aStream.ReadInt32L( ); for ( TInt i=0; i < count; i++ ) { key = InternalizeFieldL( aStream ); CleanupStack::PushL( key ); value = InternalizeField8L( aStream ); CleanupStack::Pop( key ); // This takes ownership anyway. SetAnyFieldPtrL( key, value ); } }
// --------------------------------------------------------------------------- // Configures the flex window sizes for both the initial delay and the // consequent intervals after that. // --------------------------------------------------------------------------- // EXPORT_C TInt CFlexPeriodic::Configure( TTimeIntervalMicroSeconds32 aDelayWindow, TTimeIntervalMicroSeconds32 aIntervalWindow ) { OstTraceExt3( TRACE_NORMAL, CFLEXPERIODIC_CONFIGURE, "CFlexPeriodic::Configure32;this=%x;" "aDelayWindow=%d;aIntervalWindow=%d", ( TUint )this, aDelayWindow.Int(), aIntervalWindow.Int() ); TTimeIntervalMicroSeconds32 zero( 0 ); __ASSERT_ALWAYS(aDelayWindow >= zero, User::Panic(KCFlexPeriodicPanicCat, EFlexPeriodicDelayWindowLessThanZero)); __ASSERT_ALWAYS(aIntervalWindow >= zero, User::Panic(KCFlexPeriodicPanicCat, EFlexPeriodicIntervalWindowLessThanZero)); // interval window is saved for later use. Delay window is sent // immediately to server. TInt ret = CFlexTimer::Configure( aDelayWindow ); if ( ret == KErrNone ) { // Interval window is changed only, if configuration is successful. iIntervalWindow = MAKE_TINT64( 0, aIntervalWindow.Int() ); iSendConfigure = ETrue; } return ret; }
TInt TFileOps::Open(TChar aDrvCh, TInt aNum) /// Open the file for testing, give error if there is not enough space for it. /// @param aDrvCh Drive letter. /// @param aNum File number suffix. { TVolumeInfo vol; TInt drv; TInt r = TheFs.CharToDrive(aDrvCh, drv); if (r != KErrNone) TTest::Fail(HERE, _L("CharToDrive(%c) returned %d"), (TUint)aDrvCh, r); r = TheFs.Volume(vol, drv); if (r != KErrNone) TTest::Fail(HERE, _L("Volume(%c:) returned %d"), (TUint)aDrvCh, r); iMax = I64LOW(vol.iFree / MAKE_TINT64(0,KBufLen)) / 2 - 1; if (iMax < 10) TTest::Fail(HERE, _L("Not enough space to do test, only %d KB available"), I64LOW(vol.iFree/1024)); Reset(); iName.Format(_L("%c:\\TEST_%d"), (TUint)aDrvCh, aNum); r = iF.Replace(TheFs, iName, EFileStreamText | EFileWrite); if (r == KErrNone) iOpen = ETrue; return r; }
// ----------------------------------------------------------------------------- // TSdpTypedTime::InternalizeL // Internalizes typed time from stream // ----------------------------------------------------------------------------- // TSdpTypedTime TSdpTypedTime::InternalizeL(RReadStream& aStream) { TUint32 high = aStream.ReadUint32L(); TUint32 low = aStream.ReadUint32L(); TInt64 value = MAKE_TINT64( high, low ); TUnit unit = static_cast<TUnit>(aStream.ReadInt16L()); TSdpTypedTime typedTime(value, unit); return typedTime; }
void CTest_Downloader::testDownloadNetworkOneL() { TCountingObserver o(1); auto_ptr<CDownloader> d(CDownloader::NewL( AppContext(), iDb->Db(), _L("c:\\unitttestdl"), o, KNullDesC)); d->DownloadL( MAKE_TINT64(0, 1), _L("http://jaiku.com/") ); TestUtils::WaitForActiveSchedulerStopL(5); TS_ASSERT_EQUALS ( o.finished, 1 ); TS_ASSERT_EQUALS ( o.started, 1 ); TS_ASSERT_EQUALS ( o.error, 0 ); }
// --------------------------------------------------------------------------- // CGpxConverterAO::ReadTagIdL // Read Tag Id from temp-file // --------------------------------------------------------------------------- void CGpxConverterAO::ReadTagIdL() { LOG("CGpxConverterAO::ReadTagIdL ,begin"); TUint32 low( 0 ); TUint32 high( 0 ); low = iReader.ReadUint32L(); high = iReader.ReadUint32L(); iTagId = MAKE_TINT64( high, low ); LOG("CGpxConverterAO::ReadTagIdL ,end"); }
//The clock_settime allow the calling process to set the value used by a //clock which is specified by clock_id EXPORT_C int clock_settime (clockid_t clock_id, const struct timespec *tp) { int retval = -1; TTime t(MAKE_TINT64 (0x00dcddb3 ,0x0f2f8000)) ; // 00:00, Jan 1st 1970 TInt err; TInt64 microtime; //We must get a filled structure from the user of the library if(tp == NULL) { errno = EFAULT; return retval; } //Check for boundary values of seconds and microseconds if (tp->tv_nsec < 0 || tp->tv_nsec >= 1000000000L) { errno = ERANGE; return retval; } switch(clock_id) { case CLOCK_REALTIME: //We support only the wall-clock,hence use the //User::SetHomeTime call to set the time t+=(TTimeIntervalSeconds)tp->tv_sec; microtime = (tp->tv_nsec)/1000; t+=(TTimeIntervalMicroSeconds)microtime; err = User::SetUTCTime(t); if(err) { MapError(err,errno); break; } else retval = 0; break; default: //For all other clocks that cannot be supported or invalid clockids, //we set errno to invalid retval = -1; errno = EINVAL; break; } return retval; }
void CTest_Downloader::testConnectivity1L() { TCountingObserver o(3, 2); auto_ptr<CDownloader> d(CDownloader::NewL( AppContext(), iDb->Db(), _L("c:\\unitttestdl"), o, KNullDesC, &CDummyHttp::NewL)); d->DownloadL( MAKE_TINT64(0, 1), _L("fail") ); auto_ptr<CCallTester> t(CCallTester::NewL(d->ConnectivityListener())); TestUtils::WaitForActiveSchedulerStopL(3); TS_ASSERT_EQUALS ( o.finished, 0 ); TS_ASSERT_EQUALS ( o.dequeued, 0 ); TS_ASSERT_EQUALS ( o.started, 1 ); TS_ASSERT_EQUALS ( o.retriable_error, 1 ); TS_ASSERT_EQUALS ( o.conn_changed,2 ); }
void CTestXonXoff::ReadComplete(TInt aStatus) { if (iTrace) Test.Printf(_L("CTestXonXoff::ReadComplete(%d) len = %d/%d (%d)\r\n"), aStatus, iReader->iDes.Length(), iReader->iDes.MaxLength(), iReader->iTotal); if (aStatus!=KErrNone) { Fail(ETestFailRead, aStatus); return; } switch (iState) { case EWaitIO: iRetries = 0; iTimer->Cancel(); if (!CheckDes(iReader->iDes, 0, iReader->iDes.Length(), '@', 'Z', iCount & 0x3fff)) { Fail(ETestBadData, aStatus); return; } iCount += iReader->iCount; iPackets++; { TTime end; end.UniversalTime(); TInt64 difftime = (end.MicroSecondsFrom(iStartTime).Int64()+TInt64(500000))/TInt64(1000000); if (difftime==0) difftime = 1; TInt64 cps = MAKE_TINT64(0,iCount)/difftime; TInt rate = (I64INT(cps)*10000)/11520; iRate += rate; iSpeed += I64INT(cps); Test.Printf(_L("%c %6d %d (%dbps=%d.%02d%%)\r"), KSpinner[iSpin++ & 3], iPackets, iCount, iSpeed/iPackets, (iRate/iPackets)/100, (iRate/iPackets)%100); } Read(); break; default: break; } }
/** Read local clock configuration. */ void CAutoClockAdjust::ReadLocalSettingsL() { LBSLOG(ELogP1, "CAutoClockAdjust::ReadLocalSettingsL()\n"); TInt valHi; TInt valLo; TInt err; TInt64 val; err = iCenRep->Get(KLastAutoClockAdjustmentHi, valHi); ASSERT(err == KErrNone); if (err != KErrNone) { // Retry err = iCenRep->Reset(); ASSERT(err == KErrNone); User::LeaveIfError(iCenRep->Get(KLastAutoClockAdjustmentHi, valHi)); } User::LeaveIfError(iCenRep->Get(KLastAutoClockAdjustmentLo, valLo)); val = MAKE_TINT64(valHi, valLo); iLastAdjustment = val; }
LOCAL_C void Test4(TDesC& aRoot) { // Clamp tests for non-writable file system test.Next(_L("T_DENYCLAMP - Test4()")); TBuf<256> pathName; #ifdef __WINS__ if((aRoot[0]=='Z')||(aRoot[0]=='z')) pathName=_L("clean.txt"); else pathName=_L("root.txt"); #else if((aRoot[0]=='Z')||(aRoot[0]=='z')) pathName=_L("UnicodeData.txt"); else pathName=_L("\\Test\\clamp.txt"); // For (non-composite) ROFS drive #endif RFile testFile; TInt r=testFile.Open(TheFs, pathName, EFileRead); test(r==KErrNone); // Attempt to clamp file RFileClamp handle; r=handle.Clamp(testFile); test(r==KErrPermissionDenied); // Unclamp file // Using an invalid-content cookie is OK - the request should // be rejected before the content is examined handle.iCookie[0]=MAKE_TINT64(-1,-1); handle.iCookie[1]=0; r=handle.Close(TheFs); test (r==KErrPermissionDenied); testFile.Close(); }
void CBkmrkProperties::TransLoadL() { TUint32 indexBase = IndexBase(); TInt low = 0; TInt high = 0; TInt err = iRepository->Get( indexBase + KBkmrkLastModifiedLoIndex, low ); if ( err == KErrNone ) { User::LeaveIfError(iRepository->Get(indexBase + KBkmrkLastModifiedHiIndex, high)); TUint32 timeLo = static_cast<TUint32>(low); TUint32 timeHi = static_cast<TUint32>(high); TInt64 time = MAKE_TINT64(timeHi, timeLo); iLastModified = time; } else { // Set the time as 1st January 1970 midnight. TDateTime dt ( 1970, EJanuary, 1, 0, 0, 0, 0 ); iLastModified = TTime ( dt ); } HBufC* descBuffer = HBufC::NewLC(Bookmark::KMaxDescriptorLength); TPtr descPtr = descBuffer->Des(); User::LeaveIfError(iRepository->Get(indexBase + KCmnDescriptionIndex, descPtr)); delete iDescription; iDescription = NULL; iDescription = descPtr.AllocL(); CleanupStack::PopAndDestroy(descBuffer); TInt retVal; User::LeaveIfError(iRepository->Get(indexBase + KCmnIconIndex, retVal)); iIconId = static_cast<Bookmark::TAttachmentId>(retVal); iCustomProperties->TransLoadL(); SetClean(); }
void MeasureByNOPs() { test.Start(_L("Create thread")); RThread t; TInt r=t.Create(KLitThreadName,CountNops,0x1000,NULL,NULL); test(r==KErrNone); t.SetPriority(EPriorityAbsoluteVeryLow); t.Resume(); test.Next(_L("Get processor clock frequency")); TMachineInfoV2Buf buf; TMachineInfoV2& info=buf(); r=UserHal::MachineInfo(buf); test(r==KErrNone); MaxCycles=info.iProcessorClockInKHz*1000; test.Printf(_L("Clock frequency %dHz\n"),MaxCycles); TRequestStatus s; CConsoleBase* console=test.Console(); console->Read(s); #ifdef __WINS__ TInt timerperiod = 5; UserSvr::HalFunction(EHalGroupEmulator,EEmulatorHalIntProperty,(TAny*)"TimerResolution",&timerperiod); #endif FOREVER { TUint32 init_count=NopCount; TUint32 init_ms=User::NTickCount(); User::After(1000000); TUint32 final_count=NopCount; TUint32 final_ms=User::NTickCount(); TUint32 cycles=final_count-init_count; TUint32 ms=final_ms-init_ms; #ifdef __WINS__ ms*=timerperiod; #endif while (s!=KRequestPending) { User::WaitForRequest(s); TKeyCode k=console->KeyCode(); if (k==EKeyTab) { // calibrate TInt64 inst64 = MAKE_TINT64(0, cycles); inst64*=1000; inst64/=MAKE_TINT64(0,ms); MaxCycles=I64LOW(inst64); test.Printf(_L("NOPs per second %u\n"),MaxCycles); } else if (k==EKeyEscape) return; console->Read(s); } TInt64 used64=MAKE_TINT64(0, MaxCycles); used64-=MAKE_TINT64(0,cycles); used64*=1000000; used64/=MAKE_TINT64(0,ms); used64/=MAKE_TINT64(0, MaxCycles); test.Printf(_L("%4d\n"),I64INT(used64)); } }
{_S("<2147483646"),ROWS(1,5)}, {_S(">2147483647"),NO_ROWS}, {_S("=40"),NO_ROWS} }; struct TypeInt64 { public: static const TText* const KType; static const TInt64 KValues[]; static const TSelectTest KTests[]; }; const TText* const TypeInt64::KType=_S("BIGINT"); const TInt64 TypeInt64::KValues[]= { MAKE_TINT64(0x80000000, 0x00000000), // min int64 _LINT64(-4294967296), TInt(0x80000000), // -2147483648! -1, 0u, 1u, 2147483647u, _LINT64(2147483648), _LINT64(4294967295), _LINT64(4294967296), _LINT64(9223372036854775807) // max int64 }; const TSelectTest TypeInt64::KTests[]= { {_S("IS NULL"),ROW(0)}, {_S("IS NOT NULL"),ALL_ROWS},
LOCAL_C TInt testAsyncAccess(TChar dc1, TChar dc2) // // Test one drive against the other. // { TFileOps f1; TFileOps f2; f1.Open(dc1, 1); if (dc1 != dc2) f2.Open(dc2, 2); TInt op1 = 0; TInt op2 = 0; RTimer timer; TRequestStatus tstat; TTime startTime; TTime endTime; TTimeIntervalMicroSeconds timeTaken; timer.CreateLocal(); timer.After(tstat, KTimeBM * KSecond); startTime.HomeTime(); while (tstat == KRequestPending) { TInt num = f1.Write(); num += f2.Write(); if (num == 0) User::WaitForAnyRequest(); } op1 = f1.End(); op2 = f2.End(); endTime.HomeTime(); timeTaken=endTime.MicroSecondsFrom(startTime); TInt64 dtime = timeTaken.Int64(); TTest::Printf(_L("%c: %8d writes in %6d mS = %8d bytes per second\n"), (TUint)dc1, op1, I64LOW(dtime)/1000, GetSpeed(op1, dtime)); if (dc1 != dc2) TTest::Printf(_L("%c: %8d writes in %6d mS = %8d bytes per second\n"), (TUint)dc2, op2, I64LOW(dtime)/1000, GetSpeed(op2, dtime)); AddStats(gWrStats, MAKE_TINT64(0, op1 + op2) * MAKE_TINT64(0, KBufLen) * MAKE_TINT64(0, KSecond), dtime); // now the reads! f1.Reset(); f2.Reset(); timer.After(tstat, KTimeBM * KSecond); startTime.HomeTime(); while (tstat == KRequestPending) { f1.Read(); f2.Read(); User::WaitForAnyRequest(); } op1 = f1.End(); op2 = f2.End(); endTime.HomeTime(); timeTaken=endTime.MicroSecondsFrom(startTime); dtime = timeTaken.Int64(); TTest::Printf(_L("%c: %8d reads in %6d mS = %8d bytes per second\n"), (TUint)dc1, op1, I64LOW(dtime)/1000, GetSpeed(op1, dtime)); if (dc1 != dc2) TTest::Printf(_L("%c: %8d reads in %6d mS = %8d bytes per second\n"), (TUint)dc2, op2, I64LOW(dtime)/1000, GetSpeed(op2, dtime)); AddStats(gRdStats, MAKE_TINT64(0, op1 + op2) * MAKE_TINT64(0, KBufLen) * MAKE_TINT64(0, KSecond), dtime); test.Printf(_L("\n")); test.Printf(_L("average write throughput = %d bytes/sec\n"), GetSpeed(gWrStats)); test.Printf(_L("average read throughput = %d bytes/sec\n"), GetSpeed(gRdStats)); test.Printf(_L("\n")); gWrStats.Init(); gRdStats.Init(); timer.Cancel(); timer.Close(); f1.Close(); f2.Close(); // delay for a second to allow the close to complete before dismounting. User::After(1000000); return KErrNone; }
/** Generates a BT device address for use as an unavailable device @return BT Device Address */ TBTDevAddr CT_BTGPSDeviceListHandler::GenerateUniqueBTDevAddr() { return TBTDevAddr(MAKE_TINT64(++iUniqueAddr, 0x01234567)); }
/** Open the device and do some initalisation work. @param aParams device parameters @return Epoc error code, KErrNone if everything is OK */ TInt CWinVolumeDevice::Connect(const TMediaDeviceParams& aParams) { __PRINT(_L("#-- CWinVolumeDevice::Connect()")); if(!aParams.ipDevName) { __LOG(_L("#-- CWinVolumeDevice::Connect() device name is not set!")); return KErrBadName; } __PRINTF(aParams.ipDevName); ASSERT(!HandleValid() && ipScratchBuf); //-- open the device DWORD dwAccess = GENERIC_READ; if(!aParams.iReadOnly) dwAccess |= GENERIC_WRITE; iDevHandle = CreateFileA(aParams.ipDevName, dwAccess, FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(!HandleValid()) { __LOG1(_L("#-- CWinVolumeDevice::Connect() Error creating device handle! WinErr:%d"), GetLastError()); return KErrGeneral; } //-- find out device geometry iMediaType = Unknown; iDrvGeometry.iBytesPerSector = KDefaultSectorSz; DWORD junk; //-- 1. try to query disk geometry, but it can produce wrong results for partitioned media BOOL bResult = DeviceIoControl(Handle(), IOCTL_DISK_GET_DRIVE_GEOMETRY, NULL, 0, ipScratchBuf, KScratchBufSz, &junk, (LPOVERLAPPED)NULL); if(bResult) { const DISK_GEOMETRY& dg = (const DISK_GEOMETRY&)*ipScratchBuf; iDrvGeometry.iBytesPerSector = dg.BytesPerSector; iMediaType = dg.MediaType; __PRINT3(_L("#-- dev geometry: Cyl:%d Heads:%d Sectors:%d"), dg.Cylinders.LowPart, dg.TracksPerCylinder, dg.SectorsPerTrack); __PRINT2(_L("#-- dev geometry: MediaType:%d, bps:%d"), dg.MediaType, dg.BytesPerSector); } else { iMediaType = Unknown; iDrvGeometry.iBytesPerSector = KDefaultSectorSz; __LOG1(_L("#-- CWinVolumeDevice::Connect() IOCTL_DISK_GET_DRIVE_GEOMETRY WinError:%d !"), GetLastError()); } //-- 1.1 check "bytes per sector" value and how it corresponds to the request from parameters if(aParams.iDrvGeometry.iBytesPerSector == 0) {//-- do nothing, this parameter is not set in config file, use media's } else if(aParams.iDrvGeometry.iBytesPerSector != iDrvGeometry.iBytesPerSector) {//-- we can't set "SectorSize" value for the physical media __LOG1(_L("#-- CWinVolumeDevice::Connect() can not use 'Sec. Size' value from config:%d !"), aParams.iDrvGeometry.iBytesPerSector); Disconnect(); return KErrArgument; } ASSERT(IsPowerOf2(BytesPerSector()) && BytesPerSector() >= KDefaultSectorSz && BytesPerSector() < 4096); //-- find out partition information in order to determine volume size. bResult = DeviceIoControl(Handle(), IOCTL_DISK_GET_PARTITION_INFO, NULL, 0, ipScratchBuf, KScratchBufSz, &junk, (LPOVERLAPPED)NULL); if(!bResult) {//-- this is a fatal error __LOG1(_L("#-- CWinVolumeDevice::Connect() IOCTL_DISK_GET_PARTITION_INFO WinError:%d !"), GetLastError()); Disconnect(); return KErrBadHandle; } //-- get partition informaton const PARTITION_INFORMATION& pi = (const PARTITION_INFORMATION&)*ipScratchBuf; TInt64 volSz = MAKE_TINT64(pi.PartitionLength.HighPart, pi.PartitionLength.LowPart); iDrvGeometry.iSizeInSectors = (TUint32)(volSz / iDrvGeometry.iBytesPerSector); __LOG3(_L("#-- partition size, bytes:%LU (%uMB), sectors:%u"), volSz, (TUint32)(volSz>>20), iDrvGeometry.iSizeInSectors); //-- check if the media size is set in coonfig and if we can use this setting. if(aParams.iDrvGeometry.iSizeInSectors == 0) {//-- do nothing, the media size is not set in the ini file, use existing media parameters } else if(aParams.iDrvGeometry.iSizeInSectors > iDrvGeometry.iSizeInSectors) {//-- requested media size in ini file is bigger than physical media, error. //-- we can't increase physical media size __LOG2(_L("#-- CWinVolumeDevice::Connect() 'MediaSizeSectors' value from config:%d > than physical:%d !"), aParams.iDrvGeometry.iSizeInSectors, iDrvGeometry.iSizeInSectors); Disconnect(); return KErrArgument; } else if(aParams.iDrvGeometry.iSizeInSectors < iDrvGeometry.iSizeInSectors) {//-- settings specify smaller media than physical one, adjust the size __PRINT1(_L("#-- reducing media size to %d sectors"), aParams.iDrvGeometry.iSizeInSectors); iDrvGeometry.iSizeInSectors = aParams.iDrvGeometry.iSizeInSectors; } ASSERT(iDrvGeometry.iSizeInSectors > KMinMediaSizeInSectors); return KErrNone; }
void CSuspendTest::DoRandomWriteSoak() // // For each block issues an erase and then // starts issuing write requests. The intervals // between write requests are derived from the // pseudo-random number generator. // Each block is checked after is has been erased // // The same data is written each time. This data is // also generated from the random number generator. After // each erase the data is read back to check that it is // correct. // { test.Next( _L("Erase suspend soak test using random writes") ); TRandomGenerator random; random.SetSeed( 0x13E00103 ); test.Printf( _L("Preparing buffer") ); TBuf8<20> writeBuf; writeBuf.SetLength( writeBuf.MaxLength() ); for( TInt i = writeBuf.Length(); i > 0;) { --i; writeBuf[i] = static_cast<TUint8>( random.Next() ); } test.Printf( _L("Starting test") ); random.SetSeed( MAKE_TINT64( 0xA05BE111,0x00101111 ) ); iStartTime.HomeTime(); // // We repeat the test for each block, erasing block n and reading from // block (n+1) modulo iBlockCount // // // Writes are always done to the block that we just erased. This // TBool prevents us starting writes until we have erased a block. // TBool firstErase = ETrue; for(;;) { TimeSinceStart(); for( TInt eraseBlock = 0; eraseBlock < iBlockCount; eraseBlock++ ) { TUint32 writeBlock = eraseBlock - 1; if( 0 == eraseBlock ) { writeBlock = iBlockCount - 1; } TUint32 erasePos = eraseBlock * iBlockSize; TInt writePos = writeBlock * iBlockSize; test.Printf( _L("Erasing block %d, writing to block %d"), eraseBlock, writeBlock ); // // Zero the block we are about to erase // test( KErrNone == ZeroFillBlock( eraseBlock ) ); test( ValidateBlock( eraseBlock, 0 ) ); // // Start the erase // _LIT( KEraseNotify, "Main thread starting erase\n" ); test.Printf( KEraseNotify ); iEraser->EraseBlock( erasePos, iBlockSize ); // // Now we loop, waiting for random intervals, issuing // writes, until the erase completes // TBool didWrite = EFalse; while( !iEraser->CheckDone() ) { // // Get a pseudo-random interval between 0 and 524.288 milliseconds // TInt delayInMicroseconds = random.Next() % 0x80000; User::After( delayInMicroseconds ); if( !firstErase ) { test( KErrNone == iDrive.Write( writePos, writeBuf ) ); _LIT( KWriteNotify, "Done write" ); test.Printf( KWriteNotify ); didWrite = ETrue; } } // // Now check that the block was erased // test( ValidateBlock( eraseBlock, 0xFFFFFFFF ) ); firstErase = EFalse; // // Also check that the data written to the Flash is correct. // if( didWrite ) { TBuf8<20> readBuf; test( KErrNone == iDrive.Read( writePos, writeBuf.Length(), readBuf ) ); test( readBuf == writeBuf ); test.Printf( _L("Write data is ok") ); } } } }
void CActiveConsole::RunL() { // key has been pressed TChar ch = iConsole.KeyCode(); TUint8 error = KHCIOK; TUint16 opcode; TBTDevAddr remoteaddr(MAKE_TINT64(0x0002, 0x5bff0a1e)); // an example addr TBTDevAddr remoteaddr2(MAKE_TINT64(0x0002, 0x5bff0a1e)); // an example addr // Change the errors for interesting tests of stack behaviour switch (ch) { case 's': error = KHCICommandDisallowed; opcode = KCreateACLConnectionOpcode; iEmulator.CommandStatusEvent(opcode, error); break; case 'n': opcode = KNoOpcode; iEmulator.CommandStatusEvent(opcode, error); break; case 'a': opcode = KReadBdaddrOpcode; iEmulator.ReadBDAddrCompleteEvent(error); break; case 'A': opcode = KReadLocalNameOpcode; iEmulator.ReadLocalNameCompleteEvent(error); break; case 'b': opcode = KReadBufferSizeOpcode; iEmulator.ReadBufferSizeCompleteEvent(error); break; case 'B': opcode = KHostBufferSizeOpcode; iEmulator.DefaultCommandCompleteEvent(opcode, error); break; case 'p': opcode = KWritePageTimeoutOpcode; iEmulator.DefaultCommandCompleteEvent(opcode, error); break; case 'e': opcode = KWriteScanEnableOpcode; iEmulator.DefaultCommandCompleteEvent(opcode, error); break; case 'h': opcode = KSetHostControllerToHostFlowOpcode; iEmulator.DefaultCommandCompleteEvent(opcode, error); break; case 'c': opcode = KWriteConnectionAcceptTimeoutOpcode; iEmulator.DefaultCommandCompleteEvent(opcode, error); break; case 'r': opcode = KResetOpcode; iEmulator.DefaultCommandCompleteEvent(opcode, error); break; case 'l': opcode = KChangeLocalNameOpcode; iEmulator.DefaultCommandCompleteEvent(opcode, error); break; case 'i': opcode = KInquiryOpcode; iEmulator.DefaultCommandCompleteEvent(opcode, error); break; case 'I': iEmulator.InquiryCompleteEvent(error); break; case 'C': iEmulator.ConnectionCompleteEvent(error, EACLLink); break; case 'd': iEmulator.DisconnectionCompleteEvent(error, KEmulatedBaseConnectionHandle, KHCIEmulatedDisconnectionReason); break; case 'k': iEmulator.ConnectionRequestEvent(remoteaddr, KEmulatedInquiryClassOfDevice, EACLLink); break; case 'K': iEmulator.ConnectionRequestEvent(remoteaddr2, KEmulatedInquiryNullClassOfDevice, EACLLink); break; case 'x': case 'X': iEmulator.HardwareErrorEvent(); break; case 'V': case 'v': iEmulator.SpecificVendorDebugEvent(); break; case '1': //First used for reproducing DEF074193 //Sends a SCO connection request. A DisconnectComplete event will //be sent in response to the resulting //HCI_Accept_Connection_Request command. iEmulator.ConnectionRequestEvent(KDeviceAddresses[0], KEmulatedInquiryNullClassOfDevice, ESCOLink); break; case EKeyEscape: { iEmulator.Stop(); goto end; } default: iConsole.Printf(_L("Unknown command\r\n")); } // schedule another key press RequestKey(); end: return; }
void InternalizeInt64L(TInt64& aInt, RReadStream& aStream) { TInt32 low = aStream.ReadInt32L(); TInt32 high = aStream.ReadInt32L(); aInt = MAKE_TINT64(high, low); }
/** Open the device and do some initalisation work. @param aParams device parameters @return Epoc error code, KErrNone if everything is OK */ TInt CWinImgFileDevice::Connect(const TMediaDeviceParams& aParams) { __PRINT(_L("#-- CWinImgFileDevice::Connect()")); if(!aParams.ipDevName) { __LOG(_L("#-- CWinImgFileDevice::Connect() device name is not set!")); return KErrBadName; } __PRINTF(aParams.ipDevName); ASSERT(!HandleValid()); //-- 1. try to locate an image file by given name. WIN32_FIND_DATAA wfd; iDevHandle = FindFirstFileA(aParams.ipDevName, &wfd); const TBool ImgFileAlreadyExists = HandleValid(iDevHandle); FindClose(iDevHandle); iDevHandle = NULL; //-- sector size we will use within image file const TUint32 sectorSizeToUse = (aParams.iDrvGeometry.iBytesPerSector == 0) ? KDefaultSectorSz : aParams.iDrvGeometry.iBytesPerSector; TUint32 fileSzInSectorsToUse = 0; const TUint32 reqSizeSec = aParams.iDrvGeometry.iSizeInSectors; //-- required size in sectors const DWORD dwAccessMode = (aParams.iReadOnly) ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE; if(ImgFileAlreadyExists) {//-- if the image file already exists, try to open it and optionally adjust its size const TInt64 ImgFileSize = MAKE_TINT64(wfd.nFileSizeHigh, wfd.nFileSizeLow); const TUint32 ImgFileSectors = (TUint32)(ImgFileSize / sectorSizeToUse); const TBool ImgFileIsRO = wfd.dwFileAttributes & FILE_ATTRIBUTE_READONLY; DWORD dwFileCreationMode = 0; TBool bNeedToAdjustFileSize = EFalse; if(reqSizeSec == 0 || reqSizeSec == ImgFileSectors) {//-- the required size is either not specified (auto) or the same as the existing file has. //-- we can just open this file dwFileCreationMode = OPEN_EXISTING; fileSzInSectorsToUse = ImgFileSectors; } else {//-- we will have to overwrite the image file if(ImgFileIsRO) {//-- we won't be able to overwrite existing file. __LOG(_L("#-- CWinImgFileDevice::Connect() unable to adjust image file size!")); return KErrAccessDenied; } fileSzInSectorsToUse = reqSizeSec; dwFileCreationMode = CREATE_ALWAYS; bNeedToAdjustFileSize = ETrue; } iDevHandle = CreateFileA(aParams.ipDevName, dwAccessMode, FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES)NULL, dwFileCreationMode, FILE_ATTRIBUTE_NORMAL, NULL); if(!HandleValid(iDevHandle)) { const DWORD winErr = GetLastError(); __LOG1(_L("#-- CWinImgFileDevice::Connect() Error opening/creating file! WinErr:%d"), winErr); return MapWinError(winErr); } //-- adjust file size if we need if(bNeedToAdjustFileSize) { const TInt64 newFileSize = (TInt64)reqSizeSec * sectorSizeToUse; ASSERT(newFileSize); LONG newFSzHi = I64HIGH(newFileSize); DWORD dwRes = SetFilePointer(iDevHandle, I64LOW(newFileSize), &newFSzHi, FILE_BEGIN); if(dwRes == INVALID_SET_FILE_POINTER || !SetEndOfFile(iDevHandle)) { const DWORD winErr = GetLastError(); Disconnect(); __LOG1(_L("#-- CWinImgFileDevice::Connect() unable to set file size! WinErr:%d"), winErr); return MapWinError(winErr); } } } else //if(ImgFileAlreadyExists) {//-- if the image file does not exist or its size differs from required. try to create it if(reqSizeSec == 0) { __LOG(_L("#-- CWinImgFileDevice::Connect() The image file doesn't exist ant its size isn't specified!")); return KErrArgument; } fileSzInSectorsToUse = reqSizeSec; //-- create a new image file iDevHandle = CreateFileA(aParams.ipDevName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES)NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); if(!HandleValid(iDevHandle)) { const DWORD winErr = GetLastError(); __LOG1(_L("#-- CWinImgFileDevice::Connect() can not create file! WinErr:%d"), winErr); return MapWinError(winErr); } //-- set its size const TInt64 newFileSize = (TInt64)reqSizeSec * sectorSizeToUse; ASSERT(newFileSize); LONG newFSzHi = I64HIGH(newFileSize); DWORD dwRes = SetFilePointer(iDevHandle, I64LOW(newFileSize), &newFSzHi, FILE_BEGIN); if(dwRes == INVALID_SET_FILE_POINTER || !SetEndOfFile(iDevHandle)) { const DWORD winErr = GetLastError(); Disconnect(); __LOG1(_L("#-- CWinImgFileDevice::Connect() unable to set file size! WinErr:%d"), winErr); return MapWinError(winErr); } //-- if parametrs require a read-only file, reopen it in RO mode, it doesn't make a lot of sense though... if(aParams.iReadOnly) { CloseHandle(iDevHandle); iDevHandle = NULL; iDevHandle = CreateFileA(aParams.ipDevName, GENERIC_READ , FILE_SHARE_READ, (LPSECURITY_ATTRIBUTES)NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if(!HandleValid(iDevHandle)) { const DWORD winErr = GetLastError(); __LOG1(_L("#-- CWinImgFileDevice::Connect() Can't reopen a file in RO mode! WinErr:%d"), winErr); return MapWinError(winErr); } }//if(aParams.iReadOnly) }//else if(ImgFileAlreadyExists) //-- here we must have the image file created/opened and with correct size ASSERT(HandleValid()); ASSERT(sectorSizeToUse); if(fileSzInSectorsToUse < KMinMediaSizeInSectors) { __LOG1(_L("#-- CWinImgFileDevice::Connect() Image file is too small! sectors:%d"), fileSzInSectorsToUse); Disconnect(); return KErrGeneral; } iDrvGeometry.iBytesPerSector = sectorSizeToUse; iDrvGeometry.iSizeInSectors = fileSzInSectorsToUse; //-- map the image file into memory. ASSERT(!HandleValid(ihFileMapping)); ASSERT(!ipImageFile); /* don't map image file, because it can be > 4G. ihFileMapping = CreateFileMapping(Handle(), NULL, aParams.iReadOnly ? PAGE_READONLY : PAGE_READWRITE, 0, 0, NULL); if(HandleValid(ihFileMapping)) { ipImageFile = (TUint8*)MapViewOfFile(ihFileMapping, aParams.iReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, 0,0,0); } if(!ipImageFile) { __PRINT1(_L("#-- CWinImgFileDevice::Connect() Error mapping file! WinErr:%d"), GetLastError()); Disconnect(); return KErrGeneral; } */ return KErrNone; }
#include <centralrepository.h> #include <featmgr.h> #include <AknSmallIndicator.h> #include <avkon.hrh> #include "btengserver.h" #include "btengsrvpluginmgr.h" #include "btengsrvbbconnectionmgr.h" #include "btengsrvstate.h" #include "debug.h" /** ID of active object helper */ const TInt KBTEngSettingsActive = 30; /** Constant for converting minutes to microseconds */ //const TInt64 KMinutesInMicroSecs = 60000000; const TInt64 KMinutesInMicroSecs = MAKE_TINT64( 0, 60000000 ); /** Timeout for disabling Simple Pairing debug mode. The value is 30 minutes. */ //const TInt KBTEngSspDebugModeTimeout = 1800000000; const TInt64 KBTEngSspDebugModeTimeout = MAKE_TINT64( 0, 1800000000 ); /** Timeout for turning BT off automatically. The value is 10.5 seconds. */ const TInt KBTEngBtAutoOffTimeout = 10500000; // ======== MEMBER FUNCTIONS ======== // --------------------------------------------------------------------------- // C++ default constructor // --------------------------------------------------------------------------- // CBTEngSrvSettingsMgr::CBTEngSrvSettingsMgr( CBTEngServer* aServer ) : iServer( aServer ) {