Ejemplo n.º 1
0
// -----------------------------------------------------------------------------
// RDRMRightsClient::URIFileToArrayL
// Converts the given file into an array.
// -----------------------------------------------------------------------------
//
void RDRMRightsClient::URIFileToArrayL( RFs& aFs,
                                       const TDesC& aFile,
                                       RPointerArray< HBufC8 >& aList )
    {
    DRMLOG( _L( "RDRMRightsClient::URIFileToArrayL" ) );
    RFileReadStream stream;
    TUint16 size = 0;
    TPtr8 data( NULL, 0, 0 );

    User::LeaveIfError( stream.Open( aFs, aFile, EFileRead | EFileStream ) );
    CleanupClosePushL( stream );

    size = stream.ReadUint16L();
    while( size > 0 )
        {
        HBufC8* tmp = HBufC8::NewLC( size );
        data.Set( tmp->Des() );
        stream.ReadL( data, size );
        User::LeaveIfError( aList.Append( tmp ) );
        CleanupStack::Pop(); // tmp
        size = stream.ReadUint16L();
        }

    // All read, return.

    CleanupStack::PopAndDestroy(); // stream
    }
// Tests the current system state
void CGsaStateTranToDiffStatesTest::CurrentSystemStateForStateTranTestL(RFileReadStream& aFileReadStream, TInt aSystemState)
	{
	TInt currentState = aFileReadStream.ReadUint16L();
	TSsmState currentSystemState(currentState, KSsmAnySubState);
	TSsmState expectedSystemState(aSystemState, KSsmAnySubState);

	TEST(currentSystemState == expectedSystemState);
	TPtrC currentSystemStateName(currentSystemState.Name());
	TPtrC expectedSystemStateName(expectedSystemState.Name());
	INFO_PRINTF3(_L("Current system state %S Expected %S"), &currentSystemStateName, &expectedSystemStateName);
	}
/**
Reads data chunk from the file stream.
@return ETrue if the EOF found.
@param aFileReadStream - reference to file stream 
@param aPtrLineBuffer - reference to the buffer data read
@param aIsUnicode - flag to check is it Unicode or ASCII file
@param aIgnoreCharList - pointer to ingnore char list
@leave KErrNotFound
 */
TBool TestFrameworkActionsUtils::ReadDataL(RFileReadStream& aFileReadStream,
	  TPtr& aPtrLineBuffer, TBool aIsUnicode, CArrayFixFlat<TUint16>* aIgnoreCharList)
 	{
	TUint16			element = 0;
	TKeyArrayFix	key(0, ECmpTUint16);
	TInt			charPosition = 0;
	TBool			eof = EFalse;
	TInt			errorCode = KErrNone;
	TUint8			aCharASCII = 0;

	aPtrLineBuffer.FillZ();
	aPtrLineBuffer.SetLength(0);	
	
	// Validate the input ignore char list
	if (!aIgnoreCharList)
		{
		// Invalid parameter passed to ReadDataL: No ignore char list passed
		User::Leave(KErrNotFound);
		}

	// Read data from file and store it in lineBuffer 
	do   
		{
		if(aIsUnicode)
			{
			TRAP(errorCode, (element = aFileReadStream.ReadUint16L()));
			}
		else
			{
			TRAP(errorCode, (aCharASCII = aFileReadStream.ReadUint8L()));
			element = (TUint16) aCharASCII;
			}
			
		if (errorCode!=KErrEof)
			{		
			// Check the availability of ignore char in the array							
			if ( aIgnoreCharList->Find(element, key, charPosition) != KErrNone )
				{
				// Append the char to the buffer if the read char is not ignore char
				aPtrLineBuffer.Append(element);
				}
			}								
			else
				{
				eof = ETrue;
				break;
				}
				
			// Stop at the end of line or no more data 
			} while(aPtrLineBuffer.Length()<KDefBufferSize);
	
	// Return end of file flag		
	return eof;	
	}