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