datacommsserver/esockserver/test/TE_EIntsock/TE_EIntSockTestStep.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2004-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<c32root.h>
       
    17 #include <e32base.h>
       
    18 #include <es_sock.h>
       
    19 //#include <ss_std.h>
       
    20 //#include <e32std.h>
       
    21 #include <comms-infras/eintsock.h>
       
    22 
       
    23 #include "TE_EIntSockTestStep.h"
       
    24 #include "es_ptestinternalsocket.h"
       
    25 //#include <e32des8.h>
       
    26 
       
    27 // constructor
       
    28 CEIntSockTestStep::CEIntSockTestStep()
       
    29 	{
       
    30 	}
       
    31 
       
    32 // destructor
       
    33 CEIntSockTestStep::~CEIntSockTestStep()
       
    34 	{
       
    35 	iESockProxyThread.Close();
       
    36 	}
       
    37 
       
    38 enum TVerdict CEIntSockTestStep::doTestStepPreambleL( void )
       
    39 	{
       
    40 	return EPass;
       
    41 	}
       
    42 
       
    43 enum TVerdict CEIntSockTestStep::doTestStepL()
       
    44 	{
       
    45 	
       
    46 	TRAPD(trapRet,enum TVerdict stepRet = InternalDoTestStepL();\
       
    47 		if (stepRet !=EPass)\
       
    48 			{\
       
    49 			SetTestStepResult(stepRet);\
       
    50 			}\
       
    51 			)
       
    52 			
       
    53 			if (trapRet != KErrNone)
       
    54 				{
       
    55 				SetTestStepResult(EFail);
       
    56 				return EFail;
       
    57 				}
       
    58 			return EPass;
       
    59 	};
       
    60 
       
    61 //This method ensures that any
       
    62 enum TVerdict CEIntSockTestStep::doTestStepPostambleL( void )
       
    63 	{
       
    64 	return EPass;
       
    65 	}
       
    66 	
       
    67 enum TVerdict CEIntSockTestStep::InternalDoTestStepL()
       
    68 	{
       
    69 	RSocketServ ss1;
       
    70 	TInt ret;
       
    71 	ret = ss1.Connect();
       
    72 	if (ret != KErrNone)
       
    73 		{
       
    74 		Logger().WriteFormat(_L("Connect to socket server failed with %S"),&EpocErrorToText(ret));
       
    75 		}
       
    76 	CleanupClosePushL(ss1);
       
    77 	TESTL(ret == KErrNone);
       
    78 	RSocket sock1;
       
    79 	ret = sock1.Open(ss1,KProxyAddrFamily,KSockDatagram, KProxy);
       
    80 	//ret = sock1.Open(ss1,KProxyName);
       
    81 	if (ret != KErrNone)
       
    82 		{
       
    83 		Logger().WriteFormat(_L("Opening socket to the Test Internal Socket Protocol failed with %S"),&EpocErrorToText(ret));
       
    84 		}
       
    85 	TESTL(ret == KErrNone);
       
    86 	Logger().Close();
       
    87 	TRequestStatus stat;
       
    88 		
       
    89 	TProxyProtocolRequest request;
       
    90 	request.name.Copy(TestStepName());
       
    91 	
       
    92 	TPckg<TProxyProtocolRequest> requestPckg(request);
       
    93 	
       
    94 	_LIT(PanicStep,"Test21");
       
    95 	if (TestStepName() == PanicStep)
       
    96 		{
       
    97 		doPanicStepTestPreambleL();
       
    98 		}
       
    99 
       
   100 	sock1.Ioctl(KProxyProtocolTestRequest,stat,&requestPckg);
       
   101 	User::WaitForRequest(stat);
       
   102 	CleanupStack::Pop(&ss1);
       
   103 	ss1.Close();
       
   104 
       
   105 	if (TestStepName() == PanicStep)
       
   106 		{
       
   107 		doPanicStepTestPostambleL(stat);
       
   108 		}
       
   109 	else
       
   110 		{
       
   111 		TESTL(stat == KErrNone);
       
   112 		SetTestStepResult(request.result);
       
   113 		}
       
   114 	return TestStepResult();
       
   115 	}
       
   116 
       
   117 void CEIntSockTestStep::doPanicStepTestPreambleL()
       
   118 	{
       
   119 	// Search for *ESock_Proxy* thread
       
   120 	TFindThread findThread(_L("*ESock_Proxy*"));
       
   121 	TFullName threadName;
       
   122 	TESTL(findThread.Next(threadName) == KErrNone);
       
   123 		
       
   124 	TESTL(iESockProxyThread.Open(findThread) == KErrNone);
       
   125 
       
   126 	iESockProxyThread.Logon(iESockProxyThreadStatus);
       
   127 	}
       
   128 
       
   129 void CEIntSockTestStep::doPanicStepTestPostambleL( TRequestStatus& aStat )
       
   130 	{
       
   131 	//ESock is expected to have a panic. The Kernel will therefore return KErrAbort
       
   132 	TESTL(aStat  == KErrAbort);
       
   133 
       
   134 	User::WaitForRequest(iESockProxyThreadStatus);
       
   135 
       
   136 	//Test that ESock_Proxy Paniced
       
   137 	TESTL(iESockProxyThread.ExitType() == EExitPanic);
       
   138 	
       
   139 	// Test that the Panic Category was "InternalSocket"
       
   140 	_LIT(KInternalSocketPanic, "InternalSocket");
       
   141 	TESTL(iESockProxyThread.ExitCategory() == KInternalSocketPanic);
       
   142 
       
   143 	// Test that the Panic Reason was EInternalSocketNotNullSocket (12)
       
   144 	TESTL(iESockProxyThread.ExitReason() == ENotNullSocket);
       
   145 
       
   146 	SetTestStepResult(EPass);	
       
   147 	}
       
   148 	
       
   149 // extra logging methods
       
   150 const TPtrC& CEIntSockTestStep::EpocErrorToText(const TInt aErrCode)
       
   151 /**
       
   152 Convert a Error code to text.
       
   153 
       
   154   @param aError error code to display as text.
       
   155   @return Text describing the error.
       
   156   */
       
   157 	{
       
   158 	//	TPtr errText;
       
   159 	switch (aErrCode)
       
   160 		{
       
   161 		case KErrNone:
       
   162 			iErrText.Set(_L("KErrNone"));
       
   163 			break;
       
   164 		case KErrNotFound:
       
   165 			iErrText.Set(_L("KErrNotFound"));
       
   166 			break;
       
   167 		case KErrGeneral:
       
   168 			iErrText.Set(_L("KErrGeneral"));
       
   169 			break;
       
   170 		case KErrCancel:
       
   171 			iErrText.Set(_L("KErrCancel"));
       
   172 			break;
       
   173 		case KErrNoMemory:
       
   174 			iErrText.Set(_L("KErrNoMemory"));
       
   175 			break;
       
   176 		case KErrNotSupported:
       
   177 			iErrText.Set(_L("KErrNotSupported"));
       
   178 			break;
       
   179 		case KErrArgument:
       
   180 			iErrText.Set(_L("KErrArgument"));
       
   181 			break;
       
   182 		case KErrTotalLossOfPrecision:
       
   183 			iErrText.Set(_L("KErrTotalLossOfPrecision"));
       
   184 			break;
       
   185 		case KErrBadHandle:
       
   186 			iErrText.Set(_L("KErrBadHandle"));
       
   187 			break;
       
   188 		case KErrOverflow:
       
   189 			iErrText.Set(_L("KErrOverflow"));
       
   190 			break;
       
   191 		case KErrUnderflow:
       
   192 			iErrText.Set(_L("KErrUnderflow"));
       
   193 			break;
       
   194 		case KErrAlreadyExists:
       
   195 			iErrText.Set(_L("KErrAlreadyExists"));
       
   196 			break;
       
   197 		case KErrPathNotFound:
       
   198 			iErrText.Set(_L("KErrPathNotFound"));
       
   199 			break;
       
   200 		case KErrDied:
       
   201 			iErrText.Set(_L("KErrDied"));
       
   202 			break;
       
   203 		case KErrInUse:
       
   204 			iErrText.Set(_L("KErrInUse"));
       
   205 			break;
       
   206 		case KErrServerTerminated:
       
   207 			iErrText.Set(_L("KErrServerTerminated"));
       
   208 			break;
       
   209 		case KErrServerBusy:
       
   210 			iErrText.Set(_L("KErrServerBusy"));
       
   211 			break;
       
   212 		case KErrCompletion:
       
   213 			iErrText.Set(_L("KErrCompletion"));
       
   214 			break;
       
   215 		case KErrNotReady:
       
   216 			iErrText.Set(_L("KErrNotReady"));
       
   217 			break;
       
   218 		case KErrUnknown:
       
   219 			iErrText.Set(_L("KErrUnknown"));
       
   220 			break;
       
   221 		case KErrCorrupt:
       
   222 			iErrText.Set(_L("KErrCorrupt"));
       
   223 			break;
       
   224 		case KErrAccessDenied:
       
   225 			iErrText.Set(_L("KErrAccessDenied"));
       
   226 			break;
       
   227 		case KErrLocked:
       
   228 			iErrText.Set(_L("KErrLocked"));
       
   229 			break;
       
   230 		case KErrWrite:
       
   231 			iErrText.Set(_L("KErrWrite"));
       
   232 			break;
       
   233 		case KErrDisMounted:
       
   234 			iErrText.Set(_L("KErrDisMounted"));
       
   235 			break;
       
   236 		case KErrEof:
       
   237 			iErrText.Set(_L("KErrEof"));
       
   238 			break;
       
   239 		case KErrDiskFull:
       
   240 			iErrText.Set(_L("KErrDiskFull"));
       
   241 			break;
       
   242 		case KErrBadDriver:
       
   243 			iErrText.Set(_L("KErrBadDriver"));
       
   244 			break;
       
   245 		case KErrBadName:
       
   246 			iErrText.Set(_L("KErrBadName"));
       
   247 			break;
       
   248 		case KErrCommsLineFail:
       
   249 			iErrText.Set(_L("KErrCommsLineFail"));
       
   250 			break;
       
   251 		case KErrCommsFrame:
       
   252 			iErrText.Set(_L("KErrCommsFrame"));
       
   253 			break;
       
   254 		case KErrCommsOverrun:
       
   255 			iErrText.Set(_L("KErrCommsOverrun"));
       
   256 			break;
       
   257 		case KErrCommsParity:
       
   258 			iErrText.Set(_L("KErrCommsParity"));
       
   259 			break;
       
   260 		case KErrTimedOut:
       
   261 			iErrText.Set(_L("KErrTimedOut"));
       
   262 			break;
       
   263 		case KErrCouldNotConnect:
       
   264 			iErrText.Set(_L("KErrCouldNotConnect"));
       
   265 			break;
       
   266 		case KErrCouldNotDisconnect:
       
   267 			iErrText.Set(_L("KErrCouldNotDisconnect"));
       
   268 			break;
       
   269 		case KErrDisconnected:
       
   270 			iErrText.Set(_L("KErrDisconnected"));
       
   271 			break;
       
   272 		case KErrBadLibraryEntryPoint:
       
   273 			iErrText.Set(_L("KErrBadLibraryEntryPoint"));
       
   274 			break;
       
   275 		case KErrBadDescriptor:
       
   276 			iErrText.Set(_L("KErrBadDescriptor"));
       
   277 			break;
       
   278 		case KErrAbort:
       
   279 			iErrText.Set(_L("KErrAbort"));
       
   280 			break;
       
   281 		case KErrTooBig:
       
   282 			iErrText.Set(_L("KErrTooBig"));
       
   283 			break;
       
   284 		case KRequestPending:
       
   285 			iErrText.Set(_L("KRequestPending"));
       
   286 			break;
       
   287 		default:
       
   288 			iErrBuff.Format(_L(" %d"),aErrCode);
       
   289 			iErrText.Set(iErrBuff.Ptr());
       
   290 			break;
       
   291 		}
       
   292 		return iErrText;
       
   293 	}	
       
   294 
       
   295