messagingfw/msgtest/integration/sms/src/t_sms.cpp
changeset 0 8e480a14352b
equal deleted inserted replaced
-1:000000000000 0:8e480a14352b
       
     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 // GT Messaging Test Harness T_SMS
       
    15 // Test Harness: T_SMS
       
    16 // Component: SMS
       
    17 // Owner: AA
       
    18 // Brief Description: GT Messaging SMS Smoke Test
       
    19 // Detailed Description: Tests
       
    20 // - SMS Client MTM
       
    21 // - SMS utility classes (CSmsHeader, CSmsNumber, CSmsSettings, TSmsUtilities)
       
    22 // - Reading and writing Service Centres on the SIM
       
    23 // - Reading and writing messages to the SIM
       
    24 // - Sending and receiving messages
       
    25 // Input Files REQUIRED:
       
    26 // <DRIVE>:\msgtest\sms\defaults.script
       
    27 // <DRIVE>:\msgtest\sms\smoke_recv.script
       
    28 // <DRIVE>:\msgtest\sms\smoke_enum.script
       
    29 // Intermediate Files Produced: None
       
    30 // Output files produced: <DRIVE>:\msglogs\T_Sms.<PLATFORM>.<VARIANT>.log
       
    31 // Building Instructions:
       
    32 // cd \msg\test\smoke\
       
    33 // bldmake bldfiles
       
    34 // abld test build
       
    35 // Running Instructions:
       
    36 // All Platforms:
       
    37 // 1. Build T_DB test harness from COMMDB component:
       
    38 // cd \commdb\group
       
    39 // bldmake bldfiles
       
    40 // abld test build t_db
       
    41 // 2. Run T_DB and select the your modem (probably GSM Mobile Phone)
       
    42 // 3. Build the test utilities:
       
    43 // cd \msg\testutils\group\
       
    44 // bldmake bldfiles
       
    45 // abld test build
       
    46 // 4. Edit \epoc32\wins\c\msgtest\sms\defaults.script. Replace the telephone number ("Recipients") with your mobile's number. You may also need to change the service centre ("SC") number (the default is for Vodafone UK).
       
    47 // WINS Only:
       
    48 // 1. Run T_DB.exe (if it has not already been run) and select your modem (GSM mobile phone).
       
    49 // 2. \epoc32\release\wins\<VARIANT>\T_Sms.exe can be used at the command prompt or executable can be run from Windows Explorer.
       
    50 // Platform other than WINS:
       
    51 // 1. Copy \epoc32\release\<PLATFORM>\<VARIANT>\T_Sms.exe onto the other platform (or onto the CF card)
       
    52 // 2. Copy \epoc32\release\<PLATFORM>\<VARIANT>\T_DB.exe onto the other platform (or onto the CF card)
       
    53 // 3. Copy \epoc32\release\<PLATFORM>\<VARIANT>\MsvTestUtils.DLL into <DRIVE>:\system\libs on the other platform (or onto the CF card)
       
    54 // 4. Copy \epoc32\release\<PLATFORM>\<VARIANT>\SmsTestUtils.DLL into <DRIVE>:\system\libs on the other platform (or onto the CF card)
       
    55 // 5. Copy \epoc32\wins\c\msgtest\sms\smoke_recv.script, smoke_enum.script and defaults.script into <DRIVE>:\msgtest\sms on the other platform (or onto the CF card)
       
    56 // 6. Run T_DB.exe on the other platform (if it has not already been run) and select your modem (GSM mobile phone).
       
    57 // 7. Run T_Sms.exe on the other platform.
       
    58 // 
       
    59 //
       
    60 
       
    61 #include <e32test.h>
       
    62 #include <e32uid.h>
       
    63 #include <e32std.h>
       
    64 
       
    65 #include <barsc.h>
       
    66 #include <smsuaddr.h>
       
    67 
       
    68 // Test code header files
       
    69 #include "T_SmsEnum.h"
       
    70 #include "T_smcm.h"
       
    71 #include "T_SmsSc.h"
       
    72 #include "T_SmsSendRecv.h"
       
    73 
       
    74 RTest test(_L("T_Sms Smokin' Testrig"));
       
    75 CTrapCleanup* theCleanup;
       
    76 
       
    77 _LIT(KSmsEnumTest, "smoke_enum.script");
       
    78 _LIT(KSmsRecvTest, "smoke_recv.script");
       
    79 _LIT(KBetweenTests, "############################################################\n");
       
    80 
       
    81 const TInt KWaitForWatchersToStart = 15000000; //10 secs
       
    82 
       
    83 LOCAL_C void PrintTestStart(CSmsTestBase& aTestBase)
       
    84 	{
       
    85 	TPtrC name(aTestBase.TestName());
       
    86 	aTestBase.SmsTest().Printf(KBetweenTests);
       
    87 	aTestBase.SmsTest().Printf(_L("Starting %S Test\n"), &name);
       
    88 	aTestBase.SmsTest().Printf(KBetweenTests);
       
    89 	}
       
    90 
       
    91 LOCAL_C void PrintTestFail(CSmsTestBase& aTestBase)
       
    92 	{
       
    93 	TPtrC name(aTestBase.TestName());
       
    94 	aTestBase.SmsTest().Printf(KBetweenTests);
       
    95 	aTestBase.SmsTest().Printf(_L("%S Test Failed with %d\n"), &name, aTestBase.Error());
       
    96 	aTestBase.SmsTest().Printf(KBetweenTests);
       
    97 	}
       
    98 
       
    99 LOCAL_C void StartAndVerifyTestCompleteL(CSmsTestBase& aTestBase)
       
   100 	{
       
   101 	PrintTestStart(aTestBase);
       
   102 	aTestBase.StartL();
       
   103 	if (!aTestBase.Complete())
       
   104 		{
       
   105 		PrintTestFail(aTestBase);
       
   106 		User::Leave(aTestBase.Error());
       
   107 		}
       
   108 	}
       
   109 
       
   110 LOCAL_C void doMainL()
       
   111 	{
       
   112 	// Open the socket server
       
   113 
       
   114 	RSocketServ serv;
       
   115 	RSocket socket;
       
   116 
       
   117 	User::LeaveIfError(serv.Connect());
       
   118 	CleanupClosePushL(serv);
       
   119 	
       
   120 	TProtocolDesc protoinfo;
       
   121 	TProtocolName protocolname(KSmsDatagram);
       
   122 	User::LeaveIfError(serv.FindProtocol(protocolname,protoinfo));
       
   123 	User::LeaveIfError(socket.Open(serv,protoinfo.iAddrFamily,protoinfo.iSockType,protoinfo.iProtocol));
       
   124 
       
   125 	TSmsAddr smsaddr;
       
   126 	smsaddr.SetSmsAddrFamily(ESmsAddrSendOnly);
       
   127 	User::LeaveIfError(socket.Bind(smsaddr));
       
   128 
       
   129 	CleanupClosePushL(socket);
       
   130 
       
   131 	CActiveScheduler* scheduler = new (ELeave) CActiveScheduler;
       
   132 	CleanupStack::PushL(scheduler);
       
   133 	CActiveScheduler::Install( scheduler );
       
   134 
       
   135 	CSmsTestUtils* smsTest = CSmsTestUtils::NewLC(test);
       
   136 	smsTest->iSmokeTest = ETrue;
       
   137 
       
   138 	TInt currentTest = 0;
       
   139 
       
   140 	smsTest->NotifySaPhoneOnL();
       
   141 	smsTest->WaitForInitializeL();
       
   142 
       
   143 	//Start the watchers
       
   144 	CMsvOperationWait* wait = CMsvOperationWait::NewLC();
       
   145 	smsTest->Printf(_L("Waiting %d secs for watchers to start\n"), KWaitForWatchersToStart / 1000000); 
       
   146 	CTestUtilsWatcherStarter* watchers = CTestUtilsWatcherStarter::NewL(wait->iStatus, KWaitForWatchersToStart);
       
   147 	wait->Start();
       
   148 	CActiveScheduler::Start();
       
   149 	CleanupStack::PopAndDestroy(wait);
       
   150 	CleanupStack::PushL(watchers);
       
   151 
       
   152 	CSmsTestBase* testBase = CSmsScTest::NewLC(*smsTest, KNullDesC, currentTest);
       
   153 	StartAndVerifyTestCompleteL(*testBase);
       
   154 	CleanupStack::PopAndDestroy(testBase);
       
   155 	
       
   156 	testBase = CSmsEnumTest::NewLC(*smsTest, KSmsEnumTest, currentTest);
       
   157 	StartAndVerifyTestCompleteL(*testBase);
       
   158 	CleanupStack::PopAndDestroy(testBase);
       
   159 
       
   160 	testBase = CSmsSendRecvTest::NewLC(*smsTest, KSmsRecvTest, currentTest);
       
   161 	StartAndVerifyTestCompleteL(*testBase);
       
   162 	CleanupStack::PopAndDestroy(testBase);
       
   163 	
       
   164 	testBase = CSmcmTest::NewLC(*smsTest, KNullDesC, currentTest);
       
   165 	StartAndVerifyTestCompleteL(*testBase);
       
   166 	CleanupStack::PopAndDestroy(testBase);
       
   167 	
       
   168 	testBase = CSmutTest::NewLC(*smsTest, KNullDesC, currentTest);
       
   169 	StartAndVerifyTestCompleteL(*testBase);
       
   170 	CleanupStack::PopAndDestroy(testBase);
       
   171 
       
   172 	CleanupStack::PopAndDestroy(3); //SmsTest, scheduler, watchers
       
   173 
       
   174 	CleanupStack::PopAndDestroy(&socket);
       
   175 	CleanupStack::PopAndDestroy(&serv);
       
   176 	}
       
   177 
       
   178 GLDEF_C TInt E32Main()
       
   179 	{	
       
   180 	__UHEAP_MARK;
       
   181 	test.Start(_L("Setup"));
       
   182 	theCleanup = CTrapCleanup::New();
       
   183 	TRAPD(ret,doMainL());		
       
   184 //	test(ret==KErrNone);
       
   185 	delete theCleanup;	
       
   186 	test.Console()->SetPos(0, 13);
       
   187 	test.End();
       
   188 	test.Close();
       
   189 	__UHEAP_MARKEND;
       
   190 	return(KErrNone);
       
   191 	}