|
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of the License "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Implements the post-acquisition content protection test. |
|
15 // |
|
16 // |
|
17 |
|
18 #include "tpostacquisition.h" |
|
19 #include "testprotstrdesc.h" |
|
20 #include "testagentkeystreamdecoder.h" |
|
21 #include <caf/data.h> |
|
22 #include <caf/content.h> |
|
23 #include <caf/supplier.h> |
|
24 #include <caf/metadataarray.h> |
|
25 #include <caf/supplieroutputfile.h> |
|
26 #include <caf/streaming/keystreamdecoder.h> |
|
27 |
|
28 using namespace StreamAccess; |
|
29 using namespace ContentAccess; |
|
30 |
|
31 CScafPostAcquisition::CScafPostAcquisition(CScafServer& aParent) |
|
32 /** |
|
33 Constructor for the postacquisition test object. |
|
34 */ |
|
35 : CScafStep(aParent) |
|
36 { |
|
37 SetTestStepName(KScafPostAcquisitionStep); |
|
38 } |
|
39 |
|
40 CScafPostAcquisition::~CScafPostAcquisition() |
|
41 /** |
|
42 Destructor for the postacquisition test object. |
|
43 */ |
|
44 { |
|
45 //empty |
|
46 } |
|
47 |
|
48 void DeleteFileL(RFs& aFs, const TDesC& aPath) |
|
49 { |
|
50 TInt err = 0; |
|
51 err = aFs.Delete(aPath); |
|
52 if(err != KErrNone && err != KErrNotFound && err != KErrPathNotFound) |
|
53 { |
|
54 User::Leave(err); |
|
55 } |
|
56 } |
|
57 |
|
58 TVerdict CScafPostAcquisition::doTestL() |
|
59 { |
|
60 #ifdef INTERNALLY_ENABLE_UPWARD_DEPENDENCY |
|
61 TBool createOutputFile = EFalse; |
|
62 |
|
63 if(!GetBoolFromConfig(ConfigSection(), KCreateOutputFiles, createOutputFile)) |
|
64 { |
|
65 ERR_PRINTF2(_L("Failed to read '%S' key of configuration"), &KCreateOutputFiles); |
|
66 SetTestStepResult(EFail); |
|
67 return TestStepResult(); |
|
68 } |
|
69 |
|
70 //Ensure pre-conditions |
|
71 CleanAgentsPrivateFolderL(KRtaPrivateFolder()); |
|
72 CleanAgentsPrivateFolderL(KStaPrivateFolder()); |
|
73 CleanAgentsPrivateFolderL(KTestServerPrivateFolder()); |
|
74 CleanAgentsPrivateFolderL(KRtaTestFolder()); |
|
75 DeleteFileL(iParent.Fs(), _L("c:\\PostAcquisitionTest.dr")); |
|
76 DeleteFileL(iParent.Fs(), _L("c:\\PostAcquisitionTest.TXT")); |
|
77 |
|
78 //First copy the RO, which allows to record the protected content, into the test agent's private directory |
|
79 CopyFile2AgentsPrivateFolderL(iParent.Fs(), KRecordableRoFileName(), KStaPrivateFolder()); |
|
80 |
|
81 //Secondly copy the program protected RO into the test agent's private directory |
|
82 CopyFile2AgentsPrivateFolderL(iParent.Fs(), KPostAcquisitionRoFileName(), KStaPrivateFolder()); |
|
83 |
|
84 //Create an SDP document object and set the created key stream field object |
|
85 CSdpDocument* sdpDoc = CreateSdpDocumentLC(); |
|
86 //Create a SDP object for RO-Recordable |
|
87 CSdpMediaField* sdp = CreateSdpLC(0); |
|
88 AddMediaFieldL(*sdpDoc, sdp); |
|
89 CleanupStack::Pop(sdp); |
|
90 |
|
91 // Generate a protected key stream description. |
|
92 HBufC* filePath = GetFullPathLC(KStaPrivateFolder, KNullDesC); |
|
93 CTestProtectedStreamDesc* protectStreamDesc = CTestProtectedStreamDesc::NewL(*filePath); |
|
94 CleanupStack::PopAndDestroy(filePath); |
|
95 CleanupStack::PushL(protectStreamDesc); |
|
96 |
|
97 //Create a key stream decoder |
|
98 CKeyStreamDecoder* decoder = CKeyStreamDecoder::NewL(*protectStreamDesc, *sdp, *sdpDoc); |
|
99 CleanupStack::PushL(decoder); |
|
100 |
|
101 //Check whether the content is recordable |
|
102 TBool value = EFalse; |
|
103 decoder->GetAttributeL(ECanExport, value); |
|
104 if(!value) |
|
105 { |
|
106 ERR_PRINTF1(_L("The content can not be exported. Unexpected result!")); |
|
107 SetTestStepResult(EFail); |
|
108 User::Leave(KErrCANotSupported); |
|
109 } |
|
110 |
|
111 CImportFile* import(0); |
|
112 _LIT(KPostAcqContentFileName, "postacquisition.content"); |
|
113 if(!createOutputFile) |
|
114 { |
|
115 HBufC* outputDir = GetFullPathLC(KRtaPrivateFolder(), KNullDesC()); |
|
116 import = decoder->CreateImportSessionLC(_L8("text/plain"), KPostAcqContentFileName(), *outputDir); |
|
117 CleanupStack::Pop(import); |
|
118 CleanupStack::PopAndDestroy(outputDir); |
|
119 CleanupStack::PushL(import); |
|
120 } |
|
121 else |
|
122 { |
|
123 import = decoder->CreateImportSessionLC(_L8("text/plain")); |
|
124 //To get a better coverage, delete this import object and create another one with zero-length-output-directory. |
|
125 CleanupStack::PopAndDestroy(import); |
|
126 DeleteFileL(iParent.Fs(), _L("c:\\PostAcquisitionTest.dr")); |
|
127 DeleteFileL(iParent.Fs(), _L("c:\\PostAcquisitionTest.TXT")); |
|
128 import = decoder->CreateImportSessionLC(_L8("text/plain"), _L("NULL"), KNullDesC()); |
|
129 } |
|
130 |
|
131 _LIT8(KStreamingData1,"SampleStreamingDataBegan"); |
|
132 _LIT8(KStreamingData2,"TheEndOfStreamingData"); |
|
133 _LIT8(KStreamingDataFull,"SampleStreamingDataBeganTheEndOfStreamingData"); |
|
134 |
|
135 User::LeaveIfError(import->WriteData(KStreamingData1())); |
|
136 User::LeaveIfError(import->WriteData(KStreamingData2())); |
|
137 //Import has been completed |
|
138 TFileName fileName; |
|
139 TInt err = 0; |
|
140 err = import->WriteDataComplete(); |
|
141 while (err == KErrCANewFileHandleRequired) |
|
142 { |
|
143 err = ProvideNewOutputFileL(*import, fileName); |
|
144 if(err == KErrNone) |
|
145 { |
|
146 err = import->WriteDataComplete(); |
|
147 } |
|
148 } |
|
149 User::LeaveIfError(err); |
|
150 |
|
151 CleanupStack::PopAndDestroy(3, protectStreamDesc); |
|
152 CleanupStack::PopAndDestroy(); //sdpDoc |
|
153 |
|
154 //Try to read what we have imported |
|
155 CContent* content(0); |
|
156 if(!createOutputFile) |
|
157 { |
|
158 HBufC* filePath = GetFullPathLC(KRtaPrivateFolder(), KPostAcqContentFileName()); |
|
159 content = CContent::NewL(*filePath); |
|
160 CleanupStack::PopAndDestroy(filePath); |
|
161 CleanupStack::PushL(content); |
|
162 } |
|
163 else |
|
164 { |
|
165 content = CContent::NewLC(fileName); |
|
166 } |
|
167 CData* mydata = content->OpenContentL(EView); |
|
168 CleanupStack::PushL(mydata); |
|
169 |
|
170 RBuf8 rdata; |
|
171 rdata.CreateL(KStreamingDataFull().Length()); |
|
172 rdata.CleanupClosePushL(); |
|
173 User::LeaveIfError(mydata->Read(rdata)); |
|
174 if(rdata.Compare(KStreamingDataFull())) |
|
175 { |
|
176 SetTestStepResult(EFail); |
|
177 } |
|
178 CleanupStack::PopAndDestroy(3, content); |
|
179 #endif |
|
180 return TestStepResult(); |
|
181 } |
|
182 |
|
183 TInt CScafPostAcquisition::ProvideNewOutputFileL(CImportFile& aImport, TDes& aName) |
|
184 { |
|
185 TInt err = 0; |
|
186 // supply new file in order to continue writing |
|
187 aImport.GetSuggestedOutputFileName(aName); |
|
188 HBufC* newFullName = GetFullPathLC(KRtaTestFolder(), aName); |
|
189 RFile newFile; |
|
190 User::LeaveIfError(newFile.Replace(iParent.Fs(), *newFullName, EFileWrite)); |
|
191 err = aImport.ContinueWithNewOutputFile(newFile, *newFullName); |
|
192 newFile.Close(); |
|
193 aName.Copy(*newFullName); |
|
194 CleanupStack::PopAndDestroy(newFullName); |
|
195 return err; |
|
196 } |