os/security/contentmgmt/referencedrmagent/tcaf/source/RightsManagerStep.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2004-2010 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 <test/testexecutelog.h>
sl@0
    20
#include "cafserver.h"
sl@0
    21
#include "RightsManagerStep.h"
sl@0
    22
#include "manager.h"
sl@0
    23
#include "rightsmanager.h"
sl@0
    24
#include "virtualpathptr.h"
sl@0
    25
#include "StreamablePtrArray.h"
sl@0
    26
#include "agent.h"
sl@0
    27
#include "rightsinfo.h"
sl@0
    28
#include "virtualpath.h"
sl@0
    29
sl@0
    30
sl@0
    31
using namespace ContentAccess;
sl@0
    32
sl@0
    33
sl@0
    34
/* 
sl@0
    35
 * This step creates a rights manager
sl@0
    36
 *
sl@0
    37
 */
sl@0
    38
sl@0
    39
CCAFRightsManagerStep::~CCAFRightsManagerStep()
sl@0
    40
	{
sl@0
    41
	}
sl@0
    42
sl@0
    43
CCAFRightsManagerStep::CCAFRightsManagerStep(CCAFServer& aParent) : iParent(aParent)
sl@0
    44
	{
sl@0
    45
	SetTestStepName(KCAFRightsManagerStep);
sl@0
    46
	}
sl@0
    47
sl@0
    48
sl@0
    49
TVerdict CCAFRightsManagerStep::doTestStepL()
sl@0
    50
	{
sl@0
    51
	TInt expectedResult;
sl@0
    52
	TInt result;
sl@0
    53
	CRightsManager *rightsmanager = NULL;
sl@0
    54
	
sl@0
    55
	RArray <TAgent> agents;
sl@0
    56
sl@0
    57
	SetTestStepResult(EFail);
sl@0
    58
sl@0
    59
	// Find the file to delete and the expected return code from the INI file
sl@0
    60
	GetIntFromConfig(ConfigSection(),_L("result"),expectedResult);
sl@0
    61
sl@0
    62
	INFO_PRINTF2(_L("CreateAgentResolver Expected result: %d"), expectedResult);
sl@0
    63
sl@0
    64
	__UHEAP_MARK;
sl@0
    65
	CManager *manager = CManager::NewL();
sl@0
    66
	CleanupStack::PushL(manager);
sl@0
    67
	TRAP(result, manager->ListAgentsL(agents));
sl@0
    68
		
sl@0
    69
	if(result == KErrNone && agents.Count() > 0)
sl@0
    70
		{
sl@0
    71
		TRAP(result, rightsmanager = manager->CreateRightsManagerL(agents[0]));
sl@0
    72
		CleanupStack::PushL(rightsmanager);
sl@0
    73
		if(result != expectedResult && rightsmanager)
sl@0
    74
			{	
sl@0
    75
			INFO_PRINTF3(_L("Create Rights Manager Expected result: %d, actual result: %d"), expectedResult, result);
sl@0
    76
			}
sl@0
    77
		else
sl@0
    78
			{
sl@0
    79
			SetTestStepResult(EPass);	
sl@0
    80
			}
sl@0
    81
		CleanupStack::PopAndDestroy(rightsmanager);
sl@0
    82
		}
sl@0
    83
sl@0
    84
	CleanupStack::PopAndDestroy(manager);		
sl@0
    85
	agents.Close();
sl@0
    86
    		
sl@0
    87
	__UHEAP_MARKEND;
sl@0
    88
	return TestStepResult();
sl@0
    89
	}
sl@0
    90
sl@0
    91
sl@0
    92
/* 
sl@0
    93
 * This step creates tests the rights manager listing functions
sl@0
    94
 *
sl@0
    95
 */
sl@0
    96
sl@0
    97
CCAFRightsManagerListStep::~CCAFRightsManagerListStep()
sl@0
    98
	{
sl@0
    99
	}
sl@0
   100
sl@0
   101
CCAFRightsManagerListStep::CCAFRightsManagerListStep(CCAFServer& aParent) : iParent(aParent)
sl@0
   102
	{
sl@0
   103
	SetTestStepName(KCAFRightsManagerListStep);
sl@0
   104
	}
sl@0
   105
sl@0
   106
sl@0
   107
