kerneltest/f32test/shostmassstorage/msman/test/t_mssuspend.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 "tmslog.h"
       
    30 
       
    31 extern CMsDrive* msDrive;
       
    32 
       
    33 RTest test(_L("T_MSSUSPEND"));
       
    34 RFs fsSession;
       
    35 
       
    36 
       
    37 class TTestMsSuspend
       
    38     {
       
    39 public:
       
    40     void t1L();
       
    41 
       
    42 private:
       
    43     void DrvWrite();
       
    44     };
       
    45 
       
    46 
       
    47 void TTestMsSuspend::t1L()
       
    48     {
       
    49     test.Start(_L("Test"));
       
    50     test.Next(_L("Test1"));
       
    51     TTestTimer iTimer;
       
    52     // #1
       
    53     DrvWrite();
       
    54     // wait for suspend
       
    55     test.Printf(_L("Waiting for host to suspend..."));
       
    56     iTimer.Start();
       
    57     TBool usbActive = TTestUtils::WaitForConnectionStateEventL();
       
    58     test(usbActive == EFalse);
       
    59     iTimer.End();
       
    60 
       
    61     // #2
       
    62     // Resume device by accessing drive
       
    63     DrvWrite();
       
    64     // wait for suspend
       
    65     test.Printf(_L("Waiting for host to suspend..."));
       
    66     iTimer.Start();
       
    67     usbActive = TTestUtils::WaitForConnectionStateEventL();
       
    68     iTimer.End();
       
    69     test(usbActive == EFalse);
       
    70 
       
    71     // #3
       
    72     // Resume device by accessing drive
       
    73     DrvWrite();
       
    74     // wait for suspend
       
    75     test.Printf(_L("Waiting for host to suspend..."));
       
    76     iTimer.Start();
       
    77     usbActive = TTestUtils::WaitForConnectionStateEventL();
       
    78     iTimer.End();
       
    79     test(usbActive == EFalse);
       
    80 
       
    81     // #4
       
    82     // Resume device by accessing drive
       
    83     DrvWrite();
       
    84     // wait for suspend
       
    85     test.Printf(_L("Waiting for host to suspend..."));
       
    86     iTimer.Start();
       
    87     usbActive = TTestUtils::WaitForConnectionStateEventL();
       
    88     iTimer.End();
       
    89     test(usbActive == EFalse);
       
    90     test.End();
       
    91     }
       
    92 
       
    93 
       
    94 void TTestMsSuspend::DrvWrite()
       
    95     {
       
    96     RFile file;
       
    97 
       
    98     static const TInt KFileSize = 1000;
       
    99     _LIT(KTxtControlFile, "ControlFile.txt");
       
   100     static const TChar KFillChar = 'x';
       
   101 
       
   102     TBuf8<KFileSize> testData;
       
   103     testData.Fill(KFillChar, KFileSize);
       
   104 
       
   105     // write control file
       
   106     TInt err = file.Replace(fsSession, KTxtControlFile, EFileStream);
       
   107     test(err == KErrNone);
       
   108 
       
   109     err = file.Write(testData);
       
   110     test(err == KErrNone);
       
   111 
       
   112     file.Close();
       
   113 
       
   114     // delete the file
       
   115     err = fsSession.Delete(KTxtControlFile);
       
   116     test(err == KErrNone);
       
   117     }
       
   118 
       
   119 
       
   120 void CallTestsL()
       
   121     {
       
   122     TInt driveNumber = msDrive->DriveNumber();
       
   123     // Print drive info
       
   124     TRAPD(err, TMsPrintDrive::VolInfoL(driveNumber));
       
   125     err = err;
       
   126     TTestMsSuspend t;
       
   127     t.t1L();
       
   128 
       
   129     }