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