os/security/contentmgmt/referencedrmagent/tcaf/source/cafstep.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2003-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 #include "cafstep.h"
    19 #include <test/testexecutelog.h>
    20 #include <caf/content.h>
    21 #include <caf/attribute.h>
    22 #include "cafserver.h"
    23 #include "resolver.h"
    24 #include "manager.h"
    25 #include "bitset.h"
    26 #include "CafApaRecognizer.h"
    27 
    28 #include <apasvst.h>
    29 #include <apaflrec.h>
    30 #include <fbs.h>
    31 #include <charconv.h>
    32 #include <eikenv.h>
    33 
    34 using namespace ContentAccess;
    35 
    36 /* 
    37  * Base class for all CAF test steps
    38  *
    39  */
    40 
    41 CCAFStep::CCAFStep()
    42 	{
    43 	}
    44 
    45 CCAFStep::~CCAFStep()
    46 	{
    47 	}
    48 	
    49 void CCAFStep:: InitialiseFileHandleParametersL()	
    50 	{
    51 	GetStringFromConfig(ConfigSection(),_L("uri"),iUri);
    52 	GetStringFromConfig(ConfigSection(),_L("uniqueid"),iUniqueId);
    53 	GetIntFromConfig(ConfigSection(),_L("result"),iExpectedResult);
    54 
    55 	iFs.Connect();
    56 	CleanupClosePushL(iFs);
    57 	User::LeaveIfError(iFs.ShareProtected());
    58 	User::LeaveIfError(iFile.Open(iFs, iUri, EFileShareReadersOnly| EFileRead | EFileStream));
    59 	CleanupClosePushL(iFile);
    60 	}
    61 	
    62 void CCAFStep::ReadBufferL(TDesC16& aFileName, TDes8& aBuffer)
    63 	{
    64 	RFs fs;
    65 	RFile handle;
    66 	TInt result;
    67 	User::LeaveIfError(fs.Connect());
    68 	CleanupClosePushL(fs);
    69 	result = handle.Open(fs,aFileName,EFileRead | EFileStream | EFileShareAny);
    70 	User::LeaveIfError(result);
    71 	CleanupClosePushL(handle);
    72 	handle.Read(aBuffer);
    73 	CleanupStack::PopAndDestroy(2, &fs);
    74 	}
    75 
    76 HBufC8* CCAFStep::ConvertDes16toHBufC8LC(TDesC& source)
    77 	{
    78 	RFs fs;
    79 	HBufC8 *buf = HBufC8::NewL(source.Length());
    80 	CleanupStack::PushL(buf);
    81 	TPtr8 ptr=buf->Des();
    82 
    83 	CCnvCharacterSetConverter *converter = CCnvCharacterSetConverter::NewLC();
    84 	User::LeaveIfError(fs.Connect());
    85 	CleanupClosePushL(fs);
    86 	converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierAscii, fs);
    87 	converter->ConvertFromUnicode(ptr, source);
    88 	CleanupStack::PopAndDestroy(2, converter);
    89 	return buf;
    90 	}
    91 
    92 HBufC16* CCAFStep::ConvertDes8toHBufC16LC(TDesC8& source)
    93 	{
    94 	RFs fs;
    95 	TInt status=0;
    96 	HBufC16 *buf = HBufC16::NewL(source.Length());
    97 	CleanupStack::PushL(buf);
    98 	TPtr16 ptr=buf->Des();
    99 	CCnvCharacterSetConverter *converter = CCnvCharacterSetConverter::NewLC();
   100 	User::LeaveIfError(fs.Connect());
   101 	CleanupClosePushL(fs);
   102 	converter->PrepareToConvertToOrFromL(KCharacterSetIdentifierAscii, fs);
   103 	converter->ConvertToUnicode(ptr, source, status);
   104 	CleanupStack::PopAndDestroy(2, converter);
   105 	return buf;
   106 	}
   107 
   108 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   109          
   110 HBufC8* CCAFStep::CreateWmdrmHeaderLC()     
   111     {     
   112     // create dummy header data.     
   113     const TInt KMaxBufferLen = 64;     
   114     _LIT8(KHeaderData, "W\0R\0M\0H\0E\0A\0D\0E\0R\0");     
   115          
   116     HBufC8* headerData = HBufC8::NewMaxLC(KMaxBufferLen);     
   117     TPtr8 headerPtr = headerData->Des();     
   118     headerPtr.Repeat(KHeaderData);     
   119     return headerData;     
   120     }     
   121 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT     
   122   
   123 
   124 void CCAFStep::LoadCafRecognizerL()
   125 	{
   126 	static const TUid KImplementationUID= {0x102031E9};
   127 
   128 	TAny* ptr = REComSession::CreateImplementationL(KImplementationUID, iDtorIDKey);
   129 	iRecognizer = static_cast <CApaDataRecognizerType*>(ptr);
   130     }
   131 
   132 void CCAFStep::UnLoadCafRecognizer()
   133 	{
   134 	delete iRecognizer;
   135 	iRecognizer=NULL;
   136 	REComSession::DestroyedImplementation(iDtorIDKey);
   137 	REComSession::FinalClose();
   138 	}
   139 
   140 TInt CCAFStep::Delete(const TDesC& aFile)
   141 	{
   142 	TInt err = KErrNone;
   143 	RFs fs;
   144 	err = fs.Connect();
   145 	if(err == KErrNone)
   146 		{
   147 		err = fs.Delete(aFile);
   148 		fs.Close();
   149 		}
   150 	return err;
   151 	}
   152 
   153 
   154 
   155 TVerdict CCAFStep::doTestStepPreambleL()
   156 	{
   157 	iActiveScheduler = new (ELeave) CActiveScheduler;
   158 	CActiveScheduler::Install(iActiveScheduler);
   159 	return TestStepResult();
   160 	}
   161 
   162 TVerdict CCAFStep::doTestStepPostambleL()
   163 	{
   164 	CActiveScheduler::Install(NULL);
   165 	delete iActiveScheduler;
   166 	return TestStepResult();
   167 	}
   168 
   169 
   170 // Dummy class required to create an apparc server (below)
   171 class CT_Serv2DummyShell : public CBase, public MApaAppStarter
   172      {
   173  public:
   174      TThreadId StartAppL(const CApaCommandLine&) { return *(TThreadId*)this; }
   175      void ConstructL();
   176  public:
   177      RFs iFs;
   178      RFbsSession iFbs;
   179      };
   180 
   181 void CT_Serv2DummyShell::ConstructL()
   182      {
   183      User::LeaveIfError(iFs.Connect());
   184      User::LeaveIfError(iFbs.Connect());
   185      }
   186 
   187 
   188 void CCAFStep::StartApparcServerL()
   189 	{
   190 	INFO_PRINTF1(_L("Starting Apparc Server"));
   191     FbsStartup();
   192     TInt ret=RFbsSession::Connect();
   193          TEST(ret==KErrNone);
   194  
   195      // set up an fbs
   196      ret = FbsStartup();
   197          TEST(ret==KErrNone);
   198      //
   199      // set up an app starter
   200      CT_Serv2DummyShell* dummy=new(ELeave) CT_Serv2DummyShell();
   201      dummy->ConstructL();
   202  
   203  	 ret=StartupApaServerProcess();
   204 
   205 
   206      TEST(((ret==KErrNone)||(ret==KErrAlreadyExists)));
   207      //
   208  
   209  
   210      INFO_PRINTF1(_L("Apparc Startup Complete"));
   211 	}