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