Example #1
0
LOCAL_C void test1(CArrayFix<TText>& aFix)
//
	{
	test.Next(_L("AppendL and InsertL single chars"));
	aFix.AppendL(_S("abcd"),4);
	test(aFix[0]=='a');
	test(aFix[1]=='b');
	test(aFix[3]=='d');
	test(aFix.Count()==4);
	aFix.InsertL(2,_S("ef"),2);
	test(aFix[1]=='b');
	test(aFix[2]=='e');
	test(aFix[4]=='c');
	test(aFix.Count()==6);	
	aFix.AppendL(TText('z'));
	test(aFix[6]=='z');
	aFix.InsertL(0,TText('y'));
	test(aFix[0]=='y');
	test(aFix[1]=='a');
	test(aFix.Count()==8);
	test.Next(_L("Delete single chars"));
	aFix.Delete(3);
	test(aFix[2]=='b');
	test(aFix[3]=='f');
	test(aFix[4]=='c');
	aFix.Delete(1,2);
	test(aFix[0]=='y');
	test(aFix[1]=='f');
	test(aFix[2]=='c');
	test(aFix.Count()==5);
	aFix.Compress();
	}
TBool CPingController::DecodeRespL()
{
	// Reply from %S: bytes=%D time=%Dms TTL=%D
	// time
	TUint32 triptime = User::NTickCount() - iTimestamp;//icmpHdr->timestamp;
	
	const TUint8* reply = iReplyBuf.Ptr();
	const TIpHdr* ipHdr = (const TIpHdr*)reply;
	const TIcmpHdr* icmpHdr = (const TIcmpHdr*)(reply + ipHdr->ip_hl * 4);
	if (ntohs(icmpHdr->icd_id) != ICMP_ID)
	{
		iReplyText = StringLoader::LoadL(R_PKTPING_SOMEONE_ELSE_PACKET_RECEIVED);
		return EFalse;
	}
	if (icmpHdr->icmp_type != ICMP_ECHOREPLY)
	{
		iReplyText = StringLoader::LoadL(R_PKTPING_NONE_ECHO_TYPE_RECEIVED_FORMAT, icmpHdr->icmp_type);
		return ETrue;
	}
	if (ntohs(icmpHdr->icd_seq) != iIcmpPacket->SeqNo())
	{
		iReplyText = StringLoader::LoadL(R_PKTPING_OUT_OF_ORDER_PACKET_RECEIVED);
		return EFalse;
	}
	// from
	iRecv.Zero();
	iRecvAddr.Output(iRecv);	
	// bytes
	TUint16 bytes = ntohs(ipHdr->ip_len) - ipHdr->ip_hl * 4 - ICMP_HDR_LEN;
	// TTL
	TUint8 ttl = ipHdr->ip_ttl;
	
	CDesCArrayFlat* strings = new (ELeave) CDesCArrayFlat( 1 );
	CleanupStack::PushL( strings );
	strings->AppendL(iRecv);
	CArrayFix<TInt>* vals = new (ELeave) CArrayFixFlat<TInt>(3);
	CleanupStack::PushL( vals );
	vals->AppendL(bytes);
	vals->AppendL(triptime);
	vals->AppendL(ttl);

	iReplyText = StringLoader::LoadL(R_PKTPING_REPLY_TEXT_FORMAT, *strings, *vals);
	CleanupStack::PopAndDestroy(2); // strings, vals
	
	//stat
	iStat.sum += triptime;
	++(iStat.received);
	iStat.min = Min(iStat.min, triptime);
	iStat.max = Max(iStat.max, triptime);
	return ETrue;
}
// -----------------------------------------------------------------------------
// CTestSDKQueries::TestQVSetQueryModeL
// -----------------------------------------------------------------------------
//
TInt CTestSDKQueries::TestQVDCurrentValueTextLCL( CStifItemParser& /*aItem*/ )
    {
    CAknQueryValueDate* date = CAknQueryValueDate::NewL();
    CleanupStack::PushL( date );
    
    CAknQueryValueDateArray* dateArray = CAknQueryValueDateArray::NewL( R_TESTQUERY_DATE_FORMAT );
    CleanupStack::PushL( dateArray );
    
    CArrayFix<TTime>* timeArray = new( ELeave ) CArrayFixFlat<TTime>( 4 );
    CleanupStack::PushL( timeArray );
    
    TTime time1;
    time1.HomeTime();
    TTime time2;
    time2 = time1 + TTimeIntervalDays( 3 );
    
    timeArray->AppendL( time1 );
    timeArray->AppendL( time2 );
    
    dateArray->SetArray( *timeArray );
    
    date->SetArrayL( dateArray );
    
    HBufC* text = date->CurrentValueTextLC();
    STIF_ASSERT_NOT_NULL( text );
    
    CleanupStack::Pop( KThree );
    CleanupStack::PopAndDestroy( date );
    return KErrNone;
    }
// -----------------------------------------------------------------------------
// CTestSDKQueries::TestQVSetQueryModeL
// -----------------------------------------------------------------------------
//
TInt CTestSDKQueries::TestQVDCreateEditorL( CStifItemParser& /*aItem*/ )
    {
    CAknQueryValueDate* date = CAknQueryValueDate::NewL();
    CleanupStack::PushL( date );
    
    CAknQueryValueDateArray* dateArray = CAknQueryValueDateArray::NewL( R_TESTQUERY_DATE_FORMAT );
    CleanupStack::PushL( dateArray );
    
    CArrayFix<TTime>* timeArray = new( ELeave ) CArrayFixFlat<TTime>( 4 );
    CleanupStack::PushL( timeArray );
    
    TTime time1;
    time1.HomeTime();
    TTime time2;
    time2 = time1 + TTimeIntervalDays( 3 );
    
    timeArray->AppendL( time1 );
    timeArray->AppendL( time2 );
    
    dateArray->SetArray( *timeArray );
    
    date->SetArrayL( dateArray );

    date->SetCurrentValueIndex( KZero );
    
    TBool flag = date->CreateEditorL();
    STIF_ASSERT_TRUE( flag );
    
    CleanupStack::Pop( KTwo );
    CleanupStack::PopAndDestroy( date );
    return KErrNone;
    }
