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 // f32test\msfs\src\t_ms_clisvr.cpp
18 #define __T_MS_CLISVR__
23 #include <e32std_private.h>
26 #include <massstorage.h>
27 #include "rusbmassstorage.h"
28 #include "t_ms_main.h"
30 #ifdef __USBMS_NO_PROCESSES__
34 GLDEF_D RUsbMassStorage gUsbMs;
36 // Unit test for MS client API and server API
37 GLREF_C void t_ms_clisvr();
39 // Unit test for MS file server
40 GLREF_C void t_ms_fsunit();
43 LOCAL_C TInt StartServer()
45 // Start the server process or thread
48 const TUidType serverUid(KNullUid, KNullUid, KUsbMsSvrUid);
50 #ifdef __USBMS_NO_PROCESSES__
52 // In EKA1 WINS the server is a DLL, the exported entrypoint returns a TInt
53 // which represents the real entry-point for the server thread
56 TInt err = lib.Load(KUsbMsImg, serverUid);
62 TLibraryFunction ordinal1 = lib.Lookup(1);
63 TThreadFunction serverFunc = reinterpret_cast<TThreadFunction>(ordinal1());
66 // To deal with the unique thread (+semaphore!) naming in EPOC, and that we may
67 // be trying to restart a server that has just exited we attempt to create a
68 // unique thread name for the server.
69 // This uses Math::Random() to generate a 32-bit random number for the name
71 TName name(KUsbMsServerName);
72 name.AppendNum(Math::Random(),EHex);
87 lib.Close(); // if successful, server thread has handle to library now
90 // EPOC and EKA2 is easy, we just create a new server process. Simultaneous
91 // launching of two such processes should be detected when the second one
92 // attempts to create the server object, failing with KErrAlreadyExists.
95 TInt err = server.Create(KUsbMsImg1, KNullDesC, serverUid);
96 if (err == KErrNotFound)
98 err = server.Create(KUsbMsImg, KNullDesC, serverUid);
108 server.Rendezvous(stat);
110 if (stat!=KRequestPending)
111 server.Kill(0); // abort startup
113 server.Resume(); // logon OK - start the server
115 User::WaitForRequest(stat); // wait for start or death
117 // we can't use the 'exit reason' if the server panicked as this
118 // is the panic 'reason' and may be '0' which cannot be distinguished
120 err = (server.ExitType() == EExitPanic) ? KErrServerTerminated : stat.Int();
127 LOCAL_C void DoTestConnect()
129 // Connect to the file server
132 test.Printf(_L("DoTestConnect\n"));
133 // Load MS file server
134 TInt r = StartServer();
136 // Connect to MS file server
137 r = gUsbMs.Connect();
140 test.Printf(_L("DoTestConnect ====> PASS\n"));
143 LOCAL_C void DoTestStart()
145 // Start mass storage device
149 TMassStorageConfig msConfig;
150 msConfig.iVendorId.Copy(t_vendorId);
151 msConfig.iProductId.Copy(t_productId);
152 msConfig.iProductRev.Copy(t_productRev);
154 TInt r = gUsbMs.Start(msConfig);
157 test.Printf(_L("DoTestStart ====> PASS\n"));
160 LOCAL_C void DoTestStop()
165 test.Printf(_L("TestStop\n"));
166 TInt r = gUsbMs.Stop();
169 test.Printf(_L("DoTestStop ====> PASS\n"));;
172 GLDEF_C void t_ms_clisvr()
177 test.Next( _L("TestConnect") );
179 test.Next(_L("TestStart"));
181 test.Next(_L("TestStop"));
188 GLDEF_C void CallTestsL()
190 test.Start(_L("ClientServer Tests"));
193 test.Start(_L("File System Unit Tests"));