Update contrib.
1 // Copyright (c) 1997-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32test\pccd\t_pccd3.cpp
26 LOCAL_D RTest test(_L("T_PCCD3"));
27 LOCAL_D TBool SimpleCDScheme;
28 LOCAL_D TInt TotalSockets;
29 LOCAL_D RPcCardCntrlIf PccdDrv[KMaxPBusSockets];
31 const TSocket KSocket=0;
36 LOCAL_C void theMediaChangeNotifierTests()
38 // Test UserSvr::MediaChangeNotify() and UserSvr::ForceRemountMedia().
42 test.Next(_L("The media change notifier(s)"));
44 // Test requesting on a non-removable device
45 TRequestStatus rs[KMaxPBusSockets];
46 test(UserSvr::MediaChangeNotify(EFixedMedia0,&rs[0])==KErrNotSupported);
49 test(UserSvr::MediaChangeNotify(ERemovableMedia0,&rs[0])==KErrInUse);
51 test.Printf( _L("<<<THIS WILL BREAK F32 MEDIA CHANGE NOTIFICATION>>>\r\n"));
54 for (socket=0;socket<TotalSockets;socket++)
56 // Register the notifier on all sockets here - out of the main loop to
57 // test operation with multiple outstanding requests on different sockets
58 md=(TMediaDevice)(ERemovableMedia0+socket);
59 test(UserSvr::MediaChangeNotify(md,&rs[socket])==KErrNone);
62 for (socket=0;socket<TotalSockets;socket++)
64 md=(TMediaDevice)(ERemovableMedia0+socket);
65 // Perform the entire test twice
66 for (TInt cycleCount=1;cycleCount<=2;cycleCount++)
70 // Second time around we need to make a request
71 test(UserSvr::MediaChangeNotify(md,&rs[socket])==KErrNone);
73 UserSvr::ForceRemountMedia(md); // Generate media change
74 User::WaitForRequest(rs[socket]); // From door open
75 test(rs[socket].Int()==KErrNone);
76 test.Printf( _L("Media change notify on Socket %d\r\n"),socket);
79 // For CD scheme, the open/close occur too close together to
81 test(UserSvr::MediaChangeNotify(md,&rs[socket])==KErrNone);
82 User::WaitForRequest(rs[socket]); // From door close again
83 test(rs[socket].Int()==KErrNone);
84 test.Printf( _L("Media change notify on Socket %d\r\n"),socket);
89 // Test requesting on an invalid socket for this platform
90 if (TotalSockets<KMaxPBusSockets)
91 test(UserSvr::MediaChangeNotify((TMediaDevice)(ERemovableMedia0+TotalSockets),&rs[0])==KErrGeneral);
96 LOCAL_C void theMediaChangeNotifierTests()
98 // Test UserSvr::MediaChangeNotify() and UserSvr::ForceRemountMedia().
102 test.Next(_L("The media change notifier(s)"));
104 // Test requesting on a non-removable device
106 test(UserSvr::MediaChangeNotify(EFixedMedia0,&rs)==KErrNotSupported);
109 test(UserSvr::MediaChangeNotify(ERemovableMedia0,&rs)==KErrInUse);
111 test.Printf( _L("<<<MEDIA CHANGE NOTIFICATION TESTS DISABLED>>>\r\n"),i);
116 LOCAL_C void thePccdControllerMediaChangeEventTests()
118 // Test registering on media change events
122 test.Next(_L("PC Card Controller - Media change notification"));
125 TRequestStatus rs[KMaxPBusSockets];
127 for (i=0;i<TotalSockets;i++)
128 test(PccdDrv[i].RegisterEvent(EPcCardEvMediaChange,&rs[i])==KErrNone);
130 for (i=0;i<TotalSockets;i++)
132 test.Printf( _L("<<<Insert the card in socket %d >>>\r\n"),i);
133 User::WaitForRequest(rs[i]);
134 test(rs[i].Int()==KErrNone);
141 test(PccdDrv[0].RegisterEvent(EPcCardEvMediaChange,&rs)==KErrNone);
143 #if defined (__WINS__)
144 test.Printf( _L("<<<Hit F5>>>\r\n"));
146 test.Printf( _L("<<<Open and close CF card door>>>\r\n"));
147 test.Printf( _L("<<<Machine will turn off as soon as door is opened>>>\r\n"));
149 User::WaitForRequest(rs);
150 test(rs.Int()==KErrNone);
151 #if defined (__WINS__)
152 // Delay power off until after F5 key up event. Key up doesn't occur when in standby.
153 // Without this the power-on test fails because the simulated door state is stuck open.
159 LOCAL_C void thePccdControllerPowerEventTests()
161 // Test registering on power events
165 test.Next(_L("PC Card Controller - Power-off notification."));
167 TRequestStatus prs, trs;
168 test(timer.CreateLocal()==KErrNone);
169 test(PccdDrv[0].RegisterEvent(EPcCardEvPwrDown,&prs)==KErrNone);
172 tim+=TTimeIntervalSeconds(8);
174 UserHal::SwitchOff();
175 User::WaitForRequest(prs);
176 test(prs.Int()==KErrNone);
177 User::WaitForRequest(trs);
178 test(trs.Int()==KErrNone);
180 test.Next(_L("PC Card Controller - Power-on notification."));
181 test(PccdDrv[0].RegisterEvent(EPcCardEvPwrUp,&prs)==KErrNone);
183 tim+=TTimeIntervalSeconds(8);
185 UserHal::SwitchOff();
186 User::WaitForRequest(prs);
187 test(prs.Int()==KErrNone);
188 User::WaitForRequest(trs);
189 test(trs.Int()==KErrNone);
192 LOCAL_C void thePccdControllerStatusChangeEventTests()
194 // Test registering on status change events
201 // We're going to ask tester to remove CF card in order to generate a card status change
202 // notification. However, on P2s this involves opening the CF card door first. Because of
203 // the media notifier (F32), opening door gives us a spurious RegisterEvent() notification.
204 test.Printf( _L("<<<Open (don't close) media door>>>\r\n"));
205 test(PccdDrv[0].RegisterEvent(EPcCardEvMediaChange,&rs)==KErrNone);
206 User::WaitForRequest(rs);
207 test(rs.Int()==KErrNone);
211 for (i=(TotalSockets-1);i>=0;i--)
213 test.Next(_L("Card status change notification - card removal"));
214 test(PccdDrv[i].RegisterEvent(EPcCardEvIndChange,&rs)==KErrNone);
215 test.Printf( _L("<<<Remove the card from socket %d>>>\r\n"),i);
216 User::WaitForRequest(rs);
217 test(rs.Int()==KErrNone);
219 test.Next(_L("Card status change notification - card insertion"));
220 User::After(200000); // 0.2s
221 TInt j=(i>0)?(i-1):i;
222 test(PccdDrv[j].RegisterEvent(EPcCardEvIndChange,&rs)==KErrNone);
223 test.Printf( _L("<<<Insert the card back into socket %d>>>\r\n"),j);
224 User::WaitForRequest(rs);
225 test(rs.Int()==KErrNone);
230 test.Printf( _L("<<<Close) CF card door>>>\r\n"));
231 test(PccdDrv[0].RegisterEvent(EPcCardEvPwrUp,&rs)==KErrNone);
232 User::WaitForRequest(rs);
233 test(rs.Int()==KErrNone);
237 LOCAL_C void thePccdControllerCardReadyEventTests()
239 // Test registering on ready events (tests 1 socket only!!!!).
243 test.Next(_L("Card ready notification"));
246 r=PccdDrv[0].RegisterEvent(EPcCardEvRdyChange,&rs);
247 if (r==KErrNotSupported)
249 test.Printf( _L("<<<Not supported on this platform>>>\r\n"));
256 test(PccdDrv[0].SocketInfo(s,ind)==KErrNone);
257 test(s==EPcCardNotReady);
258 test(ind.iCardDetected);
261 PccdDrv[0].PwrUp(&prs);
262 User::WaitForRequest(rs);
263 test(rs.Int()==KErrNone);
264 User::WaitForRequest(prs);
265 test(rs.Int()==KErrNone);
268 GLDEF_C TInt E32Main()
272 #if defined (__WINS__)
273 // Connect to all the local drives first as will be the case in ARM
274 TBusLocalDrive Drive[KMaxLocalDrives];
275 TBool ChangedFlag[KMaxLocalDrives];
277 for (j=0;j<KMaxLocalDrives;j++)
278 Drive[j].Connect(j,ChangedFlag[j]);
283 test.Start(_L("Read machine info."));
284 // Find out what sort of media change architecture we have. How many sockets
285 // there are and whether we have a full blown media door scheme or just a system
286 // using the PC Card CD signals. The later information we can't read from the
287 // machine info, the test program just has to be updated with the machine name of
288 // any machine which employs the CD scheme.
289 SimpleCDScheme=EFalse;
291 r=HAL::Get(HAL::EMachineUid, muid);
293 if (muid==HAL::EMachineUid_Brutus)
294 SimpleCDScheme=ETrue;
295 TDriveInfoV1Buf dinfo;
296 UserHal::DriveInfo(dinfo);
297 TotalSockets=dinfo().iTotalSockets;
300 test.Printf( _L("<<<Remove all PC/CF cards - hit a key>>>\r\n"));
304 test.Printf( _L("<<<Insert the card in socket %d - hit a key>>>\r\n"),(TotalSockets-1));
308 test.Next(_L("Load/open logical devices"));
309 r=User::LoadLogicalDevice(_L("D_PCCDIF"));
310 test(r==KErrNone||r==KErrAlreadyExists);
312 for (i=0;i<TotalSockets;i++)
314 r=PccdDrv[i].Open(i,PccdDrv[i].VersionRequired());
318 // Test UserSvr::MediaChangeNotify() and UserSvr::ForceRemountMedia().
319 theMediaChangeNotifierTests();
321 // Test registering on PC Card Controller events
322 thePccdControllerMediaChangeEventTests();
323 thePccdControllerPowerEventTests();
324 #if defined(__EPOC32__)
325 thePccdControllerStatusChangeEventTests();
326 thePccdControllerCardReadyEventTests();
329 test.Next(_L("Close/free devices"));
330 for (i=0;i<TotalSockets;i++)
332 r=User::FreeLogicalDevice(_L("PccdIf"));
337 #if defined (__WINS__)
338 for (i=0;i<KMaxLocalDrives;i++)
339 Drive[i].Disconnect();