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