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