Update contrib.
1 // Copyright (c) 2004-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 // Component test of Publish and Subscribe
26 #include <e32std_private.h>
29 #include <massstorage.h>
30 #include "t_ms_main.h"
32 #include "scsicmdbuilder.h"
33 #include "cstatemachine.h"
34 #include "cpropertywatch.h"
37 GLREF_D TBuf8<KScsiCmdMaxLen> scsiCmdBuf;
38 GLREF_D RDevTestUsbcClient usbcClient;
42 LOCAL_D TChar driveLetter;
43 GLDEF_D TInt removalDrvNo;
44 GLDEF_D TUint8 testLun(0); // Use MMC card for testing
46 _LIT(KMsFs, "MassStorageFileSystem");
48 #define LOG_AND_TEST(a, e) {if (a!=e) {test.Printf(_L("lvalue %d, rvalue%d\n\r"), a,e); test(EFalse);}}
51 LOCAL_C void ParseCommandArguments()
53 // Parses the command line arguments
57 User::CommandLine(cmd);
60 token.Set(lex.NextToken());
61 if (token.Length() != 0)
63 driveLetter = token[0];
64 driveLetter.UpperCase();
65 test.Printf(_L("CmdLine Param=%S"),&token);
69 test.Printf(_L("No or not enough command line arguments"));
70 // code drive letters based on platform
72 TInt r=HAL::Get(HAL::EMachineUid,uid);
73 LOG_AND_TEST(r,KErrNone);
77 case HAL::EMachineUid_Lubbock:
79 test.Printf(_L("Test is running on Lubbock\r\n"));
82 case HAL::EMachineUid_Win32Emulator:
84 test.Printf(_L("Test is running on Win32 Emulator\r\n"));
88 // Assume it's a H2 board for now as no relevant Enum is found
90 test.Printf(_L("Test is running on H2 board\r\n"));
97 LOCAL_C void doComponentTest()
99 // Do the component test
102 #ifndef __NO_HEAP_CHECK
107 test.Printf(_L("Start MountStart test. Be sure MMC card is inserted.\n"));
108 // Parse the CommandLine argument: removal drive
109 ParseCommandArguments();
111 // Connect to the server
112 LOG_AND_TEST(KErrNone, fs.Connect());
113 CleanupClosePushL(fs);
115 // Convert drive letter to its numerical equivalent
116 ret = fs.CharToDrive(driveLetter,removalDrvNo);
117 LOG_AND_TEST(ret, KErrNone);
119 // Load the logical device
120 _LIT(KDriverFileName,"TESTUSBC.LDD");
121 ret = User::LoadLogicalDevice(KDriverFileName);
122 LOG_AND_TEST(KErrNone, ret);
124 // Add MS file system
125 _LIT(KMsFsFsy, "MSFS.FSY");
126 LOG_AND_TEST(KErrNone, fs.AddFileSystem(KMsFsFsy));
128 // Start Ms file system
129 RUsbMassStorage usbMs;
130 CleanupClosePushL(usbMs);
132 TMassStorageConfig config;
134 config.iVendorId.Copy(_L("vendorId"));
135 config.iProductId.Copy(_L("productId"));
136 config.iProductRev.Copy(_L("rev"));
138 ret = usbMs.Connect();
139 LOG_AND_TEST(KErrNone, ret);
141 // Start usb mass storage device
142 LOG_AND_TEST(KErrNone , usbMs.Start(config));
144 // Format removable drive using FAT FS
146 TBuf<2> removalDrive;
147 removalDrive.Append(driveLetter);
148 removalDrive.Append(':');
149 TInt tracksRemaining;
150 test.Printf(_L("Start MMC card formatting\n"));
151 LOG_AND_TEST(KErrNone, format.Open(fs, removalDrive, EHighDensity|EQuickFormat, tracksRemaining));
152 while (tracksRemaining)
154 test.Printf(_L("."));
155 LOG_AND_TEST(KErrNone, format.Next(tracksRemaining));
158 test.Printf(_L("\nDone!\n"));
160 // Open a session to LDD
161 test.Printf(_L("Open LDD\n"));
162 LOG_AND_TEST(KErrNone, usbcClient.Open(0));
164 test.Printf(_L("Creating CActiveScheduler\n"));
165 CActiveScheduler* sched = new(ELeave) CActiveScheduler;
166 CleanupStack::PushL(sched);
167 CActiveScheduler::Install(sched);
169 // Create a state machine
170 CStateMachine* sm = CStateMachine::NewL();
171 CleanupStack::PushL(sm);
172 sm->AddState(EUsbMsDriveState_Disconnected);
173 sm->AddState(EUsbMsDriveState_Connecting);
174 sm->AddState(EUsbMsDriveState_Connected);
175 sm->AddState(EUsbMsDriveState_Disconnecting);
176 sm->AddState(EUsbMsDriveState_Active);
177 sm->AddState(EUsbMsDriveState_Locked);
178 sm->AddState(EUsbMsState_Written);
179 sm->AddState(EUsbMsState_Read);
181 sm->SetInitState(EUsbMsDriveState_Disconnected);
183 CPropertyHandler* driveStatusHandler = CMsDriveStatusHandler::NewLC(removalDrvNo, *sm);
184 CPropertyHandler* readStatusHandler = CMsReadStatusHandler::NewLC(removalDrvNo, *sm);
185 CPropertyHandler* writtenStatusHandler = CMsWrittenStatusHandler::NewLC(removalDrvNo, *sm);
187 CPropertyWatch::NewLC(EUsbMsDriveState_DriveStatus, *driveStatusHandler);
188 CPropertyWatch::NewLC(EUsbMsDriveState_KBytesRead, *readStatusHandler);
189 CPropertyWatch::NewLC(EUsbMsDriveState_KBytesWritten, *writtenStatusHandler);
191 CActiveScheduler::Start();
194 test.Printf(_L("usbMs.Stop returned %d\n"), ret);
195 test(ret == KErrNone);
197 // 1 sec delay for MSFS to stop
198 User::After(1000000);
199 ret = fs.RemoveFileSystem(KMsFs);
200 test(ret == KErrNone || ret == KErrNotFound);
201 test.Printf(_L("RemoveFileSystem returned %d\n"), ret);
204 ret = User::FreeLogicalDevice(_L("USBC"));
205 test.Printf(_L("FreeLogicalDevice returned %d\n"), ret);
206 test(ret == KErrNone);
208 CleanupStack::PopAndDestroy(3); // 3 CPropertyWatches
209 CleanupStack::PopAndDestroy(3); // 3 property status change handlers
210 CleanupStack::PopAndDestroy(sm);
211 CleanupStack::PopAndDestroy(sched);
212 CleanupStack::PopAndDestroy(&usbMs);
213 CleanupStack::PopAndDestroy(&fs);
215 #ifndef __NO_HEAP_CHECK
220 GLDEF_C void CallTestsL()
225 test.Start( _L("Test Publish Subscriber") );