// -----------------------------------------------------------------------------
// CTestSDKQueries::TestQVDAFormattedStringSizeTwoL
// -----------------------------------------------------------------------------
//
TInt CTestSDKQueries::TestQVDAFormattedStringSizeTwoL( CStifItemParser& /*aItem*/ )
    {
    CAknQueryValueDateArray* dateArray = CAknQueryValueDateArray::NewL( R_TESTQUERY_DATE_FORMAT );
    CleanupStack::PushL( dateArray );
    
    CArrayFix<TTime>* timeArray = new( ELeave ) CArrayFixFlat<TTime>( 4 );
    CleanupStack::PushL( timeArray );
    
    TTime time1;
    time1.HomeTime();
    TTime time2;
    time2 = time1 + TTimeIntervalDays( 3 );
    
    timeArray->AppendL( time1 );
    timeArray->AppendL( time2 );
    
    dateArray->SetArray( *timeArray );
    
    TInt size = dateArray->FormattedStringSize();
    STIF_ASSERT_NOT_EQUALS( KZero, size );
    
    CleanupStack::Pop( timeArray );
    CleanupStack::PopAndDestroy( dateArray );
    return KErrNone;
    }
// -----------------------------------------------------------------------------
// CTestSDKQueries::TestQVNumberSetArrayL
// -----------------------------------------------------------------------------
//
TInt CTestSDKQueries::TestQVNumberSetArrayL( CStifItemParser& /*aItem*/ )
    {
    CAknQueryValueNumber* number = CAknQueryValueNumber::NewLC();
    
    const MDesCArray* returnArray = number->MdcArray();
    STIF_ASSERT_NULL( returnArray );
    
    CArrayFix<TInt>* mArray = new( ELeave ) CArrayFixFlat<TInt>( 2 );
    CleanupStack::PushL( mArray );
    
    mArray->AppendL( KNumber1 );
    mArray->AppendL( KNumber2 );
    
    CAknQueryValueNumberArray* numberArray = 
        CAknQueryValueNumberArray::NewL( R_TESTQUERY_NUMBER_FORMAT );
    CleanupStack::PushL( numberArray );
    
    numberArray->SetArray( *mArray );
    
    number->SetArrayL( numberArray );
    
    returnArray = number->MdcArray();
    STIF_ASSERT_EQUALS( numberArray, ( CAknQueryValueNumberArray* )returnArray );
    
    CleanupStack::Pop( KTwo );
    CleanupStack::PopAndDestroy( number );
    return KErrNone;
    }
EXPORT_C TBool AknPhoneNumberTextUtils::WrapPhoneNumberToArrayL( 
    const TDesC& aPhoneNumberToWrap,
    TInt aLineWidthInPixels,
    TInt aMaxLines,
    const CFont& aFont,
    CArrayFix<TPtrC>& aWrappedArray )
    {
    TBool retVal( EFalse ); // Not truncated
 
    HBufC* reversedText = aPhoneNumberToWrap.AllocLC();
    TPtr revPtr = reversedText->Des();

    ReverseDescriptor( revPtr );

    CArrayFix<TInt>* lineWidthArray = new (ELeave) CArrayFixFlat<TInt>(KLineArrayGranularity);
    CleanupStack::PushL( lineWidthArray );

    lineWidthArray->AppendL( aLineWidthInPixels, aMaxLines );

    // Perform the wrap on the reversed text
    AknTextUtils::WrapToArrayL( revPtr, *lineWidthArray, aFont, aWrappedArray );

    // Now rearrange the TPtrCs to point to the original array
    TInt totalLen = reversedText->Length();
    TInt count = aWrappedArray.Count();
    TInt usedLen = 0; // Accumulates the length actually used
    for ( TInt index = 0; index < count; index++)
        {
        TPtrC& currentPtr = aWrappedArray.At(index);
        // The TPtrCs have to be moved. The reversing is taken into effect, but not purely reversed
        // because their otherwise they would have negative lengths.  That is, {a,b} does not go to
        // { final - a, final - b }, but rather to {final - b, final - a}; they are flipped, to get
        // their start points before the end points
        //
        // Now, representing the start position by pos, and the end by pos+len-1 we have the TPtrC at
        // {pos, pos+len-1} inclusive, in reversed array. 
        // The TPtrC must be modified to point to {total_len-1 - (pos+len-1), total_len-1 - pos} 
        // in the unreversed array:
        TInt len = currentPtr.Length();
        usedLen += len;
        TInt pos = currentPtr.Ptr() - reversedText->Ptr(); // pointer arithmetic
        TInt newPos = totalLen - pos - len;
        // If the TPtr is zero length then it must get special treatment, as the normal
        // calculations give an end point before the start point! i.e. {pos, pos-1}
        // We handle this by NOT flipping in this case.
        // { pos, pos-1 } -> {totalLen-1-pos, totalLen-1 - (pos-1)}
        // Note that a zero length wrapped line is completely possible amoung a bunch of other 
        // lines with characters on them, as the line lengths may be of wildly different lengths.
        if ( len == 0 ) 
            newPos--;
        currentPtr.Set( aPhoneNumberToWrap.Mid(newPos, len) );
        }

    // If the accumulated length is less than that in the entire input descriptor, then text does not fit
    if ( usedLen < totalLen )
        retVal = ETrue;

    CleanupStack::PopAndDestroy(2); // lineWidthArray first, and then reversedText
    return retVal;
    }
// -----------------------------------------------------------------------------
// CTestSDKQueries::TestQVDAMdcaPointL
// -----------------------------------------------------------------------------
//
TInt CTestSDKQueries::TestQVDAMdcaPointL( CStifItemParser& /*aItem*/ )
    {
    CAknQueryValueDateArray* dateArray = CAknQueryValueDateArray::NewL( R_TESTQUERY_DATE_FORMAT );
    CleanupStack::PushL( dateArray );
    
    CArrayFix<TTime>* timeArray = new( ELeave ) CArrayFixFlat<TTime>( 4 );
    CleanupStack::PushL( timeArray );
    
    TTime time1;
    time1.HomeTime();
    TTime time2;
    time2 = time1 + TTimeIntervalDays( 3 );
    
    timeArray->AppendL( time1 );
    timeArray->AppendL( time2 );
    
    dateArray->SetArray( *timeArray );
    
    for ( TInt mark = 0; mark < dateArray->MdcaCount(); mark++ )
        {
        TPtrC text = dateArray->MdcaPoint( mark );
        STIF_ASSERT_NOT_NULL( &text );
        }
    
    CleanupStack::Pop( timeArray );
    CleanupStack::PopAndDestroy( dateArray );
    return KErrNone;
    }
