os/security/cryptomgmtlibs/securitytestfw/test/captestframework/captestutility.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     5 * under the terms of the License "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     9 * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    11 *
    12 * Contributors:
    13 *
    14 * Description: 
    15 *
    16 */
    17 
    18 
    19 
    20 
    21 /**
    22  @file
    23 */
    24 
    25 #include "captestutility.h"
    26 
    27 // CDefaultCapabilityTest
    28 
    29 EXPORT_C CDefaultCapabilityTest::~CDefaultCapabilityTest()
    30 	{
    31 	delete iTestName;
    32 
    33 	if (iLogWriteStream)
    34 		{
    35 		iLogWriteStream->WriteInt32L(EFileEnd); // End marker
    36 		iLogWriteStream->Close();
    37 		delete iLogWriteStream;
    38 		iLogWriteStream=0;
    39 		}
    40 	}
    41 	
    42 EXPORT_C void CDefaultCapabilityTest::SetNameL(const TDesC& aName)
    43 	{
    44 	delete iTestName;
    45 	iTestName=0;
    46 	iTestName=HBufC::NewL(aName.Length());
    47 	TPtr testNamePtr=iTestName->Des();
    48 	testNamePtr.Copy(aName);
    49 	}
    50 
    51 EXPORT_C TInt CDefaultCapabilityTest::CheckFailL(TInt aResult, const TDesC& aTestName)
    52 	{
    53 	_LIT(KColourRed, "<font color=FF0000>");
    54 	_LIT(KColourGreen, "<font color=00AF00>");
    55 	_LIT(KFontEndColour, "</font>");
    56 	TBuf<1024> buf;
    57 	
    58 	if (iExpectPermissionDenied && aResult==KErrPermissionDenied)
    59 		{
    60 		buf.Format(_L("%S%S: Permission Denied,    Err=%d%S"), &KColourGreen, &aTestName, aResult, &KFontEndColour);
    61 		iLogWriteStream->WriteInt32L(ETestPassed);
    62 		*iLogWriteStream << buf;
    63 		return aResult;
    64 		}
    65 	else if (!iExpectPermissionDenied && aResult!=KErrPermissionDenied)
    66 		{
    67 		buf.Format(_L("%S%S: Succeeded,    Err=%d%S"), &KColourGreen, &aTestName, aResult, &KFontEndColour);
    68 		iLogWriteStream->WriteInt32L(ETestPassed);
    69 		*iLogWriteStream << buf;
    70 		return aResult;
    71 		}
    72 
    73 	// Test failed, do something with error.
    74 	if (aResult == KErrPermissionDenied)
    75 		{
    76 		buf.Format(_L("%S%S: Permission denied! (Unexpected),    Err=%d%S"), &KColourRed, &aTestName, aResult, &KFontEndColour);
    77 		iLogWriteStream->WriteInt32L(ETestFailed);
    78 		*iLogWriteStream << buf;
    79 		}
    80 	else
    81 		{
    82 		buf.Format(_L("%S%S: Succeeded! (Unexpected),    Err=%d%S"), &KColourRed, &aTestName, aResult, &KFontEndColour);
    83 		iLogWriteStream->WriteInt32L(ETestFailed);
    84 		*iLogWriteStream << buf;
    85 		}
    86 	
    87 	SetFail();
    88 	return aResult;
    89 	}
    90 
    91 EXPORT_C void CDefaultCapabilityTest::RunTestL(RFile& aLogFile)
    92 	{
    93 	// Setup logging
    94 	iLogFile=&aLogFile;
    95 	
    96 	if (iLogWriteStream)
    97 		{
    98 		iLogWriteStream->Close();
    99 		delete iLogWriteStream;
   100 		iLogWriteStream=0;
   101 		}
   102 	iLogWriteStream=new(ELeave) RFileWriteStream(aLogFile, 0);
   103 	
   104 	// run tests
   105 	RunTestL();
   106 
   107 	if (!iFail)
   108 		{
   109 		iLogWriteStream->WriteInt32L(ETestsEnded); // Test ended ok
   110 		}
   111 	}
   112 
   113 EXPORT_C const TDesC& CDefaultCapabilityTest::Name() const
   114 	{
   115 	if (iTestName)
   116 		{
   117 		return *iTestName;
   118 		}
   119 	return KNullDesC;
   120 	}
   121 
   122 EXPORT_C const TDesC& CDefaultCapabilityTest::SubName() const
   123 	{
   124 	if (iTestSubName)
   125 		{
   126 		return *iTestSubName;
   127 		}
   128 	return KNullDesC;
   129 	}
   130 
   131 EXPORT_C TCapabilitySet CDefaultCapabilityTest::CapabilitiesRequired() const
   132 	{
   133 	return iCapabilitySet;
   134 	}
   135 
   136 EXPORT_C TUid CDefaultCapabilityTest::VidRequired() const
   137 	{
   138 	return iVidRequired;
   139 	}
   140 	
   141 EXPORT_C TUid CDefaultCapabilityTest::SidRequired() const
   142 	{
   143 	return iSidRequired;
   144 	}
   145 
   146 EXPORT_C void CDefaultCapabilityTest::SetCapabilityRequired(const TCapability& aCapability)
   147 	{
   148 	iCapabilitySet.AddCapability(aCapability);
   149 	}
   150 
   151 EXPORT_C void CDefaultCapabilityTest::SetSidRequired(const TUid& aSid)
   152 	{
   153 	iSidRequired=aSid;
   154 	}
   155 	
   156 EXPORT_C void CDefaultCapabilityTest::SetVidRequired(const TUid& aVid)
   157 	{
   158 	iVidRequired=aVid;
   159 	}
   160 
   161 // CDefaultCapabilityTestFactory
   162 EXPORT_C MCapabilityTest* CDefaultCapabilityTestFactory::Test(TInt aTestNumber)
   163 	{
   164 	return iTests[aTestNumber];
   165 	}
   166 
   167 EXPORT_C TInt CDefaultCapabilityTestFactory::NumberOfTests()
   168 	{
   169 	return iTests.Count();
   170 	}
   171 	
   172 EXPORT_C void CDefaultCapabilityTestFactory::AddTestL(CDefaultCapabilityTest* aTest)
   173 	{
   174 	iTests.AppendL(aTest);
   175 	}
   176 
   177 
   178 EXPORT_C CDefaultCapabilityTestFactory::~CDefaultCapabilityTestFactory()
   179 	{
   180 	for (TInt i=0; i< iTests.Count(); ++i)
   181 		{
   182 		delete iTests[i];
   183 		}
   184 	iTests.Reset();
   185 	}
   186