|
1 // Copyright (c) 2007-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 // Example CTestStep derived implementation |
|
15 // |
|
16 |
|
17 |
|
18 |
|
19 /** |
|
20 @file te_perfoutputsanity.cpp |
|
21 @internalTechnology |
|
22 */ |
|
23 #include <e32math.h> //for cvs comparison of elements |
|
24 #include "te_perfoutputsanity.h" |
|
25 #include "te_ostv2integsuite_defs.h" |
|
26 #include "te_perfcsvreader.h" |
|
27 using namespace Ulogger; //CA:added so can use old ulogger api |
|
28 |
|
29 COutputCSVSanityWrapper::COutputCSVSanityWrapper() |
|
30 /** |
|
31 * Constructor |
|
32 */ |
|
33 { |
|
34 } |
|
35 |
|
36 COutputCSVSanityWrapper::~COutputCSVSanityWrapper() |
|
37 /** |
|
38 * Destructor |
|
39 */ |
|
40 { |
|
41 } |
|
42 |
|
43 COutputCSVSanityWrapper* COutputCSVSanityWrapper::NewLC() |
|
44 { |
|
45 COutputCSVSanityWrapper* self = new (ELeave)COutputCSVSanityWrapper(); |
|
46 CleanupStack::PushL(self); |
|
47 self->ConstructL(); |
|
48 return self; |
|
49 } |
|
50 |
|
51 COutputCSVSanityWrapper* COutputCSVSanityWrapper::NewL() |
|
52 { |
|
53 COutputCSVSanityWrapper* self=COutputCSVSanityWrapper::NewLC(); |
|
54 CleanupStack::Pop(); // self; |
|
55 return self; |
|
56 } |
|
57 |
|
58 void COutputCSVSanityWrapper::ConstructL() |
|
59 { |
|
60 } |
|
61 |
|
62 TAny* COutputCSVSanityWrapper::GetObject() |
|
63 { |
|
64 return NULL; |
|
65 } |
|
66 |
|
67 TBool COutputCSVSanityWrapper::DoCommandL( const TTEFFunction& /*aCommand*/, |
|
68 const TTEFSectionName& /*aSection*/, |
|
69 const TInt /*aAsyncErrorIndex*/) |
|
70 { |
|
71 |
|
72 if(BlockResult()==EPass) |
|
73 { |
|
74 SetBlockResult(TestBaselineCsv()); |
|
75 } |
|
76 |
|
77 return ETrue; |
|
78 } |
|
79 |
|
80 |
|
81 |
|
82 TVerdict COutputCSVSanityWrapper::TestBaselineCsv() |
|
83 { |
|
84 |
|
85 //read a sanity test file |
|
86 //read generated file |
|
87 //compare... |
|
88 |
|
89 //Create csvReference |
|
90 CCsvReader csvReference; |
|
91 TInt size = 0; |
|
92 //get the size of the reference file |
|
93 #ifdef __WINSCW__ |
|
94 TInt error = CsvFileSize(KReferenceWinscwCsvFile, size); |
|
95 #else |
|
96 TInt error = CsvFileSize(KReferenceCsvFile, size); |
|
97 #endif |
|
98 if(error) |
|
99 { |
|
100 SetBlockResult(EFail); |
|
101 INFO_PRINTF2(_L("TestBaselineCsv, KReferenceCsvFile, test failed on with error code %d"), error); |
|
102 } |
|
103 //Set the size of the RBuf |
|
104 csvReference.Create(size); |
|
105 |
|
106 //Create csvGenerated |
|
107 CCsvReader csvGenerated; |
|
108 //get the size of the generated file |
|
109 error = CsvFileSize(KApiCSVFile, size); |
|
110 if(error) |
|
111 { |
|
112 SetBlockResult(EFail); |
|
113 INFO_PRINTF2(_L("TestBaselineCsv, KApiCSVFile, test failed on with error code %d"), error); |
|
114 } |
|
115 //create the RBuf |
|
116 csvGenerated.Create(size); |
|
117 |
|
118 //Read the reference file into the RBuf |
|
119 #ifdef __WINSCW__ |
|
120 error = ReadCsvFile(KReferenceWinscwCsvFile, csvReference.Buffer()); |
|
121 #else |
|
122 error = ReadCsvFile(KReferenceCsvFile, csvReference.Buffer()); |
|
123 #endif |
|
124 if(error) |
|
125 { |
|
126 SetBlockResult(EFail); |
|
127 INFO_PRINTF2(_L("TestBaselineCsv, ReadCsvFile(KReferenceCsvFile) failed on with error code %d"), error); |
|
128 } |
|
129 //Read the generated file into the RBuf |
|
130 error = ReadCsvFile(KApiCSVFile, csvGenerated.Buffer()); |
|
131 if(error) |
|
132 { |
|
133 SetBlockResult(EFail); |
|
134 INFO_PRINTF2(_L("TestBaselineCsv, ReadCsvFile(KApiCSVFile) failed on with error code %d"), error); |
|
135 } |
|
136 |
|
137 //compare the two files |
|
138 if(!error) |
|
139 { |
|
140 TBool verdict = EFalse; |
|
141 RArray<TFailedResults> failedResults; |
|
142 CleanupClosePushL(failedResults); |
|
143 error = csvGenerated.CompareFile(csvReference, verdict, failedResults); |
|
144 |
|
145 if(verdict == EFalse) |
|
146 { |
|
147 for(TInt i = 0; i < failedResults.Count(); i++) |
|
148 { |
|
149 SetBlockResult(EFail); |
|
150 TFailedResults result = failedResults[i]; |
|
151 // TInt temp = result.iError; |
|
152 INFO_PRINTF5(_L("CompareFile failed, error %d, linenumber %d, elementtype %d, variation %d"), failedResults[i].iError, failedResults[i].iLineNumber, failedResults[i].iElementType, failedResults[i].iVariation); |
|
153 } |
|
154 } |
|
155 CleanupStack::PopAndDestroy(&failedResults); |
|
156 } |
|
157 |
|
158 if(error) |
|
159 { |
|
160 SetBlockResult(EFail); |
|
161 INFO_PRINTF2(_L("Output sanity test failed, with error code %d"), error); |
|
162 } |
|
163 return BlockResult(); |
|
164 } |
|
165 |
|
166 |
|
167 TInt COutputCSVSanityWrapper::CsvFileSize(const TDesC& aFilename, TInt& aSize) |
|
168 { |
|
169 RFs fsSession; |
|
170 CleanupClosePushL(fsSession); |
|
171 User::LeaveIfError(fsSession.Connect()); |
|
172 |
|
173 RFile file; |
|
174 TInt size = 0; |
|
175 TInt error = file.Open(fsSession, aFilename, EFileRead); |
|
176 if(!error) |
|
177 { |
|
178 file.Size(size); |
|
179 file.Close(); |
|
180 fsSession.Close(); |
|
181 } |
|
182 CleanupStack::PopAndDestroy();//fsSession |
|
183 aSize = size; |
|
184 return error; |
|
185 } |
|
186 |
|
187 /* |
|
188 * Read a file and stick the data in a buffer and return that. |
|
189 * The caller of the method owns the buffer |
|
190 * Ie. this method allocates the buffer but the caller is responsible for destroying it. |
|
191 */ |
|
192 TInt COutputCSVSanityWrapper::ReadCsvFile(const TDesC& aFilename, RBuf8& aBuffer) |
|
193 { |
|
194 RFs fsSession; |
|
195 CleanupClosePushL(fsSession); |
|
196 User::LeaveIfError(fsSession.Connect()); |
|
197 |
|
198 RFile file; |
|
199 TInt error = file.Open(fsSession, aFilename, EFileRead); |
|
200 if(error == KErrNone) |
|
201 { |
|
202 error = file.Read(aBuffer); |
|
203 file.Close(); |
|
204 fsSession.Close(); |
|
205 } |
|
206 CleanupStack::PopAndDestroy();//fsSession |
|
207 return error; |
|
208 } |
|
209 |
|
210 |
|
211 // eof |
|
212 |