email/imap4mtm/imapsession/test/src/ctestimapcommandbase.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 "ctestimapcommandbase.h"
       
    17 
       
    18 #include "cfakeinputstream.h"
       
    19 #include "cfakeoutputstream.h"
       
    20 #include "cactivewaiter.h"
       
    21 
       
    22 #include "moutputstream.h"
       
    23 #include "cimapsession.h"
       
    24 
       
    25 #include "cimapfolderinfo.h"
       
    26 #include "cimaputils.h"
       
    27 
       
    28 
       
    29 CTestImapCommandBase::CTestImapCommandBase()
       
    30 	: iInputStream(NULL)
       
    31 	, iOutputStream(NULL)
       
    32 	, iActiveWaiter(NULL)
       
    33 	, iImapSession(NULL)
       
    34 	{}
       
    35 
       
    36 CTestImapCommandBase::~CTestImapCommandBase()
       
    37 	{
       
    38 	delete iImapSession;
       
    39 	delete iActiveWaiter;
       
    40 	delete iOutputStream;
       
    41 	delete iInputStream;
       
    42 	CImapUtils::Delete();
       
    43 	}
       
    44 
       
    45 void CTestImapCommandBase::SetupL()
       
    46 	{
       
    47 	ASSERT(iInputStream == NULL);
       
    48 	ASSERT(iOutputStream == NULL);
       
    49 	ASSERT(iActiveWaiter == NULL);
       
    50 	ASSERT(iImapSession == NULL);
       
    51 	
       
    52 	CImapUtils::CreateL();
       
    53 	iInputStream = CFakeInputStream::NewL(Logger());
       
    54 	iOutputStream = CFakeOutputStream::NewL(Logger());
       
    55 	iActiveWaiter = new(ELeave)CActiveWaiter(Logger());
       
    56 	
       
    57 	CImapSettings* imapSettings=NULL; 
       
    58 	CImapMailStore* imapMailStore=NULL;
       
    59 	
       
    60 	iImapSession = CImapSession::NewL(*imapSettings,*imapMailStore,*iInputStream, *iOutputStream);
       
    61 	INFO_PRINTF1(_L("Setup: ServerGreeting"));
       
    62 	iInputStream->ResetInputStrings();
       
    63 	iInputStream->AppendInputStringL(_L8("* OK Microsoft Exchange 2000 IMAP4rev1 server version 6.0.6249.0 (lon-cn-exchng2k.msexchange2k.closedtest.intra) ready.\r\n"));
       
    64 	
       
    65 	ASSERT_EQUALS(CImapSession::EServerStateNone, iImapSession->ServerState());
       
    66 	
       
    67 	iImapSession->ReadServerGreetingL(iActiveWaiter->iStatus);
       
    68 	iActiveWaiter->WaitActive();
       
    69 	
       
    70 	INFO_PRINTF1(_L("...Login"));
       
    71 	iInputStream->ResetInputStrings();
       
    72 	iInputStream->AppendInputStringL(_L8("1 OK LOGIN completed\r\n"));
       
    73 			
       
    74 	iImapSession->LoginL(iActiveWaiter->iStatus, _L8("username"), _L8("password"));
       
    75 	iActiveWaiter->WaitActive();
       
    76 
       
    77 	ASSERT_EQUALS(CImapSession::EServerStateAuthenticated, iImapSession->ServerState());
       
    78 
       
    79 
       
    80 	INFO_PRINTF1(_L("...Select inbox"));
       
    81 	iInputStream->ResetInputStrings();
       
    82 	iInputStream->AppendInputStringL(_L8("2 OK [READ-WRITE] SELECT completed\r\n"));
       
    83 		
       
    84 	CImapFolderInfo* folderInfo = CImapFolderInfo::NewL();
       
    85 	CleanupStack::PushL(folderInfo);
       
    86 	
       
    87 	folderInfo->SetNameL(_L16("inbox"));
       
    88 	CleanupStack::Pop(folderInfo);
       
    89 	iImapSession->SelectL(iActiveWaiter->iStatus, folderInfo);
       
    90 	iActiveWaiter->WaitActive();
       
    91 
       
    92 	ASSERT_EQUALS(CImapSession::EServerStateSelected, iImapSession->ServerState());
       
    93 	ASSERT_EQUALS(folderInfo, iImapSession->SelectedFolderInfo());
       
    94 	folderInfo = NULL;
       
    95 
       
    96 
       
    97 	INFO_PRINTF1(_L("Setup: Complete"));
       
    98 	}
       
    99 	
       
   100 void CTestImapCommandBase::TearDownL()
       
   101 	{
       
   102 	delete iImapSession;
       
   103 	iImapSession = NULL;
       
   104 	
       
   105 	delete iActiveWaiter;
       
   106 	iActiveWaiter = NULL;
       
   107 	
       
   108 	delete iOutputStream;
       
   109 	iOutputStream = NULL;
       
   110 	
       
   111 	delete iInputStream;
       
   112 	iInputStream = NULL;
       
   113 	
       
   114 	CImapUtils::Delete();
       
   115 	}