// -----------------------------------------------------------------------------
// CTestSDKQueries::TestQVNumberCreateEditorL
// -----------------------------------------------------------------------------
//
TInt CTestSDKQueries::TestQVNumberCreateEditorL( CStifItemParser& /*aItem*/ )
    {
    CAknQueryValueNumber* number = CAknQueryValueNumber::NewLC();
    
    CArrayFix<TInt>* mArray = new( ELeave ) CArrayFixFlat<TInt>( 2 );
    CleanupStack::PushL( mArray );
    
    mArray->AppendL( KNumber1 );
    mArray->AppendL( KNumber2 );
    
    CAknQueryValueNumberArray* numberArray = 
        CAknQueryValueNumberArray::NewL( R_TESTQUERY_NUMBER_FORMAT );
    CleanupStack::PushL( numberArray );
    
    numberArray->SetArray( *mArray );
    
    number->SetArrayL( numberArray );
    
    number->SetCurrentValueIndex( KZero );
    
    TBool flag = number->CreateEditorL();
    STIF_ASSERT_TRUE( flag );
    
    CleanupStack::Pop( KTwo );
    CleanupStack::PopAndDestroy( number );
    return KErrNone;
    }
// -----------------------------------------------------------------------------
// CTestSDKQueries::TestQVNumberCurrentValueTextLCL
// -----------------------------------------------------------------------------
//
TInt CTestSDKQueries::TestQVNumberCurrentValueTextLCL( CStifItemParser& /*aItem*/ )
    {
    CAknQueryValueNumber* number = CAknQueryValueNumber::NewLC();
    
    CArrayFix<TInt>* mArray = new( ELeave ) CArrayFixFlat<TInt>( 2 );
    CleanupStack::PushL( mArray );
    
    mArray->AppendL( KNumber1 );
    mArray->AppendL( KNumber2 );
    
    CAknQueryValueNumberArray* numberArray = 
        CAknQueryValueNumberArray::NewL( R_TESTQUERY_NUMBER_FORMAT );
    CleanupStack::PushL( numberArray );
    
    numberArray->SetArray( *mArray );
    
    number->SetArrayL( numberArray );
    
    HBufC* text = number->CurrentValueTextLC();
    STIF_ASSERT_NOT_NULL( text );
    
    CleanupStack::Pop( KThree );
    CleanupStack::PopAndDestroy( number );
    return KErrNone;
    }
// ---------------------------------------------------------------------------
// CXIMPContextEventFilter::InternalizeL()
// ---------------------------------------------------------------------------
//
EXPORT_C void CXIMPContextEventFilter::InternalizeL( 
    RReadStream& aStream )
    {
    TInt count = aStream.ReadInt32L();
    if( count )
        {
        //We are internalizing data which we have previously externalized 
        // => Internalized array can be directly set as current array
        
        CArrayFix< TInt32 >* events = 
                new (ELeave) CArrayFixFlat< TInt32 >( KXIMPEventListGranurality );
        CleanupStack::PushL( events );

        for( TInt ix = 0; ix < count; ++ix )
            {
            events->AppendL( aStream.ReadInt32L() );
            }
        delete iAcceptedEvents;
        iAcceptedEvents = events;

        CleanupStack::Pop( events );
        }

    else
        {
        delete iAcceptedEvents;
        iAcceptedEvents = NULL;
        }        
    }
Example #12
0
EXPORT_C TInt FontUtils::GetAvailableHeightsInTwipsL(const CGraphicsDevice& aDevice,const TDesC& aTypefaceName,CArrayFix<TInt>& aHeightList)
/** Gets a list of all heights in twips, available for the named typeface and the 
graphics device specified.

@param aDevice The graphics device.
@param aTypefaceName The name of the typeface.
@param aHeightList On return, contains all available heights for the typeface, 
in twips. 
@return KErrNotSupported if the named typeface is not supported by the graphics 
device, otherwise KErrNone. */
	{ // static
	aHeightList.Reset();
	const TInt numTypefaces=aDevice.NumTypefaces();
	TInt fontIndex;
	for (fontIndex=0;fontIndex<numTypefaces;fontIndex++)
		{
    	TTypefaceSupport typefaceInfo;
		aDevice.TypefaceSupport(typefaceInfo,fontIndex);
		if (typefaceInfo.iTypeface.iName==aTypefaceName)
			break;
		}
	if (fontIndex>=numTypefaces)
		return KErrNotSupported;
	TTypefaceSupport typefaceInfo;
	aDevice.TypefaceSupport(typefaceInfo,fontIndex);
	const TInt numHeights=typefaceInfo.iNumHeights;
	for (TInt ii=0;ii<numHeights;ii++)
		{
		const TInt height=aDevice.FontHeightInTwips(fontIndex,ii);
		if (PointsFromTwips(height)>=EMinFontHeight)
			aHeightList.AppendL(height);
		}
	return KErrNone;
	}
/**
 Retrieves the SIM lanugages list.
 
 This will retrieve the SIM languages list in a dynamic array, the list was prepared by a previous successful call to @c PrepareSimLanguages().
 
 @param aSimLanguageCount   The count of the languages as prepared in a previous call to @c PrepareSimLanguages().
                            This count is used to allocate and expand the size of the flat buffer. 
                                                
 @return A pointer to the fixed length array CArrayFix<TInt32> of language codes.
 
 @note This API can only be called by processes with the SecureID of the System State Manager.
 
 @see RSsmMiscAdaptation::PrepareSimLanguages
 
 @publishedPartner
 @released
*/
EXPORT_C CArrayFix<TInt32>* RSsmMiscAdaptation::SimLanguagesArrayL(TInt aSimLanguageCount)
	{
	if(! Handle())
		{
		User::Leave(KErrDisconnected);
		}
	CArrayFix<TInt32>* clientArray = new (ELeave) CArrayFixFlat<TInt32>(2);
	CleanupStack::PushL(clientArray);

	CBufFlat* buffer=CBufFlat::NewL(aSimLanguageCount);
	CleanupStack::PushL(buffer);
	const TInt length = aSimLanguageCount * sizeof(TInt32);
	buffer->ExpandL(0,length);
	TPtr8 bufPtr = buffer->Ptr(0);
	User::LeaveIfError(SendReceive(EGetSimLanguagesArray, TIpcArgs(&bufPtr, aSimLanguageCount)));

	RBufReadStream readStream(*buffer);
	CleanupClosePushL(readStream);
	
	TInt32 langId = 0; //Initialized with value 0 because this value is not a language id 
	for (TInt i=0; i < aSimLanguageCount; ++i)
		{
		langId = readStream.ReadInt32L();
		clientArray->AppendL(langId);  
		}
	
	CleanupStack::PopAndDestroy(2); //readStream, buffer
	CleanupStack::Pop(clientArray);
	return clientArray;
	}
