2
|
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: This file contains testclass implementation.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// [INCLUDE FILES] - do not remove
|
|
19 |
#include <e32svr.h>
|
|
20 |
#include <StifParser.h>
|
|
21 |
#include <Stiftestinterface.h>
|
|
22 |
#include "TestFileStore.h"
|
|
23 |
|
|
24 |
// EXTERNAL DATA STRUCTURES
|
|
25 |
//extern ?external_data;
|
|
26 |
|
|
27 |
// EXTERNAL FUNCTION PROTOTYPES
|
|
28 |
//extern ?external_function( ?arg_type,?arg_type );
|
|
29 |
|
|
30 |
// CONSTANTS
|
|
31 |
//const ?type ?constant_var = ?constant;
|
|
32 |
|
|
33 |
// MACROS
|
|
34 |
//#define ?macro ?macro_def
|
|
35 |
|
|
36 |
// LOCAL CONSTANTS AND MACROS
|
|
37 |
//const ?type ?constant_var = ?constant;
|
|
38 |
//#define ?macro_name ?macro_def
|
|
39 |
|
|
40 |
// MODULE DATA STRUCTURES
|
|
41 |
//enum ?declaration
|
|
42 |
//typedef ?declaration
|
|
43 |
|
|
44 |
// LOCAL FUNCTION PROTOTYPES
|
|
45 |
//?type ?function_name( ?arg_type, ?arg_type );
|
|
46 |
|
|
47 |
// FORWARD DECLARATIONS
|
|
48 |
//class ?FORWARD_CLASSNAME;
|
|
49 |
|
|
50 |
// ============================= LOCAL FUNCTIONS ===============================
|
|
51 |
|
|
52 |
// -----------------------------------------------------------------------------
|
|
53 |
// ?function_name ?description.
|
|
54 |
// ?description
|
|
55 |
// Returns: ?value_1: ?description
|
|
56 |
// ?value_n: ?description_line1
|
|
57 |
// ?description_line2
|
|
58 |
// -----------------------------------------------------------------------------
|
|
59 |
//
|
|
60 |
/*
|
|
61 |
?type ?function_name(
|
|
62 |
?arg_type arg, // ?description
|
|
63 |
?arg_type arg) // ?description
|
|
64 |
{
|
|
65 |
|
|
66 |
?code // ?comment
|
|
67 |
|
|
68 |
// ?comment
|
|
69 |
?code
|
|
70 |
}
|
|
71 |
*/
|
|
72 |
|
|
73 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
74 |
|
|
75 |
// -----------------------------------------------------------------------------
|
|
76 |
// CTestFileStore::Delete
|
|
77 |
// Delete here all resources allocated and opened from test methods.
|
|
78 |
// Called from destructor.
|
|
79 |
// -----------------------------------------------------------------------------
|
|
80 |
//
|
|
81 |
void CTestFileStore::Delete()
|
|
82 |
{
|
|
83 |
|
|
84 |
}
|
|
85 |
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
// CTestFileStore::RunMethodL
|
|
88 |
// Run specified method. Contains also table of test mothods and their names.
|
|
89 |
// -----------------------------------------------------------------------------
|
|
90 |
//
|
|
91 |
TInt CTestFileStore::RunMethodL(
|
|
92 |
CStifItemParser& aItem )
|
|
93 |
{
|
|
94 |
|
|
95 |
static TStifFunctionInfo const KFunctions[] =
|
|
96 |
{
|
|
97 |
// Copy this line for every implemented function.
|
|
98 |
// First string is the function name used in TestScripter script file.
|
|
99 |
// Second is the actual implementation member function.
|
|
100 |
ENTRY( "Example", CTestFileStore::ExampleL ),
|
|
101 |
ENTRY( "PanicExample", CTestFileStore::PanicExample ),
|
|
102 |
ENTRY( "CreateFile", CTestFileStore::TestFileServerCreateFile ),
|
|
103 |
ENTRY( "WriteFile", CTestFileStore::TestFileServerWriteFile ),
|
|
104 |
ENTRY( "ReadFile", CTestFileStore::TestFileServerReadFile )
|
|
105 |
//ADD NEW ENTRY HERE
|
|
106 |
// [test cases entries] - Do not remove
|
|
107 |
|
|
108 |
};
|
|
109 |
|
|
110 |
const TInt count = sizeof( KFunctions ) /
|
|
111 |
sizeof( TStifFunctionInfo );
|
|
112 |
|
|
113 |
return RunInternalL( KFunctions, count, aItem );
|
|
114 |
|
|
115 |
}
|
|
116 |
|
|
117 |
// -----------------------------------------------------------------------------
|
|
118 |
// CTestFileStore::ExampleL
|
|
119 |
// Example test method function.
|
|
120 |
// (other items were commented in a header).
|
|
121 |
// -----------------------------------------------------------------------------
|
|
122 |
//
|
|
123 |
TInt CTestFileStore::ExampleL( CStifItemParser& aItem )
|
|
124 |
{
|
|
125 |
|
|
126 |
// Print to UI
|
|
127 |
_LIT( KTestFileStore, "TestFileStore" );
|
|
128 |
_LIT( KExample, "In Example" );
|
|
129 |
TestModuleIf().Printf( 0, KTestFileStore, KExample );
|
|
130 |
// Print to log file
|
|
131 |
iLog->Log( KExample );
|
|
132 |
|
|
133 |
TInt i = 0;
|
|
134 |
TPtrC string;
|
|
135 |
_LIT( KParam, "Param[%i]: %S" );
|
|
136 |
while ( aItem.GetNextString ( string ) == KErrNone )
|
|
137 |
{
|
|
138 |
TestModuleIf().Printf( i, KTestFileStore,
|
|
139 |
KParam, i, &string );
|
|
140 |
i++;
|
|
141 |
}
|
|
142 |
|
|
143 |
return KErrNone;
|
|
144 |
|
|
145 |
}
|
|
146 |
|
|
147 |
|
|
148 |
TInt CTestFileStore::TestFileServerCreateFile( CStifItemParser& aItem )
|
|
149 |
{
|
|
150 |
// Print to UI
|
|
151 |
_LIT( KSTIF_TestFileServer, "STIF_TestFileServer" );
|
|
152 |
_LIT( KExample, "Create File" );
|
|
153 |
TestModuleIf().Printf( 0, KSTIF_TestFileServer, KExample );
|
|
154 |
// Print to log file
|
|
155 |
iLog->Log( KExample );
|
|
156 |
|
|
157 |
TInt retValue = KErrNone ;
|
|
158 |
TInt expErrorCode = 0;
|
|
159 |
TPtrC filename;
|
|
160 |
|
|
161 |
TInt erro = aItem.GetNextString ( filename );
|
|
162 |
if( erro == KErrNone )
|
|
163 |
{
|
|
164 |
iLog->Log( filename );
|
|
165 |
RFs fileSession;
|
|
166 |
TRAP(erro, fileSession.Connect())
|
|
167 |
if ( erro != KErrNone)
|
|
168 |
{
|
|
169 |
iLog->Log(_L("Failed to connect to the file server"));
|
|
170 |
retValue = erro;
|
|
171 |
}
|
|
172 |
else
|
|
173 |
{
|
|
174 |
RFile file;
|
|
175 |
|
|
176 |
CleanupClosePushL(fileSession);
|
|
177 |
|
|
178 |
erro = file.Create( fileSession, filename, EFileRead | EFileWrite );
|
|
179 |
if(erro==expErrorCode)
|
|
180 |
{
|
|
181 |
iLog->Log(_L("===>Opening file passed with error code %D==="), erro);
|
|
182 |
}
|
|
183 |
else
|
|
184 |
{
|
|
185 |
iLog->Log(_L("--->Error in opening file expected error code %D error returned %D"), expErrorCode, erro);
|
|
186 |
}
|
|
187 |
CleanupStack::PopAndDestroy(&fileSession);
|
|
188 |
retValue = erro;
|
|
189 |
}
|
|
190 |
}
|
|
191 |
|
|
192 |
return retValue;
|
|
193 |
}
|
|
194 |
|
|
195 |
|
|
196 |
TInt CTestFileStore::TestFileServerWriteFile( CStifItemParser& aItem )
|
|
197 |
{
|
|
198 |
// Print to UI
|
|
199 |
_LIT( KSTIF_TestFileServer, "STIF_TestFileServer" );
|
|
200 |
_LIT( KExample, "Open File" );
|
|
201 |
TestModuleIf().Printf( 0, KSTIF_TestFileServer, KExample );
|
|
202 |
// Print to log file
|
|
203 |
iLog->Log( KExample );
|
|
204 |
|
|
205 |
TInt retValue = KErrNone ;
|
|
206 |
TInt expErrorCode = 0;
|
|
207 |
TPtrC filename;
|
|
208 |
|
|
209 |
TInt erro = aItem.GetNextString ( filename );
|
|
210 |
if( erro == KErrNone )
|
|
211 |
{
|
|
212 |
iLog->Log( filename );
|
|
213 |
RFs fileSession;
|
|
214 |
TRAP(erro, fileSession.Connect())
|
|
215 |
if ( erro != KErrNone)
|
|
216 |
{
|
|
217 |
iLog->Log(_L("Failed to connect to the file server"));
|
|
218 |
}
|
|
219 |
else
|
|
220 |
{
|
|
221 |
RFile file;
|
|
222 |
|
|
223 |
CleanupClosePushL(fileSession);
|
|
224 |
erro = file.Open(fileSession,filename,EFileRead);
|
|
225 |
if(erro==expErrorCode)
|
|
226 |
{
|
|
227 |
iLog->Log(_L("===>Opening file passed with error code %D==="), erro);
|
|
228 |
}
|
|
229 |
else
|
|
230 |
{
|
|
231 |
iLog->Log(_L("--->Error in opening file expected error code %D error returned %D"), expErrorCode, erro);
|
|
232 |
}
|
|
233 |
CleanupStack::PopAndDestroy(&fileSession);
|
|
234 |
}
|
|
235 |
retValue = erro;
|
|
236 |
}
|
|
237 |
|
|
238 |
return retValue;
|
|
239 |
}
|
|
240 |
|
|
241 |
TInt CTestFileStore::TestFileServerReadFile( CStifItemParser& aItem )
|
|
242 |
{
|
|
243 |
// Print to UI
|
|
244 |
_LIT( KSTIF_TestFileServer, "STIF_TestFileServer" );
|
|
245 |
_LIT( KExample, "Open File" );
|
|
246 |
TestModuleIf().Printf( 0, KSTIF_TestFileServer, KExample );
|
|
247 |
// Print to log file
|
|
248 |
iLog->Log( KExample );
|
|
249 |
|
|
250 |
TInt retValue = KErrNone ;
|
|
251 |
TInt expErrorCode = 0;
|
|
252 |
TPtrC filename;
|
|
253 |
|
|
254 |
TInt erro = aItem.GetNextString ( filename );
|
|
255 |
if( erro == KErrNone )
|
|
256 |
{
|
|
257 |
iLog->Log( filename );
|
|
258 |
RFs fileSession;
|
|
259 |
TRAP(erro, fileSession.Connect())
|
|
260 |
if ( erro != KErrNone)
|
|
261 |
{
|
|
262 |
iLog->Log(_L("Failed to connect to the file server"));
|
|
263 |
}
|
|
264 |
else
|
|
265 |
{
|
|
266 |
RFile file;
|
|
267 |
|
|
268 |
CleanupClosePushL(fileSession);
|
|
269 |
erro = file.Open(fileSession,filename,EFileRead);
|
|
270 |
if(erro==expErrorCode)
|
|
271 |
{
|
|
272 |
iLog->Log(_L("===>Opening file passed with error code %D==="), erro);
|
|
273 |
}
|
|
274 |
else
|
|
275 |
{
|
|
276 |
iLog->Log(_L("--->Error in opening file expected error code %D error returned %D"), expErrorCode, erro);
|
|
277 |
}
|
|
278 |
CleanupStack::PopAndDestroy(&fileSession);
|
|
279 |
}
|
|
280 |
retValue = erro;
|
|
281 |
}
|
|
282 |
|
|
283 |
return retValue;
|
|
284 |
}
|
|
285 |
|
|
286 |
|
|
287 |
TInt CTestFileStore::PanicExample(CStifItemParser& aItem)
|
|
288 |
{
|
|
289 |
_LIT( KSTIF_TestFileServer, "STIF_TestFileServer" );
|
|
290 |
_LIT( KFunction, "PanicExample" );
|
|
291 |
TestModuleIf().Printf( 0, KSTIF_TestFileServer, KFunction );
|
|
292 |
iLog->Log( KFunction );
|
|
293 |
TInt expectedPanicCode = 0;
|
|
294 |
TPtrC expectedPanicString;
|
|
295 |
TInt err1 = aItem.GetNextString(expectedPanicString);
|
|
296 |
TInt err2 = aItem.GetNextInt(expectedPanicCode);
|
|
297 |
if ( err1 != KErrNone || err2 != KErrNone)
|
|
298 |
{
|
|
299 |
iLog->Log(_L("Failed to read expected panic code"));
|
|
300 |
User::Panic(_L("USER-EXEC"), 1);
|
|
301 |
}
|
|
302 |
else
|
|
303 |
{
|
|
304 |
iLog->Log( _L("Create expected panic number= %D"), expectedPanicCode);
|
|
305 |
iLog->Log( _L("Create expected panic String= %S"), &expectedPanicString);
|
|
306 |
User::Panic(expectedPanicString, expectedPanicCode);
|
|
307 |
}
|
|
308 |
return KErrNone;
|
|
309 |
}
|