telephonyserver/etelmultimode/TETEL/te_EtelMM/TE_mmmemsms.cpp
changeset 0 3553901f7fa8
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2000-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 // Contains tests for RMobileSmsMessaging API
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 
       
    20 #include "TE_EtelMMTestStepBase.h"
       
    21 #include "TE_mmmemsms.h"
       
    22 #include "TE_mmsms.h"
       
    23 #include "testdef.h"
       
    24 
       
    25 
       
    26 CTestMemSmsMessaging::CTestMemSmsMessaging()
       
    27 /** Each test step initialises it's own name
       
    28 */
       
    29 	{
       
    30 	// store the name of this test case
       
    31 	// this is the name that is used by the script file
       
    32 	SetTestStepName(_L("TestMemSmsMessaging"));
       
    33 	}
       
    34 
       
    35 enum TVerdict CTestMemSmsMessaging::doTestStepL()
       
    36 	{
       
    37 	iTestCount=1;
       
    38 	INFO_PRINTF1(_L(""));
       
    39 	INFO_PRINTF1(_L("Test RMobileSmsMessaging coping with OOM"));
       
    40 	
       
    41 	RMobilePhone mmPhone;
       
    42 	TInt ret=mmPhone.Open(iTelServer,DMMTSY_PHONE_NAME);
       
    43 	TEST(ret==KErrNone);
       
    44 
       
    45 	RMobileSmsMessaging smsMessaging;
       
    46 	ret=smsMessaging.Open(mmPhone);
       
    47     TEST(ret==KErrNone);
       
    48 	
       
    49 	CMemTestGetSmspList* getSmspList=CMemTestGetSmspList::NewLC(smsMessaging, this);
       
    50     getSmspList->Start();
       
    51     CActiveScheduler::Start();
       
    52 	CleanupStack::PopAndDestroy();
       
    53 //	INFO_PRINTF2(_L("SmspList list retrieval OOM tests ok"));
       
    54 
       
    55 	// Test StoreBroadcastIdListL
       
    56 
       
    57 	CMobilePhoneSmspList* list = CMobilePhoneSmspList::NewL();
       
    58 	CleanupStack::PushL(list);
       
    59 
       
    60 	RMobileSmsMessaging::TMobileSmspEntryV1 entry;
       
    61 //	CTestSmsMessaging::InitSmspEntry(entry);
       
    62 	iTestSmsMessaging->InitSmspEntry(entry);
       
    63 	entry.iIndex = DMMTSY_SMSP_STORE_INDEX1;
       
    64 	list->AddEntryL(entry);
       
    65 	entry.iIndex = DMMTSY_SMSP_STORE_INDEX2;
       
    66 	list->AddEntryL(entry);
       
    67 	
       
    68 	TRequestStatus reqStatus;
       
    69 	TInt err = KErrNone;
       
    70 	TInt failNext = 0;
       
    71 	do
       
    72 		{
       
    73 		__UHEAP_FAILNEXT(++failNext);
       
    74 		TRAP(err,smsMessaging.StoreSmspListL(reqStatus,list));
       
    75 		if (err == KErrNone)
       
    76 			{
       
    77 			User::WaitForRequest(reqStatus);
       
    78 			err = reqStatus.Int();
       
    79 			}
       
    80 		TEST(err == KErrNone || err == KErrNoMemory);
       
    81 		} while (err != KErrNone);
       
    82 	__UHEAP_RESET;
       
    83 	INFO_PRINTF3(_L("Test %d - OOM test on RMobileSmsMessaging::StoreSmspListL required %d allocations to succeed"),iTestCount++,failNext);
       
    84 //	test.Next(_L("OOM test on RMobileSmsMessaging::StoreSmspListL OK"));
       
    85 	CleanupStack::PopAndDestroy();
       
    86 
       
    87 	smsMessaging.Close();
       
    88 	mmPhone.Close();
       
    89 	INFO_PRINTF1(_L(""));
       
    90 
       
    91 	return TestStepResult();
       
    92 	}
       
    93 
       
    94 /**************************************************************/
       
    95 //
       
    96 // Testing how CRetrieveMobilePhoneSmspList handles OOM
       
    97 //
       
    98 /**************************************************************/
       
    99 
       
   100 CTestMemSmsMessaging::CMemTestGetSmspList* CTestMemSmsMessaging::CMemTestGetSmspList::NewLC(RMobileSmsMessaging& aMessaging, CTestMemSmsMessaging* aTestMemSmsMessaging)
       
   101 	{
       
   102     CMemTestGetSmspList* r = new (ELeave) CMemTestGetSmspList(aMessaging, aTestMemSmsMessaging);
       
   103 	CleanupStack::PushL(r);
       
   104 	r->ConstructL();
       
   105     return r;	
       
   106 	}
       
   107 
       
   108 void CTestMemSmsMessaging::CMemTestGetSmspList::Start()
       
   109 	{
       
   110 	iFailEvery = 1;
       
   111 	StartMemTest();
       
   112 	}
       
   113 
       
   114 void CTestMemSmsMessaging::CMemTestGetSmspList::StartMemTest()
       
   115 	{
       
   116 	__UHEAP_FAILNEXT(iFailEvery);
       
   117 	CTestGetSmspList::Start();
       
   118 	}
       
   119 	
       
   120 CTestMemSmsMessaging::CMemTestGetSmspList::CMemTestGetSmspList(RMobileSmsMessaging& aMessaging, CTestMemSmsMessaging* aTestMemSmsMessaging) :
       
   121 	CTestGetSmspList(aMessaging, aTestMemSmsMessaging), iTestMemSmsMessaging(aTestMemSmsMessaging)
       
   122 	{
       
   123 
       
   124 	}
       
   125 
       
   126 void CTestMemSmsMessaging::CMemTestGetSmspList::RunL()
       
   127 	{
       
   128 	CTestGetSmspList::RunL();
       
   129 	__UHEAP_RESET;
       
   130 	iTestMemSmsMessaging->INFO_PRINTF3(_L("Test %d - CRetrieveMobilePhoneSmspList OOM Test required %d allocations to succeed"),iTestMemSmsMessaging->iTestCount++,iFailEvery);
       
   131 	}
       
   132 
       
   133 TInt CTestMemSmsMessaging::CMemTestGetSmspList::RunError(TInt aError)
       
   134 	{
       
   135 	if (aError == KErrNoMemory)
       
   136 		{
       
   137 		iFailEvery++;
       
   138 		StartMemTest();
       
   139 		return KErrNone;
       
   140 		}
       
   141 	else
       
   142 		return aError;
       
   143 	}
       
   144