datacommsserver/esockserver/test/TE_ESock/EsockTestSection27.cpp
changeset 0 dfb7c4ff071f
equal deleted inserted replaced
-1:000000000000 0:dfb7c4ff071f
       
     1 // Copyright (c) 2001-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 27
       
    15 // Integration test for DNS Query interface.
       
    16 // Note: These tests try to make different queries to the external DNS, using network connection.
       
    17 // This test requires a network connection and a properly configured DNS.
       
    18 // See also appropriate ini file, which contains information about DNS requests for testing.
       
    19 // 
       
    20 //
       
    21 
       
    22 // EPOC includes
       
    23 #include <e32base.h>
       
    24 #include <in_sock.h>
       
    25 #include <dns_qry.h>
       
    26 
       
    27 // Test system includes
       
    28 #include "EsockTestSection27.h"
       
    29 
       
    30 
       
    31 #ifdef _DEBUG
       
    32 // Panic category for "absolutely impossible!" vanilla ASSERT()-type panics from this module
       
    33 // (if it could happen through user error then you should give it an explicit, documented, category + code)
       
    34 _LIT(KSpecAssert_ESockTestEsckTst, "ESockTestEsckTst");
       
    35 #endif
       
    36 
       
    37 
       
    38 const TInt  KMaxStrLen = 256;
       
    39 
       
    40 // From ../../networking/inhook6/inc/dnd_err.h
       
    41 const TInt KErrDndNameNotFound = -5120; 
       
    42 
       
    43 
       
    44 //-------------------------------------------------------------------------------------------------------
       
    45 
       
    46 
       
    47 /**
       
    48 *   test preamble: open Host Resolver for using with implicit connection 
       
    49 */
       
    50 
       
    51 TVerdict CTestRHostRslvQuery_27::doTestStepPreambleL (void)
       
    52     {
       
    53     
       
    54     TInt    ret;
       
    55     
       
    56     //-- open host resolver on UDP
       
    57     Logger().WriteFormat(_L("Opening host resolver on UDP using implicit connection scenario"));
       
    58     ret = iHostRslv.Open(iEsockSuite->iSocketServer, KAfInet, KProtocolInetUdp);
       
    59     
       
    60     if(ret != KErrNone)
       
    61         {
       
    62         Logger().WriteFormat(_L("iHostRslv.Open error code: %d"), ret);    
       
    63         return EFail;
       
    64         }
       
    65     
       
    66     return EPass;
       
    67     }
       
    68 
       
    69 	/**
       
    70 	*   test postamble: close Host Resolver
       
    71 */
       
    72 TVerdict CTestRHostRslvQuery_27::doTestStepPostambleL(void)
       
    73     {
       
    74     Logger().WriteFormat(_L("Closing host resolver"));
       
    75     iHostRslv.Close();
       
    76     
       
    77     return EPass;
       
    78     }
       
    79 
       
    80 //-------------------------------------------------------------------------------------------------------
       
    81 
       
    82 /**
       
    83 *   Read string from .ini file into 8-bit string descriptor
       
    84 *
       
    85 *   @param  aSectName section name descriptor.
       
    86 *   @param  aKeyName  key name descriptor.  
       
    87 *   @param  aStr      ref. to the 8-bit descriptor for the result string.  
       
    88 *
       
    89 *   @return ETrue on success.
       
    90 */
       
    91 TBool   CTestRHostRslvQuery_27::GetIniFileString8(const TDesC &aSectName, const TDesC &aKeyName, TDes8& aStr)
       
    92     {
       
    93     TBuf<KMaxStrLen>    buff;
       
    94     TPtrC               buffPtr(buff);
       
    95     
       
    96     TBool bRes = GetStringFromConfig(aSectName, aKeyName, buffPtr);
       
    97     
       
    98     if(bRes)
       
    99         aStr.Copy(buffPtr);
       
   100     
       
   101     return bRes;
       
   102     }
       
   103 
       
   104 	/**
       
   105 	*   read IP address from .ini file, the address may have either IPv4 or IPv6 format.
       
   106 	*
       
   107 	*   @param  aSectName section name descriptor.
       
   108 	*   @param  aKeyName  key name descriptor.  
       
   109 	*   @param  aInetAddr will contain result.
       
   110 	*
       
   111 	*   @return ETrue on success
       
   112 */
       
   113 TBool   CTestRHostRslvQuery_27::GetIniFileIpAddr(const TDesC &aSectName, const TDesC &aKeyName, TInetAddr& aInetAddr)
       
   114     {
       
   115     TBuf<KMaxStrLen>    buff;
       
   116     TPtrC               buffPtr(buff);
       
   117     
       
   118     TBool bRes = GetStringFromConfig(aSectName, aKeyName, buffPtr);
       
   119     if(!bRes) 
       
   120         return EFalse;
       
   121     
       
   122     return aInetAddr.Input(buffPtr) == KErrNone ? ETrue : EFalse;
       
   123     }
       
   124 
       
   125 
       
   126 /**
       
   127 *   Internal helper function to handle DND error codes
       
   128 *   
       
   129 *   @param  aErrCode    original code to process
       
   130 *   @param  aEntryCount determines whether it was Query() 0 or QueryGetNext >0
       
   131 *   @return possibly    modified new code.
       
   132 */
       
   133 TInt CTestRHostRslvQuery_27::ProcessDndError(TInt aErrCode, TInt aEntryCount)
       
   134 	{
       
   135     __ASSERT_DEBUG(aEntryCount >=0, User::Panic(KSpecAssert_ESockTestEsckTst, 1));
       
   136     
       
   137     if(aErrCode == KErrNone)
       
   138         return KErrNone;
       
   139 	
       
   140     if(aErrCode == KErrNotFound || aErrCode == KErrDndNameNotFound)
       
   141 		{
       
   142 		
       
   143         if(aEntryCount == 0)
       
   144 			{//-- no result at all for the first Query(). DNS may be down or just has no records
       
   145 			//-- int his case test is inconsistent.
       
   146 			return KErrNotFound;
       
   147 			}
       
   148         else
       
   149 			{//-- OK, no more resulsts for QueryGetNext(), normal situation
       
   150 			return KErrNone;
       
   151 			}
       
   152 		}
       
   153 	else //-- real error
       
   154 		{    
       
   155 		TBuf<KMaxStrLen>  tmpBuf;
       
   156 		tmpBuf.Format(_L("! Query finished with error code:%d"), aErrCode);
       
   157 		Logger().WriteFormat(tmpBuf);
       
   158 		}
       
   159 	
       
   160 	return aErrCode;
       
   161 	}
       
   162 
       
   163 
       
   164 	/**
       
   165 	*   Requests all RR of type 'A' for the given host and prints them out
       
   166 	*
       
   167 	*   @param      aHostName name of the nost
       
   168 	*
       
   169 	*   @return     standard error code
       
   170 */
       
   171 TInt    CTestRHostRslvQuery_27::ListDnsRecordsA(const TDesC8& aHostName)
       
   172     {
       
   173     TInt    ret = KErrNone;
       
   174     
       
   175     TDnsQueryBuf      dnsQryBuf;
       
   176     TDnsRespABuf      dnsRespABuf;
       
   177     TBuf<KMaxStrLen>  addrBuf;
       
   178     TBuf<KMaxStrLen>  tmpBuf;
       
   179     
       
   180     dnsQryBuf().SetType(KDnsRRTypeA);
       
   181     dnsQryBuf().SetData(aHostName);
       
   182     
       
   183     tmpBuf.Copy(aHostName);
       
   184     addrBuf.Copy(_L("* Listing 'A' RRs for the host: "));
       
   185     addrBuf.Append(tmpBuf);
       
   186     Logger().WriteFormat(addrBuf);
       
   187     
       
   188     
       
   189     for(TInt recCnt=0; ;++recCnt)
       
   190         {
       
   191         //-- make an 'A' query. 
       
   192         if(recCnt == 0) 
       
   193             ret = iHostRslv.Query(dnsQryBuf, dnsRespABuf);  //-- make a query and get the result
       
   194         else
       
   195             ret = iHostRslv.QueryGetNext(dnsRespABuf);      //-- get the rest of the RRs
       
   196         
       
   197         const TDnsRespA& dnsRespA = dnsRespABuf();
       
   198         
       
   199         
       
   200         if(ret == KErrNone)
       
   201             {//-- everything is all right, print record data out
       
   202             
       
   203             tmpBuf.Format(_L("RR Type=%d, Class=%d, TTL=%d, Address="),dnsRespA.RRType(), dnsRespA.RRClass(), dnsRespA.RRTtl());
       
   204             dnsRespA.HostAddress().Output(addrBuf);
       
   205             tmpBuf.Append(addrBuf);
       
   206             Logger().WriteFormat(tmpBuf);
       
   207             }
       
   208         else //-- real error
       
   209             {
       
   210 			ret = ProcessDndError(ret, recCnt);
       
   211 			break;
       
   212             }
       
   213 		
       
   214         }// for
       
   215     
       
   216     
       
   217     Logger().WriteFormat(_L(""));
       
   218     return ret;
       
   219     }
       
   220 
       
   221 	/**
       
   222 	*   Requests all RR of type 'SRV' for the given host and prints them out
       
   223 	*
       
   224 	*   @param      aQuery  a query string that contains desired service, protocol and host definition
       
   225 	*
       
   226 	*   @return     standard error code
       
   227 */
       
   228 TInt    CTestRHostRslvQuery_27::ListDnsRecordsSRV(const TDesC8& aQuery)
       
   229     {
       
   230     TInt    ret = KErrNone;
       
   231     
       
   232     TDnsQueryBuf      dnsQryBuf;
       
   233     TDnsRespSRVBuf    dnsRespSRVBuf;
       
   234     TBuf<KMaxStrLen>  targetBuf;
       
   235     TBuf<KMaxStrLen>  tmpBuf;
       
   236     
       
   237     dnsQryBuf().SetType(KDnsRRTypeSRV);
       
   238     dnsQryBuf().SetData(aQuery);
       
   239     
       
   240     tmpBuf.Copy(aQuery);
       
   241     targetBuf.Copy(_L("* Listing 'SRV' RRs according to the query: "));
       
   242     targetBuf.Append(tmpBuf);
       
   243     Logger().WriteFormat(targetBuf);
       
   244     
       
   245     for(TInt recCnt =0; ;++recCnt)
       
   246         {
       
   247         //-- make an 'SRV' query. 
       
   248         
       
   249         if(recCnt == 0) 
       
   250             ret = iHostRslv.Query(dnsQryBuf, dnsRespSRVBuf);  //-- make a query and get the result
       
   251         else
       
   252             ret = iHostRslv.QueryGetNext(dnsRespSRVBuf);      //-- get the rest of the RRs
       
   253         
       
   254         const TDnsRespSRV& dnsRespSRV = dnsRespSRVBuf();
       
   255         
       
   256         if(ret == KErrNone)
       
   257             {//-- everything is all right, print record data out
       
   258             
       
   259             tmpBuf.Format(_L("RR Type=%d, Class=%d, TTL=%d, target="),dnsRespSRV.RRType(), dnsRespSRV.RRClass(), dnsRespSRV.RRTtl());
       
   260             targetBuf.Copy(dnsRespSRV.Target());
       
   261             tmpBuf.Append(targetBuf);
       
   262             Logger().WriteFormat(tmpBuf);
       
   263             }
       
   264         else //-- real error
       
   265             {
       
   266 			ret = ProcessDndError(ret, recCnt);
       
   267 			break;
       
   268             }
       
   269 		
       
   270         }// for
       
   271     
       
   272     Logger().WriteFormat(_L(""));
       
   273     return ret;
       
   274     }
       
   275 
       
   276 
       
   277 	/**
       
   278 	*   Requests all RR of type 'PTR' for the given IP address and prints them out
       
   279 	*
       
   280 	*   @param      aQuery  string containing 'PTR' query, pointer address representation, 
       
   281 	*                       e.g "3.253.253.192.in-addr.arpa"  to resolve 192.253.253.2 address.
       
   282 	*
       
   283 	*   @return     standard error code
       
   284 */
       
   285 TInt    CTestRHostRslvQuery_27::ListDnsRecordsPTR(const TDesC8& aQuery)
       
   286     {
       
   287     TInt    ret = KErrNone;
       
   288     
       
   289     TDnsQueryBuf      dnsQryBuf;
       
   290     TDnsRespPTRBuf    dnsRespPTRBuf;
       
   291     TBuf<KMaxStrLen>  targetBuf;
       
   292     TBuf<KMaxStrLen>  tmpBuf;
       
   293     
       
   294     dnsQryBuf().SetType(KDnsRRTypePTR);
       
   295     dnsQryBuf().SetData(aQuery);
       
   296     
       
   297     targetBuf.Copy(_L("* Listing 'PTR' RRs according to the address query: "));
       
   298     tmpBuf.Copy(aQuery);
       
   299     targetBuf.Append(tmpBuf);
       
   300     Logger().WriteFormat(targetBuf);
       
   301     
       
   302     for(TInt recCnt =0; ;++recCnt)
       
   303         {
       
   304         //-- make an 'PTR' query. 
       
   305         if(recCnt == 0) 
       
   306             ret = iHostRslv.Query(dnsQryBuf, dnsRespPTRBuf);  //-- make a query and get the result
       
   307         else
       
   308             ret = iHostRslv.QueryGetNext(dnsRespPTRBuf);      //-- get the rest of the RRs
       
   309         
       
   310         const TDnsRespPTR& dnsRespPTR = dnsRespPTRBuf();
       
   311         
       
   312         if(ret == KErrNone)
       
   313             {//-- everything is all right, print record data out
       
   314             
       
   315             tmpBuf.Format(_L("RR Type=%d, Class=%d, TTL=%d, host name="),dnsRespPTR.RRType(), dnsRespPTR.RRClass(), dnsRespPTR.RRTtl());
       
   316             targetBuf.Copy(dnsRespPTR.HostName());
       
   317             tmpBuf.Append(targetBuf);
       
   318             Logger().WriteFormat(tmpBuf);
       
   319             }
       
   320         else //-- real error
       
   321             {
       
   322 			ret = ProcessDndError(ret, recCnt);
       
   323 			break;
       
   324             }
       
   325 		
       
   326         }// for
       
   327     
       
   328     Logger().WriteFormat(_L(""));
       
   329     return ret;
       
   330     }
       
   331 
       
   332 
       
   333 
       
   334 	/**
       
   335 	*   Requests all RR of type 'NAPTR' for the given host and prints them out
       
   336 	*
       
   337 	*   @param      aHostName name of the nost
       
   338 	*
       
   339 	*   @return     standard error code
       
   340 */
       
   341 TInt    CTestRHostRslvQuery_27::ListDnsRecordsNAPTR(const TDesC8& aHostName)
       
   342     {
       
   343     TInt    ret = KErrNone;
       
   344     
       
   345     TDnsQueryBuf      dnsQryBuf;
       
   346     TDnsRespNAPTRBuf  dnsRespNAPTRBuf;
       
   347     TBuf<KMaxStrLen>  targetBuf;
       
   348     TBuf<KMaxStrLen>  tmpBuf;
       
   349     
       
   350     dnsQryBuf().SetType(KDnsRRTypeNAPTR);
       
   351     dnsQryBuf().SetData(aHostName);
       
   352     
       
   353     
       
   354     targetBuf.Copy(_L("* Listing 'NAPTR' RRs for host: "));
       
   355     tmpBuf.Copy(aHostName);
       
   356     targetBuf.Append(tmpBuf);
       
   357     Logger().WriteFormat(targetBuf);
       
   358     
       
   359     for(TInt recCnt =0; ;++recCnt)
       
   360         {
       
   361         //-- make an 'SRV' query. 
       
   362         if(recCnt == 0) 
       
   363             ret = iHostRslv.Query(dnsQryBuf, dnsRespNAPTRBuf);  //-- make a query and get the result
       
   364         else
       
   365             ret = iHostRslv.QueryGetNext(dnsRespNAPTRBuf);      //-- get the rest of the RRs
       
   366         
       
   367         const TDnsRespNAPTR& dnsRespNAPTR = dnsRespNAPTRBuf();
       
   368         
       
   369         if(ret == KErrNone)
       
   370             {//-- everything is all right, print record data out
       
   371             
       
   372             tmpBuf.Format(_L("RR Type=%d, Class=%d, TTL=%d, Order=%d, Pref=%d, Flags="),
       
   373                 dnsRespNAPTR.RRType(), dnsRespNAPTR.RRClass(), dnsRespNAPTR.RRTtl(), dnsRespNAPTR.Order(), dnsRespNAPTR.Pref());
       
   374             
       
   375             targetBuf.Copy(dnsRespNAPTR.Flags());
       
   376             tmpBuf.Append(targetBuf);
       
   377             Logger().WriteFormat(tmpBuf);
       
   378             
       
   379             tmpBuf.Copy(_L("Service: "));
       
   380             targetBuf.Copy(dnsRespNAPTR.Service());
       
   381             tmpBuf.Append(targetBuf);
       
   382             
       
   383             tmpBuf.Append(_L(", Regexp: "));
       
   384             targetBuf.Copy(dnsRespNAPTR.Regexp());
       
   385             tmpBuf.Append(targetBuf);
       
   386             
       
   387             tmpBuf.Append(_L(", Replacement: "));
       
   388             targetBuf.Copy(dnsRespNAPTR.Replacement());
       
   389             tmpBuf.Append(targetBuf);
       
   390             
       
   391             Logger().WriteFormat(tmpBuf);
       
   392             }
       
   393         else //-- real error
       
   394             {
       
   395 			ret = ProcessDndError(ret, recCnt);
       
   396 			break;
       
   397             }
       
   398 		
       
   399 		
       
   400         }// for
       
   401     
       
   402     Logger().WriteFormat(_L(""));
       
   403     return ret;
       
   404     }
       
   405 
       
   406 	/**
       
   407 	*   Requests all RR of type 'MX' for the given host and prints them out
       
   408 	*
       
   409 	*   @param      aHostName name of the nost
       
   410 	*
       
   411 	*   @return     standard error code
       
   412 */
       
   413 TInt    CTestRHostRslvQuery_27::ListDnsRecordsMX(const TDesC8& aHostName)
       
   414     {
       
   415     TInt    ret = KErrNone;
       
   416     
       
   417     TDnsQueryBuf      dnsQryBuf;
       
   418     TDnsRespMXBuf     dnsRespMXBuf;
       
   419     TBuf<KMaxStrLen>  addrBuf;
       
   420     TBuf<KMaxStrLen>  tmpBuf;
       
   421     
       
   422     dnsQryBuf().SetType(KDnsRRTypeMX);
       
   423     dnsQryBuf().SetData(aHostName);
       
   424     
       
   425     tmpBuf.Copy(aHostName);
       
   426     addrBuf.Copy(_L("* Listing 'MX' RRs for the host: "));
       
   427     addrBuf.Append(tmpBuf);
       
   428     Logger().WriteFormat(addrBuf);
       
   429     
       
   430     for(TInt recCnt=0; ;++recCnt)
       
   431         {
       
   432         //-- make an 'MX' query. 
       
   433         if(recCnt == 0) 
       
   434             ret = iHostRslv.Query(dnsQryBuf, dnsRespMXBuf);  //-- make a query and get the result
       
   435         else
       
   436             ret = iHostRslv.QueryGetNext(dnsRespMXBuf);      //-- get the rest of the RRs
       
   437         
       
   438         const TDnsRespMX& dnsRespMX = dnsRespMXBuf();
       
   439         
       
   440         if(ret == KErrNone)
       
   441             {//-- everything is all right, print record data out
       
   442             
       
   443             tmpBuf.Format(_L("RR Type=%d, Class=%d, TTL=%d, Pref=%d, HostName="),dnsRespMX.RRType(), dnsRespMX.RRClass(), dnsRespMX.RRTtl(), dnsRespMX.Pref());
       
   444             addrBuf.Copy(dnsRespMX.HostName());
       
   445             tmpBuf.Append(addrBuf);
       
   446             Logger().WriteFormat(tmpBuf);
       
   447             }
       
   448         else //-- real error
       
   449             {
       
   450 			ret = ProcessDndError(ret, recCnt);
       
   451 			break;
       
   452             }
       
   453 		
       
   454         }// for
       
   455     
       
   456     Logger().WriteFormat(_L(""));
       
   457     return ret;
       
   458     }
       
   459 
       
   460 	/**
       
   461 	*   Requests all RR of type 'AAAA' for the given host and prints them out
       
   462 	*
       
   463 	*   @param      aHostName name of the nost
       
   464 	*
       
   465 	*   @return     standard error code
       
   466 */
       
   467 TInt    CTestRHostRslvQuery_27::ListDnsRecordsAAAA(const TDesC8& aHostName)
       
   468     {
       
   469     TInt    ret = KErrNone;
       
   470     
       
   471     TDnsQueryBuf      dnsQryBuf;
       
   472     TDnsRespAAAABuf   dnsRespAAAABuf;
       
   473     TBuf<KMaxStrLen>  addrBuf;
       
   474     TBuf<KMaxStrLen>  tmpBuf;
       
   475     
       
   476     dnsQryBuf().SetType(KDnsRRTypeAAAA);
       
   477     dnsQryBuf().SetData(aHostName);
       
   478     
       
   479     tmpBuf.Copy(aHostName);
       
   480     addrBuf.Copy(_L("* Listing 'AAAA' RRs for the host: "));
       
   481     addrBuf.Append(tmpBuf);
       
   482     Logger().WriteFormat(addrBuf);
       
   483     
       
   484     for(TInt recCnt =0; ;++recCnt)
       
   485         {
       
   486         //-- make an 'AAAA' query. 
       
   487         if(recCnt == 0) 
       
   488             ret = iHostRslv.Query(dnsQryBuf, dnsRespAAAABuf);  //-- make a query and get the result
       
   489         else
       
   490             ret = iHostRslv.QueryGetNext(dnsRespAAAABuf);      //-- get the rest of the RRs
       
   491         
       
   492         const TDnsRespAAAA& dnsRespAAAA = dnsRespAAAABuf();
       
   493         
       
   494         if(ret == KErrNone)
       
   495             {//-- everything is all right, print record data out
       
   496             
       
   497             tmpBuf.Format(_L("RR Type=%d, Class=%d, TTL=%d, Address="),dnsRespAAAA.RRType(), dnsRespAAAA.RRClass(), dnsRespAAAA.RRTtl());
       
   498             
       
   499             dnsRespAAAA.HostAddress().Output(addrBuf);
       
   500             
       
   501             //-- remove scope modifier from the end of address representation, it may look like "%1" and confuses 'Log'
       
   502             TInt nPos = addrBuf.Locate('%');
       
   503             if(nPos >= 0)
       
   504                 addrBuf.SetLength(nPos);
       
   505             
       
   506             tmpBuf.Append(addrBuf);
       
   507             Logger().WriteFormat(tmpBuf);
       
   508             }
       
   509         else //-- real error
       
   510             {
       
   511 			ret = ProcessDndError(ret, recCnt);
       
   512 			break;
       
   513             }
       
   514 		
       
   515         }// for
       
   516     
       
   517     Logger().WriteFormat(_L(""));
       
   518     return ret;
       
   519     }
       
   520 
       
   521 	/**
       
   522 	* Internal helper function for calling appropriate method of listing a certain type of RR
       
   523 	*
       
   524 	*@param     apFunct pointer to the one of the ListDnsRecords* methods to be called. 
       
   525 	*@return    a number of test substeps performed and passed.
       
   526 	*@leave     KErrNotFound if some error occured
       
   527 */
       
   528 TInt    CTestRHostRslvQuery_27::ListDnsRecordsL(TpListRRFunct apFunct)
       
   529 	{
       
   530     TBuf8<KMaxStrLen>   queryString;
       
   531 	
       
   532     //-- read number of entries in .ini file section
       
   533     TInt nEntries=0;
       
   534     if(!GetIntFromConfig(TestStepName(), _L("Entries"), nEntries) || nEntries <=0)
       
   535         {
       
   536 		Logger().WriteFormat(_L("* Unable to read number of entries from ini file!"));
       
   537 		User::Leave(KErrNotFound);
       
   538         }
       
   539     //-- make DNS query for every key data entry in .ini file section
       
   540     TBuf<64>    keyName;
       
   541     TInt        nTstExecuted=0;
       
   542     TInt        ret;
       
   543     for(TInt cnt=0; cnt<nEntries; cnt++)
       
   544 		{
       
   545         keyName.Format(_L("Param%d"), cnt+1);//-- make key name for section parameter
       
   546         
       
   547         if(GetIniFileString8(TestStepName(), keyName, queryString))
       
   548 			{
       
   549             //-- list RRs for the given query string, calling given function by pointer.
       
   550             ret = (this->*apFunct)(queryString);
       
   551             
       
   552             if(ret == KErrNone)
       
   553                 nTstExecuted++;
       
   554             else 
       
   555 				if(ret != KErrNotFound)
       
   556 					TESTEL(EFalse, ret);
       
   557 				
       
   558 			}
       
   559 		} //for
       
   560     
       
   561     if(!nTstExecuted) //-- no tests executed
       
   562 		{
       
   563         Logger().WriteFormat(_L("* No tests executed, probably external DNS is down"));
       
   564 		}
       
   565 	
       
   566     return nTstExecuted;
       
   567 	}
       
   568 
       
   569 
       
   570 //-------------------------------------------------------------------------------------------------------
       
   571 //--  Test step 27.1
       
   572 //--  Testing RHostResolver::Query() of 'A' type
       
   573 //-------------------------------------------------------------------------------------------------------
       
   574 
       
   575 const TDesC& CEsockTest27_1::GetTestName()
       
   576     {
       
   577     // store the name of this test case
       
   578     _LIT(ret,"Test27.1");
       
   579 	
       
   580 	return ret;
       
   581     }
       
   582 
       
   583 TVerdict CEsockTest27_1::easyTestStepL()
       
   584     {
       
   585     TInt                ret = KErrNone;
       
   586     TVerdict            verdict = EPass;
       
   587     TInt                nTstExecuted=0;
       
   588     Logger().WriteFormat(_L("--- Testing RHostResolver::Query() of 'A' type"));
       
   589 	
       
   590     TRAP(ret, nTstExecuted=ListDnsRecordsL(&CEsockTest27_1::ListDnsRecordsA));
       
   591     TESTEL(ret == KErrNone, ret);
       
   592 	
       
   593     if(!nTstExecuted) //-- no tests executed
       
   594         verdict=EFail;
       
   595     
       
   596     return verdict;
       
   597     }
       
   598 
       
   599 //-------------------------------------------------------------------------------------------------------
       
   600 //--  Test step 27.2
       
   601 //--  Testing RHostResolver::Query() of 'SVR' type
       
   602 //-------------------------------------------------------------------------------------------------------
       
   603 
       
   604 const TDesC& CEsockTest27_2::GetTestName()
       
   605     {
       
   606     // store the name of this test case
       
   607     _LIT(ret,"Test27.2");
       
   608 	
       
   609 	return ret;
       
   610     }
       
   611 
       
   612 TVerdict CEsockTest27_2::easyTestStepL()
       
   613     {
       
   614     TInt                ret = KErrNone;
       
   615     TVerdict            verdict = EPass;
       
   616     
       
   617     
       
   618     Logger().WriteFormat(_L("--- Testing RHostResolver::Query() of 'SRV' type"));
       
   619     
       
   620     TInt    nTstExecuted=0;
       
   621     TRAP(ret, nTstExecuted=ListDnsRecordsL(&CEsockTest27_2::ListDnsRecordsSRV));
       
   622     TESTEL(ret == KErrNone, ret);
       
   623 	
       
   624     if(!nTstExecuted) //-- no tests executed
       
   625         verdict=EFail;
       
   626 	
       
   627     return verdict;
       
   628     }
       
   629 
       
   630 //-------------------------------------------------------------------------------------------------------
       
   631 //--  Test step 27.3
       
   632 //--  Testing RHostResolver::Query() of 'PTR' type
       
   633 //-------------------------------------------------------------------------------------------------------
       
   634 
       
   635 const TDesC& CEsockTest27_3::GetTestName()
       
   636     {
       
   637     // store the name of this test case
       
   638     _LIT(ret,"Test27.3");
       
   639 	
       
   640 	return ret;
       
   641     }
       
   642 
       
   643 TVerdict CEsockTest27_3::easyTestStepL()
       
   644     {
       
   645     TInt                ret = KErrNone;
       
   646     TVerdict            verdict = EPass;
       
   647 	
       
   648     Logger().WriteFormat(_L("--- Testing RHostResolver::Query() of 'PTR' type"));
       
   649 	
       
   650 	
       
   651     TInt    nTstExecuted=0;
       
   652     TRAP(ret, nTstExecuted=ListDnsRecordsL(&CEsockTest27_3::ListDnsRecordsPTR));
       
   653     TESTEL(ret == KErrNone, ret);
       
   654 	
       
   655     if(!nTstExecuted) //-- no tests executed
       
   656         verdict=EFail;
       
   657     
       
   658     return verdict;
       
   659     }
       
   660 
       
   661 //-------------------------------------------------------------------------------------------------------
       
   662 //--  Test step 27.4
       
   663 //--  Testing RHostResolver::Query() of 'NAPTR' type
       
   664 //-------------------------------------------------------------------------------------------------------
       
   665 
       
   666 const TDesC& CEsockTest27_4::GetTestName()
       
   667     {
       
   668     // store the name of this test case
       
   669     _LIT(ret,"Test27.4");
       
   670 	
       
   671 	return ret;
       
   672     }
       
   673 
       
   674 TVerdict CEsockTest27_4::easyTestStepL()
       
   675     {
       
   676     TInt                ret = KErrNone;
       
   677     TVerdict            verdict = EPass;
       
   678     
       
   679     Logger().WriteFormat(_L("--- Testing RHostResolver::Query() of 'NAPTR' type"));
       
   680     
       
   681     TInt    nTstExecuted=0;
       
   682     TRAP(ret, nTstExecuted=ListDnsRecordsL(&CEsockTest27_4::ListDnsRecordsNAPTR));
       
   683     TESTEL(ret == KErrNone, ret);
       
   684 	
       
   685     if(!nTstExecuted) //-- no tests executed
       
   686         verdict=EFail;
       
   687 	
       
   688     return verdict;
       
   689     }
       
   690 
       
   691 //-------------------------------------------------------------------------------------------------------
       
   692 //--  Test step 27.5
       
   693 //--  Testing RHostResolver::Query() of 'MX' type
       
   694 //-------------------------------------------------------------------------------------------------------
       
   695 
       
   696 const TDesC& CEsockTest27_5::GetTestName()
       
   697     {
       
   698     // store the name of this test case
       
   699     _LIT(ret,"Test27.5");
       
   700 	
       
   701 	return ret;
       
   702     }
       
   703 
       
   704 TVerdict CEsockTest27_5::easyTestStepL()
       
   705     {
       
   706     TInt                ret = KErrNone;
       
   707     TVerdict            verdict = EPass;
       
   708     
       
   709     Logger().WriteFormat(_L("Testing RHostResolver::Query() of 'MX' type"));
       
   710 	
       
   711 	
       
   712     TInt    nTstExecuted=0;
       
   713     TRAP(ret, nTstExecuted=ListDnsRecordsL(&CEsockTest27_5::ListDnsRecordsMX));
       
   714     TESTEL(ret == KErrNone, ret);
       
   715 	
       
   716     if(!nTstExecuted) //-- no tests executed
       
   717         verdict=EFail;
       
   718     
       
   719     return verdict;
       
   720     }
       
   721 
       
   722 //-------------------------------------------------------------------------------------------------------
       
   723 //--  Test step 27.6
       
   724 //--  Testing RHostResolver::Query() of 'AAAA' type
       
   725 //-------------------------------------------------------------------------------------------------------
       
   726 
       
   727 const TDesC& CEsockTest27_6::GetTestName()
       
   728     {
       
   729     // store the name of this test case
       
   730     _LIT(ret,"Test27.6");
       
   731 	
       
   732 	return ret;
       
   733     }
       
   734 
       
   735 TVerdict CEsockTest27_6::easyTestStepL()
       
   736     {
       
   737     TInt                ret = KErrNone;
       
   738     TVerdict            verdict = EPass;
       
   739 	
       
   740     Logger().WriteFormat(_L("Testing RHostResolver::Query() of 'AAAA' type"));
       
   741     
       
   742     TInt    nTstExecuted=0;
       
   743     TRAP(ret, nTstExecuted=ListDnsRecordsL(&CEsockTest27_6::ListDnsRecordsAAAA));
       
   744     TESTEL(ret == KErrNone, ret);
       
   745 	
       
   746     if(!nTstExecuted) //-- no tests executed
       
   747         verdict=EFail;
       
   748     
       
   749     return verdict;
       
   750     }
       
   751 
       
   752 
       
   753 
       
   754 //-------------------------------------------------------------------------------------------------------
       
   755 
       
   756 /**
       
   757 *   test preamble: open Host Resolver  using RConnection
       
   758 */
       
   759 TVerdict CTestRHostRslvQuery_27_ExplConn::doTestStepPreambleL (void)
       
   760     {
       
   761     TInt    ret;
       
   762     
       
   763     //-- open and start connection
       
   764     Logger().WriteFormat(_L("Opening and starting connection"));
       
   765     
       
   766     ret = iConnection.Open(iEsockSuite->iSocketServer);
       
   767     if(ret != KErrNone)
       
   768         {
       
   769         Logger().WriteFormat(_L("iConnection.Open error code: %d"), ret);    
       
   770         return EFail;
       
   771         }
       
   772     
       
   773     ret = iConnection.Start();
       
   774     if(ret != KErrNone)
       
   775         {
       
   776         Logger().WriteFormat(_L("iConnection.Start error code: %d"), ret);    
       
   777         return EFail;
       
   778         }
       
   779     
       
   780     //-- open host resolver on UDP
       
   781     Logger().WriteFormat(_L("Opening host resolver on UDP for using explicit connection"));
       
   782     ret = iHostRslv.Open(iEsockSuite->iSocketServer, KAfInet, KProtocolInetUdp, iConnection);
       
   783     
       
   784     if(ret != KErrNone)
       
   785         {
       
   786         Logger().WriteFormat(_L("iHostRslv.Open error code: %d"), ret);    
       
   787         return EFail;
       
   788         }
       
   789     
       
   790     return EPass;
       
   791     }
       
   792 
       
   793 	/**
       
   794 	*   test postamble: close Host Resolver
       
   795 */
       
   796 TVerdict CTestRHostRslvQuery_27_ExplConn::doTestStepPostambleL(void)
       
   797     {
       
   798     Logger().WriteFormat(_L("stopping and closing connection"));
       
   799     iConnection.Stop();
       
   800     iConnection.Close();
       
   801     
       
   802     Logger().WriteFormat(_L("Closing host resolver"));
       
   803     iHostRslv.Close();
       
   804     
       
   805     return EPass;
       
   806     }
       
   807 
       
   808 //-------------------------------------------------------------------------------------------------------
       
   809 //--  Testing RHostResolver::Query() of 'A' type.
       
   810 //--  Using Explicit connection.
       
   811 //-------------------------------------------------------------------------------------------------------
       
   812 const TDesC& CEsockTest27_1_ExplConn::GetTestName()
       
   813     {
       
   814     // store the name of this test case
       
   815     _LIT(ret,"Test27.7");
       
   816 	
       
   817 	return ret;
       
   818     }
       
   819 
       
   820 TVerdict CEsockTest27_1_ExplConn::easyTestStepL()
       
   821     {
       
   822     TInt                ret = KErrNone;
       
   823     TVerdict            verdict = EPass;
       
   824     
       
   825     Logger().WriteFormat(_L("--- Testing RHostResolver::Query() of 'A' type"));
       
   826 	
       
   827     TInt    nTstExecuted=0;
       
   828     TRAP(ret, nTstExecuted=ListDnsRecordsL(&CEsockTest27_1_ExplConn::ListDnsRecordsA));
       
   829     TESTEL(ret == KErrNone, ret);
       
   830 	
       
   831     if(!nTstExecuted) //-- no tests executed
       
   832         verdict=EFail;
       
   833 	
       
   834     return verdict;
       
   835     }
       
   836 
       
   837 
       
   838 //-------------------------------------------------------------------------------------------------------
       
   839 //  Testing RHostResolver::Query() functionality on several threads:       
       
   840 //  one thread performs Query() while another GetByName()
       
   841 //-------------------------------------------------------------------------------------------------------
       
   842 
       
   843 const TDesC& CEsockTest27_1_MThread::GetTestName()
       
   844     {
       
   845     // store the name of this test case
       
   846     _LIT(ret,"Test27.8");
       
   847 	
       
   848 	return ret;
       
   849     }
       
   850 
       
   851 
       
   852 	/**
       
   853 	*   thread parameter data ctructure for Tst27_M_Thread.
       
   854 */
       
   855 class TTestMTreadParam
       
   856     {
       
   857     public:
       
   858         
       
   859         TTestMTreadParam() : m_nTrials(0), m_nPass(0) {}
       
   860         
       
   861     public:
       
   862         
       
   863         TBuf<KMaxStrLen>    m_hostName; //< host name to be resolved
       
   864         TInt                m_nTrials;  //< number of name resolution trials
       
   865         TInt                m_nPass;    //< number of trials passed;
       
   866         
       
   867     };
       
   868 
       
   869 
       
   870 	/**
       
   871 	*   Thread function for CEsockTest27_1_MThread test.
       
   872 	*   performs several GetByName calls.
       
   873 	*
       
   874 	*   @param  aParam pointer to the thread parameter structure, see TTestMTreadParam.
       
   875 	*   @return standard error code.
       
   876 */
       
   877 TInt Tst27_M_Thread(TAny* aParam)
       
   878     {
       
   879     //-- sorry, logging isn't available here.
       
   880     //-- the output will be thread completion code and counter of successful name resolutions attempts
       
   881     //-- see TTestMTreadParam
       
   882     
       
   883     TTestMTreadParam* pTestParam = static_cast<TTestMTreadParam*> (aParam);
       
   884     
       
   885     if(! pTestParam)
       
   886         User::Invariant();
       
   887     
       
   888     TInt ret = KErrNone;
       
   889     
       
   890     RHostResolver hostRslv;
       
   891     RSocketServ   socketServer;
       
   892     
       
   893     //-- connect to the socket server and open host resolver
       
   894     if(socketServer.Connect() != KErrNone || hostRslv.Open(socketServer, KAfInet, KProtocolInetUdp) != KErrNone)
       
   895         {    
       
   896         ret = KErrGeneral;    
       
   897         }
       
   898     else
       
   899         {   //-- make several name resolution attempts.
       
   900         //-- if there was no error, increase pass counter
       
   901         TNameEntry  nameEntry;
       
   902         
       
   903         for(TInt i=0; i<pTestParam->m_nTrials; ++i)
       
   904             {
       
   905             TInt nRes = hostRslv.GetByName(pTestParam->m_hostName, nameEntry);
       
   906             //TSockAddr sockAddr = nameEntry().iAddr;
       
   907             
       
   908             if(nRes == KErrNone)
       
   909                 pTestParam->m_nPass++;    
       
   910             }
       
   911         }
       
   912     
       
   913     //-- close resolver and socket server
       
   914     hostRslv.Close();
       
   915     socketServer.Close();
       
   916     
       
   917     return ret;
       
   918     }
       
   919 
       
   920 TVerdict CEsockTest27_1_MThread::easyTestStepL()
       
   921     {
       
   922     TInt                ret = KErrNone;
       
   923     TVerdict            verdict = EPass;
       
   924     TTestMTreadParam    threadParam;
       
   925     TNameEntry          nameEntry;
       
   926     
       
   927     Logger().WriteFormat(_L("--- Testing RHostResolver::Query() functionality with several threads"));
       
   928     
       
   929     //-- try to check thread functionality firstly.
       
   930     //-- try to resolve the host name and if OK, start the thread
       
   931     TPtrC buffPtr(threadParam.m_hostName);
       
   932     TESTL(GetStringFromConfig(TestStepName(), _L("Param1"), buffPtr)); //-- get host name to resolve
       
   933     threadParam.m_hostName.Copy(buffPtr);
       
   934     
       
   935     ret = iHostRslv.GetByName(threadParam.m_hostName, nameEntry);
       
   936     TESTL(ret == KErrNone);
       
   937     
       
   938     //-- set up thread parameters
       
   939     threadParam.m_nTrials = 20; //-- how many attempts the threal will make
       
   940     threadParam.m_nPass   = 0;
       
   941     
       
   942     //-- start thread that will use RHostResolver simultaniously with this one.
       
   943     Logger().WriteFormat(_L("- Creating additional thread"));
       
   944     
       
   945     RThread         thread;
       
   946     TRequestStatus  reqStat;
       
   947     
       
   948     _LIT(KThreadName,"Test27_Thread");
       
   949     const TInt KStackSize   =0x8000;
       
   950     const TInt KHeapSize    =0x8000;
       
   951     const TInt KMaxHeapSize =0x80000;
       
   952     
       
   953     ret=thread.Create(KThreadName, Tst27_M_Thread, KStackSize,KHeapSize, KMaxHeapSize, &threadParam);
       
   954     TESTL(ret == KErrNone);
       
   955     
       
   956     thread.Resume();
       
   957     thread.Logon(reqStat);
       
   958     
       
   959     Logger().WriteFormat(_L("- additional thread has started"));
       
   960     
       
   961     //-- now make several host resolver queries at the same time with thread that 
       
   962     //-- makes name resolution attempts.
       
   963     TBuf8<KMaxStrLen>   queryString;
       
   964     TInt                nTstExecuted = 0;
       
   965     const TInt          numTrials    = 10;
       
   966     
       
   967     TESTL(GetIniFileString8(TestStepName(), _L("Param2"), queryString)); //-- get the query string
       
   968     
       
   969     Logger().WriteFormat(_L("- making %d queries in the main thread"), numTrials);
       
   970     
       
   971     //-- just query SRV records several times
       
   972     for(TInt cnt = 0; cnt < numTrials; ++cnt)
       
   973         {
       
   974         ret = ListDnsRecordsSRV(queryString);
       
   975         TESTL(ret == KErrNone);
       
   976         nTstExecuted++;
       
   977         
       
   978         }// for
       
   979     
       
   980     if(!nTstExecuted) //-- no tests executed in this thread
       
   981         verdict=EInconclusive;
       
   982     
       
   983     //-- wait for the thread to finish and check the result of its job
       
   984     Logger().WriteFormat(_L("- Waiting for additional thread to finish"));
       
   985     User::WaitForRequest(reqStat);
       
   986     thread.Close();
       
   987     
       
   988     TESTL(reqStat.Int() == KErrNone);                  //-- thread completion code
       
   989     if( threadParam.m_nPass != threadParam.m_nTrials ) //-- check the thread's job result
       
   990         verdict=EInconclusive;
       
   991     
       
   992     
       
   993     return verdict;
       
   994     }
       
   995 
       
   996 
       
   997