Example #14
0
EXPORT_C void LafScrollThumb::GetColorUseListL(CArrayFix<TCoeColorUse>& aColorUseList)
	{ // static
	TInt commonAttributes = TCoeColorUse::ESurrounds|TCoeColorUse::ENormal|TCoeColorUse::ENeutral;
	TCoeColorUse colorUse;

	colorUse.SetLogicalColor(EColorScrollThumbDimmed);
	colorUse.SetUse(TCoeColorUse::EBack|TCoeColorUse::EDimmed|commonAttributes);
	aColorUseList.AppendL(colorUse);

	colorUse.SetLogicalColor(EColorScrollButtonThumbBackgroundPressed);
	colorUse.SetUse(TCoeColorUse::EFore|TCoeColorUse::EPressed|commonAttributes);
	aColorUseList.AppendL(colorUse);

	colorUse.SetLogicalColor(EColorScrollButtonThumbBackground);
	colorUse.SetUse(TCoeColorUse::EBack|TCoeColorUse::EActive|commonAttributes);
	aColorUseList.AppendL(colorUse);
	}
Example #15
0
EXPORT_C void LafMenuPane::GetColorUseListL(CArrayFix<TCoeColorUse>& aColorUseList)
	{ // static
	TInt commonAttributes = TCoeColorUse::ENormal|TCoeColorUse::ENeutral;
	TCoeColorUse colorUse;

	colorUse.SetLogicalColor(EColorMenuPaneText);
	colorUse.SetUse(TCoeColorUse::EFore|TCoeColorUse::EActive|TCoeColorUse::ESurrounds|commonAttributes);
	aColorUseList.AppendL(colorUse);

	colorUse.SetLogicalColor(EColorMenuPaneBackground);
	colorUse.SetUse(TCoeColorUse::EBack|TCoeColorUse::EActive|TCoeColorUse::ESurrounds|commonAttributes);
	aColorUseList.AppendL(colorUse);

	colorUse.SetLogicalColor(EColorMenuPaneTextHighlight);
	colorUse.SetUse(TCoeColorUse::EFore|TCoeColorUse::EActive|TCoeColorUse::EHighlights|commonAttributes);
	aColorUseList.AppendL(colorUse);

	colorUse.SetLogicalColor(EColorMenuPaneHighlight);
	colorUse.SetUse(TCoeColorUse::EBack|TCoeColorUse::EActive|TCoeColorUse::EHighlights|commonAttributes);
	aColorUseList.AppendL(colorUse);

	colorUse.SetLogicalColor(EColorMenuPaneDimmedTextHighlight);
	colorUse.SetUse(TCoeColorUse::EBack|TCoeColorUse::EDimmed|TCoeColorUse::EHighlights|commonAttributes);
	aColorUseList.AppendL(colorUse);

	colorUse.SetLogicalColor(EColorMenuPaneDimmedHighlight);
	colorUse.SetUse(TCoeColorUse::EFore|TCoeColorUse::EDimmed|TCoeColorUse::EHighlights|commonAttributes);
	aColorUseList.AppendL(colorUse);

	colorUse.SetLogicalColor(EColorMenuPaneDimmedText);
	colorUse.SetUse(TCoeColorUse::EBack|TCoeColorUse::EDimmed|TCoeColorUse::ESurrounds|commonAttributes);
	aColorUseList.AppendL(colorUse);
	}
// ---------------------------------------------------------
// FavouritesUtil::InternalizeL
// ---------------------------------------------------------
//
void FavouritesUtil::InternalizeL
( CArrayFix<TInt>& aArray, RReadStream& aStream )
{
    TInt count = aStream.ReadInt32L();
    for ( TInt i = 0; i < count; i++ )
    {
        aArray.AppendL( aStream.ReadInt32L() );
    }
}
Example #17
0
void QtFallbackWebPopup::showS60BrowserDialog()
{
    static MBrCtlDialogsProvider* dialogs = CBrowserDialogsProvider::NewL(0);
    if (!dialogs)
        return;

    int size = itemCount();
    CArrayFix<TBrCtlSelectOptionData>* options = new CArrayFixFlat<TBrCtlSelectOptionData>(qMax(1, size));
    RPointerArray<HBufC> items(qMax(1, size));
    CleanupStack::PushL(TCleanupItem(&ResetAndDestroy, &items));

    for (int i = 0; i < size; i++) {
        if (itemType(i) == Separator) {
            TBrCtlSelectOptionData data(_L("----------"), false, false, false);
            options->AppendL(data);
        } else {
            HBufC16* itemStr = HBufC16::NewL(itemText(i).length());
            itemStr->Des().Copy((const TUint16*)itemText(i).utf16(), itemText(i).length());
            CleanupStack::PushL(itemStr);
            TBrCtlSelectOptionData data(*itemStr, i == currentIndex(), false, itemIsEnabled(i));
            options->AppendL(data);
            items.AppendL(itemStr);
            CleanupStack::Pop();
        }
    }

    dialogs->DialogSelectOptionL(KNullDesC(), (TBrCtlSelectOptionType)(ESelectTypeSingle | ESelectTypeWithFindPane), *options);

    CleanupStack::PopAndDestroy(&items);

    int newIndex;
    for (newIndex = 0; newIndex < options->Count() && !options->At(newIndex).IsSelected(); newIndex++) {}
    if (newIndex == options->Count())
        newIndex = currentIndex();
    
    m_popupVisible = false;
    popupDidHide();

    if (currentIndex() != newIndex && newIndex >= 0)
        valueChanged(newIndex);

    delete options;
}
// ---------------------------------------------------------------------------
// CPIMContactFieldInfo::MatchPIMField
// (other items were commented in a header)
// ---------------------------------------------------------------------------
//
CArrayFix<TInt>* CPIMContactFieldInfo::MatchPIMFieldL(
    TPIMContactField aContactField) const
{
    JELOG2(EPim);
    CArrayFix<TInt>* fieldArray = new(ELeave) CArrayFixFlat<TInt> (7);
    CleanupStack::PushL(fieldArray);
    TInt count = iFieldsInfo->Count();
    for (TInt i = 0; i < count; i++)
    {
        const TPIMFieldInfo& fieldInfo = (*iFieldsInfo)[i];
        if (fieldInfo.iPIMField == aContactField)
        {
            fieldArray->AppendL(fieldInfo.iContactsModelField);
        }
    }
    CleanupStack::Pop(fieldArray);
    return fieldArray;
}
// ---------------------------------------------------------------------------
// CPIMContactFieldInfo::FieldInternalAttributes
// (other items were commented in a header)
// ---------------------------------------------------------------------------
//
void CPIMContactFieldInfo::GetFieldInternalAttributesL(
    const CContentType& aContentType, CArrayFix<TUid>& aArrayOfAttributes) const
{
    JELOG2(EPim);
    TInt fieldCount = aContentType.FieldTypeCount();
    for (TInt i = 0; i < fieldCount; i++)
    {
        TFieldType fieldType = aContentType.FieldType(i);
        TBool isSupported = EFalse;
        for (TInt j = 0; j < KPIMFieldAttributeMapSize && !isSupported; j++)
        {
            // Generate uid from the specified Contacts Model field id
            TUid uid =
                { KPIMFieldAttributeMap[j][1] };

            // Add this attribute to internal attributes array if
            // it is not supported. This covers all unknow attributes
            // that those won't be lost when a database item is modified
            if (fieldType == uid)
            {
                isSupported = ETrue;
            }
        }
        // Check that if field info array knows this Uid
        TInt fieldInfoCount = iFieldsInfo->Count();
        for (TInt j = 0; j < fieldInfoCount && !isSupported; j++)
        {
            const TPIMFieldInfo& fieldInfo = (*iFieldsInfo)[j];
            // Contacts Model field type values are defined as field types
            // So the following mappings is equal to check with the field type
            TUid uid =
                { fieldInfo.iContactsModelField };
            if (fieldType == uid)
            {
                isSupported = ETrue;
            }
        }
        // Not supported, add to internal attributes
        if (!isSupported)
        {
            aArrayOfAttributes.AppendL(fieldType);
        }
    }
}
Example #20
0
TBool CDataWrapperBase::GetPointListFromConfigL(const TDesC& aSectName, const TDesC& aKeyName, CArrayFix<TPoint>& aResult)
	{
	TBuf<KMaxTestExecuteCommandLength>	tempStore;
	TPoint								point;

	aResult.Reset();
	TBool	ok=ETrue;
	for ( TInt index=0; ok; )
		{
		tempStore.Format(KFormatFieldNumber, &aKeyName, ++index);
		ok=GetPointFromConfig(aSectName, tempStore, point);
		if ( ok )
			{
			aResult.AppendL(point);
			}
		}

	return aResult.Count()>0;
	}
// -----------------------------------------------------------------------------
// CTestSDKQueries::TestQVNArrayFormatStringL
// -----------------------------------------------------------------------------
//
TInt CTestSDKQueries::TestQVNArrayFormatStringL( CStifItemParser& /*aItem*/ )
    {
    CAknQueryValueNumberArray* numberArray = 
        CAknQueryValueNumberArray::NewL( R_TESTQUERY_NUMBER_FORMAT );
    CleanupStack::PushL( numberArray );
    
    CArrayFix<TInt>* mArray = new( ELeave ) CArrayFixFlat<TInt>( 2 );
    CleanupStack::PushL( mArray );
    
    mArray->AppendL( KNumber1 );
    mArray->AppendL( KNumber2 );
    
    numberArray->SetArray( *mArray );
    
    const HBufC* text = numberArray->FormatString();
    STIF_ASSERT_NOT_NULL( text );
    
    CleanupStack::Pop( mArray );
    CleanupStack::PopAndDestroy( numberArray );
    return KErrNone;
    }
// -----------------------------------------------------------------------------
// CTestSDKQueries::TestQVNArrayFormattedStringSizeTwoL
// -----------------------------------------------------------------------------
//
TInt CTestSDKQueries::TestQVNArrayFormattedStringSizeTwoL( CStifItemParser& /*aItem*/ )
    {
    CAknQueryValueNumberArray* numberArray = 
        CAknQueryValueNumberArray::NewL( R_TESTQUERY_NUMBER_FORMAT );
    CleanupStack::PushL( numberArray );
    
    CArrayFix<TInt>* mArray = new( ELeave ) CArrayFixFlat<TInt>( 2 );
    CleanupStack::PushL( mArray );
    
    mArray->AppendL( KNumber1 );
    mArray->AppendL( KNumber2 );
    
    numberArray->SetArray( *mArray );
    
    TInt size = numberArray->FormattedStringSize();
    STIF_ASSERT_NOT_EQUALS( KZero, size );
    
    CleanupStack::Pop( mArray );
    CleanupStack::PopAndDestroy( numberArray );
    return KErrNone;
    }
// -----------------------------------------------------------------------------
// CTestSDKQueries::TestQVDASetArrayL
// -----------------------------------------------------------------------------
//
TInt CTestSDKQueries::TestQVDASetArrayL( CStifItemParser& /*aItem*/ )
    {
    CAknQueryValueDateArray* dateArray = CAknQueryValueDateArray::NewL( R_TESTQUERY_DATE_FORMAT );
    CleanupStack::PushL( dateArray );
    
    CArrayFix<TTime>* timeArray = new( ELeave ) CArrayFixFlat<TTime>( 4 );
    CleanupStack::PushL( timeArray );
    
    TTime time1;
    time1.HomeTime();
    TTime time2;
    time2 = time1 + TTimeIntervalDays( 3 );
    
    timeArray->AppendL( time1 );
    timeArray->AppendL( time2 );
    
    dateArray->SetArray( *timeArray );
    
    CleanupStack::Pop( timeArray );
    CleanupStack::PopAndDestroy( dateArray );
    return KErrNone;
    }
Example #24
0
DMAD_EXPORT_C void TDmAdUtil::ParseUriLC(const TDesC8& aUri, CArrayFix<TPtrC8>*& aUriSegList)
    {
    TPtrC8 uri(TDmAdUtil::RemoveDotSlash(aUri));
    
    CArrayFix<TPtrC8>* uriSegList;
    uriSegList = new (ELeave) CArrayFixFlat<TPtrC8>(8);
    CleanupStack::PushL(uriSegList);

    TPtrC8 seg;
    TPtrC8 curr(uri);

    while (curr.Length() > 0)
        {
        TInt offset = curr.Locate('/');
        if (offset == KErrNotFound)
            {
            seg.Set(curr);
            curr.Set(KNullDesC8);
            }
        else
            {
            seg.Set(curr.Left(offset));
            TInt rightLth = curr.Length() - offset - 1;
            if (rightLth <= 0)           
                {
                DEBUG_LOG(_L("TDmAdUtil::ParseUriLC: corrupted uri"));
                DEBUG_LOG1(_L8("URI: %S"), &aUri);
                
                User::Leave(KErrGeneral);
                }
            curr.Set(curr.Right(rightLth));
            }
        uriSegList->AppendL(seg);
        }
    
    aUriSegList = uriSegList;
    }
// -----------------------------------------------------------------------------
// CTestSDKQueries::TestQVNumberSetQueryCaptionL
// -----------------------------------------------------------------------------
//
TInt CTestSDKQueries::TestQVNumberSetQueryCaptionL( CStifItemParser& /*aItem*/ )
    {
    CAknQueryValueNumber* number = CAknQueryValueNumber::NewLC();
    
    CArrayFix<TInt>* mArray = new( ELeave ) CArrayFixFlat<TInt>( 2 );
    CleanupStack::PushL( mArray );
    
    mArray->AppendL( KNumber1 );
    mArray->AppendL( KNumber2 );
    
    CAknQueryValueNumberArray* numberArray = 
        CAknQueryValueNumberArray::NewL( R_TESTQUERY_NUMBER_FORMAT );
    CleanupStack::PushL( numberArray );
    
    numberArray->SetArray( *mArray );
    
    number->SetArrayL( numberArray );
    
    number->SetQueryCaption( R_TESTQUERY_CAPTION );
    
    CleanupStack::Pop( KTwo );
    CleanupStack::PopAndDestroy( number );
    return KErrNone;
    }
// -----------------------------------------------------------------------------
// CTestSDKQueries::TestQVNArrayMdcaPointL
// -----------------------------------------------------------------------------
//
TInt CTestSDKQueries::TestQVNArrayMdcaPointL( CStifItemParser& /*aItem*/ )
    {
    CAknQueryValueNumberArray* numberArray = 
        CAknQueryValueNumberArray::NewL( R_TESTQUERY_NUMBER_FORMAT );
    CleanupStack::PushL( numberArray );
    
    CArrayFix<TInt>* mArray = new( ELeave ) CArrayFixFlat<TInt>( 2 );
    CleanupStack::PushL( mArray );
    
    mArray->AppendL( KNumber1 );
    mArray->AppendL( KNumber2 );
    
    numberArray->SetArray( *mArray );
    
    for ( TInt mark = 0; mark < numberArray->MdcaCount(); mark++ )
        {
        TPtrC text = numberArray->MdcaPoint( mark );
        STIF_ASSERT_NOT_NULL( &text );
        }
    
    CleanupStack::Pop( mArray );
    CleanupStack::PopAndDestroy( numberArray );
    return KErrNone;
    }
void CPingController::StatL()
{
	CArrayFix<TInt>* vals = new (ELeave) CArrayFixFlat<TInt>(7);
	CleanupStack::PushL( vals );
	vals->AppendL(iStat.sent); 
	vals->AppendL(iStat.received);
	vals->AppendL(iStat.sent - iStat.received);
	vals->AppendL((iStat.sent - iStat.received) * 100 / iStat.sent);
	if (iStat.received)
	{
		vals->AppendL(iStat.min);
		vals->AppendL(iStat.max);
		vals->AppendL(iStat.sum / iStat.received);
		iReplyText = StringLoader::LoadL(R_PKTPING_STAT_FORMAT, *vals);
	}
	else
	{
		iReplyText = StringLoader::LoadL(R_PKTPING_STAT_SHORT_FORMAT, *vals);
	}
}
void CAlfPerfAppAvkonTestCaseBasic::NextAnimFrameL()
    {
    // Begin drawing
    RWindow& window = static_cast< RWindow& >( *iAvkonControl->DrawableWindow() );
    CWindowGc& gc = iAvkonControl->SystemGc();
    TRect updateRect(iAvkonControl->Rect());
    window.Invalidate( updateRect );
    window.BeginRedraw( updateRect );
    gc.Activate(window);

    // Draw background
    TRgb color (KRgbWhite);
    gc.SetBrushColor(color);
    gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
    gc.SetPenStyle(CGraphicsContext::ESolidPen);
    gc.SetPenSize(TSize(10,10));
    gc.SetPenColor(color);    
    gc.DrawRect(updateRect);  
       
    // Calc timeline
    TTime now;
    now.UniversalTime();
    TUint millisecondFromCycleStart = now.MicroSecondsFrom(iCycleStartTime).Int64() / 1000;
    double timelinePercentage = (double)millisecondFromCycleStart / KCycleDurationMs; 
    timelinePercentage *= 0.5; // scale it a bit...
   
    // Calc rect
    TRect fullRect(updateRect);
    TSize size(fullRect.Width()*(1.0 - timelinePercentage), fullRect.Height()*(1.0 - timelinePercentage));
    TPoint windowCenter = fullRect.Center();
    TPoint tl(windowCenter.iX - size.iWidth/2, windowCenter.iY - size.iHeight/2);
    TRect rect(tl, size);
        
    // Draw
    gc.SetPenColor(KRgbBlue);
    gc.SetBrushColor(KRgbRed);
    const TPoint Point1(rect.iTl);
    const TPoint Point2(rect.iBr.iX, rect.iTl.iY);
    const TPoint Point3(rect.iBr);
    const TPoint Point4(rect.iTl.iX, rect.iBr.iY);
    const TPoint center(rect.Center());

    switch (iCycleCounter)
        {
        case 1: // DrawEllipse
            {
            gc.DrawEllipse(rect);   
            break;
            }
        case 2: // DrawRect
            {
            gc.DrawRect(rect);    
            break;
            }
        case 3: // DrawRoundRect
            {
            TSize corner(rect.Width()/5, rect.Height()/5);
            gc.DrawRoundRect(rect, corner);   
            break;
            }
        case 4: // Draw lines
            {
            gc.SetPenColor(TRgb(255,0,0));
            gc.DrawLine(Point1, Point2);       
            
            gc.SetPenColor(TRgb(200,50,0));
            gc.DrawLineTo(Point3);
            
            gc.SetPenColor(TRgb(150,100,0));
            gc.DrawLineTo(Point4);
            
            gc.SetPenColor(TRgb(100,150,0));
            gc.DrawLineBy(TPoint(0, -rect.Height()));
            
            gc.SetPenColor(TRgb(50,200,0));
            gc.MoveTo(Point2);
            gc.DrawLineTo(Point4);
                       
            gc.SetPenColor(TRgb(0,255,0));
            gc.MoveBy(TPoint(0, -rect.Height()));
            gc.DrawLineTo(Point3);
            
            gc.SetPenColor(TRgb(255,0,0));
            gc.Plot(center);
            
            break;
           }
            
        case 5: // Draw 
            {
            gc.SetPenColor(TRgb(255,0,0));
            gc.DrawArc(rect, Point2, Point1);
            gc.DrawPie(rect, Point4, Point3);
            break;
            }
            
        case 6: // Draw polygons
            {
            const TInt KNumPoints = 9;
            TPoint pointList[KNumPoints];
            pointList[0] = TPoint(Point1.iX+rect.Width()*0.25, Point1.iY);
            pointList[1] = TPoint(Point1.iX+rect.Width()*0.75, Point1.iY);
            pointList[2] = TPoint(Point2.iX, Point2.iY+rect.Height()*0.25);
            pointList[3] = TPoint(Point2.iX, Point2.iY+rect.Height()*0.75);
            pointList[4] = TPoint(Point3.iX-rect.Width()*0.25, Point3.iY);
            pointList[5] = TPoint(Point3.iX-rect.Width()*0.75, Point3.iY);
            pointList[6] = TPoint(Point4.iX, Point4.iY-rect.Height()*0.25);
            pointList[7] = TPoint(Point4.iX, Point4.iY-rect.Height()*0.75);
            pointList[8] = TPoint(Point1.iX+rect.Width()*0.25, Point1.iY);
            
            CArrayFix<TPoint>* mypoints = new CArrayFixFlat<TPoint>(KNumPoints);
            CleanupStack::PushL(mypoints);
            for(TInt i=0; i<KNumPoints; i++)
                {
                mypoints->AppendL(pointList[i]);
                }

            gc.SetPenColor(TRgb(255,0,0));
            gc.SetPenSize(TSize(20,20));
            gc.DrawPolyLine(mypoints);
            
            gc.SetPenColor(TRgb(0,255,0));
            gc.SetPenSize(TSize(15,15));
            gc.DrawPolyLine(pointList, KNumPoints);
            
            gc.SetPenColor(TRgb(255,255,0));
            gc.SetPenSize(TSize(10,10));
            gc.DrawPolygon(mypoints);
            
            gc.SetPenColor(TRgb(0,0,255));
            gc.SetPenSize(TSize(5,5));
            gc.DrawPolygon(pointList, KNumPoints);
            
            CleanupStack::PopAndDestroy(); // mypoints           
            break;
            }
            
        case 7: // Draw texts
            {
            gc.UseFont(iFont);
            gc.SetDrawMode(CGraphicsContext::EDrawModePEN);
            gc.SetPenStyle(CGraphicsContext::ESolidPen);
            gc.SetBrushStyle(CGraphicsContext::ESolidBrush);    
            
            TInt h = rect.Height() / 3;
            TInt y = rect.iTl.iY;
            TRect tinyBox(rect);
            tinyBox.SetHeight(h);
            TInt fontDescent=iFont->DescentInPixels();
            gc.SetBrushColor(TRgb(0, 0, 255)); // blue
            
            gc.SetPenColor(TRgb(0,255,0)); // green
            gc.DrawText(_L("Ilves"), tinyBox.iTl+TPoint(0, fontDescent));
            
            tinyBox.Move(0,h);
            TInt posY = tinyBox.Height()-fontDescent;
            gc.SetPenColor(TRgb(255,0,0)); 
            gc.DrawText(_L("Tappara"), tinyBox, posY);
            
            gc.SetPenColor(TRgb(0,255,0)); // green
            gc.DrawTextVertical(_L("Ilves"), tinyBox.iTl+TPoint(fontDescent, 0 ), ETrue);
            
            tinyBox.Move(0,h);
            posY = tinyBox.Height()-fontDescent;
            gc.SetPenColor(TRgb(255,0,0)); 
            gc.DrawTextVertical(_L("Tappara"), tinyBox, posY, ETrue);
            
            break;
            }

        case 8: // Draw bitmaps
            {
            TPoint pos(rect.iTl);
            gc.BitBlt(pos, iPictureBm);
            
            pos = TPoint(rect.iTl.iX + rect.Width()/3, rect.iTl.iY);
            gc.BitBlt(pos, iPictureBm, TRect(iPictureBm->SizeInPixels()));

            pos = TPoint(rect.iTl.iX + rect.Width()*2/3, rect.iTl.iY);
            gc.BitBltMasked(pos, iPictureBm, TRect(iPictureBm->SizeInPixels()), iMaskBm, EFalse);

            pos = TPoint(rect.iTl.iX, rect.iTl.iY+ rect.Height()/3);
            TRect dstRect(pos, TSize(rect.Width()/3, rect.Height()/3));
            gc.DrawBitmap(dstRect, iPictureBm, TRect(iPictureBm->SizeInPixels()));

            pos = TPoint(rect.iTl.iX + rect.Width()/3, rect.iTl.iY+ rect.Height()/3);
            dstRect =  TRect(pos, dstRect.Size());
            gc.DrawBitmap(dstRect, iPictureBm);

            pos = TPoint(rect.iTl.iX, rect.iTl.iY+ rect.Height()*2/3);
            gc.DrawBitmap(pos, iPictureBm);

            pos = TPoint(rect.iTl.iX + rect.Width()/3, rect.iTl.iY+ rect.Height()*2/3);
            dstRect =  TRect(pos, dstRect.Size());
            gc.DrawBitmapMasked(dstRect, iPictureBm, TRect(iPictureBm->SizeInPixels()), iMaskBm, EFalse);

            break;
            }
            
         case 9: // Miscellanious
            {
            TRect rect1(rect);
            rect1.SetWidth(rect.Width()/2);
            rect1.SetHeight(rect.Height()/2);
            TRect rect2(rect1);
            rect2.Move(rect1.Width(),0);
            TRect rect3(rect1);
            rect3.Move(0, rect1.Height());
            TRect rect4(rect1);
            rect4.Move(rect1.Width(), rect1.Height());
            
            // Clear
            gc.Clear();
            // Brush pattern
            gc.UseBrushPattern(iPictureBm);
            gc.SetBrushStyle(CGraphicsContext::EPatternedBrush);
            gc.DrawRect(rect1);
            gc.DiscardBrushPattern();
            // Fading & copy rect
            gc.SetFaded(ETrue);
            gc.CopyRect(rect2.iTl, rect1);
            gc.SetFadingParameters(255,0);
            gc.CopyRect(rect3.iTl, rect1);
            // Map colors  
            gc.SetPenColor(KRgbBlue);
            gc.SetBrushColor(KRgbRed);
            gc.DrawRect(rect4);   
            TRgb colors[2] = {KRgbRed, KRgbGreen}; // change brush color
            gc.MapColors(rect4,colors,1,ETrue);
             
            break;
            }
            
     default:
           gc.DrawRect(rect);          
       }

    // End drawing
    gc.Deactivate();
    window.EndRedraw();
 
    iTestCaseFrameCount++;
    }
