telephonyserverplugins/simtsy/test/Te_Sim/Te_SimPacketContextTest.cpp
changeset 0 3553901f7fa8
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     1 // Copyright (c) 2005-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 "Te_SimPacketContextTest.h"
       
    17 
       
    18 CSimPacketContextTest::CSimPacketContextTest()
       
    19 	{ 
       
    20 	SetTestStepName(_L("ContextTest"));
       
    21 	}
       
    22 
       
    23 TVerdict CSimPacketContextTest::doTestStepL()
       
    24 	{
       
    25 	INFO_PRINTF1(_L("BeginPacketContextTest"));
       
    26 
       
    27  	CreateConfigFileL(_L("c:\\config3.txt"));
       
    28  	SetTestNumberL(6);
       
    29 
       
    30 	TInt ret = iPhone.Open(iTelServer,KPhoneName); 
       
    31 	INFO_PRINTF2(_L("Result: %d"),ret); 
       
    32 	TESTL(ret == KErrNone); 
       
    33 	INFO_PRINTF1(_L("Opened phone object"));
       
    34 
       
    35 	TESTL(iPacketService.Open(iPhone)==KErrNone);
       
    36 	INFO_PRINTF1(_L("Opened Packet object"));
       
    37 
       
    38 	// test GetContextInfo - get context info where no contexts created
       
    39 	TInt index = 0;
       
    40 	RPacketService::TContextInfo contextInfo;
       
    41 	TRequestStatus reqStatus, notifyStatus;
       
    42 
       
    43 	iPacketService.GetContextInfo(reqStatus, index, contextInfo);
       
    44 	iPacketService.CancelAsyncRequest(EPacketGetContextInfo);
       
    45 	User::WaitForRequest(reqStatus);
       
    46 	TESTL(reqStatus.Int()==KErrArgument); 
       
    47 	INFO_PRINTF1(_L("Get Info Test Passed - KErrArgument as no context created"));
       
    48 
       
    49 	TBuf<40> contextId;
       
    50 	iPacketService.NotifyContextAdded(notifyStatus, contextId);
       
    51 	iPacketService.CancelAsyncRequest(EPacketNotifyContextAdded);
       
    52 	User::WaitForRequest(notifyStatus);
       
    53 	TESTL(notifyStatus.Int()== KErrCancel);
       
    54 	
       
    55 	TName contextName;
       
    56 	iPacketService.NotifyContextAdded(notifyStatus, contextName);
       
    57 
       
    58 	// test RPacketContext::OpenNewContext
       
    59 	
       
    60 	TName contextNameCompare;
       
    61 	ret = iFirstPrimaryPacketContext.OpenNewContext(iPacketService, contextName);
       
    62 	contextNameCompare.Append(KSimPrimaryPacketContextName);
       
    63 	contextNameCompare.AppendNum(1);
       
    64 	TESTL(contextName.Compare(contextNameCompare)==KErrNone);
       
    65 	CHECKPOINTL(ret,KErrNone,CHP_CNTXT_CASE("E.2"));
       
    66 	INFO_PRINTF1(_L("Opened Context object"));
       
    67 		 
       
    68 	User::WaitForRequest(notifyStatus);
       
    69 	
       
    70 	TName anotherContextName;
       
    71 	TName anotherContextNameCompare;
       
    72 	TESTL(iSecondPrimaryPacketContext.OpenNewContext(iPacketService, anotherContextName)==KErrNone);
       
    73 	anotherContextNameCompare.Append(KSimPrimaryPacketContextName);
       
    74 	anotherContextNameCompare.AppendNum(2);
       
    75 	TESTL(anotherContextName.Compare(anotherContextNameCompare)==KErrNone);
       
    76 	CHECKPOINTL(ret,KErrNone,CHP_CNTXT_CASE("E.3"));
       
    77 	INFO_PRINTF1(_L("Opened another Primary Context object")); 
       
    78 
       
    79 	// test RPacketService::GetContextInfo - context has been created
       
    80 	index = 1;
       
    81 	iPacketService.GetContextInfo(reqStatus, index, contextInfo);
       
    82 	iPacketService.CancelAsyncRequest(EPacketGetContextInfo);
       
    83 	User::WaitForRequest(reqStatus);
       
    84 	TESTL(reqStatus.Int()==KErrNone); 
       
    85 	CHECKPOINTL(reqStatus.Int(),KErrNone,CHP_CNTXT_CASE("E.6"));
       
    86 	INFO_PRINTF1(_L("Get Info Test Passed"));
       
    87 
       
    88 	// test RPacketService::GetContextInfo() - on deactivated context
       
    89 	iFirstPrimaryPacketContext.Deactivate(reqStatus);
       
    90 	User::WaitForRequest(reqStatus);
       
    91 	TESTL(reqStatus.Int()==KErrNone);
       
    92 	INFO_PRINTF1(_L("Deactivated context successfully"));
       
    93 	CHECKPOINTL(reqStatus.Int(),KErrNone,CHP_CNTXT_CASE("E.7"));
       
    94 
       
    95 	index = 0;
       
    96 	iPacketService.GetContextInfo(reqStatus, index, contextInfo);
       
    97 	User::WaitForRequest(reqStatus);
       
    98 	TESTL(reqStatus.Int()==KErrNone); 
       
    99 	INFO_PRINTF1(_L("Get Info Test Passed")); 
       
   100 
       
   101 	// test RPacketContext::GetStatus
       
   102 	RPacketContext::TContextStatus contextStatus;
       
   103 	TESTL(iFirstPrimaryPacketContext.GetStatus(contextStatus) == KErrNone);
       
   104 	TESTL(contextStatus==RPacketContext::EStatusInactive);
       
   105 	CHECKPOINTL(reqStatus.Int(),KErrNone,CHP_CNTXT_CASE("E.27"));
       
   106 	INFO_PRINTF1(_L("GetStatus on inactive context successful"));
       
   107 
       
   108 	// test RPacketContext::Activate
       
   109 	iFirstPrimaryPacketContext.Activate(reqStatus);
       
   110 	iFirstPrimaryPacketContext.CancelAsyncRequest(EPacketContextActivate);
       
   111 	User::WaitForRequest(reqStatus);
       
   112 	TESTL(reqStatus.Int()==KErrCancel);
       
   113 	CHECKPOINTL(reqStatus.Int(),KErrCancel,CHP_CNTXT_CASE("E.22"));
       
   114 	INFO_PRINTF1(_L("Activation Cancel test passed"));
       
   115 
       
   116 	// test RPacketContext::GetStatus
       
   117 	TESTL(iFirstPrimaryPacketContext.GetStatus(contextStatus) == KErrNone);
       
   118 	TESTL(contextStatus==RPacketContext::EStatusInactive);
       
   119 
       
   120 	// test RPacketContext::NotifyStatusChange 
       
   121 
       
   122 	// test RPacketContext::Activate
       
   123 	StartNTRasSimulation();
       
   124 	iFirstPrimaryPacketContext.NotifyStatusChange(notifyStatus, contextStatus);
       
   125 	iFirstPrimaryPacketContext.Activate(reqStatus);
       
   126 	User::WaitForRequest(notifyStatus);
       
   127 	TESTL(notifyStatus.Int()==KErrNone);
       
   128 	User::WaitForRequest(reqStatus);
       
   129 	CHECKPOINTL(reqStatus.Int(),KErrNone,CHP_CNTXT_CASE("E.21"));
       
   130 	TESTL(notifyStatus.Int()==KErrNone);
       
   131 
       
   132 	INFO_PRINTF1(_L("Activate test passed"));
       
   133 	// test RPacketContext::GetContextInfo
       
   134 	index = 0;
       
   135 	iPacketService.GetContextInfo(reqStatus, index, contextInfo);
       
   136 	iPacketService.CancelAsyncRequest(EPacketGetContextInfo);
       
   137 	User::WaitForRequest(reqStatus);
       
   138 	TESTL(reqStatus.Int()==KErrNone); 
       
   139 	CHECKPOINTL(reqStatus.Int(),KErrNone,CHP_CNTXT_CASE("E.6"));
       
   140 	INFO_PRINTF1(_L("Get Info Test Passed"));
       
   141 
       
   142 	// test RPacketContext::GetStatus
       
   143 	TESTL(iFirstPrimaryPacketContext.GetStatus(contextStatus) == KErrNone);
       
   144 	TESTL(contextStatus==RPacketContext::EStatusActive);
       
   145 	CHECKPOINTL(reqStatus.Int(),KErrNone,CHP_CNTXT_CASE("E.28"));
       
   146 	INFO_PRINTF1(_L("GetStatus on active context successful"));
       
   147 
       
   148 	// test cancelling RPacketService::Deactivate() 
       
   149 	iFirstPrimaryPacketContext.Deactivate(reqStatus);
       
   150 	iFirstPrimaryPacketContext.CancelAsyncRequest(EPacketContextDeactivate);
       
   151 	User::WaitForRequest(reqStatus);
       
   152 	TESTL(reqStatus.Int()==KErrCancel);
       
   153 	INFO_PRINTF1(_L("Cancelled Deactivate context successfully"));
       
   154 	CHECKPOINTL(reqStatus.Int(),KErrCancel,CHP_CNTXT_CASE("E.26"));
       
   155 
       
   156 	// test RPacketContext::Deactivate
       
   157 	iFirstPrimaryPacketContext.Deactivate(reqStatus);
       
   158 	User::WaitForRequest(reqStatus);
       
   159 	TESTL(reqStatus.Int()==KErrNone);
       
   160 	INFO_PRINTF1(_L("Deactivate test passed"));
       
   161 
       
   162 	// Activate PRIMARY2
       
   163 	StartNTRasSimulation();
       
   164 	iSecondPrimaryPacketContext.Activate(reqStatus);
       
   165 	User::WaitForRequest(reqStatus);
       
   166 	TESTL(reqStatus.Int()==KErrNone);
       
   167 	INFO_PRINTF1(_L("Activate PRIMARY2 tested successfully"));
       
   168 
       
   169 	// test RPacketContext::GetStatus
       
   170 	TESTL(iSecondPrimaryPacketContext.GetStatus(contextStatus) == KErrNone);
       
   171 	TESTL(contextStatus==RPacketContext::EStatusActive);
       
   172 	INFO_PRINTF1(_L("GetStatus on active PRIMARY2 context successful"));
       
   173 
       
   174 	TUint8 addrArray[RPacketContext::KIPAddressSize] = {0,0,0,0,
       
   175 														0,0,0,0,
       
   176 														0,0,255,255,
       
   177 														102,23,224,132};
       
   178 	TUint8 subArray[RPacketContext::KIPAddressSize] =	{0,0,0,0,
       
   179 														0,0,0,0,
       
   180 														0,0,255,255,
       
   181 														255,255,255,255};
       
   182 	RPacketContext::TPacketFilterV2 packetFilterV2;
       
   183 	packetFilterV2.iId = 0;
       
   184 	packetFilterV2.iEvaluationPrecedenceIndex = 1;
       
   185 
       
   186 	for(TInt x = 0;  x<RPacketContext::KIPAddressSize; x++)
       
   187 		{
       
   188 		packetFilterV2.iSrcAddr[x] = addrArray[x];
       
   189 		packetFilterV2.iSrcAddrSubnetMask[x] = subArray[x];
       
   190 		}
       
   191 
       
   192 	packetFilterV2.iProtocolNumberOrNextHeader = 1;
       
   193 	packetFilterV2.iSrcPortMin = 0;
       
   194 	packetFilterV2.iSrcPortMax = 1;
       
   195 	packetFilterV2.iDestPortMin = 2;
       
   196 	packetFilterV2.iDestPortMax = 0;
       
   197 	packetFilterV2.iIPSecSPI = 0;
       
   198 	packetFilterV2.iTOSorTrafficClass = 1;
       
   199 	packetFilterV2.iFlowLabel = 2;
       
   200 
       
   201 	RPacketContext::TPacketFilterV2Pckg packetFilterV2pckg(packetFilterV2);
       
   202 
       
   203 	iSecondPrimaryPacketContext.AddPacketFilter(reqStatus, packetFilterV2pckg);
       
   204 	User::WaitForRequest(reqStatus);
       
   205 	TESTL(reqStatus.Int()==KErrNone); 
       
   206 	INFO_PRINTF1(_L("AddPacketFilter PRIMARY2 Test Passed"));
       
   207 
       
   208 	// test RPacketContext::ModifyActiveContext
       
   209 	iSecondPrimaryPacketContext.ModifyActiveContext(reqStatus);
       
   210 	User::WaitForRequest(reqStatus);
       
   211 	TESTL(reqStatus.Int()==KErrNone); 
       
   212 	INFO_PRINTF1(_L("ModifyActiveContext PRIMARY2 Test Passed"));
       
   213 
       
   214 	RCall::TCommPort commPort;
       
   215 	iSecondPrimaryPacketContext.LoanCommPort(reqStatus, commPort);
       
   216 	iSecondPrimaryPacketContext.CancelAsyncRequest(EPacketContextLoanCommPort);//does nothing
       
   217 	User::WaitForRequest(reqStatus);
       
   218 	TESTL(reqStatus.Int()==KErrNone);
       
   219 	TESTL(commPort.iCsy==DPCKTTSY_CSY);
       
   220 	TESTL(commPort.iPort==DPCKTTSY_PORT);
       
   221 	INFO_PRINTF1(_L("Loan Comm Port test passed"));
       
   222 	
       
   223 	_LIT8(KWriteTestData,"SIMULATOR TSY PACKET TEST"); 
       
   224 	_LIT(KPortName,"LOOPBACK::1");
       
   225 	_LIT(KCsyName,"LOOPBACK.CSY");
       
   226 
       
   227 	RCommServ cs;
       
   228 	
       
   229 	TInt r=cs.Connect();
       
   230 	r=cs.LoadCommModule(KCsyName);
       
   231 
       
   232 	RComm port;
       
   233 	TESTL(port.Open(cs,KPortName,ECommShared)==KErrNone);
       
   234 
       
   235 	port.Write(reqStatus,KWriteTestData);
       
   236 	User::WaitForRequest(reqStatus);
       
   237 	TESTL(reqStatus.Int()==KErrNone);
       
   238 
       
   239 	port.Close();
       
   240 	cs.Close();
       
   241 
       
   242 	// test RPacketContext::RecoverCommPort
       
   243 	iSecondPrimaryPacketContext.RecoverCommPort(reqStatus);
       
   244 	iSecondPrimaryPacketContext.CancelAsyncRequest(EPacketContextRecoverCommPort);
       
   245 	User::WaitForRequest(reqStatus);
       
   246 	TESTL(reqStatus.Int()==KErrNone);
       
   247 	INFO_PRINTF1(_L("Recover Comm Port test passed"));
       
   248 
       
   249 	// test RPacketContext::Deactivate
       
   250 	iFirstPrimaryPacketContext.Deactivate(reqStatus);
       
   251 	User::WaitForRequest(reqStatus);
       
   252 	TESTL(reqStatus.Int()==KErrNone);
       
   253 	INFO_PRINTF1(_L("Deactivate test passed"));
       
   254 
       
   255 
       
   256 	// test RPacketContext::Detach
       
   257 	iPacketService.Detach(reqStatus);
       
   258 	User::WaitForRequest(reqStatus);
       
   259 	TESTL(reqStatus==KErrNone);
       
   260 	INFO_PRINTF1(_L("Packet Detach Cancelled Successfully"));
       
   261 
       
   262 	// test RPacketContext::Delete
       
   263 	iFirstPrimaryPacketContext.Delete(reqStatus);
       
   264 	iFirstPrimaryPacketContext.CancelAsyncRequest(EPacketContextDelete);
       
   265 	User::WaitForRequest(reqStatus);
       
   266 	if (reqStatus.Int()==KErrNone)
       
   267 		{
       
   268 		INFO_PRINTF1(_L("Delete request completed before its cancelation"));
       
   269 		}
       
   270 	else if (reqStatus.Int()==KErrCancel)
       
   271 		{
       
   272 		INFO_PRINTF1(_L("Delete Cancel test passed"));
       
   273 		// successfully canceled, reissue the async. request again
       
   274 		iFirstPrimaryPacketContext.Delete(reqStatus);
       
   275 		User::WaitForRequest(reqStatus);
       
   276 		}
       
   277 	TESTL(reqStatus.Int()==KErrNone);
       
   278 	INFO_PRINTF1(_L("Delete test passed"));
       
   279 
       
   280 	iFirstPrimaryPacketContext.Close();
       
   281 	iSecondPrimaryPacketContext.Close();
       
   282 	iPacketService.Close();
       
   283 	iPhone.Close();
       
   284 	ASSERT(RThread().RequestCount()==0);
       
   285 
       
   286 	return TestStepResult();
       
   287 	}
       
   288