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