|
1 /* |
|
2 * Copyright (c) 2004-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 #include <test/testexecutelog.h> |
|
20 #include <apmstd.h> |
|
21 #include <caf/caf.h> |
|
22 #include <caf/manager.h> |
|
23 #include <caf/supplier.h> |
|
24 #include <caf/importfile.h> |
|
25 #include <caf/supplieroutputfile.h> |
|
26 #include "archivestep.h" |
|
27 #include "rtaArchive.h" |
|
28 #include "reftestagentconstants.h" |
|
29 |
|
30 #include <apgcli.h> |
|
31 using namespace ReferenceTestAgent; |
|
32 using namespace ContentAccess; |
|
33 |
|
34 CCreateDrmArchive::~CCreateDrmArchive() |
|
35 { |
|
36 } |
|
37 |
|
38 CCreateDrmArchive::CCreateDrmArchive(CRTAUtilsServer& aParent) : iParent(aParent) |
|
39 { |
|
40 SetTestStepName(KCreateDrmArchive); |
|
41 } |
|
42 |
|
43 |
|
44 TVerdict CCreateDrmArchive::doTestStepL() |
|
45 { |
|
46 // SetTestStepResult(EInconclusive) is a bad idea. |
|
47 // It makes the TEST macroes unusable. |
|
48 |
|
49 TPtrC contentXml; |
|
50 TPtrC rightsXml; |
|
51 TPtrC outputFile; |
|
52 GetStringFromConfig(ConfigSection(),_L("ContentDescription"),contentXml); |
|
53 GetStringFromConfig(ConfigSection(),_L("RightsDescription"),rightsXml); |
|
54 GetStringFromConfig(ConfigSection(),_L("OutputFile"),outputFile); |
|
55 __UHEAP_MARK; |
|
56 |
|
57 INFO_PRINTF1(_L("Creating DRM archive using the following parameters")); |
|
58 INFO_PRINTF2(_L(" Content Xml Description : %S"),&contentXml); |
|
59 INFO_PRINTF2(_L(" Rights Xml Description : %S"),&rightsXml); |
|
60 INFO_PRINTF2(_L(" Output File : %S"),&outputFile); |
|
61 |
|
62 // CreateArchive will need to modify the output file name |
|
63 TFileName outputFileName; |
|
64 outputFileName.Copy(outputFile); |
|
65 |
|
66 TBuf8 <KMaxDataTypeLength> mimeType; |
|
67 |
|
68 TInt err = CRefTestAgentArchive::CreateArchive(contentXml, rightsXml, outputFileName, mimeType); |
|
69 if(err != KErrNone) |
|
70 { |
|
71 INFO_PRINTF3(_L("ERROR: %d, Create Archive \"%S\" failed"), err, &outputFileName); |
|
72 INFO_PRINTF1(_L(" Check c:\\logs\\rta\\rta.log to make sure input XML is correct and make sure the output file does not already exist")); |
|
73 SetTestStepResult(EFail); |
|
74 } |
|
75 else |
|
76 { |
|
77 TBuf <KMaxDataTypeLength> mimeType16; |
|
78 mimeType16.Copy(mimeType); |
|
79 INFO_PRINTF1(_L("Drm Archive Created Successfully")); |
|
80 INFO_PRINTF2(_L(" Mime Type of Output File: %S"),&mimeType16); |
|
81 INFO_PRINTF2(_L(" Output File Produced : %S"),&outputFileName); |
|
82 } |
|
83 |
|
84 __UHEAP_MARKEND; |
|
85 |
|
86 |
|
87 return TestStepResult(); |
|
88 } |
|
89 |
|
90 |
|
91 CImportDrmArchive::~CImportDrmArchive() |
|
92 { |
|
93 } |
|
94 |
|
95 CImportDrmArchive::CImportDrmArchive(CRTAUtilsServer& aParent) : iParent(aParent) |
|
96 { |
|
97 SetTestStepName(KImportDrmArchive); |
|
98 } |
|
99 |
|
100 |
|
101 TVerdict CImportDrmArchive::doTestStepL() |
|
102 { |
|
103 // SetTestStepResult(EInconclusive) is a bad idea. |
|
104 // It makes the TEST macroes unusable. |
|
105 |
|
106 TPtrC source; |
|
107 TPtrC target; |
|
108 TPtrC importerMode; |
|
109 |
|
110 GetStringFromConfig(ConfigSection(),_L("source"),source); |
|
111 GetStringFromConfig(ConfigSection(),_L("target"),target); |
|
112 |
|
113 // importerMode is optional in ini file. If the token exist and its |
|
114 // value == ClientCreateFiles, then RTAUtils will hide the output |
|
115 // filename from CImportFile and handle opening the output file |
|
116 // and receipt files itself. |
|
117 GetStringFromConfig(ConfigSection(),_L("importerMode"),importerMode); |
|
118 |
|
119 _LIT(KClientCreateFiles, "ClientCreateFiles"); |
|
120 TBool doFileCreate = (importerMode.CompareF(KClientCreateFiles) == 0); |
|
121 |
|
122 INFO_PRINTF2(_L("Importing DRM archive : %S "), &source); |
|
123 INFO_PRINTF2(_L("Writing output archive: %S "), &target); |
|
124 |
|
125 TPtrC outputPath; |
|
126 TPtrC suggestedOutFileName; |
|
127 |
|
128 TParsePtrC parser(target); |
|
129 outputPath.Set( parser.DriveAndPath() ); |
|
130 suggestedOutFileName.Set( parser.NameAndExt() ); |
|
131 |
|
132 __UHEAP_MARK; |
|
133 TInt numpushed(0); |
|
134 |
|
135 // create a supplier session |
|
136 CSupplier *mySupplier = CSupplier::NewLC(); |
|
137 numpushed++; |
|
138 |
|
139 mySupplier->SetOutputDirectoryL(outputPath); |
|
140 |
|
141 // fill in a metadata array with just the mime type |
|
142 CMetaDataArray *metaDataArray = CMetaDataArray::NewL(); |
|
143 CleanupStack::PushL(metaDataArray); |
|
144 numpushed++; |
|
145 |
|
146 _LIT8(KContentType,"content-type"); |
|
147 metaDataArray->AddL(KContentType(), KRtaMimeRights); |
|
148 metaDataArray->AddL(KContentType(), KRtaMimeContentRights); |
|
149 |
|
150 CImportFile* import = NULL; |
|
151 if (doFileCreate) |
|
152 { |
|
153 import = mySupplier->ImportFileL(KRtaMimeContentRights, *metaDataArray); |
|
154 } |
|
155 else |
|
156 { |
|
157 import = mySupplier->ImportFileL(KRtaMimeContentRights, *metaDataArray, suggestedOutFileName); |
|
158 } |
|
159 |
|
160 CleanupStack::PopAndDestroy(metaDataArray); // numpushed-- |
|
161 CleanupStack::PushL(import); // numpushed++, so cancel with line above |
|
162 |
|
163 RFs fs; |
|
164 User::LeaveIfError(fs.Connect()); |
|
165 CleanupClosePushL(fs); |
|
166 numpushed++; |
|
167 |
|
168 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
169 RFile64 sourcefile; |
|
170 #else |
|
171 RFile sourcefile; |
|
172 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API |
|
173 |
|
174 User::LeaveIfError(sourcefile.Open(fs, source, EFileRead | EFileStream | EFileShareReadersOnly)); |
|
175 CleanupClosePushL(sourcefile); |
|
176 numpushed++; |
|
177 |
|
178 RFile targetfile; |
|
179 TBool targetFileOpen = EFalse; |
|
180 TInt err(KErrNone); |
|
181 TFileName fn; |
|
182 |
|
183 const TInt KMyBufSize = 10; |
|
184 TBuf8 <KMyBufSize> buffer; |
|
185 TInt length = KMyBufSize; |
|
186 while(length > 0) |
|
187 { |
|
188 User::LeaveIfError(sourcefile.Read(buffer, buffer.MaxLength())); |
|
189 length = buffer.Length(); |
|
190 err = import->WriteData(buffer); |
|
191 |
|
192 if(err != KErrNone) |
|
193 { |
|
194 if(err == KErrCANewFileHandleRequired) |
|
195 { |
|
196 TESTL(doFileCreate); |
|
197 TESTL(!targetFileOpen); |
|
198 |
|
199 import->GetSuggestedOutputFileName(fn); |
|
200 fn.Insert(0, outputPath); |
|
201 |
|
202 INFO_PRINTF3(_L("Agent suggested name is %S, target is %S."), &fn, &target); |
|
203 |
|
204 User::LeaveIfError(targetfile.Create(fs, target, EFileStream | EFileWrite | EFileShareAny)); |
|
205 CleanupClosePushL(targetfile); |
|
206 numpushed++; |
|
207 targetFileOpen = ETrue; |
|
208 User::LeaveIfError(import->ContinueWithNewOutputFile(targetfile, fn)); |
|
209 } |
|
210 else |
|
211 { |
|
212 INFO_PRINTF2(_L("Error writing data, Error code is: %d"),err); |
|
213 User::LeaveIfError(err); |
|
214 } |
|
215 } |
|
216 } |
|
217 |
|
218 if(targetFileOpen) |
|
219 { |
|
220 CleanupStack::PopAndDestroy(&targetfile); |
|
221 numpushed--; |
|
222 } |
|
223 |
|
224 // process the rights that were received alongside the content |
|
225 err = import->WriteDataComplete(); |
|
226 while(err == KErrCANewFileHandleRequired) |
|
227 { |
|
228 TEST(doFileCreate); |
|
229 |
|
230 import->GetSuggestedOutputFileName(fn); |
|
231 fn.Insert(0, outputPath); |
|
232 |
|
233 INFO_PRINTF2(_L("Creating Receipt File: %S "), &fn); |
|
234 RFile receiptFile; |
|
235 User::LeaveIfError(receiptFile.Replace(fs, fn, EFileStream | EFileWrite | EFileShareAny)); |
|
236 CleanupClosePushL(receiptFile); |
|
237 err = import->ContinueWithNewOutputFile(receiptFile, fn); |
|
238 CleanupStack::PopAndDestroy(&receiptFile); |
|
239 } |
|
240 |
|
241 User::LeaveIfError(err); |
|
242 |
|
243 TPtrC importOutFileName; |
|
244 TPtrC contentOutputName(KNullDesC); |
|
245 for (TInt i = 0; i < import->OutputFileCountL(); i++) |
|
246 { |
|
247 importOutFileName.Set( import->OutputFileL(i).FileName() ); |
|
248 |
|
249 if (import->OutputFileL(i).OutputType() == EContent) |
|
250 { |
|
251 contentOutputName.Set(importOutFileName); |
|
252 } |
|
253 else |
|
254 { |
|
255 // delete the receipt we just created |
|
256 // they only get in the way when importing files using the utility |
|
257 INFO_PRINTF2(_L("Receipt files %S deleted (not important) when using ImportDrmArchive step"), &importOutFileName); |
|
258 fs.Delete(importOutFileName); // ignore return code |
|
259 } |
|
260 } |
|
261 |
|
262 if (contentOutputName.CompareF(target) != 0) |
|
263 { |
|
264 // This must be the case that RTA automatically create |
|
265 // output file. See the line targetfile.Create(fs, target, ...). |
|
266 |
|
267 // Before DEF088475, users of RTAUtils test harness can |
|
268 // specify whatever extension for the output file. The |
|
269 // defect fix changed the importer from CRefTestAgentImport |
|
270 // (unit test) to CImportFile (end-to-end test). CImportFile |
|
271 // converts non-standard ext to .content. To maintain backward |
|
272 // compatibility, we need to rename the generated output. |
|
273 |
|
274 fs.Delete(target); // ignore return code |
|
275 TEST(fs.Rename(contentOutputName, target) == 0); |
|
276 } |
|
277 |
|
278 CleanupStack::PopAndDestroy(numpushed); |
|
279 |
|
280 __UHEAP_MARKEND; |
|
281 |
|
282 return TestStepResult(); |
|
283 } |
|
284 |