commsprocess/commsrootserverconfig/ts_rootserver/RootServerTestSection2.cpp
changeset 72 ae47d0499bee
parent 68 5da8188e392b
child 77 c9776eadbffd
equal deleted inserted replaced
68:5da8188e392b 72:ae47d0499bee
     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 2
       
    15 // 
       
    16 //
       
    17 
       
    18 // EPOC includes
       
    19 #include <e32base.h>
       
    20 
       
    21 // RootServer includes
       
    22 #include <es_mbman.h>
       
    23 
       
    24 // Test system includes
       
    25 #include <networking/log.h>
       
    26 #include <networking/teststep.h>
       
    27 #include <networking/testsuite.h>
       
    28 
       
    29 #include "TestStepRootServer.h"
       
    30 #include "TestSuiteRootServer.h"
       
    31 #include "TestAsynchHandler.h"
       
    32 
       
    33 #include "RootServerTestSection2.h"
       
    34 #include "RootServerTest.h"
       
    35 
       
    36 // Test step 2.1 - Enumerate with No Servers
       
    37 CRootServerTest2_1::CRootServerTest2_1()
       
    38 {
       
    39 	// store the name of this test case
       
    40 	iTestStepName = _L("Test2.1");
       
    41 }
       
    42 
       
    43 TVerdict CRootServerTest2_1::doTestStepL( void )
       
    44 	{
       
    45 	TVerdict verdict = EPass;
       
    46 
       
    47 	Log(_L("Test Purpose: Enumerate with No Servers"));
       
    48 
       
    49 	// enumerate servers
       
    50 	Log(_L("02 Enumerating servers"));
       
    51 
       
    52 	TCFModuleName moduleName;
       
    53 	TRSIter position;
       
    54 	TInt ret = iRootServerSuite->RootSess().EnumerateModules(position, moduleName);
       
    55 	Log(_L("Enumerate returned %d"), ret);
       
    56 
       
    57 	if (KErrEof != ret)
       
    58 		{
       
    59 		verdict = EFail;
       
    60 		}
       
    61 
       
    62 	return verdict;
       
    63 	}
       
    64 
       
    65 
       
    66 // Test step 2.2 - Enumerate
       
    67 CRootServerTest2_2::CRootServerTest2_2()
       
    68 	{
       
    69 	// store the name of this test case
       
    70 	iTestStepName = _L("Test2.2");
       
    71 	}
       
    72 
       
    73 TVerdict CRootServerTest2_2::doTestStepL( void )
       
    74 	{	
       
    75 	TVerdict verdict = EPass;
       
    76 
       
    77 	Log(_L("Test Purpose: EnumerateModules"));
       
    78 
       
    79 	// Create scheduler/active object framework 
       
    80 	CSelfPopScheduler* scheduler = CSelfPopScheduler::CreateLC();
       
    81     CTestAsynchHandler* asynchHandler = CTestAsynchHandler::NewLC(&iRootServerSuite->RootSess());
       
    82 
       
    83 	Log(_L8("01 Loading first cpm: %S"), &KModule1());
       
    84 	LoadNormalModuleL(asynchHandler, KModule1);
       
    85 
       
    86 	Log(_L8("02 Loading second cpm: %S"), &KModule2());
       
    87 	LoadNormalModuleL(asynchHandler, KModule2);
       
    88 
       
    89 	// uninstall active scheduler
       
    90 	CleanupStack::PopAndDestroy(asynchHandler);
       
    91 	CleanupStack::PopAndDestroy(scheduler);
       
    92 
       
    93 	// now enumerate
       
    94 	Log(_L("03 Enumerating once to get first servername"));
       
    95 
       
    96 	TCFModuleName moduleName;
       
    97 	TPtrC8 expectedModule2;
       
    98 	TRSIter position;
       
    99 	TInt ret = iRootServerSuite->RootSess().EnumerateModules(position, moduleName);
       
   100 
       
   101 	Log(_L("Enumerate returned %d"), ret);
       
   102 
       
   103 	if (KErrNone != ret)
       
   104 		{
       
   105 		verdict = EFail;
       
   106 		}
       
   107 	else
       
   108 		{
       
   109 		if (moduleName == KModule1)
       
   110 			{
       
   111 			expectedModule2.Set(KModule2);
       
   112 			}
       
   113 		else if(moduleName == KModule2)
       
   114 			{
       
   115 			expectedModule2.Set(KModule1);
       
   116 			}
       
   117 		else
       
   118 			{
       
   119 			Log(_L8("%S not found in serverlist"), &moduleName);
       
   120 			verdict = EFail;
       
   121 			}
       
   122 		if(expectedModule2.Length())
       
   123 			{
       
   124 			Log(_L("Found first so enumerating again to get second servername"));
       
   125 			ret = iRootServerSuite->RootSess().EnumerateModules(position, moduleName);
       
   126 
       
   127 			Log(_L("Enumerate returned %d"), ret);
       
   128 
       
   129 			if (KErrNone != ret)
       
   130 				{
       
   131 				verdict = EFail;
       
   132 				}
       
   133 			else if (moduleName != expectedModule2)
       
   134 				{
       
   135 				Log(_L8("%S not found in serverlist"), &moduleName);
       
   136 				verdict = EFail;
       
   137 				}
       
   138 			else
       
   139 				{
       
   140 				Log(_L("Found second so enumerating again to get EOF"));
       
   141 				ret = iRootServerSuite->RootSess().EnumerateModules(position, moduleName);
       
   142 				Log(_L("Enumerate returned %d"), ret);
       
   143 				if(ret != KErrEof)
       
   144 					{
       
   145 					verdict = EFail;
       
   146 					}
       
   147 				else
       
   148 					{
       
   149 					Log(_L("Found end of enumeration; enumerating again to check stability"));
       
   150 					ret = iRootServerSuite->RootSess().EnumerateModules(position, moduleName);
       
   151 					Log(_L("Enumerate returned %d"), ret);
       
   152 					if(ret != KErrEof)
       
   153 						{
       
   154 						verdict = EFail;
       
   155 						}
       
   156 					}
       
   157 				}
       
   158 			}
       
   159 			
       
   160 		}
       
   161 
       
   162 	return verdict;
       
   163 	}
       
   164 
       
   165 // Test step 2.3 - Enumerate submodules
       
   166 CRootServerTest2_3::CRootServerTest2_3()
       
   167 	{
       
   168 	// store the name of this test case
       
   169 	iTestStepName = _L("Test2.3");
       
   170 	}
       
   171 
       
   172 TVerdict CRootServerTest2_3::doTestStepL( void )
       
   173 	{	
       
   174 	TVerdict verdict = EPass;
       
   175 
       
   176 	Log(_L("Test Purpose: EnumerateSubModules"));
       
   177 
       
   178 	// Create scheduler/active object framework 
       
   179 	CSelfPopScheduler* scheduler = CSelfPopScheduler::CreateLC();
       
   180     CTestAsynchHandler* asynchHandler = CTestAsynchHandler::NewLC(&iRootServerSuite->RootSess());
       
   181 
       
   182 	Log(_L8("01 Loading test module: %S"), &KModule1());
       
   183 	LoadNormalModuleL(asynchHandler, KModule1);
       
   184 
       
   185 	// uninstall and destroy active scheduler
       
   186 	CleanupStack::PopAndDestroy(asynchHandler);
       
   187 	CleanupStack::PopAndDestroy(scheduler);
       
   188 	
       
   189 	TCFSubModuleName subModule;
       
   190 	TCFModuleName module(KModule1());
       
   191 	TBuf<0x40> str;
       
   192 	TCFSubModuleName expected1(_L8("Test Protocol1"));
       
   193 	TCFSubModuleName expected2(_L8("Test Protocol2"));
       
   194 	TCFSubModuleName expected3(_L8("Test Protocol3"));
       
   195 	TCFSubModuleName* expected[] = { &expected1, &expected2, &expected3 };
       
   196 	const TInt cntExpected = sizeof(expected) / sizeof(expected[0]);
       
   197 	TInt idx;
       
   198 	TRSIter position;
       
   199 	TInt ret;
       
   200 	while((ret = iRootServerSuite->RootSess().EnumerateSubModules(module, position, subModule)) == KErrNone)
       
   201 		{
       
   202 		str.Copy(subModule);
       
   203 
       
   204 		Log(_L("Got %S"), &str);
       
   205 		for(idx = 0; idx < cntExpected; ++idx)
       
   206 			{
       
   207 			if ((expected[idx] && subModule == *expected[idx]))
       
   208 				{
       
   209 				expected[idx] = NULL;
       
   210 				break;
       
   211 				}
       
   212 			}
       
   213 		if(idx == cntExpected)
       
   214 			{
       
   215 			Log(_L("not an expected sub-module"));
       
   216 			verdict = EFail;
       
   217 			}
       
   218 		}
       
   219 	if(EPass == verdict && KErrEof != ret)
       
   220 		{
       
   221 		Log(_L("Enumeration didn't end with expected KErrEof"));
       
   222 		verdict = EFail;
       
   223 		}
       
   224 	else if((ret = iRootServerSuite->RootSess().EnumerateSubModules(module, position, subModule)) != KErrEof)
       
   225 		{
       
   226 		Log(_L("Further enumeration didn't return expected KErrEof"));
       
   227 		verdict = EFail;
       
   228 		}
       
   229 
       
   230 	for(idx = 0; idx < cntExpected; ++idx)
       
   231 		{
       
   232 		if (expected[idx])
       
   233 			{
       
   234 			Log(_L8("Expected sub-module %S wasn't enumerated"), expected[idx]);
       
   235 			verdict = EFail;
       
   236 			break;
       
   237 			}
       
   238 		}
       
   239 
       
   240 	return verdict;
       
   241 	}
       
   242