os/security/contentmgmt/referencedrmagent/tcaf/source/bitsetstep.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <caf/caf.h>
sl@0
    20
#include <caf/bitset.h>
sl@0
    21
#include <caf/attribute.h>
sl@0
    22
#include <s32mem.h>
sl@0
    23
#include "bitsetstep.h"
sl@0
    24
sl@0
    25
const TInt KAttrTop = 10;
sl@0
    26
sl@0
    27
using namespace ContentAccess;
sl@0
    28
sl@0
    29
CBitsetBaseStep::CBitsetBaseStep(const TDesC& aStepName)
sl@0
    30
	{
sl@0
    31
	SetTestStepName(aStepName);
sl@0
    32
	}
sl@0
    33
sl@0
    34
TVerdict CBitsetBaseStep::doTestStepPreambleL()
sl@0
    35
	{
sl@0
    36
	return TestStepResult();
sl@0
    37
	}
sl@0
    38
sl@0
    39
TVerdict CBitsetBaseStep::doTestStepPostambleL()
sl@0
    40
	{
sl@0
    41
	return TestStepResult();
sl@0
    42
	}
sl@0
    43
sl@0
    44
CBitset* CBitsetBaseStep::GetBitsetLC(const TDesC& aHeader)
sl@0
    45
	{
sl@0
    46
	_LIT(KBitCount, "bitcount");
sl@0
    47
	_LIT(KBit, "bit%02d");
sl@0
    48
sl@0
    49
	// Firstly, from the script, get the number of bits to set. If aHeader
sl@0
    50
	// is "left-", then the bitcount key is "left-bitcount"
sl@0
    51
	HBufC* buf = HBufC::NewLC(aHeader.Length() + KBitCount().Length());
sl@0
    52
	TPtr ptr(buf->Des());
sl@0
    53
	ptr = aHeader;
sl@0
    54
	ptr.Append(KBitCount());
sl@0
    55
	TInt bitcount = 0;
sl@0
    56
	GetIntFromConfig(ConfigSection(), ptr, bitcount);
sl@0
    57
sl@0
    58
	INFO_PRINTF3(_L("%S = %d"), &ptr, bitcount);
sl@0
    59
sl@0
    60
	// Now, create the bitset
sl@0
    61
	CBitset* bitset = CBitset::NewLC(bitcount);
sl@0
    62
	
sl@0
    63
	TInt i = 0;
sl@0
    64
	for (; i < bitcount; ++i)
sl@0
    65
		{
sl@0
    66
		TInt bit = 0;
sl@0
    67
		ptr = aHeader;
sl@0
    68
		ptr.AppendFormat(KBit, i);
sl@0
    69
		GetIntFromConfig(ConfigSection(), ptr, bit);
sl@0
    70
		if (bit)
sl@0
    71
			{
sl@0
    72
			bitset->Set(i);
sl@0
    73
			INFO_PRINTF2(_L("%S is set"), &ptr);
sl@0
    74
			}
sl@0
    75
		}
sl@0
    76
sl@0
    77
	CleanupStack::Pop(bitset);
sl@0
    78
	CleanupStack::PopAndDestroy(buf);
sl@0
    79
	CleanupStack::PushL(bitset);
sl@0
    80
	return bitset;
sl@0
    81
	}
sl@0
    82
sl@0
    83
/*
sl@0
    84
 * Step2 performs some basic internal Bitset sanity tests
sl@0
    85
 *
sl@0
    86
 */
sl@0
    87
sl@0
    88
CBasicBitsetStep::CBasicBitsetStep() 
sl@0
    89
	: CBitsetBaseStep(KBasicBitsetStep)
sl@0
    90
	{
sl@0
    91
	}
sl@0
    92
sl@0
    93
//	EIsProtected EIsForwardable EIsModifyable EIsCopyable
sl@0
    94
