sl@0
|
1 |
// Copyright (c) 1996-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 |
// e32test\buffer\t_func.cpp
|
sl@0
|
15 |
// Overview:
|
sl@0
|
16 |
// Comprehensive test for the ARM coded Mem, Des and integer divide routines.
|
sl@0
|
17 |
// Check memory for a large variation of buffer sizes and alignments,
|
sl@0
|
18 |
// check all the optimizations made in the copying/filling code.
|
sl@0
|
19 |
// API Information:
|
sl@0
|
20 |
// Mem::Fill, Mem::Copy, Mem::Move, Mem::Swap, Mem::Compare
|
sl@0
|
21 |
// Details:
|
sl@0
|
22 |
// - Create blocks, fill some data into one block, copy data across block of varying
|
sl@0
|
23 |
// lengths, alignments and check the copy is as expected.
|
sl@0
|
24 |
// - Create blocks, fill some data into the block, move data from one block to other
|
sl@0
|
25 |
// block and check it is as expected.
|
sl@0
|
26 |
// - Create blocks, fill some data and check the data is filled as expected.
|
sl@0
|
27 |
// - Create blocks, fill some data in two blocks, swap the blocks check the data
|
sl@0
|
28 |
// is swapped as expected.
|
sl@0
|
29 |
// - Create blocks, fill some data into the blocks, compare the data at different specified
|
sl@0
|
30 |
// offsets, compare the return value, check it is as expected.
|
sl@0
|
31 |
// - Check the conversion from specified integer numbers in different number systems to
|
sl@0
|
32 |
// character representation is as expected. Check for both upper and lower case results.
|
sl@0
|
33 |
// - Initialize variables with signed, unsigned, positive, negative integer values, check the
|
sl@0
|
34 |
// integer division routines are as expected.
|
sl@0
|
35 |
// - Check the integer modulo operation results are as expected.
|
sl@0
|
36 |
// Platforms/Drives/Compatibility:
|
sl@0
|
37 |
// All
|
sl@0
|
38 |
// Assumptions/Requirement/Pre-requisites:
|
sl@0
|
39 |
// Failures and causes:
|
sl@0
|
40 |
// Base Port information:
|
sl@0
|
41 |
//
|
sl@0
|
42 |
//
|
sl@0
|
43 |
|
sl@0
|
44 |
#include <e32std.h>
|
sl@0
|
45 |
#include <e32std_private.h>
|
sl@0
|
46 |
#include <e32base.h>
|
sl@0
|
47 |
#include <e32base_private.h>
|
sl@0
|
48 |
#include <e32test.h>
|
sl@0
|
49 |
#include <e32svr.h>
|
sl@0
|
50 |
#include <e32panic.h>
|
sl@0
|
51 |
|
sl@0
|
52 |
RTest test(_L("T_FUNC"));
|
sl@0
|
53 |
|
sl@0
|
54 |
TInt failed;
|
sl@0
|
55 |
|
sl@0
|
56 |
void PrintInfo(TText8* aBuf1,TText8* aBuf2)
|
sl@0
|
57 |
{
|
sl@0
|
58 |
if(aBuf1<aBuf2)
|
sl@0
|
59 |
test.Printf(_L("source before target\n"));
|
sl@0
|
60 |
else if(aBuf1==aBuf2)
|
sl@0
|
61 |
test.Printf(_L("source and target identical\n"));
|
sl@0
|
62 |
else
|
sl@0
|
63 |
test.Printf(_L("target before source\n"));
|
sl@0
|
64 |
}
|
sl@0
|
65 |
|
sl@0
|
66 |
void testFailed(const TDesC& anError)
|
sl@0
|
67 |
{
|
sl@0
|
68 |
test.Printf(_L("Test %S failed\n"),&anError);
|
sl@0
|
69 |
//test.Getch();
|
sl@0
|
70 |
failed=KErrGeneral;
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
void testMemCopy()
|
sl@0
|
74 |
{
|
sl@0
|
75 |
|
sl@0
|
76 |
TText8 bufa[0x200];
|
sl@0
|
77 |
TText8 bufb[0x200];
|
sl@0
|
78 |
|
sl@0
|
79 |
TInt ii,jj,kk;
|
sl@0
|
80 |
|
sl@0
|
81 |
test.Next(_L("Mem::Copy"));
|
sl@0
|
82 |
//
|
sl@0
|
83 |
// Test various copying lengths and alignments and src before/after trg
|
sl@0
|
84 |
//
|
sl@0
|
85 |
TInt length;
|
sl@0
|
86 |
TChar a55(0x55);
|
sl@0
|
87 |
TChar aAA(0xaa);
|
sl@0
|
88 |
|
sl@0
|
89 |
TUint8* addr;
|
sl@0
|
90 |
|
sl@0
|
91 |
for(ii=24;ii<496;ii+=19)
|
sl@0
|
92 |
{
|
sl@0
|
93 |
for(jj=24;jj<496;jj+=18)
|
sl@0
|
94 |
{
|
sl@0
|
95 |
length=Min(496-jj,496-ii);
|
sl@0
|
96 |
|
sl@0
|
97 |
Mem::Fill(&bufa[0],512,a55);
|
sl@0
|
98 |
Mem::Fill(&bufb[0],512,aAA);
|
sl@0
|
99 |
|
sl@0
|
100 |
addr=Mem::Copy(&bufa[ii],&bufb[jj],length);
|
sl@0
|
101 |
|
sl@0
|
102 |
if(addr!=(&bufa[ii]+length))
|
sl@0
|
103 |
{
|
sl@0
|
104 |
PrintInfo(bufb,bufa);
|
sl@0
|
105 |
test.Printf(_L("Mem::Copy returned incorrect address for %d bytes\n"),length);
|
sl@0
|
106 |
failed=KErrGeneral;
|
sl@0
|
107 |
//test.Getch();
|
sl@0
|
108 |
return;
|
sl@0
|
109 |
}
|
sl@0
|
110 |
|
sl@0
|
111 |
for(kk=0;kk<512;kk++)
|
sl@0
|
112 |
{
|
sl@0
|
113 |
if(kk<ii && bufa[kk]!=0x55)
|
sl@0
|
114 |
{
|
sl@0
|
115 |
PrintInfo(bufb,bufa);
|
sl@0
|
116 |
test.Printf(_L("Mem::Copy failed copying %d bytes from bufb[%d] to bufa[%d] at byte %d\n"),length,jj,ii,kk);
|
sl@0
|
117 |
failed=KErrGeneral;
|
sl@0
|
118 |
//test.Getch();
|
sl@0
|
119 |
return;
|
sl@0
|
120 |
}
|
sl@0
|
121 |
if(kk>=ii && kk<(ii+length) && bufa[kk]!=0xaa)
|
sl@0
|
122 |
{
|
sl@0
|
123 |
PrintInfo(bufb,bufa);
|
sl@0
|
124 |
test.Printf(_L("Mem::Copy failed copying %d bytes from bufb[%d] to bufa[%d] at byte %d\n"),length,jj,ii,kk);
|
sl@0
|
125 |
failed=KErrGeneral;
|
sl@0
|
126 |
//test.Getch();
|
sl@0
|
127 |
return;
|
sl@0
|
128 |
}
|
sl@0
|
129 |
if(kk>=(ii+length) && bufa[kk]!=0x55)
|
sl@0
|
130 |
{
|
sl@0
|
131 |
PrintInfo(bufb,bufa);
|
sl@0
|
132 |
test.Printf(_L("Mem::Copy failed copying %d bytes from bufb[%d] to bufa[%d] at byte %d\n"),length,jj,ii,kk);
|
sl@0
|
133 |
failed=KErrGeneral;
|
sl@0
|
134 |
//test.Getch();
|
sl@0
|
135 |
return;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
}
|
sl@0
|
138 |
|
sl@0
|
139 |
Mem::Fill(&bufa[0],512,a55);
|
sl@0
|
140 |
Mem::Fill(&bufb[0],512,aAA);
|
sl@0
|
141 |
|
sl@0
|
142 |
length=Min(496-jj,496-ii);
|
sl@0
|
143 |
|
sl@0
|
144 |
addr=Mem::Copy(&bufb[ii],&bufa[jj],length);
|
sl@0
|
145 |
|
sl@0
|
146 |
if(addr!=(&bufb[ii]+length))
|
sl@0
|
147 |
{
|
sl@0
|
148 |
PrintInfo(bufa,bufb);
|
sl@0
|
149 |
test.Printf(_L("Mem::Copy returned incorrect address for %d bytes\n"),length);
|
sl@0
|
150 |
failed=KErrGeneral;
|
sl@0
|
151 |
//test.Getch();
|
sl@0
|
152 |
return;
|
sl@0
|
153 |
}
|
sl@0
|
154 |
|
sl@0
|
155 |
for(kk=0;kk<512;kk++)
|
sl@0
|
156 |
{
|
sl@0
|
157 |
if(kk<ii && bufb[kk]!=0xaa)
|
sl@0
|
158 |
{
|
sl@0
|
159 |
PrintInfo(bufa,bufb);
|
sl@0
|
160 |
test.Printf(_L("Mem::Copy failed copying %d bytes from bufa[%d] to bufb[%d] at byte %d\n"),length,jj,ii,kk);
|
sl@0
|
161 |
failed=KErrGeneral;
|
sl@0
|
162 |
//test.Getch();
|
sl@0
|
163 |
return;
|
sl@0
|
164 |
}
|
sl@0
|
165 |
if(kk>=ii && kk<(ii+length) && bufb[kk]!=0x55)
|
sl@0
|
166 |
{
|
sl@0
|
167 |
PrintInfo(bufa,bufb);
|
sl@0
|
168 |
test.Printf(_L("Mem::Copy failed copying %d bytes from bufa[%d] to bufb[%d] at byte %d\n"),length,jj,ii,kk);
|
sl@0
|
169 |
failed=KErrGeneral;
|
sl@0
|
170 |
//test.Getch();
|
sl@0
|
171 |
return;
|
sl@0
|
172 |
}
|
sl@0
|
173 |
if(kk>=(ii+length) && bufb[kk]!=0xaa)
|
sl@0
|
174 |
{
|
sl@0
|
175 |
PrintInfo(bufa,bufb);
|
sl@0
|
176 |
test.Printf(_L("Mem::Copy failed copying %d bytes from bufa[%d] to bufb[%d] at byte %d\n"),length,jj,ii,kk);
|
sl@0
|
177 |
failed=KErrGeneral;
|
sl@0
|
178 |
//test.Getch();
|
sl@0
|
179 |
return;
|
sl@0
|
180 |
}
|
sl@0
|
181 |
}
|
sl@0
|
182 |
};
|
sl@0
|
183 |
}
|
sl@0
|
184 |
}
|
sl@0
|
185 |
|
sl@0
|
186 |
//
|
sl@0
|
187 |
// Assert panic test, debug ARM build only. See DEF118984.
|
sl@0
|
188 |
//
|
sl@0
|
189 |
#if defined(_DEBUG) && defined(__CPU_ARM)
|
sl@0
|
190 |
const TInt KMemMoveBufferSize=0x20;
|
sl@0
|
191 |
const TInt KMemMoveBadLength=3;
|
sl@0
|
192 |
|
sl@0
|
193 |
enum TMemMoveTest
|
sl@0
|
194 |
{
|
sl@0
|
195 |
EMemMoveValid=0,
|
sl@0
|
196 |
EMemMoveSourceNotAligned=1,
|
sl@0
|
197 |
EMemMoveTargetNotAligned=2,
|
sl@0
|
198 |
EMemMoveLengthNotMultipleOf4=3,
|
sl@0
|
199 |
};
|
sl@0
|
200 |
|
sl@0
|
201 |
LOCAL_C TInt MemMoveClient(TAny* aPtr)
|
sl@0
|
202 |
{
|
sl@0
|
203 |
TMemMoveTest aMode = *(TMemMoveTest *)&aPtr;
|
sl@0
|
204 |
TText8 srcbuf[KMemMoveBufferSize];
|
sl@0
|
205 |
TText8 trgbuf[KMemMoveBufferSize];
|
sl@0
|
206 |
TText8 *src=srcbuf, *trg=trgbuf;
|
sl@0
|
207 |
TInt length=KMemMoveBufferSize;
|
sl@0
|
208 |
|
sl@0
|
209 |
switch (aMode)
|
sl@0
|
210 |
{
|
sl@0
|
211 |
case EMemMoveValid:
|
sl@0
|
212 |
break;
|
sl@0
|
213 |
case EMemMoveSourceNotAligned:
|
sl@0
|
214 |
src=&srcbuf[1];
|
sl@0
|
215 |
break;
|
sl@0
|
216 |
case EMemMoveTargetNotAligned:
|
sl@0
|
217 |
trg=&trgbuf[1];
|
sl@0
|
218 |
break;
|
sl@0
|
219 |
case EMemMoveLengthNotMultipleOf4:
|
sl@0
|
220 |
length=KMemMoveBadLength;
|
sl@0
|
221 |
break;
|
sl@0
|
222 |
}
|
sl@0
|
223 |
Mem::Move(trg,src,length);
|
sl@0
|
224 |
return KErrNone;
|
sl@0
|
225 |
}
|
sl@0
|
226 |
#endif //_DEBUG
|
sl@0
|
227 |
|
sl@0
|
228 |
void testMemMove()
|
sl@0
|
229 |
{
|
sl@0
|
230 |
TText8 bufa[0x200];
|
sl@0
|
231 |
TText8 bufb[0x200];
|
sl@0
|
232 |
|
sl@0
|
233 |
TInt ii,jj,kk;
|
sl@0
|
234 |
|
sl@0
|
235 |
test.Next(_L("Mem::Move()"));
|
sl@0
|
236 |
//
|
sl@0
|
237 |
// Test various copying lengths and alignments and src before/after trg
|
sl@0
|
238 |
//
|
sl@0
|
239 |
TInt length;
|
sl@0
|
240 |
TChar a55(0x55);
|
sl@0
|
241 |
TChar aAA(0xaa);
|
sl@0
|
242 |
|
sl@0
|
243 |
TUint8* addr;
|
sl@0
|
244 |
|
sl@0
|
245 |
for(ii=0;ii<512;ii+=24)
|
sl@0
|
246 |
{
|
sl@0
|
247 |
for(jj=0;jj<512;jj+=24)
|
sl@0
|
248 |
{
|
sl@0
|
249 |
length=Min(512-jj,512-ii);
|
sl@0
|
250 |
|
sl@0
|
251 |
Mem::Fill(&bufa[0],512,a55);
|
sl@0
|
252 |
Mem::Fill(&bufb[0],512,aAA);
|
sl@0
|
253 |
|
sl@0
|
254 |
addr=Mem::Move(&bufa[ii],&bufb[jj],length);
|
sl@0
|
255 |
|
sl@0
|
256 |
if(addr!=(&bufa[ii]+length))
|
sl@0
|
257 |
{
|
sl@0
|
258 |
PrintInfo(bufb,bufa);
|
sl@0
|
259 |
test.Printf(_L("Mem::Copy returned incorrect address for %d bytes\n"),length);
|
sl@0
|
260 |
failed=KErrGeneral;
|
sl@0
|
261 |
//test.Getch();
|
sl@0
|
262 |
return;
|
sl@0
|
263 |
}
|
sl@0
|
264 |
|
sl@0
|
265 |
for(kk=0;kk<512;kk++)
|
sl@0
|
266 |
{
|
sl@0
|
267 |
if(kk<ii && bufa[kk]!=0x55)
|
sl@0
|
268 |
{
|
sl@0
|
269 |
PrintInfo(bufb,bufa);
|
sl@0
|
270 |
test.Printf(_L("Mem::Move failed copying %d bytes from bufb[%d] to bufa[%d] at byte %d\n"),length,jj,ii,kk);
|
sl@0
|
271 |
failed=KErrGeneral;
|
sl@0
|
272 |
//test.Getch();
|
sl@0
|
273 |
return;
|
sl@0
|
274 |
}
|
sl@0
|
275 |
if(kk>=ii && kk<(ii+length) && bufa[kk]!=0xaa)
|
sl@0
|
276 |
{
|
sl@0
|
277 |
PrintInfo(bufb,bufa);
|
sl@0
|
278 |
test.Printf(_L("Mem::Move failed copying %d bytes from bufb[%d] to bufa[%d] at byte %d\n"),length,jj,ii,kk);
|
sl@0
|
279 |
failed=KErrGeneral;
|
sl@0
|
280 |
//test.Getch();
|
sl@0
|
281 |
return;
|
sl@0
|
282 |
}
|
sl@0
|
283 |
if(kk>=(ii+length) && bufa[kk]!=0x55)
|
sl@0
|
284 |
{
|
sl@0
|
285 |
PrintInfo(bufb,bufa);
|
sl@0
|
286 |
test.Printf(_L("Mem::Move failed copying %d bytes from bufb[%d] to bufa[%d] at byte %d\n"),length,jj,ii,kk);
|
sl@0
|
287 |
failed=KErrGeneral;
|
sl@0
|
288 |
//test.Getch();
|
sl@0
|
289 |
return;
|
sl@0
|
290 |
}
|
sl@0
|
291 |
}
|
sl@0
|
292 |
|
sl@0
|
293 |
Mem::Fill(&bufa[0],512,a55);
|
sl@0
|
294 |
Mem::Fill(&bufb[0],512,aAA);
|
sl@0
|
295 |
|
sl@0
|
296 |
length=Min(512-jj,512-ii);
|
sl@0
|
297 |
|
sl@0
|
298 |
addr=Mem::Move(&bufb[ii],&bufa[jj],length);
|
sl@0
|
299 |
|
sl@0
|
300 |
if(addr!=(&bufb[ii]+length))
|
sl@0
|
301 |
{
|
sl@0
|
302 |
PrintInfo(bufa,bufb);
|
sl@0
|
303 |
test.Printf(_L("Mem::Copy returned incorrect address for %d bytes\n"),length);
|
sl@0
|
304 |
failed=KErrGeneral;
|
sl@0
|
305 |
//test.Getch();
|
sl@0
|
306 |
return;
|
sl@0
|
307 |
}
|
sl@0
|
308 |
|
sl@0
|
309 |
for(kk=0;kk<512;kk++)
|
sl@0
|
310 |
{
|
sl@0
|
311 |
if(kk<ii && bufb[kk]!=0xaa)
|
sl@0
|
312 |
{
|
sl@0
|
313 |
PrintInfo(bufa,bufb);
|
sl@0
|
314 |
test.Printf(_L("Mem::Move failed copying %d bytes from bufa[%d] to bufb[%d] at byte %d\n"),length,jj,ii,kk);
|
sl@0
|
315 |
failed=KErrGeneral;
|
sl@0
|
316 |
//test.Getch();
|
sl@0
|
317 |
return;
|
sl@0
|
318 |
}
|
sl@0
|
319 |
if(kk>=ii && kk<(ii+length) && bufb[kk]!=0x55)
|
sl@0
|
320 |
{
|
sl@0
|
321 |
PrintInfo(bufa,bufb);
|
sl@0
|
322 |
test.Printf(_L("Mem::Move failed copying %d bytes from bufa[%d] to bufb[%d] at byte %d\n"),length,jj,ii,kk);
|
sl@0
|
323 |
failed=KErrGeneral;
|
sl@0
|
324 |
//test.Getch();
|
sl@0
|
325 |
return;
|
sl@0
|
326 |
}
|
sl@0
|
327 |
if(kk>=(ii+length) && bufb[kk]!=0xaa)
|
sl@0
|
328 |
{
|
sl@0
|
329 |
PrintInfo(bufa,bufb);
|
sl@0
|
330 |
test.Printf(_L("Mem::Move failed copying %d bytes from bufa[%d] to bufb[%d] at byte %d\n"),length,jj,ii,kk);
|
sl@0
|
331 |
failed=KErrGeneral;
|
sl@0
|
332 |
//test.Getch();
|
sl@0
|
333 |
return;
|
sl@0
|
334 |
}
|
sl@0
|
335 |
}
|
sl@0
|
336 |
};
|
sl@0
|
337 |
}
|
sl@0
|
338 |
#if defined(_DEBUG) && defined(__CPU_ARM)
|
sl@0
|
339 |
//
|
sl@0
|
340 |
// Test wordmove asserts. Source and target addresses are word aligned,
|
sl@0
|
341 |
// and length is a multiple of the word size.
|
sl@0
|
342 |
// Test asserts (debug build only)
|
sl@0
|
343 |
//
|
sl@0
|
344 |
RThread clientThread;
|
sl@0
|
345 |
TRequestStatus status(KRequestPending);
|
sl@0
|
346 |
|
sl@0
|
347 |
User::SetJustInTime(EFalse);
|
sl@0
|
348 |
test.Next(_L("Mem::Move() - wordmove() valid call"));
|
sl@0
|
349 |
test(clientThread.Create(_L("MemMovePanic - Valid"),MemMoveClient,KDefaultStackSize,0x2000,0x2000,(TAny*)EMemMoveValid)==KErrNone);
|
sl@0
|
350 |
clientThread.Logon(status);
|
sl@0
|
351 |
clientThread.Resume();
|
sl@0
|
352 |
User::WaitForRequest(status);
|
sl@0
|
353 |
test(clientThread.ExitType()==EExitKill);
|
sl@0
|
354 |
test(clientThread.ExitReason()==KErrNone);
|
sl@0
|
355 |
clientThread.Close();
|
sl@0
|
356 |
status=KRequestPending;
|
sl@0
|
357 |
test.Next(_L("Mem::Move() - wordmove() source alignment"));
|
sl@0
|
358 |
test(clientThread.Create(_L("MemMovePanic - SrcAlign"),MemMoveClient,KDefaultStackSize,0x2000,0x2000,(TAny*)EMemMoveSourceNotAligned)==KErrNone);
|
sl@0
|
359 |
clientThread.Logon(status);
|
sl@0
|
360 |
clientThread.Resume();
|
sl@0
|
361 |
User::WaitForRequest(status);
|
sl@0
|
362 |
test(clientThread.ExitType()==EExitPanic);
|
sl@0
|
363 |
test(clientThread.ExitReason()==EWordMoveSourceNotAligned);
|
sl@0
|
364 |
clientThread.Close();
|
sl@0
|
365 |
status=KRequestPending;
|
sl@0
|
366 |
test.Next(_L("Mem::Move() - wordmove() target alignment"));
|
sl@0
|
367 |
test(clientThread.Create(_L("MemMovePanic - TrgAlign"),MemMoveClient,KDefaultStackSize,0x2000,0x2000,(TAny*)EMemMoveTargetNotAligned)==KErrNone);
|
sl@0
|
368 |
clientThread.Logon(status);
|
sl@0
|
369 |
clientThread.Resume();
|
sl@0
|
370 |
User::WaitForRequest(status);
|
sl@0
|
371 |
test(clientThread.ExitType()==EExitPanic);
|
sl@0
|
372 |
test(clientThread.ExitReason()==EWordMoveTargetNotAligned);
|
sl@0
|
373 |
clientThread.Close();
|
sl@0
|
374 |
status=KRequestPending;
|
sl@0
|
375 |
test.Next(_L("Mem::Move() - wordmove() length word multiple"));
|
sl@0
|
376 |
test(clientThread.Create(_L("MemMovePanic - LengthMultiple"),MemMoveClient,KDefaultStackSize,0x2000,0x2000,(TAny*)EMemMoveLengthNotMultipleOf4)==KErrNone);
|
sl@0
|
377 |
clientThread.Logon(status);
|
sl@0
|
378 |
clientThread.Resume();
|
sl@0
|
379 |
User::WaitForRequest(status);
|
sl@0
|
380 |
test(clientThread.ExitType()==EExitPanic);
|
sl@0
|
381 |
test(clientThread.ExitReason()==EWordMoveLengthNotMultipleOf4);
|
sl@0
|
382 |
clientThread.Close();
|
sl@0
|
383 |
User::SetJustInTime(ETrue);
|
sl@0
|
384 |
#endif //_DEBUG
|
sl@0
|
385 |
}
|
sl@0
|
386 |
|
sl@0
|
387 |
void testMemFill()
|
sl@0
|
388 |
{
|
sl@0
|
389 |
|
sl@0
|
390 |
TText8 bufa[0x200];
|
sl@0
|
391 |
|
sl@0
|
392 |
TInt ii,jj,kk,pos,length;
|
sl@0
|
393 |
|
sl@0
|
394 |
test.Next(_L("Mem::Fill()"));
|
sl@0
|
395 |
|
sl@0
|
396 |
TChar a55(0x55);
|
sl@0
|
397 |
TChar aAA(0xaa);
|
sl@0
|
398 |
|
sl@0
|
399 |
for(ii=0;ii<512-32;ii++)
|
sl@0
|
400 |
{
|
sl@0
|
401 |
for(jj=0;jj<32;jj++)
|
sl@0
|
402 |
{
|
sl@0
|
403 |
Mem::Fill(&bufa[0],512,aAA);
|
sl@0
|
404 |
|
sl@0
|
405 |
pos=ii+jj;
|
sl@0
|
406 |
length=512-32-ii;
|
sl@0
|
407 |
|
sl@0
|
408 |
Mem::Fill(&bufa[pos],length,a55);
|
sl@0
|
409 |
|
sl@0
|
410 |
for(kk=0;kk<512;kk++)
|
sl@0
|
411 |
{
|
sl@0
|
412 |
if(kk<(pos) && bufa[kk]!=0xaa)
|
sl@0
|
413 |
{
|
sl@0
|
414 |
test.Printf(_L("Mem::Fill failed filling %d bytes to bufa[%d] at byte %d (1)\n"),length,pos,kk);
|
sl@0
|
415 |
failed=KErrGeneral;
|
sl@0
|
416 |
//test.Getch();
|
sl@0
|
417 |
return;
|
sl@0
|
418 |
}
|
sl@0
|
419 |
if(kk>=(pos) && kk<(pos+length) && bufa[kk]!=0x55)
|
sl@0
|
420 |
{
|
sl@0
|
421 |
test.Printf(_L("Mem::Fill failed filling %d bytes to bufa[%d] at byte %d (2)\n"),length,pos,kk);
|
sl@0
|
422 |
failed=KErrGeneral;
|
sl@0
|
423 |
//test.Getch();
|
sl@0
|
424 |
return;
|
sl@0
|
425 |
}
|
sl@0
|
426 |
if(kk>=(pos+length) && bufa[kk]!=0xaa)
|
sl@0
|
427 |
{
|
sl@0
|
428 |
test.Printf(_L("Mem::Fill failed filling %d bytes to bufa[%d] at byte %d (3)\n"),length,pos,kk);
|
sl@0
|
429 |
failed=KErrGeneral;
|
sl@0
|
430 |
//test.Getch();
|
sl@0
|
431 |
return;
|
sl@0
|
432 |
}
|
sl@0
|
433 |
}
|
sl@0
|
434 |
}
|
sl@0
|
435 |
}
|
sl@0
|
436 |
}
|
sl@0
|
437 |
|
sl@0
|
438 |
void testMemSwap()
|
sl@0
|
439 |
{
|
sl@0
|
440 |
|
sl@0
|
441 |
test.Next(_L("Mem::Swap()"));
|
sl@0
|
442 |
|
sl@0
|
443 |
TText8 bufa[0x200];
|
sl@0
|
444 |
TText8 bufb[0x200];
|
sl@0
|
445 |
|
sl@0
|
446 |
TInt ii,jj,kk;
|
sl@0
|
447 |
|
sl@0
|
448 |
TInt length;
|
sl@0
|
449 |
TChar a55(0x55);
|
sl@0
|
450 |
TChar aAA(0xaa);
|
sl@0
|
451 |
|
sl@0
|
452 |
for(ii=24;ii<496;ii+=5)
|
sl@0
|
453 |
{
|
sl@0
|
454 |
for(jj=24;jj<496;jj+=3)
|
sl@0
|
455 |
{
|
sl@0
|
456 |
length=Min(496-jj,496-ii);
|
sl@0
|
457 |
|
sl@0
|
458 |
Mem::Fill(&bufa[0],512,a55);
|
sl@0
|
459 |
Mem::Fill(&bufb[0],512,aAA);
|
sl@0
|
460 |
|
sl@0
|
461 |
Mem::Swap(&bufa[ii],&bufb[jj],length);
|
sl@0
|
462 |
|
sl@0
|
463 |
for(kk=0;kk<512;kk++)
|
sl@0
|
464 |
{
|
sl@0
|
465 |
if(kk<ii && bufa[kk]!=0x55)
|
sl@0
|
466 |
{
|
sl@0
|
467 |
test.Printf(_L("Mem::Swap failed. bufa[%d] contains wrong byte. Swap length=%d, ii=%d, jj=%d\n"),kk,length,ii,jj);
|
sl@0
|
468 |
failed=KErrGeneral;
|
sl@0
|
469 |
//test.Getch();
|
sl@0
|
470 |
}
|
sl@0
|
471 |
if(kk>=ii && kk<(ii+length) && bufa[kk]!=0xaa)
|
sl@0
|
472 |
{
|
sl@0
|
473 |
test.Printf(_L("Mem::Swap failed. bufa[%d] contains wrong byte. Swap length=%d, ii=%d, jj=%d\n"),kk,length,ii,jj);
|
sl@0
|
474 |
failed=KErrGeneral;
|
sl@0
|
475 |
//test.Getch();
|
sl@0
|
476 |
}
|
sl@0
|
477 |
if(kk>=(ii+length) && bufa[kk]!=0x55)
|
sl@0
|
478 |
{
|
sl@0
|
479 |
test.Printf(_L("Mem::Swap failed. bufa[%d] contains wrong byte. Swap length=%d, ii=%d, jj=%d\n"),kk,length,ii,jj);
|
sl@0
|
480 |
failed=KErrGeneral;
|
sl@0
|
481 |
//test.Getch();
|
sl@0
|
482 |
}
|
sl@0
|
483 |
if(kk<jj && bufb[kk]!=0xaa)
|
sl@0
|
484 |
{
|
sl@0
|
485 |
test.Printf(_L("Mem::Swap failed. bufb[%d] contains wrong byte. Swap length=%d, ii=%d, jj=%d\n"),kk,length,ii,jj);
|
sl@0
|
486 |
failed=KErrGeneral;
|
sl@0
|
487 |
//test.Getch();
|
sl@0
|
488 |
}
|
sl@0
|
489 |
if(kk>=jj && kk<(jj+length) && bufb[kk]!=0x55)
|
sl@0
|
490 |
{
|
sl@0
|
491 |
test.Printf(_L("Mem::Swap failed. bufb[%d] contains wrong byte. Swap length=%d, ii=%d, jj=%d\n"),kk,length,ii,jj);
|
sl@0
|
492 |
failed=KErrGeneral;
|
sl@0
|
493 |
//test.Getch();
|
sl@0
|
494 |
}
|
sl@0
|
495 |
if(kk>=(jj+length) && bufb[kk]!=0xaa)
|
sl@0
|
496 |
{
|
sl@0
|
497 |
test.Printf(_L("Mem::Swap failed. bufb[%d] contains wrong byte. Swap length=%d, ii=%d, jj=%d\n"),kk,length,ii,jj);
|
sl@0
|
498 |
failed=KErrGeneral;
|
sl@0
|
499 |
//test.Getch();
|
sl@0
|
500 |
}
|
sl@0
|
501 |
}
|
sl@0
|
502 |
}
|
sl@0
|
503 |
}
|
sl@0
|
504 |
}
|
sl@0
|
505 |
|
sl@0
|
506 |
void testMemCompare()
|
sl@0
|
507 |
{
|
sl@0
|
508 |
|
sl@0
|
509 |
TText8 bufa[516];
|
sl@0
|
510 |
TText8 bufb[516];
|
sl@0
|
511 |
|
sl@0
|
512 |
test.Next(_L("Mem::Compare()"));
|
sl@0
|
513 |
|
sl@0
|
514 |
TInt ii,jj,kk;
|
sl@0
|
515 |
|
sl@0
|
516 |
TChar a55(0x55);
|
sl@0
|
517 |
TChar a11(0x11);
|
sl@0
|
518 |
TChar a99(0x99);
|
sl@0
|
519 |
|
sl@0
|
520 |
TInt posi,posj,offi,offj,leni,lenj;
|
sl@0
|
521 |
|
sl@0
|
522 |
for(ii=0;ii<512;ii+=2)
|
sl@0
|
523 |
{
|
sl@0
|
524 |
for(jj=0;jj<512;jj+=3)
|
sl@0
|
525 |
{
|
sl@0
|
526 |
Mem::Fill(&bufa[0],512,a55);
|
sl@0
|
527 |
Mem::Fill(&bufb[0],512,a55);
|
sl@0
|
528 |
|
sl@0
|
529 |
posi=(511+ii)/2; // get a position somewhere in the middle
|
sl@0
|
530 |
posj=(511+jj)/2;
|
sl@0
|
531 |
|
sl@0
|
532 |
bufa[posi]=0x12;
|
sl@0
|
533 |
bufb[posj]=0x12;
|
sl@0
|
534 |
|
sl@0
|
535 |
offi=posi-ii;
|
sl@0
|
536 |
offj=posj-jj;
|
sl@0
|
537 |
|
sl@0
|
538 |
leni=511-ii;
|
sl@0
|
539 |
lenj=511-jj;
|
sl@0
|
540 |
//
|
sl@0
|
541 |
// Make sure that outside the compare range is different
|
sl@0
|
542 |
//
|
sl@0
|
543 |
Mem::Fill(&bufa[ii+leni],4,a11);
|
sl@0
|
544 |
Mem::Fill(&bufb[jj+lenj],4,a99);
|
sl@0
|
545 |
|
sl@0
|
546 |
kk=Mem::Compare(&bufa[ii],leni,&bufb[jj],lenj);
|
sl@0
|
547 |
|
sl@0
|
548 |
if(offi==offj) // Wrong byte is at same offset
|
sl@0
|
549 |
{
|
sl@0
|
550 |
if(ii==jj) // Same lengths being compared, so should compare ok
|
sl@0
|
551 |
{
|
sl@0
|
552 |
if(kk!=0)
|
sl@0
|
553 |
{
|
sl@0
|
554 |
test.Printf(_L("%d returned when offi=%d, offj=%d, ii=%d, jj=%d\n"),kk,offi,offj,ii,jj);
|
sl@0
|
555 |
test.Printf(_L("Should return zero\n"));
|
sl@0
|
556 |
test.Printf(_L("bufa=%d,bufb=%d, leftl=%d, rightl=%d\n"),&bufa[ii],&bufb[jj],leni,lenj);
|
sl@0
|
557 |
//test.Getch();
|
sl@0
|
558 |
failed=KErrGeneral;
|
sl@0
|
559 |
}
|
sl@0
|
560 |
}
|
sl@0
|
561 |
else // Different lengths, so should return difference of lengths
|
sl@0
|
562 |
{
|
sl@0
|
563 |
if(kk!=leni-lenj)
|
sl@0
|
564 |
{
|
sl@0
|
565 |
test.Printf(_L("%d returned when offi=%d, offj=%d, ii=%d, jj=%d\n"),kk,offi,offj,ii,jj);
|
sl@0
|
566 |
test.Printf(_L("Should return difference of the lengths\n"));
|
sl@0
|
567 |
test.Printf(_L("bufa=%d,bufb=%d, leftl=%d, rightl=%d\n"),&bufa[ii],&bufb[jj],leni,lenj);
|
sl@0
|
568 |
//test.Getch();
|
sl@0
|
569 |
failed=KErrGeneral;
|
sl@0
|
570 |
}
|
sl@0
|
571 |
}
|
sl@0
|
572 |
}
|
sl@0
|
573 |
if(offi!=offj) // Wrong byte at different offset
|
sl@0
|
574 |
{
|
sl@0
|
575 |
if(offi<offj && kk!=0x12-0x55)
|
sl@0
|
576 |
{
|
sl@0
|
577 |
test.Printf(_L("%d returned when offi=%d, offj=%d, ii=%d, jj=%d\n"),kk,offi,offj,ii,jj);
|
sl@0
|
578 |
test.Printf(_L("Should return difference of the bytes\n"));
|
sl@0
|
579 |
test.Printf(_L("bufa=%d,bufb=%d, leftl=%d, rightl=%d\n"),&bufa[ii],&bufb[jj],leni,lenj);
|
sl@0
|
580 |
//test.Getch();
|
sl@0
|
581 |
failed=KErrGeneral;
|
sl@0
|
582 |
}
|
sl@0
|
583 |
if(offj<offi && kk!=0x55-0x12)
|
sl@0
|
584 |
{
|
sl@0
|
585 |
test.Printf(_L("%d returned when offi=%d, offj=%d, ii=%d, jj=%d\n"),kk,offi,offj,ii,jj);
|
sl@0
|
586 |
test.Printf(_L("Should return difference of the bytes\n"));
|
sl@0
|
587 |
test.Printf(_L("bufa=%d,bufb=%d, leftl=%d, rightl=%d\n"),&bufa[ii],&bufb[jj],leni,lenj);
|
sl@0
|
588 |
//test.Getch();
|
sl@0
|
589 |
failed=KErrGeneral;
|
sl@0
|
590 |
}
|
sl@0
|
591 |
}
|
sl@0
|
592 |
}
|
sl@0
|
593 |
}
|
sl@0
|
594 |
}
|
sl@0
|
595 |
|
sl@0
|
596 |
void testDesNum()
|
sl@0
|
597 |
{
|
sl@0
|
598 |
|
sl@0
|
599 |
TBuf<36> aBuf;
|
sl@0
|
600 |
|
sl@0
|
601 |
test.Next(_L("Des::Num(EHex)"));
|
sl@0
|
602 |
aBuf.Num(0x1b34a678,EHex);
|
sl@0
|
603 |
if(aBuf!=_L("1b34a678"))
|
sl@0
|
604 |
testFailed(_L("Des::Num(0x1b34a678,EHex)"));
|
sl@0
|
605 |
else
|
sl@0
|
606 |
{
|
sl@0
|
607 |
aBuf.Num(0x1234,EHex);
|
sl@0
|
608 |
if(aBuf!=_L("1234"))
|
sl@0
|
609 |
testFailed(_L("Des::Num(0x1234,EHex)"));
|
sl@0
|
610 |
}
|
sl@0
|
611 |
|
sl@0
|
612 |
test.Next(_L("Des::Num(EDecimal)"));
|
sl@0
|
613 |
aBuf.Num(7462521,EDecimal);
|
sl@0
|
614 |
if(aBuf!=_L("7462521"))
|
sl@0
|
615 |
testFailed(_L("Des::Num(7462521,EDecimal)"));
|
sl@0
|
616 |
else
|
sl@0
|
617 |
{
|
sl@0
|
618 |
aBuf.Num(1234,EDecimal);
|
sl@0
|
619 |
if(aBuf!=_L("1234"))
|
sl@0
|
620 |
testFailed(_L("Des::Num(1234,EDecimal)"));
|
sl@0
|
621 |
}
|
sl@0
|
622 |
|
sl@0
|
623 |
test.Next(_L("Des::Num(EOctal)"));
|
sl@0
|
624 |
|
sl@0
|
625 |
aBuf.Num(03521,EOctal);
|
sl@0
|
626 |
if(aBuf!=_L("3521"))
|
sl@0
|
627 |
testFailed(_L("Des::Num(03521,EOctal)"));
|
sl@0
|
628 |
else
|
sl@0
|
629 |
{
|
sl@0
|
630 |
aBuf.Num(0706321,EOctal);
|
sl@0
|
631 |
if(aBuf!=_L("706321"))
|
sl@0
|
632 |
testFailed(_L("Des::Num(0706321,EOctal)"));
|
sl@0
|
633 |
}
|
sl@0
|
634 |
|
sl@0
|
635 |
test.Next(_L("Des::Num(EBinary)"));
|
sl@0
|
636 |
aBuf.Num(0x92074625,EBinary);
|
sl@0
|
637 |
if(aBuf!=_L("10010010000001110100011000100101"))
|
sl@0
|
638 |
{
|
sl@0
|
639 |
testFailed(_L("Des::Num(0x92074625,EBinary)"));
|
sl@0
|
640 |
}
|
sl@0
|
641 |
else
|
sl@0
|
642 |
{
|
sl@0
|
643 |
aBuf.Num(0x4625,EBinary);
|
sl@0
|
644 |
if(aBuf!=_L("100011000100101"))
|
sl@0
|
645 |
testFailed(_L("Des::Num(0x4625,EBinary)"));
|
sl@0
|
646 |
}
|
sl@0
|
647 |
}
|
sl@0
|
648 |
|
sl@0
|
649 |
void testDesNumUC()
|
sl@0
|
650 |
{
|
sl@0
|
651 |
|
sl@0
|
652 |
TBuf<36> aBuf;
|
sl@0
|
653 |
|
sl@0
|
654 |
test.Next(_L("Des::NumUC(EHex)"));
|
sl@0
|
655 |
aBuf.NumUC(0x1b3ca678,EHex);
|
sl@0
|
656 |
if(aBuf!=_L("1B3CA678"))
|
sl@0
|
657 |
testFailed(_L("Des::NumUC(0x1b3ca678,EHex)"));
|
sl@0
|
658 |
else
|
sl@0
|
659 |
{
|
sl@0
|
660 |
aBuf.NumUC(0x89abcdef,EHex);
|
sl@0
|
661 |
if(aBuf!=_L("89ABCDEF"))
|
sl@0
|
662 |
testFailed(_L("Des::NumUC(0x89abcdef,EHex)"));
|
sl@0
|
663 |
}
|
sl@0
|
664 |
|
sl@0
|
665 |
test.Next(_L("Des::NumUC(EDecimal)"));
|
sl@0
|
666 |
aBuf.NumUC(7462521,EDecimal);
|
sl@0
|
667 |
if(aBuf!=_L("7462521"))
|
sl@0
|
668 |
testFailed(_L("Des::NumUC(7462521,EDecimal)"));
|
sl@0
|
669 |
else
|
sl@0
|
670 |
{
|
sl@0
|
671 |
aBuf.NumUC(1234,EDecimal);
|
sl@0
|
672 |
if(aBuf!=_L("1234"))
|
sl@0
|
673 |
testFailed(_L("Des::NumUC(1234,EDecimal)"));
|
sl@0
|
674 |
}
|
sl@0
|
675 |
|
sl@0
|
676 |
test.Next(_L("Des::NumUC(EOctal)"));
|
sl@0
|
677 |
|
sl@0
|
678 |
aBuf.NumUC(03521,EOctal);
|
sl@0
|
679 |
if(aBuf!=_L("3521"))
|
sl@0
|
680 |
testFailed(_L("Des::NumUC(03521,EOctal)"));
|
sl@0
|
681 |
else
|
sl@0
|
682 |
{
|
sl@0
|
683 |
aBuf.NumUC(0706321,EOctal);
|
sl@0
|
684 |
if(aBuf!=_L("706321"))
|
sl@0
|
685 |
testFailed(_L("Des::NumUC(0706321,EOctal)"));
|
sl@0
|
686 |
}
|
sl@0
|
687 |
|
sl@0
|
688 |
test.Next(_L("Des::NumUC(EBinary)"));
|
sl@0
|
689 |
aBuf.NumUC(0x92074625,EBinary);
|
sl@0
|
690 |
if(aBuf!=_L("10010010000001110100011000100101"))
|
sl@0
|
691 |
{
|
sl@0
|
692 |
testFailed(_L("Des::NumUC(0x92074625,EBinary)"));
|
sl@0
|
693 |
}
|
sl@0
|
694 |
else
|
sl@0
|
695 |
{
|
sl@0
|
696 |
aBuf.NumUC(0x4625,EBinary);
|
sl@0
|
697 |
if(aBuf!=_L("100011000100101"))
|
sl@0
|
698 |
testFailed(_L("Des::NumUC(0x4625,EBinary)"));
|
sl@0
|
699 |
}
|
sl@0
|
700 |
}
|
sl@0
|
701 |
|
sl@0
|
702 |
void testDivTen(TInt aInc)
|
sl@0
|
703 |
//
|
sl@0
|
704 |
// Always pass aInc as zero. It's just there to stop the compiler
|
sl@0
|
705 |
// optimising the a=a/10 statements out for you. They must be
|
sl@0
|
706 |
// worked out by the operating system at runtime.
|
sl@0
|
707 |
//
|
sl@0
|
708 |
{
|
sl@0
|
709 |
|
sl@0
|
710 |
TUint a=68417814+aInc; // some random unsigned number
|
sl@0
|
711 |
TInt b=-48910759+aInc; // some random signed negative number
|
sl@0
|
712 |
TInt c=2147483647+aInc; // maximum positive number
|
sl@0
|
713 |
TUint d=3147484647u+aInc; // high positive unsigned number
|
sl@0
|
714 |
|
sl@0
|
715 |
TUint ar=68417814/10;
|
sl@0
|
716 |
TInt br=-48910759/10;
|
sl@0
|
717 |
TInt cr=2147483647/10;
|
sl@0
|
718 |
TUint dr=3147484647u/10;
|
sl@0
|
719 |
|
sl@0
|
720 |
a=a/10;
|
sl@0
|
721 |
b=b/10;
|
sl@0
|
722 |
c=c/10;
|
sl@0
|
723 |
d=d/10;
|
sl@0
|
724 |
|
sl@0
|
725 |
test.Next(_L("Integer divide by 10"));
|
sl@0
|
726 |
|
sl@0
|
727 |
if(a!=ar)
|
sl@0
|
728 |
{
|
sl@0
|
729 |
test.Printf(_L("68417814/10 gives %u\n"),a);
|
sl@0
|
730 |
failed=KErrGeneral;
|
sl@0
|
731 |
}
|
sl@0
|
732 |
if(b!=br)
|
sl@0
|
733 |
{
|
sl@0
|
734 |
test.Printf(_L("-48910759/10 gives %d\n"),b);
|
sl@0
|
735 |
failed=KErrGeneral;
|
sl@0
|
736 |
}
|
sl@0
|
737 |
if(c!=cr)
|
sl@0
|
738 |
{
|
sl@0
|
739 |
test.Printf(_L("2147483647/10 gives %d\n"),c);
|
sl@0
|
740 |
failed=KErrGeneral;
|
sl@0
|
741 |
}
|
sl@0
|
742 |
if(d!=dr)
|
sl@0
|
743 |
{
|
sl@0
|
744 |
test.Printf(_L("3147484647/10 gives %u\n"),d);
|
sl@0
|
745 |
failed=KErrGeneral;
|
sl@0
|
746 |
}
|
sl@0
|
747 |
}
|
sl@0
|
748 |
|
sl@0
|
749 |
void testDivSeven(TInt aInc)
|
sl@0
|
750 |
//
|
sl@0
|
751 |
// Always pass aInc as zero. It's just there to stop the compiler
|
sl@0
|
752 |
// optimising the a=a/7 statements out for you. They must be
|
sl@0
|
753 |
// worked out by the operating system at runtime.
|
sl@0
|
754 |
//
|
sl@0
|
755 |
{
|
sl@0
|
756 |
|
sl@0
|
757 |
TUint a=68417814+aInc; // some random unsigned number
|
sl@0
|
758 |
TInt b=-48910759+aInc; // some random signed negative number
|
sl@0
|
759 |
TInt c=2147483647+aInc; // maximum positive number
|
sl@0
|
760 |
TUint d=3147484647u+aInc; // high positive unsigned number
|
sl@0
|
761 |
|
sl@0
|
762 |
TUint ar=68417814/7;
|
sl@0
|
763 |
TInt br=-48910759/7;
|
sl@0
|
764 |
TInt cr=2147483647/7;
|
sl@0
|
765 |
TUint dr=3147484647u/7;
|
sl@0
|
766 |
|
sl@0
|
767 |
a=a/7;
|
sl@0
|
768 |
b=b/7;
|
sl@0
|
769 |
c=c/7;
|
sl@0
|
770 |
d=d/7;
|
sl@0
|
771 |
|
sl@0
|
772 |
test.Next(_L("Integer divide by 7"));
|
sl@0
|
773 |
|
sl@0
|
774 |
if(a!=ar)
|
sl@0
|
775 |
{
|
sl@0
|
776 |
test.Printf(_L("68417814/7 gives %u\n"),a);
|
sl@0
|
777 |
failed=KErrGeneral;
|
sl@0
|
778 |
}
|
sl@0
|
779 |
if(b!=br)
|
sl@0
|
780 |
{
|
sl@0
|
781 |
test.Printf(_L("-48910759/7 gives %d\n"),b);
|
sl@0
|
782 |
failed=KErrGeneral;
|
sl@0
|
783 |
}
|
sl@0
|
784 |
if(c!=cr)
|
sl@0
|
785 |
{
|
sl@0
|
786 |
test.Printf(_L("2147483647/7 gives %d\n"),c);
|
sl@0
|
787 |
failed=KErrGeneral;
|
sl@0
|
788 |
}
|
sl@0
|
789 |
if(d!=dr)
|
sl@0
|
790 |
{
|
sl@0
|
791 |
test.Printf(_L("3147484647/7 gives %u\n"),d);
|
sl@0
|
792 |
failed=KErrGeneral;
|
sl@0
|
793 |
}
|
sl@0
|
794 |
}
|
sl@0
|
795 |
|
sl@0
|
796 |
void testDivFive(TInt aInc)
|
sl@0
|
797 |
//
|
sl@0
|
798 |
// Always pass aInc as zero. It's just there to stop the compiler
|
sl@0
|
799 |
// optimising the a=a/5 statements out for you. They must be
|
sl@0
|
800 |
// worked out by the operating system at runtime.
|
sl@0
|
801 |
//
|
sl@0
|
802 |
{
|
sl@0
|
803 |
|
sl@0
|
804 |
TUint a=68417814+aInc; // some random unsigned number
|
sl@0
|
805 |
TInt b=-48910759+aInc; // some random signed negative number
|
sl@0
|
806 |
TInt c=2147483647+aInc; // maximum positive number
|
sl@0
|
807 |
TUint d=3147484647u+aInc; // high positive unsigned number
|
sl@0
|
808 |
|
sl@0
|
809 |
TUint ar=68417814/5;
|
sl@0
|
810 |
TInt br=-48910759/5;
|
sl@0
|
811 |
TInt cr=2147483647/5;
|
sl@0
|
812 |
TUint dr=3147484647u/5;
|
sl@0
|
813 |
|
sl@0
|
814 |
a=a/5;
|
sl@0
|
815 |
b=b/5;
|
sl@0
|
816 |
c=c/5;
|
sl@0
|
817 |
d=d/5;
|
sl@0
|
818 |
|
sl@0
|
819 |
test.Next(_L("Integer divide by 5"));
|
sl@0
|
820 |
|
sl@0
|
821 |
if(a!=ar)
|
sl@0
|
822 |
{
|
sl@0
|
823 |
test.Printf(_L("68417814/5 gives %u\n"),a);
|
sl@0
|
824 |
failed=KErrGeneral;
|
sl@0
|
825 |
}
|
sl@0
|
826 |
if(b!=br)
|
sl@0
|
827 |
{
|
sl@0
|
828 |
test.Printf(_L("-48910759/5 gives %d\n"),b);
|
sl@0
|
829 |
failed=KErrGeneral;
|
sl@0
|
830 |
}
|
sl@0
|
831 |
if(c!=cr)
|
sl@0
|
832 |
{
|
sl@0
|
833 |
test.Printf(_L("2147483647/5 gives %d\n"),c);
|
sl@0
|
834 |
failed=KErrGeneral;
|
sl@0
|
835 |
}
|
sl@0
|
836 |
if(d!=dr)
|
sl@0
|
837 |
{
|
sl@0
|
838 |
test.Printf(_L("3147484647/5 gives %u\n"),d);
|
sl@0
|
839 |
failed=KErrGeneral;
|
sl@0
|
840 |
}
|
sl@0
|
841 |
}
|
sl@0
|
842 |
|
sl@0
|
843 |
void testDivSixteen(TInt aInc)
|
sl@0
|
844 |
//
|
sl@0
|
845 |
// Always pass aInc as zero. It's just there to stop the compiler
|
sl@0
|
846 |
// optimising the a=a/16 statements out for you. They must be
|
sl@0
|
847 |
// worked out by the operating system at runtime.
|
sl@0
|
848 |
//
|
sl@0
|
849 |
{
|
sl@0
|
850 |
|
sl@0
|
851 |
TUint a=68417814+aInc; // some random unsigned number
|
sl@0
|
852 |
TInt b=-48910759+aInc; // some random signed negative number
|
sl@0
|
853 |
TInt c=2147483647+aInc; // maximum positive number
|
sl@0
|
854 |
TUint d=3147484647u+aInc; // high positive unsigned number
|
sl@0
|
855 |
|
sl@0
|
856 |
TUint ar=68417814/16;
|
sl@0
|
857 |
TInt br=-48910759/16;
|
sl@0
|
858 |
TInt cr=2147483647/16;
|
sl@0
|
859 |
TUint dr=3147484647u/16;
|
sl@0
|
860 |
|
sl@0
|
861 |
a=a/16;
|
sl@0
|
862 |
b=b/16;
|
sl@0
|
863 |
c=c/16;
|
sl@0
|
864 |
d=d/16;
|
sl@0
|
865 |
|
sl@0
|
866 |
test.Next(_L("Integer divide by 16"));
|
sl@0
|
867 |
|
sl@0
|
868 |
if(a!=ar)
|
sl@0
|
869 |
{
|
sl@0
|
870 |
test.Printf(_L("68417814/16 gives %u\n"),a);
|
sl@0
|
871 |
failed=KErrGeneral;
|
sl@0
|
872 |
}
|
sl@0
|
873 |
if(b!=br)
|
sl@0
|
874 |
{
|
sl@0
|
875 |
test.Printf(_L("-48910759/16 gives %d\n"),b);
|
sl@0
|
876 |
failed=KErrGeneral;
|
sl@0
|
877 |
}
|
sl@0
|
878 |
if(c!=cr)
|
sl@0
|
879 |
{
|
sl@0
|
880 |
test.Printf(_L("2147483647/16 gives %d\n"),c);
|
sl@0
|
881 |
failed=KErrGeneral;
|
sl@0
|
882 |
}
|
sl@0
|
883 |
if(d!=dr)
|
sl@0
|
884 |
{
|
sl@0
|
885 |
test.Printf(_L("3147484647/16 gives %u\n"),d);
|
sl@0
|
886 |
failed=KErrGeneral;
|
sl@0
|
887 |
}
|
sl@0
|
888 |
}
|
sl@0
|
889 |
|
sl@0
|
890 |
void testModulo(TInt aInc)
|
sl@0
|
891 |
{
|
sl@0
|
892 |
|
sl@0
|
893 |
test.Next(_L("Integer modulo"));
|
sl@0
|
894 |
|
sl@0
|
895 |
TInt ii,kk;
|
sl@0
|
896 |
|
sl@0
|
897 |
for(kk=1;kk<32;kk++)
|
sl@0
|
898 |
{
|
sl@0
|
899 |
for(ii=0;ii<kk;ii++)
|
sl@0
|
900 |
{
|
sl@0
|
901 |
TInt jj=(kk*73)+aInc+ii;
|
sl@0
|
902 |
|
sl@0
|
903 |
if((jj%kk)!=ii)
|
sl@0
|
904 |
{
|
sl@0
|
905 |
test.Printf(_L("%d mod %d gives %d\n"),jj,kk,jj%kk);
|
sl@0
|
906 |
failed=KErrGeneral;
|
sl@0
|
907 |
}
|
sl@0
|
908 |
}
|
sl@0
|
909 |
}
|
sl@0
|
910 |
}
|
sl@0
|
911 |
|
sl@0
|
912 |
TInt E32Main()
|
sl@0
|
913 |
//
|
sl@0
|
914 |
// Benchmark for Mem functions
|
sl@0
|
915 |
//
|
sl@0
|
916 |
{
|
sl@0
|
917 |
|
sl@0
|
918 |
failed=KErrNone;
|
sl@0
|
919 |
|
sl@0
|
920 |
test.Title();
|
sl@0
|
921 |
test.Start(_L("T_FUNC"));
|
sl@0
|
922 |
|
sl@0
|
923 |
testMemCopy();
|
sl@0
|
924 |
testMemMove();
|
sl@0
|
925 |
testMemFill();
|
sl@0
|
926 |
testMemSwap();
|
sl@0
|
927 |
testMemCompare();
|
sl@0
|
928 |
testDesNum();
|
sl@0
|
929 |
testDesNumUC();
|
sl@0
|
930 |
testDivTen(0);
|
sl@0
|
931 |
testDivSixteen(0);
|
sl@0
|
932 |
testDivFive(0);
|
sl@0
|
933 |
testDivSeven(0);
|
sl@0
|
934 |
testModulo(0);
|
sl@0
|
935 |
|
sl@0
|
936 |
test(failed==KErrNone);
|
sl@0
|
937 |
|
sl@0
|
938 |
test.End();
|
sl@0
|
939 |
return(KErrNone);
|
sl@0
|
940 |
}
|
sl@0
|
941 |
|