// From MTest: void CTestCase::ExecuteL (TTestResult& aResult) { TInt error = ExecuteImplL(); aResult.iResult = error; // add the possible failure or error to the result if (error == KErrCppUnitAssertionFailed) { CAssertFailure* assertFailure = AssertFailureFromTlsL (); CleanupStack::PushL(assertFailure); TBuf16 <0x80> convertBuf; TBuf16 <256> temporaryBuf; convertBuf.Copy(assertFailure->What()); temporaryBuf.Append(convertBuf); temporaryBuf.AppendFormat(_L(" at Line %i of "), assertFailure->LineNumber()); convertBuf.Copy(assertFailure->FileName()); if (convertBuf.Length() + temporaryBuf.Length() >= 0x80) { TBuf <0x80> printBuf; printBuf = convertBuf.Right(0x80 - temporaryBuf.Length() - 1 -3 ); convertBuf = _L("..."); convertBuf.Append(printBuf); } temporaryBuf.Append(convertBuf); aResult.iResultDes = temporaryBuf; CleanupStack::PopAndDestroy(assertFailure); } }
//******************************************************************************* // Method : CTestAppConsole::QueryIPAddress() // Purpose : // Parameters : // Return Value: //******************************************************************************* void CTestAppConsole::QueryIPAddress() { TBuf16<80> line; // Query IP address and parse it TUint32 address; RArray<TUint32> values; TInt inputErr( 0 ); iConsole->Printf( _L("\nINPUT IP (use dot as a separator): ") ); iConsole->Printf( _L("\nPress enter if IP not needed in tests\n\n") ); GetStringFromConsole( line ); if ( line.Length() != 0 ) { TInt dotIndex( 0 ); TBool dotExist = ETrue; while ( dotExist ) { dotIndex = line.Locate( '.' ); // True if last attribute value if( KErrNotFound == dotIndex ) { dotExist = EFalse; dotIndex = line.Length(); } TUint8 number; TLex16 lex = line.Mid( 0, dotIndex ); inputErr = lex.Val( number, EDecimal ); if ( !inputErr ) { values.AppendL( number ); } if( dotExist ) { line.Delete( 0, dotIndex + 1 ); } } if ( !inputErr && values.Count() == 4 ) { address = INET_ADDR( values[0], values[1], values[2], values[3] ); iNetsettings.iRemoteAddress.SetAddress( address ); } } }
HBufC* CPluginUtils::ConvertUtfToUnicodeL( const TDesC8& aUtf7 ) { RBuf output; CleanupClosePushL( output ); TBuf16<20> outputBuffer; TPtrC8 remainderOfUtf7( aUtf7 ); for(;;) { const TInt returnValue = CnvUtfConverter::ConvertToUnicodeFromUtf8(outputBuffer, remainderOfUtf7); if (returnValue==CnvUtfConverter::EErrorIllFormedInput) return NULL; else if (returnValue<0) return NULL; output.ReAllocL( output.Length() + outputBuffer.Length() ); output.Append( outputBuffer ); if (returnValue == 0) break; remainderOfUtf7.Set(remainderOfUtf7.Right(returnValue)); } HBufC* ret = output.AllocL(); CleanupStack::PopAndDestroy( &output ); return ret; }
void CAknEcsNote::SetEmergencyNumber( const TDesC& aMatchedNumber ) { TRect screen(iAvkonAppUi->ApplicationRect()); TAknLayoutRect mainPane; mainPane.LayoutRect(screen, AKN_LAYOUT_WINDOW_main_pane(screen, 0, 1, 1)); TAknLayoutRect popupNoteWindow; AknLayoutUtils::TAknCbaLocation cbaLocation( AknLayoutUtils::CbaLocation() ); TInt variety( 0 ); if ( cbaLocation == AknLayoutUtils::EAknCbaLocationRight ) { variety = 5; } else if ( cbaLocation == AknLayoutUtils::EAknCbaLocationLeft ) { variety = 8; } else { variety = 2; } popupNoteWindow.LayoutRect(mainPane.Rect(), AknLayoutScalable_Avkon::popup_note_window( variety )); TAknLayoutText textRect; textRect.LayoutText(popupNoteWindow.Rect(), AKN_LAYOUT_TEXT_Note_pop_up_window_texts_Line_1(4)); // Size of a temporary buffer that contains new lines, spaces and // emergency number for a note. TBuf16<KAknEcsMaxMatchingLength+80> number; number.Append('\n'); number.Append('\n'); TInt spaceCharWidthInPixels = textRect.Font()->CharWidthInPixels(' '); if (spaceCharWidthInPixels < 1) { // Avoid divide by zero situation even the space char would have zero length. spaceCharWidthInPixels = 1; } TInt length = (textRect.TextRect().Width() - textRect.Font()->TextWidthInPixels(aMatchedNumber)) / spaceCharWidthInPixels; const TInt matchedNumberLength = aMatchedNumber.Length(); const TInt numberLength = number.Length(); const TInt numberMaxLength = number.MaxLength(); if ( numberLength + length + matchedNumberLength > numberMaxLength) { // To make sure that buffer overflow does not happen. length = numberMaxLength - numberLength - matchedNumberLength; } for (int i = 0; i < length ; i++) { number.Append(' '); } number.Append(aMatchedNumber); TRAP_IGNORE(SetTextL(number)); }
/** * Returns bluetooth friendly name * Output: bluetooth friendly name */ std::wstring *S60BluetoothPlatformControl::getBluetoothName() { TBuf16<KMaxBluetoothNameLen> bluetoothName; JELOG2(EJavaBluetooth); TInt error = RProperty::Get(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothGetDeviceName, bluetoothName); if (error != KErrNone || (0 == bluetoothName.Length())) { ELOG(EJavaBluetooth, "Bluetooth friendly name was not set"); return NULL; } std::wstring *deviceName = new std::wstring((wchar_t*) bluetoothName.Ptr()); deviceName->resize(bluetoothName.Length()); return deviceName; }
GLDEF_C TInt E32Main() { TBuf16<512> cmd; User::CommandLine(cmd); if(cmd.Length() && TChar(cmd[0]).IsDigit()) { TInt function = -1; TInt arg1 = -1; TInt arg2 = -1; TLex lex(cmd); lex.Val(function); lex.SkipSpace(); lex.Val(arg1); lex.SkipSpace(); lex.Val(arg2); return DoTestProcess(function,arg1,arg2); } test.Title(); if((!PlatSec::ConfigSetting(PlatSec::EPlatSecProcessIsolation))||(!PlatSec::ConfigSetting(PlatSec::EPlatSecEnforcement))) { test.Start(_L("TESTS NOT RUN - PlatSecProcessIsolation is not enforced")); test.End(); return 0; } test(SyncMutex.CreateGlobal(KSyncMutext)==KErrNone); test.Start(_L("Test SetJustInTime")); TestSetJustInTime(); test.Next(_L("Test Rename")); TestRename(); test.Next(_L("Test Kill, Panic and Teminate")); TestKill(); test.Next(_L("Test Resume")); TestResume(); test.Next(_L("Test SetPriority")); TestSetPriority(); SyncMutex.Close(); test.End(); return(0); }
void CDebugLogPrint::WriteToLog8L(const TDesC8 &aDes, const TDesC8 &aDes2) { TBuf16<256> buf; TInt pos=aDes.LocateReverse(' '); if (pos<0) pos=0; buf.Copy(aDes.Mid(pos)); buf.Append(' '); TInt bufLen=buf.Length(); TPtr16 ptr(&buf[bufLen],buf.MaxLength()-bufLen); ptr.Copy(aDes2); buf.SetLength(bufLen+aDes2.Length()); _LIT(KDebugFormatString, "%S"); RDebug::Print(KDebugFormatString, &buf); }
/** * Returns bluetooth address * Output: bluetooth address */ std::wstring *S60BluetoothPlatformControl::getBluetoothAddress() { TPckgBuf<TBTDevAddr> localDeviceBluetoothAddress; TBuf16<20> bluetoothAddress; JELOG2(EJavaBluetooth); TInt error = RProperty::Get(KPropertyUidBluetoothCategory, KPropertyKeyBluetoothGetLocalDeviceAddress, localDeviceBluetoothAddress); if (error != KErrNone) { return NULL; } localDeviceBluetoothAddress().GetReadable(bluetoothAddress); std::wstring *deviceAddress = new std::wstring((wchar_t*) bluetoothAddress.Ptr()); deviceAddress->resize(bluetoothAddress.Length()); return deviceAddress; }
//******************************************************************************* // Method : CTestAppConsole::QueryNetworkSettings() // Purpose : // Parameters : // Return Value: //******************************************************************************* void CTestAppConsole::QueryNetworkSettings() { TBuf16<80> line; iConsole->Printf( _L("\nQUERYING NETWORK SETTINGS") ); iConsole->Printf( _L("\nPress enter to use existing value") ); TUint iap( KTestIapId ); TInt inputErr( 0 ); do { iConsole->Printf( _L("\nINPUT IAPID: ") ); GetStringFromConsole( line ); if ( line.Length() != 0 ) { TLex lex( line ); inputErr = lex.Val( iap ); } } while ( inputErr ); iNetsettings.iIapId = iap; }
int main() { __UHEAP_MARK; int retval =ESuccess; wchar_t* mywcharstring = L"Hello Widechar String"; int wchar_length= wcslen(mywcharstring); TBuf16 <42> myBuffer; retval = WcharToTbuf16 (mywcharstring, myBuffer); int buf_len = myBuffer.Length(); if (retval ==ESuccess && wchar_length == buf_len && buf_len == 21 ) { printf("wchartotbuf16 boundary2 Passed\n"); } else { assert_failed = true; printf("wchartotbuf16 boundary2 Failed\n"); } __UHEAP_MARKEND; testResultXml("test_wchartotbuf16_boundary2"); }
GLDEF_C TInt E32Main() { TBuf16<512> cmd; User::CommandLine(cmd); if(cmd.Length() && TChar(cmd[0]).IsDigit()) { TInt function = -1; TInt arg1 = -1; TInt arg2 = -1; TLex lex(cmd); lex.Val(function); lex.SkipSpace(); lex.Val(arg1); lex.SkipSpace(); lex.Val(arg2); return DoTestProcess(function,arg1,arg2); } MemModelAttributes=UserSvr::HalFunction(EHalGroupKernel, EKernelHalMemModelInfo, NULL, NULL); TUint mm=MemModelAttributes&EMemModelTypeMask; PhysicalCommitSupported = mm!=EMemModelTypeDirect && mm!=EMemModelTypeEmul; // Turn off lazy dll unloading RLoader l; test(l.Connect()==KErrNone); test(l.CancelLazyDllUnload()==KErrNone); l.Close(); test.Title(); #if defined(__FIXED__) || defined(__SECOND_FIXED__) || defined(__MOVING_FIXED__) if(mm!=EMemModelTypeMoving) { test.Printf(_L("TESTS NOT RUN - Only applicable to moving memory model\r\n")); return 0; } #endif test.Start(_L("Loading test driver...")); TInt r; r=User::LoadLogicalDevice(KSharedIoTestLddName); test(r==KErrNone || r==KErrAlreadyExists); r=User::LoadLogicalDevice(KSharedIoTestLddName); test(r==KErrAlreadyExists); r=ldd.Open(); test(r==KErrNone); TAny* buffer; TUint32 size; TUint32 key; TInt testBufferSize=0; for(; TestBufferSizes[testBufferSize]!=0; ++testBufferSize) { test.Printf(_L("Test buffer size = %08x\n"),TestBufferSizes[testBufferSize]); test.Next(_L("Create buffer")); r=ldd.CreateBuffer(TestBufferSizes[testBufferSize]); if(r!=KErrNone) test.Printf(_L("Creating buffer failed client r=%d"), r); test(r==KErrNone); test.Next(_L("Map In Buffer")); r=ldd.MapInBuffer(&buffer,&size); test.Next(_L("CheckBuffer")); test(CheckBuffer(buffer,size)); test(r==KErrNone); test.Next(_L("Fill and check shared buffer")); key=Math::Random(); fillBuffer(buffer,size,key); test(ldd.CheckBuffer(key)==KErrNone); key=Math::Random(); test(ldd.FillBuffer(key)==KErrNone); test(checkBuffer(buffer,size,key)==KErrNone); test.Next(_L("Map Out Buffer")); r=ldd.MapOutBuffer(); test(r==KErrNone); test.Next(_L("Destroy Buffer")); r=ldd.DestroyBuffer(); test(r==KErrNone); test.Next(_L("Create a buffer under OOM conditions")); CreateWithOOMCheck(TestBufferSizes[testBufferSize], EFalse); if(PhysicalCommitSupported) { test.Next(_L("Create a buffer with a physical address under OOM conditions")); CreateWithOOMCheck(TestBufferSizes[testBufferSize], ETrue); test.Next(_L("Create a buffer with a physical address")); r=ldd.CreateBufferPhysAddr(0x1000); test(r==KErrNone); test.Next(_L("Map In physical address Buffer")); r=ldd.MapInBuffer(&buffer,&size); test(r==KErrNone); test.Next(_L("Fill and check physical address shared buffer")); key=Math::Random(); fillBuffer(buffer,size,key); test(ldd.CheckBuffer(key)==KErrNone); key=Math::Random(); test(ldd.FillBuffer(key)==KErrNone); test(checkBuffer(buffer,size,key)==KErrNone); test.Next(_L("Map Out physical address Buffer")); r=ldd.MapOutBuffer(); test(r==KErrNone); test.Next(_L("Destroy a buffer with a physical address")); r=ldd.DestroyBufferPhysAddr(); test(r==KErrNone); } test.Next(_L("Check using the same buffer by 2 different user processes")); TAny* gbuffer; TUint32 gsize; r=ldd.MapInGlobalBuffer(RProcess().Id(),gbuffer,gsize); test(r==KErrNone); fillBuffer(gbuffer,gsize,23454); r=ldd.MapOutGlobalBuffer(); test(r==KErrNone); r=ldd.CreateBuffer(TestBufferSizes[testBufferSize]); test(r==KErrNone); r=ldd.MapInBuffer(&buffer,&size); test(r==KErrNone); test(CheckBuffer(buffer,size)); key=Math::Random(); fillBuffer(buffer,size,key); test(ldd.CheckBuffer(key)==KErrNone); RTestProcess rogueP; TRequestStatus rendezvous; TRequestStatus logon; if(MemModelAttributes&EMemModelAttrProcessProt) { test.Next(_L("Checking buffers are protected at context switching")); rogueP.Create(ETestProcess2,(TInt)buffer,(TInt)size); rogueP.Logon(logon); rogueP.Rendezvous(rendezvous); rogueP.Resume(); User::WaitForRequest(rendezvous); test(rendezvous==KProcessRendezvous); User::WaitForRequest(logon); test(rogueP.ExitType()==EExitPanic); test(logon==3); test(ldd.CheckBuffer(key)==KErrNone); } r=ldd.MapOutBuffer(); test(r==KErrNone); r=ldd.DestroyBuffer(); test(r==KErrNone); RTestProcess process; if((MemModelAttributes&EMemModelAttrKernProt) && (MemModelAttributes&EMemModelTypeMask)!=EMemModelTypeDirect) { test.Next(_L("Checking writing to unmapped buffer")); process.Create(ETestProcess1); process.Logon(logon); process.Rendezvous(rendezvous); test(ldd.MapInGlobalBuffer(process.Id(),gbuffer,gsize)==KErrNone); test(process.SetParameter(1,(TInt)gbuffer)==KErrNone); test(process.SetParameter(2,(TInt)gsize)==KErrNone); process.Resume(); User::WaitForRequest(rendezvous); test(rendezvous==KProcessRendezvous); User::WaitForRequest(logon); test(process.ExitType()==EExitPanic); test(logon==3); process.Close(); } r=ldd.CreateBuffer(TestBufferSizes[testBufferSize]); if(r!=KErrNone) return r; r=ldd.MapInBuffer(&buffer,&size); if(r!=KErrNone) return r; if(!CheckBuffer(buffer,size)) return KErrGeneral; *(TInt*)buffer=KMagic1; TPckg<TInt> buf(*(TInt*)buffer); RTestProcess proc; test.Next(_L("Checking address lookup is implemented")); proc.Create(ETestProcess3,(TInt)&buf,RThread().Id()); proc.Logon(logon); proc.Resume(); User::WaitForRequest(logon); test(proc.ExitType()==EExitKill); test(logon==0); test(*(TInt*)buffer==KMagic2); ldd.DestroyBuffer(); // Check process death whilst buffer is mapped in // Test case for defect DEF051851 - Shared IO Buffer fault when process dies test.Next(_L("Checking process death whilst buffer is mapped in")); process.Create(ETestProcess1); process.Logon(logon); test.Start(_L("Map buffer into another process")); test(ldd.MapInGlobalBuffer(process.Id(),gbuffer,gsize)==KErrNone); test.Next(_L("Kill other process")); process.Kill(99); User::WaitForRequest(logon); test(process.ExitType()==EExitKill); test(logon==99); process.Close(); test.Next(_L("Map out buffer")); r=ldd.MapOutGlobalBuffer(); test.Printf(_L("result = %d\n"),r); test(r==KErrNone); test.Next(_L("Map buffer into this process")); test(ldd.MapInGlobalBuffer(RProcess().Id(),gbuffer,gsize)==KErrNone); test.Next(_L("Map out buffer from this process")); r=ldd.MapOutGlobalBuffer(); test.Printf(_L("result = %d\n"),r); test(r==KErrNone); process.Create(ETestProcess1); process.Logon(logon); test.Next(_L("Map buffer into another process")); test(ldd.MapInGlobalBuffer(process.Id(),gbuffer,gsize)==KErrNone); test.Next(_L("Kill other process")); process.Kill(99); User::WaitForRequest(logon); test(process.ExitType()==EExitKill); test(logon==99); process.Close(); test.Next(_L("Map out buffer")); r=ldd.MapOutGlobalBuffer(); test.Printf(_L("result = %d\n"),r); test(r==KErrNone); test.End(); } // loop for next buffer size test.Next(_L("Create and map in buffer")); r=ldd.CreateBuffer(KTestBufferSize); test(r==KErrNone); r=ldd.MapInBuffer(&buffer,&size); test(r==KErrNone); // Test for DEF053512 - Can't delete SharedIo buffers in DLogicalDevice destructor test.Next(_L("Map in global buffer")); TAny* gbuffer; TUint32 gsize; test(ldd.MapInGlobalBuffer(RProcess().Id(),gbuffer,gsize)==KErrNone); test.Next(_L("Closing channel (with a buffer still mapped in)")); ldd.Close(); // Test for DEF053512 - Can't delete SharedIo buffers in DLogicalDevice destructor test.Next(_L("Unload driver (whilst global buffer still mapped in)")); r=User::FreeLogicalDevice(KSharedIoTestLddName); test(r==KErrNone); test.End(); return(0); }
EXPORT_C void CIpuTestHarness::GetAnEntry(const TDesC& ourPrompt, TDes& currentstring) // // Get an input string from the user, displaying a supplied prompt and default string value { // If we're scripting, try reading from script first TInt readScriptErr = KErrNotFound; if (iScriptRunning) { readScriptErr = ReadLineFromScript(currentstring); } if (!readScriptErr) return; // Either not scripting, or hit end of script - continue with user input TBuf16<KMaxUserEntrySize> ourLine; TBuf<KMaxUserEntrySize> tempstring; //tempstring is a unicode descriptor //create a temporary buffer where the //unicode strings are stored in order to //be displayed ourLine.Zero (); tempstring.Copy(currentstring); //Copy current string to Unicode buffer TKeyCode key = EKeyNull; //current string buffer is 8 bits wide. //Unicode string bufffer (tempstring) is 16 bits wide. for (;;) { if (ourLine.Length () == 0) { iTest.Console()->SetPos (0, iTest.Console()->WhereY ()); iTest.Console()->Printf (_L ("%S"), &ourPrompt); if (tempstring.Length () != 0) //get tempstring's number of items iTest.Console()->Printf (_L (" = %S"), &tempstring); //if not zero print them to iTest.Console() iTest.Console()->Printf (_L (" : ")); iTest.Console()->ClearToEndOfLine (); } key = iTest.Getch(); if (key == EKeyBackspace) { if (ourLine.Length() !=0) { ourLine.SetLength(ourLine.Length()-1); iTest.Console()->Printf (_L ("%c"), key); iTest.Console()->SetPos(iTest.Console()->WhereX(),iTest.Console()->WhereY()); iTest.Console()->ClearToEndOfLine(); } // end if (ourLine.Length() !=0) } // end if (key == KeyBackSpace) if (key == EKeyDelete) { ourLine.Zero(); iTest.Console()->SetPos (0, iTest.Console()->WhereY ()); iTest.Console()->ClearToEndOfLine (); tempstring.Copy(ourLine); break; } if (key == EKeyEnter) break; if (key < 32) { continue; } ourLine.Append (key); iTest.Console()->Printf (_L ("%c"), key); iTest.Console()->SetPos(iTest.Console()->WhereX(),iTest.Console()->WhereY()); iTest.Console()->ClearToEndOfLine(); if (ourLine.Length () == ourLine.MaxLength ()) break; } // end of for statement if ((key == EKeyEnter) && (ourLine.Length () == 0)) tempstring.Copy (currentstring); //copy contents of 8 bit "ourLine" descriptor iTest.Console()->SetPos (0, iTest.Console()->WhereY ()); iTest.Console()->ClearToEndOfLine (); iTest.Console()->Printf (_L ("%S"), &ourPrompt); if ((key == EKeyEnter) && (ourLine.Length() !=0)) tempstring.Copy(ourLine); if (tempstring.Length () != 0) //if temstring length is not zero { iTest.Console()->Printf (_L (" = %S\n"), &tempstring); //print the contents to iTest.Console() LogIt(_L ("%S = %S\n"), &ourPrompt, &tempstring); } else //iTest.Console()->Printf (_L (" is empty")); iTest.Console()->Printf (_L ("\n")); currentstring.Copy(tempstring); //copy 16 bit tempstring descriptor back }