void CTestImapBodyStructureBuilder::TestRfc822MessageL()
	{
	INFO_PRINTF1(_L("TestRfc822MessageL"));
		
	_LIT8(KLine, "(\"MESSAGE\" \"RFC822\" (n1 v1 n2 v2) rfcID \"this is an rfc822 message\" rfcEncoding rfcSize (env-date env-subject ((from1name from1adl from1mbox from1host)(NIL NIL from2mbox from2host)) NIL NIL ((to-name to-adl to-mbox to-host)) NIL NIL in-reply-to msg-id) (TEXT PLAIN NIL subID \"sub description\" subEncoding subSize subLines) rfcLines");
	
	TBool wantMore = iBodyStructureBuilder->ProcessBlockL(KLine);
	ASSERT_FALSE(wantMore);

	// Check the root bodystructure
	CImapBodyStructure* bodyStructure = iFetchResponse->BodyStructure();
	ASSERT_NOT_NULL(bodyStructure);
	AssertDescriptorsEqual(bodyStructure->Type(), _L8("MESSAGE"));
	AssertDescriptorsEqual(bodyStructure->SubType(), _L8("RFC822"));
	AssertDescriptorsEqual(bodyStructure->BodyDescription(), _L8("this is an rfc822 message"));
	AssertDescriptorsEqual(bodyStructure->BodyLines(), _L8("rfcLines"));
	AssertDescriptorsEqual(bodyStructure->BodyId(), _L8("rfcID"));
	AssertDescriptorsEqual(bodyStructure->BodyEncoding(), _L8("rfcEncoding"));
	AssertDescriptorsEqual(bodyStructure->BodySizeOctets(), _L8("rfcSize"));
	ASSERT_EQUALS(bodyStructure->ParameterList().Count(), 2);
 	ASSERT_EQUALS(bodyStructure->ParameterList()[0].iAttribute, _L8("n1"));
	ASSERT_EQUALS(bodyStructure->ParameterList()[0].iValue, _L8("v1"));
	ASSERT_EQUALS(bodyStructure->ParameterList()[1].iAttribute, _L8("n2"));
	ASSERT_EQUALS(bodyStructure->ParameterList()[1].iValue, _L8("v2"));
	
	// Check its envelope
	CImapEnvelope& envelope = bodyStructure->GetRfc822EnvelopeStructureL();
	AssertDescriptorsEqual(envelope.EnvDate(), _L8("env-date"));
	AssertDescriptorsEqual(envelope.EnvSubject(), _L8("env-subject"));
	ASSERT_EQUALS(envelope.EnvFrom().Count(), 2);
	CheckAddressL(envelope.EnvFrom()[0], _L16("\"from1name\" <from1mbox@from1host>"));
	CheckAddressL(envelope.EnvFrom()[1], _L16("from2mbox@from2host"));
	ASSERT_EQUALS(envelope.EnvSender().Count(), 0);
	ASSERT_EQUALS(envelope.EnvReplyTo().Count(), 0);
	ASSERT_EQUALS(envelope.EnvTo().Count(), 1);
	CheckAddressL(envelope.EnvTo()[0], _L16("\"to-name\" <to-mbox@to-host>"));
	ASSERT_EQUALS(envelope.EnvCc().Count(), 0);
	ASSERT_EQUALS(envelope.EnvBcc().Count(), 0);	
	AssertDescriptorsEqual(envelope.EnvInReplyTo(), _L8("in-reply-to"));
	AssertDescriptorsEqual(envelope.EnvMessageId(), _L8("msg-id"));
	
	// Check the embedded bodystructure
	ASSERT_EQUALS(bodyStructure->EmbeddedBodyStructureList().Count(), 1);
	CImapBodyStructure* bodyStructureEmbedded = bodyStructure->EmbeddedBodyStructureList()[0];
	
	AssertDescriptorsEqual(bodyStructureEmbedded->Type(), _L8("TEXT"));
	AssertDescriptorsEqual(bodyStructureEmbedded->SubType(), _L8("PLAIN"));
	ASSERT_EQUALS(bodyStructureEmbedded->ParameterList().Count(), 0);
 	AssertDescriptorsEqual(bodyStructureEmbedded->BodyId(), _L8("subID"));
	AssertDescriptorsEqual(bodyStructureEmbedded->BodyDescription(), _L8("sub description"));
	AssertDescriptorsEqual(bodyStructureEmbedded->BodyEncoding(), _L8("subEncoding"));
	AssertDescriptorsEqual(bodyStructureEmbedded->BodySizeOctets(), _L8("subSize"));
	AssertDescriptorsEqual(bodyStructureEmbedded->BodyLines(), _L8("subLines"));
	}
TInt CCommDbTest036_10::executeStepL()
	{
	CCommsDbTemplateRecord* templateRecord = CCommsDbTemplateRecord::NewL(iTheDb, TPtrC(DIAL_IN_ISP));
	CleanupStack::PushL(templateRecord);
	
	User::LeaveIfError(templateRecord->Modify());

	TUint32 inputInt = RMobileCall::KCapsSpeed32000;
	templateRecord->WriteTextL(TPtrC(COMMDB_NAME), _L("Name"));
	templateRecord->WriteTextL(TPtrC(ISP_IP_NAME_SERVER1),_L("MyDnsServer"));
	templateRecord->WriteBoolL(TPtrC(ISP_IP_ADDR_FROM_SERVER), ETrue);
	templateRecord->WriteBoolL(TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER), ETrue);
	templateRecord->WriteBoolL(TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER), ETrue);
	templateRecord->WriteUintL(TPtrC(ISP_BEARER_SPEED), inputInt);
	User::LeaveIfError(templateRecord->StoreModifications());

	CleanupStack::PopAndDestroy(templateRecord);

	//Create a view on the DialInISP table, make a new record and change the value we set in the template
	CCommsDbTableView* tableView = iTheDb->OpenTableLC(TPtrC(DIAL_IN_ISP));
	TUint32 dummyId;
	//Create a new record, so we can be sure it is the same as the templated one
	User::LeaveIfError(tableView->InsertRecord(dummyId));
	tableView->WriteTextL(TPtrC(COMMDB_NAME), _L("Test ISP"));
	tableView->WriteBoolL(TPtrC(ISP_IP_ADDR_FROM_SERVER), EFalse);
	tableView->WriteBoolL(TPtrC(ISP_IP_DNS_ADDR_FROM_SERVER), EFalse);
	tableView->WriteBoolL(TPtrC(ISP_IP6_DNS_ADDR_FROM_SERVER), EFalse);
	//Overwrite value we set in the template
	TUint32 overwriteInt = RMobileCall::KCapsSpeed64000;
	tableView->WriteUintL(TPtrC(ISP_BEARER_SPEED), overwriteInt);
	User::LeaveIfError(tableView->PutRecordChanges());

	//Retrieve the TUint32 we just set
	TUint32 retrievedInt;
	tableView->ReadUintL(TPtrC(ISP_BEARER_SPEED), retrievedInt);

	TBuf16<KCommsDbSvrMaxFieldLength> ifAuthName(_L16("Invalid"));
	tableView->ReadTextL(TPtrC(ISP_IP_NAME_SERVER1), ifAuthName);
	if(ifAuthName.Compare(_L16("MyDnsServer")))
		{
		User::Leave(KErrGeneral);
		}

	CleanupStack::PopAndDestroy(tableView);

	if(retrievedInt!=overwriteInt)
		return KErrGeneral;

	return KErrNone;
	}
