sl@0: /* sl@0: * Copyright (c) 2005-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: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include "captestutility.h" sl@0: sl@0: // CDefaultCapabilityTest sl@0: sl@0: EXPORT_C CDefaultCapabilityTest::~CDefaultCapabilityTest() sl@0: { sl@0: delete iTestName; sl@0: sl@0: if (iLogWriteStream) sl@0: { sl@0: iLogWriteStream->WriteInt32L(EFileEnd); // End marker sl@0: iLogWriteStream->Close(); sl@0: delete iLogWriteStream; sl@0: iLogWriteStream=0; sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CDefaultCapabilityTest::SetNameL(const TDesC& aName) sl@0: { sl@0: delete iTestName; sl@0: iTestName=0; sl@0: iTestName=HBufC::NewL(aName.Length()); sl@0: TPtr testNamePtr=iTestName->Des(); sl@0: testNamePtr.Copy(aName); sl@0: } sl@0: sl@0: EXPORT_C TInt CDefaultCapabilityTest::CheckFailL(TInt aResult, const TDesC& aTestName) sl@0: { sl@0: _LIT(KColourRed, ""); sl@0: _LIT(KColourGreen, ""); sl@0: _LIT(KFontEndColour, ""); sl@0: TBuf<1024> buf; sl@0: sl@0: if (iExpectPermissionDenied && aResult==KErrPermissionDenied) sl@0: { sl@0: buf.Format(_L("%S%S: Permission Denied, Err=%d%S"), &KColourGreen, &aTestName, aResult, &KFontEndColour); sl@0: iLogWriteStream->WriteInt32L(ETestPassed); sl@0: *iLogWriteStream << buf; sl@0: return aResult; sl@0: } sl@0: else if (!iExpectPermissionDenied && aResult!=KErrPermissionDenied) sl@0: { sl@0: buf.Format(_L("%S%S: Succeeded, Err=%d%S"), &KColourGreen, &aTestName, aResult, &KFontEndColour); sl@0: iLogWriteStream->WriteInt32L(ETestPassed); sl@0: *iLogWriteStream << buf; sl@0: return aResult; sl@0: } sl@0: sl@0: // Test failed, do something with error. sl@0: if (aResult == KErrPermissionDenied) sl@0: { sl@0: buf.Format(_L("%S%S: Permission denied! (Unexpected), Err=%d%S"), &KColourRed, &aTestName, aResult, &KFontEndColour); sl@0: iLogWriteStream->WriteInt32L(ETestFailed); sl@0: *iLogWriteStream << buf; sl@0: } sl@0: else sl@0: { sl@0: buf.Format(_L("%S%S: Succeeded! (Unexpected), Err=%d%S"), &KColourRed, &aTestName, aResult, &KFontEndColour); sl@0: iLogWriteStream->WriteInt32L(ETestFailed); sl@0: *iLogWriteStream << buf; sl@0: } sl@0: sl@0: SetFail(); sl@0: return aResult; sl@0: } sl@0: sl@0: EXPORT_C void CDefaultCapabilityTest::RunTestL(RFile& aLogFile) sl@0: { sl@0: // Setup logging sl@0: iLogFile=&aLogFile; sl@0: sl@0: if (iLogWriteStream) sl@0: { sl@0: iLogWriteStream->Close(); sl@0: delete iLogWriteStream; sl@0: iLogWriteStream=0; sl@0: } sl@0: iLogWriteStream=new(ELeave) RFileWriteStream(aLogFile, 0); sl@0: sl@0: // run tests sl@0: RunTestL(); sl@0: sl@0: if (!iFail) sl@0: { sl@0: iLogWriteStream->WriteInt32L(ETestsEnded); // Test ended ok sl@0: } sl@0: } sl@0: sl@0: EXPORT_C const TDesC& CDefaultCapabilityTest::Name() const sl@0: { sl@0: if (iTestName) sl@0: { sl@0: return *iTestName; sl@0: } sl@0: return KNullDesC; sl@0: } sl@0: sl@0: EXPORT_C const TDesC& CDefaultCapabilityTest::SubName() const sl@0: { sl@0: if (iTestSubName) sl@0: { sl@0: return *iTestSubName; sl@0: } sl@0: return KNullDesC; sl@0: } sl@0: sl@0: EXPORT_C TCapabilitySet CDefaultCapabilityTest::CapabilitiesRequired() const sl@0: { sl@0: return iCapabilitySet; sl@0: } sl@0: sl@0: EXPORT_C TUid CDefaultCapabilityTest::VidRequired() const sl@0: { sl@0: return iVidRequired; sl@0: } sl@0: sl@0: EXPORT_C TUid CDefaultCapabilityTest::SidRequired() const sl@0: { sl@0: return iSidRequired; sl@0: } sl@0: sl@0: EXPORT_C void CDefaultCapabilityTest::SetCapabilityRequired(const TCapability& aCapability) sl@0: { sl@0: iCapabilitySet.AddCapability(aCapability); sl@0: } sl@0: sl@0: EXPORT_C void CDefaultCapabilityTest::SetSidRequired(const TUid& aSid) sl@0: { sl@0: iSidRequired=aSid; sl@0: } sl@0: sl@0: EXPORT_C void CDefaultCapabilityTest::SetVidRequired(const TUid& aVid) sl@0: { sl@0: iVidRequired=aVid; sl@0: } sl@0: sl@0: // CDefaultCapabilityTestFactory sl@0: EXPORT_C MCapabilityTest* CDefaultCapabilityTestFactory::Test(TInt aTestNumber) sl@0: { sl@0: return iTests[aTestNumber]; sl@0: } sl@0: sl@0: EXPORT_C TInt CDefaultCapabilityTestFactory::NumberOfTests() sl@0: { sl@0: return iTests.Count(); sl@0: } sl@0: sl@0: EXPORT_C void CDefaultCapabilityTestFactory::AddTestL(CDefaultCapabilityTest* aTest) sl@0: { sl@0: iTests.AppendL(aTest); sl@0: } sl@0: sl@0: sl@0: EXPORT_C CDefaultCapabilityTestFactory::~CDefaultCapabilityTestFactory() sl@0: { sl@0: for (TInt i=0; i< iTests.Count(); ++i) sl@0: { sl@0: delete iTests[i]; sl@0: } sl@0: iTests.Reset(); sl@0: } sl@0: