os/kernelhwsrv/kerneltest/f32test/shostmassstorage/msman/test/t_msvbus.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
/*
sl@0
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description:
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
sl@0
    27
#include "rusbhostsession.h"
sl@0
    28
#include "rusbotgsession.h"
sl@0
    29
sl@0
    30
#include "cmsdrive.h"
sl@0
    31
#include "tmsprintdrive.h"
sl@0
    32
#include "ttestutils.h"
sl@0
    33
#include "tmslog.h"
sl@0
    34
sl@0
    35
RTest test(_L("T_MSVBUS"));
sl@0
    36
RFs fsSession;
sl@0
    37
RUsbOtgSession usbOtgSession;
sl@0
    38
sl@0
    39
extern CMsDrive* msDrive;
sl@0
    40
sl@0
    41
sl@0
    42
void Test1L()
sl@0
    43
    {
sl@0
    44
    test.Start(_L("Test1"));
sl@0
    45
    test.Next(_L("Test1"));
sl@0
    46
sl@0
    47
    usbOtgSession.BusDrop();
sl@0
    48
    usbOtgSession.DeviceInserted();
sl@0
    49
sl@0
    50
    TTestTimer iTimer;
sl@0
    51
    // #1
sl@0
    52
    // wait for suspend
sl@0
    53
sl@0
    54
    iTimer.Start();
sl@0
    55
    TBool usbActive = TTestUtils::WaitForConnectionStateEventL();
sl@0
    56
    test(usbActive == EFalse);
sl@0
    57
    iTimer.End();
sl@0
    58
sl@0
    59
    // #2
sl@0
    60
    // wait for suspend
sl@0
    61
    iTimer.Start();
sl@0
    62
    usbActive = TTestUtils::WaitForConnectionStateEventL();
sl@0
    63
    iTimer.End();
sl@0
    64
    test(usbActive == EFalse);
sl@0
    65
sl@0
    66
    // #3
sl@0
    67
    // wait for suspend
sl@0
    68
    iTimer.Start();
sl@0
    69
    usbActive = TTestUtils::WaitForConnectionStateEventL();
sl@0
    70
    iTimer.End();
sl@0
    71
    test(usbActive == EFalse);
sl@0
    72
sl@0
    73
    // #4
sl@0
    74
    // wait for suspend
sl@0
    75
    iTimer.Start();
sl@0
    76
    usbActive = TTestUtils::WaitForConnectionStateEventL();
sl@0
    77
    iTimer.End();
sl@0
    78
    test(usbActive == EFalse);
sl@0
    79
    test.End();
sl@0
    80
    }
sl@0
    81
sl@0
    82
sl@0
    83
sl@0
    84
void CallTestsL()
sl@0
    85
    {
sl@0
    86
    CleanupClosePushL(fsSession);
sl@0
    87
    User::LeaveIfError(fsSession.Connect());
sl@0
    88
sl@0
    89
    TTestUtils::WaitForBusEventL();
sl@0
    90
sl@0
    91
    Test1L();
sl@0
    92
sl@0
    93
    CleanupStack::PopAndDestroy();
sl@0
    94
    }
sl@0
    95
sl@0
    96
sl@0
    97
GLDEF_C void MainL()
sl@0
    98
    {
sl@0
    99
    __MSFNSLOG
sl@0
   100
sl@0
   101
    TInt err;
sl@0
   102
sl@0
   103
    RUsbHostSession usbHostSession;
sl@0
   104
    err = usbHostSession.Connect();
sl@0
   105
    User::LeaveIfError(err);
sl@0
   106
    CleanupClosePushL(usbHostSession);
sl@0
   107
    test.Printf(_L("USB Host Server Connected\n"));
sl@0
   108
sl@0
   109
    err = usbHostSession.Start();
sl@0
   110
    User::LeaveIfError(err);
sl@0
   111
    test.Printf(_L("USB Host Server Started\n"));
sl@0
   112
sl@0
   113
    err = usbOtgSession.Connect();
sl@0
   114
    User::LeaveIfError(err);
sl@0
   115
    CleanupClosePushL(usbOtgSession);
sl@0
   116
    test.Printf(_L("USB OTG Server Connected\n"));
sl@0
   117
sl@0
   118
    TBool deviceInserted;
sl@0
   119
    deviceInserted = usbOtgSession.DeviceInserted();
sl@0
   120
    RDebug::Printf(">>>>>>>>>>>> %d", deviceInserted);
sl@0
   121
sl@0
   122
    CallTestsL();
sl@0
   123
sl@0
   124
    test.Printf(_L("Destroying sessions...\n"));
sl@0
   125
    test.Printf(_L("Destroying USB OTG session...\n"));
sl@0
   126
    CleanupStack::PopAndDestroy(&usbOtgSession);
sl@0
   127
sl@0
   128
    test.Printf(_L("Destroying USB Host session...\n"));
sl@0
   129
    CleanupStack::PopAndDestroy(&usbHostSession);
sl@0
   130
    test.Printf(_L("Sessions Destroyed.\n"));
sl@0
   131
    }
sl@0
   132
sl@0
   133
sl@0
   134
GLDEF_C TInt E32Main()
sl@0
   135
	{
sl@0
   136
    CTrapCleanup* cleanup = CTrapCleanup::New();
sl@0
   137
	__UHEAP_MARK;
sl@0
   138
    test.Title();
sl@0
   139
    test.Start(_L("Starting tests..."));
sl@0
   140
sl@0
   141
	TTime timerC;
sl@0
   142
	timerC.HomeTime();
sl@0
   143
sl@0
   144
	TRAPD(err, MainL());
sl@0
   145
sl@0
   146
    if (err != KErrNone)
sl@0
   147
       {
sl@0
   148
       RDebug::Print(_L("MainL error: %d\n"),err);
sl@0
   149
       }
sl@0
   150
sl@0
   151
    TTime endTimeC;
sl@0
   152
    endTimeC.HomeTime();
sl@0
   153
    TTimeIntervalSeconds timeTakenC;
sl@0
   154
    err = endTimeC.SecondsFrom(timerC,timeTakenC);
sl@0
   155
    test(err == KErrNone);
sl@0
   156
    test.Printf(_L("Time taken for test = %d seconds\n"),timeTakenC.Int());
sl@0
   157
sl@0
   158
	test.End();
sl@0
   159
	test.Close();
sl@0
   160
	__UHEAP_MARKEND;
sl@0
   161
	delete cleanup;
sl@0
   162
	return KErrNone;
sl@0
   163
	}