email/imap4mtm/imapsession/test/src/cfakeinputstream.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 "cfakeinputstream.h"
       
    17 #include <utf.h>
       
    18 
       
    19 CFakeInputStream* CFakeInputStream::NewL(CTestExecuteLogger& aLogger)
       
    20 // static
       
    21 	{
       
    22 	return new(ELeave)CFakeInputStream(aLogger);
       
    23 	}
       
    24 
       
    25 CFakeInputStream::CFakeInputStream(CTestExecuteLogger& aLogger)
       
    26 	: CActive(CActive::EPriorityStandard)
       
    27 	, iLogger(aLogger)
       
    28 	{
       
    29 	CActiveScheduler::Add(this);
       
    30 	}
       
    31 		
       
    32 CFakeInputStream::~CFakeInputStream()
       
    33 	{
       
    34 	Cancel(); 
       
    35 	iInputStrings.Reset();
       
    36 	}
       
    37 
       
    38 void CFakeInputStream::Bind(MInputStreamObserver& aInputStreamObserver, TInt /*aLogId*/)
       
    39 	{
       
    40 	INFO_PRINTF1(_L("CFakeInputStream::Bind()"));
       
    41 	iInputStreamObserver = &aInputStreamObserver;
       
    42 	}
       
    43 void CFakeInputStream::ReadReq(TInt aIdleTime)
       
    44 	{
       
    45 	aIdleTime = aIdleTime;// To avoid build errors
       
    46 	INFO_PRINTF1(_L("CFakeInputStream::ReadReq()"));
       
    47 	iIsReading = ETrue;
       
    48 	CompleteSelf(KErrNone);
       
    49 	}
       
    50 void CFakeInputStream::CancelReadReq()
       
    51 	{
       
    52 	INFO_PRINTF1(_L("CFakeInputStream::CancelReadReq()"));
       
    53 	iIsReading = EFalse;
       
    54 	Cancel();
       
    55 	}
       
    56 TBool CFakeInputStream::IsReading()
       
    57 	{
       
    58 	INFO_PRINTF1(_L("CFakeInputStream::IsReading()"));
       
    59 	return iIsReading;
       
    60 	}
       
    61 	
       
    62 void CFakeInputStream::CompleteSelf(TInt aError)
       
    63 	{
       
    64 	TRequestStatus* status = &iStatus;
       
    65 	SetActive();
       
    66 	User::RequestComplete(status, aError);
       
    67 	}
       
    68 	
       
    69 void CFakeInputStream::RunL()
       
    70 	{
       
    71 	if (iNextInputString < iInputStrings.Count())
       
    72 		{
       
    73 		TPtrC8& ptrInputString = iInputStrings[iNextInputString];
       
    74 		
       
    75 		HBufC16* unicodeBuffer = NULL;
       
    76 		TRAPD(err,
       
    77 			unicodeBuffer = CnvUtfConverter::ConvertToUnicodeFromUtf8L(ptrInputString);
       
    78 		);
       
    79 		if (err == KErrNone)
       
    80 			{
       
    81 			INFO_PRINTF2(_L("S >>> C [%S]"), unicodeBuffer);
       
    82 			}
       
    83 		delete unicodeBuffer;
       
    84 		
       
    85 		iIsReading = EFalse;
       
    86 		iInputStreamObserver->ReceivedDataIndL(ptrInputString);
       
    87 		++iNextInputString;
       
    88 		}
       
    89 		
       
    90 	if (iNextInputString == iInputStrings.Count())
       
    91 		{
       
    92 		// No more data to deliver.
       
    93 		iInputStrings.Reset();
       
    94 		iNextInputString = 0;
       
    95 		
       
    96 		// Notify the observer if one has been set
       
    97 		if (iStreamIsEmptyObserver != NULL)
       
    98 			{
       
    99 			// Need to reset the observer before it is called.
       
   100 			MFakeInputStreamIsEmptyObserver* observer = iStreamIsEmptyObserver;
       
   101 			iStreamIsEmptyObserver = NULL;
       
   102 			
       
   103 			observer->OnInputStreamIsEmptyL();
       
   104 			}
       
   105 		}
       
   106 	}
       
   107 	
       
   108 void CFakeInputStream::DoCancel()
       
   109 	{}
       
   110 
       
   111 void CFakeInputStream::NotifyWhenStreamIsEmpty(MFakeInputStreamIsEmptyObserver& aStreamIsEmptyObserver)
       
   112 	{
       
   113 	ASSERT(iStreamIsEmptyObserver == NULL);	
       
   114 	iStreamIsEmptyObserver = &aStreamIsEmptyObserver;
       
   115 	}
       
   116 
       
   117 void CFakeInputStream::AppendInputStringL(const TDesC8& aString)
       
   118 	{
       
   119 	iInputStrings.AppendL(aString);
       
   120 	}
       
   121 
       
   122 void CFakeInputStream::ResetInputStrings()
       
   123 	{
       
   124 	iInputStrings.Reset();
       
   125 	iNextInputString = 0;
       
   126 	}