email/imap4mtm/imapsession/test/src/cfakeoutputstream.cpp
changeset 0 72b543305e3a
equal deleted inserted replaced
-1:000000000000 0:72b543305e3a
       
     1 // Copyright (c) 2006-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 "cfakeoutputstream.h"
       
    17 #include "moutputstreamobserver.h"
       
    18 #include <utf.h>
       
    19 
       
    20 CFakeOutputStream* CFakeOutputStream::NewL(CTestExecuteLogger& aLogger)
       
    21 // static 
       
    22 	{
       
    23 	CFakeOutputStream* self = new(ELeave)CFakeOutputStream(aLogger);
       
    24 	CleanupStack::PushL(self);
       
    25 	self->ConstructL();
       
    26 	CleanupStack::Pop();
       
    27 	return self;
       
    28 	}
       
    29 
       
    30 CFakeOutputStream::CFakeOutputStream(CTestExecuteLogger& aLogger)
       
    31 	: iLogger(aLogger)
       
    32 	{}
       
    33 	
       
    34 void CFakeOutputStream::ConstructL()
       
    35 	{
       
    36 	iOutputBuffer = CBufFlat::NewL(1024);
       
    37 	}
       
    38 	
       
    39 CFakeOutputStream::~CFakeOutputStream()
       
    40 	{
       
    41 	delete iOutputBuffer;
       
    42 	}
       
    43 	
       
    44 
       
    45 void CFakeOutputStream::Bind(MOutputStreamObserver& aObserver, TInt /*aLogId*/)
       
    46 	{
       
    47 	INFO_PRINTF1(_L("CFakeOutputStream::Bind()"));
       
    48 	
       
    49 	iOutputStreamObserver = &aObserver;
       
    50 	}
       
    51 
       
    52 void CFakeOutputStream::BindSecure(MOutputStreamSecureObserver& /*aObserver*/)
       
    53 	{
       
    54 	INFO_PRINTF1(_L("CFakeOutputStream::BindSecure()"));
       
    55 	}
       
    56 
       
    57 void CFakeOutputStream::SendDataReq(const TDesC8& aBuffer, TInt aIdleTime)
       
    58 	{
       
    59 	aIdleTime = aIdleTime;// To avoid build warnings
       
    60 	INFO_PRINTF1(_L("CFakeOutputStream::SendDataReq()"));
       
    61 	
       
    62 	// Append the data to the output buffer;
       
    63 	TRAP_IGNORE(
       
    64 		iOutputBuffer->InsertL(iOutputBuffer->Size(), aBuffer);
       
    65 	)
       
    66 	
       
    67 	// Log the data (SendDataReq is non-leaving, so avoid leaving.  Hence no cleanup stack)
       
    68 	HBufC16* unicodeBuffer = NULL;
       
    69 	TRAPD(err,
       
    70 		unicodeBuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(aBuffer);
       
    71 	);
       
    72 	if (err == KErrNone)
       
    73 		{
       
    74 		INFO_PRINTF2(_L("S <<< C [%S]"), unicodeBuffer);
       
    75 		}
       
    76 	delete unicodeBuffer;
       
    77 	
       
    78 	iOutputStreamObserver->SendDataCnf();
       
    79 	}
       
    80 
       
    81 void CFakeOutputStream::SecureClientReq(const TDesC8& /*aHostName*/)
       
    82 	{
       
    83 	INFO_PRINTF1(_L("CFakeOutputStream::SecureClientReq()"));
       
    84 	}
       
    85 
       
    86 void CFakeOutputStream::Close()
       
    87 	{
       
    88 	INFO_PRINTF1(_L("CFakeOutputStream::Close()"));
       
    89 	}
       
    90 
       
    91 TPtrC8 CFakeOutputStream::PtrOutput()
       
    92 	{
       
    93 	return iOutputBuffer->Ptr(0);
       
    94 	}
       
    95 	
       
    96 void CFakeOutputStream::ResetOutput()
       
    97 	{
       
    98 	iOutputBuffer->Reset();
       
    99 	}