TVerdict CBasicBitsetStep::doTestStepL()
sl@0
    95
	{
sl@0
    96
	TInt i;
sl@0
    97
	SetTestStepResult(EPass); // Default result to PASS
sl@0
    98
sl@0
    99
	__UHEAP_MARK;
sl@0
   100
	INFO_PRINTF1(_L("Basic Bitset Test"));
sl@0
   101
sl@0
   102
	// Note we must size according to current EAttrTop (attribute.h)
sl@0
   103
	INFO_PRINTF1(_L("Creating set1..."));
sl@0
   104
	CBitset *set1 = CBitset::NewLC((TAttribute) KAttrTop); // on cleanup
sl@0
   105
sl@0
   106
	// check that all the bits are initially not set
sl@0
   107
	for(i = 0; i < KAttrTop; i++)
sl@0
   108
		{
sl@0
   109
		if (set1->IsSet(i))
sl@0
   110
			{
sl@0
   111
			INFO_PRINTF1(_L("Bitset::NewLC() test failed."));
sl@0
   112
			SetTestStepResult(EFail);
sl@0
   113
			}
sl@0
   114
		}
sl@0
   115
	
sl@0
   116
	INFO_PRINTF1(_L("Performing single bit set/test..."));
sl@0
   117
	set1->Set(EIsForwardable);
sl@0
   118
sl@0
   119
	// check that only EIsForwardable is set
sl@0
   120
	for(i = 0; i < KAttrTop; i++)
sl@0
   121
		{
sl@0
   122
		if (set1->IsSet(i) && i != EIsForwardable)
sl@0
   123
			{
sl@0
   124
			INFO_PRINTF1(_L("Single test/set(1) test failed."));
sl@0
   125
			SetTestStepResult(EFail);
sl@0
   126
			}
sl@0
   127
		}
sl@0
   128
	if (!set1->IsSet(EIsForwardable))
sl@0
   129
		{
sl@0
   130
		INFO_PRINTF1(_L("Single test/set(2) failed."));
sl@0
   131
		SetTestStepResult(EFail);
sl@0
   132
		}
sl@0
   133
sl@0
   134
	set1->Unset(EIsForwardable);
sl@0
   135
sl@0
   136
	// check that none of the bits are set
sl@0
   137
	for(i = 0; i < KAttrTop; i++)
sl@0
   138
		{
sl@0
   139
		if (set1->IsSet(i))
sl@0
   140
			{
sl@0
   141
			INFO_PRINTF1(_L("Single test/set(3) failed."));
sl@0
   142
			SetTestStepResult(EFail);
sl@0
   143
			}
sl@0
   144
		}
sl@0
   145
sl@0
   146
	INFO_PRINTF1(_L("Performing setall tests..."));
sl@0
   147
	set1->SetAll();
sl@0
   148
sl@0
   149
	// check that all bits are set
sl@0
   150
	for(i = 0; i < KAttrTop; i++)
sl@0
   151
		{
sl@0
   152
		if (!set1->IsSet(i))
sl@0
   153
			{
sl@0
   154
			INFO_PRINTF1(_L("SetAll test failed."));
sl@0
   155
			SetTestStepResult(EFail);
sl@0
   156
			}
sl@0
   157
		}
sl@0
   158
	
sl@0
   159
	set1->Reset();
sl@0
   160
sl@0
   161
	// check all bits are reset
sl@0
   162
	for(i = 0; i < KAttrTop; i++)
sl@0
   163
		{
sl@0
   164
		if (set1->IsSet(i))
sl@0
   165
			{
sl@0
   166
			INFO_PRINTF1(_L("Reset test failed."));
sl@0
   167
			SetTestStepResult(EFail);
sl@0
   168
			}
sl@0
   169
		}
sl@0
   170
sl@0
   171
	CleanupStack::PopAndDestroy(set1);	
sl@0
   172
	
sl@0
   173
	__UHEAP_MARKEND;
sl@0
   174
sl@0
   175
	return TestStepResult();
sl@0
   176
	}
sl@0
   177
sl@0
   178
// --------------------------------------------------------------------------
sl@0
   179
// This step tests the bitset SetList and IsSetList functions
sl@0
   180
sl@0
   181
CBitsetListStep::CBitsetListStep()
sl@0
   182
	: CBitsetBaseStep(KBitsetListStep)
sl@0
   183
	{
sl@0
   184
	}
sl@0
   185
sl@0
   186