int main()
{
    __UHEAP_MARK;
    RBuf16 myrbuf;
    TBufC16<20> myTBufC (_L16("Descriptor data"));
    myrbuf.Create(myTBufC);
    myrbuf.CleanupClosePushL();
    char *des= NULL;
    int retval=ESuccess;
    int size=40;
    retval= Rbuf16ToChar(myrbuf,des,size);

    if(retval == EInvalidPointer)
    {
        printf("Test_rbuf16tochar_nullcheck passed\n");
    }
    else
    {
        assert_failed = true;
        printf("Test_rbuf16tochar_nullcheck FAILURE\n");
    }
    delete[] des;
    des=NULL;
    CleanupStack::PopAndDestroy(1);
    __UHEAP_MARKEND;
    testResultXml("test_rbuf16tochar_nullcheck");
    return 0;
}
// -----------------------------------------------------------------------------
// CMCETestUIEngineEvent::State
// -----------------------------------------------------------------------------
//
EXPORT_C const TDesC& CMCETestUIEngineEvent::State() 
    {
    if ( !iEvent ) 
        {
        User::Panic( _L16("CMCETestUIEngine"), 0 );
        }
        
    TInt state = iEvent->State();

	switch( state ) 
		{
		case CMceEvent::EIdle: 
		    return KEventStateIdle; 
		    break;
		case CMceEvent::EPending: 
		    return KEventStatePending; 
		    break;
		case CMceEvent::EActive: 
		    return KEventStateActive; 
		    break;
		case CMceEvent::ETerminated: 
		    return KEventStateTerminated; 
		    break;
		default: 
		    return KEventStateUnknown; 
		    break;
		}    
    }
Beispiel #5
0
LOCAL_C void testTLitC()
	{
	test.Start(_L("All members"));
	test (_L("")==KNullDesC);			// operator const TDesC&
	test (KNullDesC()==TPtrC());		// operator()
	const TDesC* pNull=&KNullDesC;	// operator&
	test (pNull->Compare(_L(""))==0);
	test (&testByRef(KNullDesC)==&KNullDesC);	// operator const TRefByValue<const TDesC>
#if defined(_UNICODE)
	test (_L16("")==KNullDesC);			// operator const TDesC&
	test (KNullDesC()==TPtrC16());		// operator()
	const TDesC16* pNull16=&KNullDesC;	// operator&
	test (pNull16->Compare(_L16(""))==0);
	test (&testByRef16(KNullDesC)==&KNullDesC);	// operator const TRefByValue<const TDesC>
#else
	test (_L8("")==KNullDesC);			// operator const TDesC&
	test (KNullDesC()==TPtrC8());		// operator()
	const TDesC8* pNull8=&KNullDesC;	// operator&
	test (pNull8->Compare(_L8(""))==0);
	test (&testByRef8(KNullDesC)==&KNullDesC);	// operator const TRefByValue<const TDesC>
#endif
//
	test.Next(_L("Literal values"));
	const TDesC& t1=KLitTest1;
	test (t1.Length()==1);
	test (t1[0]=='1');
	test (t1==_L("1"));
	const TDesC& t12=KLitTest12;
	test (t12.Length()==2);
	test (t12[0]=='1');
	test (t12==_L("12"));
	const TDesC& t123=KLitTest123;
	test (t123.Length()==3);
	test (t123[0]=='1');
	test (t123==_L("123"));
	const TDesC& t1234=KLitTest1234;
	test (t1234.Length()==4);
	test (t1234[0]=='1');
	test (t1234==_L("1234"));
	const TDesC& talpha=KLitTestalpha;
	test (talpha.Length()==26);
	test (talpha[0]=='a');
	test (talpha==_L("abcdefghijklmnopqrstuvwxyz"));
//
	test.End();
	}
void CTestImapNoop::SetupL()
	{
	ASSERT(iInputStream == NULL);
	ASSERT(iOutputStream == NULL);
	ASSERT(iActiveWaiter == NULL);
	ASSERT(iImapSession == NULL);

	CImapUtils::CreateL();
	iInputStream = CFakeInputStream::NewL(Logger());
	iOutputStream = CFakeOutputStream::NewL(Logger());
	iActiveWaiter = new(ELeave)CActiveWaiter(Logger());
	
	CImapSettings* imapSettings=NULL; 
	CImapMailStore* imapMailStore=NULL;
	
	iImapSession = CImapSession::NewL(*imapSettings,*imapMailStore,*iInputStream, *iOutputStream);
	
	INFO_PRINTF1(_L("Setup: ServerGreeting"));
	iInputStream->ResetInputStrings();
	iInputStream->AppendInputStringL(_L8("* OK Microsoft Exchange 2000 IMAP4rev1 server version 6.0.6249.0 (lon-cn-exchng2k.msexchange2k.closedtest.intra) ready.\r\n"));

	ASSERT_EQUALS(CImapSession::EServerStateNone, iImapSession->ServerState());
	
	iImapSession->ReadServerGreetingL(iActiveWaiter->iStatus);
	iActiveWaiter->WaitActive();
	
	INFO_PRINTF1(_L("...Login"));
	iInputStream->ResetInputStrings();
	iInputStream->AppendInputStringL(_L8("1 OK LOGIN completed\r\n"));
			
	iImapSession->LoginL(iActiveWaiter->iStatus, _L8("username"), _L8("password"));
	iActiveWaiter->WaitActive();

	ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState());


	INFO_PRINTF1(_L("...Select inbox"));
	iInputStream->ResetInputStrings();
	iInputStream->AppendInputStringL(_L8("* 23 EXISTS\r\n"));
	iInputStream->AppendInputStringL(_L8("* 1 RECENT\r\n"));
	iInputStream->AppendInputStringL(_L8("* OK [UNSEEN 12] Message 12 is first unseen\r\n"));
	iInputStream->AppendInputStringL(_L8("* OK [UIDVALIDITY 3857529045] UIDs valid\r\n"));
	iInputStream->AppendInputStringL(_L8("2 OK [READ-WRITE] SELECT completed\r\n"));
		
	CImapFolderInfo* folderInfo = CImapFolderInfo::NewL();
	CleanupStack::PushL(folderInfo);
	
	folderInfo->SetNameL(_L16("inbox"));
	CleanupStack::Pop(folderInfo);
	iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo);
	iActiveWaiter->WaitActive();

	ASSERT_EQUALS(CImapSession::EServerStateSelected, iImapSession->ServerState());
	ASSERT_EQUALS(folderInfo, iImapSession->SelectedFolderInfo());
	
	ResetFolderInfo(*folderInfo);	
	folderInfo = NULL;
	}
