examples/Base/IPC/AdvancedClientServerExample/test/te_ProcessClientServerTest/src/MainTestStep.cpp

Go to the documentation of this file.
00001 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
00002 // All rights reserved.
00003 // This component and the accompanying materials are made available
00004 // under the terms of "Eclipse Public License v1.0"
00005 // which accompanies this distribution, and is available
00006 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
00007 //
00008 // Initial Contributors:
00009 // Nokia Corporation - initial contribution.
00010 //
00011 // Contributors:
00012 //
00013 // Description:
00014 // Example CTestStep derived implementation
00015 //
00016 
00017 
00018 
00022 #include "MainTestStep.h"
00023 #include "Te_ProcessClientServerTestSuiteDefs.h"
00024 
00025 
00026 _LIT8(KTestData, "abcdefghijklmnopqrstuvwxyz");
00027 _LIT(KTestCaseId, "tc_id");
00028 
00032 CMainTestStep::~CMainTestStep()
00033         {
00034         }
00038 CMainTestStep::CMainTestStep(CTe_ProcessClientServerTestSuite& aParent)
00039 :CTe_ProcessClientServerTestSuiteStepBase(aParent)
00040         {
00041         // **MUST** call SetTestStepName in the constructor as the controlling
00042         // framework uses the test step name immediately following construction to set
00043         // up the step's unique logging ID.
00044         SetTestStepName(KMainTestStep);
00045         }
00052 TVerdict CMainTestStep::doTestStepL()
00053         {
00054           if (TestStepResult()==EPass)
00055                 {
00056                 // get the test case id from ini file
00057                 TInt id;
00058                 if (!GetIntFromConfig(ConfigSection(),KTestCaseId,id))
00059                         {
00060                         User::Panic(_L("Cannot fetch test case id value from ini file"), 1);
00061                         }
00062                         
00063                 RProcessClient& client = iParent.Handler();
00064                 if (id != 6)
00065                         {
00066                         //common setting for all test cases except test case SampleThreadServer-0006
00067                         CleanupClosePushL(client);
00068                         User::LeaveIfError(client.Connect());
00069                         INFO_PRINTF1(_L("Connected to Process Server"));
00070                         }
00071                 // common variables used in test cases
00072                 TInt r;
00073                 TRequestStatus status;
00074                 
00075                 switch (id)
00076                         {
00077                         case 1: 
00078                                 {
00079                                 // Test case "SampleProcessServer-0001"
00080                                 // Check the device drivers (both LDD and PDD) have been loaded when 
00081                                 // client has connected to server
00082                                 _LIT(KSampleDriverLddFileName,"DRIVER1_LDD");
00083                                 _LIT(KSampleDriverPddFileName,"DRIVER1_PDD");
00084 
00085                                 INFO_PRINTF1(_L("Trying to load the same device driver Pdd"));
00086                                 r = User::LoadPhysicalDevice(KSampleDriverPddFileName);
00087                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrAlreadyExists,r);
00088                                 if (r!= KErrAlreadyExists)
00089                                         {
00090                                         SetTestStepResult(EFail);
00091                                         break;
00092                                         }
00093                                 
00094                                 INFO_PRINTF1(_L("Trying to load the same device driver Ldd"));
00095                                 r = User::LoadLogicalDevice(KSampleDriverLddFileName);
00096                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrAlreadyExists,r);
00097                                 if (r!= KErrAlreadyExists)
00098                                         {
00099                                         SetTestStepResult(EFail);
00100                                         }
00101                                 }
00102                                 break;
00103                                 
00104                         case 2:
00105                                 {
00106                                 // Test case "SampleProcessServer-0002"
00107                                 // Issue asynchronous request to server
00108                                 User::LeaveIfError(client.OpenDriver());
00109                                 INFO_PRINTF1(_L("Device Driver Opened"));
00110                                 
00111                                 INFO_PRINTF1(_L("Sending Data 1"));
00112                                 client.Send(KTestData,status);
00113                                 User::WaitForRequest(status);
00114                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrNone,status.Int());
00115                                 if (status.Int()!=KErrNone)
00116                                         {
00117                                         SetTestStepResult(EFail);
00118                                         }
00119                                 }
00120                                 break;
00121                                 
00122                         case 3:
00123                                 {
00124                                 // Test case "SampleProcessServer-0003"
00125                                 // Cancel outstanding asynchronous request
00126                                 User::LeaveIfError(client.OpenDriver());
00127                                 INFO_PRINTF1(_L("Device Driver Opened"));
00128                                 
00129                                 INFO_PRINTF1(_L("Sending Data 2"));
00130                                 client.Send(KTestData,status);
00131                                 INFO_PRINTF1(_L("Cancel Sending Data 2"));
00132                                 client.SendCancel();
00133                                 User::WaitForRequest(status);
00134                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrCancel,status.Int());
00135                                 if (status!=KErrCancel)
00136                                         {
00137                                         SetTestStepResult(EFail);
00138                                         }
00139                                 }
00140                                 break;
00141                                 
00142                         case 4:
00143                                 {
00144                                 // Test case "SampleProcessServer-0004"
00145                                 // Issue two synchronous requests to server
00146                                 User::LeaveIfError(client.OpenDriver());
00147                                 INFO_PRINTF1(_L("Device Driver Opened"));
00148                                 
00149                                 INFO_PRINTF1(_L("Sending Data 3"));
00150                                 client.Send(KTestData,status);
00151                                 
00152                                 TRequestStatus status2;
00153                                 INFO_PRINTF1(_L("Sending Data 4"));
00154                                 client.Send(KTestData,status2);
00155                                 
00156                                 User::WaitForRequest(status);
00157                                 INFO_PRINTF1(_L("Finished Sending Data 3"));
00158                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrNone,status.Int());
00159                                 if (status!=KErrNone)
00160                                         {
00161                                         SetTestStepResult(EFail);
00162                                         }
00163                                 User::WaitForRequest(status2);
00164                                 INFO_PRINTF1(_L("Finished Sending Data 4"));
00165                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrNone,status2.Int());
00166                                 if (status2!=KErrNone)
00167                                         {
00168                                         SetTestStepResult(EFail);
00169                                         }
00170                                 }
00171                                 break;
00172                         
00173                         case 5:
00174                                 {
00175                                 // Test case "SampleProcessServer-0005"
00176                                 // Repeatedly loading and unloading device driver using client APIs
00177                                 r = client.LoadDeviceDriver();
00178                                 if (r!=KErrNone)
00179                                         {
00180                                         INFO_PRINTF2(_L("Loading Device Driver Finished with error %d"), r);
00181                                         SetTestStepResult(EFail);
00182                                         break;
00183                                         }
00184                                 INFO_PRINTF1(_L("Device Driver Loaded"));
00185                                 
00186                                 r = client.UnloadDeviceDriver();
00187                                 if (r!=KErrNone)
00188                                         {
00189                                         INFO_PRINTF2(_L("Unloading Device Driver Finished with error %d"), r);
00190                                         SetTestStepResult(EFail);
00191                                         break;
00192                                         }
00193                                 INFO_PRINTF1(_L("Device Driver Unloaded"));
00194                                 }
00195                                 break;
00196                                 
00197                         case 6:
00198                                 {
00199                                 // test case SampleProcessServer-0006
00200                                 // two test steps are running concurrently to
00201                                 // simulate two clients trying to connect to server
00202                                 // at the same time
00203                                 RProcessClient anotherClient;
00204                                 CleanupClosePushL(anotherClient);
00205                                 INFO_PRINTF1(_L("trying to connect to server"));
00206                                 r = anotherClient.Connect();
00207                                 INFO_PRINTF2(_L("Connected to Process Server with error %d"), r);
00208                                 if (KErrNone!=r)
00209                                         {
00210                                         SetTestStepResult(EFail);
00211                                         }
00212                                 CleanupStack::PopAndDestroy(&anotherClient);
00213                                 INFO_PRINTF1(_L("Close Handle to ProcessServer"));
00214                                 }
00215                                 break;
00216                                 
00217                         default:
00218                                 User::Panic(_L("Unrecognised Test Case IDs"), 1);
00219                         }
00220                 
00221                 if (id != 6)
00222                         {
00223                         CleanupStack::PopAndDestroy(&client); 
00224                         INFO_PRINTF1(_L("Close Handle to ProcessServer"));
00225                         }
00226                 
00227                 
00228 
00229                 }
00230           return TestStepResult();
00231         }
00232         
00233 
00234 
00235 //eof
00236 

Generated by  doxygen 1.6.2