datacommsserver/esockserver/test/TE_ESock/EsockTestSection28.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2003-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 // This contains ESock Test cases from section 28
       
    15 // Integration test for IPv6 static DNS configuration.
       
    16 //
       
    17 //
       
    18 
       
    19 // EPOC includes
       
    20 #include <e32base.h>
       
    21 #include <in_sock.h>
       
    22 #include <es_sock.h>
       
    23 #include <nifman.h>
       
    24 #include <commdbconnpref.h>
       
    25 
       
    26 // Test system includes
       
    27 #include "EsockTestSection28.h"
       
    28 #include <comms-infras/esocktestutils.h>
       
    29 
       
    30 //
       
    31 // Base class for Test 28 containing common code
       
    32 // 
       
    33 
       
    34 CEsockTest28::~CEsockTest28()
       
    35 /**
       
    36 Destructor for common base class CEsockTest28
       
    37 
       
    38   destroy the interface names array
       
    39   */
       
    40 	{
       
    41 	iNames.ResetAndDestroy();
       
    42 	iNames.Close();
       
    43 	}
       
    44 
       
    45 
       
    46 void CEsockTest28::NameInit()
       
    47 	{
       
    48 	}
       
    49 
       
    50 TInt CEsockTest28::NameAppendL(const TDesC& aName)
       
    51 /**
       
    52 Add a name to the interface names array
       
    53 
       
    54   @param aName interface name to add
       
    55   @return KErrNone or a system wide error code
       
    56   */
       
    57 	{
       
    58 	return iNames.Append(aName.AllocL());
       
    59 	}
       
    60 
       
    61 TBool CEsockTest28::NameFound(const TDesC& aName)
       
    62 /**
       
    63 Check whether a name is present in the interface names array
       
    64 
       
    65   @param aName interface name to check
       
    66   @return ETrue if name is present else EFalse
       
    67   */
       
    68 	{
       
    69 	TInt count = iNames.Count();
       
    70 	for (TInt i = 0 ; i < count ; i++)
       
    71 		{
       
    72 		if (*iNames[i] == aName)
       
    73 			{
       
    74 			return ETrue;
       
    75 			}
       
    76 		}
       
    77 	return EFalse;
       
    78 	}
       
    79 
       
    80 void CEsockTest28::NamePrint()
       
    81 /**
       
    82 Print out the interface names array
       
    83 */
       
    84 	{
       
    85 	Logger().WriteFormat(_L("Interface names: "));
       
    86 	TInt count = iNames.Count();
       
    87 	for (TInt i = 0 ; i < count ; i++)
       
    88 		{
       
    89 		Logger().WriteFormat(_L("\t%S"), iNames[i]);
       
    90 		}
       
    91 	}
       
    92 
       
    93 TVerdict CEsockTest28::Ipv6StaticDnsTestL(TInt aSubStep)
       
    94 /**
       
    95 Test IPv6 Static DNS Configuration for different NIF's
       
    96 
       
    97   This routine contains common base class code for tests in
       
    98   section 28.
       
    99   
       
   100 	The test is used to check that a particular NIF is taking
       
   101 	into account the following CommDb parameters:
       
   102 	
       
   103 	  
       
   104 		Ip6DNSAddrFromServer
       
   105 		Ip6NameServer1
       
   106 		Ip6NameServer2
       
   107 		
       
   108 		  Basic strategy:
       
   109 		  
       
   110 			1.  Retrieve configuration information from ini file (IAP, DNS addresses)
       
   111 			2.  Start the NIF to test via RConnection
       
   112 			3.  Retrieve the interface binder names (via RConnection KConnGetInterfaceName)
       
   113 			4.  Retrieve all TCP/IP interface information (via KSoInetNextInterface socket option)
       
   114 			5.  For each interface retrieved in (4), match its name against the names retrieved
       
   115 			in (3) (to find the TCP/IP interface(s) corresponding to the RConnection) and
       
   116 			ensure that its DNS addresses match those in the Ini file (which, in turn, match
       
   117 			those in the CommDb).
       
   118 			
       
   119 			  The test code in this routine is executed for each Test 28 substep.
       
   120 			  Each substep is used to test a different NIF, with the aSubStep parameter being used
       
   121 			  to index into a different section of the ini file to retrieve the parameters
       
   122 			  needed for the particular substep (in particular, the IAP to start).
       
   123 			  
       
   124 				@param aSubStep Sub step number
       
   125 				@return TVerdict code
       
   126 				*/
       
   127 	{
       
   128     TVerdict    verdict = EPass;
       
   129 	
       
   130     Logger().WriteFormat(_L("Testing IPv6 static DNS configuration"));
       
   131 	
       
   132 	TInt err;
       
   133 	
       
   134 	
       
   135 	// Retrieve the IAP for the particular test from the Ini file.
       
   136 	
       
   137 	TBuf<50> sectionBuf;
       
   138 	sectionBuf.Format(_L("Test_28.%d"), aSubStep);
       
   139 	TInt iap;
       
   140 	
       
   141 	if (!GetIntFromConfig(sectionBuf, KKeyIap(), iap))					// retrieve IAP
       
   142 		{
       
   143 		Logger().WriteFormat(_L("Cannot retrieve IAP from Ini file"));
       
   144 		return EAbort;
       
   145 		}
       
   146 	
       
   147 	// Connect to ESOCK
       
   148 	
       
   149 	RSocketServ ss;
       
   150 	err = ss.Connect();
       
   151 	TESTEL(KErrNone == err, err);
       
   152 	
       
   153 	RConnection conn;
       
   154 	err = conn.Open(ss);
       
   155 	TESTEL(KErrNone == err, err);
       
   156 	
       
   157 	CleanupClosePushL(conn);
       
   158 	
       
   159 	// Start up the RConnection
       
   160 	
       
   161 	TCommDbConnPref pref;
       
   162 	pref.SetIapId(iap);
       
   163 	pref.SetDialogPreference(ECommDbDialogPrefDoNotPrompt);
       
   164 	err = conn.Start(pref);
       
   165 	
       
   166 	if (err == KErrHardwareNotAvailable)
       
   167 		{
       
   168 		TPtrC isEthernet;
       
   169 		if (GetStringFromConfig(sectionBuf, KKeyEthernet(), isEthernet))
       
   170 			{
       
   171 			if (isEthernet == _L("true"))
       
   172 				Logger().WriteFormat(_L("*** Test step requires Ethernet setup ***"));
       
   173 			}
       
   174 		}
       
   175 	
       
   176 	TESTEL(KErrNone == err, err);
       
   177 	
       
   178 	// Read the primary and secondary DNS addresses from CommDb
       
   179 	
       
   180 	TBuf<KMaxAddressTextSize> IniPrimary;
       
   181 	TBuf<KMaxAddressTextSize> IniSecondary;
       
   182 	
       
   183 	err = conn.GetDesSetting(TPtrC(SERVICE_IP6_NAME_SERVER1), IniPrimary);
       
   184 	TESTEL(KErrNone == err, err);
       
   185 	
       
   186 	err = conn.GetDesSetting(TPtrC(SERVICE_IP6_NAME_SERVER2), IniSecondary);
       
   187 	TESTEL(KErrNone == err, err);
       
   188 	
       
   189 	TInetAddr primaryAddr;
       
   190 	TInetAddr secondaryAddr;
       
   191 	
       
   192 	primaryAddr.Input(IniPrimary);
       
   193 	secondaryAddr.Input(IniSecondary);
       
   194 	
       
   195 	// Retrieve the interface names
       
   196 	
       
   197 	TConnInterfaceName name;
       
   198 	name.iIndex = 1;
       
   199 	
       
   200 	NameInit();
       
   201 	
       
   202 	TPckg<TConnInterfaceName> namePkg(name);
       
   203 	do
       
   204 		{
       
   205 		err = conn.Control(KCOLProvider, KConnGetInterfaceName, namePkg);
       
   206 		
       
   207 		if (!NameFound(name.iName))
       
   208 			{
       
   209 			NameAppendL(name.iName);
       
   210 			}
       
   211 		
       
   212 		name.iIndex++;
       
   213 		}
       
   214 	while (err == KErrNone);
       
   215 	
       
   216 	NamePrint();
       
   217 	
       
   218 	// - read information from TCPIP6 about each interface and its addresses (via
       
   219 	//   socket options).
       
   220 	// - find the TCPIP6 interfaces relevant to the RConnection by matching the
       
   221 	//	 interface names retrieved above with each interface entry returned by TCPIP6.
       
   222 	// - for each matching interface, check to see if the primary and secondary DNS
       
   223 	//   addresses match those that we are testing.  If a match is found, the test passes,
       
   224 	//   else it fails.
       
   225 	
       
   226 	RSocket sock;
       
   227 	err = sock.Open(ss, KAfInet, KSockDatagram, KProtocolInetUdp);
       
   228 	TESTEL(KErrNone == err, err);
       
   229 	
       
   230 	CleanupClosePushL(sock);
       
   231 	
       
   232 	Logger().WriteFormat(_L("Interface DNS addresses:"));
       
   233 	err = sock.SetOpt(KSoInetEnumInterfaces, KSolInetIfCtrl);
       
   234 	TESTEL(KErrNone == err, err);
       
   235 	
       
   236 	TSoInetInterfaceInfo info;
       
   237 	TPckg<TSoInetInterfaceInfo> opt(info);
       
   238 	
       
   239 	
       
   240 	TBool found = EFalse;
       
   241 	
       
   242 	do {
       
   243 		// Retrieve information about next interface (actually, interface address)
       
   244 		err = sock.GetOpt(KSoInetNextInterface, KSolInetIfCtrl, opt);
       
   245 		if (err == KErrNone)
       
   246 			{
       
   247 			if (!info.iAddress.IsUnspecified())
       
   248 				{
       
   249 				// Check first if it is an address associated with the RConnection
       
   250 				if (NameFound(info.iName))
       
   251 					{
       
   252 					if (!info.iNameSer1.IsUnspecified() && !info.iNameSer2.IsUnspecified())
       
   253 						{
       
   254 						TBuf<KMaxAddressTextSize> primary;
       
   255 						TBuf<KMaxAddressTextSize> secondary;
       
   256 						
       
   257 						info.iNameSer1.Output(primary);
       
   258 						info.iNameSer2.Output(secondary);
       
   259 						
       
   260 						if (primary.Length() > 0 && secondary.Length() > 0)
       
   261 							{
       
   262 							Logger().WriteFormat(_L("\t%S:\tprimary = %S, secondary = %S"), &info.iName, &primary, &secondary);
       
   263 							// Match primary and secondary addresses with the interface
       
   264 							if (info.iNameSer1.Match(primaryAddr) && info.iNameSer2.Match(secondaryAddr))
       
   265 								{
       
   266 								Logger().WriteFormat(_L("Interface DNS addresses match for %S"), &info.iName);
       
   267 								found = ETrue;
       
   268 								break;
       
   269 								}
       
   270 							}
       
   271 						}
       
   272 					}
       
   273 				}
       
   274 			}
       
   275 		else
       
   276 			TESTEL(KErrNotFound == err, err);
       
   277 		}
       
   278 	while (err != KErrNotFound);
       
   279 	
       
   280 	// Close socket
       
   281 	
       
   282 	sock.Close();
       
   283 	CleanupStack::Pop(&sock);
       
   284 	
       
   285 	if (!found)
       
   286 		{
       
   287 		verdict = EFail;
       
   288 		}
       
   289 	
       
   290 	// Close connection
       
   291 	
       
   292 	conn.Stop();
       
   293 	conn.Close();
       
   294 	CleanupStack::Pop(&conn);
       
   295 	
       
   296 	ss.Close();
       
   297 	
       
   298 	return verdict;
       
   299 	}
       
   300 	
       
   301 	
       
   302 	
       
   303 const TDesC& CEsockTest28_1::GetTestName()
       
   304 /**
       
   305 Constructor for Test 28.1
       
   306 */
       
   307 	{
       
   308 	// store the name of this test case
       
   309 	_LIT(ret,"Test28.1");
       
   310 	
       
   311 	return ret;
       
   312 	}
       
   313 
       
   314 TVerdict CEsockTest28_1::doTestStepPreambleL()
       
   315 /**
       
   316 Preamble for Test 28.1
       
   317 
       
   318   Cleans up pending connections, otherwise KErrInUse occurs as
       
   319   we try to start up a IAP using same COMM port.
       
   320   
       
   321 	@return TVerdict code indicating test result of preamble
       
   322 	*/
       
   323 	{
       
   324 	TBuf<200> errDesc;
       
   325 	ESockTestUtils::StopAllInterfaces(errDesc);
       
   326 	return EPass;
       
   327 	}
       
   328 
       
   329 TVerdict CEsockTest28_1::easyTestStepL()
       
   330 /**
       
   331 Test step 28.1
       
   332 
       
   333   IPv6 static DNS configuration (PPP NIF)
       
   334   
       
   335 	Requires a connection
       
   336 	
       
   337 	  @return TVerdict code indicating test result
       
   338 	  */
       
   339 	{
       
   340 	return Ipv6StaticDnsTestL(1);
       
   341 	}
       
   342 
       
   343 
       
   344 const TDesC& CEsockTest28_2::GetTestName()
       
   345 /**
       
   346 Constructor for Test 28.2
       
   347 */
       
   348 	{
       
   349 	// store the name of this test case
       
   350 	_LIT(ret,"Test28.2");
       
   351 	
       
   352 	return ret;
       
   353 	}
       
   354 
       
   355 TVerdict CEsockTest28_2::easyTestStepL()
       
   356 /**
       
   357 Test step 28.2
       
   358 
       
   359   IPv6 static DNS configuration (Ethernet NIF)
       
   360   
       
   361 	Requires Ethernet NIF to be setup (but does not transmit packets)
       
   362 	
       
   363 	  @return TVerdict code indicating test result
       
   364 	  */
       
   365 	{
       
   366 	return Ipv6StaticDnsTestL(2);
       
   367 	}
       
   368 //
       
   369 
       
   370