os/kernelhwsrv/kerneltest/f32test/shostmassstorage/msman/test/t_msrmb.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 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 //
    15 
    16 
    17 #include <e32def.h>
    18 #include <e32cmn.h>
    19 #include <e32base.h>
    20 #include <f32file.h>
    21 #include <e32cons.h>
    22 #include <e32debug.h>
    23 #define __E32TEST_EXTENSION__
    24 #include <e32test.h>
    25 
    26 #include "cmsdrive.h"
    27 #include "tmsprintdrive.h"
    28 #include "ttestutils.h"
    29 #include "cblockdevicetester.h"
    30 #include "tmslog.h"
    31 
    32 extern CMsDrive* msDrive;
    33 
    34 RTest test(_L("T_MSRMB"));
    35 RFs fsSession;
    36 
    37 class TTests
    38     {
    39 public:
    40     TTests(TInt aDriveNumber);
    41 
    42     void FullFormat();
    43 
    44     void tRemovableSet();
    45     void tRemovableClr();
    46     void RemountDrive();
    47 
    48 private:
    49     TInt iDriveNumber;
    50     };
    51 
    52 TTests::TTests(TInt aDriveNumber)
    53 :   iDriveNumber(aDriveNumber)
    54     {
    55     }
    56 
    57 
    58 void TTests::RemountDrive()
    59     {
    60     TDriveInfo info;
    61     const TUint KMediaRemountForceMediaChange = 0x00000001;
    62 
    63     TRequestStatus changeStatus;
    64     fsSession.NotifyChange(ENotifyAll, changeStatus);
    65 
    66     test.Printf(_L("Remounting the drive\n"));
    67     TInt err = fsSession.RemountDrive(iDriveNumber, NULL, KMediaRemountForceMediaChange);
    68     test(err == KErrNotReady || err == KErrNone);
    69 
    70     do
    71         {
    72         test.Printf(_L("Waiting for media change...\n"));
    73         User::WaitForRequest(changeStatus);
    74 
    75         err = fsSession.Drive(info, iDriveNumber);
    76         test.Printf(_L("Completed\n"));
    77 
    78         fsSession.NotifyChange(ENotifyAll, changeStatus);
    79         }
    80     while (err == KErrNotReady);
    81     fsSession.NotifyChangeCancel(changeStatus);
    82     }
    83 
    84 
    85 void TTests::tRemovableSet()
    86     {
    87     test.Start(_L("tRemovableSet\n"));
    88 
    89     TDriveInfo driveInfo;
    90     TInt err = fsSession.Drive(driveInfo);
    91     test(err == KErrNone);
    92 
    93     test.Printf(_L("DriveInfo DriveAtt= %x\n"), driveInfo.iDriveAtt);
    94 
    95     test(driveInfo.iDriveAtt&KDriveAttRemovable != 0);
    96     test.End();
    97     }
    98 
    99 
   100 void TTests::tRemovableClr()
   101     {
   102     test.Start(_L("tRemovableClr\n"));
   103 
   104     TDriveInfo driveInfo;
   105     TInt err = fsSession.Drive(driveInfo);
   106     test(err == KErrNone);
   107 
   108     test.Printf(_L("DriveInfo DriveAtt= %x\n"), driveInfo.iDriveAtt);
   109 
   110     test(driveInfo.iDriveAtt&KDriveAttRemovable != 0);
   111     test.End();
   112     }
   113 
   114 
   115 void TTests::FullFormat()
   116     {
   117     TInt counter;
   118     RFormat format;
   119     test.Next(_L("Test EFullFormat"));
   120 
   121     TInt err = format.Open(fsSession, msDrive->GetSessionPath(), EFullFormat, counter);
   122     test(err == KErrNone);
   123     while (counter)
   124         {
   125         err = format.Next(counter);
   126         test(err == KErrNone);
   127         }
   128     format.Close();
   129     }
   130 
   131 
   132 
   133 void CallTestsL()
   134     {
   135     TInt driveNumber = msDrive->DriveNumber();
   136     // Print drive info
   137     TRAPD(err, TMsPrintDrive::VolInfoL(driveNumber));
   138     err = err;
   139 
   140     TTests t(driveNumber);
   141 
   142     test.Printf(_L("Preparing target drive..."));
   143     //t.FullFormat();
   144 
   145     CWrPrTester* wpTester = CWrPrTester::NewL(driveNumber);
   146     CleanupStack::PushL(wpTester);
   147     test.Printf(_L("Target drive ready.\n"));
   148 
   149     test.Start(_L("REMOVABLE"));
   150 
   151     test.Next(_L("Test RMB=Set\n"));
   152     err = wpTester->SetRemovableL();
   153     test(err == KErrNone);
   154     t.RemountDrive();
   155     t.tRemovableSet();
   156 
   157     test.Next(_L("Test RMB=Clr\n"));
   158     err = wpTester->ClrRemovableL();
   159     test(err == KErrNone);
   160     t.RemountDrive();
   161     t.tRemovableClr();
   162     test.End();
   163 
   164     CleanupStack::PopAndDestroy(wpTester);
   165     }