1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/contentmgmt/referencedrmagent/tcaf/source/cafstep.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,211 @@
1.4 +/*
1.5 +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +#include "cafstep.h"
1.22 +#include <test/testexecutelog.h>
1.23 +#include <caf/content.h>
1.24 +#include <caf/attribute.h>
1.25 +#include "cafserver.h"
1.26 +#include "resolver.h"
1.27 +#include "manager.h"
1.28 +#include "bitset.h"
1.29 +#include "CafApaRecognizer.h"
1.30 +
1.31 +#include <apasvst.h>
1.32 +#include <apaflrec.h>
1.33 +#include <fbs.h>
1.34 +#include <charconv.h>
1.35 +#include <eikenv.h>
1.36 +
1.37 +using namespace ContentAccess;
1.38 +
1.39 +/*
1.40 + * Base class for all CAF test steps
1.41 + *
1.42 + */
1.43 +
1.44 +CCAFStep::CCAFStep()
1.45 + {
1.46 + }
1.47 +
1.48 +CCAFStep::~CCAFStep()
1.49 + {
1.50 + }
1.51 +
1.52 +void CCAFStep:: InitialiseFileHandleParametersL()
1.53 + {
1.54 + GetStringFromConfig(ConfigSection(),_L("uri"),iUri);
1.55 + GetStringFromConfig(ConfigSection(),_L("uniqueid"),iUniqueId);
1.56 + GetIntFromConfig(ConfigSection(),_L("result"),iExpectedResult);
1.57 +
1.58 + iFs.Connect();
1.59 + CleanupClosePushL(iFs);
1.60 + User::LeaveIfError(iFs.ShareProtected());
1.61 + User::LeaveIfError(iFile.Open(iFs, iUri, EFileShareReadersOnly| EFileRead | EFileStream));
1.62 + CleanupClosePushL(iFile);
1.63 + }
1.64 +
1.65 +void CCAFStep::ReadBufferL(TDesC16& aFileName, TDes8& aBuffer)
1.66 + {
1.67 + RFs fs;
1.68 + RFile handle;
1.69 + TInt result;
1.70 + User::LeaveIfError(fs.Connect());
1.71 + CleanupClosePushL(fs);
1.72 + result = handle.Open(fs,aFileName,EFileRead | EFileStream | EFileShareAny);
1.73 + User::LeaveIfError(result);
1.74 + CleanupClosePushL(handle);
1.75 + handle.Read(aBuffer);
1.76 + CleanupStack::PopAndDestroy(2, &fs);
1.77 + }
1.78 +
1.79 +HBufC8* CCAFStep::ConvertDes16toHBufC8LC(TDesC& source)
1.80 + {
1.81 + RFs fs;
1.82 + HBufC8 *buf = HBufC8::NewL(source.Length());
1.83 + CleanupStack::PushL(buf);
1.84 + TPtr8 ptr=buf->Des();
1.85 +
1.86 + CCnvCharacterSetConverter *converter = CCnvCharacterSetConverter::NewLC();
1.87 + User::LeaveIfError(fs.Connect());
1.88 + CleanupClosePushL(fs);
1.89 + converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierAscii, fs);
1.90 + converter->ConvertFromUnicode(ptr, source);
1.91 + CleanupStack::PopAndDestroy(2, converter);
1.92 + return buf;
1.93 + }
1.94 +
1.95 +HBufC16* CCAFStep::ConvertDes8toHBufC16LC(TDesC8& source)
1.96 + {
1.97 + RFs fs;
1.98 + TInt status=0;
1.99 + HBufC16 *buf = HBufC16::NewL(source.Length());
1.100 + CleanupStack::PushL(buf);
1.101 + TPtr16 ptr=buf->Des();
1.102 + CCnvCharacterSetConverter *converter = CCnvCharacterSetConverter::NewLC();
1.103 + User::LeaveIfError(fs.Connect());
1.104 + CleanupClosePushL(fs);
1.105 + converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierAscii, fs);
1.106 + converter->ConvertToUnicode(ptr, source, status);
1.107 + CleanupStack::PopAndDestroy(2, converter);
1.108 + return buf;
1.109 + }
1.110 +
1.111 +#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.112 +
1.113 +HBufC8* CCAFStep::CreateWmdrmHeaderLC()
1.114 + {
1.115 + // create dummy header data.
1.116 + const TInt KMaxBufferLen = 64;
1.117 + _LIT8(KHeaderData, "W\0R\0M\0H\0E\0A\0D\0E\0R\0");
1.118 +
1.119 + HBufC8* headerData = HBufC8::NewMaxLC(KMaxBufferLen);
1.120 + TPtr8 headerPtr = headerData->Des();
1.121 + headerPtr.Repeat(KHeaderData);
1.122 + return headerData;
1.123 + }
1.124 +#endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
1.125 +
1.126 +
1.127 +void CCAFStep::LoadCafRecognizerL()
1.128 + {
1.129 + static const TUid KImplementationUID= {0x102031E9};
1.130 +
1.131 + TAny* ptr = REComSession::CreateImplementationL(KImplementationUID, iDtorIDKey);
1.132 + iRecognizer = static_cast <CApaDataRecognizerType*>(ptr);
1.133 + }
1.134 +
1.135 +void CCAFStep::UnLoadCafRecognizer()
1.136 + {
1.137 + delete iRecognizer;
1.138 + iRecognizer=NULL;
1.139 + REComSession::DestroyedImplementation(iDtorIDKey);
1.140 + REComSession::FinalClose();
1.141 + }
1.142 +
1.143 +TInt CCAFStep::Delete(const TDesC& aFile)
1.144 + {
1.145 + TInt err = KErrNone;
1.146 + RFs fs;
1.147 + err = fs.Connect();
1.148 + if(err == KErrNone)
1.149 + {
1.150 + err = fs.Delete(aFile);
1.151 + fs.Close();
1.152 + }
1.153 + return err;
1.154 + }
1.155 +
1.156 +
1.157 +
1.158 +TVerdict CCAFStep::doTestStepPreambleL()
1.159 + {
1.160 + iActiveScheduler = new (ELeave) CActiveScheduler;
1.161 + CActiveScheduler::Install(iActiveScheduler);
1.162 + return TestStepResult();
1.163 + }
1.164 +
1.165 +TVerdict CCAFStep::doTestStepPostambleL()
1.166 + {
1.167 + CActiveScheduler::Install(NULL);
1.168 + delete iActiveScheduler;
1.169 + return TestStepResult();
1.170 + }
1.171 +
1.172 +
1.173 +// Dummy class required to create an apparc server (below)
1.174 +class CT_Serv2DummyShell : public CBase, public MApaAppStarter
1.175 + {
1.176 + public:
1.177 + TThreadId StartAppL(const CApaCommandLine&) { return *(TThreadId*)this; }
1.178 + void ConstructL();
1.179 + public:
1.180 + RFs iFs;
1.181 + RFbsSession iFbs;
1.182 + };
1.183 +
1.184 +void CT_Serv2DummyShell::ConstructL()
1.185 + {
1.186 + User::LeaveIfError(iFs.Connect());
1.187 + User::LeaveIfError(iFbs.Connect());
1.188 + }
1.189 +
1.190 +
1.191 +void CCAFStep::StartApparcServerL()
1.192 + {
1.193 + INFO_PRINTF1(_L("Starting Apparc Server"));
1.194 + FbsStartup();
1.195 + TInt ret=RFbsSession::Connect();
1.196 + TEST(ret==KErrNone);
1.197 +
1.198 + // set up an fbs
1.199 + ret = FbsStartup();
1.200 + TEST(ret==KErrNone);
1.201 + //
1.202 + // set up an app starter
1.203 + CT_Serv2DummyShell* dummy=new(ELeave) CT_Serv2DummyShell();
1.204 + dummy->ConstructL();
1.205 +
1.206 + ret=StartupApaServerProcess();
1.207 +
1.208 +
1.209 + TEST(((ret==KErrNone)||(ret==KErrAlreadyExists)));
1.210 + //
1.211 +
1.212 +
1.213 + INFO_PRINTF1(_L("Apparc Startup Complete"));
1.214 + }