os/security/authorisation/userpromptservice/policies/test/tupspolicies/source/util.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2007-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 #include "util.h"
    20 
    21 using namespace UserPromptService;
    22 
    23 const TDesC& OptionToString(CPolicy::TOptions aOption)
    24 	{
    25 	switch (aOption)
    26 		{
    27 		case CPolicy::EYes:
    28 			_LIT(KYes, "Yes");
    29 			return KYes;
    30 		case CPolicy::ENo:
    31 			_LIT(KNo, "No");
    32 			return KNo;
    33 		case CPolicy::ESessionYes:
    34 			_LIT(KSessionYes, "SessionYes");
    35 			return KSessionYes;
    36 		case CPolicy::ESessionNo:
    37 			_LIT(KSessionNo, "SessionNo");
    38 			return KSessionNo;
    39 		case CPolicy::EAlways:
    40 			_LIT(KAlways, "Always");
    41 			return KAlways;
    42 		case CPolicy::ENever:
    43 			_LIT(KNever, "Never");
    44 			return KNever;
    45 		default:		
    46 			_LIT(KUnknown, "Unknown");
    47 			return KUnknown;
    48 		}	
    49 	}
    50 
    51 TInt StringToOptionL(const TDesC& aString)
    52 	{
    53 	if (aString.MatchF(_L("yes")))
    54 		return CPolicy::EYes;
    55 	else if (aString.MatchF(_L("no")))
    56 		return CPolicy::ENo;
    57 	else if (aString.MatchF(_L("session")))
    58 		return CPolicy::ESessionYes;
    59 	else if (aString.MatchF(_L("sessionyes")))
    60 		return CPolicy::ESessionYes;
    61 	else if (aString.MatchF(_L("sessionno")))
    62 		return CPolicy::ESessionNo;
    63 	else if (aString.MatchF(_L("always")))
    64 		return CPolicy::EAlways;
    65 	else if (aString.MatchF(_L("never")))
    66 		return CPolicy::ENever;	
    67 	
    68 	User::Leave(KErrGeneral);
    69 	/*lint -unreachable*/
    70 	return 0;
    71 	}
    72 	
    73 TBool CheckExpectedError(CTestExecuteLogger& aLogger, TInt aExpected, TInt aActual)
    74 /**
    75 Compares the expected and the actual error and logs the result.
    76 @param aExpected 	The expected error code.
    77 @param aActual 		The actual error.
    78 @return ETrue, if the expected and actual errors matched; otherwise, EFalse is returned.
    79 */
    80 	{
    81 	if (aActual == KErrNone && aExpected == KErrNone)
    82 		{
    83 		aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, 
    84 			_L("Passed - no error"));
    85 		return ETrue;
    86 		}
    87 	else if (aActual == aExpected)
    88 		{
    89 		aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrInfo, 
    90 			_L("Encountered expected error %d"), aActual);
    91 		return ETrue;
    92 		}
    93 	else if (aActual == KErrNone)
    94 		{
    95 		aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, 
    96 			_L("Did not encounter expected error %d"), aExpected);
    97 		return EFalse;
    98 		}
    99 	else 
   100 		{
   101 		aLogger.LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, 
   102 			_L("Unexpected error %d"), aActual);
   103 		return EFalse;
   104 		}	
   105 	}