Beispiel #7
0
LOCAL_C void testTLitC16()
	{
	test.Start(_L("All members"));
	test (_L16("")==KNullDesC16);			// operator const TDesC16&
	test (KNullDesC16()==TPtrC16());		// operator()
	const TDesC16* pNull=&KNullDesC16;	// operator&
	test (pNull->Compare(_L16(""))==0);
	test (&testByRef16(KNullDesC16)==&KNullDesC16);	// operator const TRefByValue<const TDesC16>
//
	test.Next(_L("Literal values"));
	const TDesC16& t1=KLitTest1_16;
	test (t1.Length()==1);
	test (t1[0]=='1');
	test (t1==_L16("1"));
	const TDesC16& t12=KLitTest12_16;
	test (t12.Length()==2);
	test (t12[0]=='1');
	test (t12==_L16("12"));
	const TDesC16& t123=KLitTest123_16;
	test (t123.Length()==3);
	test (t123[0]=='1');
	test (t123==_L16("123"));
	const TDesC16& t1234=KLitTest1234_16;
	test (t1234.Length()==4);
	test (t1234[0]=='1');
	test (t1234==_L16("1234"));
	const TDesC16& talpha=KLitTestalpha_16;
	test (talpha.Length()==26);
	test (talpha[0]=='a');
	test (talpha==_L16("abcdefghijklmnopqrstuvwxyz"));
//
	test.End();
	}
Beispiel #8
0
GLDEF_C void TestCopy16()
//	Test TPtr16 copy constructor
	{
    TBuf16<0x20> buf(_S16("Paddington Station"));
	TPtr16 ptr1((TText16*)buf.Ptr(),buf.Length(),buf.MaxLength());
	ptr1.__DbgTestInvariant();
	TPtr16 ptr2(ptr1);
	ptr2.__DbgTestInvariant();
	ptr2[11]='B';
	ptr2[12]='e';
	ptr2[13]='a';
	ptr2[14]='r';
	ptr2[15]=' ';
	ptr1.SetLength(15);
	ptr2.Append(_L16(" acid"));
	test(ptr1==_L16("Paddington Bear"));
	test(ptr2==_L16("Paddington Bear on acid"));
	}
Beispiel #9
0
/**
@SYMTestCaseID          SYSLIB-BAFL-CT-0437
@SYMTestCaseDesc        Reading ALIGNMENT_HORROR resources test
                        Test for TResourceReader::ReadTPtrC8(),TResourceReader::ReadTPtrC16() function
@SYMTestPriority        High
@SYMTestActions         Tests for reading descriptors and checks for alignment
@SYMTestExpectedResults Tests must not fail
@SYMREQ                 REQ0000
*/
void TRsReadTester::TestAlignment1L()
	{
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0437 Test reading ALIGNMENT_HORROR resources "));
	TPtrC8  ref8 =_L8("xyz");
	TPtrC16 ref16=_L16("xyz");
    TResourceReader reader;
	for (TInt rr=0; horrors[rr]!=0; rr++)
		{
		CreateResourceReaderLC(reader,horrors[rr]);
		test(reader.ReadTPtrC8() ==ref8.Left(rr));
		test(reader.ReadTPtrC16()==ref16.Left(rr));
		CleanupStack::PopAndDestroy(1);
		}
	}
Beispiel #10
0
/**
@SYMTestCaseID          SYSLIB-BAFL-CT-0438
@SYMTestCaseDesc        Reading ALIGNMENT_HORROR_ARRAY resource test
@SYMTestPriority        High
@SYMTestActions         Tests for reading descriptors and checks for alignment
@SYMTestExpectedResults Tests must not fail
@SYMREQ                 REQ0000
*/
void TRsReadTester::TestAlignment2L()
	{
	test.Next(_L(" @SYMTestCaseID:SYSLIB-BAFL-CT-0438 Test reading ALIGNMENT_HORROR_ARRAY resource "));
    TResourceReader reader;
    CreateResourceReaderLC(reader,SYS_ALIGNMENT_HORROR_ARRAY);
    test(reader.ReadInt16()==7); // how many items following
    TPtrC8  ref8 =_L8("abcdef");
    TPtrC16 ref16=_L16("abcdef");
    for (TInt ii=0; ii<=6; ii++)
        {
        test(reader.ReadTPtrC8() ==ref8.Left(ii));
        test(reader.ReadTPtrC16()==ref16.Mid(ii));
        }
    CleanupStack::PopAndDestroy(1);
	}
Beispiel #11
0
GLDEF_C void Test16To8()
//	Test ASCII dest with Unicode source
	{
    TBuf8<0x20> buf(_S8("Paddington Station"));
	TPtr8 ptr1((TText8*)buf.Ptr(),buf.Length(),buf.MaxLength());
	ptr1.__DbgTestInvariant();
	TPtr8 ptr2(ptr1);
	ptr2.__DbgTestInvariant();
	ptr2[11]='B';
	ptr2[12]='e';
	ptr2[13]='a';
	ptr2[14]='r';
	ptr2[15]=' ';
	ptr1.SetLength(15);
	ptr1.__DbgTestInvariant();
	ptr2.Append(_L16(" acid"));
	ptr2.__DbgTestInvariant();
	test(ptr1==_L8("Paddington Bear"));
	test(ptr2==_L8("Paddington Bear on acid"));
	}
