os/security/contentmgmt/cafstreamingsupport/test/tscaf/source/tpostacquisition.cpp
Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // Implements the post-acquisition content protection test.
18 #include "tpostacquisition.h"
19 #include "testprotstrdesc.h"
20 #include "testagentkeystreamdecoder.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>
28 using namespace StreamAccess;
29 using namespace ContentAccess;
31 CScafPostAcquisition::CScafPostAcquisition(CScafServer& aParent)
33 Constructor for the postacquisition test object.
37 SetTestStepName(KScafPostAcquisitionStep);
40 CScafPostAcquisition::~CScafPostAcquisition()
42 Destructor for the postacquisition test object.
48 void DeleteFileL(RFs& aFs, const TDesC& aPath)
51 err = aFs.Delete(aPath);
52 if(err != KErrNone && err != KErrNotFound && err != KErrPathNotFound)
58 TVerdict CScafPostAcquisition::doTestL()
60 TBool createOutputFile = EFalse;
62 if(!GetBoolFromConfig(ConfigSection(), KCreateOutputFiles, createOutputFile))
64 ERR_PRINTF2(_L("Failed to read '%S' key of configuration"), &KCreateOutputFiles);
65 SetTestStepResult(EFail);
66 return TestStepResult();
69 //Ensure pre-conditions
70 CleanAgentsPrivateFolderL(KRtaPrivateFolder());
71 CleanAgentsPrivateFolderL(KStaPrivateFolder());
72 CleanAgentsPrivateFolderL(KTestServerPrivateFolder());
73 CleanAgentsPrivateFolderL(KRtaTestFolder());
74 DeleteFileL(iParent.Fs(), _L("c:\\PostAcquisitionTest.dr"));
75 DeleteFileL(iParent.Fs(), _L("c:\\PostAcquisitionTest.TXT"));
77 //First copy the RO, which allows to record the protected content, into the test agent's private directory
78 CopyFile2AgentsPrivateFolderL(iParent.Fs(), KRecordableRoFileName(), KStaPrivateFolder());
80 //Secondly copy the program protected RO into the test agent's private directory
81 CopyFile2AgentsPrivateFolderL(iParent.Fs(), KPostAcquisitionRoFileName(), KStaPrivateFolder());
83 //Create an SDP document object and set the created key stream field object
84 CSdpDocument* sdpDoc = CreateSdpDocumentLC();
85 //Create a SDP object for RO-Recordable
86 CSdpMediaField* sdp = CreateSdpLC(0);
87 AddMediaFieldL(*sdpDoc, sdp);
88 CleanupStack::Pop(sdp);
90 // Generate a protected key stream description.
91 HBufC* filePath = GetFullPathLC(KStaPrivateFolder, KNullDesC);
92 CTestProtectedStreamDesc* protectStreamDesc = CTestProtectedStreamDesc::NewL(*filePath);
93 CleanupStack::PopAndDestroy(filePath);
94 CleanupStack::PushL(protectStreamDesc);
96 //Create a key stream decoder
97 CKeyStreamDecoder* decoder = CKeyStreamDecoder::NewL(*protectStreamDesc, *sdp, *sdpDoc);
98 CleanupStack::PushL(decoder);
100 //Check whether the content is recordable
101 TBool value = EFalse;
102 decoder->GetAttributeL(ECanExport, value);
105 ERR_PRINTF1(_L("The content can not be exported. Unexpected result!"));
106 SetTestStepResult(EFail);
107 User::Leave(KErrCANotSupported);
110 CImportFile* import(0);
111 _LIT(KPostAcqContentFileName, "postacquisition.content");
112 if(!createOutputFile)
114 HBufC* outputDir = GetFullPathLC(KRtaPrivateFolder(), KNullDesC());
115 import = decoder->CreateImportSessionLC(_L8("text/plain"), KPostAcqContentFileName(), *outputDir);
116 CleanupStack::Pop(import);
117 CleanupStack::PopAndDestroy(outputDir);
118 CleanupStack::PushL(import);
122 import = decoder->CreateImportSessionLC(_L8("text/plain"));
123 //To get a better coverage, delete this import object and create another one with zero-length-output-directory.
124 CleanupStack::PopAndDestroy(import);
125 DeleteFileL(iParent.Fs(), _L("c:\\PostAcquisitionTest.dr"));
126 DeleteFileL(iParent.Fs(), _L("c:\\PostAcquisitionTest.TXT"));
127 import = decoder->CreateImportSessionLC(_L8("text/plain"), _L("NULL"), KNullDesC());
130 _LIT8(KStreamingData1,"SampleStreamingDataBegan");
131 _LIT8(KStreamingData2,"TheEndOfStreamingData");
132 _LIT8(KStreamingDataFull,"SampleStreamingDataBeganTheEndOfStreamingData");
134 User::LeaveIfError(import->WriteData(KStreamingData1()));
135 User::LeaveIfError(import->WriteData(KStreamingData2()));
136 //Import has been completed
139 err = import->WriteDataComplete();
140 while (err == KErrCANewFileHandleRequired)
142 err = ProvideNewOutputFileL(*import, fileName);
145 err = import->WriteDataComplete();
148 User::LeaveIfError(err);
150 CleanupStack::PopAndDestroy(3, protectStreamDesc);
151 CleanupStack::PopAndDestroy(); //sdpDoc
153 //Try to read what we have imported
154 CContent* content(0);
155 if(!createOutputFile)
157 HBufC* filePath = GetFullPathLC(KRtaPrivateFolder(), KPostAcqContentFileName());
158 content = CContent::NewL(*filePath);
159 CleanupStack::PopAndDestroy(filePath);
160 CleanupStack::PushL(content);
164 content = CContent::NewLC(fileName);
166 CData* mydata = content->OpenContentL(EView);
167 CleanupStack::PushL(mydata);
170 rdata.CreateL(KStreamingDataFull().Length());
171 rdata.CleanupClosePushL();
172 User::LeaveIfError(mydata->Read(rdata));
173 if(rdata.Compare(KStreamingDataFull()))
175 SetTestStepResult(EFail);
177 CleanupStack::PopAndDestroy(3, content);
178 return TestStepResult();
181 TInt CScafPostAcquisition::ProvideNewOutputFileL(CImportFile& aImport, TDes& aName)
184 // supply new file in order to continue writing
185 aImport.GetSuggestedOutputFileName(aName);
186 HBufC* newFullName = GetFullPathLC(KRtaTestFolder(), aName);
188 User::LeaveIfError(newFile.Replace(iParent.Fs(), *newFullName, EFileWrite));
189 err = aImport.ContinueWithNewOutputFile(newFile, *newFullName);
191 aName.Copy(*newFullName);
192 CleanupStack::PopAndDestroy(newFullName);