os/security/authorisation/userpromptservice/policies/test/tupspolicies/source/util.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/authorisation/userpromptservice/policies/test/tupspolicies/source/util.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,105 @@
     1.4 +/*
     1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "util.h"
    1.23 +
    1.24 +using namespace UserPromptService;
    1.25 +
    1.26 +const TDesC& OptionToString(CPolicy::TOptions aOption)
    1.27 +	{
    1.28 +	switch (aOption)
    1.29 +		{
    1.30 +		case CPolicy::EYes:
    1.31 +			_LIT(KYes, "Yes");
    1.32 +			return KYes;
    1.33 +		case CPolicy::ENo:
    1.34 +			_LIT(KNo, "No");
    1.35 +			return KNo;
    1.36 +		case CPolicy::ESessionYes:
    1.37 +			_LIT(KSessionYes, "SessionYes");
    1.38 +			return KSessionYes;
    1.39 +		case CPolicy::ESessionNo:
    1.40 +			_LIT(KSessionNo, "SessionNo");
    1.41 +			return KSessionNo;
    1.42 +		case CPolicy::EAlways:
    1.43 +			_LIT(KAlways, "Always");
    1.44 +			return KAlways;
    1.45 +		case CPolicy::ENever:
    1.46 +			_LIT(KNever, "Never");
    1.47 +			return KNever;
    1.48 +		default:		
    1.49 +			_LIT(KUnknown, "Unknown");
    1.50 +			return KUnknown;
    1.51 +		}	
    1.52 +	}
    1.53 +
    1.54 +TInt StringToOptionL(const TDesC& aString)
    1.55 +	{
    1.56 +	if (aString.MatchF(_L("yes")))
    1.57 +		return CPolicy::EYes;
    1.58 +	else if (aString.MatchF(_L("no")))
    1.59 +		return CPolicy::ENo;
    1.60 +	else if (aString.MatchF(_L("session")))
    1.61 +		return CPolicy::ESessionYes;
    1.62 +	else if (aString.MatchF(_L("sessionyes")))
    1.63 +		return CPolicy::ESessionYes;
    1.64 +	else if (aString.MatchF(_L("sessionno")))
    1.65 +		return CPolicy::ESessionNo;
    1.66 +	else if (aString.MatchF(_L("always")))
    1.67 +		return CPolicy::EAlways;
    1.68 +	else if (aString.MatchF(_L("never")))
    1.69 +		return CPolicy::ENever;	
    1.70 +	
    1.71 +	User::Leave(KErrGeneral);
    1.72 +	/*lint -unreachable*/
    1.73 +	return 0;
    1.74 +	}
    1.75 +	
    1.76 +TBool CheckExpectedError(CTestExecuteLogger& aLogger, TInt aExpected, TInt aActual)
    1.77 +/**
    1.78 +Compares the expected and the actual error and logs the result.
    1.79 +@param aExpected 	The expected error code.
    1.80 +@param aActual 		The actual error.
    1.81 +@return ETrue, if the expected and actual errors matched; otherwise, EFalse is returned.
    1.82 +*/
    1.83 +	{
    1.84 +	if (aActual == KErrNone && aExpected == KErrNone)
    1.85 +		{
    1.86 +		aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, 
    1.87 +			_L("Passed - no error"));
    1.88 +		return ETrue;
    1.89 +		}
    1.90 +	else if (aActual == aExpected)
    1.91 +		{
    1.92 +		aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, 
    1.93 +			_L("Encountered expected error %d"), aActual);
    1.94 +		return ETrue;
    1.95 +		}
    1.96 +	else if (aActual == KErrNone)
    1.97 +		{
    1.98 +		aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, 
    1.99 +			_L("Did not encounter expected error %d"), aExpected);
   1.100 +		return EFalse;
   1.101 +		}
   1.102 +	else 
   1.103 +		{
   1.104 +		aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, 
   1.105 +			_L("Unexpected error %d"), aActual);
   1.106 +		return EFalse;
   1.107 +		}	
   1.108 +	}