Example #29
0
LOCAL_C void testFix(CArrayFix<TBuf<0x10> >& aFix)
//
// Test all methods
//
	{
	test.Next(_L("Test all methods"));
	test(aFix.Count()==0);
	test(aFix.Length()==sizeof(TBuf<0x10>));
	aFix.Compress();
	test(TRUE);
	aFix.Reset();
	test(TRUE);
	TKeyArrayFix kk(0,ECmpNormal,0x10);
	test(TRUE);
	aFix.Sort(kk);
	test(TRUE);
	TBuf<0x10> aa(_L("aaaaa"));
	aFix.InsertL(0,aa);
	test(TRUE);
	aFix[0].Fill(' ');
	test(TRUE);
	TBuf<0x10> z(aFix[0]);
    z.Length();
	test(TRUE);
	aFix[0].Fill('a');
	test(TRUE);
	TInt pp;
	test(aFix.Find(aa,kk,pp)==0);
	test(pp==0);
	aFix.Delete(0);
	TBuf<0x10> bb(_L("bbbbb"));
	aFix.AppendL(bb);
	test(aFix.Count()==1);
	test(aFix.InsertIsqAllowDuplicatesL(aa,kk)==0);
	test(aFix.InsertIsqAllowDuplicatesL(bb,kk)==2);
	test(aFix.FindIsq(aa,kk,pp)==0);
	test(pp==0);
	aFix.Reset();
	for(TInt index=0;index<KTestGranularity*7/2;index++)
		aFix.AppendL(aa);
	const TBuf<0x10> *end=NULL;
	const TBuf<0x10> *ptr=NULL;
	for(TInt index2=0;index2<KTestGranularity*7/2;index2++)
		{
		if (end==ptr)
			{
			end=aFix.End(index2);
			ptr=&aFix[index2];
			TInt seglen=end-ptr;
			test(seglen==KTestGranularity || seglen==(aFix.Count()-index2));
			}
		test(&aFix[index2]==ptr++);
		}
	const TBuf<0x10> *bak=NULL;
	ptr=NULL;
	for(TInt index3=KTestGranularity*7/2;index3>0;index3--)
		{
		if (bak==ptr)
			{
			bak=aFix.Back(index3);
			ptr=&aFix[index3-1]+1;
			TInt seglen=ptr-bak;
			test(seglen==KTestGranularity || seglen==index3 || seglen==index3%KTestGranularity);
			}
		test(&aFix[index3-1]==--ptr);
		}
	
	//Test ExpandL
	//Expand array in slot 1
	TBuf16<0x10> exp;
	exp=_L("abc AbC");
	aFix.InsertL(0,exp);
	aFix.InsertL(1,exp);
	aFix.InsertL(2,exp);
	exp=aFix.ExpandL(1);
	test(aFix[0]==_L("abc AbC"));
	test(aFix[1]==_L(""));
	test(aFix[2]==_L("abc AbC"));
	test(aFix[3]==_L("abc AbC"));
	
	//Test ResizeL and InsertReplL
	//Resize the array to containing 20 records,
	//copying a record into any new slots.
	TBuf<0x10> res(_L("bbbbb"));
	aFix.Reset();
	aFix.ResizeL(20,res);
	for(TInt i=0;i<20;i++)
	    {
        test(aFix[1]==_L("bbbbb"));
	    }
	}
