messagingfw/msgtestfw/TestActions/Drm/src/CMtfTestActionCheckMessageStore.cpp
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     1 // Copyright (c) 2004-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 // __ACTION_INFO_BEGIN__ 
       
    15 // [Action Name]
       
    16 // CheckMessageStore
       
    17 // [Action Parameters]
       
    18 // session			input 			CMsvSession
       
    19 // [Action Description]
       
    20 // CheckMessageStore Test Action is intended to traverse the message store to
       
    21 // ensure its integrity.
       
    22 // [APIs Used]	
       
    23 // CMsvSession::GetEntryL
       
    24 // CMsvEntrySelection::Count
       
    25 // CMsvEntry::ChildrenL
       
    26 // CMsvEntry::Entry
       
    27 // CMsvEntry::SetEntryL
       
    28 // CMsvEntry::HasStore
       
    29 // CMsvStore::ReadStoreL
       
    30 // CMsvStore::AttachmentManagerL
       
    31 // CImEmailMessage::GetAttachmentListL
       
    32 // MMsvAttachmentManager::AttachmentCount
       
    33 // __ACTION_INFO_END__
       
    34 //
       
    35 
       
    36 //! @file
       
    37 
       
    38 #include "CMtfTestActionCheckMessageStore.h"
       
    39 
       
    40 #include "CMtfTestCase.h"
       
    41 #include "CMtfTestActionParameters.h"
       
    42 
       
    43 #include <msvstore.h>
       
    44 #include <miutset.h>
       
    45 #include <miutmsg.h>
       
    46 #include <mmsvattachmentmanager.h>
       
    47 
       
    48 /**
       
    49   Function : NewL
       
    50   Description : 
       
    51   @internalTechnology
       
    52   @param : aTestCase - CMtfTestCase for the CMtfTestAction base class
       
    53   @param : aActionParams - CMtfTestActionParameters 
       
    54   @return : CMtfTestAction* - a base class pointer to the newly created CMtfTestActionCheckMessageStore object
       
    55   @pre none
       
    56   @post none
       
    57 */
       
    58 CMtfTestAction* CMtfTestActionCheckMessageStore::NewL(CMtfTestCase& aTestCase,CMtfTestActionParameters* aActionParameters)
       
    59 {
       
    60 	CMtfTestActionCheckMessageStore* self = new (ELeave) CMtfTestActionCheckMessageStore(aTestCase);
       
    61 	CleanupStack::PushL(self);
       
    62 	self->ConstructL(aActionParameters);
       
    63 	CleanupStack::Pop(self);
       
    64 	return self;
       
    65 }
       
    66 
       
    67 /**
       
    68   Function : CMtfTestActionCheckMessageStore
       
    69   Description : Constructor
       
    70   @internalTechnology
       
    71   @param : aTestCase - CMtfTestCase for the CMtfTestAction base class
       
    72   @return : N/A
       
    73   @pre none
       
    74   @post none
       
    75 */
       
    76 CMtfTestActionCheckMessageStore::CMtfTestActionCheckMessageStore(CMtfTestCase& aTestCase) : CMtfSynchronousTestAction(aTestCase)
       
    77 {
       
    78 }
       
    79 	
       
    80 /**
       
    81   Function : ~CMtfTestActionCheckMessageStore
       
    82   Description : Destructor
       
    83   @internalTechnology
       
    84   @param :
       
    85   @return : 
       
    86   @pre 
       
    87   @post 
       
    88 */
       
    89 CMtfTestActionCheckMessageStore::~CMtfTestActionCheckMessageStore()
       
    90 {
       
    91 }
       
    92 
       
    93 /**
       
    94   Function : ExecuteActionL
       
    95   Description : Entry point for the this test action in the test framework
       
    96   @internalTechnology
       
    97   @param : none
       
    98   @return : void
       
    99   @pre none 
       
   100   @post none
       
   101 */
       
   102 void CMtfTestActionCheckMessageStore::ExecuteActionL()
       
   103 {
       
   104 	TestCase().INFO_PRINTF2(_L("Test Action %S start..."), &KTestActionCheckMessageStore);
       
   105 	CMsvSession* session = ObtainParameterReferenceL<CMsvSession>(TestCase(),ActionParameters().Parameter(0));
       
   106 	
       
   107 	// Get the root entry
       
   108 	CMsvEntry* entry = session->GetEntryL(KMsvRootIndexEntryIdValue);
       
   109 	CleanupStack::PushL(entry);
       
   110 	
       
   111 	// Traverse the message store and check the entries
       
   112 	TRAPD(err, WalkMessageStoreL(*entry));
       
   113 	if (err == KErrNone)
       
   114 	{
       
   115 		TestCase().INFO_PRINTF1(_L("CMtfTestActionCheckMessageStore: Message Store integrity OK!"));
       
   116 		TestCase().SetTestStepResult(EPass);
       
   117 	}
       
   118 	else
       
   119 	{
       
   120 		TestCase().ERR_PRINTF2(_L("CMtfTestActionCheckMessageStore: FAILED! Error traversing message store: [%d]!"), err);
       
   121 		TestCase().SetTestStepResult(EFail);
       
   122 	}
       
   123 	CleanupStack::PopAndDestroy(entry);
       
   124 	TestCase().INFO_PRINTF2(_L("Test Action %S completed."), &KTestActionCheckMessageStore);
       
   125 	TestCase().ActionCompletedL(*this);
       
   126 }
       
   127 
       
   128 /**
       
   129   Function : WalkMessageStore
       
   130   Description : Recurse down the message store
       
   131   @internalTechnology
       
   132   @param : aEntry - CMsvEntry representing the starting point for traversal
       
   133   @return : void
       
   134   @pre none 
       
   135   @post none
       
   136 */
       
   137 void CMtfTestActionCheckMessageStore::WalkMessageStoreL(CMsvEntry& aEntry)
       
   138 {
       
   139 	// Get all the children of the current entry into a selection
       
   140 	CMsvEntrySelection* sel = aEntry.ChildrenL();
       
   141 	CleanupStack::PushL(sel);
       
   142 	
       
   143 	// Loop through the sub-entries
       
   144 	for(TInt i=0;i<sel->Count();i++)
       
   145 	{
       
   146 		// Reset the entry to the child[i]
       
   147 		aEntry.SetEntryL(sel->At(i));
       
   148 		TMsvEntry entry = aEntry.Entry();
       
   149 		
       
   150 		// Parse the message. We're only interested in email messages.
       
   151 		if(entry.iType == KUidMsvMessageEntry && (entry.iMtm == KUidMsgTypeIMAP4 || entry.iMtm == KUidMsgTypePOP3))
       
   152 		{
       
   153 			ProcessMessageL(aEntry);
       
   154 		}
       
   155 		
       
   156 		// aEntry now used so safe to go recursive again
       
   157 		WalkMessageStoreL(aEntry);
       
   158 	}
       
   159 	CleanupStack::PopAndDestroy(sel);
       
   160 }
       
   161 
       
   162 /**
       
   163   Function : ProcessMessageL
       
   164   Description : Checks that the entry is valid
       
   165   @internalTechnology
       
   166   @param : aEntry - CMsvEntry to check
       
   167   @return : void
       
   168   @pre none 
       
   169   @post none
       
   170 */
       
   171 void CMtfTestActionCheckMessageStore::ProcessMessageL(CMsvEntry& aEntry)
       
   172 {
       
   173 	CImEmailMessage* message = CImEmailMessage::NewLC(aEntry);
       
   174 	message->GetAttachmentsListL(aEntry.EntryId(),CImEmailMessage::EAllAttachments,CImEmailMessage::EThisMessageAndEmbeddedMessages);
       
   175 	TInt count = message->AttachmentManager().AttachmentCount();
       
   176 	{
       
   177 		if(aEntry.HasStoreL())
       
   178 		{
       
   179 			CMsvStore* store = aEntry.ReadStoreL();
       
   180 			MMsvAttachmentManager& attManager = store->AttachmentManagerL();																			 
       
   181 			TInt count = attManager.AttachmentCount();
       
   182 			
       
   183 			// we might want to loop through the attachments and check that their files exist
       
   184 			
       
   185 			delete store;
       
   186 		}
       
   187 	}
       
   188 	CleanupStack::PopAndDestroy(message);
       
   189 }