kerneltest/f32test/shostmassstorage/msman/test/t_mswrpr.cpp
changeset 0 a41df078684a
child 297 b2826f67641f
equal deleted inserted replaced
-1:000000000000 0:a41df078684a
       
     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_MSWRPR"));
       
    35 RFs fsSession;
       
    36 
       
    37 
       
    38 
       
    39 class TTests
       
    40     {
       
    41 public:
       
    42     TTests(TInt aDriveNumber);
       
    43 
       
    44     void FullFormat();
       
    45     void tReadOnly();
       
    46     void tReadWrite();
       
    47     void RemountDrive();
       
    48 
       
    49 private:
       
    50     TInt iDriveNumber;
       
    51     };
       
    52 
       
    53 TTests::TTests(TInt aDriveNumber)
       
    54 :   iDriveNumber(aDriveNumber)
       
    55     {
       
    56     }
       
    57 
       
    58 
       
    59 void TTests::RemountDrive()
       
    60     {
       
    61     TDriveInfo info;
       
    62     const TUint KMediaRemountForceMediaChange = 0x00000001;
       
    63 
       
    64     TRequestStatus changeStatus;
       
    65     fsSession.NotifyChange(ENotifyAll, changeStatus);
       
    66 
       
    67     test.Printf(_L("Remounting the drive\n"));
       
    68     TInt err = fsSession.RemountDrive(iDriveNumber, NULL, KMediaRemountForceMediaChange);
       
    69     test(err == KErrNotReady || err == KErrNone);
       
    70 
       
    71     do
       
    72         {
       
    73         test.Printf(_L("Waiting for media change...\n"));
       
    74         User::WaitForRequest(changeStatus);
       
    75 
       
    76         err = fsSession.Drive(info, iDriveNumber);
       
    77         test.Printf(_L("Completed.\n"));
       
    78 
       
    79         fsSession.NotifyChange(ENotifyAll, changeStatus);
       
    80         }
       
    81     while (err == KErrNotReady);
       
    82     fsSession.NotifyChangeCancel(changeStatus);
       
    83     }
       
    84 
       
    85 void TTests::tReadOnly()
       
    86     {
       
    87     test.Start(_L("tReadOnly\n"));
       
    88 
       
    89     TDriveInfo driveInfo;
       
    90     TInt err = fsSession.Drive(driveInfo);
       
    91     test(err == KErrNone);
       
    92 
       
    93     test.Printf(_L("DriveInfo MediaAtt= 0x%x\n"), driveInfo.iMediaAtt);
       
    94 
       
    95     test((driveInfo.iMediaAtt&KMediaAttWriteProtected) != 0);
       
    96     test.End();
       
    97     }
       
    98 
       
    99 
       
   100 void TTests::tReadWrite()
       
   101     {
       
   102     test.Start(_L("tReadWrite\n"));
       
   103 
       
   104     TDriveInfo driveInfo;
       
   105     TInt err = fsSession.Drive(driveInfo);
       
   106     test(err == KErrNone);
       
   107 
       
   108     test.Printf(_L("DriveInfo MediaAtt = %x %x\n"), driveInfo.iMediaAtt, driveInfo.iMediaAtt&KMediaAttWriteProtected);
       
   109     test((driveInfo.iMediaAtt&KMediaAttWriteProtected) == 0);
       
   110 
       
   111 
       
   112 
       
   113     test.End();
       
   114     }
       
   115 
       
   116 
       
   117 void TTests::FullFormat()
       
   118     {
       
   119     TInt counter;
       
   120     RFormat format;
       
   121     test.Next(_L("Test EFullFormat\n"));
       
   122 
       
   123     TInt err = format.Open(fsSession, msDrive->GetSessionPath(), EFullFormat, counter);
       
   124     test(err == KErrNone);
       
   125     while (counter)
       
   126         {
       
   127         err = format.Next(counter);
       
   128         test(err == KErrNone);
       
   129         }
       
   130     format.Close();
       
   131     }
       
   132 
       
   133 
       
   134 void CallTestsL()
       
   135     {
       
   136     TInt driveNumber = msDrive->DriveNumber();
       
   137     // Print drive info
       
   138     TRAPD(err, TMsPrintDrive::VolInfoL(driveNumber));
       
   139     err = err;
       
   140 
       
   141     TTests t(driveNumber);
       
   142 
       
   143     test.Printf(_L("Preparing target drive..."));
       
   144     //t.FullFormat();
       
   145 
       
   146     CWrPrTester* wpTester = CWrPrTester::NewL(driveNumber);
       
   147     CleanupStack::PushL(wpTester);
       
   148     test.Printf(_L("Target drive ready.\n"));
       
   149 
       
   150     test.Start(_L("**** WRITE PROTECT ****"));
       
   151 
       
   152     t.RemountDrive();
       
   153     t.tReadWrite();
       
   154     err = wpTester->WriteReadTestL();
       
   155     test(err == KErrNone);
       
   156 
       
   157     test.Next(_L("**** Test WP=Set ****"));
       
   158     TRAP(err, wpTester->SetWriteProtectL());
       
   159     test(err == KErrNone);
       
   160     t.RemountDrive();
       
   161     t.tReadOnly();
       
   162     err = wpTester->WriteReadTestL();
       
   163     test(err == KErrAccessDenied);
       
   164 
       
   165     test.Next(_L("**** Test WP=Clr ****"));
       
   166     TRAP(err, wpTester->ClrWriteProtectL());
       
   167     test(err == KErrNone);
       
   168     t.RemountDrive();
       
   169     t.tReadWrite();
       
   170     err = wpTester->WriteReadTestL();
       
   171     test(err == KErrNone);
       
   172 
       
   173     test.End();
       
   174 
       
   175     CleanupStack::PopAndDestroy(wpTester);
       
   176     }