/*
 * Get cipher list supported by SSL/TLS backend.
 */
PJ_DEF(pj_status_t) pj_ssl_cipher_get_availables (pj_ssl_cipher ciphers[],
					          unsigned *cipher_num)
{
    unsigned i;

    PJ_ASSERT_RETURN(ciphers && cipher_num, PJ_EINVAL);
    
    if (ciphers_num_ == 0) {
        RSocket sock;
        CSecureSocket *secure_sock;
        TPtrC16 proto(_L16("TLS1.0"));

        secure_sock = CSecureSocket::NewL(sock, proto);
        if (secure_sock) {
            TBuf8<128> ciphers_buf(0);
            secure_sock->AvailableCipherSuites(ciphers_buf);
            
            ciphers_num_ = ciphers_buf.Length() / 2;
            if (ciphers_num_ > PJ_ARRAY_SIZE(ciphers_))
        	ciphers_num_ = PJ_ARRAY_SIZE(ciphers_);
            for (i = 0; i < ciphers_num_; ++i) {
                ciphers_[i].id = (pj_ssl_cipher)(ciphers_buf[i*2]*10 + 
					         ciphers_buf[i*2+1]);
		ciphers_[i].name = get_cipher_name(ciphers_[i].id);
	    }
        }
        
        delete secure_sock;
    }
    
    if (ciphers_num_ == 0) {
	*cipher_num = 0;
	return PJ_ENOTFOUND;
    }
    
    *cipher_num = PJ_MIN(*cipher_num, ciphers_num_);
    for (i = 0; i < *cipher_num; ++i)
        ciphers[i] = ciphers_[i].id;
    
    return PJ_SUCCESS;
}
void CT_ISO2022JP1_2::TestIso2022Jp(CCnvCharacterSetConverter * characterSetConverter, TBool isS60version)
    {
    //
    INFO_PRINTF1(_L("Empty descriptor"));
    TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 0, 10, 0, KNullDesC8, KNullDesC8, KNullDesC16);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 0, 10, 0, 0, KNullDesC16, KNullDesC8);
    INFO_PRINTF1(_L("Testing converting to ISO-2022-JP"));

    _LIT(KTestUnicode,">.@>0l90");
    _LIT(KTestUnicode2,"\x0393\x03b1\x03c3\x03bf\x03c5\x3055\x3088");
    TestConversionFromUnicodeToIso(*characterSetConverter, KTestUnicode2);
    TestConversionFromUnicodeToIso(*characterSetConverter, KTestUnicode);
    
    TBuf16<50> originalUnicode;
    originalUnicode.Format(_L16("%c%c%c%c%c\xa5%c%c%c%c%c"), 0x0393, 0x03b1, 0x03c3, 0x03bf, 0x03c5, 0x3055, 0x3088, 0x3046, 0x306a, 0x3089);
    TestTruncatedConversionFromUnicodeToIso2022Jp(*characterSetConverter, originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 3, 7, 12, _L8(""), _L8("\x1b\x24\x42\x26\x23\x26\x41\x26\x52\x26\x4f\x26\x54\x1b\x28\x4a\\\x1b\x28\x42\\\x1b\x24\x42\x24\x35\x24\x68\x24\x26\x24\x4a\x24\x69\x1b\x28\x42"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 8, 9, 11, _L8("\x1b\x24\x42\x26\x23\x1b\x28\x42"), _L8("\x1b\x24\x42\x26\x41\x26\x52\x26\x4f\x26\x54\x1b\x28\x4a\\\x1b\x28\x42\\\x1b\x24\x42\x24\x35\x24\x68\x24\x26\x24\x4a\x24\x69\x1b\x28\x42"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 10, 11, 10, _L8("\x1b\x24\x42\x26\x23\x26\x41\x1b\x28\x42"), _L8("\x1b\x24\x42\x26\x52\x26\x4f\x26\x54\x1b\x28\x4a\\\x1b\x28\x42\\\x1b\x24\x42\x24\x35\x24\x68\x24\x26\x24\x4a\x24\x69\x1b\x28\x42"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 12, 13, 9, _L8("\x1b\x24\x42\x26\x23\x26\x41\x26\x52\x1b\x28\x42"), _L8("\x1b\x24\x42\x26\x4f\x26\x54\x1b\x28\x4a\\\x1b\x28\x42\\\x1b\x24\x42\x24\x35\x24\x68\x24\x26\x24\x4a\x24\x69\x1b\x28\x42"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 14, 15, 8, _L8("\x1b\x24\x42\x26\x23\x26\x41\x26\x52\x26\x4f\x1b\x28\x42"), _L8("\x1b\x24\x42\x26\x54\x1b\x28\x4a\\\x1b\x28\x42\\\x1b\x24\x42\x24\x35\x24\x68\x24\x26\x24\x4a\x24\x69\x1b\x28\x42"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 16, 19, 7, _L8("\x1b\x24\x42\x26\x23\x26\x41\x26\x52\x26\x4f\x26\x54\x1b\x28\x42"), _L8("\x1b\x28\x4a\\\x1b\x28\x42\\\x1b\x24\x42\x24\x35\x24\x68\x24\x26\x24\x4a\x24\x69\x1b\x28\x42"), originalUnicode);
//    TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 20, 23, 6, _L8("\x1b\x24\x42\x26\x23\x26\x41\x26\x52\x26\x4f\x26\x54\x1b\x28\x4a\\\x1b\x28\x42"), _L8("\\\x1b\x24\x42\x24\x35\x24\x68\x24\x26\x24\x4a\x24\x69\x1b\x28\x42"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 24, 28, 5, _L8("\x1b\x24\x42\x26\x23\x26\x41\x26\x52\x26\x4f\x26\x54\x1b\x28\x4a\\\x1b\x28\x42\\"), _L8("\x1b\x24\x42\x24\x35\x24\x68\x24\x26\x24\x4a\x24\x69\x1b\x28\x42"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 29, 30, 4, _L8("\x1b\x24\x42\x26\x23\x26\x41\x26\x52\x26\x4f\x26\x54\x1b\x28\x4a\\\x1b\x28\x42\\\x1b\x24\x42\x24\x35\x1b\x28\x42"), _L8("\x1b\x24\x42\x24\x68\x24\x26\x24\x4a\x24\x69\x1b\x28\x42"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 31, 32, 3, _L8("\x1b\x24\x42\x26\x23\x26\x41\x26\x52\x26\x4f\x26\x54\x1b\x28\x4a\\\x1b\x28\x42\\\x1b\x24\x42\x24\x35\x24\x68\x1b\x28\x42"), _L8("\x1b\x24\x42\x24\x26\x24\x4a\x24\x69\x1b\x28\x42"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 33, 34, 2, _L8("\x1b\x24\x42\x26\x23\x26\x41\x26\x52\x26\x4f\x26\x54\x1b\x28\x4a\\\x1b\x28\x42\\\x1b\x24\x42\x24\x35\x24\x68\x24\x26\x1b\x28\x42"), _L8("\x1b\x24\x42\x24\x4a\x24\x69\x1b\x28\x42"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 35, 36, 1, _L8("\x1b\x24\x42\x26\x23\x26\x41\x26\x52\x26\x4f\x26\x54\x1b\x28\x4a\\\x1b\x28\x42\\\x1b\x24\x42\x24\x35\x24\x68\x24\x26\x24\x4a\x1b\x28\x42"), _L8("\x1b\x24\x42\x24\x69\x1b\x28\x42"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 37, 50, 0, _L8("\x1b\x24\x42\x26\x23\x26\x41\x26\x52\x26\x4f\x26\x54\x1b\x28\x4a\\\x1b\x28\x42\\\x1b\x24\x42\x24\x35\x24\x68\x24\x26\x24\x4a\x24\x69\x1b\x28\x42"), KNullDesC8, originalUnicode);
    originalUnicode.Format(_L16("%cX%cY%cZ"), 0x6153, 0x6376, 0x65d9);
    TestTruncatedConversionFromUnicodeToIso2022Jp(*characterSetConverter, originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 3, 7, 6, _L8(""), _L8("\x1b\x24\x42XX\x1b\x28\x42X\x1b\x24\x42YY\x1b\x28\x42Y\x1b\x24\x42ZZ\x1b\x28\x42Z"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 8, 11, 5, _L8("\x1b\x24\x42XX\x1b\x28\x42"), _L8("X\x1b\x24\x42YY\x1b\x28\x42Y\x1b\x24\x42ZZ\x1b\x28\x42Z"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 12, 16, 4, _L8("\x1b\x24\x42XX\x1b\x28\x42X"), _L8("\x1b\x24\x42YY\x1b\x28\x42Y\x1b\x24\x42ZZ\x1b\x28\x42Z"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 17, 20, 3, _L8("\x1b\x24\x42XX\x1b\x28\x42X\x1b\x24\x42YY\x1b\x28\x42"), _L8("Y\x1b\x24\x42ZZ\x1b\x28\x42Z"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 21, 25, 2, _L8("\x1b\x24\x42XX\x1b\x28\x42X\x1b\x24\x42YY\x1b\x28\x42Y"), _L8("\x1b\x24\x42ZZ\x1b\x28\x42Z"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 26, 29, 1, _L8("\x1b\x24\x42XX\x1b\x28\x42X\x1b\x24\x42YY\x1b\x28\x42Y\x1b\x24\x42ZZ\x1b\x28\x42"), _L8("Z"), originalUnicode);
//  TestSplittingConvertingFromUnicodeToIso2022Jp(*characterSetConverter, 30, 40, 0, _L8("\x1b\x24\x42XX\x1b\x28\x42X\x1b\x24\x42YY\x1b\x28\x42Y\x1b\x24\x42ZZ\x1b\x28\x42Z"), KNullDesC8, originalUnicode);
    INFO_PRINTF1(_L("Testing converting to Unicode"));
    const TPtrC8 originalIso2022Jp(_S8("\x1b\x24\x40\x1b\x28\x4aMy name is \x1b\x28\x4a\x1b\x28\x42\x1b\x24\x40\x25\x47\x25\x23\x25\x53\x25\x45\x1b\x28\x4a in \x1b\x24\x42\x46\x7c\x4b\x5c\x38\x6c\x1b\x28\x42\\~\x1b\x28\x4a\\~"));
    TBuf16<50> expectedUnicode;
    if (!isS60version)        
        expectedUnicode.Format(_L16("My name is %c%c%c%c in %c%c%c\\~%c%c"), 0x30c7, 0x30a3, 0x30d3, 0x30c5, 0x65e5, 0x672c, 0x8a9e, 0x00a5, 0x203e);
    else
        expectedUnicode.Format(_L16("My name is %c%c%c%c in %c%c%c\\~%c%c"), 0x30c7, 0x30a3, 0x30d3, 0x30c5, 0x65e5, 0x672c, 0x8a9e, 0x00a5, 0x7e);
    TestTruncatedConversionToUnicodeFromIso2022Jp(*characterSetConverter, expectedUnicode, originalIso2022Jp);
    TestTruncatedConversionToUnicodeFromIso2022Jp(*characterSetConverter, _L16(" Hello"), _L8("\x1b\x24\x42\x1b\x28\x4a\x1b\x24\x42\x1b\x28\x4a\x1b\x24\x42\x1b\x28\x4a Hello"));
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 0, 0, 60, 0, expectedUnicode, originalIso2022Jp);
    for (int i=1; i<=10; ++i)
        {
        TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, i, i, 54-i, i, expectedUnicode, originalIso2022Jp);
        }
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 11, 11, 34, 11, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 12, 12, 32, 12, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 13, 13, 30, 13, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 14, 14, 28, 14, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 15, 15, 23, 15, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 16, 16, 22, 16, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 17, 17, 21, 17, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 18, 18, 20, 18, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 19, 19, 16, 19, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 20, 20, 14, 20, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 21, 21, 12, 21, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 22, 22, 7, 22, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 23, 23, 6, 23, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 24, 24, 2, 24, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 25, 25, 1, 25, expectedUnicode, originalIso2022Jp);
    TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, 26, 40, 0, 26, expectedUnicode, originalIso2022Jp);
    INFO_PRINTF1(_L("Testing the default ISO-2022-JP state"));
    for (int i=0; i<=6; ++i)
        {
        TestSplittingConvertingToUnicodeFromIso2022Jp(*characterSetConverter, i, i, 6-i, i, _L16("Hello\xa5"), _L8("Hello\\"));
        }
    INFO_PRINTF1(_L("Testing ill-formed ISO-2022-JP"));
    TestIsIllFormedIso2022Jp(*characterSetConverter, _L8("abc \x1b\x24\x42\x21\x1b\x28\x4a def"));
    TestIsIllFormedIso2022Jp(*characterSetConverter, _L8("abc \x1b\x24\x42\x21\x21\x21\x1b\x28\x4a def"));
    TestIsIllFormedIso2022Jp(*characterSetConverter, _L8("abc \x1b\x24\x42\x21\x21\x21\x21\x21\x1b\x28\x4a def"));
    TestIsIllFormedIso2022Jp(*characterSetConverter, _L8("abc \x1b"));
    TestIsIllFormedIso2022Jp(*characterSetConverter, _L8("abc \x1b\x24"));
    TestIsIllFormedIso2022Jp(*characterSetConverter, _L8("abc \x1b\x24\xff"));
    TestIsIllFormedIso2022Jp(*characterSetConverter, _L8("abc \x1b\x26\x40"));
    }
/**
@SYMTestCaseID          SYSLIB-CHARCONV-CT-0540
@SYMTestCaseDesc        JIS to Unicode and Unicode to EucJpPacked conversion tests
@SYMTestPriority        Medium
@SYMTestActions         Calls up all conversion test functions from EucJpPacked to Unicode
@SYMTestExpectedResults Test must not fail
@SYMREQ                 REQ0000
*/
void CT_EUCJP_PACKED_2::DoE32MainL()
	{
	RFs fileServerSession;
	CleanupClosePushL(fileServerSession);
	User::LeaveIfError(fileServerSession.Connect());
	CCnvCharacterSetConverter* characterSetConverter=CCnvCharacterSetConverter::NewLC();
	CArrayFix<CCnvCharacterSetConverter::SCharacterSet>* arrayOfCharacterSetsAvailable=CCnvCharacterSetConverter::CreateArrayOfCharacterSetsAvailableLC(fileServerSession);
	INFO_PRINTF1(_L("Available:\n"));
	TInt i;
	for (i=arrayOfCharacterSetsAvailable->Count()-1; i>=0; --i)
		{
		const CCnvCharacterSetConverter::SCharacterSet& charactersSet=(*arrayOfCharacterSetsAvailable)[i];
		characterSetConverter->PrepareToConvertToOrFromL(charactersSet.Identifier(), *arrayOfCharacterSetsAvailable, fileServerSession);
		TPtrC charactersSetName(charactersSet.Name());
		if (charactersSet.NameIsFileName())
			{
			charactersSetName.Set(TParsePtrC(charactersSetName).Name());
			}
		INFO_PRINTF2(_L("    %S\n"), &charactersSetName);
		}
	INFO_PRINTF1(_L(" @SYMTestCaseID:SYSLIB-CHARCONV-CT-0540 Testing EUC-JP (packed) conversions "));
	characterSetConverter->PrepareToConvertToOrFromL(KCharacterSetTestEucjpPacked_2, *arrayOfCharacterSetsAvailable, fileServerSession);
	//
	INFO_PRINTF1(_L("Empty descriptor"));
	TestSplittingConvertingFromUnicodeToEucJpPacked(*characterSetConverter, 0, 10, 0, 0, KNullDesC8, KNullDesC16);
	TestSplittingConvertingToUnicodeFromEucJpPacked(*characterSetConverter, 0, 10, 0, 0, KNullDesC16, KNullDesC8);
	INFO_PRINTF1(_L("Testing converting to EUC-JP (packed)"));
	TBuf16<50> originalUnicode;
	originalUnicode.Format(_L16("Some %c%c%c%c%c%c"), 0xff9a, 0xff70, 0x6f22, 0x5b57, 0x5379, 0x5dce);
	const TPtrC8 expectedEucJpPacked(_S8("Some \x8e\xda\x8e\xb0\xb4\xc1\xbb\xfa\x8f\xb4\xc1\x8f\xbb\xfa"));
	TestTruncatedConversionFromUnicodeToEucJpPacked(*characterSetConverter, originalUnicode);
	TestSplittingConvertingFromUnicodeToEucJpPacked(*characterSetConverter, 0, 0, 11, 0, expectedEucJpPacked, originalUnicode);
	TestSplittingConvertingFromUnicodeToEucJpPacked(*characterSetConverter, 1, 1, 10, 1, expectedEucJpPacked, originalUnicode);
	TestSplittingConvertingFromUnicodeToEucJpPacked(*characterSetConverter, 2, 2, 9, 2, expectedEucJpPacked, originalUnicode);
	TestSplittingConvertingFromUnicodeToEucJpPacked(*characterSetConverter, 3, 3, 8, 3, expectedEucJpPacked, originalUnicode);
	TestSplittingConvertingFromUnicodeToEucJpPacked(*characterSetConverter, 4, 4, 7, 4, expectedEucJpPacked, originalUnicode);
	TestSplittingConvertingFromUnicodeToEucJpPacked(*characterSetConverter, 5, 6, 6, 5, expectedEucJpPacked, originalUnicode);
	TestSplittingConvertingFromUnicodeToEucJpPacked(*characterSetConverter, 7, 8, 5, 7, expectedEucJpPacked, originalUnicode);
	TestSplittingConvertingFromUnicodeToEucJpPacked(*characterSetConverter, 9, 10, 4, 9, expectedEucJpPacked, originalUnicode);
	TestSplittingConvertingFromUnicodeToEucJpPacked(*characterSetConverter, 11, 12, 3, 11, expectedEucJpPacked, originalUnicode);
	TestSplittingConvertingFromUnicodeToEucJpPacked(*characterSetConverter, 13, 15, 2, 13, expectedEucJpPacked, originalUnicode);
	TestSplittingConvertingFromUnicodeToEucJpPacked(*characterSetConverter, 16, 18, 1, 16, expectedEucJpPacked, originalUnicode);
	TestSplittingConvertingFromUnicodeToEucJpPacked(*characterSetConverter, 19, 30, 0, 19, expectedEucJpPacked, originalUnicode);
	INFO_PRINTF1(_L("Testing converting to Unicode"));
	const TPtrC8 originalEucJpPacked(_S8("pool\xbe\xae\xc3\xd3\x8e\xcc\x8e\xdf\x8e\xd9\x8f\xc0\xcd\x8f\xc8\xc5pool\x8e\xcc\x8e\xdf\x8e\xd9\xbe\xae\xc3\xd3\x8f\xc0\xcd\x8f\xc8\xc5\xbe\xae\xc3\xd3pool\x8f\xc0\xcd\x8f\xc8\xc5\x8e\xcc\x8e\xdf\x8e\xd9pool"));
	TBuf16<50> expectedUnicode;
	expectedUnicode.Format(_L16("pool%c%c%c%c%c%c%cpool%c%c%c%c%c%c%c%c%cpool%c%c%c%c%cpool"), 0x5c0f, 0x6c60, 0xff8c, 0xff9f, 0xff99, 0x641e, 0x6f0d, 0xff8c, 0xff9f, 0xff99, 0x5c0f, 0x6c60, 0x641e, 0x6f0d, 0x5c0f, 0x6c60, 0x641e, 0x6f0d, 0xff8c, 0xff9f, 0xff99);
	TestTruncatedConversionToUnicodeFromEucJpPacked(*characterSetConverter, expectedUnicode, originalEucJpPacked);
	TestTruncatedConversionToUnicodeFromEucJpPacked(*characterSetConverter, expectedUnicode.Mid(4, 2), originalEucJpPacked.Mid(4, 4));
	TestTruncatedConversionToUnicodeFromEucJpPacked(*characterSetConverter, expectedUnicode.Mid(6, 3), originalEucJpPacked.Mid(8, 6));
	TestTruncatedConversionToUnicodeFromEucJpPacked(*characterSetConverter, expectedUnicode.Mid(9, 2), originalEucJpPacked.Mid(14, 6));
	static const TInt numberOfCharactersInEachHomogeneousRun[13]={4, 2, 3, 2, 4, 3, 2, 2, 2, 4, 2, 3, 4};
	static const TInt numberOfBytesPerCharacterInEachHomogeneousRun[13]={1, 2, 2, 3, 1, 2, 2, 3, 2, 1, 3, 2, 1};
	TInt e=64;
	TInt u=0;
	for (i=0; i<13; ++i)
		{
		TInt j;
		for (j=0; j<numberOfCharactersInEachHomogeneousRun[i]; ++j, ++u, e-=numberOfBytesPerCharacterInEachHomogeneousRun[i])
			{
			TestSplittingConvertingToUnicodeFromEucJpPacked(*characterSetConverter, u, u, e, u, expectedUnicode, originalEucJpPacked);
			}
		}
	test(e==0);
	test(u==37);
	TestSplittingConvertingToUnicodeFromEucJpPacked(*characterSetConverter, u, u+10, e, u, expectedUnicode, originalEucJpPacked);
	INFO_PRINTF1(_L("Testing ill-formed EUC-JP (packed)"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\xa1"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\xa1\xb2\xc3"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\xa1\xb2\x8e"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\xa1\xb2\x8f"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\xa1\xb2\x8f\xaa"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\x8e\xd4\x8e"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\x8e\xd4\x8f"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\x8e\xd4\x8f\xbb"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\x8f\xe5\x8e"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\x8f\xe5\x8f"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\x8f\xe5\x8f\xcc"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("xyz\x8e\xd4\x8e"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("xyz\x8e\xd4\x8f"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("xyz\x8e\xd4\x8f\xdd"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("xyz\x8f\xe5\x8e"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("xyz\x8f\xe5\x8f"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("xyz\x8f\xe5\x8f\xee"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\x8e "));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\x8f "));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\x8f\xf1 "));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\x8e\x41"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\x8f\x41"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\x8f\xe2\x41"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("amb\x8e "));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("amb\x8f "));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("amb\x8f\xf1 "));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("amb\x8e\x41"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("amb\x8f\x41"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("amb\x8f\xe2\x41"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\xa1 "));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("\xa1\x61"));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("eb\xa1 "));
	TestIsIllFormedEucJpPacked(*characterSetConverter, _L8("eb\xa1\x61"));

    const TPtrC8 originalEucJpPackedYen(_S8("pool\x5c"));
    TBuf16<10> expectedUnicodeBackSlash;
    expectedUnicodeBackSlash.Format(_L16("pool%c"), 0x005c);
    TInt state=CCnvCharacterSetConverter::KStateDefault;
    TBuf16<KBufferLength> generatedUnicodeBackSlash;
    test(characterSetConverter->ConvertToUnicode(generatedUnicodeBackSlash, originalEucJpPackedYen, state) == 0);
    test(generatedUnicodeBackSlash==expectedUnicodeBackSlash);
	
	CleanupStack::PopAndDestroy(3); // arrayOfCharacterSetsAvailable and characterSetConverter and fileServerSession
	}