TVerdict CBitsetListStep::doTestStepL()
sl@0
   187
	{
sl@0
   188
	TInt i;
sl@0
   189
	SetTestStepResult(EPass); 
sl@0
   190
sl@0
   191
	__UHEAP_MARK;
sl@0
   192
sl@0
   193
	INFO_PRINTF1(_L("Creating set1..."));
sl@0
   194
sl@0
   195
	CBitset *set1 = CBitset::NewLC(KAttrTop); 
sl@0
   196
sl@0
   197
	INFO_PRINTF1(_L("Performing SetList call"));
sl@0
   198
	set1->SetListL(2, EIsCopyable, EIsModifyable);
sl@0
   199
sl@0
   200
	for(i = 0; i < KAttrTop; i++)
sl@0
   201
		{
sl@0
   202
		if (set1->IsSet(i) && i != EIsCopyable && i != EIsModifyable)
sl@0
   203
			{
sl@0
   204
			INFO_PRINTF1(_L("SetList(1) failed."));
sl@0
   205
			SetTestStepResult(EFail);
sl@0
   206
			}
sl@0
   207
		}
sl@0
   208
sl@0
   209
	if (!set1->IsSet(EIsModifyable) || !set1->IsSet(EIsCopyable))
sl@0
   210
		{
sl@0
   211
		INFO_PRINTF1(_L("SetList(2) failed."));
sl@0
   212
		SetTestStepResult(EFail);
sl@0
   213
		}
sl@0
   214
sl@0
   215
	// Now check the IsSetList call
sl@0
   216
	INFO_PRINTF1(_L("Performing IsSetList calls"));
sl@0
   217
	if (!set1->IsSetList(2, EIsCopyable, EIsModifyable))
sl@0
   218
		{
sl@0
   219
		INFO_PRINTF1(_L("IsSetList call(3) failed."));
sl@0
   220
		SetTestStepResult(EFail);
sl@0
   221
		}
sl@0
   222
sl@0
   223
	if (set1->IsSetList(2, EIsProtected, EIsForwardable))
sl@0
   224
		{
sl@0
   225
		INFO_PRINTF1(_L("IsSetList call(4) failed."));
sl@0
   226
		SetTestStepResult(EFail);
sl@0
   227
		}
sl@0
   228
sl@0
   229
	CleanupStack::PopAndDestroy(set1);	
sl@0
   230
	__UHEAP_MARKEND;
sl@0
   231
sl@0
   232
	return TestStepResult();
sl@0
   233
	}
sl@0
   234
sl@0
   235
// --------------------------------------------------------------------------
sl@0
   236
sl@0
   237
CBitsetEqualityStep::CBitsetEqualityStep()
sl@0
   238
	: CBitsetBaseStep(KBitsetEqualityStep)
sl@0
   239
	{
sl@0
   240
	}
sl@0
   241
sl@0
   242
TVerdict CBitsetEqualityStep::doTestStepL()
sl@0
   243
	{
sl@0
   244
	SetTestStepResult(EPass); // Default result to EPass
sl@0
   245
sl@0
   246
	__UHEAP_MARK;
sl@0
   247
	// Get the bitset from the script section
sl@0
   248
	CBitset* left = GetBitsetLC(_L("left-"));
sl@0
   249
	CBitset* right = GetBitsetLC(_L("right-"));
sl@0
   250
sl@0
   251
	// Now see whether we expect the result to be equal
sl@0
   252
	TBool equalExpected = EFalse;
sl@0
   253
	GetIntFromConfig(ConfigSection(), _L("equal"), equalExpected);
sl@0
   254
sl@0
   255
	if (equalExpected)
sl@0
   256
		{
sl@0
   257
		INFO_PRINTF1(_L("Equality expected"));
sl@0
   258
		}
sl@0
   259
	else
sl@0
   260
		{
sl@0
   261
		INFO_PRINTF1(_L("Inequality expected"));
sl@0
   262
		}
sl@0
   263
sl@0
   264
	TBool result = (*left == *right);
sl@0
   265
	if (!result != !equalExpected)
sl@0
   266
		{
sl@0
   267
		INFO_PRINTF1(_L("Equality test failed."));
sl@0
   268
		SetTestStepResult(EFail);
sl@0
   269
		}
sl@0
   270
	CleanupStack::PopAndDestroy(2, left);
sl@0
   271
sl@0
   272
	__UHEAP_MARKEND;
sl@0
   273
sl@0
   274
	return TestStepResult();
sl@0
   275
	}
sl@0
   276
sl@0
   277
