sl@0
|
1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
2 |
// All rights reserved.
|
sl@0
|
3 |
// This component and the accompanying materials are made available
|
sl@0
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
5 |
// which accompanies this distribution, and is available
|
sl@0
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
7 |
//
|
sl@0
|
8 |
// Initial Contributors:
|
sl@0
|
9 |
// Nokia Corporation - initial contribution.
|
sl@0
|
10 |
//
|
sl@0
|
11 |
// Contributors:
|
sl@0
|
12 |
//
|
sl@0
|
13 |
// Description:
|
sl@0
|
14 |
// f32test\manager\t_romg.cpp
|
sl@0
|
15 |
//
|
sl@0
|
16 |
//
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <f32file.h>
|
sl@0
|
19 |
#include <e32test.h>
|
sl@0
|
20 |
#include <e32rom.h>
|
sl@0
|
21 |
#include "..\server\t_server.h"
|
sl@0
|
22 |
|
sl@0
|
23 |
const TInt KBufSize=0x10000;
|
sl@0
|
24 |
const TInt KFillerSize=0x100;
|
sl@0
|
25 |
const TInt KRomFileHeaderSize=0x100;
|
sl@0
|
26 |
const TInt KRomFileHeaderNameSize=0x10;
|
sl@0
|
27 |
|
sl@0
|
28 |
class TRomFileHeaderBase
|
sl@0
|
29 |
{
|
sl@0
|
30 |
public:
|
sl@0
|
31 |
TText8 iName[KRomFileHeaderNameSize];
|
sl@0
|
32 |
TText8 iVersionStr[4];
|
sl@0
|
33 |
TText8 iBuildNumStr[4];
|
sl@0
|
34 |
TInt iRomSize;
|
sl@0
|
35 |
TInt iHeaderSize;
|
sl@0
|
36 |
};
|
sl@0
|
37 |
|
sl@0
|
38 |
class TRomFileHeader : public TRomFileHeaderBase
|
sl@0
|
39 |
{
|
sl@0
|
40 |
public:
|
sl@0
|
41 |
TUint8 iFiller[KRomFileHeaderSize-sizeof(TRomFileHeaderBase)];
|
sl@0
|
42 |
};
|
sl@0
|
43 |
|
sl@0
|
44 |
class CMemDir;
|
sl@0
|
45 |
class CMemEntry : public CBase
|
sl@0
|
46 |
{
|
sl@0
|
47 |
public:
|
sl@0
|
48 |
static CMemEntry* New(const TEntry& anEntry);
|
sl@0
|
49 |
~CMemEntry();
|
sl@0
|
50 |
TInt EntrySize();
|
sl@0
|
51 |
void Write();
|
sl@0
|
52 |
void WriteFile();
|
sl@0
|
53 |
inline TBool IsDir() {return(iEntry.iAtt&KEntryAttDir);}
|
sl@0
|
54 |
inline CMemDir& Dir() {return(*iDir);}
|
sl@0
|
55 |
inline void SetDir(CMemDir& aDir) {iDir=(&aDir);}
|
sl@0
|
56 |
inline TInt Size() {return(iSize);}
|
sl@0
|
57 |
inline TLinAddr Base() {return(iBase);}
|
sl@0
|
58 |
inline void SetBase();
|
sl@0
|
59 |
inline const TDesC& Name() {return(*iName);}
|
sl@0
|
60 |
inline static TInt LinkOffset() {return(_FOFF(CMemEntry,iLink));}
|
sl@0
|
61 |
protected:
|
sl@0
|
62 |
CMemEntry(const TEntry& anEntry);
|
sl@0
|
63 |
private:
|
sl@0
|
64 |
TLinAddr iBase;
|
sl@0
|
65 |
TInt iSize;
|
sl@0
|
66 |
TRomEntry iEntry;
|
sl@0
|
67 |
HBufC* iName;
|
sl@0
|
68 |
CMemDir* iDir;
|
sl@0
|
69 |
TDblQueLink iLink;
|
sl@0
|
70 |
};
|
sl@0
|
71 |
|
sl@0
|
72 |
class CMemDir : public CBase
|
sl@0
|
73 |
{
|
sl@0
|
74 |
public:
|
sl@0
|
75 |
static CMemDir* NewL();
|
sl@0
|
76 |
~CMemDir();
|
sl@0
|
77 |
void LoadDirL(const TDesC& aPath);
|
sl@0
|
78 |
void SetBaseDirs();
|
sl@0
|
79 |
void SetBaseFiles();
|
sl@0
|
80 |
void WriteDirs();
|
sl@0
|
81 |
void WriteFiles();
|
sl@0
|
82 |
void Write();
|
sl@0
|
83 |
TFileName Name(const TDesC& aName);
|
sl@0
|
84 |
inline TLinAddr Base() {return(iBase);}
|
sl@0
|
85 |
protected:
|
sl@0
|
86 |
CMemDir();
|
sl@0
|
87 |
private:
|
sl@0
|
88 |
TInt iSize;
|
sl@0
|
89 |
TInt iCount;
|
sl@0
|
90 |
TLinAddr iBase;
|
sl@0
|
91 |
HBufC* iPath;
|
sl@0
|
92 |
TDblQue<CMemEntry> iEntryQ;
|
sl@0
|
93 |
};
|
sl@0
|
94 |
|
sl@0
|
95 |
class RFileX : public RFile
|
sl@0
|
96 |
{
|
sl@0
|
97 |
public:
|
sl@0
|
98 |
RFileX() : RFile() {}
|
sl@0
|
99 |
TInt Write(const TDesC8& aDes);
|
sl@0
|
100 |
TInt Write(const TDesC8& aDes,TInt aLength);
|
sl@0
|
101 |
};
|
sl@0
|
102 |
|
sl@0
|
103 |
GLDEF_D RTest test(_L("T_ROMG"));
|
sl@0
|
104 |
LOCAL_D RFileX TheFile;
|
sl@0
|
105 |
LOCAL_D TRomHeader TheRomHeader;
|
sl@0
|
106 |
LOCAL_D TLinAddr TheCurrentBase;
|
sl@0
|
107 |
LOCAL_D CMemDir* TheRootDir;
|
sl@0
|
108 |
LOCAL_D TInt TheLevel;
|
sl@0
|
109 |
LOCAL_D TBuf8<KBufSize> TheBuf;
|
sl@0
|
110 |
LOCAL_D TBuf8<KFillerSize> TheFiller;
|
sl@0
|
111 |
#if defined(_UNICODE)
|
sl@0
|
112 |
LOCAL_D const TPtrC TheFileName=_L("ROMFILEU.BIN");
|
sl@0
|
113 |
#else
|
sl@0
|
114 |
LOCAL_D const TPtrC TheFileName=_L("ROMFILE.BIN");
|
sl@0
|
115 |
#endif
|
sl@0
|
116 |
|
sl@0
|
117 |
TInt RFileX::Write(const TDesC8& aDes)
|
sl@0
|
118 |
//
|
sl@0
|
119 |
// Write and update the file pos
|
sl@0
|
120 |
//
|
sl@0
|
121 |
{
|
sl@0
|
122 |
|
sl@0
|
123 |
TheCurrentBase+=aDes.Size();
|
sl@0
|
124 |
return(RFile::Write(aDes));
|
sl@0
|
125 |
}
|
sl@0
|
126 |
|
sl@0
|
127 |
TInt RFileX::Write(const TDesC8& aDes,TInt aLength)
|
sl@0
|
128 |
//
|
sl@0
|
129 |
// Write and update the file pos
|
sl@0
|
130 |
//
|
sl@0
|
131 |
{
|
sl@0
|
132 |
|
sl@0
|
133 |
TheCurrentBase+=aLength;
|
sl@0
|
134 |
return(RFile::Write(aDes,aLength));
|
sl@0
|
135 |
}
|
sl@0
|
136 |
|
sl@0
|
137 |
CMemEntry* CMemEntry::New(const TEntry& anEntry)
|
sl@0
|
138 |
//
|
sl@0
|
139 |
// Create a new entry.
|
sl@0
|
140 |
//
|
sl@0
|
141 |
{
|
sl@0
|
142 |
|
sl@0
|
143 |
CMemEntry* pE=new(ELeave) CMemEntry(anEntry);
|
sl@0
|
144 |
pE->iName=anEntry.iName.Alloc();
|
sl@0
|
145 |
test(pE->iName!=NULL);
|
sl@0
|
146 |
return(pE);
|
sl@0
|
147 |
}
|
sl@0
|
148 |
|
sl@0
|
149 |
#pragma warning( disable : 4705 ) // statement has no effect
|
sl@0
|
150 |
CMemEntry::CMemEntry(const TEntry& anEntry)
|
sl@0
|
151 |
//
|
sl@0
|
152 |
// Constructor.
|
sl@0
|
153 |
//
|
sl@0
|
154 |
{
|
sl@0
|
155 |
|
sl@0
|
156 |
iEntry.iAtt=(TUint8)(anEntry.iAtt|KEntryAttReadOnly); // All rom files are read only
|
sl@0
|
157 |
iEntry.iSize=anEntry.iSize;
|
sl@0
|
158 |
iEntry.iNameLength=(TUint8)anEntry.iName.Size();
|
sl@0
|
159 |
iSize=Align4(anEntry.iSize);
|
sl@0
|
160 |
__DECLARE_NAME(_S("CMemEntry"));
|
sl@0
|
161 |
}
|
sl@0
|
162 |
#pragma warning( default : 4705 )
|
sl@0
|
163 |
|
sl@0
|
164 |
CMemEntry::~CMemEntry()
|
sl@0
|
165 |
//
|
sl@0
|
166 |
// Destruct.
|
sl@0
|
167 |
//
|
sl@0
|
168 |
{
|
sl@0
|
169 |
|
sl@0
|
170 |
if (iLink.iNext!=NULL)
|
sl@0
|
171 |
iLink.Deque();
|
sl@0
|
172 |
delete iName;
|
sl@0
|
173 |
if (IsDir())
|
sl@0
|
174 |
delete iDir;
|
sl@0
|
175 |
}
|
sl@0
|
176 |
|
sl@0
|
177 |
void CMemEntry::SetBase()
|
sl@0
|
178 |
//
|
sl@0
|
179 |
// Set the entries base address.
|
sl@0
|
180 |
//
|
sl@0
|
181 |
{
|
sl@0
|
182 |
|
sl@0
|
183 |
iBase=TheCurrentBase;
|
sl@0
|
184 |
iEntry.iAddressLin=TheCurrentBase;
|
sl@0
|
185 |
}
|
sl@0
|
186 |
|
sl@0
|
187 |
TInt CMemEntry::EntrySize()
|
sl@0
|
188 |
//
|
sl@0
|
189 |
// Calculate the entries size.
|
sl@0
|
190 |
//
|
sl@0
|
191 |
{
|
sl@0
|
192 |
|
sl@0
|
193 |
return(Align4(KRomEntrySize+iEntry.iNameLength));
|
sl@0
|
194 |
}
|
sl@0
|
195 |
|
sl@0
|
196 |
void CMemEntry::Write()
|
sl@0
|
197 |
//
|
sl@0
|
198 |
// Write the current entry.
|
sl@0
|
199 |
//
|
sl@0
|
200 |
{
|
sl@0
|
201 |
|
sl@0
|
202 |
test(TheFile.Write(TPtrC8((TUint8*)&iEntry,KRomEntrySize))==KErrNone);
|
sl@0
|
203 |
test(TheFile.Write(TPtrC8((TUint8*)iName->Ptr(),iName->Size()))==KErrNone);
|
sl@0
|
204 |
TInt rem=EntrySize()-iName->Size()-KRomEntrySize;
|
sl@0
|
205 |
if (rem)
|
sl@0
|
206 |
test(TheFile.Write(TheFiller,rem)==KErrNone);
|
sl@0
|
207 |
}
|
sl@0
|
208 |
|
sl@0
|
209 |
void CMemEntry::WriteFile()
|
sl@0
|
210 |
//
|
sl@0
|
211 |
// Write the current entries file.
|
sl@0
|
212 |
//
|
sl@0
|
213 |
{
|
sl@0
|
214 |
|
sl@0
|
215 |
test(iBase==TheCurrentBase);
|
sl@0
|
216 |
TAutoClose<RFile> f;
|
sl@0
|
217 |
TFileName n=Dir().Name(*iName);
|
sl@0
|
218 |
test(f.iObj.Open(TheFs,n,EFileStream|EFileRead)==KErrNone);
|
sl@0
|
219 |
TInt size=0;
|
sl@0
|
220 |
do
|
sl@0
|
221 |
{
|
sl@0
|
222 |
test(f.iObj.Read(TheBuf)==KErrNone);
|
sl@0
|
223 |
test(TheFile.Write(TheBuf)==KErrNone);
|
sl@0
|
224 |
size+=TheBuf.Length();
|
sl@0
|
225 |
} while (TheBuf.Length()==TheBuf.MaxLength());
|
sl@0
|
226 |
test(iEntry.iSize==size);
|
sl@0
|
227 |
TInt rem=iSize-size;
|
sl@0
|
228 |
if (rem)
|
sl@0
|
229 |
test(TheFile.Write(TheFiller,rem)==KErrNone);
|
sl@0
|
230 |
}
|
sl@0
|
231 |
|
sl@0
|
232 |
CMemDir* CMemDir::NewL()
|
sl@0
|
233 |
//
|
sl@0
|
234 |
// Create a new directory.
|
sl@0
|
235 |
//
|
sl@0
|
236 |
{
|
sl@0
|
237 |
|
sl@0
|
238 |
return(new(ELeave) CMemDir);
|
sl@0
|
239 |
}
|
sl@0
|
240 |
|
sl@0
|
241 |
CMemDir::CMemDir()
|
sl@0
|
242 |
//
|
sl@0
|
243 |
// Constructor.
|
sl@0
|
244 |
//
|
sl@0
|
245 |
: iEntryQ(CMemEntry::LinkOffset())
|
sl@0
|
246 |
{
|
sl@0
|
247 |
|
sl@0
|
248 |
__DECLARE_NAME(_S("CMemDir"));
|
sl@0
|
249 |
}
|
sl@0
|
250 |
|
sl@0
|
251 |
CMemDir::~CMemDir()
|
sl@0
|
252 |
//
|
sl@0
|
253 |
// Destruct.
|
sl@0
|
254 |
//
|
sl@0
|
255 |
{
|
sl@0
|
256 |
|
sl@0
|
257 |
while (!iEntryQ.IsEmpty())
|
sl@0
|
258 |
{
|
sl@0
|
259 |
CMemEntry* pE=iEntryQ.First();
|
sl@0
|
260 |
delete pE;
|
sl@0
|
261 |
}
|
sl@0
|
262 |
delete iPath;
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
void CMemDir::SetBaseDirs()
|
sl@0
|
266 |
//
|
sl@0
|
267 |
// Set the base address of the directory and any sub-directories.
|
sl@0
|
268 |
//
|
sl@0
|
269 |
{
|
sl@0
|
270 |
|
sl@0
|
271 |
iBase=TheCurrentBase;
|
sl@0
|
272 |
iSize=sizeof(TInt);
|
sl@0
|
273 |
TDblQueIter<CMemEntry> q(iEntryQ);
|
sl@0
|
274 |
CMemEntry* pE;
|
sl@0
|
275 |
while ((pE=q++)!=NULL)
|
sl@0
|
276 |
{
|
sl@0
|
277 |
iCount++;
|
sl@0
|
278 |
iSize+=pE->EntrySize();
|
sl@0
|
279 |
}
|
sl@0
|
280 |
TheCurrentBase+=iSize;
|
sl@0
|
281 |
q.SetToFirst();
|
sl@0
|
282 |
while ((pE=q++)!=NULL)
|
sl@0
|
283 |
{
|
sl@0
|
284 |
if (pE->IsDir())
|
sl@0
|
285 |
{
|
sl@0
|
286 |
pE->SetBase();
|
sl@0
|
287 |
pE->Dir().SetBaseDirs();
|
sl@0
|
288 |
}
|
sl@0
|
289 |
}
|
sl@0
|
290 |
}
|
sl@0
|
291 |
|
sl@0
|
292 |
void CMemDir::SetBaseFiles()
|
sl@0
|
293 |
//
|
sl@0
|
294 |
// Set the base address of each file.
|
sl@0
|
295 |
//
|
sl@0
|
296 |
{
|
sl@0
|
297 |
|
sl@0
|
298 |
TDblQueIter<CMemEntry> q(iEntryQ);
|
sl@0
|
299 |
CMemEntry* pE;
|
sl@0
|
300 |
while ((pE=q++)!=NULL)
|
sl@0
|
301 |
{
|
sl@0
|
302 |
if (!pE->IsDir())
|
sl@0
|
303 |
{
|
sl@0
|
304 |
pE->SetBase();
|
sl@0
|
305 |
TheCurrentBase+=pE->Size();
|
sl@0
|
306 |
}
|
sl@0
|
307 |
}
|
sl@0
|
308 |
q.SetToFirst();
|
sl@0
|
309 |
while ((pE=q++)!=NULL)
|
sl@0
|
310 |
{
|
sl@0
|
311 |
if (pE->IsDir())
|
sl@0
|
312 |
pE->Dir().SetBaseFiles();
|
sl@0
|
313 |
}
|
sl@0
|
314 |
}
|
sl@0
|
315 |
|
sl@0
|
316 |
void CMemDir::WriteDirs()
|
sl@0
|
317 |
//
|
sl@0
|
318 |
// Write the directory and any sub-directories.
|
sl@0
|
319 |
//
|
sl@0
|
320 |
{
|
sl@0
|
321 |
|
sl@0
|
322 |
TheLevel++;
|
sl@0
|
323 |
TFileName name=Name(_L(""));
|
sl@0
|
324 |
test.Printf(_L("%*p%S\n"),TheLevel<<1,&name);
|
sl@0
|
325 |
Write();
|
sl@0
|
326 |
TDblQueIter<CMemEntry> q(iEntryQ);
|
sl@0
|
327 |
CMemEntry* pE;
|
sl@0
|
328 |
while ((pE=q++)!=NULL)
|
sl@0
|
329 |
{
|
sl@0
|
330 |
if (pE->IsDir())
|
sl@0
|
331 |
pE->Dir().WriteDirs();
|
sl@0
|
332 |
}
|
sl@0
|
333 |
TheLevel--;
|
sl@0
|
334 |
}
|
sl@0
|
335 |
|
sl@0
|
336 |
void CMemDir::WriteFiles()
|
sl@0
|
337 |
//
|
sl@0
|
338 |
// Set the base address of each file.
|
sl@0
|
339 |
//
|
sl@0
|
340 |
{
|
sl@0
|
341 |
|
sl@0
|
342 |
TheLevel++;
|
sl@0
|
343 |
TFileName name=Name(_L(""));
|
sl@0
|
344 |
test.Printf(_L("%*p%S\n"),TheLevel<<1,&name);
|
sl@0
|
345 |
TDblQueIter<CMemEntry> q(iEntryQ);
|
sl@0
|
346 |
CMemEntry* pE;
|
sl@0
|
347 |
while ((pE=q++)!=NULL)
|
sl@0
|
348 |
{
|
sl@0
|
349 |
if (!pE->IsDir())
|
sl@0
|
350 |
{
|
sl@0
|
351 |
test.Printf(_L("%*p%S\n"),(TheLevel<<1)+2,&pE->Name()),
|
sl@0
|
352 |
pE->WriteFile();
|
sl@0
|
353 |
}
|
sl@0
|
354 |
}
|
sl@0
|
355 |
q.SetToFirst();
|
sl@0
|
356 |
while ((pE=q++)!=NULL)
|
sl@0
|
357 |
{
|
sl@0
|
358 |
if (pE->IsDir())
|
sl@0
|
359 |
pE->Dir().WriteFiles();
|
sl@0
|
360 |
}
|
sl@0
|
361 |
TheLevel--;
|
sl@0
|
362 |
}
|
sl@0
|
363 |
|
sl@0
|
364 |
void CMemDir::Write()
|
sl@0
|
365 |
//
|
sl@0
|
366 |
// Write the current directory.
|
sl@0
|
367 |
//
|
sl@0
|
368 |
{
|
sl@0
|
369 |
|
sl@0
|
370 |
test(iBase==TheCurrentBase);
|
sl@0
|
371 |
TInt size=iSize-sizeof(TInt);
|
sl@0
|
372 |
test(TheFile.Write(TPtrC8((TUint8*)&size,sizeof(TInt)))==KErrNone);
|
sl@0
|
373 |
TDblQueIter<CMemEntry> q(iEntryQ);
|
sl@0
|
374 |
CMemEntry* pE;
|
sl@0
|
375 |
while ((pE=q++)!=NULL)
|
sl@0
|
376 |
pE->Write();
|
sl@0
|
377 |
TInt sz=(TheCurrentBase-iBase);
|
sl@0
|
378 |
test(sz==iSize);
|
sl@0
|
379 |
}
|
sl@0
|
380 |
|
sl@0
|
381 |
TFileName CMemDir::Name(const TDesC& aName)
|
sl@0
|
382 |
//
|
sl@0
|
383 |
// Make a full path name from aName.
|
sl@0
|
384 |
//
|
sl@0
|
385 |
{
|
sl@0
|
386 |
|
sl@0
|
387 |
TFileName n(*iPath);
|
sl@0
|
388 |
n+=_L("\\");
|
sl@0
|
389 |
n+=aName;
|
sl@0
|
390 |
return(n);
|
sl@0
|
391 |
}
|
sl@0
|
392 |
|
sl@0
|
393 |
void CMemDir::LoadDirL(const TDesC& aPath)
|
sl@0
|
394 |
//
|
sl@0
|
395 |
// Load a directory.
|
sl@0
|
396 |
//
|
sl@0
|
397 |
{
|
sl@0
|
398 |
|
sl@0
|
399 |
TheLevel++;
|
sl@0
|
400 |
iPath=aPath.AllocL();
|
sl@0
|
401 |
TFileName name=Name(_L("*.*"));
|
sl@0
|
402 |
test.Printf(_L("%*p%S\n"),TheLevel<<1,&name);
|
sl@0
|
403 |
CDir* pD;
|
sl@0
|
404 |
test(TheFs.GetDir(Name(_L("*.*")),KEntryAttMatchMask,EDirsFirst|ESortByName,pD)==KErrNone);
|
sl@0
|
405 |
TInt count=pD->Count();
|
sl@0
|
406 |
TInt i=0;
|
sl@0
|
407 |
while (i<count)
|
sl@0
|
408 |
{
|
sl@0
|
409 |
const TEntry& e=(*pD)[i++];
|
sl@0
|
410 |
TParse parse;
|
sl@0
|
411 |
parse.Set(e.iName,NULL,NULL);
|
sl@0
|
412 |
if (!parse.Ext().CompareF(_L(".NCB")))
|
sl@0
|
413 |
continue; // Ignore .ncb files - cannot open/read them.
|
sl@0
|
414 |
CMemEntry* pE=CMemEntry::New(e);
|
sl@0
|
415 |
iEntryQ.AddLast(*pE);
|
sl@0
|
416 |
}
|
sl@0
|
417 |
delete pD;
|
sl@0
|
418 |
TDblQueIter<CMemEntry> q(iEntryQ);
|
sl@0
|
419 |
CMemEntry* pE;
|
sl@0
|
420 |
while ((pE=q++)!=NULL)
|
sl@0
|
421 |
{
|
sl@0
|
422 |
if (pE->IsDir())
|
sl@0
|
423 |
{
|
sl@0
|
424 |
CMemDir* pM=CMemDir::NewL();
|
sl@0
|
425 |
pE->SetDir(*pM);
|
sl@0
|
426 |
pM->LoadDirL(Name(pE->Name()));
|
sl@0
|
427 |
}
|
sl@0
|
428 |
else
|
sl@0
|
429 |
pE->SetDir(*this);
|
sl@0
|
430 |
}
|
sl@0
|
431 |
TheLevel--;
|
sl@0
|
432 |
}
|
sl@0
|
433 |
|
sl@0
|
434 |
LOCAL_C void buildRomImageL()
|
sl@0
|
435 |
//
|
sl@0
|
436 |
// Build the ROM image.
|
sl@0
|
437 |
//
|
sl@0
|
438 |
{
|
sl@0
|
439 |
|
sl@0
|
440 |
test.Start(_L("Parse command line"));
|
sl@0
|
441 |
HBufC* buf=HBufC::New(RProcess().CommandLineLength());
|
sl@0
|
442 |
test(buf!=NULL);
|
sl@0
|
443 |
TPtr cmd = buf->Des();
|
sl@0
|
444 |
RProcess().CommandLine(cmd);
|
sl@0
|
445 |
TLex lex(*buf);
|
sl@0
|
446 |
TFileName n=lex.NextToken();
|
sl@0
|
447 |
if (n.Length()==0)
|
sl@0
|
448 |
n=_L("\\F32");
|
sl@0
|
449 |
test(n.Length()!=0);
|
sl@0
|
450 |
if (n.Right(1)==_L("\\"))
|
sl@0
|
451 |
n.SetLength(n.Length()-1);
|
sl@0
|
452 |
//
|
sl@0
|
453 |
test.Next(_L("Create root mem dir"));
|
sl@0
|
454 |
TRAPD(r,TheRootDir=CMemDir::NewL());
|
sl@0
|
455 |
test(r==KErrNone);
|
sl@0
|
456 |
//
|
sl@0
|
457 |
test.Next(_L("Load directory structure"));
|
sl@0
|
458 |
TheLevel=(-1);
|
sl@0
|
459 |
TRAP(r,TheRootDir->LoadDirL(n));
|
sl@0
|
460 |
test(r==KErrNone);
|
sl@0
|
461 |
test(TheLevel==(-1));
|
sl@0
|
462 |
//
|
sl@0
|
463 |
delete buf;
|
sl@0
|
464 |
test.End();
|
sl@0
|
465 |
}
|
sl@0
|
466 |
|
sl@0
|
467 |
LOCAL_C void baseRomImage()
|
sl@0
|
468 |
//
|
sl@0
|
469 |
// Set base addresses for the ROM image.
|
sl@0
|
470 |
//
|
sl@0
|
471 |
{
|
sl@0
|
472 |
|
sl@0
|
473 |
test.Start(_L("Setting up the header"));
|
sl@0
|
474 |
Mem::FillZ(&TheRomHeader,sizeof(TRomHeader));
|
sl@0
|
475 |
test.Printf(_L("1"));
|
sl@0
|
476 |
TheRomHeader.iVersion=TVersion(1,0,1);
|
sl@0
|
477 |
test.Printf(_L("2"));
|
sl@0
|
478 |
TTime t;
|
sl@0
|
479 |
t.HomeTime();
|
sl@0
|
480 |
test.Printf(_L("3"));
|
sl@0
|
481 |
TheRomHeader.iTime=t.Int64();
|
sl@0
|
482 |
test.Printf(_L("4"));
|
sl@0
|
483 |
TheRomHeader.iRomBase=UserSvr::RomHeaderAddress();
|
sl@0
|
484 |
test.Printf(_L("5"));
|
sl@0
|
485 |
TheRomHeader.iRomRootDirectoryList=TheCurrentBase=UserSvr::RomHeaderAddress()+sizeof(TRomHeader);
|
sl@0
|
486 |
test.Printf(_L("6"));
|
sl@0
|
487 |
//
|
sl@0
|
488 |
test.Next(_L("Set dirs base"));
|
sl@0
|
489 |
TheRootDir->SetBaseDirs();
|
sl@0
|
490 |
//
|
sl@0
|
491 |
test.Next(_L("Set files base"));
|
sl@0
|
492 |
TheRootDir->SetBaseFiles();
|
sl@0
|
493 |
TheRomHeader.iRomSize=TheCurrentBase-UserSvr::RomHeaderAddress();
|
sl@0
|
494 |
//
|
sl@0
|
495 |
test.End();
|
sl@0
|
496 |
}
|
sl@0
|
497 |
|
sl@0
|
498 |
LOCAL_C void writeRomImage()
|
sl@0
|
499 |
//
|
sl@0
|
500 |
// Write the ROM image.
|
sl@0
|
501 |
//
|
sl@0
|
502 |
{
|
sl@0
|
503 |
|
sl@0
|
504 |
test.Start(_L("Write rom file header"));
|
sl@0
|
505 |
//
|
sl@0
|
506 |
TPckgBuf<TRomFileHeader> fileHeadB;
|
sl@0
|
507 |
fileHeadB.FillZ(fileHeadB.MaxLength());
|
sl@0
|
508 |
TRomFileHeader& fileHead=fileHeadB();
|
sl@0
|
509 |
Mem::Copy(&fileHead.iName[0],"EPOC468 ROM ",KRomFileHeaderNameSize);
|
sl@0
|
510 |
Mem::Copy(&fileHead.iVersionStr[0],"0.01",4);
|
sl@0
|
511 |
Mem::Copy(&fileHead.iBuildNumStr[0]," 1",4);
|
sl@0
|
512 |
fileHead.iRomSize=TheRomHeader.iRomSize;
|
sl@0
|
513 |
fileHead.iHeaderSize=KRomFileHeaderSize;
|
sl@0
|
514 |
test(TheFile.Write(fileHeadB)==KErrNone);
|
sl@0
|
515 |
//
|
sl@0
|
516 |
test.Next(_L("Write rom header"));
|
sl@0
|
517 |
TheFiller.FillZ(TheFiller.MaxLength());
|
sl@0
|
518 |
TPckgC<TRomHeader> head(TheRomHeader);
|
sl@0
|
519 |
test(TheFile.Write(head)==KErrNone);
|
sl@0
|
520 |
TheCurrentBase=UserSvr::RomHeaderAddress()+sizeof(TheRomHeader);
|
sl@0
|
521 |
//
|
sl@0
|
522 |
test.Next(_L("Write directories"));
|
sl@0
|
523 |
TheLevel=(-1);
|
sl@0
|
524 |
TheRootDir->WriteDirs();
|
sl@0
|
525 |
test(TheLevel==(-1));
|
sl@0
|
526 |
//
|
sl@0
|
527 |
test.Next(_L("Write files"));
|
sl@0
|
528 |
TheLevel=(-1);
|
sl@0
|
529 |
TheRootDir->WriteFiles();
|
sl@0
|
530 |
test(TheLevel==(-1));
|
sl@0
|
531 |
//
|
sl@0
|
532 |
test.End();
|
sl@0
|
533 |
}
|
sl@0
|
534 |
|
sl@0
|
535 |
GLDEF_C void CallTestsL(void)
|
sl@0
|
536 |
//
|
sl@0
|
537 |
// Test the file server.
|
sl@0
|
538 |
//
|
sl@0
|
539 |
{
|
sl@0
|
540 |
test.Title();
|
sl@0
|
541 |
|
sl@0
|
542 |
#if defined(__WINS__)
|
sl@0
|
543 |
test.Printf(_L("Running on WINS. Skipping ROM test"));
|
sl@0
|
544 |
return;
|
sl@0
|
545 |
#endif
|
sl@0
|
546 |
//
|
sl@0
|
547 |
test.Start(_L("Testing rom"));
|
sl@0
|
548 |
|
sl@0
|
549 |
TInt r=TheFs.Delete(TheFileName);
|
sl@0
|
550 |
if (r==KErrAccessDenied)
|
sl@0
|
551 |
{
|
sl@0
|
552 |
test.Printf(_L("Error: Cannot access %S"),&TheFileName);
|
sl@0
|
553 |
test.End();
|
sl@0
|
554 |
return;
|
sl@0
|
555 |
}
|
sl@0
|
556 |
test(r==KErrNone || r==KErrNotFound);
|
sl@0
|
557 |
//
|
sl@0
|
558 |
test.Next(_L("Generating ROM image"));
|
sl@0
|
559 |
TRAP(r,buildRomImageL());
|
sl@0
|
560 |
test(r==KErrNone);
|
sl@0
|
561 |
//
|
sl@0
|
562 |
test.Next(_L("Basing the rom image"));
|
sl@0
|
563 |
baseRomImage();
|
sl@0
|
564 |
//
|
sl@0
|
565 |
TBuf<0x80> b=_L("Writing ROM file ");
|
sl@0
|
566 |
b+=TheFileName;
|
sl@0
|
567 |
test.Next(b);
|
sl@0
|
568 |
r=TheFile.Replace(TheFs,TheFileName,EFileStream|EFileWrite);
|
sl@0
|
569 |
test(r==KErrNone);
|
sl@0
|
570 |
writeRomImage();
|
sl@0
|
571 |
TheFile.Close();
|
sl@0
|
572 |
delete TheRootDir;
|
sl@0
|
573 |
|
sl@0
|
574 |
test.End();
|
sl@0
|
575 |
return;
|
sl@0
|
576 |
}
|
sl@0
|
577 |
|