dbgsrv/coredumpserver/plugins/formatters/test/testcrashdatasave.cpp
changeset 0 c6b0df440bee
equal deleted inserted replaced
-1:000000000000 0:c6b0df440bee
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include <e32base.h>
       
    17 #include "testcrashdatasave.h"
       
    18 
       
    19 CTestDataSave::~CTestDataSave()
       
    20 {
       
    21     iData.Close();
       
    22 }
       
    23 
       
    24 CTestDataSave* CTestDataSave::NewL()
       
    25 {
       
    26     CTestDataSave* self = new(ELeave) CTestDataSave();
       
    27     CleanupStack::PushL(self);
       
    28     //self->ConstructL();
       
    29     self->iData.CreateL(0);
       
    30     CleanupStack::Pop(self);
       
    31     return self;
       
    32 }
       
    33 
       
    34 TInt CTestDataSave::Open(const TDesC& aParam )
       
    35 {
       
    36     iData.Zero();
       
    37 	return KErrNone;
       
    38 }
       
    39 
       
    40 TInt CTestDataSave::Close()
       
    41 {
       
    42      iData.ZeroTerminate();
       
    43 	 return KErrNone;
       
    44 }
       
    45 
       
    46 TInt CTestDataSave::Write( const TDesC8& aData)
       
    47 {
       
    48     iData.ReAlloc(iData.Length() + aData.Length());
       
    49     iData.Append(aData);
       
    50 	//Print();
       
    51 	return KErrNone;
       
    52 }
       
    53 
       
    54 TInt CTestDataSave::Write( TAny* aData, TUint aSize)
       
    55 {
       
    56     TPtrC8 data(static_cast<TUint8*>(aData), aSize);
       
    57     return ( Write(data) );
       
    58 }
       
    59 
       
    60 TInt CTestDataSave::Write( TInt aPos, const TDesC8& aData )
       
    61 {
       
    62 	if( 0 == iData.Length() )
       
    63 		{
       
    64 		iData.CreateMax( aPos + aData.Length() );
       
    65 		}
       
    66 	else if( aPos >= iData.Length() )
       
    67 		{
       
    68 		iData.ReAlloc( aPos + aData.Length() );
       
    69 		iData.SetMax();
       
    70 
       
    71 		}
       
    72 	else if( (aPos + aData.Length()) > iData.Length() )
       
    73 		{
       
    74 		iData.ReAlloc( aPos - iData.Length() + aData.Length() );
       
    75 		}
       
    76 
       
    77 	iData.Replace( aPos, aData.Length(), aData );
       
    78 
       
    79 	return KErrNone;
       
    80 }
       
    81 
       
    82 
       
    83 TInt CTestDataSave::Write( TInt aPos, TAny* aData, TUint aSize )
       
    84 	{
       
    85     TPtrC8 data(static_cast<TUint8*>(aData), aSize);
       
    86     return ( Write(aPos, data) );
       
    87 	}
       
    88 
       
    89 void CTestDataSave::Print() const
       
    90 	{
       
    91 	RBuf8 printBuf;
       
    92 	printBuf.Create( iData, iData.Length()+1 );
       
    93 	char* clPrompt = (char*) printBuf.PtrZ();
       
    94 	RDebug::Printf("  CTestDataSave::Print() length=%d, iData=>>>%s<<<\n", iData.Length(), clPrompt );
       
    95 	printBuf.Close();
       
    96 	}