void CTestImapFetchBody::TestFetchBinaryBodyWithCancelL()
	{
	INFO_PRINTF1(_L("TestFetchBinaryBodyWithCancelL"));
	
	iInputStream->ResetInputStrings();
	iInputStream->AppendInputStringL(_L8("* 1 FETCH (BINARY[1]<0> {19}\r\n"));
	iInputStream->AppendInputStringL(_L8("a small test body\r\n")); 
		
	iInputStream->NotifyWhenStreamIsEmpty(*this);
	
	//some test values for the info class
	_LIT8(KBodySection,"1");
	const TDesC8& bodySection(KBodySection);
	TInt messageSize=19;
	
	//more test values
	TUint messageUid=45;
	TBool peek=ETrue;
	
	// Set BINARY capability
	CImapCapabilityInfo& capabilityInfo = const_cast<CImapCapabilityInfo&>(iImapSession->CapabilityInfo());
	capabilityInfo.SetFlag(CImapCapabilityInfo::EBinaryCap, ETrue);
	
	CFetchBodyInfo* iFetchBodyInfo = CFetchBodyInfo::NewL(iBodyMessageEntry);
	iFetchBodyInfo->SetSizeToFetch(messageSize);
	iFetchBodyInfo->SetIsText(ETrue);
	iFetchBodyInfo->SetRelativePathL(bodySection);
	iFetchBodyInfo->SetBodyPartRemainingSize(0);

	delete iFetchBodyResponse;
	iFetchBodyResponse = NULL;
	iFetchBodyResponse = CImapFetchBodyResponse::NewL();
	iImapSession->FetchBodyL(iActiveWaiter->iStatus,messageUid,peek,*iFetchBodyInfo, *iFetchBodyResponse);
	
	// OnInputStreamIsEmptyL will be called during WaitActive, causing FetchBodyL to be cancelled
	iActiveWaiter->WaitActive(KErrCancel);	

	// Simulate the rest of the response being returned (after the cancel)
	iInputStream->ResetInputStrings();
	iInputStream->AppendInputStringL(_L8("UID 2717 FLAGS (\\Seen))\r\n"));
	iInputStream->AppendInputStringL(_L8("3 OK FETCH completed\r\n"));
		
		
	// Flush the rest of the response
	iImapSession->FlushCancelledCommand(iActiveWaiter->iStatus);
	iActiveWaiter->WaitActive();

	// Response data should now be flushed.
	// Try to do a simple list command using the same input stream.
	iInputStream->ResetInputStrings();
	iInputStream->AppendInputStringL(_L8("* LIST (\\UnMarked) \"/\" Drafts\r\n"));
	iInputStream->AppendInputStringL(_L8("* LIST (\\Marked) \"/\" INBOX\r\n"));
	iInputStream->AppendInputStringL(_L8("4 OK LIST completed\r\n"));
		
	RArrayImapListFolderInfo folderList;
	iImapSession->ListL(iActiveWaiter->iStatus, _L(""), _L("%"), folderList);
	iActiveWaiter->WaitActive();

	ASSERT_EQUALS(folderList.Count(), 2);
	
	ASSERT_EQUALS(folderList[0]->iHierarchySeperator, (TChar)'/');
	ASSERT_EQUALS(folderList[0]->FolderName(), _L16("Drafts"));
	ASSERT_FALSE(folderList[0]->QueryFlag(CImapListFolderInfo::ENoinferiors));
	ASSERT_FALSE(folderList[0]->QueryFlag(CImapListFolderInfo::ENoselect));
	ASSERT_FALSE(folderList[0]->QueryFlag(CImapListFolderInfo::EMarked));
	ASSERT_TRUE(folderList[0]->QueryFlag(CImapListFolderInfo::EUnmarked));
	
	ASSERT_EQUALS(folderList[1]->iHierarchySeperator, (TChar)'/');
	ASSERT_EQUALS(folderList[1]->FolderName(), _L16("INBOX"));
	ASSERT_FALSE(folderList[1]->QueryFlag(CImapListFolderInfo::ENoinferiors));
	ASSERT_FALSE(folderList[1]->QueryFlag(CImapListFolderInfo::ENoselect));
	ASSERT_TRUE(folderList[1]->QueryFlag(CImapListFolderInfo::EMarked));
	ASSERT_FALSE(folderList[1]->QueryFlag(CImapListFolderInfo::EUnmarked));

	folderList.ResetAndDestroy();

	INFO_PRINTF1(_L("Complete"));
	}