// --------------------------------------------------------------------------
sl@0
   278
sl@0
   279
CBitsetCopyStep::CBitsetCopyStep()
sl@0
   280
	: CBitsetBaseStep(KBitsetCopyStep)
sl@0
   281
	{
sl@0
   282
	}
sl@0
   283
sl@0
   284
TVerdict CBitsetCopyStep::doTestStepL()
sl@0
   285
	{
sl@0
   286
	SetTestStepResult(EPass); // Default result to EPass
sl@0
   287
sl@0
   288
	__UHEAP_MARK;
sl@0
   289
	// Get the bitset from the script section
sl@0
   290
	CBitset* set = GetBitsetLC(KNullDesC);
sl@0
   291
sl@0
   292
	// Now, create a copy
sl@0
   293
	CBitset* copy = CBitset::NewLC(*set);
sl@0
   294
sl@0
   295
	// Now check the copy
sl@0
   296
	if (*set != *copy)
sl@0
   297
		{
sl@0
   298
		INFO_PRINTF1(_L("Copy constructor return unequal result."));
sl@0
   299
		SetTestStepResult(EFail);
sl@0
   300
		}
sl@0
   301
sl@0
   302
	// Now create another bitset of arbitrary length
sl@0
   303
	CBitset* another = CBitset::NewLC(5);
sl@0
   304
sl@0
   305
	// Perform assignment
sl@0
   306
	*another = *copy;
sl@0
   307
sl@0
   308
	// Now check another equals the original set
sl@0
   309
	if (*set != *another)
sl@0
   310
		{
sl@0
   311
		INFO_PRINTF1(_L("operator= returned unequal result."));
sl@0
   312
		SetTestStepResult(EFail);
sl@0
   313
		}
sl@0
   314
sl@0
   315
	// Now invert another and copy and make sure they are equal
sl@0
   316
	another->Invert();
sl@0
   317
	copy->Invert();
sl@0
   318
sl@0
   319
	if (*copy != *another)
sl@0
   320
		{
sl@0
   321
		INFO_PRINTF1(_L("Invert returned unequal result."));
sl@0
   322
		SetTestStepResult(EFail);
sl@0
   323
		}
sl@0
   324
sl@0
   325
	// Invert the copy again and ensure it is equal to the original
sl@0
   326
	copy->Invert();
sl@0
   327
	if (*set != *copy)
sl@0
   328
		{
sl@0
   329
		INFO_PRINTF1(_L("Double invert fails."));
sl@0
   330
		SetTestStepResult(EFail);
sl@0
   331
		}
sl@0
   332
sl@0
   333
	CleanupStack::PopAndDestroy(3, set);
sl@0
   334
sl@0
   335
	__UHEAP_MARKEND;
sl@0
   336
sl@0
   337
	return TestStepResult();
sl@0
   338
	}
sl@0
   339
sl@0
   340
// --------------------------------------------------------------------------
sl@0
   341
sl@0
   342
CBitsetSerialiseStep::CBitsetSerialiseStep()
sl@0
   343
	: CBitsetBaseStep(KBitsetSerialiseStep)
sl@0
   344
	{
sl@0
   345
	}
sl@0
   346
sl@0
   347
