cbsref/csyrefplugins/csy27010/test/unit_test_base/unitTestBase.h
branchRCL_3
changeset 65 630d2f34d719
equal deleted inserted replaced
61:17af172ffa5f 65:630d2f34d719
       
     1 //
       
     2 // * Copyright 2004 Neusoft America Inc.
       
     3 // * All rights reserved.
       
     4 // * This component and the accompanying materials are made available
       
     5 // * under the terms of the Eclipse Public License v1.0
       
     6 // * which accompanies this distribution, and is available
       
     7 // * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 // *
       
     9 // * Contributors:
       
    10 // * Keith Collins (Neusoft America Inc.)  original software development and additional code and modifications.
       
    11 // * Thomas Gahagen (Neusoft America Inc.)  additional code and modifications.
       
    12 // * Zhen Yuan (Neusoft America Inc.)  additional code and modifications.
       
    13 // *
       
    14 // * Description:  This file contains the defintion for the base class from 
       
    15 // *               which all unit test classes are derived.
       
    16 //
       
    17 
       
    18 // UnitTestBase.h
       
    19 
       
    20 /** @file UnitTestBase.h
       
    21  *
       
    22  */
       
    23 
       
    24 #ifndef UNITTESTBASE_H__
       
    25 #define UNITTESTBASE_H__
       
    26 
       
    27 #include <e32base.h>
       
    28 #include <e32test.h>
       
    29 #include <c32comm.h>
       
    30 #include "f32file.h"
       
    31 //#include "inifile.h"
       
    32 
       
    33 #include <etel.h>
       
    34 #include <etelmm.h>
       
    35 
       
    36 //#include "Constants.h"
       
    37 
       
    38 //comment out this line if both passed & failed tests
       
    39 //are to be logged in the test log file, reftsyTest.txt
       
    40 //#define LOG_FAILED_TESTS_ONLY
       
    41 
       
    42 #define TEST(AAA) {TInt XXX = (AAA); if (XXX) return (__LINE__);}
       
    43 
       
    44 //_LIT(KCsyName, "ECUART.CSY");
       
    45 _LIT(KCsyName, "GSM0710.CSY");
       
    46 //_LIT(KTsyName,    "phonetsy");
       
    47 _LIT(KTsyName,    "GSM0707");
       
    48 
       
    49 _LIT(KTestSessionPath, "c:\\Logs\\Tests\\");
       
    50 _LIT(KUnitTestSpec, "UTS;");
       
    51 _LIT(KAccTestSpec, "ATS;");
       
    52 _LIT(KAutoTestMarker, "AUTO;");
       
    53 _LIT(KPassed, "PASSED;");
       
    54 _LIT(KFailed, "FAILED;");
       
    55 _LIT(KZeroPadding, "0");
       
    56 _LIT(KHyphen,"-");
       
    57 _LIT(KSemiColon,";");
       
    58 _LIT(KColon, ":");
       
    59 _LIT(KNewLine, "\r\n");
       
    60 
       
    61 const TUint KTsyTesterSetupTime = 3000000;
       
    62 const TUint KTsyTestCompleteTime = 3000000;
       
    63 const TUint KBufSize1 = 1;
       
    64 const TUint KBufSize4 = 4;
       
    65 const TUint KBufSize25 = 25;
       
    66 const TUint KBufSize10 = 10;
       
    67 const TUint KBufSize100 = 100;
       
    68 const TUint KZeroPadValue = 10;
       
    69 const TUint KMaxTestTelNumberSize = 20;
       
    70 
       
    71 // BttTest.Ini constants
       
    72 _LIT(KIniFile, "CommPTest.INI");
       
    73 _LIT(KIniSection, "PhoneNumberList");
       
    74 _LIT(KIniSection2, "Sms");
       
    75 _LIT(KIniSection3, "GeneralSettings");
       
    76 _LIT(KIniTelNumConnect1, "TelNumConnect1");
       
    77 _LIT(KIniTelNumConnect2, "TelNumConnect2");
       
    78 _LIT(KIniTelNumConnect3, "TelNumConnect3");
       
    79 _LIT(KIniTelNumConnect4, "TelNumConnect4");
       
    80 _LIT(KIniTelNumConnect5, "TelNumConnect5");
       
    81 _LIT(KIniTelNumConnect6, "TelNumConnect6");
       
    82 _LIT(KIniTelNumConnect7, "TelNumConnect7");
       
    83 _LIT(KIniTelNumDataConnect, "TelNumDataConnect");
       
    84 _LIT(KIniTelNumNeverConnect, "TelNumNeverConnect");
       
    85 _LIT(KIniTelNumRejectCall, "TelNumRejectCall");
       
    86 _LIT(KIniTelNumRemoteEndHangUp, "TelNumRemoteEndHangUp");
       
    87 _LIT(KIniTelNumIncorrect1, "TelNumIncorrect1");
       
    88 _LIT(KIniTelNumIncorrect2, "TelNumIncorrect2");
       
    89 _LIT(KIniTelNumMobile1, "TelNumMobile1");
       
    90 _LIT(KIniTelNumDTMFTest, "TelNumDTMFTest");
       
    91 _LIT(KIniTelNumCallback, "TelNumCallbackService");
       
    92 _LIT(KIniTelNumDataServer1, "TelNumDataServer1");
       
    93 _LIT(KIniTelNumDataServer2, "TelNumDataServer2");
       
    94 _LIT(KIniTelNumDataServer3, "TelNumDataServer3");
       
    95 _LIT(KIniTelNumDataServer4, "TelNumDataServer4");
       
    96 _LIT(KIniSmsDestNumber, "SmsDestNumber");
       
    97 _LIT(KIniTelNumberInMadCow, "SimTelNumberInMadCow");
       
    98 _LIT(KIniSmsNetworkName, "SmsNetworkName");
       
    99 _LIT(KIniTypeOfTest, "TypeOfTest");
       
   100 _LIT(KIniKeepPhoneOpen, "KeepPhoneOpen");
       
   101 _LIT(KIniAutoRepeatFailedTests, "AutoRepeatFailedTests");
       
   102 _LIT(KIniTypeOfNumber1, "DestNumberIs44Format");
       
   103 _LIT(KIniTypeOfNumber2, "MadCowNumberIs44Format");
       
   104 
       
   105 // Moved from phone
       
   106 const TUint KDelayLong   = 10000000;
       
   107 const TUint KDelayMedium = 1000000;
       
   108 const TUint KDelayShort  = 100000;
       
   109 
       
   110 //const TUint KOneSecond = 1000000;
       
   111 const TUint KTwoSeconds = 2000000;
       
   112 const TUint KFiveSeconds = 5000000;
       
   113 const TUint KTenSeconds = 10000000;
       
   114 const TUint KTwentySeconds = 20000000;
       
   115 
       
   116 #define KEightSeconds TTimeIntervalMicroSeconds32(8000000)
       
   117 
       
   118 #if defined (__WINS__)
       
   119 #define PDD_NAME _L("ECDRV")
       
   120 #define LDD_NAME _L("ECOMM")
       
   121 #else  // __GCC32__
       
   122 #define PDD_SIR_NAME _L("ESIR")
       
   123 #define PDD_UART_NAME _L("ECUART4")
       
   124 #define LDD_NAME _L("ECOMM")
       
   125 #endif
       
   126 
       
   127 const TInt KErrWrongValue=KErrGeneral;
       
   128 
       
   129 //Network Name
       
   130 //Size of text string must be less than
       
   131 //12 for the  Cellnet and Vodafone test SIM
       
   132 //10 for the  Orange test SIM
       
   133 //8  for the  One-2-One  test SIM
       
   134 //for the SMSP list storage test to pass.
       
   135 const TUint KMaxSimNameLen = 12;
       
   136 
       
   137 class CUnitTestBase : public CBase
       
   138 	{
       
   139 public:
       
   140 	enum TTestMode
       
   141 		{
       
   142 		EBatch,
       
   143 		EInteractive
       
   144 		};
       
   145 
       
   146 	enum TTestPhoneNumbers
       
   147 		{
       
   148 		ETelNumConnect1,
       
   149 		ETelNumConnect2,
       
   150 		ETelNumConnect3,
       
   151 		ETelNumConnect4,
       
   152 		ETelNumConnect5,
       
   153 		ETelNumConnect6,
       
   154 		ETelNumConnect7,
       
   155 		ETelNumDataConnect,
       
   156 		ETelNumNeverConnect,
       
   157 		ETelNumRejectCall,
       
   158 		ETelNumIncorrect1,
       
   159 		ETelNumIncorrect2,
       
   160 		ETelNumDTMFTest,
       
   161 		ETelNumCallbackService,
       
   162 		ETelNumDataServer1,
       
   163 		ETelNumDataServer2,
       
   164 		ETelNumDataServer3,
       
   165 		ETelNumDataServer4,
       
   166 		ESmsDestNumber,
       
   167 		ETelNumberInMadCow,
       
   168 		ESmsNetworkName,
       
   169 		ETypeOfTest
       
   170 		};
       
   171 
       
   172 //	virtual static void CreateTestL()=0;//not allowed in C++!!
       
   173 	~CUnitTestBase();
       
   174 
       
   175 	inline RTest Test() const;
       
   176 
       
   177 	//These functions are called within CreateTestL() which is a
       
   178 	//static member function of CUnitTestBase derived classes.
       
   179 	//Every derived class must implement CreateTestL() as it
       
   180 	//first calls NewL() to instantiate the derived class before
       
   181 	//calling SetUpTest() and RunUnitTestsL().
       
   182 	//CreateTestL() is called in E32Main() which should be in the file
       
   183     //containing the CUnitTestBase derived class implementation
       
   184 	//Please look at the SMS test code for an example on how to
       
   185 	//code up E32main() and CreateTestL()
       
   186 	virtual TInt SetUpTest();    //load drivers & start C32
       
   187 	void RunUnitTestsL();
       
   188 
       
   189 	//Helper Functions
       
   190 	TInt CompareTestResult(TInt aExpectedResult,TRequestStatus aStatus);
       
   191 
       
   192 	//For running more than one at once
       
   193 	void ResizeConsoleL(const TDesC& aName, TInt aXOrg, TInt aYOrg, TInt aXSize, TInt aYSize);
       
   194 
       
   195 	//For test result logging
       
   196 	//Setters to be called by derived classes within their specific tests
       
   197 	inline void SetTsIdentifier(const TName& aTsIdentifier);
       
   198 	inline void SetMethodName(const TName& aMethodName);
       
   199 	inline void SetFunIndex(TUint aFunIndex);
       
   200 	void SetFunIndex2(TUint aFunIndex1,TUint aFunIndex2);
       
   201 	void SetFunIndex3(TUint aFunIndex1,TUint aFunIndex2,
       
   202 		              TUint aFunIndex3);
       
   203 	void SetFunIndex4(TUint aFunIndex1,TUint aFunIndex2,
       
   204 		              TUint aFunIndex3,TUint aFunIndex4);
       
   205 
       
   206 	// These three made public for the acceptance tests
       
   207 	TInt  LoadComms();
       
   208 	TInt  UnloadComms();
       
   209 	TBool DoSingleTestL(TInt aMethodNum, TInt aTestNum, TTestMode aTestMode);
       
   210 
       
   211 protected:
       
   212 	CUnitTestBase(const TDesC& aUnitTestName,const TDesC& aLogFileName,
       
   213 				  const TDesC& aTestSpecName,const TDesC& aTestScriptName);
       
   214 	void ConstructL();
       
   215 
       
   216 	TInt GetRequestOrTimeOut(TRequestStatus& aRequestStatus,
       
   217 		TTimeIntervalMicroSeconds32 aTimeOut);
       
   218 
       
   219 	//Derived classes must implement this function
       
   220 	//which is just simply a switch statement to
       
   221 	//run their specific tests according to API and test numbers
       
   222 	virtual void RunTestsL(TBool aEndInd,TTestMode aTestMode,
       
   223 						   TInt& aErrCode, TInt& aLeaveCode,
       
   224 		                   TInt aApiNumber,TInt aTestNumber)=0;
       
   225 	//this function is to be called within RunTestsL() in the default case
       
   226 	//of the switch statement
       
   227 	void ActionNoMatch(TBool aEndInd,TTestMode aTestMode,
       
   228 					   TInt aApiNumber,TInt aTestNumber);
       
   229 
       
   230 	// overload this function if you want to show what test is what number
       
   231 	virtual void PrintTestSpecIdentifiers();
       
   232 	// overload this function to show detail of the tests
       
   233 	virtual void PrintTestDetails(TInt aTstSpecNumber);
       
   234 
       
   235 	// Should the base class automatically connect to the Etel server. Overload if not
       
   236 	virtual TBool HasTestRangesDefined();
       
   237 
       
   238 	void RequestIncomingCallL(RMobileCall& aCall);
       
   239 	TBool DoTestsL();
       
   240 
       
   241 protected:
       
   242 	virtual TInt PostTestDelayTime();     ///< configurable delay time after each test
       
   243 	inline void LeaveIfPhoneAlreadyOpenL();
       
   244 
       
   245 private:
       
   246 	void GetCompilationDate(TInt& aDay, TInt& aMonth, TInt& aYear);
       
   247 	void EnsureTargetDeviceClockIsSet();  ///< prompt user for date if Assabet clock not set
       
   248 	void ReadStr(TDes& aDes);
       
   249 
       
   250 	TBool DoAutoMethodsL();
       
   251 	TBool DoAutoMethodTestsL(TInt aMethodNum);
       
   252 	TBool DoTestsInSpecifiedRangeL(TInt aStartMethodNum,
       
   253 									TInt aStartTestNum,
       
   254 									TInt aEndMethodNum,
       
   255 									TInt aEndTestNum);
       
   256 
       
   257 	//DoTestsL() calls SelectTestL(), RunTestsL() and LogTestResult()
       
   258 
       
   259 	TBool SelectTestL(TInt& aApiNum,TInt& aTestNum,
       
   260 						TInt& aEndApiNum, TInt& aEndTestNum,
       
   261 						TTestMode& aTestMode, TBool& aExit);
       
   262 
       
   263 	//These functions are called within SelectTestL()
       
   264 	TInt  UserChoice(TChar aNumberKey);
       
   265 	TBool UserSelectionL(TChar aMainNumber,
       
   266 						TInt aNumMethods,
       
   267 						TBool aRangeSpecified,
       
   268 						TInt& aApiNum, TInt& aTestNum,
       
   269 						TTestMode& aTestMode);
       
   270 
       
   271 
       
   272 
       
   273 
       
   274 	//process command line params
       
   275 	TBool CommandLineL(TInt& aApiNum, TInt& aTestNum,
       
   276 						TInt& aEndApiNum, TInt& aEndTestNum);
       
   277 
       
   278 	void LogTestResult(TInt aErrCode, TInt aLeaveCode, TBool aEndInd,
       
   279 		               TInt aApiNumber,TInt aTestNumber,TTestMode aTestMode);
       
   280 
       
   281 	TInt WriteLog(TBool aIsPassed,TUint aFunIndex,TUint aApiNum,
       
   282 		          TUint aTstNum, TInt aErrorCode);
       
   283 	void FormDateTimeBit(TDes8& aDateTimeField,TUint aDateTimeBit,
       
   284 		                 TBool aIsDateSepa,TBool aAddSepa);
       
   285 
       
   286 private:
       
   287 	RCommServ   iCommServer;
       
   288 
       
   289 	TBuf<KMaxTestTelNumberSize> iTelNumConnect1;
       
   290 	TBuf<KMaxTestTelNumberSize> iTelNumConnect2;
       
   291 	TBuf<KMaxTestTelNumberSize> iTelNumConnect3;
       
   292 	TBuf<KMaxTestTelNumberSize> iTelNumConnect4;
       
   293 	TBuf<KMaxTestTelNumberSize> iTelNumConnect5;
       
   294 	TBuf<KMaxTestTelNumberSize> iTelNumConnect6;
       
   295 	TBuf<KMaxTestTelNumberSize> iTelNumConnect7;
       
   296 	TBuf<KMaxTestTelNumberSize> iTelNumMobile1;
       
   297 	TBuf<KMaxTestTelNumberSize> iTelNumDataConnect;
       
   298 	TBuf<KMaxTestTelNumberSize> iTelNumNeverConnect;
       
   299 	TBuf<KMaxTestTelNumberSize> iTelNumRejectCall;
       
   300 	TBuf<KMaxTestTelNumberSize> iTelNumRemoteEndHangUp;
       
   301 	TBuf<KMaxTestTelNumberSize> iTelNumIncorrect1;
       
   302 	TBuf<KMaxTestTelNumberSize> iTelNumIncorrect2;
       
   303 	TBuf<KMaxTestTelNumberSize> iTelNumDTMFTest;
       
   304 	TBuf<KMaxTestTelNumberSize> iTelNumCallback;
       
   305 	TBuf<KMaxTestTelNumberSize> iTelNumDataServer1;
       
   306 	TBuf<KMaxTestTelNumberSize> iTelNumDataServer2;
       
   307 	TBuf<KMaxTestTelNumberSize> iTelNumDataServer3;
       
   308 	TBuf<KMaxTestTelNumberSize> iTelNumDataServer4;
       
   309 	TBuf<KMaxTestTelNumberSize> iSmsDestNumber;
       
   310 	TBuf<KMaxTestTelNumberSize> iTelNumberInMadCow;
       
   311 	TBuf<KMaxSimNameLen>		iSmsNetworkName;
       
   312 	TInt	 iTypeOfTest;
       
   313 
       
   314 	///< Determines whether to repeat the tests that failed at the end of a full automatic run
       
   315 	TBool    iRepeatFailedTests;
       
   316 	///< Do we want to keep the phone open between tests?
       
   317 	TBool    iKeepPhoneOpen;
       
   318 
       
   319 	TBool iExitAfterTestsComplete;
       
   320 
       
   321 private:
       
   322 	// Another session with Etel, to be kept permanently open. Helps to test
       
   323 	// bad states building up, speeds the tests up too...
       
   324 
       
   325 	struct TTestFailure
       
   326 		{
       
   327 		TTestFailure(TInt aMethodNum,TInt aTestIndex) : iMethodNum(aMethodNum), iTestIndex(aTestIndex) {}
       
   328 		TInt iMethodNum;
       
   329 		TInt iTestIndex;
       
   330 		};
       
   331 	typedef RArray<TTestFailure> RFailedTestsArray;
       
   332 	RFailedTestsArray iFailedTests;
       
   333 
       
   334 protected:
       
   335 	RFs iFs;
       
   336 	RFile iLogFile;
       
   337 	RTest		iTest;
       
   338 	const TName iUnitTestName;
       
   339 	const TName iLogFileName;
       
   340 	const TName iTestScriptName;
       
   341 	const TName iTestSpecName;
       
   342 	TName iTsIdentifier;
       
   343 	TName iMethodName;
       
   344 	RArray<TUint> iFunIndices;
       
   345 	};
       
   346 
       
   347 //inline functions
       
   348 RTest CUnitTestBase::Test() const
       
   349 	{
       
   350 	return iTest;
       
   351 	}
       
   352 
       
   353 void CUnitTestBase::SetTsIdentifier(const TName& aTsIdentifier)
       
   354 	{
       
   355 	iTsIdentifier=aTsIdentifier;
       
   356 	}
       
   357 
       
   358 void CUnitTestBase::SetMethodName(const TName& aMethodName)
       
   359 	{
       
   360 	iMethodName=aMethodName;
       
   361 	}
       
   362 
       
   363 void CUnitTestBase::SetFunIndex(TUint aFunIndex)
       
   364 	{
       
   365 	iFunIndices.Insert(aFunIndex,0);
       
   366 	}
       
   367 
       
   368 void CUnitTestBase::LeaveIfPhoneAlreadyOpenL()
       
   369 	{
       
   370 	if (iKeepPhoneOpen)
       
   371 		User::Leave(KErrAbort);
       
   372 	}
       
   373 
       
   374 #endif//END UNITTESTBASE_H__