kerneltest/e32test/misc/drvread.cpp
changeset 0 a41df078684a
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     1 // Copyright (c) 1997-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 "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // e32test\misc\drvread.cpp
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <e32test.h>
       
    19 #include <e32svr.h>
       
    20 #include <d32locd.h>
       
    21 
       
    22 RTest test(_L("DriveRead"));
       
    23 CConsoleBase* C;
       
    24 TRequestStatus KeyStat;
       
    25 TBool Changed;
       
    26 TBusLocalDrive D;
       
    27 TInt Drive;
       
    28 
       
    29 void OpenDrive()
       
    30 	{
       
    31 	D.Close();
       
    32 	TInt r=D.Connect(Drive, Changed);
       
    33 	test(r==KErrNone);
       
    34 	}
       
    35 
       
    36 TInt Inkey()
       
    37 	{
       
    38 	if (KeyStat==KRequestPending)
       
    39 		return -1;
       
    40 	User::WaitForRequest(KeyStat);
       
    41 	TKeyCode k=C->KeyCode();
       
    42 	C->Read(KeyStat);
       
    43 	return (TInt)k;
       
    44 	}
       
    45 
       
    46 void ReadDrive(TAny* aDest, const TInt64& aPos, TInt aSize)
       
    47 	{
       
    48 	TInt64 pos=aPos;
       
    49 	TPtr8 p((TUint8*)aDest, 0, aSize);
       
    50 	TInt r=D.Read(pos, aSize, p);
       
    51 	test(r==KErrNone);
       
    52 	}
       
    53 
       
    54 TInt E32Main()
       
    55 	{
       
    56 	test.Title();
       
    57 	C=test.Console();
       
    58 	C->Read(KeyStat);
       
    59 
       
    60 	TInt increment;
       
    61 	TBuf<256> cmdBuf;
       
    62 	User::CommandLine(cmdBuf);
       
    63 	TLex cmd(cmdBuf);
       
    64 	cmd.SkipSpace();
       
    65 	test(cmd.Val(Drive)==KErrNone);
       
    66 	cmd.SkipSpace();
       
    67 	test(cmd.Val(*(TUint32*)&increment,EHex)==KErrNone);
       
    68 
       
    69 	TInt block_size=0x10000;
       
    70 	TUint8* buf=(TUint8*)User::Alloc(block_size);
       
    71 	test(buf!=NULL);
       
    72 
       
    73 	OpenDrive();
       
    74 
       
    75 	TLocalDriveCapsV2 caps;
       
    76 	TPckg<TLocalDriveCapsV2> capsPckg(caps);
       
    77 	TInt r=D.Caps(capsPckg);
       
    78 	test(r==KErrNone);
       
    79 	TInt64 drive_size=caps.iSize;
       
    80 	TInt64 pos=0;
       
    81 	TUint32 fc=User::NTickCount();
       
    82 	test.Printf(_L("Drive size = %x%08x\n"),I64HIGH(drive_size),I64LOW(drive_size));
       
    83 
       
    84 	FOREVER
       
    85 		{
       
    86 		TInt k=Inkey();
       
    87 		if (k==EKeyEscape)
       
    88 			break;
       
    89 		ReadDrive(buf, pos, block_size);
       
    90 		pos+=TInt64(increment);
       
    91 		if (pos+TInt64(block_size) > drive_size)
       
    92 			pos=0;
       
    93 		if ((User::NTickCount()-fc)>1000)
       
    94 			{
       
    95 			fc=User::NTickCount();
       
    96 			test.Printf(_L("Pos=%x%08x\n"),I64HIGH(pos),I64LOW(pos));
       
    97 			}
       
    98 		}
       
    99 
       
   100 	User::Free(buf);
       
   101 	D.Close();
       
   102 
       
   103 	return 0;
       
   104 	}
       
   105 
       
   106