void CTestImapFetchBody::SetupL()
	{	
	ASSERT(iInputStream == NULL);
	ASSERT(iOutputStream == NULL);
	ASSERT(iActiveWaiter == NULL);
	ASSERT(iImapSession == NULL);
	ASSERT(iMsvServer == NULL);
	
	//clear the messaging folder
	CEmailTestUtils* testUtils;
	testUtils = CEmailTestUtils::NewL(test);
	CleanupStack::PushL(testUtils);
	testUtils->FileSession().SetSessionPath(KCDrive);
	
// TODO: How to clean the message folders or close the messaging server without a PANIC ????
//	testUtils->CleanMessageFolderL();
	
	testUtils->ClearEmailAccountsL();
	
	testUtils->CreateAllTestDirectories( );
	testUtils->FileSession( ).SetSessionPath( _L( "C:\\" ) );

	CleanupStack::PopAndDestroy(testUtils);

	iMsvServer = CMsvServer::NewL();

	// wait a couple of seconds
	CTestTimer* timer = CTestTimer::NewL();
	timer->After(5000000);
	CActiveScheduler::Start();
	delete timer;
	iServerEntry = CMsvServerEntry::NewL(*iMsvServer, KMsvRootIndexEntryId);
	CImapUtils::CreateL();
	iImapMailStore = CImapMailStore::NewL(*iServerEntry);	 
	iImapSettings = CImapSettings::NewL(*iServerEntry);

	iInputStream = CFakeInputStream::NewL(Logger());
	iOutputStream = CFakeOutputStream::NewL(Logger());
	iActiveWaiter = new(ELeave)CActiveWaiter(Logger());
	iImapSession = CImapSession::NewL(*iImapSettings,*iImapMailStore,*iInputStream, *iOutputStream);
	
	//create the test environment 
	CreateMessageStructureL(KMsvGlobalOutBoxIndexEntryIdValue);	

	
	INFO_PRINTF1(_L("Setup: ServerGreeting"));
	iInputStream->ResetInputStrings();
	iInputStream->AppendInputStringL(_L8("* OK Microsoft Exchange 2000 IMAP4rev1 server version 6.0.6249.0 (lon-cn-exchng2k.msexchange2k.closedtest.intra) ready.\r\n"));
	
	ASSERT_EQUALS(CImapSession::EServerStateNone, iImapSession->ServerState());
	
	iImapSession->ReadServerGreetingL(iActiveWaiter->iStatus);
	iActiveWaiter->WaitActive();
	
	INFO_PRINTF1(_L("...Login"));
	iInputStream->ResetInputStrings();
	iInputStream->AppendInputStringL(_L8("1 OK LOGIN completed\r\n"));
			
	iImapSession->LoginL(iActiveWaiter->iStatus, _L8("username"), _L8("password"));
	iActiveWaiter->WaitActive();

	ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState());


	INFO_PRINTF1(_L("...Select inbox"));
	iInputStream->ResetInputStrings();
	iInputStream->AppendInputStringL(_L8("2 OK [READ-WRITE] SELECT completed\r\n"));
		
	CImapFolderInfo* folderInfo = CImapFolderInfo::NewL();
	CleanupStack::PushL(folderInfo);
	
	folderInfo->SetNameL(_L16("inbox"));	
	CleanupStack::Pop();//folderInfo
	iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo);
	iActiveWaiter->WaitActive();

	ASSERT_EQUALS(CImapSession::EServerStateSelected, iImapSession->ServerState());
	ASSERT_EQUALS(folderInfo, iImapSession->SelectedFolderInfo());
	
	
	INFO_PRINTF1(_L("Setup: Complete"));
	}