installationservices/swinstallationfw/test/tusif/source/tsifcommonunitteststep.cpp
changeset 24 84a16765cd86
child 25 98b66e4fb0be
equal deleted inserted replaced
6:aba6b8104af3 24:84a16765cd86
       
     1 /*
       
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /**
       
    20  @file
       
    21  @internalTechnology 
       
    22 */
       
    23 
       
    24 #include "tsifcommonunitteststep.h"
       
    25 #include "tsifsuitedefs.h"
       
    26 #include <usif/sif/sifcommon.h>
       
    27 #include <ct/rcpointerarray.h>
       
    28 
       
    29 using namespace Usif;
       
    30 
       
    31 namespace
       
    32 	{
       
    33 	TInt PackCapabilitySet(const TCapabilitySet& aCapSet)
       
    34 		{
       
    35 		TInt caps=0;
       
    36 		for (TInt c=0; c<ECapability_Limit; ++c)
       
    37 			{
       
    38 			if (aCapSet.HasCapability(TCapability(c)))
       
    39 				{
       
    40 				caps += (1<<c);
       
    41 				}
       
    42 			}
       
    43 		return caps;
       
    44 		}
       
    45 	}
       
    46 
       
    47 CSifCommonUnitTestStep::~CSifCommonUnitTestStep()
       
    48 /**
       
    49 * Destructor
       
    50 */
       
    51 	{
       
    52 	INFO_PRINTF1(_L("Cleanup in CSifCommonUnitTestStep::~CSifCommonUnitTestStep()"));
       
    53 	}
       
    54 
       
    55 CSifCommonUnitTestStep::CSifCommonUnitTestStep()
       
    56 /**
       
    57 * Constructor
       
    58 */
       
    59 	{
       
    60 	}
       
    61 
       
    62 void CSifCommonUnitTestStep::ImplTestStepL()
       
    63 /**
       
    64 * @return - TVerdict code
       
    65 * Override of base class pure virtual
       
    66 * Our implementation only gets called if the base class doTestStepPreambleL() did
       
    67 * not leave. That being the case, the current test result value will be EPass.
       
    68 */
       
    69 	{
       
    70 	INFO_PRINTF1(_L("I am in CSifCommonUnitTestStep::doTestStep()."));
       
    71 
       
    72 	SetTestStepResult(EFail);
       
    73 
       
    74 	TestComponentInfoL();
       
    75 	TestOpaqueNamedParamsL();
       
    76 
       
    77 	SetTestStepResult(EPass);
       
    78 	}
       
    79 
       
    80 
       
    81 
       
    82 void CSifCommonUnitTestStep::ImplTestStepPostambleL()
       
    83 /**
       
    84 * @return - TVerdict code
       
    85 * Override of base class virtual
       
    86 */
       
    87 	{
       
    88 	}
       
    89 
       
    90 
       
    91 void CSifCommonUnitTestStep::ImplTestStepPreambleL()
       
    92 /**
       
    93 * @return - TVerdict code
       
    94 * Override of base class virtual
       
    95 */
       
    96 	{
       
    97 	}
       
    98 
       
    99 void CSifCommonUnitTestStep::TestComponentInfoL()
       
   100 	{
       
   101 	TCapabilitySet capSet(ECapabilityReadDeviceData);
       
   102 	
       
   103 	CComponentInfo* compInfo = CComponentInfo::NewLC();
       
   104 	
       
   105 	/* Internalize from an empty descriptor and read invalid root node */
       
   106 	TIpcArgs ipcArgs;
       
   107 	compInfo->PrepareForIpcL(ipcArgs, 0);
       
   108 	TDes8* des = reinterpret_cast<TDes8*>(ipcArgs.iArgs[0]);
       
   109 	des->FillZ(1);
       
   110 	TRAPD(err, compInfo->RootNodeL());
       
   111 	if (err != KErrNotFound)
       
   112 		{
       
   113 		INFO_PRINTF1(_L("Internalize from an empty descriptor and read invalid root node"));
       
   114 		User::Leave(err);
       
   115 		}
       
   116 	CleanupStack::PopAndDestroy(compInfo);
       
   117 
       
   118 	/* Add invalid child */
       
   119 	CComponentInfo::CNode* node = CComponentInfo::CNode::NewLC(KNullDesC, KNullDesC, KNullDesC, KNullDesC, EDeactivated, ENewComponent, 12345678, KNullDesC, ENotAuthenticated, capSet, 1234, EFalse);
       
   120 	TRAP(err, node->AddChildL(NULL));
       
   121 	if (err != KErrArgument)
       
   122 		{
       
   123 		INFO_PRINTF1(_L("TestComponentInfoL: Add invalid child"));
       
   124 		User::Leave(err);
       
   125 		}
       
   126 	/* Get empty GlobalComponentId */
       
   127 	if (node->GlobalComponentId() != KNullDesC)
       
   128 		{
       
   129 		INFO_PRINTF1(_L("TestComponentInfoL: Get empty GlobalComponentId"));
       
   130 		User::Leave(KErrGeneral);
       
   131 		}
       
   132 	CleanupStack::PopAndDestroy(node);
       
   133 
       
   134 	/* Overflow detection */
       
   135 	const TInt maxDescriptorLength = 256;
       
   136 	const TInt tooBigLen = maxDescriptorLength + 1;
       
   137 	const TInt maxSize = 1234;
       
   138 	const TBool hasExe = EFalse;
       
   139 
       
   140 	HBufC* tooBigStr = HBufC::NewLC(tooBigLen);
       
   141 	TPtr tooBigStrPtr = tooBigStr->Des();
       
   142 	tooBigStrPtr.FillZ(tooBigLen);
       
   143 	
       
   144 	// for SoftwareTypeName
       
   145 	TRAP(err, CComponentInfo::CNode::NewLC(*tooBigStr, KNullDesC, KNullDesC, KNullDesC, EDeactivated, ENewComponent, 12345678, KNullDesC, ENotAuthenticated, capSet, maxSize, hasExe));
       
   146 	if (err != KErrOverflow)
       
   147 		{
       
   148 		INFO_PRINTF1(_L("TestComponentInfoL: Overflow detection for SoftwareTypeName"));
       
   149 		User::Leave(err);
       
   150 		}
       
   151 
       
   152 	// for ComponentName
       
   153 	TRAP(err, CComponentInfo::CNode::NewLC(KNullDesC, *tooBigStr, KNullDesC, KNullDesC, EDeactivated, ENewComponent, 12345678, KNullDesC, ENotAuthenticated, capSet, maxSize, hasExe));
       
   154 	if (err != KErrOverflow)
       
   155 		{
       
   156 		INFO_PRINTF1(_L("TestComponentInfoL: Overflow detection for ComponentName"));
       
   157 		User::Leave(err);
       
   158 		}
       
   159 
       
   160 	// for Version
       
   161 	TRAP(err, CComponentInfo::CNode::NewLC(KNullDesC, KNullDesC, *tooBigStr, KNullDesC, EDeactivated, ENewComponent, 12345678, KNullDesC, ENotAuthenticated, capSet, maxSize, hasExe));
       
   162 	if (err != KErrOverflow)
       
   163 		{
       
   164 		INFO_PRINTF1(_L("TestComponentInfoL: Overflow detection for aVersion"));
       
   165 		User::Leave(err);
       
   166 		}
       
   167 
       
   168 	// for Vendor
       
   169 	TRAP(err, CComponentInfo::CNode::NewLC(KNullDesC, KNullDesC, KNullDesC, *tooBigStr, EDeactivated, ENewComponent, 12345678, KNullDesC, ENotAuthenticated, capSet, maxSize, hasExe));
       
   170 	if (err != KErrOverflow)
       
   171 		{
       
   172 		INFO_PRINTF1(_L("TestComponentInfoL: Overflow detection for aVendor"));
       
   173 		User::Leave(err);
       
   174 		}
       
   175 
       
   176 	// for GlobalComponentId
       
   177 	TRAP(err, CComponentInfo::CNode::NewLC(KNullDesC, KNullDesC, KNullDesC, KNullDesC, EDeactivated, ENewComponent, 12345678, *tooBigStr, ENotAuthenticated, capSet, maxSize, hasExe));
       
   178 	if (err != KErrOverflow)
       
   179 		{
       
   180 		INFO_PRINTF1(_L("TestComponentInfoL: Overflow detection for GlobalComponentId"));
       
   181 		User::Leave(err);
       
   182 		}
       
   183 
       
   184 	CleanupStack::PopAndDestroy(tooBigStr);
       
   185 	
       
   186 	/* Testing embedded nodes */
       
   187 	compInfo = CComponentInfo::NewLC();
       
   188 	
       
   189 	/* Set invalid root node */
       
   190 	TRAP(err, compInfo->SetRootNodeL(NULL));
       
   191 	if (err != KErrArgument)
       
   192 		{
       
   193 		INFO_PRINTF1(_L("TestComponentInfoL: Set invalid root node"));
       
   194 		User::Leave(err);
       
   195 		}
       
   196 
       
   197 	CComponentInfo::CNode* emptyNode = CComponentInfo::CNode::NewLC(KNullDesC, KNullDesC, KNullDesC, KNullDesC, EDeactivated, ENewComponent, 12345678, KNullDesC, ENotAuthenticated, capSet, 1234, EFalse);
       
   198 	const TDesC& globalComponentId(emptyNode->GlobalComponentId());
       
   199 	ASSERT(globalComponentId.Length() == 0);
       
   200 	TRAP(err, compInfo->SetRootNodeAsChildL(*emptyNode));
       
   201 	if (err != KErrNotFound)
       
   202 		{
       
   203 		INFO_PRINTF1(_L("TestComponentInfoL: Set root node as child without a root node"));
       
   204 		User::Leave(err);
       
   205 		}
       
   206 	CleanupStack::PopAndDestroy(emptyNode);
       
   207 	
       
   208 	// Create root node
       
   209 	_LIT(KTxtRootSoftwareTypeName, "Test Software Type");
       
   210 	_LIT(KTxtRootComponentName, "Root Component");
       
   211 	_LIT(KTxtRootVersion, "1.0.0");
       
   212 	_LIT(KTxtRootVendor, "Symbian");
       
   213 	_LIT(KTxtRootGlobalComponentId, "Root Component Global Id");
       
   214 	CComponentInfo::CNode* root = CComponentInfo::CNode::NewLC(KTxtRootSoftwareTypeName,
       
   215 				KTxtRootComponentName, KTxtRootVersion, KTxtRootVendor, EDeactivated,
       
   216 				ENewComponent, 12345678, KTxtRootGlobalComponentId, ENotAuthenticated, capSet, maxSize, hasExe);
       
   217 	
       
   218 	// Create an array of nodes
       
   219 	RCPointerArray<CComponentInfo::CNode> children;
       
   220 	CleanupClosePushL(children);
       
   221 	
       
   222 	// Create second child node
       
   223 	_LIT(KTxtChild2SoftwareTypeName, "Test Software Type");
       
   224 	_LIT(KTxtChild2ComponentName, "Child2 Component");
       
   225 	_LIT(KTxtChild2Version, "1.2.0");
       
   226 	_LIT(KTxtChild2Vendor, "Symbian");
       
   227 	_LIT(KTxtChild2GlobalComponentId, "Child2 Component Global Id");
       
   228 	CComponentInfo::CNode* child2 = CComponentInfo::CNode::NewLC(KTxtChild2SoftwareTypeName,
       
   229 				KTxtChild2ComponentName, KTxtChild2Version, KTxtChild2Vendor, EDeactivated,
       
   230 				ENewComponent, 12345678, KTxtChild2GlobalComponentId, ENotAuthenticated, capSet, maxSize, hasExe);
       
   231 	children.AppendL(child2);
       
   232 	CleanupStack::Pop(child2);
       
   233 	
       
   234 	// Create third child node
       
   235 	_LIT(KTxtChild3SoftwareTypeName, "Test Software Type");
       
   236 	_LIT(KTxtChild3ComponentName, "Child3 Component");
       
   237 	_LIT(KTxtChild3Version, "1.3.0");
       
   238 	_LIT(KTxtChild3Vendor, "Symbian");
       
   239 	_LIT(KTxtChild3GlobalComponentId, "Child3 Component Global Id");
       
   240 	CComponentInfo::CNode* child3 = CComponentInfo::CNode::NewLC(KTxtChild3SoftwareTypeName,
       
   241 				KTxtChild3ComponentName, KTxtChild3Version, KTxtChild3Vendor, EDeactivated,
       
   242 				ENewComponent, 12345678, KTxtChild3GlobalComponentId, ENotAuthenticated, capSet, maxSize, hasExe);
       
   243 	children.AppendL(child3);
       
   244 	CleanupStack::Pop(child3);
       
   245 	
       
   246 	// Create first child node
       
   247 	_LIT(KTxtChild1SoftwareTypeName, "Test Software Type");
       
   248 	_LIT(KTxtChild1ComponentName, "Child1 Component");
       
   249 	_LIT(KTxtChild1Version, "1.1.0");
       
   250 	_LIT(KTxtChild1Vendor, "Symbian");
       
   251 	_LIT(KTxtChild1GlobalComponentId, "Child1 Component Global Id");
       
   252 	CComponentInfo::CNode* child1 = CComponentInfo::CNode::NewLC(KTxtChild1SoftwareTypeName,
       
   253 				KTxtChild1ComponentName, KTxtChild1Version, KTxtChild1Vendor, EDeactivated,
       
   254 				ENewComponent, 12345678, KTxtChild1GlobalComponentId, ENotAuthenticated, capSet,
       
   255 				maxSize, hasExe, &children);
       
   256 	root->AddChildL(child1);
       
   257 	CleanupStack::Pop(child1);
       
   258 	CleanupStack::PopAndDestroy(&children);
       
   259 	
       
   260 	// Set the root node
       
   261 	compInfo->SetRootNodeL(root);
       
   262 	CleanupStack::Pop(root);
       
   263 	
       
   264 	// Check the content of the third node
       
   265 	const CComponentInfo::CNode& rootNode = compInfo->RootNodeL();
       
   266 	const CComponentInfo::CNode& child1Node = *rootNode.Children()[0];
       
   267 	const CComponentInfo::CNode& child3Node = *child1Node.Children()[1];
       
   268 	
       
   269 	if (child3Node.SoftwareTypeName() != KTxtChild3SoftwareTypeName ||
       
   270 		child3Node.ComponentName() != KTxtChild3ComponentName ||
       
   271 		child3Node.Version() != KTxtChild3Version ||
       
   272 		child3Node.Vendor() != KTxtChild3Vendor ||
       
   273 		child3Node.ScomoState() != EDeactivated ||
       
   274 		child3Node.InstallStatus() != ENewComponent ||
       
   275 		child3Node.ComponentId() != 12345678 ||
       
   276 		child3Node.GlobalComponentId() != KTxtChild3GlobalComponentId ||
       
   277 		child3Node.Authenticity() != ENotAuthenticated ||
       
   278 		PackCapabilitySet(child3Node.UserGrantableCaps()) != PackCapabilitySet(capSet) ||
       
   279 		child3Node.MaxInstalledSize() != maxSize ||
       
   280 		child3Node.Children().Count() != 0)
       
   281 		{
       
   282 		INFO_PRINTF1(_L("TestComponentInfoL: 'Testing embedded nodes' failed"));
       
   283 		User::Leave(KErrGeneral);
       
   284 		}
       
   285 	
       
   286 	CleanupStack::PopAndDestroy(compInfo);
       
   287 	}
       
   288 
       
   289 void CSifCommonUnitTestStep::TestOpaqueNamedParamsL()
       
   290 	{
       
   291 	_LIT(KParamName1, "param 1");
       
   292 	_LIT(KParamName2, "param 2");
       
   293 	_LIT(KParamName3, "param 3");
       
   294 	_LIT(KParamName4, "param 4");
       
   295 	_LIT(KParamName5, "param 5");
       
   296 	
       
   297 	_LIT(KStringValue1, "value 1");
       
   298 	_LIT(KStringValue2, "value 2");
       
   299 
       
   300 	const TInt KIntValue1 = 111;
       
   301 	const TInt KIntValue2 = 222;
       
   302 	const TInt KIntValue3 = 333;
       
   303 	
       
   304 	/*  NewL */
       
   305 	COpaqueNamedParams* params1 = COpaqueNamedParams::NewL();
       
   306 	CleanupStack::PushL(params1);
       
   307 
       
   308 	/* String operations */
       
   309 
       
   310 	// AddStringL for a new param
       
   311 	params1->AddStringL(KParamName1, KStringValue2);
       
   312 	// AddStringL for an already existing param
       
   313 	params1->AddStringL(KParamName1, KStringValue1);
       
   314 	// StringByName for an existing param
       
   315 	if (params1->StringByNameL(KParamName1) != KStringValue1)
       
   316 		{
       
   317 		INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'StringByName for an existing param' failed"));
       
   318 		User::Leave(KErrGeneral);
       
   319 		}
       
   320 	// StringByName for a non-existing param
       
   321 	if (params1->StringByNameL(KParamName2) != KNullDesC)
       
   322 		{
       
   323 		INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'StringByName for a non-existing param' failed"));
       
   324 		User::Leave(KErrGeneral);
       
   325 		}
       
   326 	// StringByNameL for an existing param
       
   327 	if (params1->StringByNameL(KParamName1) != KStringValue1)
       
   328 		{
       
   329 		INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'StringByNameL for an existing param' failed"));
       
   330 		User::Leave(KErrGeneral);
       
   331 		}
       
   332 	// StringByNameL for a non-existing param
       
   333 	if (params1->StringByNameL(KParamName2) != KNullDesC)
       
   334 		{
       
   335 		INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'StringByNameL for a non-existing param' failed"));
       
   336 		User::Leave(KErrGeneral);
       
   337 		}
       
   338 
       
   339 	CleanupStack::PopAndDestroy(params1);
       
   340 
       
   341 	/* NewLC */
       
   342 	COpaqueNamedParams* params2 = COpaqueNamedParams::NewLC();
       
   343 
       
   344 	/* Int operations */
       
   345 
       
   346 	// AddIntL for a new param
       
   347 	params2->AddIntL(KParamName1, KIntValue2);
       
   348 	// AddIntL for an already existing param
       
   349 	params2->AddIntL(KParamName1, KIntValue1);
       
   350 	// GetIntByName for an existing param
       
   351 	TInt intValue1 = 0;
       
   352 	if (!params2->GetIntByNameL(KParamName1, intValue1) || intValue1 != KIntValue1)
       
   353 		{
       
   354 		INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'GetIntByName for an existing param' failed"));
       
   355 		User::Leave(KErrGeneral);
       
   356 		}
       
   357 	// GetIntByName for a non-existing param
       
   358 	if (params2->GetIntByNameL(KParamName2, intValue1))
       
   359 		{
       
   360 		INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'GetIntByName for a non-existing param' failed"));
       
   361 		User::Leave(KErrGeneral);
       
   362 		}
       
   363 	// IntByNameL for an existing param
       
   364 	if (params2->IntByNameL(KParamName1) != KIntValue1)
       
   365 		{
       
   366 		INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'IntByNameL for an existing param' failed"));
       
   367 		User::Leave(KErrGeneral);
       
   368 		}
       
   369 	// IntByNameL for a non-existing param
       
   370 	TRAPD(err, params2->IntByNameL(KParamName2));
       
   371 	if (err != KErrNotFound)
       
   372 		{
       
   373 		INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'IntByNameL for a non-existing param' failed"));
       
   374 		User::Leave(err);
       
   375 		}
       
   376 
       
   377 	/* GetNamesL & Count*/
       
   378 	params2->AddStringL(KParamName2, KStringValue2);
       
   379 	params2->AddIntL(KParamName3, KIntValue3);
       
   380 	RCPointerArray<HBufC> names;
       
   381 	CleanupClosePushL(names);
       
   382 	params2->GetNamesL(names);
       
   383 	if (params2->CountL() != 3 || names.Count() != 3 ||
       
   384 		*names[0] != KParamName1 || *names[1] != KParamName2 || *names[2] != KParamName3)
       
   385 		{
       
   386 		INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'GetNamesL & Count' failed"));
       
   387 		User::Leave(KErrGeneral);
       
   388 		}
       
   389 
       
   390 	/* Overflow detection */
       
   391 
       
   392 	COpaqueNamedParams* params3 = COpaqueNamedParams::NewLC();
       
   393 
       
   394 	const TInt bigLen = 128;
       
   395 	HBufC* bigStr = HBufC::NewLC(bigLen);
       
   396 	TPtr bigStrPtr = bigStr->Des();
       
   397 	bigStrPtr.FillZ(bigLen);
       
   398 
       
   399 	// Max acceptable length of descriptor
       
   400 	const TInt maxGoodLen = 128/2; 
       
   401 	TRAP(err, params3->AddStringL(KParamName1, bigStr->Left(maxGoodLen)));
       
   402 	if (err != KErrNone)
       
   403 		{
       
   404 		INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'Overflow detection: Max acceptable length of descriptor'"));
       
   405 		User::Leave(err);
       
   406 		}
       
   407 		
       
   408 	// Too big descriptor - same param name
       
   409 	const TInt tooBigLen = 128/2+1;
       
   410 	TRAP(err, params3->AddStringL(KParamName1, bigStr->Left(tooBigLen)));
       
   411 	if (err != KErrOverflow)
       
   412 		{
       
   413 		INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'Overflow detection: Too big descriptor - updated param'"));
       
   414 		User::Leave(err);
       
   415 		}		
       
   416 
       
   417 	// Too big descriptor - different param name
       
   418 	TRAP(err, params3->AddStringL(KParamName2, bigStr->Left(tooBigLen)));
       
   419 	if (err != KErrOverflow)
       
   420 		{
       
   421 		INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'Overflow detection: Too big descriptor - new param'"));
       
   422 		User::Leave(err);
       
   423 		}
       
   424 
       
   425 	// Overflow in KMaxExternalizedSize
       
   426 	params3->AddStringL(KParamName3, bigStr->Left(maxGoodLen));
       
   427 	params3->AddStringL(KParamName4, bigStr->Left(maxGoodLen));
       
   428 	params3->AddStringL(KParamName4, bigStr->Left(maxGoodLen)); // Add the same param to check overwriting
       
   429 	TRAP(err, params3->AddStringL(KParamName5, bigStr->Left(maxGoodLen)));
       
   430 	if (err != KErrOverflow)
       
   431 		{
       
   432 		INFO_PRINTF1(_L("TestOpaqueNamedParamsL: 'Overflow detection: Overflow in KMaxExternalizedSize'"));
       
   433 		User::Leave(err);
       
   434 		}
       
   435 
       
   436 	CleanupStack::PopAndDestroy(4, params2);
       
   437 	}