os/graphics/windowing/windowserver/test/tdynamicres/inc/teflogextensions.h
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) 2008-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 "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 * @file
    16 * 
    17 *
    18 */
    19 
    20 
    21 
    22 #ifndef __TEF_LOG_EXTENSIONS__
    23 #define __TEF_LOG_EXTENSIONS__
    24 
    25 #include <test/tefunit.h>
    26 
    27 /*
    28 This file contains extensions to the TEF macros used for logging, defined in
    29 tefunit.h.
    30 */
    31 
    32 /*
    33 Wrapper to check for an error, then print it and leave with it if not KErrNone.
    34 do ... while (0) ensures the macro can be treated like a single statement. A
    35 macro is used to get the line number information.
    36 Note that p1 will be evaluated once and only once.
    37 */
    38 #define PRINT_ON_ERROR2_L(test, p1, p2)	\
    39 	do \
    40 		{ \
    41 		TInt result = (test); \
    42 		if (result != KErrNone) \
    43 			{ \
    44 			Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2)); \
    45 			User::Leave(result); \
    46 			} \
    47 		} \
    48 	while (0)
    49 
    50 #define PRINT_ON_ERROR3_L(test, p1, p2, p3)	\
    51 	do \
    52 		{ \
    53 		TInt result = (test); \
    54 		if (result != KErrNone) \
    55 			{ \
    56 			Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, (p1), (p2), (p3)); \
    57 			User::Leave(result); \
    58 			} \
    59 		} \
    60 	while (0)
    61 
    62 /*
    63 Modified version of ASSERT_EQUALS() that will log the expression tested, the
    64 expected result and the actual one.
    65 */
    66 #define ASSERT_CONDITION(c)	_LIT(KExpression, c);
    67 
    68 #define ASSERT_EQUALS_X(aExpression, aExpected) \
    69 	do \
    70 		{ \
    71 		TInt result = (TInt)(aExpression); \
    72 		TInt expected = (TInt)(aExpected); \
    73 		if (result != expected) \
    74 			{ \
    75 			ASSERT_CONDITION(#aExpression); \
    76 			Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, _L("%S == %d, not %d"), &KExpression(), result, expected ); \
    77 			User::Leave(KErrTEFUnitFail); \
    78 			} \
    79 		} \
    80 	while (0)
    81 
    82 #define ASSERT_NOT_EQUALS_X(aExpression, aUnexpected) \
    83 	do \
    84 		{ \
    85 		TInt result = (TInt)(aExpression); \
    86 		TInt unexpected = (TInt)(aUnexpected); \
    87 		if (result == unexpected) \
    88 			{ \
    89 			ASSERT_CONDITION(#aExpression); \
    90 			Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, _L("%S == %d, unexpectedly"), &KExpression(), result ); \
    91 			User::Leave(KErrTEFUnitFail); \
    92 			} \
    93 		} \
    94 	while (0)
    95 
    96 #define ASSERT_TRUE_X(aExpression) \
    97 	do \
    98 		{ \
    99 		TBool result = (TBool)(aExpression); \
   100 		if (!result) \
   101 			{ \
   102 			ASSERT_CONDITION(#aExpression); \
   103 			Logger().LogExtra(((TText8*)__FILE__), __LINE__, ESevrErr, _L("%S false"), &KExpression() ); \
   104 			User::Leave(KErrTEFUnitFail); \
   105 			} \
   106 		} \
   107 	while (0)
   108 
   109 #endif // __TEF_LOG_EXTENSIONS__
   110