First public contribution.
2 * Copyright (c) 2004-2010 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
19 #include <test/testexecutelog.h>
20 #include "cafserver.h"
21 #include "RightsManagerStep.h"
23 #include "rightsmanager.h"
24 #include "virtualpathptr.h"
25 #include "StreamablePtrArray.h"
27 #include "rightsinfo.h"
28 #include "virtualpath.h"
31 using namespace ContentAccess;
35 * This step creates a rights manager
39 CCAFRightsManagerStep::~CCAFRightsManagerStep()
43 CCAFRightsManagerStep::CCAFRightsManagerStep(CCAFServer& aParent) : iParent(aParent)
45 SetTestStepName(KCAFRightsManagerStep);
49 TVerdict CCAFRightsManagerStep::doTestStepL()
53 CRightsManager *rightsmanager = NULL;
55 RArray <TAgent> agents;
57 SetTestStepResult(EFail);
59 // Find the file to delete and the expected return code from the INI file
60 GetIntFromConfig(ConfigSection(),_L("result"),expectedResult);
62 INFO_PRINTF2(_L("CreateAgentResolver Expected result: %d"), expectedResult);
65 CManager *manager = CManager::NewL();
66 CleanupStack::PushL(manager);
67 TRAP(result, manager->ListAgentsL(agents));
69 if(result == KErrNone && agents.Count() > 0)
71 TRAP(result, rightsmanager = manager->CreateRightsManagerL(agents[0]));
72 CleanupStack::PushL(rightsmanager);
73 if(result != expectedResult && rightsmanager)
75 INFO_PRINTF3(_L("Create Rights Manager Expected result: %d, actual result: %d"), expectedResult, result);
79 SetTestStepResult(EPass);
81 CleanupStack::PopAndDestroy(rightsmanager);
84 CleanupStack::PopAndDestroy(manager);
88 return TestStepResult();
93 * This step creates tests the rights manager listing functions
97 CCAFRightsManagerListStep::~CCAFRightsManagerListStep()
101 CCAFRightsManagerListStep::CCAFRightsManagerListStep(CCAFServer& aParent) : iParent(aParent)
103 SetTestStepName(KCAFRightsManagerListStep);
107 TVerdict CCAFRightsManagerListStep::doTestStepL()
113 CRightsManager *rightsManager = NULL;
115 RArray <TAgent> agents;
116 RStreamablePtrArray <CRightsInfo> rights;
117 RStreamablePtrArray <CVirtualPath> contentList;
119 SetTestStepResult(EFail);
121 // Find the file to delete and the expected return code from the INI file
122 GetIntFromConfig(ConfigSection(),_L("API"),ListAPI);
124 if(ListAPI !=8 && ListAPI !=9)
126 GetStringFromConfig(ConfigSection(),_L("uri"),uri);
127 GetIntFromConfig(ConfigSection(),_L("result"),expectedResult);
131 CManager *manager = CManager::NewL();
132 CleanupStack::PushL(manager);
133 TRAP(result, manager->ListAgentsL(agents));
135 if(result == KErrNone && agents.Count() > 0)
137 TRAP(result, rightsManager = manager->CreateRightsManagerL(agents[0]));
138 CleanupStack::PopAndDestroy(manager);
141 CleanupStack::PushL(rightsManager);
144 rightsManager->ListAllRightsL(rights);
145 CleanupClosePushL(rights);
146 if(rights.Count() == 1)
148 SetTestStepResult(EPass);
152 INFO_PRINTF1(_L("ListAllRights() is empty"));
154 CleanupStack::PopAndDestroy(&rights);
156 else if(ListAPI == 2)
158 rightsManager->ListRightsL(rights, uri);
159 CleanupClosePushL(rights);
160 if(rights.Count() == 1)
162 SetTestStepResult(EPass);
166 INFO_PRINTF1(_L("ListRights(uri) is empty"));
168 CleanupStack::PopAndDestroy(&rights);
170 else if(ListAPI == 3)
172 TVirtualPathPtr virtualPath = uri;
173 rightsManager->ListRightsL(rights, virtualPath );
174 CleanupClosePushL(rights);
175 if(rights.Count() == 1)
177 SetTestStepResult(EPass);
181 INFO_PRINTF1(_L("ListRights(TVirtualPathPtr) is empty"));
183 CleanupStack::PopAndDestroy(&rights);
185 else if(ListAPI == 4)
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)
194 SetTestStepResult(EPass);
198 INFO_PRINTF1(_L("ListContent(CRightsInfo) is empty"));
200 CleanupStack::PopAndDestroy(&contentList);
202 else if(ListAPI == 5)
204 CRightsInfo *rightsInfo = CRightsInfo::NewL(KNullDesC(), KNullDesC(), ERightsTypeConsumable , ERightsStatusNone);
205 CleanupStack::PushL(rightsInfo);
206 MAgentRightsBase *ptr = rightsManager->GetRightsDataL(*rightsInfo);
207 CleanupStack::PopAndDestroy(rightsInfo);
210 SetTestStepResult(EPass);
213 else if(ListAPI == 6)
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)
221 SetTestStepResult(EPass);
224 else if(ListAPI == 7)
226 TVirtualPathPtr virtualPath = uri;
227 result = rightsManager->DeleteAllRightsObjects(virtualPath);
228 if(result == KErrNone)
230 SetTestStepResult(EPass);
233 else if(ListAPI == 8 || ListAPI == 9)
235 //initialisation for testing purposes such as iUri, iFs, iFile, iExpectedResult and iUniqueId.
236 InitialiseFileHandleParametersL();
238 // test the RFile overload
241 TRAP(result,rightsManager->ListRightsL(rights, iFile, iUniqueId));
242 CleanupClosePushL(rights);
244 if(result == iExpectedResult)
246 SetTestStepResult(EPass);
247 INFO_PRINTF1(_L("CRightsManager::ListRightsL()(RFile handle overload) PASSED"));
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);
254 CleanupStack::PopAndDestroy(&rights);
256 else if (ListAPI ==9)
258 result = rightsManager->DeleteAllRightsObjects(iFile, iUniqueId);
260 if(result == iExpectedResult)
262 SetTestStepResult(EPass);
263 INFO_PRINTF1(_L("CRightsManager::DeleteAllRightsObjects()(RFile handle overload) PASSED"));
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);
271 //cleanup iFs and iFile instances by closing the handles.
272 CleanupStack::PopAndDestroy(2, &iFs);
274 CleanupStack::PopAndDestroy(rightsManager);
278 if (result == KErrNotSupported) // dummy test agent expects -5
280 SetTestStepResult(EPass);
284 INFO_PRINTF1(_L("Create CRightsManager Failed"));
290 INFO_PRINTF1(_L("Create CManager Failed"));
295 return TestStepResult();