|
1 /* |
|
2 * Copyright (c) 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 * |
|
16 */ |
|
17 #include "testutils.h" |
|
18 |
|
19 CTestWrapper* CTestWrapper::NewLC(RTest& aTester) |
|
20 { |
|
21 CTestWrapper* self = new (ELeave) CTestWrapper(aTester); |
|
22 CleanupStack::PushL(self); |
|
23 return self; |
|
24 } |
|
25 |
|
26 CTestWrapper::CTestWrapper(RTest& aTester) : iTester(aTester) |
|
27 { |
|
28 } |
|
29 |
|
30 CTestWrapper::~CTestWrapper() |
|
31 { |
|
32 iTester.Close(); |
|
33 } |
|
34 |
|
35 void CTestWrapper::Start(const TDesC& aHeading) |
|
36 { |
|
37 iTester.Start(aHeading); |
|
38 iTestCount = 1; |
|
39 iCheckCount = 0; |
|
40 iTotalCount = 0; |
|
41 } |
|
42 |
|
43 void CTestWrapper::Next(const TDesC& aHeading) |
|
44 { |
|
45 iTester.Next(aHeading); |
|
46 ++iTestCount; |
|
47 iCheckCount = 0; |
|
48 } |
|
49 |
|
50 void CTestWrapper::End() |
|
51 { |
|
52 TInt failedCount = iFailedTests.Count(); |
|
53 iTester.Printf(_L("")); |
|
54 iTester.Printf(_L("*** Summary ***")); |
|
55 iTester.Printf(_L("Tests run: %d"), iTotalCount); |
|
56 iTester.Printf(_L("Test failures: %d"), failedCount); |
|
57 if (failedCount != 0) |
|
58 { |
|
59 TInt i = 0; |
|
60 for (; i < failedCount; ++i) |
|
61 { |
|
62 iTester.Printf(_L("Failed level [%d] at check number [%d]\n"), |
|
63 iFailedTests[i].iTestNumber, iFailedTests[i].iCheckNumber); |
|
64 } |
|
65 } |
|
66 else |
|
67 { |
|
68 iTester.End(); // prints success message |
|
69 } |
|
70 iFailedTests.Close(); |
|
71 } |
|
72 |
|
73 void CTestWrapper::Test(TInt aResult, TInt aLineNum) |
|
74 { |
|
75 // Test a condition. |
|
76 ++iCheckCount; |
|
77 ++iTotalCount; |
|
78 iTester(ETrue); // this just updates the iTester test count so that it is in sync with the wrapper. |
|
79 if (!aResult) |
|
80 { |
|
81 TFailedTest test; |
|
82 test.iTestNumber = iTestCount; |
|
83 test.iCheckNumber = iCheckCount; |
|
84 iTester.Printf(_L("FAIL : Failed level [%d] check [%d] in file [%S] at line number [%d]\n"), iTestCount, iCheckCount, &iFilename, aLineNum); |
|
85 if (iFailedTests.Append(test) != KErrNone) |
|
86 iTester.Panic(_L("Checkpoint can't be added to failed list")); |
|
87 } |
|
88 } |
|
89 |
|
90 void CTestWrapper::Test(TInt aResult, TInt aError, TInt aLineNum) |
|
91 { |
|
92 // Test a condition. |
|
93 ++iCheckCount; |
|
94 ++iTotalCount; |
|
95 iTester(ETrue); // this just updates the iTester test count so that it is in sync with the wrapper. |
|
96 if (!aResult) |
|
97 { |
|
98 TFailedTest test; |
|
99 test.iTestNumber = iTestCount; |
|
100 test.iCheckNumber = iCheckCount; |
|
101 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); |
|
102 if (iFailedTests.Append(test) != KErrNone) |
|
103 iTester.Panic(_L("Checkpoint can't be added to failed list")); |
|
104 } |
|
105 } |
|
106 |
|
107 void CTestWrapper::SetFile(const TDesC& aFilename) |
|
108 { |
|
109 iFilename = aFilename; |
|
110 } |
|
111 |
|
112 RTest& CTestWrapper::Tester() |
|
113 { |
|
114 return iTester; |
|
115 } |