applayerpluginsandutils/uripermissionservices/Test/testutils.cpp
changeset 0 b16258d2340f
equal deleted inserted replaced
-1:000000000000 0:b16258d2340f
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "testutils.h"
       
    17 
       
    18 CTestWrapper* CTestWrapper::NewLC(RTest& aTester)
       
    19 	{
       
    20 	CTestWrapper* self = new (ELeave) CTestWrapper(aTester);
       
    21 	CleanupStack::PushL(self);
       
    22 	return self;
       
    23 	}
       
    24 
       
    25 CTestWrapper::CTestWrapper(RTest& aTester) : iTester(aTester)
       
    26 	{
       
    27 	}
       
    28 
       
    29 CTestWrapper::~CTestWrapper()
       
    30 	{
       
    31 	iTester.Close();
       
    32 	}
       
    33 
       
    34 void CTestWrapper::Start(const TDesC& aHeading)
       
    35 	{
       
    36 	iTester.Start(aHeading);
       
    37 	iTestCount = 1;
       
    38 	iCheckCount = 0;
       
    39 	iTotalCount = 0;
       
    40 	}
       
    41 
       
    42 void CTestWrapper::Next(const TDesC& aHeading)
       
    43 	{
       
    44 	iTester.Next(aHeading);
       
    45 	++iTestCount;
       
    46 	iCheckCount = 0;
       
    47 	}
       
    48 
       
    49 void CTestWrapper::End()
       
    50 	{
       
    51 	TInt failedCount = iFailedTests.Count();
       
    52 	iTester.Printf(_L(""));
       
    53 	iTester.Printf(_L("*** Summary ***"));
       
    54 	iTester.Printf(_L("Tests run:	%d"), iTotalCount);
       
    55 	iTester.Printf(_L("Test failures:	%d"), failedCount);
       
    56 	if (failedCount != 0)
       
    57 		{
       
    58 		TInt i = 0;
       
    59 		for (; i < failedCount; ++i)
       
    60 			{
       
    61 			iTester.Printf(_L("Failed level [%d] at check number [%d]\n"),
       
    62 					iFailedTests[i].iTestNumber, iFailedTests[i].iCheckNumber);
       
    63 			}
       
    64 		}
       
    65 	else
       
    66 		{
       
    67 		iTester.End(); // prints success message
       
    68 		}
       
    69 	iFailedTests.Close();
       
    70 	}
       
    71 
       
    72 void CTestWrapper::Test(TInt aResult, TInt aLineNum)
       
    73     {
       
    74     // Test a condition.
       
    75     ++iCheckCount;
       
    76     ++iTotalCount;
       
    77 	iTester(ETrue); // this just updates the iTester test count so that it is in sync with the wrapper.
       
    78     if (!aResult)
       
    79         {
       
    80 		TFailedTest test;
       
    81 		test.iTestNumber = iTestCount;
       
    82 		test.iCheckNumber = iCheckCount;
       
    83         iTester.Printf(_L("FAIL : Failed level [%d] check [%d] in file [%S] at line number [%d]\n"), iTestCount, iCheckCount, &iFilename, aLineNum);
       
    84         if (iFailedTests.Append(test) != KErrNone)
       
    85         	iTester.Panic(_L("Checkpoint can't be added to failed list"));
       
    86         }
       
    87     }
       
    88 
       
    89 void CTestWrapper::Test(TInt aResult, TInt aError, TInt aLineNum)
       
    90     {
       
    91     // Test a condition.
       
    92     ++iCheckCount;
       
    93     ++iTotalCount;
       
    94 	iTester(ETrue); // this just updates the iTester test count so that it is in sync with the wrapper.
       
    95     if (!aResult)
       
    96         {
       
    97 		TFailedTest test;
       
    98 		test.iTestNumber = iTestCount;
       
    99 		test.iCheckNumber = iCheckCount;
       
   100         iTester.Printf(_L("FAIL : Failed level [%d] check [%d] in file [%S] at line number [%d] with error code [%d]\n"), iTestCount, iCheckCount, &iFilename, aLineNum, aError);
       
   101         if (iFailedTests.Append(test) != KErrNone)
       
   102         	iTester.Panic(_L("Checkpoint can't be added to failed list"));
       
   103         }
       
   104     }
       
   105 
       
   106 void CTestWrapper::SetFile(const TDesC& aFilename)
       
   107 	{
       
   108 	iFilename = aFilename;
       
   109 	}
       
   110 
       
   111 RTest& CTestWrapper::Tester()
       
   112 	{
       
   113 	return iTester;
       
   114 	}