/** @SYMTestCaseID SYSLIB-CHARCONV-CT-0536 @SYMTestCaseDesc Splitting and converting from Unicode to EucJpPacked test @SYMTestPriority Medium @SYMTestActions Tests for conversion after splitting, from Unicode to EucJpPacked and back to Unicode @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ void CT_EUCJP_PACKED_2::TestSplittingConvertingFromUnicodeToEucJpPacked(CCnvCharacterSetConverter& aCharacterSetConverter, TInt aMaximumLengthLowerLimit, TInt aMaximumLengthUpperLimit, TInt aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit, TInt aExpectedLengthOfFirstPartOfEucJpPacked, const TDesC8& aExpectedEucJpPacked, const TDesC16& aOriginalUnicode) { INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0536 ")); test(aMaximumLengthLowerLimit<=aMaximumLengthUpperLimit); test(aMaximumLengthUpperLimit<=KBufferLength); TUint8 eucJpPackedBuffer[KBufferLength]; for (TInt i=aMaximumLengthLowerLimit; i<=aMaximumLengthUpperLimit; ++i) { TPtr8 generatedFirstPartOfEucJpPacked(eucJpPackedBuffer, i); test(aCharacterSetConverter.ConvertFromUnicode(generatedFirstPartOfEucJpPacked, aOriginalUnicode)==aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit); test(generatedFirstPartOfEucJpPacked==aExpectedEucJpPacked.Left(aExpectedLengthOfFirstPartOfEucJpPacked)); TBuf8<KBufferLength> generatedSecondPartOfEucJpPacked; test(aCharacterSetConverter.ConvertFromUnicode(generatedSecondPartOfEucJpPacked, aOriginalUnicode.Right(aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit))==0); test(generatedSecondPartOfEucJpPacked==aExpectedEucJpPacked.Mid(aExpectedLengthOfFirstPartOfEucJpPacked)); TInt state=CCnvCharacterSetConverter::KStateDefault; TBuf16<KBufferLength> generatedUnicode; test(aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedFirstPartOfEucJpPacked, state)==0); test(state==CCnvCharacterSetConverter::KStateDefault); TBuf16<KBufferLength> generatedSecondPartOfUnicode; test(aCharacterSetConverter.ConvertToUnicode(generatedSecondPartOfUnicode, generatedSecondPartOfEucJpPacked, state)==0); test(state==CCnvCharacterSetConverter::KStateDefault); generatedUnicode.Append(generatedSecondPartOfUnicode); test(generatedUnicode==aOriginalUnicode); } }
void CT_ISO2022JP1_2::TestSplittingConvertingFromUnicodeToIso2022Jp( CCnvCharacterSetConverter& aCharacterSetConverter, TInt aMaximumLengthLowerLimit, TInt aMaximumLengthUpperLimit, TInt aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit, const TDesC8& aExpectedFirstPartOfIso2022Jp, const TDesC8& aExpectedSecondPartOfIso2022Jp, const TDesC16& aOriginalUnicode) { INFO_PRINTF1(_L(" TestTruncatedConversionFromUnicodeToIso2022Jp ")); test(aMaximumLengthLowerLimit<=aMaximumLengthUpperLimit); test(aMaximumLengthUpperLimit<=KBufferLength); TUint8 iso2022JpBuffer[KBufferLength]; for (TInt i=aMaximumLengthLowerLimit; i<=aMaximumLengthUpperLimit; ++i) { TPtr8 generatedFirstPartOfIso2022Jp(iso2022JpBuffer, i); test(aCharacterSetConverter.ConvertFromUnicode(generatedFirstPartOfIso2022Jp, aOriginalUnicode)==aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit); test(generatedFirstPartOfIso2022Jp==aExpectedFirstPartOfIso2022Jp); TBuf8<KBufferLength> generatedSecondPartOfIso2022Jp; test(aCharacterSetConverter.ConvertFromUnicode(generatedSecondPartOfIso2022Jp, aOriginalUnicode.Right(aExpectedNumberOfUnicodeCharactersNotConvertedAtSplit))==0); test(generatedSecondPartOfIso2022Jp==aExpectedSecondPartOfIso2022Jp); TInt state=CCnvCharacterSetConverter::KStateDefault; TBuf16<KBufferLength> generatedUnicode; test(aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedFirstPartOfIso2022Jp, state)==0); TBuf16<KBufferLength> generatedSecondPartOfUnicode; test(aCharacterSetConverter.ConvertToUnicode(generatedSecondPartOfUnicode, generatedSecondPartOfIso2022Jp, state)==0); generatedUnicode.Append(generatedSecondPartOfUnicode); test(generatedUnicode==aOriginalUnicode); } }
void CLocaLogicImpl::DeletedL(const TTupleName& aName, const TDesC& aSubName) { if (aName==KLocaScriptTuple) { if (aSubName.Length()>0 && aSubName[0]!='_') { TInterpreterAutoLock interpr; // borrowed PyObject* main_module = PyImport_AddModule("__main__"); if (! main_module ) return; // borrowed PyObject* global_dict = PyModule_GetDict(main_module); if (! global_dict ) return; auto_ptr<HBufC8> subname8(HBufC8::NewL(aSubName.Length()+10)); TPtr8 p=subname8->Des(); TInt err=KErrNone; TInt unconverted=0, unconverted_pos=0; err=iCC->ConvertFromUnicode(p, aSubName, unconverted, unconverted_pos); if (err!=KErrNone || unconverted!=0) return; subname8->Des().Append('\0'); PyDict_DelItemString(global_dict, (char*)subname8->Ptr()); TInt pos; DeleteFromArrayL(iFunctions, *subname8); DeleteFromArrayL(iErrorFunctions, *subname8); } } }
/** @SYMTestCaseID SYSLIB-CHARCONV-CT-0535 @SYMTestCaseDesc Tests for truncated conversion from Unicode to EucJpPacked @SYMTestPriority Medium @SYMTestActions Tests for truncated conversion from Unicode to EucJpPacked and back to Unicode @SYMTestExpectedResults Test must not fail @SYMREQ REQ0000 */ void CT_EUCJP_PACKED_2::TestTruncatedConversionFromUnicodeToEucJpPacked(CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aOriginalUnicode) { INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0535 ")); for (TInt i=aOriginalUnicode.Length(); i>=0; --i) { TBuf8<KBufferLength> generatedEucJpPacked; const TInt returnValue=aCharacterSetConverter.ConvertFromUnicode(generatedEucJpPacked, aOriginalUnicode.Left(i)); test(returnValue>=0); TBuf8<KBufferLength> generatedsecondPartOfEucJpPacked; test(aCharacterSetConverter.ConvertFromUnicode(generatedsecondPartOfEucJpPacked, aOriginalUnicode.Mid(i-returnValue))==0); generatedEucJpPacked.Append(generatedsecondPartOfEucJpPacked); TInt state=CCnvCharacterSetConverter::KStateDefault; TBuf16<KBufferLength> generatedUnicode; test(aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedEucJpPacked, state)==0); test(generatedUnicode==aOriginalUnicode); } }
void CT_ISO2022JP1_2::TestTruncatedConversionFromUnicodeToIso2022Jp( CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aOriginalUnicode) { INFO_PRINTF1(_L(" TestTruncatedConversionFromUnicodeToIso2022Jp ")); for (TInt i=aOriginalUnicode.Length(); i>=0; --i) { TBuf8<KBufferLength> generatedIso2022Jp; const TInt returnValue=aCharacterSetConverter.ConvertFromUnicode(generatedIso2022Jp, aOriginalUnicode.Left(i)); test(returnValue>=0); TBuf8<KBufferLength> generatedsecondPartOfIso2022Jp; test(aCharacterSetConverter.ConvertFromUnicode(generatedsecondPartOfIso2022Jp, aOriginalUnicode.Mid(i-returnValue))==0); generatedIso2022Jp.Append(generatedsecondPartOfIso2022Jp); TInt state=CCnvCharacterSetConverter::KStateDefault; TBuf16<KBufferLength> generatedUnicode; test(aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedIso2022Jp, state)==0); test(generatedUnicode==aOriginalUnicode); } }
HBufC8* CRecogStep::ConvertDes16toHBufC8LC(TDesC& source) { HBufC8 *buf = HBufC8::NewL(source.Length()); CleanupStack::PushL(buf); TPtr8 ptr=buf->Des(); CCnvCharacterSetConverter *converter = CCnvCharacterSetConverter::NewLC(); converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierAscii, iTheFs); converter->ConvertFromUnicode(ptr, source); CleanupStack::PopAndDestroy(converter); return buf; }
void CT_ISO2022JP1_2::TestSplittingConvertingToUnicodeFromIso2022Jp( CCnvCharacterSetConverter& aCharacterSetConverter, TInt aMaximumLengthLowerLimit, TInt aMaximumLengthUpperLimit, TInt aExpectedNumberOfIso2022JpBytesNotConvertedAtSplit, TInt aExpectedLengthOfFirstPartOfUnicode, const TDesC16& aExpectedUnicode, const TDesC8& aOriginalIso2022Jp) { INFO_PRINTF1(_L(" TestSplittingConvertingToUnicodeFromIso2022Jp ")); test(aMaximumLengthLowerLimit<=aMaximumLengthUpperLimit); test(aMaximumLengthUpperLimit<=KBufferLength); TUint16 unicodeBuffer[KBufferLength]; for (TInt i=aMaximumLengthLowerLimit; i<=aMaximumLengthUpperLimit; ++i) { TPtr16 generatedFirstPartOfUnicode(unicodeBuffer, i); TInt state=CCnvCharacterSetConverter::KStateDefault; const TInt returnValue=aCharacterSetConverter.ConvertToUnicode(generatedFirstPartOfUnicode, aOriginalIso2022Jp, state); test(generatedFirstPartOfUnicode==aExpectedUnicode.Left(aExpectedLengthOfFirstPartOfUnicode)); test(returnValue==aExpectedNumberOfIso2022JpBytesNotConvertedAtSplit); TBuf16<KBufferLength> generatedSecondPartOfUnicode; test(aCharacterSetConverter.ConvertToUnicode(generatedSecondPartOfUnicode, aOriginalIso2022Jp.Right(aExpectedNumberOfIso2022JpBytesNotConvertedAtSplit), state)==0); test(generatedSecondPartOfUnicode==aExpectedUnicode.Mid(aExpectedLengthOfFirstPartOfUnicode)); TBuf8<KBufferLength> generatedIso2022Jp; test(aCharacterSetConverter.ConvertFromUnicode(generatedIso2022Jp, generatedFirstPartOfUnicode)==0); TBuf8<KBufferLength> generatedSecondPartOfIso2022Jp; test(aCharacterSetConverter.ConvertFromUnicode(generatedSecondPartOfIso2022Jp, generatedSecondPartOfUnicode)==0); generatedIso2022Jp.Append(generatedSecondPartOfIso2022Jp); TBuf16<KBufferLength> regeneratedUnicode; state=CCnvCharacterSetConverter::KStateDefault; test(aCharacterSetConverter.ConvertToUnicode(regeneratedUnicode, generatedIso2022Jp, state)==0); // test(regeneratedUnicode==aExpectedUnicode); state=CCnvCharacterSetConverter::KStateDefault; test(aCharacterSetConverter.ConvertToUnicode(regeneratedUnicode, aOriginalIso2022Jp, state)==0); test(regeneratedUnicode==aExpectedUnicode); } }
void CT_ISO2022JP1_2::TestConversionFromUnicodeToIso( CCnvCharacterSetConverter& aCharacterSetConverter, const TDesC16& aOriginalUnicode) { INFO_PRINTF1(_L(" TestConversionFromUnicodeToIso ")); TBuf8<KNotEnoughBufferLength> generatedIso2022Jp; generatedIso2022Jp.FillZ(KNotEnoughBufferLength); const TInt returnValue=aCharacterSetConverter.ConvertFromUnicode(generatedIso2022Jp, aOriginalUnicode); test(returnValue>=0); TInt state=CCnvCharacterSetConverter::KStateDefault; TBuf16<KBufferLength> generatedUnicode; TInt testresult; testresult=aCharacterSetConverter.ConvertToUnicode(generatedUnicode, generatedIso2022Jp, state); test(testresult==0); // test(generatedUnicode==aOriginalUnicode); }
void CLocaLogicImpl::ConvertFromPythonString(auto_ptr<HBufC8>& aBuf, PyObject* aString) { if (PyString_Check(aString)) { TInt len=PyString_Size(aString); if (! aBuf.get() || aBuf->Des().MaxLength() < len) { aBuf.reset(HBufC8::NewL(len*2)); } aBuf->Des()=TPtrC8((TUint8*)PyString_AsString(aString), len); } else if (PyUnicode_Check(aString)) { TInt len=PyUnicode_GetSize(aString); if (! aBuf.get() || aBuf->Des().MaxLength() < len) { aBuf.reset(HBufC8::NewL(len*2)); } TPtr8 p=aBuf->Des(); iCC->ConvertFromUnicode(p, TPtrC((TUint16*)PyUnicode_AsUnicode(aString), len)); } PyErr_Clear(); }
// ----------------------------------------------------------------------------- // CSTSPinConverter::ConvertToUTF8L // // ----------------------------------------------------------------------------- void CSTSPinConverter::ConvertToUTF8L(const TDesC& aPinValue, TPtr8& aConvertedPIN, TBool aUpperCase) { // RFs for CCnvCharacterSetConverter RFs fsSession; User::LeaveIfError(fsSession.Connect()); CleanupClosePushL(fsSession); CCnvCharacterSetConverter* converter = CCnvCharacterSetConverter::NewLC(); // transform pin to UTF8 if (converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierUtf8, fsSession) != CCnvCharacterSetConverter::EAvailable) { User::Leave(KErrNotSupported); } TInt error = converter->ConvertFromUnicode(aConvertedPIN, aPinValue); // check to see that the descriptor isn’t corrupt - leave if it is if (error == CCnvCharacterSetConverter::EErrorIllFormedInput) { User::Leave(KErrCorrupt); } if (error < 0) { User::Leave(KErrGeneral); } //convert to uppercase if (aUpperCase) { aConvertedPIN.UpperCase(); } CleanupStack::PopAndDestroy(converter); CleanupStack::PopAndDestroy(&fsSession); }
// // Calculate a hash value for each server entry // TBool CEmailNotificationParser::CalcHashValueL(CCnvCharacterSetConverter& aCharConv, const TDesC8& aUserName, const TDesC& aServerName, const TDesC8& aPortNum) { TInt total = 0; TInt loop = 0; TInt unConvertChar; TInt posOfUnconv; delete iServerName; iServerName = NULL; iServerName = HBufC8::NewL(aServerName.Length()); TPtr8 svr = iServerName->Des(); aCharConv.ConvertFromUnicode( svr, aServerName, unConvertChar,posOfUnconv); // Fix for DEF044588: the Smart Messaging Specification (Revision 3.0.0) states (page 3-17) that // the value of the first character of S is multiplied by one, second character by two etc. for(loop = 0; loop < aUserName.Length(); loop++) { total += ( (loop+1) * (TUint)aUserName[loop]); } TInt pos = aUserName.Length(); for(loop = 0; loop < svr.Length(); loop++) { total += ( (pos + (loop+1) )* (TUint)svr[loop]); } pos += aServerName.Length(); for(loop = 0; loop < aPortNum.Length(); loop++) { total += ( (pos + (loop+1) )* (TUint)aPortNum[loop]); } TReal hashVal; User::LeaveIfError(Math::Mod(hashVal, total, KServerIdModVal)); return ((TInt)hashVal == iServerId); }
// ============================================================================ // CWidgetBackupRegistryXml::FromUnicodeL // Utility to bundle transcoding to unicode steps. // // @since 5.0 // @param aEncoding input buffer encoding // @param aUnicodeSizeMultiplier how many bytes of input make one unicode char // @param aInBuf input data in encoding // @param aOutBuf malloc'ed output buf, caller takes ownership // @param aFileSession CCnvCharacterSetConverter requires it // ============================================================================ // void CWidgetBackupRegistryXml::FromUnicodeL( TInt aEncoding, TInt aUnicodeSizeMultiplier, TPtrC16 aInBuf, HBufC8** aOutBuf, RFs& aFileSession ) { *aOutBuf = NULL; // outbuf sizing and alloction HBufC8* outBuf = HBufC8::NewLC(aUnicodeSizeMultiplier * (aInBuf.Length() + 1)); TPtr8 outPtr = outBuf->Des(); // convert from unicode CCnvCharacterSetConverter* charConv = CCnvCharacterSetConverter::NewLC(); charConv->PrepareToConvertToOrFromL( aEncoding, aFileSession ); User::LeaveIfError( charConv->ConvertFromUnicode( outPtr, aInBuf)); outPtr.ZeroTerminate(); CleanupStack::PopAndDestroy( charConv ); CleanupStack::Pop( outBuf ); *aOutBuf = outBuf; }
void CLocaLogicImpl::NewScriptL(const TDesC& aSubName, const MBBData* aData) { TInterpreterAutoLock interp; const CBBString* code=bb_cast<CBBString>(aData); if (!code) { Reporting().UserErrorLog(_L("Could not read Python script named "), aSubName, _L(" (wrong bb type)")); return; } auto_ptr<HBufC8> code8(HBufC8::NewL(code->Value().Length()+10)); auto_ptr<HBufC8> subname8(HBufC8::NewL(aSubName.Length()+10)); { TInt err=KErrNone; TInt unconverted=0, unconverted_pos=0; { TPtr8 p=code8->Des(); err=iCC->ConvertFromUnicode(p, code->Value(), unconverted, unconverted_pos); } if (err==KErrNone && unconverted==0) { TPtr8 p=subname8->Des(); err=iCC->ConvertFromUnicode(p, aSubName, unconverted, unconverted_pos); } if (err!=KErrNone || unconverted>0) { TBuf<30> rest; if (err!=KErrNone) { rest=_L("to Latin1, err: "); rest.AppendNum(err); } else { rest=_L("to Latin1, at position "); rest.AppendNum(unconverted_pos); } Reporting().UserErrorLog(_L("Could not convert Python script named"), aSubName, rest); return; } } if ( code8.get() && code8->Length()>1 && (*code8)[code8->Length()-1] != '\n' ) { code8->Des().Append('\n'); } code8->Des().Append('\0'); TInt res=PyRun_SimpleString( (char*)code8->Ptr() ); if (res < 0) { msg=_L("Cannot compile code in script "); msg.Append(aSubName); ReportPythonError(msg); return; } if (aSubName.Length()>0 && aSubName[0]!='_') { // borrowed PyObject* main_module = PyImport_AddModule("__main__"); if (! main_module ) User::Leave(KErrNoMemory); // borrowed PyObject* global_dict = PyModule_GetDict(main_module); if (! global_dict ) User::Leave(KErrNoMemory); // borrowed subname8->Des().Append('\0'); PyObject* func=PyDict_GetItemString(global_dict, (const char*)subname8->Ptr()); if (func==0) { Reporting().UserErrorLog(_L("Running Python script "), aSubName, _L(" didn't create a function with that name")); } else { AddToArrayL(iFunctions, *subname8); DeleteFromArrayL(iErrorFunctions, *subname8); } } }
void CLocaLogicImpl::GetMessageL(const CBBBtDeviceList* devices, const TTime& aAtTime, TInt& doSendToIndex, TInt& aMessageCode, TDes& aWithName, TDes& aWithTitle, auto_ptr<HBufC8>& aBody) { CALLSTACKITEM_N(_CL("CLocaLogicImpl"), _CL("GetMessage")); TInterpreterAutoLock interpr; doSendToIndex=-1; TInt count=-1; const TBBBtDeviceInfo* dev=0; TInt max_seen_priority=-1; for (dev=devices->First(); dev; dev=devices->Next()) count++; python_ptr<PyObject> dict_general(PyDict_New()); if (! dict_general ) User::Leave(KErrNoMemory); AddToPyDict(dict_general, "nodename", iNodeName); AddToPyDict(dict_general, "time", aAtTime); AddToPyDict(dict_general, "bt_count", count); // borrowed PyObject* main_module = PyImport_AddModule("__main__"); if (! main_module ) User::Leave(KErrNoMemory); // borrowed PyObject* global_dict = PyModule_GetDict(main_module); if (! global_dict ) User::Leave(KErrNoMemory); // borrowed TInt index=0; dev=devices->First(); // first is the node itself for (dev=devices->Next(); dev; dev=devices->Next()) { index++; TBuf<15> mac; dev->iMAC.IntoStringL(mac); AddToPyDict(dict_general, "mac", mac); AddToPyDict(dict_general, "majorclass", dev->iMajorClass()); AddToPyDict(dict_general, "minorclass", dev->iMinorClass()); TBool found=EFalse; python_ptr<PyObject> dict_devstats(PyDict_New()); { TBuf<50> node; TDevStats s; for(found=iDevStats->FirstStats(*dev, node, s); found; found=iDevStats->NextStats(*dev, node, s)) { python_ptr<PyObject> dict_dev( DevStatToPyDict(s)); auto_ptr<HBufC8> node8(HBufC8::NewL(node.Length()+2)); TPtr8 p=node8->Des(); iCC->ConvertFromUnicode(p, node); node8->Des().ZeroTerminate(); AddToPyDict(dict_devstats, (char*)node8->Ptr(), dict_dev); } } python_ptr<PyObject> dict_msgstats(0); { TMessageStats s; iMessageStats->GetStatsL(*dev, s); dict_msgstats.reset(MessageStatToPyDict(s)); } for (int i=0; i<iFunctions->Count(); i++) { TScriptError err=RunScript(main_module, global_dict, iFunctions->MdcaPoint(i), max_seen_priority, dict_general.get(), dict_devstats.get(), dict_msgstats.get(), aMessageCode, aWithName, aWithTitle, aBody, iErrorMsgBuf, dev->iMAC() ); if (err>EHighestPriority) { #if !defined(__WINS__) && !defined(CONTEXTLOCA) if (IsInArray(iErrorFunctions, iFunctions->MdcaPoint(i))) { PyErr_Clear(); continue; } #endif AddToArrayL(iErrorFunctions, iFunctions->MdcaPoint(i)); TBuf<50> name; TInt state=CCnvCharacterSetConverter::KStateDefault; iCC->ConvertToUnicode(name, iFunctions->MdcaPoint(i), state); name.SetLength(name.Length()-1); if (err==EPythonError) { AppendCheckingSpaceL(iErrorMsgBuf, _L(" in script ")); AppendCheckingSpaceL(iErrorMsgBuf, name); ReportPythonError(iErrorMsgBuf); } else { Reporting().UserErrorLog( iErrorMsgBuf, _L(" in script "), name); } } else if (err==EHighestPriority) { doSendToIndex=index; } } } /* // phone or PDA if (aDevice.iMajorClass()==0x02 || ( aDevice.iMajorClass()==0x01 && aDevice.iMinorClass()>0x03 )) { } else { return; } */ }