email/imap4mtm/imapservermtm/test/src/ctestimapservermtmconnectandsync.cpp
changeset 31 ebfee66fde93
parent 0 72b543305e3a
equal deleted inserted replaced
30:6a20128ce557 31:ebfee66fde93
       
     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 "cactivewaiter.h"
       
    17 #include "ctestimapservermtmconnectandsync.h"
       
    18 
       
    19 CTestImapServerMtmConnectAndSync::CTestImapServerMtmConnectAndSync( )
       
    20 	{
       
    21 	
       
    22 	}
       
    23 	
       
    24 CTestImapServerMtmConnectAndSync::~CTestImapServerMtmConnectAndSync( )
       
    25 	{
       
    26 	
       
    27 	}
       
    28 	
       
    29 void CTestImapServerMtmConnectAndSync::TestConnectAndSyncNoEmailL( )
       
    30 	{
       
    31 	INFO_PRINTF1( _L( "TestConnectAndSyncNoEmailL" ) );
       
    32 	
       
    33 	DoStartSpoofServerL( _L( "spoofserver_connect_and_sync_no_email_script" ) );
       
    34 
       
    35 	DoConnectAndSyncL( );
       
    36 	ASSERT_EQUALS( iActiveWaiter->iStatus.Int( ), KErrNone );
       
    37 	
       
    38 	DoWaitForBackGroundSyncL( );
       
    39 	ASSERT_EQUALS( iActiveWaiter->iStatus.Int( ), KErrNone );
       
    40 	
       
    41 	// check progress
       
    42 	const TDesC8& progBuf = iImapServerMtm->Progress( );
       
    43 	
       
    44 	TImap4CompoundProgress temp;    
       
    45 	TPckgC<TImap4CompoundProgress> paramPack( temp );
       
    46 
       
    47 	paramPack.Set( progBuf );
       
    48 	TImap4CompoundProgress progress = paramPack( );
       
    49 	
       
    50 /*	ASSERT_EQUALS( progress.iGenericProgress.iType, EImap4GenericProgressType );
       
    51 	ASSERT_EQUALS( progress.iGenericProgress.iOperation, TImap4GenericProgress::EConnect );
       
    52 	ASSERT_EQUALS( progress.iGenericProgress.iState, TImap4GenericProgress::ESelecting );
       
    53 	ASSERT_EQUALS( progress.iGenericProgress.iImap4SubStateProgress, TImap4GenericProgress::EIdle );
       
    54 	ASSERT_EQUALS( progress.iGenericProgress.iMsgsToDo, 0 );
       
    55 	ASSERT_EQUALS( progress.iGenericProgress.iMsgsDone, 0 );
       
    56 	ASSERT_EQUALS( progress.iGenericProgress.iPartsToDo, 1 );
       
    57 	ASSERT_EQUALS( progress.iGenericProgress.iPartsDone, 0 );
       
    58 	ASSERT_EQUALS( progress.iGenericProgress.iBytesToDo, 0 );
       
    59 	ASSERT_EQUALS( progress.iGenericProgress.iBytesDone, 0 );
       
    60 	ASSERT_EQUALS( progress.iGenericProgress.iErrorCode, 0 );
       
    61 	ASSERT_EQUALS( progress.iGenericProgress.iReturnedMsvId, ( TMsvId ) 0 );
       
    62 	ASSERT_EQUALS( progress.iGenericProgress.iTotalSize, 0 );
       
    63 
       
    64 	ASSERT_EQUALS( progress.iSyncProgress.iType, EImap4SyncProgressType );
       
    65 	ASSERT_EQUALS( progress.iSyncProgress.iState, TImap4SyncProgress::ESyncInbox );
       
    66 	ASSERT_EQUALS( progress.iSyncProgress.iFoldersToDo, 1 );
       
    67 	ASSERT_EQUALS( progress.iSyncProgress.iFoldersDone, 0 );
       
    68 	ASSERT_EQUALS( progress.iSyncProgress.iMsgsToDo, 0 );
       
    69 	ASSERT_EQUALS( progress.iSyncProgress.iMsgsDone, 0 );
       
    70 	ASSERT_EQUALS( progress.iSyncProgress.iHeadersFetched, 0 );
       
    71 	ASSERT_EQUALS( progress.iSyncProgress.iOrphanedFolders, 0 );
       
    72 	ASSERT_EQUALS( progress.iSyncProgress.iNewFolders, 0 );
       
    73 	ASSERT_EQUALS( progress.iSyncProgress.iOrphanedMessages, 0 );
       
    74 	ASSERT_EQUALS( progress.iSyncProgress.iRemoteMessagesDeleteTagged, 0 );
       
    75 	ASSERT_EQUALS( progress.iSyncProgress.iMessagesFetchedOK, 0 );
       
    76 	ASSERT_EQUALS( progress.iSyncProgress.iMessagePartsFetchedOK, 0 );
       
    77 	ASSERT_EQUALS( progress.iSyncProgress.iMessagePartsNotFound, 0 );
       
    78 	ASSERT_EQUALS( progress.iSyncProgress.iFoldersNotFound, 0 );
       
    79 	ASSERT_EQUALS( progress.iSyncProgress.iErrorCode, 0 );	
       
    80 */
       
    81 	
       
    82 	DoDisconnectL( );
       
    83 	ASSERT_EQUALS( iActiveWaiter->iStatus.Int( ), KErrNone );
       
    84 	
       
    85 	INFO_PRINTF1( _L( "TestConnectAndSyncNoEmailL completed" ) );
       
    86 	}
       
    87 	
       
    88 void CTestImapServerMtmConnectAndSync::TestConnectAndSyncWithOneEmailL( )
       
    89 	{
       
    90 	INFO_PRINTF1( _L( "TestConnectAndSyncWithOneEmailL" ) );
       
    91 	
       
    92 	INFO_PRINTF1( _L( "TestConnectAndSyncWithOneEmailL completed" ) );
       
    93 	}
       
    94 
       
    95 void CTestImapServerMtmConnectAndSync::TestConnectAndSyncWithTenEmailsL( )
       
    96 	{
       
    97 	INFO_PRINTF1( _L( "TestConnectAndSyncWithTenEmailsL" ) );
       
    98 	
       
    99 	INFO_PRINTF1( _L( "TestConnectAndSyncWithTenEmailsL completed" ) );
       
   100 	}
       
   101 	
       
   102 void CTestImapServerMtmConnectAndSync::TestConnectAndSyncWithBadLoginL( )
       
   103 	{
       
   104 	INFO_PRINTF1( _L( "TestConnectAndSyncWithBadLoginL" ) );
       
   105 	
       
   106 	DoStartSpoofServerL( _L( "spoofserver_connect_and_sync_with_bad_login_script" ) );
       
   107 
       
   108 	DoConnectAndSyncL( );
       
   109 	ASSERT_EQUALS( iActiveWaiter->iStatus.Int( ), KErrImapBadLogon );
       
   110 
       
   111 	// check progress
       
   112 	const TDesC8& progBuf = iImapServerMtm->Progress( );
       
   113 	
       
   114 	TImap4CompoundProgress temp;    
       
   115 	TPckgC<TImap4CompoundProgress> paramPack( temp );
       
   116 
       
   117 	paramPack.Set( progBuf );
       
   118 	TImap4CompoundProgress progress = paramPack( );
       
   119 	
       
   120 	ASSERT_EQUALS( progress.iGenericProgress.iType, EImap4GenericProgressType );
       
   121 	ASSERT_EQUALS( progress.iGenericProgress.iOperation, TImap4GenericProgress::EConnect );
       
   122 	ASSERT_EQUALS( progress.iGenericProgress.iState, TImap4GenericProgress::EDisconnected );
       
   123 	ASSERT_EQUALS( progress.iGenericProgress.iImap4SubStateProgress, TImap4GenericProgress::EIdle );
       
   124 	ASSERT_EQUALS( progress.iGenericProgress.iMsgsToDo, 0 );
       
   125 	ASSERT_EQUALS( progress.iGenericProgress.iMsgsDone, 0 );
       
   126 	ASSERT_EQUALS( progress.iGenericProgress.iPartsToDo, 0 );
       
   127 	ASSERT_EQUALS( progress.iGenericProgress.iPartsDone, 0 );
       
   128 	ASSERT_EQUALS( progress.iGenericProgress.iBytesToDo, 0 );
       
   129 	ASSERT_EQUALS( progress.iGenericProgress.iBytesDone, 0 );
       
   130 	ASSERT_EQUALS( progress.iGenericProgress.iErrorCode, KErrImapBadLogon );
       
   131 	ASSERT_EQUALS( progress.iGenericProgress.iReturnedMsvId, ( TMsvId ) 0 );
       
   132 	ASSERT_EQUALS( progress.iGenericProgress.iTotalSize, 0 );
       
   133 
       
   134 	ASSERT_EQUALS( progress.iSyncProgress.iType, EImap4SyncProgressType );
       
   135 	ASSERT_EQUALS( progress.iSyncProgress.iState, TImap4SyncProgress::EIdle );
       
   136 	ASSERT_EQUALS( progress.iSyncProgress.iFoldersToDo, 0 );
       
   137 	ASSERT_EQUALS( progress.iSyncProgress.iFoldersDone, 0 );
       
   138 	ASSERT_EQUALS( progress.iSyncProgress.iMsgsToDo, 0 );
       
   139 	ASSERT_EQUALS( progress.iSyncProgress.iMsgsDone, 0 );
       
   140 	ASSERT_EQUALS( progress.iSyncProgress.iHeadersFetched, 0 );
       
   141 	ASSERT_EQUALS( progress.iSyncProgress.iOrphanedFolders, 0 );
       
   142 	ASSERT_EQUALS( progress.iSyncProgress.iNewFolders, 0 );
       
   143 	ASSERT_EQUALS( progress.iSyncProgress.iOrphanedMessages, 0 );
       
   144 	ASSERT_EQUALS( progress.iSyncProgress.iRemoteMessagesDeleteTagged, 0 );
       
   145 	ASSERT_EQUALS( progress.iSyncProgress.iMessagesFetchedOK, 0 );
       
   146 	ASSERT_EQUALS( progress.iSyncProgress.iMessagePartsFetchedOK, 0 );
       
   147 	ASSERT_EQUALS( progress.iSyncProgress.iMessagePartsNotFound, 0 );
       
   148 	ASSERT_EQUALS( progress.iSyncProgress.iFoldersNotFound, 0 );
       
   149 	ASSERT_EQUALS( progress.iSyncProgress.iErrorCode, 0 );
       
   150 	
       
   151 	INFO_PRINTF1( _L( "TestConnectAndSyncWithBadLoginL completed" ) );
       
   152 	}
       
   153 	
       
   154 void CTestImapServerMtmConnectAndSync::TestConnectAndSyncWithBadPasswordL( )
       
   155 	{
       
   156 	INFO_PRINTF1( _L( "TestConnectAndSyncWithBadPasswordL" ) );
       
   157 	
       
   158 	DoStartSpoofServerL( _L( "spoofserver_connect_and_sync_with_bad_password_script" ) );
       
   159 
       
   160 	DoConnectAndSyncL( );
       
   161 	ASSERT_EQUALS( iActiveWaiter->iStatus.Int( ), KErrImapBadLogon );
       
   162 	
       
   163 	// check progress
       
   164 	const TDesC8& progBuf = iImapServerMtm->Progress( );
       
   165 	
       
   166 	TImap4CompoundProgress temp;    
       
   167 	TPckgC<TImap4CompoundProgress> paramPack( temp );
       
   168 
       
   169 	paramPack.Set( progBuf );
       
   170 	TImap4CompoundProgress progress = paramPack( );
       
   171 	
       
   172 	ASSERT_EQUALS( progress.iGenericProgress.iType, EImap4GenericProgressType );
       
   173 	ASSERT_EQUALS( progress.iGenericProgress.iOperation, TImap4GenericProgress::EConnect );
       
   174 	ASSERT_EQUALS( progress.iGenericProgress.iState, TImap4GenericProgress::EDisconnected );
       
   175 	ASSERT_EQUALS( progress.iGenericProgress.iImap4SubStateProgress, TImap4GenericProgress::EIdle );
       
   176 	ASSERT_EQUALS( progress.iGenericProgress.iMsgsToDo, 0 );
       
   177 	ASSERT_EQUALS( progress.iGenericProgress.iMsgsDone, 0 );
       
   178 	ASSERT_EQUALS( progress.iGenericProgress.iPartsToDo, 0 );
       
   179 	ASSERT_EQUALS( progress.iGenericProgress.iPartsDone, 0 );
       
   180 	ASSERT_EQUALS( progress.iGenericProgress.iBytesToDo, 0 );
       
   181 	ASSERT_EQUALS( progress.iGenericProgress.iBytesDone, 0 );
       
   182 	ASSERT_EQUALS( progress.iGenericProgress.iErrorCode, KErrImapBadLogon );
       
   183 	ASSERT_EQUALS( progress.iGenericProgress.iReturnedMsvId, ( TMsvId ) 0 );
       
   184 	ASSERT_EQUALS( progress.iGenericProgress.iTotalSize, 0 );
       
   185 
       
   186 	ASSERT_EQUALS( progress.iSyncProgress.iType, EImap4SyncProgressType );
       
   187 	ASSERT_EQUALS( progress.iSyncProgress.iState, TImap4SyncProgress::EIdle );
       
   188 	ASSERT_EQUALS( progress.iSyncProgress.iFoldersToDo, 0 );
       
   189 	ASSERT_EQUALS( progress.iSyncProgress.iFoldersDone, 0 );
       
   190 	ASSERT_EQUALS( progress.iSyncProgress.iMsgsToDo, 0 );
       
   191 	ASSERT_EQUALS( progress.iSyncProgress.iMsgsDone, 0 );
       
   192 	ASSERT_EQUALS( progress.iSyncProgress.iHeadersFetched, 0 );
       
   193 	ASSERT_EQUALS( progress.iSyncProgress.iOrphanedFolders, 0 );
       
   194 	ASSERT_EQUALS( progress.iSyncProgress.iNewFolders, 0 );
       
   195 	ASSERT_EQUALS( progress.iSyncProgress.iOrphanedMessages, 0 );
       
   196 	ASSERT_EQUALS( progress.iSyncProgress.iRemoteMessagesDeleteTagged, 0 );
       
   197 	ASSERT_EQUALS( progress.iSyncProgress.iMessagesFetchedOK, 0 );
       
   198 	ASSERT_EQUALS( progress.iSyncProgress.iMessagePartsFetchedOK, 0 );
       
   199 	ASSERT_EQUALS( progress.iSyncProgress.iMessagePartsNotFound, 0 );
       
   200 	ASSERT_EQUALS( progress.iSyncProgress.iFoldersNotFound, 0 );
       
   201 	ASSERT_EQUALS( progress.iSyncProgress.iErrorCode, 0 );
       
   202 	
       
   203 	INFO_PRINTF1( _L( "TestConnectAndSyncWithBadPasswordL completed" ) );
       
   204 	}
       
   205 	
       
   206 CTestSuite* CTestImapServerMtmConnectAndSync::CreateSuiteL( const TDesC& aName )
       
   207 	{
       
   208 	SUB_SUITE;
       
   209 //	ADD_ASYNC_TEST_STEP( TestConnectAndSyncWithBadLoginL );
       
   210 //	ADD_ASYNC_TEST_STEP( TestConnectAndSyncWithBadPasswordL );
       
   211 	ADD_ASYNC_TEST_STEP( TestConnectAndSyncNoEmailL );
       
   212 //	ADD_ASYNC_TEST_STEP( TestConnectAndSyncWithOneEmailL );
       
   213 //	ADD_ASYNC_TEST_STEP( TestConnectAndSyncWithTenEmailsL );
       
   214 	END_SUITE;
       
   215 	}
       
   216 	
       
   217 void CTestImapServerMtmConnectAndSync::DoConnectAndSyncL( )
       
   218 	{
       
   219 	iSelection->Reset( );
       
   220 	iSelection->AppendL( iImapAccount.iImapService );
       
   221 	
       
   222 	iImapServerMtm->StartCommandL( *iSelection, 
       
   223 					    		   KIMAP4MTMConnectAndSynchronise, 
       
   224 								   KNullDesC8, 
       
   225 								   iActiveWaiter->iStatus );
       
   226 
       
   227 	iActiveWaiter->WaitActive( );
       
   228 
       
   229 	}
       
   230 
       
   231 void CTestImapServerMtmConnectAndSync::DoWaitForBackGroundSyncL( )
       
   232 	{
       
   233 	
       
   234 	// TODO: Replace with loop that waits for completion (checks progress)	
       
   235 	iSelection->Reset( );
       
   236 	iImapServerMtm->StartCommandL( *iSelection,
       
   237 								   KIMAP4MTMWaitForBackground,
       
   238 								   KNullDesC8,
       
   239 								   iActiveWaiter->iStatus );
       
   240 	
       
   241 	iActiveWaiter->WaitActive( );	
       
   242 	}