sl@0: // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of the License "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // f32test\msfs\src\t_ms_clisvr.cpp sl@0: // sl@0: // sl@0: sl@0: #define __T_MS_CLISVR__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include "rusbmassstorage.h" sl@0: #include "t_ms_main.h" sl@0: sl@0: #ifdef __USBMS_NO_PROCESSES__ sl@0: #include sl@0: #endif sl@0: sl@0: GLDEF_D RUsbMassStorage gUsbMs; sl@0: sl@0: // Unit test for MS client API and server API sl@0: GLREF_C void t_ms_clisvr(); sl@0: sl@0: // Unit test for MS file server sl@0: GLREF_C void t_ms_fsunit(); sl@0: sl@0: sl@0: LOCAL_C TInt StartServer() sl@0: // sl@0: // Start the server process or thread sl@0: // sl@0: { sl@0: const TUidType serverUid(KNullUid, KNullUid, KUsbMsSvrUid); sl@0: sl@0: #ifdef __USBMS_NO_PROCESSES__ sl@0: // sl@0: // In EKA1 WINS the server is a DLL, the exported entrypoint returns a TInt sl@0: // which represents the real entry-point for the server thread sl@0: // sl@0: RLibrary lib; sl@0: TInt err = lib.Load(KUsbMsImg, serverUid); sl@0: sl@0: if (err != KErrNone ) sl@0: { sl@0: return err; sl@0: } sl@0: TLibraryFunction ordinal1 = lib.Lookup(1); sl@0: TThreadFunction serverFunc = reinterpret_cast(ordinal1()); sl@0: sl@0: // sl@0: // To deal with the unique thread (+semaphore!) naming in EPOC, and that we may sl@0: // be trying to restart a server that has just exited we attempt to create a sl@0: // unique thread name for the server. sl@0: // This uses Math::Random() to generate a 32-bit random number for the name sl@0: // sl@0: TName name(KUsbMsServerName); sl@0: name.AppendNum(Math::Random(),EHex); sl@0: sl@0: RThread server; sl@0: err = server.Create ( sl@0: name, sl@0: serverFunc, sl@0: KUsbMsStackSize, sl@0: NULL, sl@0: &lib, sl@0: NULL, sl@0: KUsbMsMinHeapSize, sl@0: KUsbMsMaxHeapSize, sl@0: EOwnerProcess sl@0: ); sl@0: sl@0: lib.Close(); // if successful, server thread has handle to library now sl@0: #else sl@0: // sl@0: // EPOC and EKA2 is easy, we just create a new server process. Simultaneous sl@0: // launching of two such processes should be detected when the second one sl@0: // attempts to create the server object, failing with KErrAlreadyExists. sl@0: // sl@0: RProcess server; sl@0: TInt err = server.Create(KUsbMsImg1, KNullDesC, serverUid); sl@0: if (err == KErrNotFound) sl@0: { sl@0: err = server.Create(KUsbMsImg, KNullDesC, serverUid); sl@0: } sl@0: #endif sl@0: sl@0: if (err != KErrNone) sl@0: { sl@0: return err; sl@0: } sl@0: sl@0: TRequestStatus stat; sl@0: server.Rendezvous(stat); sl@0: sl@0: if (stat!=KRequestPending) sl@0: server.Kill(0); // abort startup sl@0: else sl@0: server.Resume(); // logon OK - start the server sl@0: sl@0: User::WaitForRequest(stat); // wait for start or death sl@0: sl@0: // we can't use the 'exit reason' if the server panicked as this sl@0: // is the panic 'reason' and may be '0' which cannot be distinguished sl@0: // from KErrNone sl@0: err = (server.ExitType() == EExitPanic) ? KErrServerTerminated : stat.Int(); sl@0: sl@0: server.Close(); sl@0: sl@0: return err; sl@0: } sl@0: sl@0: LOCAL_C void DoTestConnect() sl@0: // sl@0: // Connect to the file server sl@0: // sl@0: { sl@0: test.Printf(_L("DoTestConnect\n")); sl@0: // Load MS file server sl@0: TInt r = StartServer(); sl@0: test(KErrNone == r); sl@0: // Connect to MS file server sl@0: r = gUsbMs.Connect(); sl@0: test(KErrNone == r); sl@0: sl@0: test.Printf(_L("DoTestConnect ====> PASS\n")); sl@0: } sl@0: sl@0: LOCAL_C void DoTestStart() sl@0: // sl@0: // Start mass storage device sl@0: // sl@0: { sl@0: sl@0: TMassStorageConfig msConfig; sl@0: msConfig.iVendorId.Copy(t_vendorId); sl@0: msConfig.iProductId.Copy(t_productId); sl@0: msConfig.iProductRev.Copy(t_productRev); sl@0: sl@0: TInt r = gUsbMs.Start(msConfig); sl@0: test(KErrNone == r); sl@0: sl@0: test.Printf(_L("DoTestStart ====> PASS\n")); sl@0: } sl@0: sl@0: LOCAL_C void DoTestStop() sl@0: // sl@0: // Stop USB device sl@0: // sl@0: { sl@0: test.Printf(_L("TestStop\n")); sl@0: TInt r = gUsbMs.Stop(); sl@0: test(KErrNone == r); sl@0: sl@0: test.Printf(_L("DoTestStop ====> PASS\n"));; sl@0: } sl@0: sl@0: GLDEF_C void t_ms_clisvr() sl@0: // sl@0: // Do all tests sl@0: // sl@0: { sl@0: test.Next( _L("TestConnect") ); sl@0: DoTestConnect(); sl@0: test.Next(_L("TestStart")); sl@0: DoTestStart(); sl@0: test.Next(_L("TestStop")); sl@0: DoTestStop(); sl@0: gUsbMs.Shutdown(); sl@0: gUsbMs.Close(); sl@0: sl@0: } sl@0: sl@0: GLDEF_C void CallTestsL() sl@0: { sl@0: test.Start(_L("ClientServer Tests")); sl@0: t_ms_clisvr(); sl@0: test.End(); sl@0: test.Start(_L("File System Unit Tests")); sl@0: t_ms_fsunit(); sl@0: test.End(); sl@0: }