TVerdict CBitsetSerialiseStep::doTestStepL()
sl@0
   348
	{
sl@0
   349
	SetTestStepResult(EPass); // Default result to EPass
sl@0
   350
sl@0
   351
	__UHEAP_MARK;
sl@0
   352
	// Get the bitset from the script section
sl@0
   353
	CBitset* set = GetBitsetLC(KNullDesC);
sl@0
   354
sl@0
   355
	// Create a buffer stream
sl@0
   356
	CBufFlat* buf = CBufFlat::NewL(50);
sl@0
   357
	CleanupStack::PushL(buf);
sl@0
   358
	RBufWriteStream stream(*buf);
sl@0
   359
	CleanupClosePushL(stream);
sl@0
   360
sl@0
   361
	// call the stream function
sl@0
   362
	stream << *set;
sl@0
   363
	CleanupStack::PopAndDestroy(&stream);
sl@0
   364
sl@0
   365
	// Now, create an HBufC8 from the stream buf's length, and copy 
sl@0
   366
	// the stream buffer into this descriptor
sl@0
   367
	HBufC8* des = HBufC8::NewL(buf->Size());
sl@0
   368
	TPtr8 ptr(des->Des());
sl@0
   369
	buf->Read(0, ptr, buf->Size());
sl@0
   370
sl@0
   371
	// destroy the buffer
sl@0
   372
	CleanupStack::PopAndDestroy(buf);
sl@0
   373
	CleanupStack::PushL(des);
sl@0
   374
sl@0
   375
	// Now, stream a new bitset from the descriptor
sl@0
   376
	CBitset* newset = CBitset::NewLC(5);
sl@0
   377
	RDesReadStream readstream(*des);
sl@0
   378
	CleanupClosePushL(readstream);
sl@0
   379
	readstream >> *newset;
sl@0
   380
	CleanupStack::PopAndDestroy(&readstream);
sl@0
   381
sl@0
   382
	// Now check that the new bitset equals the old one
sl@0
   383
	if (*set != *newset)
sl@0
   384
		{
sl@0
   385
		INFO_PRINTF1(_L("serialisation returned unequal result."));
sl@0
   386
		SetTestStepResult(EFail);
sl@0
   387
		}
sl@0
   388
sl@0
   389
	CleanupStack::PopAndDestroy(3, set);
sl@0
   390
sl@0
   391
	__UHEAP_MARKEND;
sl@0
   392
sl@0
   393
	return TestStepResult();
sl@0
   394
	}
sl@0
   395
sl@0
   396
// --------------------------------------------------------------------------
sl@0
   397
sl@0
   398
CBitsetPanicStep::CBitsetPanicStep()
sl@0
   399
	: CBitsetBaseStep(KBitsetPanicStep)
sl@0
   400
	{
sl@0
   401
	}
sl@0
   402
sl@0
   403
TVerdict CBitsetPanicStep::doTestStepL()
sl@0
   404
	{
sl@0
   405
	SetTestStepResult(EPass); // Default result to EPass
sl@0
   406
sl@0
   407
	__UHEAP_MARK;
sl@0
   408
	// Get the bitset from the script section
sl@0
   409
	CBitset* panic = GetBitsetLC(_L("panic-"));
sl@0
   410
sl@0
   411
	// Now see whether we expect the result to be equal
sl@0
   412
	TInt panictest = -1;
sl@0
   413
	GetIntFromConfig(ConfigSection(), _L("panictest"), panictest);
sl@0
   414
sl@0
   415
	// all of the following cases should panic
sl@0
   416
	switch(panictest)
sl@0
   417
		{
sl@0
   418
	case 1:
sl@0
   419
		INFO_PRINTF1(_L("IsSet(-1)"));
sl@0
   420
		panic->IsSet(-1);
sl@0
   421
		break;
sl@0
   422
	case 2:
sl@0
   423
		INFO_PRINTF1(_L("IsSet(MaxBits()+1)"));
sl@0
   424
		panic->IsSet(panic->MaxBits()+1);
sl@0
   425
		break;
sl@0
   426
	case 3:
sl@0
   427
		INFO_PRINTF1(_L("Set(-1)"));
sl@0
   428
		panic->Set(-1);
sl@0
   429
		break;
sl@0
   430
	case 4:
sl@0
   431
		INFO_PRINTF1(_L("Set(MaxBits()+1)"));
sl@0
   432
		panic->Set(panic->MaxBits()+1);
sl@0
   433
		break;
sl@0
   434
	case 5:
sl@0
   435
		INFO_PRINTF1(_L("UnSet(-1)"));
sl@0
   436
		panic->Unset(-1);
sl@0
   437
		break;
sl@0
   438
	case 6:
sl@0
   439
		INFO_PRINTF1(_L("UnSet(MaxBits()+1)"));
sl@0
   440
		panic->Unset(panic->MaxBits()+1);
sl@0
   441
		break;
sl@0
   442
sl@0
   443
	default:
sl@0
   444
		SetTestStepResult(EFail); 
sl@0
   445
		};
sl@0
   446
sl@0
   447
	SetTestStepResult(EFail); 
sl@0
   448
	CleanupStack::PopAndDestroy(panic);
sl@0
   449
sl@0
   450
	__UHEAP_MARKEND;
sl@0
   451
sl@0
   452
	return TestStepResult();
sl@0
   453
	}
sl@0
   454