TVerdict CCAFRightsManagerListStep::doTestStepL()
sl@0
   108
	{
sl@0
   109
	TInt expectedResult;
sl@0
   110
	TInt result;
sl@0
   111
	TInt ListAPI;
sl@0
   112
	TPtrC uri;
sl@0
   113
	CRightsManager *rightsManager = NULL;
sl@0
   114
	
sl@0
   115
	RArray <TAgent> agents;
sl@0
   116
	RStreamablePtrArray <CRightsInfo> rights;
sl@0
   117
	RStreamablePtrArray <CVirtualPath> contentList;
sl@0
   118
sl@0
   119
	SetTestStepResult(EFail);
sl@0
   120
sl@0
   121
	// Find the file to delete and the expected return code from the INI file
sl@0
   122
	GetIntFromConfig(ConfigSection(),_L("API"),ListAPI);
sl@0
   123
	
sl@0
   124
	if(ListAPI !=8 && ListAPI !=9)
sl@0
   125
		{
sl@0
   126
		GetStringFromConfig(ConfigSection(),_L("uri"),uri);
sl@0
   127
		GetIntFromConfig(ConfigSection(),_L("result"),expectedResult);
sl@0
   128
		}
sl@0
   129
		
sl@0
   130
	__UHEAP_MARK;
sl@0
   131
	CManager *manager = CManager::NewL();
sl@0
   132
	CleanupStack::PushL(manager);
sl@0
   133
	TRAP(result, manager->ListAgentsL(agents));
sl@0
   134
		
sl@0
   135
	if(result == KErrNone && agents.Count() > 0)
sl@0
   136
		{
sl@0
   137
		TRAP(result, rightsManager = manager->CreateRightsManagerL(agents[0]));
sl@0
   138
		CleanupStack::PopAndDestroy(manager);		
sl@0
   139
		if(rightsManager)
sl@0
   140
			{	
sl@0
   141
			CleanupStack::PushL(rightsManager);
sl@0
   142
			if(ListAPI == 1)
sl@0
   143
				{
sl@0
   144
				rightsManager->ListAllRightsL(rights);
sl@0
   145
				CleanupClosePushL(rights);
sl@0
   146
				if(rights.Count() == 1)
sl@0
   147
					{
sl@0
   148
					SetTestStepResult(EPass);
sl@0
   149
					}
sl@0
   150
				else
sl@0
   151
					{
sl@0
   152
					INFO_PRINTF1(_L("ListAllRights() is empty"));			
sl@0
   153
					}
sl@0
   154
				CleanupStack::PopAndDestroy(&rights);
sl@0
   155
				}
sl@0
   156
			else if(ListAPI == 2)
sl@0
   157
				{
sl@0
   158
				rightsManager->ListRightsL(rights, uri);
sl@0
   159
				CleanupClosePushL(rights);
sl@0
   160
				if(rights.Count() == 1)
sl@0
   161
					{
sl@0
   162
					SetTestStepResult(EPass);
sl@0
   163
					}
sl@0
   164
				else
sl@0
   165
					{
sl@0
   166
					INFO_PRINTF1(_L("ListRights(uri) is empty"));			
sl@0
   167
					}
sl@0
   168
				CleanupStack::PopAndDestroy(&rights);
sl@0
   169
				}
sl@0
   170
			else if(ListAPI == 3)
sl@0
   171
				{
sl@0
   172
				TVirtualPathPtr virtualPath = uri;
sl@0
   173
				rightsManager->ListRightsL(rights, virtualPath );
sl@0
   174
				CleanupClosePushL(rights);
sl@0
   175
				if(rights.Count() == 1)
sl@0
   176
					{
sl@0
   177
					SetTestStepResult(EPass);
sl@0
   178
					}
sl@0
   179
				else
sl@0
   180
					{
sl@0
   181
					INFO_PRINTF1(_L("ListRights(TVirtualPathPtr) is empty"));			
sl@0
   182
					}
sl@0
   183
				CleanupStack::PopAndDestroy(&rights);
sl@0
   184
				}
sl@0
   185
			else if(ListAPI == 4)
sl@0
   186
				{
sl@0
   187
				CRightsInfo *rightsInfo = CRightsInfo::NewL(KNullDesC(), KNullDesC(), ERightsTypeConsumable , ERightsStatusNone);
sl@0
   188
				CleanupStack::PushL(rightsInfo);
sl@0
   189
				rightsManager->ListContentL(contentList, *rightsInfo);
sl@0
   190
				CleanupStack::PopAndDestroy(rightsInfo);
sl@0
   191
				CleanupClosePushL(contentList);
sl@0
   192
				if(contentList.Count() == 1)
sl@0
   193
					{
sl@0
   194
					SetTestStepResult(EPass);
sl@0
   195
					}
sl@0
   196
				else
sl@0
   197
					{
sl@0
   198
					INFO_PRINTF1(_L("ListContent(CRightsInfo) is empty"));			
sl@0
   199
					}
sl@0
   200
				CleanupStack::PopAndDestroy(&contentList);
sl@0
   201
				}
sl@0
   202
			else if(ListAPI == 5)
sl@0
   203
				{
sl@0
   204
				CRightsInfo *rightsInfo = CRightsInfo::NewL(KNullDesC(), KNullDesC(), ERightsTypeConsumable , ERightsStatusNone);
sl@0
   205
				CleanupStack::PushL(rightsInfo);
sl@0
   206
				MAgentRightsBase *ptr = rightsManager->GetRightsDataL(*rightsInfo);
sl@0
   207
				CleanupStack::PopAndDestroy(rightsInfo);
sl@0
   208
				if(ptr == NULL)
sl@0
   209
					{
sl@0
   210
					SetTestStepResult(EPass);
sl@0
   211
					}
sl@0
   212
				}
sl@0
   213
			else if(ListAPI == 6)
sl@0
   214
				{
sl@0
   215
				CRightsInfo *rightsInfo = CRightsInfo::NewL(KNullDesC(), KNullDesC(), ERightsTypeStateless  , ERightsStatusNone);
sl@0
   216
				CleanupStack::PushL(rightsInfo);
sl@0
   217
				result = rightsManager->DeleteRightsObject(*rightsInfo);
sl@0
   218
				CleanupStack::PopAndDestroy(rightsInfo);
sl@0
   219
				if(result == KErrNone)
sl@0
   220
					{
sl@0
   221
					SetTestStepResult(EPass);
sl@0
   222
					}
sl@0
   223
				}
sl@0
   224
			else if(ListAPI == 7)
sl@0
   225
				{
sl@0
   226
				TVirtualPathPtr virtualPath = uri;
sl@0
   227
				result = rightsManager->DeleteAllRightsObjects(virtualPath);
sl@0
   228
				if(result == KErrNone)
sl@0
   229
					{
sl@0
   230
					SetTestStepResult(EPass);
sl@0
   231
					}
sl@0
   232
				}
sl@0
   233
			else if(ListAPI == 8 || ListAPI == 9)
sl@0
   234
				{
sl@0
   235
				//initialisation for testing purposes such as  iUri, iFs, iFile, iExpectedResult and iUniqueId. 
sl@0
   236
				InitialiseFileHandleParametersL();
sl@0
   237
				
sl@0
   238
				// test the RFile overload
sl@0
   239
				if (ListAPI ==8)
sl@0
   240
					{
sl@0
   241
					TRAP(result,rightsManager->ListRightsL(rights, iFile, iUniqueId));
sl@0
   242
					CleanupClosePushL(rights);	
sl@0
   243
											
sl@0
   244
					if(result == iExpectedResult)
sl@0
   245
						{
sl@0
   246
						SetTestStepResult(EPass);
sl@0
   247
						INFO_PRINTF1(_L("CRightsManager::ListRightsL()(RFile handle overload) PASSED"));
sl@0
   248
						}
sl@0
   249
					else
sl@0
   250
						{
sl@0
   251
						INFO_PRINTF1(_L("CRightsManager::ListRightsL()(RFile handle overload) returned unexpected error"));
sl@0
   252
						INFO_PRINTF3(_L("CRightsManager::ListRightsL()(RFile handle overload) Expected result: %d, actual result: %d"), iExpectedResult, result);	
sl@0
   253
						}	
sl@0
   254
					CleanupStack::PopAndDestroy(&rights);	
sl@0
   255
					}
sl@0
   256
				else if (ListAPI ==9)
sl@0
   257
					{
sl@0
   258
					result = rightsManager->DeleteAllRightsObjects(iFile, iUniqueId);
sl@0
   259
				
sl@0
   260
					if(result == iExpectedResult)
sl@0
   261
						{
sl@0
   262
						SetTestStepResult(EPass);
sl@0
   263
						INFO_PRINTF1(_L("CRightsManager::DeleteAllRightsObjects()(RFile handle overload) PASSED"));
sl@0
   264
						}
sl@0
   265
					else
sl@0
   266
						{
sl@0
   267
						INFO_PRINTF1(_L("CRightsManager::DeleteAllRightsObjects()(RFile handle overload) returned unexpected error"));		
sl@0
   268
						INFO_PRINTF3(_L("CRightsManager::DeleteAllRightsObjects()(RFile handle overload) Expected result: %d, actual result: %d"), iExpectedResult, result);	
sl@0
   269
						}						
sl@0
   270
					}
sl@0
   271
				//cleanup iFs and iFile instances by closing the handles.
sl@0
   272
				CleanupStack::PopAndDestroy(2, &iFs);	
sl@0
   273
				}
sl@0
   274
			CleanupStack::PopAndDestroy(rightsManager);
sl@0
   275
			}
sl@0
   276
		else
sl@0
   277
			{
sl@0
   278
			if (result == KErrNotSupported) // dummy test agent expects -5
sl@0
   279
				{
sl@0
   280
				SetTestStepResult(EPass);
sl@0
   281
				}
sl@0
   282
			else
sl@0
   283
				{
sl@0
   284
				INFO_PRINTF1(_L("Create CRightsManager Failed"));		
sl@0
   285
				}
sl@0
   286
			}
sl@0
   287
		}
sl@0
   288
	else
sl@0
   289
		{
sl@0
   290
		INFO_PRINTF1(_L("Create CManager Failed"));
sl@0
   291
		}
sl@0
   292
	agents.Close();
sl@0
   293
    		
sl@0
   294
	__UHEAP_MARKEND;
sl@0
   295
	return TestStepResult();
sl@0
   296
	}
sl@0
   297