sl@0: /* sl@0: * Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "cafserver.h" sl@0: #include "bitset.h" sl@0: #include "Consumerstep.h" sl@0: #include "attributeset.h" sl@0: #include "stringattributeset.h" sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: using namespace ContentAccess; sl@0: sl@0: const TInt KCafTestMaxDataTypeLength = 255; sl@0: const TInt KCafTestSecToMS = 1000; sl@0: sl@0: _LIT(KCDataThreadSemaphore, "CData_Thread_Test"); sl@0: sl@0: /* sl@0: * Step1 compares an agent 'size' call with that obtained by RFile sl@0: * sl@0: */ sl@0: sl@0: CCAFSizeStep::~CCAFSizeStep() sl@0: { sl@0: } sl@0: sl@0: CCAFSizeStep::CCAFSizeStep(CCAFServer& aParent) sl@0: : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFSizeStep); sl@0: } sl@0: sl@0: TVerdict CCAFSizeStep::doTestStepL() sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: SetTestStepResult(EInconclusive); sl@0: sl@0: INFO_PRINTF1(_L("Basic Open Content Test")); sl@0: sl@0: TPtrC uri1; sl@0: TPtrC uri2; sl@0: GetStringFromConfig(ConfigSection(),_L("URI1"),uri1); sl@0: GetStringFromConfig(ConfigSection(),_L("URI2"),uri2); sl@0: sl@0: INFO_PRINTF2(_L("Creating CContent object with uri: %S"), &uri1); sl@0: CContent* content = CContent::NewLC(uri1); sl@0: INFO_PRINTF1(_L("Creating CData object from content")); sl@0: sl@0: CData* data = content->OpenContentL(EPeek); sl@0: CleanupStack::PushL(data); sl@0: sl@0: TInt size = 0; sl@0: data->DataSizeL(size); sl@0: INFO_PRINTF2(_L("Size of content from caf CContent::OpenContentL(): %d"),size); sl@0: CleanupStack::PopAndDestroy(data); sl@0: CleanupStack::PopAndDestroy(content); sl@0: sl@0: INFO_PRINTF2(_L("Creating CData object with uri: %S"), &uri1); sl@0: TInt size1 = 0; sl@0: sl@0: TBool withoutIntent; sl@0: if (!GetBoolFromConfig(ConfigSection(),_L("WITHOUTINTENT"),withoutIntent)) sl@0: { sl@0: INFO_PRINTF1(_L("With Intent")); sl@0: data = CData::NewL(TVirtualPathPtr(uri1), EPeek, EContentShareReadOnly); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Without Intent")); sl@0: data = CData::NewL(TVirtualPathPtr(uri1), EContentShareReadOnly); sl@0: data->SetProperty(EAgentPropertyAgentUI, 0); sl@0: User::LeaveIfError(data->EvaluateIntent(EPeek)); sl@0: } sl@0: sl@0: CleanupStack::PushL(data); sl@0: data->DataSizeL(size1); sl@0: INFO_PRINTF2(_L("Size of content from caf CData::NewL(): %d"),size1); sl@0: CleanupStack::PopAndDestroy(data); sl@0: sl@0: INFO_PRINTF2(_L("Opening standard RFile interface with uri: %S"),&uri2); sl@0: RFile file; sl@0: User::LeaveIfError(file.Open(iParent.Fs(), uri2, EFileRead)); sl@0: sl@0: TInt size2; sl@0: file.Size(size2); sl@0: file.Close(); sl@0: sl@0: INFO_PRINTF2(_L("Size of content from f32: %d"),size2); sl@0: sl@0: if(size == size2 && size == size1) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: else sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: /* sl@0: * This is the 64bit version of CCAFSizeStep sl@0: */ sl@0: sl@0: CCAFSizeStep64::~CCAFSizeStep64() sl@0: { sl@0: } sl@0: sl@0: CCAFSizeStep64::CCAFSizeStep64(CCAFServer& aParent) sl@0: : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFSizeStep); sl@0: } sl@0: sl@0: TVerdict CCAFSizeStep64::doTestStepL() sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: SetTestStepResult(EInconclusive); sl@0: sl@0: INFO_PRINTF1(_L("Basic Open Content Test")); sl@0: sl@0: TPtrC uri1; sl@0: TPtrC uri2; sl@0: GetStringFromConfig(ConfigSection(),_L("URI1"),uri1); sl@0: GetStringFromConfig(ConfigSection(),_L("URI2"),uri2); sl@0: sl@0: INFO_PRINTF2(_L("Creating CContent object with uri: %S"), &uri1); sl@0: CContent* content = CContent::NewLC(uri1); sl@0: INFO_PRINTF1(_L("Creating CData object from content")); sl@0: sl@0: CData* data = content->OpenContentL(EPeek); sl@0: CleanupStack::PushL(data); sl@0: sl@0: TInt64 size = 0; sl@0: data->DataSize64L(size); sl@0: INFO_PRINTF2(_L("Size of content from caf CContent::OpenContentL(): %Ld"),size); sl@0: CleanupStack::PopAndDestroy(data); sl@0: CleanupStack::PopAndDestroy(content); sl@0: sl@0: INFO_PRINTF2(_L("Creating CData object with uri: %S"), &uri1); sl@0: TInt64 size1 = 0; sl@0: sl@0: TBool withoutIntent; sl@0: if (!GetBoolFromConfig(ConfigSection(),_L("WITHOUTINTENT"),withoutIntent)) sl@0: { sl@0: INFO_PRINTF1(_L("With Intent")); sl@0: data = CData::NewL(TVirtualPathPtr(uri1), EPeek, EContentShareReadOnly); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("Without Intent")); sl@0: data = CData::NewL(TVirtualPathPtr(uri1), EContentShareReadOnly); sl@0: data->SetProperty(EAgentPropertyAgentUI, 0); sl@0: User::LeaveIfError(data->EvaluateIntent(EPeek)); sl@0: } sl@0: sl@0: CleanupStack::PushL(data); sl@0: data->DataSize64L(size1); sl@0: INFO_PRINTF2(_L("Size of content from caf CData::NewL(): %Ld"),size1); sl@0: CleanupStack::PopAndDestroy(data); sl@0: sl@0: INFO_PRINTF2(_L("Opening standard RFile interface with uri: %S"),&uri2); sl@0: RFile64 file; sl@0: User::LeaveIfError(file.Open(iParent.Fs(), uri2, EFileRead)); sl@0: sl@0: TInt64 size2; sl@0: file.Size(size2); sl@0: file.Close(); sl@0: sl@0: INFO_PRINTF2(_L("Size of content from f32: %Ld"),size2); sl@0: sl@0: if(size == size2 && size == size1) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: else sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: sl@0: /* sl@0: * This step compares a seek and read using CAF with that using RFile sl@0: * sl@0: */ sl@0: sl@0: CCAFSeekReadStep::~CCAFSeekReadStep() sl@0: { sl@0: } sl@0: sl@0: CCAFSeekReadStep::CCAFSeekReadStep(CCAFServer& aParent) sl@0: : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFSeekReadStep); sl@0: } sl@0: sl@0: void CCAFSeekReadStep::StandardCheckReturnValue(TInt aReturnValue) sl@0: { sl@0: if (aReturnValue != KErrNone) sl@0: { sl@0: INFO_PRINTF2(_L("ERROR Unexpected return value: %d"),aReturnValue); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: TVerdict CCAFSeekReadStep::doTestStepL() sl@0: { sl@0: SetTestStepResult(EInconclusive); sl@0: sl@0: TBuf8<2> buf1; sl@0: TBuf8<2> buf2; sl@0: TRequestStatus status; sl@0: sl@0: __UHEAP_MARK; sl@0: INFO_PRINTF1(_L("Basic Open Content Test")); sl@0: sl@0: TPtrC uri1; sl@0: TPtrC uri2; sl@0: GetStringFromConfig(ConfigSection(),_L("URI1"),uri1); sl@0: GetStringFromConfig(ConfigSection(),_L("URI2"),uri2); sl@0: sl@0: INFO_PRINTF2(_L("Creating content object with uri: %S"), &uri1); sl@0: CContent* content = CContent::NewLC(uri1); sl@0: sl@0: INFO_PRINTF1(_L("Creating data object from content")); sl@0: CData* data = content->OpenContentL(EPeek); sl@0: sl@0: // don't need CContent any more sl@0: CleanupStack::PopAndDestroy(content); sl@0: CleanupStack::PushL(data); sl@0: sl@0: // Now, open the same file using RFile sl@0: RFile file; sl@0: INFO_PRINTF2(_L("Opening standard RFile interface with uri: %S"),&uri2); sl@0: User::LeaveIfError(file.Open(iParent.Fs(), uri2, EFileRead | EFileShareReadersOnly)); sl@0: CleanupClosePushL(file); sl@0: sl@0: TInt size = 0; sl@0: file.Size(size); sl@0: INFO_PRINTF2(_L("Size of content from f32: %d"),size); sl@0: sl@0: // Seek and read from start using both CAF and RFile sl@0: TInt pos1 = size/4; sl@0: data->Seek(ESeekStart, pos1); sl@0: TInt pos2 = size/4; sl@0: file.Seek(ESeekStart, pos2); sl@0: data->Read(buf1); sl@0: file.Read(buf2); sl@0: INFO_PRINTF2(_L("Position from ESeekStart test using CData: %d"), pos1); sl@0: INFO_PRINTF2(_L("Position from ESeekStart test using RFile: %d"), pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || pos1 != size/4) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // set the location within the file then retrieve the current location within the file sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek(ESeekCurrent, pos1); sl@0: file.Seek(ESeekCurrent, pos2); sl@0: sl@0: INFO_PRINTF2(_L("Current position using CData: %d"), pos1); sl@0: INFO_PRINTF2(_L("Current position using RFile: %d"), pos2); sl@0: sl@0: if(pos1 != pos2 || pos1 != (size/4 + buf1.Length())) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Seek and read from current using both CAF and RFile sl@0: pos1 = size/4; sl@0: data->Seek(ESeekCurrent, pos1); sl@0: pos2 = size/4; sl@0: file.Seek(ESeekCurrent, pos2); sl@0: data->Read(buf1); sl@0: file.Read(buf2); sl@0: INFO_PRINTF2(_L("Position from ESeekCurrent test using CData: %d"), pos1); sl@0: INFO_PRINTF2(_L("Position from ESeekCurrent test using RFile: %d"), pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || pos1 != (size/2 + buf1.Length())) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Seek and read from end using both CAF and RFile sl@0: pos1 = -size/4; sl@0: data->Seek(ESeekEnd, pos1); sl@0: pos2 = -size/4; sl@0: file.Seek(ESeekEnd, pos2); sl@0: data->Read(buf1); sl@0: file.Read(buf2); sl@0: INFO_PRINTF2(_L("Position from ESeekEnd test using CData: %d"), pos1); sl@0: INFO_PRINTF2(_L("Position from ESeekEnd test using RFile: %d"), pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || pos1 != (size - size/4)) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Test other overloaded forms of CData::Read sl@0: sl@0: // Read only 1 byte using both CAF and RFile sl@0: pos1 = size/4; sl@0: data->Seek(ESeekStart, pos1); sl@0: pos2 = size/4; sl@0: file.Seek(ESeekStart, pos2); sl@0: data->Read(buf1,1); sl@0: file.Read(buf2,1); sl@0: INFO_PRINTF2(_L("Data Length from CData::Read(TDesC& ,TInt Length) : %d"), buf1.Length()); sl@0: INFO_PRINTF2(_L("Data Length from RFile::Read(TDesC& , TInt Length): %d"), buf2.Length()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek(ESeekCurrent, pos1); sl@0: file.Seek(ESeekCurrent,pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Read asynchronously using both CAF and RFile sl@0: INFO_PRINTF1(_L("Asynchronous read from CAF and RFile")); sl@0: pos1 = size/4; sl@0: data->Seek(ESeekStart, pos1); sl@0: pos2 = size/4; sl@0: file.Seek(ESeekStart, pos2); sl@0: status = KRequestPending; sl@0: data->Read(buf1,status); sl@0: User::WaitForRequest(status); sl@0: status = KRequestPending; sl@0: file.Read(buf2,status); sl@0: User::WaitForRequest(status); sl@0: INFO_PRINTF2(_L("Data length from CData::Read(TDesC& ,TRequestStatus& aStatus): %d"), buf1.Length()); sl@0: INFO_PRINTF2(_L("Data length from RFile::Read(TDesC& , TRequestStatus& aStatus): %d"), buf2.Length()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek(ESeekCurrent, pos1); sl@0: file.Seek(ESeekCurrent,pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Read only 1 byte asynchronously using both CAF and RFile sl@0: INFO_PRINTF1(_L("Asynchronous read of 1 byte from CAF and RFile")); sl@0: pos1 = size/4; sl@0: data->Seek(ESeekStart, pos1); sl@0: pos2 = size/4; sl@0: file.Seek(ESeekStart, pos2); sl@0: status = KRequestPending; sl@0: data->Read(buf1,1,status); sl@0: User::WaitForRequest(status); sl@0: status = KRequestPending; sl@0: file.Read(buf2,1, status); sl@0: User::WaitForRequest(status); sl@0: INFO_PRINTF2(_L("Data Length from CData::Read(TDesC& ,TInt Length, TRequestStatus aStatus) : %d"), buf1.Length()); sl@0: INFO_PRINTF2(_L("Data Length from RFile::Read(TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf2.Length()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek(ESeekCurrent, pos1); sl@0: file.Seek(ESeekCurrent,pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // read past EOF sl@0: pos1 = size+1; sl@0: pos2 = size+1; sl@0: data->Seek(ESeekStart, pos1); sl@0: file.Seek(ESeekStart, pos2); sl@0: data->Read(buf1); sl@0: file.Read(buf2); sl@0: sl@0: if(buf1.Length() != 0 || buf1.Length() != 0) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR data read past EOF")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: sl@0: // Read asynchronously supplying an offset using both CAF and RFile sl@0: TInt err; sl@0: INFO_PRINTF1(_L("Asynchronous read of 1 byte from CAF and RFile supplying an offset within the file")); sl@0: pos1 = size/4; sl@0: pos2 = size/4; sl@0: status = KRequestPending; sl@0: err = data->Read(pos1,buf1,1,status); sl@0: sl@0: StandardCheckReturnValue(err); sl@0: sl@0: User::WaitForRequest(status); sl@0: status = KRequestPending; sl@0: file.Read(pos2, buf2,1, status); sl@0: User::WaitForRequest(status); sl@0: INFO_PRINTF2(_L("Data Length from CData::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf1.Length()); sl@0: INFO_PRINTF2(_L("Data Length from RFile::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf2.Length()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek(ESeekCurrent, pos1); sl@0: file.Seek(ESeekCurrent,pos2); sl@0: if (buf1 !=buf2 || pos1 != pos2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Check asynchronous cancellation sl@0: err = 0; sl@0: INFO_PRINTF1(_L("Asynchronous read cancellation using both CAF and RFile with an offset within the file")); sl@0: pos1 = size/4; sl@0: pos2 = size/4; sl@0: status = KRequestPending; sl@0: err = data->Read(pos1,buf1,1,status); sl@0: StandardCheckReturnValue(err); sl@0: data->ReadCancel(status); sl@0: User::WaitForRequest(status); sl@0: TRequestStatus status2(KRequestPending); sl@0: file.Read(pos2, buf2,1, status2); sl@0: file.ReadCancel(); sl@0: User::WaitForRequest(status2); sl@0: INFO_PRINTF3(_L("Data Length from CData::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d, status is %d"), buf1.Length(), status.Int()); sl@0: INFO_PRINTF3(_L("Data Length from RFile::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d, status is %d"), buf2.Length(), status2.Int()); sl@0: if (status.Int() != status2.Int() || buf1 !=buf2 || pos1 != pos2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR status, buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // read past EOF sl@0: pos1 = size+1; sl@0: pos2 = size+1; sl@0: status = KRequestPending; sl@0: data->Read(pos1,buf1,1,status); sl@0: StandardCheckReturnValue(err); sl@0: User::WaitForRequest(status); sl@0: status = KRequestPending; sl@0: file.Read(pos2,buf2,1,status); sl@0: User::WaitForRequest(status); sl@0: sl@0: if(buf1.Length() != 0 || buf1.Length() != 0) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR data read past EOF")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // read over the length of the buffer sl@0: INFO_PRINTF1(_L("Asynchronous read of 5 bytes from CAF and RFile supplying an offset within the file")); sl@0: pos1 = size/4; sl@0: pos2 = size/4; sl@0: status = KRequestPending; sl@0: err = data->Read(pos1,buf1,5,status); sl@0: StandardCheckReturnValue(err); sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrOverflow) sl@0: { sl@0: INFO_PRINTF2(_L("ERROR Unexpected status returned: %d"),status.Int()); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: status = KRequestPending; sl@0: file.Read(pos2, buf2,5, status); sl@0: User::WaitForRequest(status); sl@0: INFO_PRINTF2(_L("Data Length from CData::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf1.Length()); sl@0: INFO_PRINTF2(_L("Data Length from RFile::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf2.Length()); sl@0: sl@0: if (buf1 !=buf2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: // read negative position this should return KErrArgument, dont supply -ve pos to RFile as will panic test sl@0: INFO_PRINTF1(_L("Asynchronous read from CAF supplying a negative offset within the file")); sl@0: pos1 = -1; sl@0: status = KRequestPending; sl@0: err = data->Read(pos1,buf1,5,status); sl@0: if(err!=KErrArgument) sl@0: { sl@0: INFO_PRINTF2(_L("ERROR Unexpected return value: %d"),err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Read asynchronously supplying an offset of 0 and a length greater than size of file using both CAF and RFile sl@0: INFO_PRINTF1(_L("Asynchronous read of length greater than size of file from CAF and RFile supplying an offset of 0 within the file")); sl@0: TBuf8<256> buf3; sl@0: TBuf8<256> buf4; sl@0: pos1 = 0; sl@0: pos2 = 0; sl@0: status = KRequestPending; sl@0: err = data->Read(pos1,buf3,size+1,status); sl@0: StandardCheckReturnValue(err); sl@0: User::WaitForRequest(status); sl@0: status = KRequestPending; sl@0: file.Read(pos2, buf4,size+1, status); sl@0: User::WaitForRequest(status); sl@0: INFO_PRINTF2(_L("Data Length from CData::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf3.Size()); sl@0: INFO_PRINTF2(_L("Data Length from RFile::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf4.Size()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek(ESeekCurrent, pos1); sl@0: file.Seek(ESeekCurrent,pos2); sl@0: if (buf3 != buf4 || pos1 != pos2 || buf3.Length() != buf4.Length() || pos1 != size || sl@0: pos2 != size || buf3.Size() != pos1 || buf4.Size() != pos2) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Read asynchronously supplying an offset of size/4 and a length greater than size of file using both CAF and RFile sl@0: INFO_PRINTF1(_L("Asynchronous read of length greater than size of file from CAF and RFile supplying an offset within the file")); sl@0: pos1 = size/4; sl@0: pos2 = size/4; sl@0: status = KRequestPending; sl@0: err = data->Read(pos1,buf3,size+1,status); sl@0: StandardCheckReturnValue(err); sl@0: User::WaitForRequest(status); sl@0: status = KRequestPending; sl@0: file.Read(pos2, buf4,size+1, status); sl@0: User::WaitForRequest(status); sl@0: INFO_PRINTF2(_L("Data Length from CData::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf3.Size()); sl@0: INFO_PRINTF2(_L("Data Length from RFile::Read(TInt aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf4.Size()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek(ESeekCurrent, pos1); sl@0: file.Seek(ESeekCurrent,pos2); sl@0: if (buf3 != buf4 || pos1 != pos2 || buf3.Size() != buf4.Size() || pos1 != size || pos2 != size) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2, data); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: if (TestStepResult() != EFail) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: /* sl@0: * This is the 64bit version of CCAFSeekReadStep. sl@0: */ sl@0: sl@0: CCAFSeekReadStep64::~CCAFSeekReadStep64() sl@0: { sl@0: } sl@0: sl@0: CCAFSeekReadStep64::CCAFSeekReadStep64(CCAFServer& aParent) sl@0: : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFSeekReadStep); sl@0: } sl@0: sl@0: void CCAFSeekReadStep64::StandardCheckReturnValue(TInt aReturnValue) sl@0: { sl@0: if (aReturnValue != KErrNone) sl@0: { sl@0: INFO_PRINTF2(_L("ERROR Unexpected return value: %d"),aReturnValue); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: TVerdict CCAFSeekReadStep64::doTestStepL() sl@0: { sl@0: SetTestStepResult(EInconclusive); sl@0: sl@0: TBuf8<2> buf1; sl@0: TBuf8<2> buf2; sl@0: TRequestStatus status; sl@0: sl@0: __UHEAP_MARK; sl@0: INFO_PRINTF1(_L("Basic Open Content Test")); sl@0: sl@0: TPtrC uri1; sl@0: TPtrC uri2; sl@0: GetStringFromConfig(ConfigSection(),_L("URI1"),uri1); sl@0: GetStringFromConfig(ConfigSection(),_L("URI2"),uri2); sl@0: sl@0: INFO_PRINTF2(_L("Creating content object with uri: %S"), &uri1); sl@0: CContent* content = CContent::NewLC(uri1); sl@0: sl@0: INFO_PRINTF1(_L("Creating data object from content")); sl@0: CData* data = content->OpenContentL(EPeek); sl@0: sl@0: // don't need CContent any more sl@0: CleanupStack::PopAndDestroy(content); sl@0: CleanupStack::PushL(data); sl@0: sl@0: // Now, open the same file using RFile sl@0: RFile64 file; sl@0: INFO_PRINTF2(_L("Opening standard RFile interface with uri: %S"),&uri2); sl@0: User::LeaveIfError(file.Open(iParent.Fs(), uri2, EFileRead | EFileShareReadersOnly)); sl@0: CleanupClosePushL(file); sl@0: sl@0: TInt64 size = 0; sl@0: file.Size(size); sl@0: INFO_PRINTF2(_L("Size of content from f32: %Ld"),size); sl@0: sl@0: // Seek and read from start using both CAF and RFile sl@0: TInt64 pos1 = size/4; sl@0: data->Seek64(ESeekStart, pos1); sl@0: //pos2 needs to be modified to TInt64 when file server supports 64bit sl@0: TInt64 pos2 = size/4; sl@0: file.Seek(ESeekStart, pos2); sl@0: data->Read(buf1); sl@0: file.Read(buf2); sl@0: INFO_PRINTF2(_L("Position from ESeekStart test using CData: %Ld"), pos1); sl@0: INFO_PRINTF2(_L("Position from ESeekStart test using RFile: %Ld"), pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || pos1 != size/4) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // set the location within the file then retrieve the current location within the file sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek64(ESeekCurrent, pos1); sl@0: file.Seek(ESeekCurrent, pos2); sl@0: sl@0: INFO_PRINTF2(_L("Current position using CData: %Ld"), pos1); sl@0: INFO_PRINTF2(_L("Current position using RFile: %Ld"), pos2); sl@0: sl@0: if(pos1 != pos2 || pos1 != (size/4 + buf1.Length())) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Seek and read from current using both CAF and RFile sl@0: pos1 = size/4; sl@0: data->Seek64(ESeekCurrent, pos1); sl@0: pos2 = size/4; sl@0: file.Seek(ESeekCurrent, pos2); sl@0: data->Read(buf1); sl@0: file.Read(buf2); sl@0: INFO_PRINTF2(_L("Position from ESeekCurrent test using CData: %Ld"), pos1); sl@0: INFO_PRINTF2(_L("Position from ESeekCurrent test using RFile: %Ld"), pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || pos1 != (size/2 + buf1.Length())) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Seek and read from end using both CAF and RFile sl@0: pos1 = -size/4; sl@0: data->Seek64(ESeekEnd, pos1); sl@0: pos2 = -size/4; sl@0: file.Seek(ESeekEnd, pos2); sl@0: data->Read(buf1); sl@0: file.Read(buf2); sl@0: INFO_PRINTF2(_L("Position from ESeekEnd test using CData: %Ld"), pos1); sl@0: INFO_PRINTF2(_L("Position from ESeekEnd test using RFile: %Ld"), pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || pos1 != (size - size/4)) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Test other overloaded forms of CData::Read sl@0: sl@0: // Read only 1 byte using both CAF and RFile sl@0: pos1 = size/4; sl@0: data->Seek64(ESeekStart, pos1); sl@0: pos2 = size/4; sl@0: file.Seek(ESeekStart, pos2); sl@0: data->Read(buf1,1); sl@0: file.Read(buf2,1); sl@0: INFO_PRINTF2(_L("Data Length from CData::Read(TDesC& ,TInt Length) : %d"), buf1.Length()); sl@0: INFO_PRINTF2(_L("Data Length from RFile::Read(TDesC& , TInt Length): %d"), buf2.Length()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek64(ESeekCurrent, pos1); sl@0: file.Seek(ESeekCurrent,pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Read asynchronously using both CAF and RFile sl@0: INFO_PRINTF1(_L("Asynchronous read from CAF and RFile")); sl@0: pos1 = size/4; sl@0: data->Seek64(ESeekStart, pos1); sl@0: pos2 = size/4; sl@0: file.Seek(ESeekStart, pos2); sl@0: status = KRequestPending; sl@0: data->Read(buf1,status); sl@0: User::WaitForRequest(status); sl@0: status = KRequestPending; sl@0: file.Read(buf2,status); sl@0: User::WaitForRequest(status); sl@0: INFO_PRINTF2(_L("Data length from CData::Read(TDesC& ,TRequestStatus& aStatus): %d"), buf1.Length()); sl@0: INFO_PRINTF2(_L("Data length from RFile::Read(TDesC& , TRequestStatus& aStatus): %d"), buf2.Length()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek64(ESeekCurrent, pos1); sl@0: file.Seek(ESeekCurrent,pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Read only 1 byte asynchronously using both CAF and RFile sl@0: INFO_PRINTF1(_L("Asynchronous read of 1 byte from CAF and RFile")); sl@0: pos1 = size/4; sl@0: data->Seek64(ESeekStart, pos1); sl@0: pos2 = size/4; sl@0: file.Seek(ESeekStart, pos2); sl@0: status = KRequestPending; sl@0: data->Read(buf1,1,status); sl@0: User::WaitForRequest(status); sl@0: status = KRequestPending; sl@0: file.Read(buf2,1, status); sl@0: User::WaitForRequest(status); sl@0: INFO_PRINTF2(_L("Data Length from CData::Read(TDesC& ,TInt Length, TRequestStatus aStatus) : %d"), buf1.Length()); sl@0: INFO_PRINTF2(_L("Data Length from RFile::Read(TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf2.Length()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek64(ESeekCurrent, pos1); sl@0: file.Seek(ESeekCurrent,pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // read past EOF sl@0: pos1 = size+1; sl@0: pos2 = size+1; sl@0: data->Seek64(ESeekStart, pos1); sl@0: file.Seek(ESeekStart, pos2); sl@0: data->Read(buf1); sl@0: file.Read(buf2); sl@0: sl@0: if(buf1.Length() != 0 || buf1.Length() != 0) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR data read past EOF")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: sl@0: // Read asynchronously supplying an offset using both CAF and RFile sl@0: TInt err; sl@0: INFO_PRINTF1(_L("Asynchronous read of 1 byte from CAF and RFile supplying an offset within the file")); sl@0: pos1 = size/4; sl@0: pos2 = size/4; sl@0: status = KRequestPending; sl@0: err = data->Read(pos1,buf1,1,status); sl@0: sl@0: StandardCheckReturnValue(err); sl@0: sl@0: User::WaitForRequest(status); sl@0: status = KRequestPending; sl@0: file.Read(pos2, buf2,1, status); sl@0: User::WaitForRequest(status); sl@0: INFO_PRINTF2(_L("Data Length from CData::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf1.Length()); sl@0: INFO_PRINTF2(_L("Data Length from RFile::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf2.Length()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek64(ESeekCurrent, pos1); sl@0: file.Seek(ESeekCurrent,pos2); sl@0: if (buf1 !=buf2 || pos1 != pos2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Check asynchronous cancellation sl@0: err = 0; sl@0: INFO_PRINTF1(_L("Asynchronous read cancellation using both CAF and RFile with an offset within the file")); sl@0: pos1 = size/4; sl@0: pos2 = size/4; sl@0: status = KRequestPending; sl@0: err = data->Read(pos1,buf1,1,status); sl@0: StandardCheckReturnValue(err); sl@0: data->ReadCancel(status); sl@0: User::WaitForRequest(status); sl@0: TRequestStatus status2(KRequestPending); sl@0: file.Read(pos2, buf2,1, status2); sl@0: file.ReadCancel(); sl@0: User::WaitForRequest(status2); sl@0: INFO_PRINTF3(_L("Data Length from CData::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d, status is %d"), buf1.Length(), status.Int()); sl@0: INFO_PRINTF3(_L("Data Length from RFile::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d, status is %d"), buf2.Length(), status2.Int()); sl@0: if (status.Int() != status2.Int() || buf1 !=buf2 || pos1 != pos2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR status, buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // read past EOF sl@0: pos1 = size+1; sl@0: pos2 = size+1; sl@0: status = KRequestPending; sl@0: data->Read(pos1,buf1,1,status); sl@0: StandardCheckReturnValue(err); sl@0: User::WaitForRequest(status); sl@0: status = KRequestPending; sl@0: file.Read(pos2,buf2,1,status); sl@0: User::WaitForRequest(status); sl@0: sl@0: if(buf1.Length() != 0 || buf1.Length() != 0) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR data read past EOF")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // read over the length of the buffer sl@0: INFO_PRINTF1(_L("Asynchronous read of 5 bytes from CAF and RFile supplying an offset within the file")); sl@0: pos1 = size/4; sl@0: pos2 = size/4; sl@0: status = KRequestPending; sl@0: err = data->Read(pos1,buf1,5,status); sl@0: StandardCheckReturnValue(err); sl@0: User::WaitForRequest(status); sl@0: if(status.Int()!=KErrOverflow) sl@0: { sl@0: INFO_PRINTF2(_L("ERROR Unexpected status returned: %d"),status.Int()); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: status = KRequestPending; sl@0: file.Read(pos2, buf2,5, status); sl@0: User::WaitForRequest(status); sl@0: INFO_PRINTF2(_L("Data Length from CData::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf1.Length()); sl@0: INFO_PRINTF2(_L("Data Length from RFile::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf2.Length()); sl@0: sl@0: if (buf1 !=buf2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: // read negative position this should return KErrArgument, dont supply -ve pos to RFile as will panic test sl@0: INFO_PRINTF1(_L("Asynchronous read from CAF supplying a negative offset within the file")); sl@0: pos1 = -1; sl@0: status = KRequestPending; sl@0: err = data->Read(pos1,buf1,5,status); sl@0: if(err!=KErrArgument) sl@0: { sl@0: INFO_PRINTF2(_L("ERROR Unexpected return value: %d"),err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Read asynchronously supplying an offset of 0 and a length greater than size of file using both CAF and RFile sl@0: INFO_PRINTF1(_L("Asynchronous read of length greater than size of file from CAF and RFile supplying an offset of 0 within the file")); sl@0: TBuf8<256> buf3; sl@0: TBuf8<256> buf4; sl@0: pos1 = 0; sl@0: pos2 = 0; sl@0: status = KRequestPending; sl@0: err = data->Read(pos1,buf3,size+1,status); sl@0: StandardCheckReturnValue(err); sl@0: User::WaitForRequest(status); sl@0: status = KRequestPending; sl@0: file.Read(pos2, buf4,size+1, status); sl@0: User::WaitForRequest(status); sl@0: INFO_PRINTF2(_L("Data Length from CData::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf3.Size()); sl@0: INFO_PRINTF2(_L("Data Length from RFile::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf4.Size()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek64(ESeekCurrent, pos1); sl@0: file.Seek(ESeekCurrent,pos2); sl@0: if (buf3 != buf4 || pos1 != pos2 || buf3.Length() != buf4.Length() || pos1 != size || sl@0: pos2 != size || buf3.Size() != pos1 || buf4.Size() != pos2) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Read asynchronously supplying an offset of size/4 and a length greater than size of file using both CAF and RFile sl@0: INFO_PRINTF1(_L("Asynchronous read of length greater than size of file from CAF and RFile supplying an offset within the file")); sl@0: pos1 = size/4; sl@0: pos2 = size/4; sl@0: status = KRequestPending; sl@0: err = data->Read(pos1,buf3,size+1,status); sl@0: StandardCheckReturnValue(err); sl@0: User::WaitForRequest(status); sl@0: status = KRequestPending; sl@0: file.Read(pos2, buf4,size+1, status); sl@0: User::WaitForRequest(status); sl@0: INFO_PRINTF2(_L("Data Length from CData::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus) : %d"), buf3.Size()); sl@0: INFO_PRINTF2(_L("Data Length from RFile::Read(TInt64 aPos, TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf4.Size()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek64(ESeekCurrent, pos1); sl@0: file.Seek(ESeekCurrent,pos2); sl@0: if (buf3 != buf4 || pos1 != pos2 || buf3.Size() != buf4.Size() || pos1 != size || pos2 != size) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2, data); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: if (TestStepResult() != EFail) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API sl@0: /* sl@0: * This step retrieves the attributes of a file using the CAF framework sl@0: * sl@0: */ sl@0: sl@0: CCAFAttributesStep::~CCAFAttributesStep() sl@0: { sl@0: } sl@0: sl@0: CCAFAttributesStep::CCAFAttributesStep(CCAFServer& aParent) : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFAttributesStep); sl@0: } sl@0: sl@0: sl@0: TVerdict CCAFAttributesStep::doTestStepL() sl@0: { sl@0: CContent *content; sl@0: CAttribute *attrs; sl@0: TPtrC fileName; sl@0: TBool Protected; sl@0: TBool Forwardable; sl@0: sl@0: sl@0: TBool Value; sl@0: sl@0: SetTestStepResult(EFail); sl@0: sl@0: GetStringFromConfig(ConfigSection(),_L("filename"),fileName); sl@0: GetBoolFromConfig(ConfigSection(),_L("Protected"),Protected); sl@0: GetBoolFromConfig(ConfigSection(),_L("Forwardable"),Forwardable); sl@0: sl@0: sl@0: INFO_PRINTF2(_L("Check attributes of file: %S"), &fileName); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: // Open a file and retrieve the attributes sl@0: content = CContent::NewLC(fileName); sl@0: attrs = content->NewAttributeL(ETrue); sl@0: CleanupStack::PushL(attrs); sl@0: sl@0: // Assume all the attributes are what we expect them to be sl@0: SetTestStepResult(EPass); sl@0: sl@0: Value = attrs->ResponseSet().IsSet(EIsProtected); sl@0: if(Value != Protected) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: Protected ? INFO_PRINTF1(_L("File is Protected")) : INFO_PRINTF1(_L("File is not Protected")); sl@0: } sl@0: sl@0: Value = attrs->ResponseSet().IsSet(EIsForwardable); sl@0: if(Value != Forwardable) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: Forwardable ? INFO_PRINTF1(_L("File is Forwardable")) : INFO_PRINTF1(_L("File is not Forwardable")); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2, content); sl@0: sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: /* sl@0: * This step retrieves the string attributes of a file using the CAF framework sl@0: * sl@0: */ sl@0: sl@0: CCAFStringAttributesStep::~CCAFStringAttributesStep() sl@0: { sl@0: } sl@0: sl@0: CCAFStringAttributesStep::CCAFStringAttributesStep(CCAFServer& aParent) : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFStringAttributesStep); sl@0: } sl@0: sl@0: sl@0: TVerdict CCAFStringAttributesStep::doTestStepL() sl@0: { sl@0: TInt expectedResult; sl@0: TInt attribute; sl@0: TPtrC expectedValue; sl@0: TBuf <256> value; //this will be used to test KErrOverFlow when transactionid is 257char long. sl@0: TInt result = KErrNone; sl@0: TPtrC uri; sl@0: TPtrC uniqueId; sl@0: sl@0: SetTestStepResult(EPass); sl@0: sl@0: GetIntFromConfig(ConfigSection(),_L("stringattribute"),attribute); sl@0: GetStringFromConfig(ConfigSection(),_L("uri"),uri); sl@0: GetStringFromConfig(ConfigSection(),_L("uniqueid"),uniqueId); sl@0: GetStringFromConfig(ConfigSection(),_L("value"),expectedValue); sl@0: GetIntFromConfig(ConfigSection(),_L("result"),expectedResult); sl@0: sl@0: __UHEAP_MARK; sl@0: CContent *content = CContent::NewLC(uri); sl@0: CData *data = content->OpenContentL(EPeek, uniqueId); sl@0: result = data->GetStringAttribute(attribute, value); sl@0: delete data; sl@0: if(result != expectedResult) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF3(_L("CData::GetStringAttribute() Expected result: %d, actual result: %d"), expectedResult, result); sl@0: } sl@0: if(value != expectedValue) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF3(_L("CData::GetStringAttribute() Expected value: %S, actual result: %S"), &expectedValue, &value); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(content); sl@0: sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: sl@0: /* sl@0: * Step reads from a CData from multiple threads sl@0: * sl@0: */ sl@0: sl@0: CCAFMultiThreadCDataStep::~CCAFMultiThreadCDataStep() sl@0: { sl@0: } sl@0: sl@0: CCAFMultiThreadCDataStep::CCAFMultiThreadCDataStep(CCAFServer& aParent) sl@0: : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFMultiThreadCDataStep); sl@0: } sl@0: sl@0: TVerdict CCAFMultiThreadCDataStep::doTestStepL() sl@0: { sl@0: TBuf8<2> buf; sl@0: sl@0: __UHEAP_MARK; sl@0: _LIT(KCDataThread,"CData_Thread"); sl@0: sl@0: SetTestStepResult(EInconclusive); sl@0: sl@0: INFO_PRINTF1(_L("Multi Thread CData Test")); sl@0: sl@0: TPtrC uri; sl@0: GetStringFromConfig(ConfigSection(),_L("URI"),uri); sl@0: sl@0: INFO_PRINTF1(_L("Creating data object from content")); sl@0: CContent* content = CContent::NewLC(uri); sl@0: CData* data = content->OpenContentL(EPeek); sl@0: CleanupStack::PushL(data); sl@0: sl@0: TInt size, pos; sl@0: sl@0: // Create a mutex for communication between our thread and the new thread sl@0: RSemaphore threadSemaphore; sl@0: threadSemaphore.CreateGlobal(KCDataThreadSemaphore(), 1, EOwnerProcess); sl@0: threadSemaphore.Wait(); sl@0: sl@0: // fire up a new thread, stack size and heap size 8k, might need to be bigger in the future sl@0: RThread readerThread; sl@0: User::LeaveIfError(readerThread.Create(KCDataThread(),CCAFMultiThreadCDataStep::ReaderThreadEntry,8192, KMinHeapSize, 8192, (TAny *) data, EOwnerProcess)); sl@0: sl@0: // request notification of thread completion sl@0: TRequestStatus stat; sl@0: readerThread.Logon(stat); sl@0: readerThread.Resume(); sl@0: sl@0: data->DataSizeL(size); sl@0: pos = size/2; sl@0: data->Seek(ESeekStart,pos); sl@0: data->Read(buf); sl@0: sl@0: threadSemaphore.Wait(); // wait for thread function to run and signal the semaphore sl@0: threadSemaphore.Signal(); // finished with semaphore sl@0: threadSemaphore.Close(); // so close sl@0: sl@0: User::WaitForRequest(stat); // wait for thread to finish sl@0: TInt error=(readerThread.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); sl@0: User::LeaveIfError(error); sl@0: readerThread.Close(); // close the thread sl@0: sl@0: CleanupStack::PopAndDestroy(data); sl@0: CleanupStack::PopAndDestroy(content); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: SetTestStepResult(EPass); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: TInt CCAFMultiThreadCDataStep::ReaderThreadEntry(TAny *aPtr) sl@0: { sl@0: TBuf8 <2> buf; sl@0: CData *data = reinterpret_cast (aPtr); sl@0: sl@0: // create a trap handler sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: sl@0: RSemaphore threadSemaphore; sl@0: threadSemaphore.OpenGlobal(KCDataThreadSemaphore() ,EOwnerProcess); sl@0: sl@0: data->Read(buf); sl@0: threadSemaphore.Signal(); // allow original thread to continue sl@0: threadSemaphore.Close(); sl@0: sl@0: delete cleanup; sl@0: return KErrNone; sl@0: } sl@0: sl@0: sl@0: /* sl@0: * Obtains the mime type from a CData sl@0: * sl@0: */ sl@0: sl@0: CCAFMimeTypeCDataStep::~CCAFMimeTypeCDataStep() sl@0: { sl@0: } sl@0: sl@0: CCAFMimeTypeCDataStep::CCAFMimeTypeCDataStep(CCAFServer& aParent) sl@0: : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFMimeTypeCDataStep); sl@0: } sl@0: sl@0: TVerdict CCAFMimeTypeCDataStep::doTestStepL() sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: sl@0: SetTestStepResult(EFail); sl@0: sl@0: INFO_PRINTF1(_L("CData MimeType Test")); sl@0: sl@0: TPtrC uri; sl@0: TPtrC expectedMimeType; sl@0: TBool mimeTypeKnown=EFalse; sl@0: sl@0: // Load INI parameters sl@0: GetStringFromConfig(ConfigSection(),_L("URI"),uri); sl@0: GetStringFromConfig(ConfigSection(),_L("ContentMimeType"),expectedMimeType); sl@0: GetBoolFromConfig(ConfigSection(),_L("Known"),mimeTypeKnown); sl@0: sl@0: // convert to Des8 sl@0: HBufC8 *expected = ConvertDes16toHBufC8LC(expectedMimeType); sl@0: sl@0: // Create CContent and CData sl@0: INFO_PRINTF1(_L("Creating data object from content")); sl@0: CContent* content = CContent::NewLC(uri); sl@0: CData* data = content->OpenContentL(EPeek); sl@0: CleanupStack::PushL(data); sl@0: sl@0: // Get mime type from CData sl@0: INFO_PRINTF1(_L("Checking mime type")); sl@0: HBufC8 *buffer = HBufC8::NewLC(KCafTestMaxDataTypeLength); sl@0: TPtr8 ptr = buffer->Des(); sl@0: TBool r = data->GetMimeTypeL(ptr); sl@0: sl@0: // check if result matches expected result sl@0: if(r == mimeTypeKnown && *buffer == *expected) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(4,expected); sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /* sl@0: * This step tests file sharing modes sl@0: * sl@0: */ sl@0: sl@0: CCAFShareModeStep::~CCAFShareModeStep() sl@0: { sl@0: } sl@0: sl@0: CCAFShareModeStep::CCAFShareModeStep(CCAFServer& aParent) : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFShareModeStep); sl@0: } sl@0: sl@0: sl@0: TVerdict CCAFShareModeStep::doTestStepL() sl@0: { sl@0: TVerdict verdict = EFail; sl@0: TRAPD(err, verdict = doShareModeStepL()); sl@0: if(err != KErrNone) sl@0: { sl@0: if(err != KErrInUse) sl@0: { sl@0: User::Leave(err); sl@0: } sl@0: else sl@0: { sl@0: User::Leave(KErrGeneral); sl@0: } sl@0: } sl@0: return verdict; sl@0: } sl@0: sl@0: TVerdict CCAFShareModeStep::doShareModeStepL() sl@0: { sl@0: CAttribute *attr = NULL; sl@0: RFile file; sl@0: RFs fs; sl@0: TPtrC fileName; sl@0: TInt err = 0; sl@0: sl@0: SetTestStepResult(EPass); sl@0: sl@0: GetStringFromConfig(ConfigSection(),_L("FileName"),fileName); sl@0: sl@0: // This function works if I step through everything but fails sl@0: // when run or step over the TRAP sl@0: // User::Leave(KErrGeneral); sl@0: sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: INFO_PRINTF2(_L("Creating Content object for file: %S"), &fileName); sl@0: CContent* content= CContent::NewL(fileName); sl@0: CData *data = NULL; sl@0: sl@0: fs.Connect(); sl@0: CleanupClosePushL(fs); sl@0: sl@0: sl@0: INFO_PRINTF1(_L("Testing EContentShareReadOnly")); sl@0: User::LeaveIfError(file.Open(fs, fileName, EFileShareReadersOnly | EFileRead | EFileStream)); sl@0: CleanupClosePushL(file); sl@0: data = content->OpenContentL(EPeek); sl@0: delete data; sl@0: data = NULL; sl@0: data = content->OpenContentL(EPeek, EContentShareReadOnly); sl@0: delete data; sl@0: data = NULL; sl@0: TRAP(err, data = content->OpenContentL(EPeek, EContentShareReadWrite)); sl@0: delete data; sl@0: data = NULL; sl@0: sl@0: // We can open read-write because CAF never writes. sl@0: sl@0: if(err != KErrNone) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // However, exclusive mode should be impossible. sl@0: sl@0: TRAP(err, data = content->OpenContentL(EPeek, EContentShareExclusive)); sl@0: delete data; sl@0: data = NULL; sl@0: if(err != KErrInUse) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: CleanupStack::PopAndDestroy(&file); sl@0: delete content; sl@0: sl@0: sl@0: INFO_PRINTF1(_L("Testing EContentShareReadWrite")); sl@0: content = CContent::NewL(fileName, EContentShareReadWrite); sl@0: User::LeaveIfError(file.Open(fs, fileName, EFileShareReadersOrWriters | EFileRead | EFileStream)); sl@0: CleanupClosePushL(file); sl@0: data = content->OpenContentL(EPeek, EContentShareReadWrite); sl@0: delete data; sl@0: data = NULL; sl@0: sl@0: // We should be able to open read-only sl@0: sl@0: TRAP(err, data = content->OpenContentL(EPeek, EContentShareReadOnly)); sl@0: delete data; sl@0: data = NULL; sl@0: if(err != KErrNone) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // but not share exclusive sl@0: sl@0: TRAP(err, data = content->OpenContentL(EPeek, EContentShareExclusive)); sl@0: delete data; sl@0: data = NULL; sl@0: if(err != KErrInUse) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: CleanupStack::PopAndDestroy(&file); sl@0: sl@0: sl@0: // Reopen the file with write attributes, and make sure ReadOnly becomes impossible sl@0: User::LeaveIfError(file.Open(fs, fileName, EFileShareReadersOrWriters | EFileRead | EFileWrite | EFileStream)); sl@0: CleanupClosePushL(file); sl@0: sl@0: TRAP(err, data = content->OpenContentL(EPeek, EContentShareReadOnly)); sl@0: delete data; sl@0: data = NULL; sl@0: if(err != KErrInUse) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(&file); sl@0: delete content; sl@0: sl@0: sl@0: INFO_PRINTF1(_L("Testing EContentShareExclusive")); sl@0: User::LeaveIfError(file.Open(fs, fileName, EFileShareExclusive | EFileRead | EFileStream)); sl@0: CleanupClosePushL(file); sl@0: TRAP(err, data = CData::NewL(TVirtualPathPtr(fileName), EPeek, EContentShareReadOnly)); sl@0: delete data; sl@0: data = NULL; sl@0: if(err != KErrInUse) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: TRAP(err, data = CData::NewL(TVirtualPathPtr(fileName), EPeek, EContentShareReadWrite)); sl@0: delete data; sl@0: data = NULL; sl@0: if(err != KErrInUse) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: TRAP(err, data = CData::NewL(TVirtualPathPtr(fileName), EPeek, EContentShareExclusive)); sl@0: delete data; sl@0: data = NULL; sl@0: if(err != KErrInUse) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: CleanupStack::PopAndDestroy(&file); sl@0: sl@0: INFO_PRINTF1(_L("Testing CContent::NewAttributeL")); sl@0: content = CContent::NewL(fileName, EContentShareReadWrite); sl@0: User::LeaveIfError(file.Open(fs, fileName, EFileShareAny | EFileRead | EFileStream)); sl@0: CleanupClosePushL(file); sl@0: attr = content->NewAttributeL(ETrue,EContentShareReadWrite); sl@0: delete attr; sl@0: attr = NULL; sl@0: TRAP(err, attr = content->NewAttributeL(ETrue)); sl@0: delete attr; sl@0: attr = NULL; sl@0: if(err != KErrInUse) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: CleanupStack::PopAndDestroy(2, &fs); // fs, file sl@0: delete content; sl@0: sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: CCAFHandleSizeStep::CCAFHandleSizeStep(CCAFServer& aParent) sl@0: :iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFHandleSizeStep); sl@0: } sl@0: sl@0: CCAFHandleSizeStep::~CCAFHandleSizeStep() sl@0: { sl@0: sl@0: sl@0: } sl@0: sl@0: TVerdict CCAFHandleSizeStep::doTestStepL() sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: SetTestStepResult(EInconclusive); sl@0: sl@0: INFO_PRINTF1(_L("Basic Open Content Test")); sl@0: sl@0: TPtrC uri1; sl@0: TPtrC uri2; sl@0: GetStringFromConfig(ConfigSection(),_L("URI1"),uri1); sl@0: GetStringFromConfig(ConfigSection(),_L("URI2"),uri2); sl@0: sl@0: INFO_PRINTF2(_L("Creating content object with uri: %S"), &uri1); sl@0: sl@0: RFile file1; sl@0: User::LeaveIfError(file1.Open(iParent.Fs(), uri1, EFileRead)); sl@0: CleanupClosePushL(file1); sl@0: sl@0: CContent* content = CContent::NewLC(file1); sl@0: sl@0: INFO_PRINTF1(_L("Creating data object from content")); sl@0: sl@0: CData* data = content->OpenContentL(EPeek); sl@0: CleanupStack::PushL(data); sl@0: sl@0: TInt size = 0; sl@0: data->DataSizeL(size); sl@0: INFO_PRINTF2(_L("Size of content from caf: %d"),size); sl@0: CleanupStack::PopAndDestroy(data); sl@0: CleanupStack::PopAndDestroy(content); sl@0: sl@0: TInt pos = 0; sl@0: file1.Seek(ESeekStart, pos); sl@0: sl@0: INFO_PRINTF2(_L("Creating CData object with uri: %S"), &uri1); sl@0: TInt size1 = 0; sl@0: data = CData::NewL(file1, KDefaultContentObject(), EPeek); sl@0: CleanupStack::PushL(data); sl@0: data->DataSizeL(size1); sl@0: INFO_PRINTF2(_L("Size of content from caf CData::NewL(): %d"),size1); sl@0: CleanupStack::PopAndDestroy(data); sl@0: CleanupStack::PopAndDestroy(&file1); sl@0: sl@0: INFO_PRINTF2(_L("Opening standard RFile interface with uri: %S"),&uri2); sl@0: RFile file2; sl@0: User::LeaveIfError(file2.Open(iParent.Fs(), uri2, EFileRead)); sl@0: sl@0: TInt size2; sl@0: file2.Size(size2); sl@0: file2.Close(); sl@0: sl@0: INFO_PRINTF2(_L("Size of content from f32: %d"),size2); sl@0: sl@0: if(size == size2 && size1 == size2) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: else sl@0: { sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: CCAFHandleSeekReadStep::~CCAFHandleSeekReadStep() sl@0: { sl@0: sl@0: } sl@0: sl@0: CCAFHandleSeekReadStep::CCAFHandleSeekReadStep(CCAFServer& aParent) sl@0: : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFHandleSeekReadStep); sl@0: } sl@0: sl@0: TVerdict CCAFHandleSeekReadStep::doTestStepL() sl@0: { sl@0: SetTestStepResult(EInconclusive); sl@0: sl@0: TBuf8<2> buf1; sl@0: TBuf8<2> buf2; sl@0: TRequestStatus status; sl@0: sl@0: __UHEAP_MARK; sl@0: INFO_PRINTF1(_L("Basic Open Content Test")); sl@0: sl@0: TPtrC uri1; sl@0: TPtrC uri2; sl@0: GetStringFromConfig(ConfigSection(),_L("URI1"),uri1); sl@0: GetStringFromConfig(ConfigSection(),_L("URI2"),uri2); sl@0: sl@0: INFO_PRINTF2(_L("Creating content object with uri: %S"), &uri1); sl@0: RFile file1; sl@0: User::LeaveIfError(file1.Open(iParent.Fs(), uri1, EFileRead | EFileShareReadersOnly)); sl@0: CleanupClosePushL(file1); sl@0: CContent* content = CContent::NewLC(file1); sl@0: sl@0: INFO_PRINTF1(_L("Creating data object from content")); sl@0: CData* data = content->OpenContentL(EPeek); sl@0: CleanupStack::PushL(data); sl@0: sl@0: // Now, open the same file using RFile sl@0: RFile file2; sl@0: INFO_PRINTF2(_L("Opening standard RFile interface with uri: %S"),&uri2); sl@0: //User::LeaveIfError(file2.Open(iParent.Fs(), uri2, EFileRead | EFileShareReadersOnly)); sl@0: TInt res = file2.Open(iParent.Fs(), uri2, EFileRead | EFileShareReadersOnly); sl@0: CleanupClosePushL(file2); sl@0: sl@0: TInt size = 0; sl@0: file2.Size(size); sl@0: INFO_PRINTF2(_L("Size of content from f32: %d"),size); sl@0: sl@0: // Seek and read from start using both CAF and RFile sl@0: TInt pos1 = size/4; sl@0: data->Seek(ESeekStart, pos1); sl@0: TInt pos2 = size/4; sl@0: file2.Seek(ESeekStart, pos2); sl@0: data->Read(buf1); sl@0: file2.Read(buf2); sl@0: INFO_PRINTF2(_L("Position from ESeekStart test using CData: %d"), pos1); sl@0: INFO_PRINTF2(_L("Position from ESeekStart test using RFile: %d"), pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || pos1 != size/4) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // set the location within the file then retrieve the current location within the file sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek(ESeekCurrent, pos1); sl@0: file2.Seek(ESeekCurrent, pos2); sl@0: sl@0: INFO_PRINTF2(_L("Current position using CData: %d"), pos1); sl@0: INFO_PRINTF2(_L("Current position using RFile: %d"), pos2); sl@0: sl@0: if(pos1 != pos2 || pos1 != (size/4 + buf1.Length())) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Seek and read from current using both CAF and RFile sl@0: pos1 = size/4; sl@0: data->Seek(ESeekCurrent, pos1); sl@0: pos2 = size/4; sl@0: file2.Seek(ESeekCurrent, pos2); sl@0: data->Read(buf1); sl@0: file2.Read(buf2); sl@0: INFO_PRINTF2(_L("Position from ESeekCurrent test using CData: %d"), pos1); sl@0: INFO_PRINTF2(_L("Position from ESeekCurrent test using RFile: %d"), pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || pos1 != (size/2 + buf1.Length())) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Seek and read from end using both CAF and RFile sl@0: pos1 = -size/4; sl@0: data->Seek(ESeekEnd, pos1); sl@0: pos2 = -size/4; sl@0: file2.Seek(ESeekEnd, pos2); sl@0: data->Read(buf1); sl@0: file2.Read(buf2); sl@0: INFO_PRINTF2(_L("Position from ESeekEnd test using CData: %d"), pos1); sl@0: INFO_PRINTF2(_L("Position from ESeekEnd test using RFile: %d"), pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || pos1 != (size - size/4)) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Test other overloaded forms of CData::Read sl@0: sl@0: // Read only 1 byte using both CAF and RFile sl@0: pos1 = size/4; sl@0: data->Seek(ESeekStart, pos1); sl@0: pos2 = size/4; sl@0: file2.Seek(ESeekStart, pos2); sl@0: data->Read(buf1,1); sl@0: file2.Read(buf2,1); sl@0: INFO_PRINTF2(_L("Data Length from CData::Read(TDesC& ,TInt Length) : %d"), buf1.Length()); sl@0: INFO_PRINTF2(_L("Data Length from RFile::Read(TDesC& , TInt Length): %d"), buf2.Length()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek(ESeekCurrent, pos1); sl@0: file2.Seek(ESeekCurrent,pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Read asynchronously using both CAF and RFile sl@0: INFO_PRINTF1(_L("Asynchronous read from CAF and RFile")); sl@0: pos1 = size/4; sl@0: data->Seek(ESeekStart, pos1); sl@0: pos2 = size/4; sl@0: file2.Seek(ESeekStart, pos2); sl@0: status = KRequestPending; sl@0: data->Read(buf1,status); sl@0: User::WaitForRequest(status); sl@0: status = KRequestPending; sl@0: file2.Read(buf2,status); sl@0: User::WaitForRequest(status); sl@0: INFO_PRINTF2(_L("Data length from CData::Read(TDesC& ,TRequestStatus& aStatus): %d"), buf1.Length()); sl@0: INFO_PRINTF2(_L("Data length from RFile::Read(TDesC& , TRequestStatus& aStatus): %d"), buf2.Length()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek(ESeekCurrent, pos1); sl@0: file2.Seek(ESeekCurrent,pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // Read only 1 byte asynchronously using both CAF and RFile sl@0: INFO_PRINTF1(_L("Asynchronous read of 1 byte from CAF and RFile")); sl@0: pos1 = size/4; sl@0: data->Seek(ESeekStart, pos1); sl@0: pos2 = size/4; sl@0: file2.Seek(ESeekStart, pos2); sl@0: status = KRequestPending; sl@0: data->Read(buf1,1,status); sl@0: User::WaitForRequest(status); sl@0: status = KRequestPending; sl@0: file2.Read(buf2,1, status); sl@0: User::WaitForRequest(status); sl@0: INFO_PRINTF2(_L("Data Length from CData::Read(TDesC& ,TInt Length, TRequestStatus aStatus) : %d"), buf1.Length()); sl@0: INFO_PRINTF2(_L("Data Length from RFile::Read(TDesC& , TInt Length, TRequestStatus aStatus): %d"), buf2.Length()); sl@0: sl@0: pos1=0; sl@0: pos2=0; sl@0: data->Seek(ESeekCurrent, pos1); sl@0: file2.Seek(ESeekCurrent,pos2); sl@0: if (buf1 != buf2 || pos1 != pos2 || buf1.Length() != buf2.Length()) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR buffers or position do not match")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: // read past EOF sl@0: pos1 = size+1; sl@0: pos2 = size+1; sl@0: data->Seek(ESeekStart, pos1); sl@0: file2.Seek(ESeekStart, pos2); sl@0: data->Read(buf1); sl@0: file2.Read(buf2); sl@0: sl@0: if(buf1.Length() != 0 || buf1.Length() != 0) sl@0: { sl@0: INFO_PRINTF1(_L("ERROR data read past EOF")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(4); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: if (TestStepResult() != EFail) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /* sl@0: * Step reads from a CData from multiple threads using RFile handle sl@0: * sl@0: */ sl@0: sl@0: CCAFHandleMultiThreadCDataStep::~CCAFHandleMultiThreadCDataStep() sl@0: { sl@0: sl@0: } sl@0: sl@0: CCAFHandleMultiThreadCDataStep::CCAFHandleMultiThreadCDataStep(CCAFServer& aParent) sl@0: :iParent(aParent) sl@0: { sl@0: sl@0: SetTestStepName(KCAFHandleMultiThreadCDataStep); sl@0: } sl@0: sl@0: TVerdict CCAFHandleMultiThreadCDataStep::doTestStepL() sl@0: { sl@0: TBuf8<2> buf; sl@0: sl@0: __UHEAP_MARK; sl@0: _LIT(KCDataThread,"CData_Thread"); sl@0: sl@0: SetTestStepResult(EInconclusive); sl@0: sl@0: INFO_PRINTF1(_L("Multi Thread CData Test using RFile Handle")); sl@0: sl@0: TPtrC uri; sl@0: GetStringFromConfig(ConfigSection(),_L("URI"),uri); sl@0: sl@0: INFO_PRINTF1(_L("Creating data object from content")); sl@0: RFile file; sl@0: User::LeaveIfError(file.Open(iParent.Fs(), uri, EFileRead)); sl@0: sl@0: CleanupClosePushL(file); sl@0: sl@0: CContent* content = CContent::NewLC(file); sl@0: CData* data = content->OpenContentL(EPeek); sl@0: CleanupStack::PushL(data); sl@0: sl@0: TInt size, pos; sl@0: sl@0: // Create a mutex for communication between our thread and the new thread sl@0: RSemaphore threadSemaphore; sl@0: threadSemaphore.CreateGlobal(KCDataThreadSemaphore(), 1, EOwnerProcess); sl@0: threadSemaphore.Wait(); sl@0: sl@0: // fire up a new thread, stack size and heap size 8k, might need to be bigger in the future sl@0: RThread readerThread; sl@0: User::LeaveIfError(readerThread.Create(KCDataThread(),CCAFMultiThreadCDataStep::ReaderThreadEntry,8192, KMinHeapSize, 8192, (TAny *) data, EOwnerProcess)); sl@0: sl@0: // request notification of thread completion sl@0: TRequestStatus stat; sl@0: readerThread.Logon(stat); sl@0: readerThread.Resume(); sl@0: sl@0: sl@0: data->DataSizeL(size); sl@0: pos = size/2; sl@0: data->Seek(ESeekStart,pos); sl@0: data->Read(buf); sl@0: sl@0: threadSemaphore.Wait(); // wait for thread function to run and signal the semaphore sl@0: threadSemaphore.Signal(); // finished with semaphore sl@0: threadSemaphore.Close(); // so close sl@0: sl@0: User::WaitForRequest(stat); // wait for thread to finish sl@0: TInt error=(readerThread.ExitType()==EExitPanic) ? KErrGeneral : stat.Int(); sl@0: User::LeaveIfError(error); sl@0: readerThread.Close(); // close the thread sl@0: sl@0: CleanupStack::PopAndDestroy(data); sl@0: CleanupStack::PopAndDestroy(content); sl@0: CleanupStack::PopAndDestroy(&file); //file sl@0: sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: SetTestStepResult(EPass); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: TInt CCAFHandleMultiThreadCDataStep::ReaderThreadEntry(TAny *aPtr) sl@0: { sl@0: TBuf8 <2> buf; sl@0: CData *data = reinterpret_cast (aPtr); sl@0: sl@0: // create a trap handler sl@0: CTrapCleanup* cleanup = CTrapCleanup::New(); sl@0: sl@0: RSemaphore threadSemaphore; sl@0: threadSemaphore.OpenGlobal(KCDataThreadSemaphore() ,EOwnerProcess); sl@0: sl@0: data->Read(buf); sl@0: threadSemaphore.Signal(); // allow original thread to continue sl@0: threadSemaphore.Close(); sl@0: sl@0: delete cleanup; sl@0: return KErrNone; sl@0: } sl@0: sl@0: /* sl@0: * Data attribute step sl@0: * sl@0: */ sl@0: sl@0: CCAFDataAttributeStep::~CCAFDataAttributeStep() sl@0: { sl@0: } sl@0: sl@0: CCAFDataAttributeStep::CCAFDataAttributeStep(CCAFServer& aParent) : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFDataAttributeStep); sl@0: } sl@0: sl@0: TVerdict CCAFDataAttributeStep::doTestStepL() sl@0: { sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: TBool wmdrmFlag = EFalse; sl@0: GetBoolFromConfig(ConfigSection(),_L("wmdrmEnabled"), wmdrmFlag); sl@0: sl@0: if(wmdrmFlag) sl@0: { sl@0: TVerdict verdict = doWmdrmTestStepL(); sl@0: return verdict; sl@0: } sl@0: #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: TInt attribute; sl@0: TInt value = KErrNone; sl@0: TInt expectedValue = KErrNone; sl@0: TPtrC uri; sl@0: TPtrC uniqueId; sl@0: sl@0: SetTestStepResult(EPass); sl@0: sl@0: GetIntFromConfig(ConfigSection(),_L("attribute"),attribute); sl@0: GetStringFromConfig(ConfigSection(),_L("uri"),uri); sl@0: GetStringFromConfig(ConfigSection(),_L("uniqueid"),uniqueId); sl@0: GetIntFromConfig(ConfigSection(),_L("value"),expectedValue); sl@0: sl@0: __UHEAP_MARK; sl@0: CContent *content = CContent::NewLC(uri); sl@0: CData *data = content->OpenContentL(EPeek, uniqueId); sl@0: User::LeaveIfError(data->GetAttribute(attribute, value)); sl@0: delete data; sl@0: if(expectedValue != value) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF3(_L("CData::GetAttribute() Expected value: %d, actual value: %d"), expectedValue, value); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(content); sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /* sl@0: * Data attributeset step sl@0: * sl@0: */ sl@0: sl@0: CCAFDataAttributeSetStep::~CCAFDataAttributeSetStep() sl@0: { sl@0: } sl@0: sl@0: CCAFDataAttributeSetStep::CCAFDataAttributeSetStep(CCAFServer& aParent) : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFDataAttributeSetStep); sl@0: } sl@0: sl@0: TVerdict CCAFDataAttributeSetStep::doTestStepL() sl@0: { sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: TBool wmdrmFlag = EFalse; sl@0: GetBoolFromConfig(ConfigSection(),_L("wmdrmEnabled"), wmdrmFlag); sl@0: sl@0: if(wmdrmFlag) sl@0: { sl@0: TVerdict verdict = doWmdrmTestStepL(); sl@0: return verdict; sl@0: } sl@0: #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: TInt expectedValue1; sl@0: TInt expectedValue2; sl@0: TInt value1; sl@0: TInt value2; sl@0: TInt attribute1; sl@0: TInt attribute2; sl@0: TInt result = KErrNone; sl@0: TPtrC uri; sl@0: TPtrC uniqueId; sl@0: sl@0: SetTestStepResult(EPass); sl@0: sl@0: GetStringFromConfig(ConfigSection(),_L("uri"),uri); sl@0: GetStringFromConfig(ConfigSection(),_L("uniqueid"),uniqueId); sl@0: GetIntFromConfig(ConfigSection(),_L("attribute1"),attribute1); sl@0: GetIntFromConfig(ConfigSection(),_L("attribute2"),attribute2); sl@0: GetIntFromConfig(ConfigSection(),_L("value1"),expectedValue1); sl@0: GetIntFromConfig(ConfigSection(),_L("value2"),expectedValue2); sl@0: sl@0: __UHEAP_MARK; sl@0: CContent *content = CContent::NewLC(uri); sl@0: RAttributeSet attributeSet; sl@0: CleanupClosePushL(attributeSet); sl@0: attributeSet.AddL(attribute1); sl@0: attributeSet.AddL(attribute2); sl@0: sl@0: CData *data = content->OpenContentL(EPeek, uniqueId); sl@0: result = data->GetAttributeSet(attributeSet); sl@0: delete data; sl@0: if(result != KErrNone) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF1(_L("CData::GetAttribute() failed")); sl@0: } sl@0: User::LeaveIfError(attributeSet.GetValue(attribute1, value1)); sl@0: User::LeaveIfError(attributeSet.GetValue(attribute2, value2)); sl@0: if(value1 != expectedValue1 || value2 != expectedValue2 || attributeSet.Count() != 2) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF1(_L("CData::GetAttributeSet() values don't match expected values")); sl@0: } sl@0: CleanupStack::PopAndDestroy(&attributeSet); sl@0: CleanupStack::PopAndDestroy(content); sl@0: sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: /* sl@0: * Data string attribute step sl@0: * sl@0: */ sl@0: sl@0: CCAFDataStringAttributeStep::~CCAFDataStringAttributeStep() sl@0: { sl@0: } sl@0: sl@0: CCAFDataStringAttributeStep::CCAFDataStringAttributeStep(CCAFServer& aParent) : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFDataStringAttributeStep); sl@0: } sl@0: sl@0: TVerdict CCAFDataStringAttributeStep::doTestStepL() sl@0: { sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: TBool wmdrmFlag = EFalse; sl@0: GetBoolFromConfig(ConfigSection(),_L("wmdrmEnabled"), wmdrmFlag); sl@0: sl@0: if(wmdrmFlag) sl@0: { sl@0: TVerdict verdict = doWmdrmTestStepL(); sl@0: return verdict; sl@0: } sl@0: #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: TInt expectedResult; sl@0: TInt attribute; sl@0: TPtrC expectedValue; sl@0: TBuf <200> value; sl@0: TInt result = KErrNone; sl@0: TPtrC uri; sl@0: TPtrC uniqueId; sl@0: sl@0: SetTestStepResult(EPass); sl@0: sl@0: GetIntFromConfig(ConfigSection(),_L("attribute"),attribute); sl@0: GetStringFromConfig(ConfigSection(),_L("uri"),uri); sl@0: GetStringFromConfig(ConfigSection(),_L("uniqueid"),uniqueId); sl@0: GetStringFromConfig(ConfigSection(),_L("value"),expectedValue); sl@0: GetIntFromConfig(ConfigSection(),_L("result"),expectedResult); sl@0: sl@0: __UHEAP_MARK; sl@0: CContent *content = CContent::NewLC(uri); sl@0: CData *data = content->OpenContentL(EPeek, uniqueId); sl@0: result = data->GetStringAttribute(attribute, value); sl@0: delete data; sl@0: if(result != expectedResult) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF3(_L("CData::GetStringAttribute() Expected result: %d, actual result: %d"), expectedResult, result); sl@0: } sl@0: if(value != expectedValue) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF3(_L("CData::GetStringAttribute() Expected value: %S, actual result: %S"), &expectedValue, &value); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(content); sl@0: sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /* sl@0: * Data StringAttributeSet step sl@0: * sl@0: */ sl@0: sl@0: CCAFDataStringAttributeSetStep::~CCAFDataStringAttributeSetStep() sl@0: { sl@0: } sl@0: sl@0: CCAFDataStringAttributeSetStep::CCAFDataStringAttributeSetStep(CCAFServer& aParent) : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFDataStringAttributeSetStep); sl@0: } sl@0: sl@0: TVerdict CCAFDataStringAttributeSetStep::doTestStepL() sl@0: { sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: TBool wmdrmFlag = EFalse; sl@0: GetBoolFromConfig(ConfigSection(),_L("wmdrmEnabled"), wmdrmFlag); sl@0: sl@0: if(wmdrmFlag) sl@0: { sl@0: TVerdict verdict = doWmdrmTestStepL(); sl@0: return verdict; sl@0: } sl@0: #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: TPtrC expectedValue1; sl@0: TPtrC expectedValue2; sl@0: TBuf <200> value1; sl@0: TBuf <200> value2; sl@0: TInt attribute1; sl@0: TInt attribute2; sl@0: TInt result = KErrNone; sl@0: TInt result1; sl@0: TInt result2; sl@0: TPtrC uri; sl@0: TPtrC uniqueId; sl@0: sl@0: SetTestStepResult(EPass); sl@0: sl@0: GetStringFromConfig(ConfigSection(),_L("uri"),uri); sl@0: GetStringFromConfig(ConfigSection(),_L("uniqueid"),uniqueId); sl@0: GetIntFromConfig(ConfigSection(),_L("attribute1"),attribute1); sl@0: GetIntFromConfig(ConfigSection(),_L("attribute2"),attribute2); sl@0: GetStringFromConfig(ConfigSection(),_L("value1"),expectedValue1); sl@0: GetStringFromConfig(ConfigSection(),_L("value2"),expectedValue2); sl@0: GetIntFromConfig(ConfigSection(),_L("result1"),result1); sl@0: GetIntFromConfig(ConfigSection(),_L("result2"),result2); sl@0: sl@0: __UHEAP_MARK; sl@0: CContent *content = CContent::NewLC(uri); sl@0: RStringAttributeSet attributeSet; sl@0: CleanupClosePushL(attributeSet); sl@0: attributeSet.AddL(attribute1); sl@0: attributeSet.AddL(attribute2); sl@0: sl@0: CData *data = content->OpenContentL(EPeek, uniqueId); sl@0: result = data->GetStringAttributeSet(attributeSet); sl@0: delete data; sl@0: if(result != KErrNone) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF1(_L("CData::GetAttribute() failed")); sl@0: } sl@0: if(result1 != attributeSet.GetValue(attribute1, value1)) sl@0: { sl@0: INFO_PRINTF1(_L("RStringAttributeSet::GetValue failed")); sl@0: } sl@0: if(result2 != attributeSet.GetValue(attribute2, value2)) sl@0: { sl@0: INFO_PRINTF1(_L("RStringAttributeSet::GetValue failed")); sl@0: } sl@0: if( value1 != expectedValue1 || value2 != expectedValue2 || attributeSet.Count() != 2) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: INFO_PRINTF1(_L("CData::GetAttributeSet() values don't match expected values")); sl@0: } sl@0: CleanupStack::PopAndDestroy(&attributeSet); sl@0: CleanupStack::PopAndDestroy(content); sl@0: sl@0: sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: CCAFExecuteIntentStep::~CCAFExecuteIntentStep() sl@0: { sl@0: } sl@0: sl@0: CCAFExecuteIntentStep::CCAFExecuteIntentStep(CCAFServer& aParent) sl@0: : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFSizeStep); sl@0: } sl@0: sl@0: TVerdict CCAFExecuteIntentStep::doTestStepL() sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: SetTestStepResult(EInconclusive); sl@0: sl@0: INFO_PRINTF1(_L("Execute Intent Test")); sl@0: sl@0: TPtrC fileName; sl@0: TPtrC uniqueId; sl@0: TInt intent = EPeek; sl@0: TInt expectedResult = KErrNone; sl@0: sl@0: GetStringFromConfig(ConfigSection(),_L("FileName"),fileName); sl@0: GetStringFromConfig(ConfigSection(),_L("UniqueId"),uniqueId); sl@0: GetIntFromConfig(ConfigSection(),_L("Intent"),intent); sl@0: GetIntFromConfig(ConfigSection(),_L("ExpectedResult"),expectedResult); sl@0: sl@0: INFO_PRINTF3(_L("Creating CData object with filename: %S, UniqueId: %S"), &fileName, &uniqueId); sl@0: sl@0: CData* data = NULL; sl@0: sl@0: TRAPD(err, data = CData::NewL(TVirtualPathPtr(fileName, uniqueId),static_cast(intent), EContentShareReadOnly)); sl@0: sl@0: if(err != expectedResult) sl@0: { sl@0: INFO_PRINTF2(_L("Unexpected result, EvaluateIntent() returned %d"), err); sl@0: } sl@0: else sl@0: { sl@0: SetTestStepResult(EPass); sl@0: if(err == KErrNone) sl@0: { sl@0: err = data->ExecuteIntent(static_cast(intent)); sl@0: if(err == KErrNone) sl@0: { sl@0: TBuf8 <128> buffer; sl@0: TInt length = 128; sl@0: sl@0: // read the entire content object sl@0: while(err == KErrNone && length > 0) sl@0: { sl@0: err = data->Read(buffer); sl@0: length = buffer.Length(); sl@0: } sl@0: if(err != KErrEof && err != KErrNone) sl@0: { sl@0: INFO_PRINTF2(_L("Unexpected error while reading content object: %d"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF2(_L("Unexpected error, EvaluteIntent succeeded but ExecuteIntent failed with error: %d"), err); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: delete data; sl@0: sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /* sl@0: * DRM File Open Performance Test Step sl@0: * sl@0: */ sl@0: sl@0: CCAFDRMFileOpenPerformanceTest::~CCAFDRMFileOpenPerformanceTest() sl@0: { sl@0: iIterationSum = 0; sl@0: } sl@0: sl@0: CCAFDRMFileOpenPerformanceTest::CCAFDRMFileOpenPerformanceTest(CCAFServer& aParent) : iParent(aParent) sl@0: { sl@0: SetTestStepName(KCAFDRMFileOpenPerformanceStep); sl@0: } sl@0: sl@0: TVerdict CCAFDRMFileOpenPerformanceTest::doTestStepL() sl@0: { sl@0: __UHEAP_MARK; sl@0: sl@0: INFO_PRINTF1(_L("DRM File Open Performance Test")); sl@0: sl@0: TPtrC inputFileName; sl@0: TInt maxValue = 0 ,iterCount = 0; sl@0: sl@0: GetStringFromConfig(ConfigSection(),_L("FileName"),inputFileName); sl@0: GetIntFromConfig(ConfigSection(),_L("IterationCount"),iterCount); sl@0: GetIntFromConfig(ConfigSection(),_L("MaxTimeLimitInMS"),maxValue); sl@0: sl@0: iIterationSum=0; sl@0: // iterated iterCount times to get the average time taken to open the file. sl@0: for (TInt i = 0; i < iterCount; ++i) sl@0: { sl@0: OpenAndReadFileContentL(inputFileName); sl@0: } sl@0: sl@0: TInt tickPeriod; sl@0: HAL::Get(HAL::ENanoTickPeriod, tickPeriod); sl@0: TInt nTickPeriodMS = tickPeriod / KCafTestSecToMS; sl@0: sl@0: TInt avgTimeForFileOpen = (iIterationSum * nTickPeriodMS) / iterCount; sl@0: if((avgTimeForFileOpen > maxValue)) sl@0: { sl@0: INFO_PRINTF1(_L("Performance Test failed.")); sl@0: SetTestStepResult(EFail); sl@0: } sl@0: sl@0: INFO_PRINTF2(_L("Expected maximum time to open DRM file in millisecs is : %d"), maxValue); sl@0: INFO_PRINTF2(_L("Obtained time in millisecs is: %d"), avgTimeForFileOpen); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: void CCAFDRMFileOpenPerformanceTest::OpenAndReadFileContentL(const TDesC& aFileName) sl@0: { sl@0: TPtrC uniqueIdentifier; sl@0: sl@0: GetStringFromConfig(ConfigSection(),_L("UniqueId"),uniqueIdentifier); sl@0: CContent *content = CContent::NewLC(aFileName); sl@0: CData *data = NULL; sl@0: TUint32 tickCounterValBeforeFileOpen, tickCounterValAfterFileOpen; sl@0: if(uniqueIdentifier.Length() > 0) sl@0: { sl@0: tickCounterValBeforeFileOpen = User::NTickCount(); sl@0: data = content->OpenContentL(EPeek,uniqueIdentifier); sl@0: tickCounterValAfterFileOpen = User::NTickCount(); sl@0: } sl@0: else sl@0: { sl@0: tickCounterValBeforeFileOpen = User::NTickCount(); sl@0: data = content->OpenContentL(EPeek); sl@0: tickCounterValAfterFileOpen = User::NTickCount(); sl@0: } sl@0: delete data; sl@0: // finished with Data object sl@0: CleanupStack::PopAndDestroy(content); sl@0: iIterationSum += tickCounterValAfterFileOpen - tickCounterValBeforeFileOpen; sl@0: } sl@0: sl@0: #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT sl@0: sl@0: CWmdrmCAFContentStep::~CWmdrmCAFContentStep() sl@0: { sl@0: } sl@0: sl@0: CWmdrmCAFContentStep::CWmdrmCAFContentStep() sl@0: { sl@0: SetTestStepName(KWmdrmCAFContentStep); sl@0: } sl@0: sl@0: sl@0: TVerdict CWmdrmCAFContentStep::doTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: TBool protectedVal; sl@0: GetBoolFromConfig(ConfigSection(),_L("attribValue1"), protectedVal); sl@0: TBool forwardable; sl@0: GetBoolFromConfig(ConfigSection(),_L("attribValue2"), forwardable); sl@0: sl@0: TBool headerDataPresent = ETrue; sl@0: GetBoolFromConfig(ConfigSection(),_L("headerDataFlag"), headerDataPresent); sl@0: sl@0: INFO_PRINTF1(_L("Verify CContent APIs for WMDRM content")); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: CContent* content = NULL; sl@0: sl@0: // this condition verifies that CContent construction leaves with KErrMissingWmdrmHeaderData, sl@0: // when no header data is provided. sl@0: if(!headerDataPresent) sl@0: { sl@0: content = CContent::NewL(KNullDesC8()); sl@0: return EPass; sl@0: } sl@0: sl@0: // create a dummy header data. sl@0: HBufC8* headerData = CreateWmdrmHeaderLC(); sl@0: sl@0: // Open a file and retrieve the attributes. sl@0: // If headerDataPresent is false, the code will never reach here.s sl@0: content = CContent::NewL(*headerData); sl@0: CleanupStack::PushL(content); sl@0: CAttribute* attrs = content->NewAttributeL(ETrue); sl@0: CleanupStack::PushL(attrs); sl@0: sl@0: TBool value1 = attrs->ResponseSet().IsSet(EIsProtected); sl@0: TBool value2 = attrs->ResponseSet().IsSet(EIsForwardable); sl@0: if(value1 == protectedVal && value2 == forwardable) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(3, headerData); sl@0: sl@0: __UHEAP_MARKEND; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: CWmdrmCAFDataStep::~CWmdrmCAFDataStep() sl@0: { sl@0: } sl@0: sl@0: CWmdrmCAFDataStep::CWmdrmCAFDataStep() sl@0: { sl@0: SetTestStepName(KWmdrmCAFDataStep); sl@0: } sl@0: sl@0: TVerdict CWmdrmCAFDataStep::doTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: TInt attribute; sl@0: TInt expectedValue = KErrNone; sl@0: sl@0: GetIntFromConfig(ConfigSection(),_L("attribute"), attribute); sl@0: GetIntFromConfig(ConfigSection(),_L("value"), expectedValue); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: HBufC8* headerData = CreateWmdrmHeaderLC(); sl@0: sl@0: CContent *content = CContent::NewLC(*headerData); sl@0: CData *data = content->OpenContentL(EPeek); sl@0: TInt value = KErrNone; sl@0: User::LeaveIfError(data->GetAttribute(attribute, value)); sl@0: delete data; sl@0: sl@0: if(expectedValue == value) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("CData::GetAttribute() Expected value: %d, actual value: %d"), expectedValue, value); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2, headerData); sl@0: __UHEAP_MARKEND; sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: CWmdrmCAFReadStep::~CWmdrmCAFReadStep() sl@0: { sl@0: } sl@0: sl@0: CWmdrmCAFReadStep::CWmdrmCAFReadStep() sl@0: { sl@0: SetTestStepName(KWmdrmCAFReadStep); sl@0: } sl@0: sl@0: sl@0: TVerdict CWmdrmCAFReadStep::doTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: TBool synchronous = EFalse; sl@0: GetBoolFromConfig(ConfigSection(),_L("synchronous"), synchronous); sl@0: TBool intent = EFalse; sl@0: GetBoolFromConfig(ConfigSection(),_L("intent"), intent); sl@0: TPtrC inputPacket; sl@0: GetStringFromConfig(ConfigSection(),_L("inputPacket"), inputPacket); sl@0: TPtrC expectedOutput; sl@0: GetStringFromConfig(ConfigSection(),_L("outputPacket"), expectedOutput); sl@0: sl@0: __UHEAP_MARK; sl@0: TPtrC header; sl@0: HBufC8* headerData = NULL; sl@0: sl@0: if(GetStringFromConfig(ConfigSection(),_L("header"), header)) sl@0: { sl@0: headerData = ConvertDes16toHBufC8LC(header); sl@0: } sl@0: else sl@0: { sl@0: headerData = CreateWmdrmHeaderLC(); sl@0: } sl@0: sl@0: TInt result = 0; sl@0: if(!synchronous) sl@0: { sl@0: result = TestAsynchronousReadL(*headerData, intent, inputPacket, expectedOutput); sl@0: } sl@0: else sl@0: { sl@0: result = TestSynchronousReadL(*headerData, intent, inputPacket, expectedOutput); sl@0: } sl@0: sl@0: if(result == KErrNone) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(headerData); sl@0: __UHEAP_MARKEND; sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: TInt CWmdrmCAFReadStep::TestSynchronousReadL(const TDesC8& aHeaderData, TBool aIntent, TDesC& aInputPacket, TDesC& aExpectedOutput) sl@0: { sl@0: __UHEAP_MARK; sl@0: CData* data = NULL; sl@0: TInt returnVal = KErrGeneral; sl@0: sl@0: if(aIntent) sl@0: { sl@0: data = CData::NewL(aHeaderData, EPeek); sl@0: } sl@0: else sl@0: { sl@0: data = CData::NewL(aHeaderData); sl@0: } sl@0: sl@0: CleanupStack::PushL(data); sl@0: sl@0: if(aInputPacket.Length() <= 0) sl@0: { sl@0: // dummy output buffer.This loop essentially tests the error condition KErrInsufficientDataPacketLength. sl@0: TBuf8<2> outputBuffer; sl@0: User::LeaveIfError(data->Read(KNullDesC8(), outputBuffer)); sl@0: } sl@0: sl@0: else sl@0: { sl@0: HBufC8* inputPacket = ConvertDes16toHBufC8LC(aInputPacket); sl@0: HBufC8* outputPacket = HBufC8::NewLC(aInputPacket.Length()); sl@0: TPtr8 outputPacketPtr = outputPacket->Des(); sl@0: sl@0: User::LeaveIfError(data->Read(*inputPacket, outputPacketPtr)); sl@0: HBufC8* expectedOutput = ConvertDes16toHBufC8LC(aExpectedOutput); sl@0: if(expectedOutput->Compare(*outputPacket) == KErrNone) sl@0: { sl@0: returnVal = KErrNone; sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(3, inputPacket); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(data); sl@0: __UHEAP_MARKEND; sl@0: sl@0: return returnVal; sl@0: } sl@0: sl@0: TInt CWmdrmCAFReadStep::TestAsynchronousReadL(const TDesC8& aHeaderData, TBool aIntent, TDesC& aInputPacket, TDesC& aExpectedOutput) sl@0: { sl@0: __UHEAP_MARK; sl@0: CData* data = NULL; sl@0: TInt returnVal = KErrGeneral; sl@0: sl@0: if(aIntent) sl@0: { sl@0: data = CData::NewL(aHeaderData, EPeek); sl@0: } sl@0: else sl@0: { sl@0: data = CData::NewL(aHeaderData); sl@0: } sl@0: sl@0: CleanupStack::PushL(data); sl@0: sl@0: if(aInputPacket.Length() <= 0) sl@0: { sl@0: TBuf8<2> outputBuffer; sl@0: User::LeaveIfError(data->Read(KNullDesC8(), outputBuffer)); sl@0: } sl@0: sl@0: else sl@0: { sl@0: HBufC8* inputPacket = ConvertDes16toHBufC8LC(aInputPacket); sl@0: HBufC8* outputPacket = HBufC8::NewLC(aInputPacket.Length()); sl@0: TPtr8 outputPacketPtr = outputPacket->Des(); sl@0: sl@0: TRequestStatus status; sl@0: data->Read(*inputPacket, outputPacketPtr, status); sl@0: User::WaitForRequest(status); sl@0: sl@0: if(status.Int() != KErrNone) sl@0: { sl@0: CleanupStack::PopAndDestroy(3, data); sl@0: return status.Int(); sl@0: } sl@0: sl@0: HBufC8* expectedOutput = ConvertDes16toHBufC8LC(aExpectedOutput); sl@0: if(expectedOutput->Compare(*outputPacket) == KErrNone) sl@0: { sl@0: returnVal = KErrNone; sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(3, inputPacket); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(data); sl@0: __UHEAP_MARKEND; sl@0: sl@0: return returnVal; sl@0: } sl@0: sl@0: TVerdict CCAFDataAttributeStep::doWmdrmTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: TInt attribVal; sl@0: GetIntFromConfig(ConfigSection(),_L("attribute"), attribVal); sl@0: sl@0: TInt expectedValue; sl@0: GetIntFromConfig(ConfigSection(),_L("value"), expectedValue); sl@0: sl@0: __UHEAP_MARK; sl@0: TPtrC header; sl@0: HBufC8* headerData = NULL; sl@0: sl@0: if(GetStringFromConfig(ConfigSection(),_L("header"), header)) sl@0: { sl@0: headerData = ConvertDes16toHBufC8LC(header); sl@0: } sl@0: else sl@0: { sl@0: headerData = CreateWmdrmHeaderLC(); sl@0: } sl@0: sl@0: CContent *content = CContent::NewLC(*headerData); sl@0: CData *data = content->OpenContentL(EPeek); sl@0: TInt value; sl@0: User::LeaveIfError(data->GetAttribute(attribVal, value)); sl@0: delete data; sl@0: sl@0: if(expectedValue == value) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("CData::GetAttribute() Expected value: %d, actual value: %d"), expectedValue, value); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2, headerData); sl@0: __UHEAP_MARKEND; sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: TVerdict CCAFDataAttributeSetStep::doWmdrmTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: TInt attribute1; sl@0: GetIntFromConfig(ConfigSection(),_L("attribute1"),attribute1); sl@0: sl@0: TInt attribute2; sl@0: GetIntFromConfig(ConfigSection(),_L("attribute2"),attribute2); sl@0: sl@0: TInt expectedValue1; sl@0: GetIntFromConfig(ConfigSection(),_L("value1"),expectedValue1); sl@0: sl@0: TInt expectedValue2; sl@0: GetIntFromConfig(ConfigSection(),_L("value2"),expectedValue2); sl@0: sl@0: __UHEAP_MARK; sl@0: sl@0: TPtrC header; sl@0: HBufC8* headerData = NULL; sl@0: sl@0: if(GetStringFromConfig(ConfigSection(),_L("header"), header)) sl@0: { sl@0: headerData = ConvertDes16toHBufC8LC(header); sl@0: } sl@0: else sl@0: { sl@0: headerData = CreateWmdrmHeaderLC(); sl@0: } sl@0: sl@0: CContent *content = CContent::NewLC(*headerData); sl@0: CData *data = content->OpenContentL(EPeek); sl@0: sl@0: RAttributeSet attributeSet; sl@0: CleanupClosePushL(attributeSet); sl@0: attributeSet.AddL(attribute1); sl@0: attributeSet.AddL(attribute2); sl@0: sl@0: TInt result = data->GetAttributeSet(attributeSet); sl@0: delete data; sl@0: sl@0: if(result == KErrNone) sl@0: { sl@0: TInt value1; sl@0: User::LeaveIfError(attributeSet.GetValue(attribute1, value1)); sl@0: sl@0: TInt value2; sl@0: User::LeaveIfError(attributeSet.GetValue(attribute2, value2)); sl@0: sl@0: if(expectedValue1 == value1 && expectedValue2 == value2 && attributeSet.Count() == 2) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("CData::GetAttributeSet() values don't match expected values")); sl@0: } sl@0: } sl@0: sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("CData::GetAttributeSet() failed")); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(3, headerData); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: TVerdict CCAFDataStringAttributeStep::doWmdrmTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: TInt attribVal; sl@0: GetIntFromConfig(ConfigSection(),_L("attribute"),attribVal); sl@0: sl@0: TPtrC expectedValue; sl@0: GetStringFromConfig(ConfigSection(),_L("value"),expectedValue); sl@0: sl@0: TInt expectedResult; sl@0: GetIntFromConfig(ConfigSection(),_L("result"),expectedResult); sl@0: sl@0: __UHEAP_MARK; sl@0: TPtrC header; sl@0: HBufC8* headerData = NULL; sl@0: sl@0: if(GetStringFromConfig(ConfigSection(),_L("header"), header)) sl@0: { sl@0: headerData = ConvertDes16toHBufC8LC(header); sl@0: } sl@0: else sl@0: { sl@0: headerData = CreateWmdrmHeaderLC(); sl@0: } sl@0: sl@0: CContent *content = CContent::NewLC(*headerData); sl@0: CData *data = content->OpenContentL(EPeek); sl@0: sl@0: TBuf <200> value; sl@0: TInt result = data->GetStringAttribute(attribVal, value); sl@0: delete data; sl@0: sl@0: if(result == expectedResult && value == expectedValue) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("CData::GetStringAttribute() Expected result: %d, actual result: %d"), expectedResult, result); sl@0: INFO_PRINTF3(_L("CData::GetStringAttribute() Expected value: %S, actual value: %S"), &expectedValue, &value); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2, headerData); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: sl@0: TVerdict CCAFDataStringAttributeSetStep::doWmdrmTestStepL() sl@0: { sl@0: SetTestStepResult(EFail); sl@0: sl@0: TInt attribute1; sl@0: GetIntFromConfig(ConfigSection(),_L("attribute1"),attribute1); sl@0: sl@0: TInt attribute2; sl@0: GetIntFromConfig(ConfigSection(),_L("attribute2"),attribute2); sl@0: sl@0: TPtrC expectedValue1; sl@0: GetStringFromConfig(ConfigSection(),_L("value1"),expectedValue1); sl@0: sl@0: TPtrC expectedValue2; sl@0: GetStringFromConfig(ConfigSection(),_L("value2"),expectedValue2); sl@0: sl@0: __UHEAP_MARK; sl@0: TPtrC header; sl@0: HBufC8* headerData = NULL; sl@0: sl@0: if(GetStringFromConfig(ConfigSection(),_L("header"), header)) sl@0: { sl@0: headerData = ConvertDes16toHBufC8LC(header); sl@0: } sl@0: else sl@0: { sl@0: headerData = CreateWmdrmHeaderLC(); sl@0: } sl@0: sl@0: CContent *content = CContent::NewLC(*headerData); sl@0: CData *data = content->OpenContentL(EPeek); sl@0: sl@0: RStringAttributeSet attributeSet; sl@0: CleanupClosePushL(attributeSet); sl@0: attributeSet.AddL(attribute1); sl@0: attributeSet.AddL(attribute2); sl@0: sl@0: TInt result = data->GetStringAttributeSet(attributeSet); sl@0: delete data; sl@0: sl@0: TBuf <200> value1; sl@0: TBuf <200> value2; sl@0: if(result == KErrNone) sl@0: { sl@0: TInt result3 = attributeSet.GetValue(attribute1, value1); sl@0: TInt result4 = attributeSet.GetValue(attribute2, value2); sl@0: sl@0: if(value1 == expectedValue1 && value2 == expectedValue2 && attributeSet.Count() == 2 sl@0: && result3 == KErrNone && result4 == KErrNone) sl@0: { sl@0: SetTestStepResult(EPass); sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF3(_L("RStringAttributeSet::GetValue() for attribute1.Expected value: %S, actual value: %S"), &expectedValue1, &value1); sl@0: INFO_PRINTF3(_L("RStringAttributeSet::GetValue() for attribute2.Expected value: %S, actual value: %S"), &expectedValue2, &value2); sl@0: INFO_PRINTF3(_L("RStringAttributeSet::GetValue() for attribute1. Expected result: %d, actual result: %d"), 0, result3); sl@0: INFO_PRINTF3(_L("RStringAttributeSet::GetValue() for attribute2. Expected result: %d, actual result: %d"), 0, result4); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1(_L("CData::GetStringAttributeSet() failed")); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(3, headerData); sl@0: sl@0: __UHEAP_MARKEND; sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT