messagingfw/biomsgfw/BITSTSRC/TSBIOGEN.CPP
changeset 62 db3f5fa34ec7
parent 0 8e480a14352b
equal deleted inserted replaced
60:9f5ae1728557 62:db3f5fa34ec7
       
     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 //	Test harness for CBioServerSideTestUtilities. 
       
    15 //
       
    16 //  BIO messages are created by synchronous calls....
       
    17 
       
    18 #pragma warning( disable : 4100 )
       
    19 
       
    20 //  Includes...
       
    21 #include <e32base.h>
       
    22 #include <e32std.h>
       
    23 #include <e32test.h>
       
    24 #include <e32hal.h>
       
    25 #include <e32uid.h>
       
    26 #include <msvapi.h>
       
    27 #include <msventry.h>
       
    28 #include "MSVSERV.H"
       
    29 #include <msvuids.h>
       
    30 #include <msvruids.h>
       
    31 #include <msvids.h>
       
    32 #include <f32fsys.h>
       
    33 #include <s32file.h>
       
    34 #include <barsc.h>
       
    35 #include <msvreg.h>
       
    36 
       
    37 #include <txtrich.h>				//	rich text stuff
       
    38 #include <txtfmlyr.h>				//	para format gubbins..
       
    39 
       
    40 #include <biouids.h>	// Defines for use in Bio messaging
       
    41 #include <bitsids.h>		// Uids for use in Test Harnesses
       
    42 
       
    43 #include "biotestutils.h"
       
    44 
       
    45 
       
    46 // Uncomment following define to print the details to screen
       
    47 // Difficult to view as there's so much information
       
    48 
       
    49 //#define _TBIOTEST_PRINTING_  
       
    50 
       
    51 
       
    52 #define _TBIOTEST_LOGGING_  // Commment this line to disable logging
       
    53 
       
    54 //  Constants ids.
       
    55 
       
    56 //  Classes defined/used
       
    57 class CTestScheduler;
       
    58 class CObserverTester;
       
    59 
       
    60 //  Global functions..
       
    61 //  functions()
       
    62 GLDEF_C void doMainL();
       
    63 GLDEF_C TInt E32Main();
       
    64 
       
    65 //  Resources..
       
    66 GLDEF_C RTest test(_L("BIO Message Generator Test Rig"));
       
    67 LOCAL_D CTrapCleanup*       theCleanup;
       
    68 LOCAL_D CTestScheduler*		theScheduler;
       
    69 LOCAL_D RFs                 rFs;
       
    70 
       
    71 // States for the tester
       
    72 typedef enum
       
    73     {
       
    74     EStart,
       
    75     EStop
       
    76     } TTesterState;
       
    77 
       
    78 
       
    79 //**********************************************************************************
       
    80 //
       
    81 //  CTestScheduler - Concrete active scheduler class for our test harness
       
    82 //
       
    83 //**********************************************************************************
       
    84 class CTestScheduler : public CActiveScheduler
       
    85     {
       
    86     public:
       
    87         //  inline
       
    88         void Error(TInt anError) const;
       
    89     };
       
    90 
       
    91 
       
    92 void CTestScheduler::Error(TInt anError) const
       
    93     {
       
    94     CActiveScheduler::Stop();
       
    95     test.Printf(_L("\nLeave signalled, reason=%d\n"),anError);
       
    96     }
       
    97 
       
    98 //******************************************************************************
       
    99 //
       
   100 //		CMessGeneratorTester - class declarations
       
   101 //
       
   102 //******************************************************************************
       
   103 
       
   104 class CServerSideMsgGeneratorTester : public CActive
       
   105     {
       
   106     //  public API
       
   107     public:
       
   108         static CServerSideMsgGeneratorTester * NewL();
       
   109         static CServerSideMsgGeneratorTester * NewLC();
       
   110         ~CServerSideMsgGeneratorTester ();
       
   111 
       
   112 		//	Starts everything off
       
   113 		void StartL();
       
   114 		//  Sets the active scheduler going
       
   115         void QueueOperationAsync(TInt aErr);
       
   116     
       
   117 
       
   118     protected:
       
   119         CServerSideMsgGeneratorTester ();
       
   120         void ConstructL();
       
   121         
       
   122 		void InitialiseTesterL();
       
   123 
       
   124     private:    // Active Object functions
       
   125         void DoCancel();
       
   126         void RunL();
       
   127 
       
   128     private:
       
   129         //  Resources
       
   130 		CBioTestUtils*				iBIOGenerator;
       
   131         //  Entry, Entry Selection, message details..
       
   132         CMsvEntrySelection*			iSelection;
       
   133 
       
   134 		TBIOMessageType				iCurrentMessageType;
       
   135 		
       
   136 		//  States   
       
   137 		TTesterState				iState;
       
   138         //  Service Ids
       
   139         TMsvId                      iBIOServiceId;
       
   140     };
       
   141 
       
   142 
       
   143 
       
   144 //
       
   145 //																				//
       
   146 //  Implementation of the CMessGeneratorTester test harness...					//
       
   147 //																				//
       
   148 //
       
   149 
       
   150 CServerSideMsgGeneratorTester* CServerSideMsgGeneratorTester::NewL()
       
   151     {
       
   152     CServerSideMsgGeneratorTester* self = CServerSideMsgGeneratorTester::NewLC();
       
   153     CleanupStack::Pop();
       
   154     return self;
       
   155     }
       
   156 
       
   157 CServerSideMsgGeneratorTester* CServerSideMsgGeneratorTester::NewLC()
       
   158     {
       
   159     CServerSideMsgGeneratorTester* self = new (ELeave) CServerSideMsgGeneratorTester();
       
   160     CleanupStack::PushL(self);
       
   161     self->ConstructL();
       
   162     return self;
       
   163     }
       
   164 
       
   165 CServerSideMsgGeneratorTester::CServerSideMsgGeneratorTester()
       
   166 : CActive(EPriorityNormal)
       
   167     {
       
   168     }
       
   169 
       
   170 CServerSideMsgGeneratorTester::~CServerSideMsgGeneratorTester()
       
   171     {
       
   172 	// NB don't delete the Logger or Printer objects because this object doesn't own them
       
   173 	Cancel();
       
   174 	//
       
   175     delete iSelection;
       
   176 	//
       
   177 	delete iBIOGenerator;
       
   178     }
       
   179 
       
   180 void CServerSideMsgGeneratorTester::ConstructL()
       
   181     {
       
   182 	// Create the SMS Test Message Utility object
       
   183 	iBIOGenerator = CBioTestUtils::NewL(test);
       
   184 	iBIOGenerator->GoServerSideL();
       
   185 
       
   186 //	Add ourselves to the active scheduler
       
   187 //   User::LeaveIfError(iTimer.CreateLocal());
       
   188     CActiveScheduler::Add(this);
       
   189 	}
       
   190 
       
   191 //
       
   192 //																					//
       
   193 //						StartL - sets the tester going								//
       
   194 //																					//
       
   195 //
       
   196 
       
   197 void CServerSideMsgGeneratorTester::StartL()
       
   198 	{
       
   199     // Set the Scheduler going so we go to our RunL().
       
   200 	iState=EStart;
       
   201     QueueOperationAsync(KErrNone);
       
   202 	}
       
   203 
       
   204 
       
   205 //
       
   206 //																				//
       
   207 //						Tester's Active Object Stuff							//
       
   208 //																				//
       
   209 //
       
   210 
       
   211 void CServerSideMsgGeneratorTester::RunL()
       
   212     {
       
   213     TInt err = iStatus.Int();
       
   214 
       
   215     if(err != KErrNone)
       
   216         {
       
   217         CActiveScheduler::Stop();
       
   218         }
       
   219     switch(iState)
       
   220         {
       
   221 		case EStart:   
       
   222 			iState = EStop;
       
   223 			InitialiseTesterL();
       
   224             break;
       
   225 		case EStop:
       
   226 			CActiveScheduler::Stop();
       
   227             break;
       
   228         }
       
   229     }
       
   230 
       
   231 void CServerSideMsgGeneratorTester::DoCancel()
       
   232     {
       
   233     }
       
   234 
       
   235 void CServerSideMsgGeneratorTester::QueueOperationAsync(TInt aErr)
       
   236     {
       
   237     TRequestStatus*  pS = &iStatus;
       
   238 	iStatus = KRequestPending;
       
   239     User::RequestComplete(pS, aErr);
       
   240 	SetActive();
       
   241     }
       
   242 
       
   243 void CServerSideMsgGeneratorTester::InitialiseTesterL()
       
   244 	{
       
   245 	// Get the NB if we don't need this two step process, use SetSmsServiceL().
       
   246 	//iBIOGenerator->SetSmsServiceIdL();
       
   247 	iBIOGenerator->SetBIOServiceIdL();
       
   248 	// Empty the Inbox
       
   249 	iBIOGenerator->EmptyInboxMessagesL();
       
   250 	iSelection = iBIOGenerator->GenerateMessagesL();
       
   251 	QueueOperationAsync(KErrNone);
       
   252 	}
       
   253 
       
   254 
       
   255 
       
   256 //*****************************************************************************
       
   257 //
       
   258 //  Implementation; global stuff
       
   259 //
       
   260 //*****************************************************************************
       
   261 
       
   262 GLDEF_C TInt E32Main()
       
   263     {
       
   264 	__UHEAP_MARK;
       
   265 	theCleanup = CTrapCleanup::New();
       
   266 	TRAPD(err,doMainL());		
       
   267 	test(err==KErrNone);
       
   268 	delete theCleanup;	
       
   269 	test.End();
       
   270 	test.Close();
       
   271 	__UHEAP_MARKEND;
       
   272 	return(KErrNone);
       
   273     }
       
   274 
       
   275 GLDEF_C void doMainL()
       
   276     {
       
   277 	// Create an active scheduler for the program session
       
   278     theScheduler = new (ELeave) CTestScheduler();
       
   279     CleanupStack::PushL(theScheduler);
       
   280     CActiveScheduler::Install(theScheduler);
       
   281     test.Title();
       
   282     test.Start(_L("Starting test harness"));
       
   283     rFs.Connect();
       
   284     //  Can't actually lock a message client side
       
   285     CServerSideMsgGeneratorTester* theTester = 
       
   286 						CServerSideMsgGeneratorTester::NewLC(); //  release context on create 
       
   287 	theTester->StartL();
       
   288 	CActiveScheduler::Start();
       
   289     CleanupStack::PopAndDestroy(); //theTester
       
   290     CleanupStack::PopAndDestroy(); //theScheduler
       
   291 	rFs.Close();
       
   292     }
       
   293 
       
   294