serviceproviders/sapi_messaging/tsrc/dev/tmessagingtest/tmsg_deletemessageiter1/src/tdeletemessagetestblocks.cpp
author Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
Tue, 24 Nov 2009 08:56:33 +0200
changeset 33 50974a8b132e
parent 19 989d2f495d90
permissions -rw-r--r--
Revision: 200945 Kit: 200948

/*
* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of the License "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:   ?Description
*
*/




// INCLUDE FILES
#include <e32svr.h>
#include <StifParser.h>
//#include <SAPI_TEST\testprg.h>
#include <StifTestInterface.h>
#include <msvids.h> 
#include <msvapi.h> 
#include "messageheader.h"
#include "messagingservice.h"
////#include <senduiconsts.h>
#include "tdeletemessagetest.h"




// -----------------------------------------------------------------------------
// CTDeleteMessageTest::Delete
// Delete here all resources allocated and opened from test methods. 
// Called from destructor. 
// -----------------------------------------------------------------------------
//
void CTDeleteMessageTest::Delete() 
    {

    }

// -----------------------------------------------------------------------------
// CTDeleteMessageTest::RunMethodL
// Run specified method. Contains also table of test mothods and their names.
// -----------------------------------------------------------------------------
//
TInt CTDeleteMessageTest::RunMethodL( 
    CStifItemParser& aItem ) 
    {

    static TStifFunctionInfo const KFunctions[] =
        {  
        // Copy this line for every implemented function.
        // First string is the function name used in TestScripter script file.
        // Second is the actual implementation member function. 
        //TRY( "SendMessage",    CTDeleteMessageTest::SendMessage ),
        
        ENTRY( "DeleteMessageSms",    CTDeleteMessageTest::DeleteMessageSms),
        ENTRY( "DeleteMessageMms",    CTDeleteMessageTest::DeleteMessageMms),
        ENTRY( "DeleteMessageInvalid",    CTDeleteMessageTest::DeleteMessageInvalid),

        };

    const TInt count = sizeof( KFunctions ) / 
                        sizeof( TStifFunctionInfo );

    return RunInternalL( KFunctions, count, aItem );

    }




     
TInt  CTDeleteMessageTest::DeleteMessageSms(CStifItemParser& /*aItem*/)
	{
	__UHEAP_MARK;
	
	TInt result = KErrNone;
	
	CMessagingService* test = (CMessagingService* ) CMessagingService::NewL() ; 
	
	CleanupStack::PushL(test);	

	CFilterParamInfo* filterParams = CFilterParamInfo::NewL();

	filterParams->AddMtmL(_L("SMS"));
	
	CMsvEntrySelection* entrySelection = NULL;
	
	test->GetIdListL( filterParams, 0, NULL, entrySelection );
	
	if ( entrySelection && ( entrySelection->Count() > 0 ))
		{
		TMsvId messageid;

		CMessageHeader* header = NULL;
		
		TInt index = 0;
		test->GetNextHeaderL( filterParams, entrySelection, index, NULL, header );
		if ( header )
			{
			header->GetMessageId( messageid );
			delete header;
			header = NULL;
			
			test->DeleteMessageL( messageid, NULL );
			
			TRAPD( err, test->DeleteMessageL( messageid, NULL ));
			
			if ( err == KErrNone )
				result = KErrGeneral;
			}
		}
		
	entrySelection->Reset();
	delete entrySelection;
	delete filterParams;

	CleanupStack::PopAndDestroy(test);	

	__UHEAP_MARKEND;
	
	return result;
	}



TInt  CTDeleteMessageTest::DeleteMessageMms(CStifItemParser& /*aItem*/)
	{
	__UHEAP_MARK;
	
	TInt result = KErrNone;
	
	CMessagingService* test = (CMessagingService* ) CMessagingService::NewL() ; 
	
	CleanupStack::PushL(test);	

	CFilterParamInfo* filterParams = CFilterParamInfo::NewL();

	filterParams->AddMtmL(_L("MMS"));
	
	CMsvEntrySelection* entrySelection = NULL;
	
	test->GetIdListL( filterParams, 0, NULL, entrySelection );
	
	if ( entrySelection && ( entrySelection->Count() > 0 ))
		{
		TMsvId messageid;

		CMessageHeader* header = NULL;
		
		TInt index = 0;
		test->GetNextHeaderL( filterParams, entrySelection, index, NULL, header );
		if ( header )
			{
			header->GetMessageId( messageid );
			delete header;
			header = NULL;
			
			test->DeleteMessageL( messageid, NULL );
			
			TRAPD( err, test->DeleteMessageL( messageid, NULL ));
			
			if ( err == KErrNone )
				result = KErrGeneral;
	
			}
		}
		
	entrySelection->Reset();
	delete entrySelection;
	delete filterParams;

	CleanupStack::PopAndDestroy(test);	

	__UHEAP_MARKEND;
	
	return result;
	}


TInt  CTDeleteMessageTest::DeleteMessageInvalid(CStifItemParser& /*aItem*/)
	{

	__UHEAP_MARK;

	CMessagingService* test = (CMessagingService* ) CMessagingService::NewL() ; 
	CleanupStack::PushL(test);	


	TRAPD(err, test->DeleteMessageL(-1,NULL));


	CleanupStack::PopAndDestroy(1) ;

	__UHEAP_MARKEND;
	
	if(err != KErrNone)
	{	
		return KErrNone;
	}
	else
	{
		return err;
	}
}