telephonyserverplugins/multimodetsy/test/gprs/t_gprs.cpp
changeset 0 3553901f7fa8
equal deleted inserted replaced
-1:000000000000 0:3553901f7fa8
       
     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 // \file t_gprs.cpp
       
    15 // This file implements all GPRS and Context test cases. The test cases are built
       
    16 // for using against a Motorola GPRS and Ericsson T39/520 phones.
       
    17 // All test cases that are in tgprsinter are also in this file.
       
    18 // 
       
    19 //
       
    20 
       
    21 #include <e32base.h>
       
    22 #include <e32test.h>
       
    23 #include <c32comm.h>
       
    24 #include "f32file.h"
       
    25 #include <etel.h>
       
    26 #include <autotest.h>
       
    27 #include <es_sock.h>
       
    28 #include <in_sock.h>
       
    29 #include "tmain.h"
       
    30 #include <etelQoS.h>
       
    31 #include <pcktcs.h>
       
    32 // Globals
       
    33 CAutoTest* gAutoTest;
       
    34 
       
    35 //GLREF_D     RConnection		conn;
       
    36 
       
    37 
       
    38 // Support functions
       
    39 LOCAL_C void TestConfigParams(RPacketContext::TContextConfigGPRS& aArg1, RPacketContext::TContextConfigGPRS& aArg2);
       
    40 LOCAL_C TInt ListRoutes(RSocket& aSocket);
       
    41 
       
    42 
       
    43 void WaitWithTimeout(TRequestStatus& aStatus)
       
    44 /**	Waits untill end or request or time out
       
    45  * @param request itself
       
    46  * @param  number Of microseconds
       
    47  */
       
    48 	{
       
    49 	TRequestStatus timerStatus;
       
    50 	RTimer timer;
       
    51 	timer.CreateLocal() ;
       
    52 
       
    53 	const TInt KOneSecondInMicroSeconds=1000000L;
       
    54 	timer.After(timerStatus,120*KOneSecondInMicroSeconds);		// x second timer
       
    55 
       
    56 	User::WaitForRequest(aStatus, timerStatus);
       
    57 
       
    58 	// Cancel timer if it did not complete
       
    59 	if (timerStatus == KRequestPending)
       
    60 		{
       
    61 		timer.Cancel();
       
    62 		User::WaitForRequest(timerStatus);
       
    63 		}
       
    64 	else
       
    65 		{
       
    66 		aStatus=-999;		// Hopefully -999 reported in the test result log will make it obvious
       
    67 								    // that the request was cancelled due to it taking to long
       
    68 		gTest.Printf(_L("User::WaitForRequest cancelled as it did not complete within a reasonable time\n"));
       
    69 		}
       
    70 
       
    71 	timer.Close() ;
       
    72 	}
       
    73 
       
    74 
       
    75 LOCAL_C void  GprsDefaultContextParamsTest()
       
    76 /**
       
    77  * This tests the default context params
       
    78  */
       
    79     {
       
    80     RPacketContext::TContextConfigGPRS     setDefaultParams;
       
    81     RPacketContext::TContextConfigGPRS     getDefaultParams;
       
    82 
       
    83 	// Some default params to set, does not matter what it is.
       
    84     _LIT(KAccesspoint, "www.Symbian.com");  
       
    85     _LIT(KPpdpaddress, "192.168.111.100");
       
    86 
       
    87     gTest(gPacketService.Open(gPhone ) == KErrNone);
       
    88     
       
    89     setDefaultParams.iPdpType = RPacketContext::EPdpTypeIPv4;
       
    90     setDefaultParams.iAccessPointName = KAccesspoint;
       
    91     setDefaultParams.iPdpAddress = KPpdpaddress;
       
    92     setDefaultParams.iPdpCompression = 1;
       
    93 
       
    94     TPckg<RPacketContext::TContextConfigGPRS>    setcontextConfigPckg(setDefaultParams);
       
    95     TPckg<RPacketContext::TContextConfigGPRS>    getcontextConfigPckg(getDefaultParams);
       
    96     gTest(gPacketService.SetDefaultContextParams(setcontextConfigPckg) == KErrNone);
       
    97     gTest(gPacketService.GetDefaultContextParams(getcontextConfigPckg) == KErrNone);
       
    98     TestConfigParams(setDefaultParams, getDefaultParams);
       
    99 
       
   100     gPacketService.Close();
       
   101     User::After(500000);
       
   102     }
       
   103 
       
   104 
       
   105 LOCAL_C void  GprsUnSupportedTest()
       
   106 /**
       
   107  * Tests all unsupported GPRS API calls to the TSY.
       
   108  */
       
   109     {
       
   110     TRequestStatus status;
       
   111     gTest(gPacketService.Open(gPhone ) == KErrNone);
       
   112     gPacketService.RejectActivationRequest(status);
       
   113 	 
       
   114 	  User::WaitForRequest(status);
       
   115 	  gTest(status.Int()== KErrNotSupported);
       
   116 
       
   117     gPacketService.RejectActivationRequest(status);
       
   118     gPacketService.CancelAsyncRequest(EPacketRejectActivationRequest);
       
   119     User::WaitForRequest(status);
       
   120     gTest(status.Int() == KErrNotSupported);
       
   121 
       
   122     RPacketService::TMSClass msClass;
       
   123     gPacketService.NotifyMSClassChange(status, msClass);
       
   124     User::WaitForRequest(status);
       
   125     gTest(status.Int() == KErrNotSupported);
       
   126 
       
   127     RPacketService::TDynamicCapsFlags dynCaps;
       
   128     gTest(gPacketService.GetDynamicCaps(dynCaps) == KErrNotSupported);
       
   129 
       
   130     gPacketService.NotifyDynamicCapsChange(status, dynCaps);
       
   131     User::WaitForRequest(status);
       
   132     gTest(status.Int() == KErrNotSupported);
       
   133 
       
   134     RPacketService::TAttachMode attachMode = RPacketService::EAttachWhenPossible;
       
   135     gTest(gPacketService.SetAttachMode(attachMode) == KErrNotSupported);
       
   136     gTest(gPacketService.GetAttachMode(attachMode) == KErrNotSupported);
       
   137 
       
   138     RPacketService::TRegistrationStatus registrationStatus = RPacketService::ERegisteredRoaming;
       
   139     gPacketService.GetNtwkRegStatus(status, registrationStatus);
       
   140 		User::WaitForRequest(status);
       
   141 		gTest(status.Int() == KErrNone || status.Int() == KErrNotSupported);
       
   142 
       
   143 		gPacketService.Close();
       
   144 	
       
   145     User::After(500000);
       
   146     }
       
   147 
       
   148 
       
   149 LOCAL_C void  GprsContextAttachTest()
       
   150 /**
       
   151  * This tests the context attach and detach
       
   152  */
       
   153     {
       
   154     TRequestStatus                      stat1;
       
   155     TRequestStatus						stat2;
       
   156 	TBuf<30>                            contextName;
       
   157     RPacketContext::TContextStatus        contextStatus;
       
   158     gTest(gPacketService.Open(gPhone ) == KErrNone);
       
   159     gTest(gPacketContext[0].OpenNewContext(gPacketService, contextName) == KErrNone);
       
   160     
       
   161     gPacketContext[0].NotifyStatusChange(stat1, contextStatus);
       
   162     gPacketContext[0].CancelAsyncRequest(EPacketContextNotifyStatusChange);
       
   163     User::WaitForRequest(stat1);
       
   164     gTest(stat1.Int() == KErrCancel);
       
   165 
       
   166     gPacketContext[0].NotifyStatusChange(stat1, contextStatus);
       
   167     
       
   168 	gPacketContext[0].Activate(stat2);
       
   169 	User::WaitForRequest(stat2);
       
   170 	gTest(stat2.Int()== KErrNone);
       
   171     
       
   172 	User::WaitForRequest(stat1);
       
   173     gTest(stat1.Int() == KErrNone);
       
   174     gTest(contextStatus == RPacketContext::EStatusActivating);
       
   175     gPacketContext[0].NotifyStatusChange(stat1, contextStatus);
       
   176     User::WaitForRequest(stat1);
       
   177     gTest(stat1.Int() == KErrNone);
       
   178     gTest(contextStatus == RPacketContext::EStatusActive);
       
   179     
       
   180     gPacketContext[0].NotifyStatusChange(stat1, contextStatus);
       
   181     
       
   182 		gPacketContext[0].Deactivate(stat2);
       
   183 		User::WaitForRequest(stat2);
       
   184 		gTest(stat2.Int() == KErrNone);
       
   185 
       
   186     User::WaitForRequest(stat1);
       
   187     gTest(stat1.Int() == KErrNone);
       
   188     gTest(contextStatus == RPacketContext::EStatusDeactivating);
       
   189     gPacketContext[0].NotifyStatusChange(stat1, contextStatus);
       
   190     User::WaitForRequest(stat1);
       
   191     gTest(stat1.Int() == KErrNone);
       
   192     gTest(contextStatus == RPacketContext::EStatusInactive);
       
   193     
       
   194     gPacketContext[0].Close();
       
   195     gPacketService.Close();
       
   196     User::After(500000);
       
   197     }
       
   198 
       
   199 
       
   200 LOCAL_C void  GprsContextDeleteTest()
       
   201 /**
       
   202  *  This tests the context delete.
       
   203  */
       
   204     {
       
   205     TRequestStatus						stat1;
       
   206 		TBuf<30>                            contextName;
       
   207     RPacketContext::TContextStatus		contextStatus;
       
   208 
       
   209     gTest(gPacketService.Open(gPhone ) == KErrNone);
       
   210     gTest(gPacketContext[0].OpenNewContext(gPacketService, contextName) == KErrNone);
       
   211     
       
   212 		gPacketContext[0].Delete(stat1);
       
   213 		User::WaitForRequest(stat1);
       
   214 		gTest(stat1.Int() == KErrNone);
       
   215     
       
   216 		gPacketContext[0].Activate(stat1);
       
   217 		User::WaitForRequest(stat1);
       
   218 		gTest(stat1.Int() == KErrAccessDenied);
       
   219 
       
   220     gTest(gPacketContext[0].GetStatus(contextStatus) == KErrNone);
       
   221     gTest(contextStatus == RPacketContext::EStatusDeleted);
       
   222 
       
   223     gPacketContext[0].Close();
       
   224     gPacketService.Close();
       
   225     User::After(KOneSecond);
       
   226     }   
       
   227 
       
   228 
       
   229 LOCAL_C void  GprsContextLoanComport()
       
   230 /**
       
   231  * This tests the comport loan.
       
   232  */
       
   233     {
       
   234 	TRequestStatus						stat1;
       
   235     TBuf<30>                            contextName;
       
   236 	RCall::TCommPort dataPort;
       
   237 
       
   238     gTest(gPacketService.Open(gPhone ) == KErrNone);
       
   239     gTest(gPacketContext[0].OpenNewContext(gPacketService, contextName) == KErrNone);
       
   240     
       
   241     gPacketContext[0].RecoverCommPort(stat1);
       
   242 	User::WaitForRequest(stat1);
       
   243 	gTest(stat1.Int() == KErrEtelPortNotLoanedToClient);
       
   244 
       
   245     gPacketContext[0].LoanCommPort(stat1, dataPort);
       
   246 	User::WaitForRequest(stat1);
       
   247 	gTest(stat1.Int() == KErrNotReady);
       
   248 
       
   249     gPacketContext[0].Activate(stat1);
       
   250 	User::WaitForRequest(stat1);
       
   251 	gTest(stat1.Int() == KErrNone);
       
   252 
       
   253     gPacketContext[0].LoanCommPort(stat1, dataPort);
       
   254 	User::WaitForRequest(stat1); 
       
   255 	gTest(stat1.Int() == KErrNone);
       
   256 
       
   257     gPacketContext[0].Activate(stat1);
       
   258 	User::WaitForRequest(stat1);
       
   259 	gTest(stat1.Int() == KErrInUse);
       
   260 
       
   261     gPacketContext[0].RecoverCommPort(stat1);
       
   262 	User::WaitForRequest(stat1);
       
   263 	gTest(stat1.Int() == KErrNone);
       
   264 
       
   265     gPacketContext[0].Deactivate(stat1);
       
   266 	User::WaitForRequest(stat1);
       
   267 	gTest(stat1.Int() == KErrNone);
       
   268 
       
   269     gPacketContext[0].Close();
       
   270     gPacketService.Close();
       
   271     User::After(KOneSecond);
       
   272     }   
       
   273 
       
   274 
       
   275 LOCAL_C void  GprsContextUnSupportedTest()
       
   276 /**
       
   277  *  This tests all GPRS context API calls.
       
   278  */
       
   279     {
       
   280     TRequestStatus            stat1;
       
   281     TBuf<30>                  contextName;
       
   282     TInt                      err = 0;
       
   283 	RPacketContext::TDataVolume volume;
       
   284     gTest(gPacketService.Open(gPhone ) == KErrNone);
       
   285     gTest(gPacketContext[0].OpenNewContext(gPacketService, contextName) == KErrNone);
       
   286     
       
   287     gTest(gPacketContext[0].GetDataVolumeTransferred(volume) == KErrNotSupported);
       
   288     gPacketContext[0].NotifyDataTransferred(stat1, volume);
       
   289     User::WaitForRequest(stat1);
       
   290     gTest(stat1.Int() == KErrNotSupported);
       
   291 
       
   292     gTest(gPacketContext[0].GetLastErrorCause(err) == KErrNotSupported);
       
   293 
       
   294     gPacketContext[0].Close();
       
   295     gPacketService.Close();
       
   296     User::After(KOneSecond);
       
   297 
       
   298     }
       
   299 
       
   300 
       
   301 LOCAL_C void  GprsMsClassTest()
       
   302 /**
       
   303  * This tests the MS Class.
       
   304  */
       
   305     {
       
   306     TRequestStatus stat1;
       
   307     gTest(gPacketService.Open(gPhone ) == KErrNone);
       
   308     
       
   309     RPacketService::TMSClass     currentClass;
       
   310     RPacketService::TMSClass     maxClass;
       
   311     gPacketService.GetMSClass(stat1, currentClass, maxClass);
       
   312 	User::WaitForRequest(stat1);
       
   313 	gTest(stat1.Int() == KErrNone);
       
   314  
       
   315 	if(GPhoneBrand == EMotorola)
       
   316 		{
       
   317 		gPacketService.SetMSClass(stat1, currentClass);
       
   318 		User::WaitForRequest(stat1);
       
   319 		gTest(stat1.Int() == KErrNone);
       
   320 	    gTest(currentClass	== RPacketService::EMSClassSuspensionRequired);
       
   321 		gTest(maxClass		== RPacketService::EMSClassSuspensionRequired);
       
   322 		}
       
   323 
       
   324     gPacketService.Close();
       
   325     }
       
   326 
       
   327 
       
   328 LOCAL_C void  GprsAttachTestL()
       
   329 /**
       
   330  *  This tests the attach and detach.
       
   331  */
       
   332     {
       
   333     TRequestStatus stat1;
       
   334     RPacketService::TStatus status;
       
   335 
       
   336     User::LeaveIfError(gPacketService.Open(gPhone));
       
   337     
       
   338 		gPacketService.Attach(stat1);
       
   339     User::WaitForRequest(stat1);
       
   340     User::LeaveIfError(stat1.Int());
       
   341     
       
   342 		gPacketService.GetStatus(status);
       
   343 		GLOBAL_CHECKPOINT_COMPARE(status,RPacketService::EStatusAttached,_L("Expected RPacketService::EStatusAttached"));
       
   344 
       
   345     gPacketService.Detach(stat1);
       
   346     User::WaitForRequest(stat1);
       
   347     User::LeaveIfError(stat1.Int());
       
   348 
       
   349     gPacketService.GetStatus(status);
       
   350 		GLOBAL_CHECKPOINT_COMPARE(status,RPacketService::EStatusUnattached,_L("Expected RPacketService::EStatusUnattached"));
       
   351 
       
   352     gPacketService.Close();
       
   353     User::After(KOneSecond);
       
   354     }
       
   355 
       
   356 
       
   357 LOCAL_C void  GprsNotificationTest()
       
   358 /**
       
   359  * Tests Notify Context added, Tests Notify status
       
   360  */
       
   361     {
       
   362     TRequestStatus stat1,stat2,stat3;
       
   363     TBuf<20> context= _L("");
       
   364     gTest(gPacketService.Open(gPhone ) == KErrNone);
       
   365     TBuf<40> contextId;
       
   366 
       
   367     gPacketService.NotifyContextAdded(stat1, contextId);
       
   368     gPacketService.CancelAsyncRequest(EPacketNotifyContextAdded);
       
   369 	User::WaitForRequest(stat1);
       
   370     gTest(stat1.Int()== KErrCancel);
       
   371     gPacketService.NotifyContextAdded(stat1, contextId);
       
   372     gTest(gPacketContext[0].OpenNewContext(gPacketService, context) == KErrNone);
       
   373     User::WaitForRequest(stat1);
       
   374     gTest(stat1.Int() == KErrNone);
       
   375 
       
   376     RPacketService::TStatus gprsStatus;
       
   377     gPacketService.NotifyStatusChange(stat2, gprsStatus);
       
   378     gPacketService.CancelAsyncRequest(EPacketNotifyStatusChange);
       
   379     User::WaitForRequest(stat2);
       
   380     gTest(stat2.Int() == KErrCancel);
       
   381 
       
   382     gPacketService.NotifyStatusChange(stat2, gprsStatus);
       
   383     gPacketService.Attach(stat1);
       
   384 	User::WaitForRequest(stat1);
       
   385 	gTest(stat1.Int() == KErrNone);
       
   386     User::WaitForRequest(stat2);
       
   387     gTest(stat2.Int() == KErrNone);
       
   388     gTest(gprsStatus == RPacketService::EStatusAttached);
       
   389 
       
   390 	User::After(1000000);	// Delay to allow phone to settle
       
   391 
       
   392     gPacketService.NotifyStatusChange(stat3, gprsStatus);
       
   393     gPacketService.Detach(stat1);
       
   394 	User::WaitForRequest(stat1);
       
   395 	gTest(stat1.Int() == KErrNone);
       
   396     User::WaitForRequest(stat3);
       
   397     gTest(stat3.Int() == KErrNone);
       
   398     gTest(gprsStatus == RPacketService::EStatusUnattached);
       
   399 
       
   400     gPacketContext[0].Close();
       
   401     gPacketService.Close();
       
   402     User::After(KOneSecond);
       
   403     }
       
   404 
       
   405 
       
   406 LOCAL_C void  GprsContextConfigTest()
       
   407 /**
       
   408  * Test context config.
       
   409  */
       
   410     {
       
   411     TRequestStatus stat1;
       
   412 	gTest(gPacketService.Open(gPhone ) == KErrNone);
       
   413     TBuf<30> contextName;
       
   414     gTest(gPacketContext[0].OpenNewContext(gPacketService, contextName) == KErrNone);
       
   415     gTest(gPacketContext[1].OpenNewContext(gPacketService, contextName) == KErrNone);
       
   416     
       
   417     RPacketContext::TContextConfigGPRS     Getparams;
       
   418     RPacketContext::TContextConfigGPRS     Setparams;
       
   419     TPckg<RPacketContext::TContextConfigGPRS>    GetcontextConfigPckg(Getparams);
       
   420     gPacketContext[0].GetConfig(stat1, GetcontextConfigPckg);
       
   421 	User::WaitForRequest(stat1);
       
   422 	gTest(stat1.Int() == KErrNone);
       
   423     Setparams = Getparams;
       
   424 
       
   425     TPckg<RPacketContext::TContextConfigGPRS>    SetcontextConfigPckg(Setparams);
       
   426     gPacketContext[0].SetConfig(stat1, SetcontextConfigPckg);
       
   427 	User::WaitForRequest(stat1);
       
   428 	gTest(stat1.Int() == KErrNone);
       
   429     gPacketContext[1].SetConfig(stat1, SetcontextConfigPckg);
       
   430 	User::WaitForRequest(stat1);
       
   431 	gTest(stat1.Int() == KErrNone);
       
   432     gPacketContext[0].GetConfig(stat1, SetcontextConfigPckg);
       
   433 	User::WaitForRequest(stat1);
       
   434 	gTest(stat1.Int() == KErrNone);
       
   435     TestConfigParams(Getparams, Setparams);
       
   436 
       
   437 	TRequestStatus stat;
       
   438 	gPacketContext[0].SetConfig(stat, SetcontextConfigPckg);
       
   439 	gPacketContext[0].CancelAsyncRequest(EPacketContextSetConfig);
       
   440 	User::WaitForRequest(stat);
       
   441 	gTest(stat.Int() == KErrCancel);
       
   442 
       
   443 	gPacketContext[0].GetConfig(stat, GetcontextConfigPckg);
       
   444 	gPacketContext[0].CancelAsyncRequest(EPacketContextGetConfig);
       
   445 	User::WaitForRequest(stat);
       
   446 	gTest(stat.Int() == KErrCancel);
       
   447 
       
   448 
       
   449 	Setparams.iPdpType = RPacketContext::TProtocolType(20); // Set out of range
       
   450 	TPckg<RPacketContext::TContextConfigGPRS>    errorPackage(Setparams);
       
   451 	gPacketContext[0].SetConfig(stat1, errorPackage);
       
   452 	User::WaitForRequest(stat1);
       
   453 	gTest(stat1.Int() == KErrNotSupported);
       
   454 
       
   455 
       
   456     gPacketContext[0].Close();
       
   457     gPacketContext[1].Close();
       
   458     gPacketService.Close();
       
   459     User::After(KOneSecond);
       
   460     }
       
   461 
       
   462 
       
   463 LOCAL_C void  GprsContextConfigNotificationsTest()
       
   464 /**
       
   465  * Test context notifications.
       
   466  */
       
   467     {
       
   468     TRequestStatus                      stat1, stat2;
       
   469     TBuf<30>                            contextName;
       
   470     RPacketContext::TContextConfigGPRS   params, notifyParams;
       
   471     TPckg<RPacketContext::TContextConfigGPRS>  contextConfigPckg(params);
       
   472     TPckg<RPacketContext::TContextConfigGPRS>  notifyContextConfigPckg(notifyParams);
       
   473     
       
   474     gTest(gPacketService.Open(gPhone ) == KErrNone);
       
   475     gTest(gPacketContext[0].OpenNewContext(gPacketService, contextName) == KErrNone);
       
   476     gTest(gPacketContext[1].OpenNewContext(gPacketService, contextName) == KErrNone);
       
   477     gPacketContext[0].NotifyConfigChanged(stat1, notifyContextConfigPckg);
       
   478     gPacketContext[0].CancelAsyncRequest(EPacketContextNotifyConfigChanged);
       
   479     User::WaitForRequest(stat1);
       
   480     gTest(stat1.Int() == KErrCancel);
       
   481 
       
   482     gPacketContext[0].GetConfig(stat1, contextConfigPckg);
       
   483 	User::WaitForRequest(stat1);
       
   484 	gTest(stat1.Int() == KErrNone);
       
   485     gPacketContext[0].NotifyConfigChanged(stat1, notifyContextConfigPckg);
       
   486     
       
   487 	gPacketContext[0].SetConfig(stat2, contextConfigPckg);
       
   488 	User::WaitForRequest(stat2);
       
   489 	gTest(stat2.Int() == KErrNone);
       
   490 
       
   491     User::WaitForRequest(stat1);
       
   492     gTest(stat1.Int() == KErrNone);
       
   493     TestConfigParams(params, notifyParams);
       
   494 	
       
   495     gPacketContext[0].Close();
       
   496     gPacketContext[1].Close();
       
   497     gPacketService.Close();
       
   498     User::After(KOneSecond);
       
   499     }
       
   500 
       
   501 
       
   502 LOCAL_C void  OpenGprsMaxContextsTest()
       
   503 /**
       
   504  *  Tests enumerate contexts, open new context, open existing context.
       
   505  */
       
   506     {
       
   507     TRequestStatus	stat1;
       
   508 	TBuf<20> contextName = _L("");
       
   509 
       
   510     gTest(gPacketService.Open(gPhone ) == KErrNone);
       
   511     TInt countContexts;
       
   512     TInt maxAllowedContexts;
       
   513     gPacketService.EnumerateContexts(stat1, countContexts, maxAllowedContexts);
       
   514 	User::WaitForRequest(stat1);
       
   515     gTest(countContexts == 0);
       
   516 	if(GPhoneBrand == EMotorola)
       
   517 		gTest(maxAllowedContexts == 3);
       
   518 	else if(GPhoneBrand == EEricsson)
       
   519 		gTest(maxAllowedContexts == 10);
       
   520     TInt i = 0;
       
   521     RPacketService::TContextInfo contextinfo;
       
   522 
       
   523     for(i = 0; i < maxAllowedContexts;i++)
       
   524         {
       
   525         RPacketContext contextPacket;
       
   526         TBuf<30> tmpContextName;
       
   527         tmpContextName = _L("GPRS_CONTEXT");
       
   528         tmpContextName.AppendNum(i+1);
       
   529         gTest(gPacketContext[i].OpenNewContext(gPacketService, contextName) == KErrNone);
       
   530         gPacketService.GetContextInfo(stat1, i, contextinfo);
       
   531 		User::WaitForRequest(stat1);
       
   532         gTest(contextinfo.iName == tmpContextName);
       
   533         gTest(contextinfo.iStatus == RPacketContext::EStatusUnknown);
       
   534         gTest(contextPacket.OpenExistingContext(gPacketService, contextName) == KErrNone);
       
   535         gTest(contextName == tmpContextName); 
       
   536         contextPacket.Close();
       
   537         }
       
   538     gTest(gPacketContext[i+5].OpenNewContext(gPacketService, contextName) == KErrOverflow);
       
   539 	
       
   540 	gPacketService.GetContextInfo(stat1, i+1, contextinfo);
       
   541 	User::WaitForRequest(stat1);
       
   542 	gTest(stat1.Int() == KErrArgument);
       
   543     for(i = 0; i < maxAllowedContexts;i++)
       
   544         {
       
   545         gPacketContext[i].Close(); 
       
   546         }
       
   547     gPacketService.Close();
       
   548 	User::After(KOneSecond);
       
   549     }
       
   550 
       
   551 
       
   552 
       
   553 LOCAL_C void GprsCancelTest()
       
   554 /**
       
   555  * This test will call all GPRS API calls 
       
   556  * that can be canceled with an outstanding request
       
   557  * to the phone.
       
   558  */ 
       
   559 	{
       
   560 	TRequestStatus	stat;
       
   561 	
       
   562 	gTest(gPacketService.Open(gPhone ) == KErrNone);
       
   563 
       
   564 	gPacketService.Attach(stat);
       
   565 	gPacketService.CancelAsyncRequest(EPacketAttach);
       
   566 	User::WaitForRequest(stat);
       
   567 	gTest(stat.Int() == KErrCancel);
       
   568 
       
   569 	gPacketService.Detach(stat);
       
   570 	gPacketService.CancelAsyncRequest(EPacketDetach);
       
   571 	User::WaitForRequest(stat);
       
   572 	gTest(stat.Int() == KErrCancel);
       
   573 
       
   574 	RPacketService::TMSClass currentClass;
       
   575 	RPacketService::TMSClass maxClass;
       
   576 
       
   577 	gPacketService.GetMSClass(stat, currentClass, maxClass);
       
   578 	gPacketService.CancelAsyncRequest(EPacketGetMSClass);
       
   579 	User::WaitForRequest(stat);
       
   580 	gTest((stat.Int() == KErrCancel)||(stat.Int() == KErrNone));
       
   581 
       
   582 	currentClass = RPacketService::EMSClassSuspensionRequired;
       
   583 	gPacketService.SetMSClass(stat, currentClass);
       
   584 	gPacketService.CancelAsyncRequest(EPacketSetMSClass);
       
   585 	User::WaitForRequest(stat);
       
   586 	gTest(stat.Int() == KErrCancel);
       
   587 
       
   588 	gPacketService.Close();
       
   589 	User::After(KOneSecond);
       
   590 	}
       
   591 
       
   592 
       
   593 LOCAL_C void  GprsDownloadWebbPageTestL()
       
   594 
       
   595 /**
       
   596  * This test will open a socket and download a
       
   597  * page/file that is specified by KTestCfgHTTPServerIpAddress
       
   598  * and KTestCfgHTTPPageAddress
       
   599  *
       
   600  */
       
   601 
       
   602 	{
       
   603 	// Constants used for this test.
       
   604 	const TInt KWebPort = 80;
       
   605 	const TPtrC testAddr = testConfigParams->FindAlphaVar(KTestCfgHTTPServerIpAddress,KNullDesC);
       
   606 	const TPtrC testPage = testConfigParams->FindAlphaVar(KTestCfgHTTPPageAddress,KNullDesC);
       
   607 	
       
   608 	HBufC8* iWebPage = HBufC8::NewMaxL(4096);
       
   609 
       
   610 	
       
   611 	gTest.Printf(_L("Send HTML request\n"));
       
   612 	RSocket sock;
       
   613 	gTest.Printf(_L("Open tcpip socket\n"));
       
   614 	gTest(sock.Open(gSocketServer, KAfInet, KSockStream, KProtocolInetTcp) == KErrNone);
       
   615 
       
   616 	TInetAddr addr(KWebPort);
       
   617 	addr.Input(testAddr );
       
   618 	TRequestStatus stat;
       
   619 
       
   620 	gTest.Printf(_L("Connecting to socket\n"));
       
   621 	sock.Connect(addr, stat);
       
   622 	WaitWithTimeout(stat);
       
   623 	User::LeaveIfError(stat.Int());
       
   624 
       
   625 	// List the route to the server.
       
   626 	gTest.Printf(_L("List the route to the server\n"));
       
   627 	ListRoutes(sock);
       
   628 
       
   629 	TPtr8 des(iWebPage->Des());
       
   630 	des.Copy(_L("GET"));
       
   631 	des.Append(testPage);
       
   632 	des.Append(_L(" \r\n\r\n"));
       
   633 
       
   634 	gTest.Printf(_L("Writing data to socket\n"));
       
   635 	sock.Write(*iWebPage, stat);
       
   636 	WaitWithTimeout(stat);
       
   637 	User::LeaveIfError(stat.Int());
       
   638 	gTest.Printf(_L("Sent request OK\n"));
       
   639 
       
   640 	TSockXfrLength HTTPHeaderLen;
       
   641 	TInt rcount = 0;
       
   642 	TTime startTime;
       
   643 	startTime.UniversalTime();
       
   644 	FOREVER
       
   645 		{
       
   646 		des.Zero();
       
   647 		sock.RecvOneOrMore(des,0,stat,HTTPHeaderLen);
       
   648 		User::WaitForRequest(stat);//, readStat);
       
   649 		if(stat!=KErrNone)
       
   650 			break;
       
   651 		rcount += iWebPage->Length();
       
   652 		gTest.Console()->SetPos(0);
       
   653 		gTest.Printf(_L("\rRecved:%10d Bytes"), rcount);
       
   654 		}
       
   655 
       
   656 	if(stat.Int() != KErrEof)
       
   657 		User::Leave(KErrEof);
       
   658 
       
   659 	// Calculate the number of bytes per second.
       
   660 	TTime stopTime;
       
   661 	stopTime.UniversalTime();
       
   662 	TTimeIntervalMicroSeconds totalTime = stopTime.MicroSecondsFrom(startTime);
       
   663 	TInt64 byteRate(rcount);
       
   664 	byteRate *= KOneSecond;
       
   665 	byteRate /=totalTime.Int64();
       
   666 	gTest.Printf(_L("\n"));
       
   667 	gTest.Printf(_L("Rate: %d B/s\n"), I64INT(byteRate));
       
   668 	gTest.Printf(_L("Received HTML page OK\n"));
       
   669 
       
   670 	// Close the socket.
       
   671 	sock.Close();
       
   672 	// Stop the agent so that the we will be disconnected from the network.
       
   673 //	gGenericAgent.Stop();
       
   674 	conn.Stop();
       
   675 	
       
   676 	// Delete the webpage buffer.
       
   677 	delete iWebPage;
       
   678 	User::After(KFiveSeconds);
       
   679 	}
       
   680 
       
   681 
       
   682 LOCAL_C void TestGprsfaxCancel()
       
   683 /**
       
   684  * This function tests the opening of 2 call objects
       
   685  * and doing a hang-up on them while there is a 
       
   686  * GPRS object in the system.
       
   687  */
       
   688 	{
       
   689     TBuf<100>                           Context;
       
   690     TRequestStatus stat1, stat2;
       
   691     Context = _L("");
       
   692     _LIT(KFaxLineName,"Fax");
       
   693     _LIT(KVoiceLineName,"Voice");
       
   694 
       
   695     gTest(gPacketService.Open(gPhone ) == KErrNone);
       
   696     RLine faxLine;
       
   697     RCall call;
       
   698 	RCall call2;
       
   699     RLine voiceLine;
       
   700     TName callName;
       
   701     faxLine.Open(gPhone ,KFaxLineName);
       
   702     voiceLine.Open(gPhone ,KVoiceLineName);
       
   703     gTest(gPhone .Initialise()==KErrNone);
       
   704     faxLine.NotifyIncomingCall(stat1,callName);
       
   705 	faxLine.NotifyIncomingCallCancel();
       
   706 	voiceLine.NotifyIncomingCall(stat1,callName);
       
   707     voiceLine.NotifyIncomingCallCancel();
       
   708     User::WaitForRequest(stat1);
       
   709 	User::WaitForRequest(stat2);
       
   710     gTest(call.OpenNewCall(voiceLine)==KErrNone);
       
   711     gTest(call.HangUp()==KErrNone);
       
   712     gTest(call2.OpenNewCall(faxLine)==KErrNone);
       
   713     gTest(call2.HangUp()==KErrNone);
       
   714 
       
   715     call.Close();
       
   716 	call2.Close();
       
   717     voiceLine.Close();
       
   718     faxLine.Close();
       
   719     gPacketService.Close();
       
   720 	}
       
   721 
       
   722 
       
   723 LOCAL_C void  TestOpenContextByNameL()
       
   724 /**
       
   725  * This test should verify that defect SHY-54SNHT is fixed.
       
   726  */
       
   727 	{
       
   728 	User::LeaveIfError(gPacketService.Open(gPhone));
       
   729   TBuf<30> contextName;
       
   730 	User::LeaveIfError(gPacketContext[0].OpenNewContext(gPacketService,contextName));
       
   731 	User::LeaveIfError(gPacketContext[1].OpenExistingContext(gPacketService,contextName));
       
   732 	gPacketService.Close();
       
   733 	}
       
   734 
       
   735 
       
   736 LOCAL_C void  TestNetworkRegStatusL()
       
   737 /**
       
   738  * This test does a basic test on the Get Current Network 
       
   739  * Registration Status functionality.
       
   740  */
       
   741 	{
       
   742 	User::LeaveIfError(gPacketService.Open(gPhone));
       
   743 	RPacketService::TRegistrationStatus regStatus;
       
   744 	TRequestStatus status;
       
   745 	gPacketService.GetNtwkRegStatus(status,regStatus);
       
   746 	User::WaitForRequest(status);
       
   747 	if(status!=KErrNone && status!=KErrNotSupported)		// Do not consider KErrNotSupported a failure
       
   748 		{
       
   749 		gPacketService.Close();
       
   750 		User::Leave(status.Int());
       
   751 		}
       
   752 	gPacketService.Close();
       
   753 	}
       
   754 
       
   755 
       
   756 LOCAL_C void TestGetStaticCapsL()
       
   757 /**
       
   758  * Simple test for RPacketService::GetStaticCaps
       
   759  */
       
   760  	{
       
   761 	User::LeaveIfError(gPacketService.Open(gPhone));
       
   762 
       
   763 	//
       
   764 	// Call RPacketService::GetStaticCaps with EPdpTypeIPv6
       
   765 	// We would expect this call to fail with KErrNotSupported
       
   766 	TUint caps(0);		// Create and initialise caps
       
   767 	TInt ret=gPacketService.GetStaticCaps(caps,RPacketContext::EPdpTypeIPv6);
       
   768 	GLOBAL_CHECKPOINT_COMPARE(ret,KErrNotSupported,_L("Expected KErrNotSupported for GetStaticCaps with EPdpTypeIPv6"));
       
   769 
       
   770 	//
       
   771 	// Call RPacketService::GetStaticCaps
       
   772 	caps=0;		// Intialise caps
       
   773 	User::LeaveIfError(gPacketService.GetStaticCaps(caps,RPacketContext::EPdpTypeIPv4));
       
   774 
       
   775 	//
       
   776 	// Validate caps returned by GetStaticCaps.
       
   777 	// (we know what the values should be as they specified in the MMTSY design document
       
   778 	//  are harcoded in the MMTSY)
       
   779 	GLOBAL_CHECKPOINT_COMPARE(caps,RPacketService::KCapsSetDefaultContextSupported|RPacketService::KCapsMSClassSupported,_L("Unexpcted Static Caps"));
       
   780 
       
   781 	gPacketService.Close();
       
   782 	}
       
   783 
       
   784 
       
   785 LOCAL_C void TestOpenExistingContextL()
       
   786 /**
       
   787  * Simple test for RPacketService::OpenExistingContext.
       
   788  * This test should verify the fix for defect SHY-54SNHT.
       
   789  * If SHY-54SNHT has not been fixed an access violation will occur in Etel during the 
       
   790  * OPenExistingContext call.
       
   791  */
       
   792 	{
       
   793 	RPacketService packetService;
       
   794 	User::LeaveIfError(packetService.Open(gPhone));
       
   795 
       
   796 	//
       
   797 	// Open context using an invalid context name (call should fail with KErrNotFound)
       
   798 	RPacketContext context;
       
   799 	_LIT(KUnknownContextName,"NonExistantContext");
       
   800 	TInt ret=context.OpenExistingContext(packetService,KUnknownContextName);
       
   801 	GLOBAL_CHECKPOINT_COMPARE(ret,KErrNotFound,_L("RPacketContext::OpenExistingContext did not fail when it should have"));
       
   802 
       
   803 	packetService.Close();
       
   804 	}
       
   805 
       
   806 
       
   807 
       
   808 LOCAL_C void TestConfigParams(RPacketContext::TContextConfigGPRS& aArg1, RPacketContext::TContextConfigGPRS& aArg2)
       
   809 	{
       
   810 	gTest(aArg1.iPdpType                      == aArg2.iPdpType);
       
   811     gTest(aArg1.iAccessPointName              == aArg2.iAccessPointName );
       
   812     gTest(aArg1.iPdpCompression               == aArg2.iPdpCompression);
       
   813 	gTest(aArg1.iPdpAddress                   == aArg2.iPdpAddress);
       
   814 	gTest(aArg1.iAnonymousAccessReqd          == aArg2.iAnonymousAccessReqd);
       
   815 	}
       
   816 
       
   817 const TAutoTestCase KGPRSTestCases[] =
       
   818 /**
       
   819  * List of all test cases. It consists of a function pointer and a text label.
       
   820  */
       
   821 	{   
       
   822   {GprsDefaultContextParamsTest,        _S("GprsDefaultContextParamsTest ")},
       
   823   {GprsUnSupportedTest,                 _S("GprsUnSupportedTest ")},  
       
   824   {GprsContextAttachTest,               _S("GprsContextAttachTest ")},        
       
   825   {GprsContextDeleteTest,               _S("GprsContextDeleteTest ")},        
       
   826   {GprsContextLoanComport,              _S("GprsContextLoanComport ")},       
       
   827   {GprsContextUnSupportedTest,          _S("GprsContextUnSupportedTest ")},   
       
   828   {GprsAttachTestL,                      _S("GprsAttachTest ")},
       
   829   {GprsNotificationTest,                _S("GprsNotificationTest ")},
       
   830   {GprsMsClassTest,                     _S("GprsMsClassTest ")},
       
   831   {GprsContextConfigTest,               _S("GprsContextConfigTest ")},
       
   832   {GprsContextConfigNotificationsTest,  _S("GprsContextConfigNotificationsTest ")},
       
   833   {OpenGprsMaxContextsTest,             _S("OpenGprsMaxContextsTest")},
       
   834 	{GprsCancelTest,			          _S("GprsCancelTest ")},
       
   835 	{TestGprsfaxCancel,					 _S("TestGprsfaxCancel ")},
       
   836 	{TestOpenContextByNameL,					 _S("TestOpenContextByName")},
       
   837 	{TestNetworkRegStatusL,					 _S("TestNetworkRegStatus")},
       
   838 	{TestGetStaticCapsL,					 _S("TestGetStaticCaps")},
       
   839 	{TestOpenExistingContextL,					 _S("TestOpenExistingContext")},
       
   840 	{GprsDownloadWebbPageTestL,           _S("GprsDownloadWebbPageTest ")},
       
   841 	};
       
   842 
       
   843 
       
   844 GLDEF_C void AutoTestExecute()
       
   845     {
       
   846     _LIT(KGPRSTestReport, "gprs_testreport.txt");
       
   847     _LIT8(KGPRSCompInfo, "MM.TSY");
       
   848     GLOBAL_AUTOTEST_EXECUTE(KGPRSTestCases, KGPRSTestReport, KGPRSCompInfo, gTest );
       
   849     }
       
   850 
       
   851 
       
   852 LOCAL_C TInt ListRoutes(RSocket& aSocket)
       
   853  
       
   854 /**
       
   855  * This function lists all the hops that the packet 
       
   856  * needs to make to reach the port on the server.
       
   857  */
       
   858 
       
   859 	{
       
   860 
       
   861 	TPckgBuf<TSoInetRouteInfo> opt;
       
   862 	TInt ret;
       
   863 	ret = aSocket.SetOpt(KSoInetEnumRoutes, KSolInetRtCtrl);
       
   864 	if (ret!=KErrNone)
       
   865 		return ret;
       
   866 
       
   867 	gTest.Printf(_L("  Destination      NetMask        Gateway      Interface  State Metric Type\r\n"));
       
   868 	while (ret==KErrNone)
       
   869 		{
       
   870 		ret = aSocket.GetOpt(KSoInetNextRoute, KSolInetRtCtrl, opt);
       
   871 		if (ret!=KErrNone)
       
   872 			continue;
       
   873 		TBuf<40> ia, ga, da, nm;
       
   874 		opt().iDstAddr.Output(da);
       
   875 		opt().iNetMask.Output(nm);
       
   876 		opt().iGateway.Output(ga);
       
   877 		opt().iIfAddr.Output(ia);
       
   878 		gTest.Printf(_L("%15S %15S %15S %15S %d %d %d\r\n"), &da, &nm, &ga, &ia, opt().iState, opt().iMetric, opt().iType);
       
   879 		}
       
   880 	return ret==KErrEof ? KErrNone : ret;
       
   881 	}
       
   882 
       
   883