messagingfw/scheduledsendmtm/test/unit/src/t_schsendexe.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     1 // Copyright (c) 1999-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 "t_schsendexe.h"
       
    17 #include <msvids.h>
       
    18 #include <msvuids.h>
       
    19 
       
    20 CTrapCleanup* theCleanup;
       
    21 
       
    22 void doMainL(RTest& aTest)
       
    23 	{
       
    24 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
       
    25 	CleanupStack::PushL(scheduler);
       
    26 	CActiveScheduler::Install( scheduler );
       
    27 
       
    28 	CSchSendExeTest* schSendTest = CSchSendExeTest::NewL(aTest);
       
    29 	CleanupStack::PushL(schSendTest);
       
    30 
       
    31 	schSendTest->StartL();
       
    32 
       
    33 	CleanupStack::PopAndDestroy(2); //schSendTest, scheduler
       
    34 
       
    35 	aTest.Printf(_L("\nWaiting 5 seconds before closing...\n"));
       
    36 	User::After(5000000);
       
    37 	}
       
    38 
       
    39 GLDEF_C TInt E32Main()
       
    40 	{
       
    41 	RTest test(_L("Scheduled Sending Test Harness"));
       
    42 	__UHEAP_MARK;
       
    43 	test.Title();
       
    44 	test.Start(_L("Scheduled Sending Test Harness"));
       
    45 	theCleanup = CTrapCleanup::New();
       
    46 	test(theCleanup !=NULL);
       
    47 	TRAPD(error,doMainL(test));
       
    48 	test(error==KErrNone);
       
    49 	delete theCleanup;
       
    50 	test.Printf(_L("Completed with return code %d"),error);
       
    51 	test.End();
       
    52 	test.Close();
       
    53 	__UHEAP_MARKEND;
       
    54 	return KErrNone;
       
    55 	}
       
    56 
       
    57 CSchSendExeTest* CSchSendExeTest::NewL(RTest& aTest)
       
    58 	{
       
    59 	CSchSendExeTest* self = new (ELeave) CSchSendExeTest(aTest);
       
    60 	CleanupStack::PushL(self);
       
    61 	self->ConstructL();
       
    62 	CleanupStack::Pop(); //self
       
    63 	return self;
       
    64 	}
       
    65 
       
    66 CSchSendExeTest::CSchSendExeTest(RTest& aTest)
       
    67 : CSchSendTestUtils(aTest)
       
    68 	{
       
    69 	}
       
    70 
       
    71 void CSchSendExeTest::ShowMenuL()
       
    72 	{
       
    73 	RunAutoL();
       
    74 	}
       
    75 
       
    76 CSchSendExeTest::~CSchSendExeTest()
       
    77 	{
       
    78 	}
       
    79 
       
    80 void CSchSendExeTest::RunAutoL()
       
    81 	{
       
    82 	TInt nextTest = 0;
       
    83 	TestStart(++nextTest, _L("Operation Fail"));
       
    84 	TestOperationFailureL();
       
    85 	TestFinish(nextTest, KErrNone);
       
    86 
       
    87 // DEF051316
       
    88 	}
       
    89 
       
    90 void CSchSendExeTest::TestOperationFailureL()
       
    91 	{
       
    92 	Printf(_L("TestOperationFailure\n"));
       
    93 	TTime now;
       
    94 	now.HomeTime();
       
    95 	TMsvEntry entry;
       
    96 	CreateMessageLC(entry, KMsvGlobalOutBoxIndexEntryId, now);
       
    97 
       
    98 	iSelection->Reset();
       
    99 	iSelection->AppendL(entry.Id());
       
   100 
       
   101 	const TInt KTestOpFailError = -111;
       
   102 	TPckgBuf<TInt> pkg(KTestOpFailError);
       
   103 	iSchTestActive->TransferCommandSyncL(EScheduleOpFail, *iSelection, pkg, ETrue);
       
   104 
       
   105 	CSchSendTestWaitForState* wait = CSchSendTestWaitForState::NewL(*this);
       
   106 	CleanupStack::PushL(wait);
       
   107 
       
   108 	wait->Reset();
       
   109 	wait->AppendL(KMsvSendStateResend);
       
   110 	wait->StartL(*iSelection, 1000000 * 60 * 4); //4 mins
       
   111 
       
   112 	SetEntryL(entry.Id());
       
   113 	entry = Entry();
       
   114 	iRTest(entry.iError == KTestOpFailError);
       
   115 
       
   116 	Printf(_L("Wait completed with %d\n"), wait->iStatus.Int());
       
   117 	iRTest(wait->iStatus.Int() == KErrNone);
       
   118 
       
   119 	CleanupStack::PopAndDestroy(wait);
       
   120 	CleanupStack::PopAndDestroy(); //message
       
   121 	}
       
   122 
       
   123 void CSchSendExeTest::TestSessionFailureL()
       
   124 	{
       
   125 	Printf(_L("TestSessionFailure\n"));
       
   126 	TTime now;
       
   127 	now.HomeTime();
       
   128 	TMsvEntry entry;
       
   129 	CreateMessageLC(entry, KMsvGlobalOutBoxIndexEntryId, now);
       
   130 
       
   131 	iSelection->Reset();
       
   132 	iSelection->AppendL(entry.Id());
       
   133 
       
   134 	// create a semaphore that causes CMsvSession construction to fail
       
   135 	RSemaphore moving;
       
   136 	User::LeaveIfError(moving.CreateGlobal(KMsvMovingSemaphore,0));
       
   137 	CleanupClosePushL(moving);
       
   138 
       
   139 	iSchTestActive->TransferCommandSyncL(EScheduleAllL, *iSelection, ETrue);
       
   140 
       
   141 	CSchSendTestWaitForState* wait = CSchSendTestWaitForState::NewL(*this);
       
   142 	CleanupStack::PushL(wait);
       
   143 
       
   144 	Printf(_L("Waiting %d secs to check message scheduled\n"), 5);
       
   145 	wait->AppendL(KMsvSendStateScheduled);
       
   146 	wait->StartL(*iSelection, 1000000 * 5); //5 secs
       
   147 
       
   148 	Printf(_L("Wait completed with %d\n"), wait->iStatus.Int());
       
   149 	iRTest(wait->iStatus.Int() == KErrNone);
       
   150 
       
   151 	Printf(_L("Closing Move Semaphore\n"));
       
   152 	Printf(_L("Waiting %d secs for message to send\n"), 60 * 2);
       
   153 	moving.Close();
       
   154 	wait->Reset();
       
   155 	wait->AppendL(KMsvSendStateSent);
       
   156 	wait->StartL(*iSelection, 1000000 * 60 * 2); //2 mins
       
   157 
       
   158 	Printf(_L("Wait completed with %d\n"), wait->iStatus.Int());
       
   159 	iRTest(wait->iStatus.Int() == KErrNone);
       
   160 
       
   161 	CleanupStack::PopAndDestroy(wait);
       
   162 	CleanupStack::Pop(); //moving
       
   163 	CleanupStack::PopAndDestroy(); //message
       
   164 	}
       
   165 
       
   166