Example #30
0
LOCAL_C void DoTestsL()
    {
	test.Start(_L("@SYMTESTCaseID:PIM-T-DB-SORTL-TEST-0001 T_DB_SortL_test"));


	// create default, empty database
	CContactDatabase* db = CContactDatabase::ReplaceL(KDbName);
	CleanupStack::PushL(db);
	
	// create contact 1 and add it to the db
	CContactCard* contact1 = CContactCard::NewLC();
	CContactItemField* fname1 = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
	_LIT(KFname1, "Aaron");
	fname1->TextStorage()->SetTextL(KFname1() );
	contact1->AddFieldL(*fname1);
	CleanupStack::Pop(fname1);
	CContactItemField* lname1 = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
	_LIT(KLname1, "Zimmerman");
	lname1->TextStorage()->SetTextL(KLname1() );
	contact1->AddFieldL(*lname1);
	CleanupStack::Pop(lname1);
	db->AddNewContactL(*contact1);
	
	// create contact 2 and add it to the db
	CContactCard* contact2 = CContactCard::NewLC();
	CContactItemField* fname2 = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldGivenName);
	_LIT(KFname2, "Zachary");
	fname2->TextStorage()->SetTextL(KFname2() );
	contact2->AddFieldL(*fname2);
	CleanupStack::Pop(fname2);
	CContactItemField* lname2 = CContactItemField::NewLC(KStorageTypeText, KUidContactFieldFamilyName);
	_LIT(KLname2, "Abrahams");
	lname2->TextStorage()->SetTextL(KLname2() );
	contact2->AddFieldL(*lname2);
	CleanupStack::Pop(lname2);
	db->AddNewContactL(*contact2);

	// fetch and print contact IDs. Expected order: 1, 2
	const CContactIdArray* items = db->SortedItemsL(); // doesn't take ownership
	_LIT(KFormattedIdList1, "Contact IDs *before* sorting: %d, %d\n");
	test.Printf(KFormattedIdList1, (*items)[0], (*items)[1]);
	TInt item1BeforeSort = (*items)[0];
	TInt item2BeforeSort = (*items)[1];
	
	// create sort order array
	CArrayFix<CContactDatabase::TSortPref>* sortOrder = new (ELeave) CArrayFixFlat<CContactDatabase::TSortPref>(2);
	CleanupStack::PushL(sortOrder);
	sortOrder->AppendL(CContactDatabase::TSortPref(KUidContactFieldFamilyName) );
	sortOrder->AppendL(CContactDatabase::TSortPref(KUidContactFieldGivenName) );

	// sort db and measure differences in heap allocations as a proxy for 
	// whether sortOrder has been deleted by SortL() or not.
	TInt totalAllocSize(0);
	TInt heapCellsDifference = User::AllocSize(totalAllocSize);
	db->SortL(sortOrder);
	heapCellsDifference -= User::AllocSize(totalAllocSize);
	CleanupStack::Pop(sortOrder);
	
	// fetch and print contact IDs. Expected order: 2, 1
	items = db->SortedItemsL(); // doesn't take ownership
	_LIT(KFormattedIdList2, "Contact IDs *after* sorting:  %d, %d\n");
	test.Printf(KFormattedIdList2, (*items)[0], (*items)[1]);
	TInt item1AfterSort = (*items)[0];
	TInt item2AfterSort = (*items)[1];
	
	//check the sort order to make sure
	test(item1BeforeSort == item2AfterSort);
	test(item2BeforeSort == item1AfterSort);
	
	// check to see if sortOrder is still usable
	if (heapCellsDifference == 0)
		{
		// attempt to re-use sortOrder -- should be allowed after workaround
		CContactDatabase::TSortPref sortPref( (*sortOrder)[0]);
		_LIT(KSortOrderInfo, "The first sort order preference's field type is: %d.\n");
		test.Printf(KSortOrderInfo, sortPref.iFieldType);
		_LIT(KYesSame, "Yes, have successfully re-used sortOrder.\n");
		test.Printf(KYesSame);
		}
	else
		{
		// looks like sortOrder has been deleted so don't try to use it
		_LIT(KNoDifferent, "No, have not reused sortOrder as it has probably been deleted.\n");
		test.Printf(KNoDifferent);
		}
	
	// cleanup
	CleanupStack::PopAndDestroy(3, db);	// and contact1, contact2
	CContactDatabase::DeleteDatabaseL(KDbName);
	
    test.End();
    test.Close();
    }