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

Go to the documentation of this file.
00001 /*
00002 Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
00003 
00004 Redistribution and use in source and binary forms, with or without
00005 modification, are permitted provided that the following conditions are met:
00006 
00007 * Redistributions of source code must retain the above copyright notice, this
00008   list of conditions and the following disclaimer.
00009 * Redistributions in binary form must reproduce the above copyright notice,
00010   this list of conditions and the following disclaimer in the documentation
00011   and/or other materials provided with the distribution.
00012 * Neither the name of Nokia Corporation nor the names of its contributors
00013   may be used to endorse or promote products derived from this software
00014   without specific prior written permission.
00015 
00016 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00019 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00020 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00021 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00022 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00023 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00024 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00025 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00026 
00027 Description: Example CTestStep derived implementation  
00028 */
00029 
00030 
00034 #include "MainTestStep.h"
00035 #include "Te_ProcessClientServerTestSuiteDefs.h"
00036 
00037 
00038 _LIT8(KTestData, "abcdefghijklmnopqrstuvwxyz");
00039 _LIT(KTestCaseId, "tc_id");
00040 
00044 CMainTestStep::~CMainTestStep()
00045         {
00046         }
00050 CMainTestStep::CMainTestStep(CTe_ProcessClientServerTestSuite& aParent)
00051 :CTe_ProcessClientServerTestSuiteStepBase(aParent)
00052         {
00053         // **MUST** call SetTestStepName in the constructor as the controlling
00054         // framework uses the test step name immediately following construction to set
00055         // up the step's unique logging ID.
00056         SetTestStepName(KMainTestStep);
00057         }
00064 TVerdict CMainTestStep::doTestStepL()
00065         {
00066           if (TestStepResult()==EPass)
00067                 {
00068                 // get the test case id from ini file
00069                 TInt id;
00070                 if (!GetIntFromConfig(ConfigSection(),KTestCaseId,id))
00071                         {
00072                         User::Panic(_L("Cannot fetch test case id value from ini file"), 1);
00073                         }
00074                         
00075                 RProcessClient& client = iParent.Handler();
00076                 if (id != 6)
00077                         {
00078                         //common setting for all test cases except test case SampleThreadServer-0006
00079                         CleanupClosePushL(client);
00080                         User::LeaveIfError(client.Connect());
00081                         INFO_PRINTF1(_L("Connected to Process Server"));
00082                         }
00083                 // common variables used in test cases
00084                 TInt r;
00085                 TRequestStatus status;
00086                 
00087                 switch (id)
00088                         {
00089                         case 1: 
00090                                 {
00091                                 // Test case "SampleProcessServer-0001"
00092                                 // Check the device drivers (both LDD and PDD) have been loaded when 
00093                                 // client has connected to server
00094                                 _LIT(KSampleDriverLddFileName,"DRIVER1_LDD");
00095                                 _LIT(KSampleDriverPddFileName,"DRIVER1_PDD");
00096 
00097                                 INFO_PRINTF1(_L("Trying to load the same device driver Pdd"));
00098                                 r = User::LoadPhysicalDevice(KSampleDriverPddFileName);
00099                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrAlreadyExists,r);
00100                                 if (r!= KErrAlreadyExists)
00101                                         {
00102                                         SetTestStepResult(EFail);
00103                                         break;
00104                                         }
00105                                 
00106                                 INFO_PRINTF1(_L("Trying to load the same device driver Ldd"));
00107                                 r = User::LoadLogicalDevice(KSampleDriverLddFileName);
00108                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrAlreadyExists,r);
00109                                 if (r!= KErrAlreadyExists)
00110                                         {
00111                                         SetTestStepResult(EFail);
00112                                         }
00113                                 }
00114                                 break;
00115                                 
00116                         case 2:
00117                                 {
00118                                 // Test case "SampleProcessServer-0002"
00119                                 // Issue asynchronous request to server
00120                                 User::LeaveIfError(client.OpenDriver());
00121                                 INFO_PRINTF1(_L("Device Driver Opened"));
00122                                 
00123                                 INFO_PRINTF1(_L("Sending Data 1"));
00124                                 client.Send(KTestData,status);
00125                                 User::WaitForRequest(status);
00126                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrNone,status.Int());
00127                                 if (status.Int()!=KErrNone)
00128                                         {
00129                                         SetTestStepResult(EFail);
00130                                         }
00131                                 }
00132                                 break;
00133                                 
00134                         case 3:
00135                                 {
00136                                 // Test case "SampleProcessServer-0003"
00137                                 // Cancel outstanding asynchronous request
00138                                 User::LeaveIfError(client.OpenDriver());
00139                                 INFO_PRINTF1(_L("Device Driver Opened"));
00140                                 
00141                                 INFO_PRINTF1(_L("Sending Data 2"));
00142                                 client.Send(KTestData,status);
00143                                 INFO_PRINTF1(_L("Cancel Sending Data 2"));
00144                                 client.SendCancel();
00145                                 User::WaitForRequest(status);
00146                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrCancel,status.Int());
00147                                 if (status!=KErrCancel)
00148                                         {
00149                                         SetTestStepResult(EFail);
00150                                         }
00151                                 }
00152                                 break;
00153                                 
00154                         case 4:
00155                                 {
00156                                 // Test case "SampleProcessServer-0004"
00157                                 // Issue two synchronous requests to server
00158                                 User::LeaveIfError(client.OpenDriver());
00159                                 INFO_PRINTF1(_L("Device Driver Opened"));
00160                                 
00161                                 INFO_PRINTF1(_L("Sending Data 3"));
00162                                 client.Send(KTestData,status);
00163                                 
00164                                 TRequestStatus status2;
00165                                 INFO_PRINTF1(_L("Sending Data 4"));
00166                                 client.Send(KTestData,status2);
00167                                 
00168                                 User::WaitForRequest(status);
00169                                 INFO_PRINTF1(_L("Finished Sending Data 3"));
00170                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrNone,status.Int());
00171                                 if (status!=KErrNone)
00172                                         {
00173                                         SetTestStepResult(EFail);
00174                                         }
00175                                 User::WaitForRequest(status2);
00176                                 INFO_PRINTF1(_L("Finished Sending Data 4"));
00177                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrNone,status2.Int());
00178                                 if (status2!=KErrNone)
00179                                         {
00180                                         SetTestStepResult(EFail);
00181                                         }
00182                                 }
00183                                 break;
00184                         
00185                         case 5:
00186                                 {
00187                                 // Test case "SampleProcessServer-0005"
00188                                 // Repeatedly loading and unloading device driver using client APIs
00189                                 r = client.LoadDeviceDriver();
00190                                 if (r!=KErrNone)
00191                                         {
00192                                         INFO_PRINTF2(_L("Loading Device Driver Finished with error %d"), r);
00193                                         SetTestStepResult(EFail);
00194                                         break;
00195                                         }
00196                                 INFO_PRINTF1(_L("Device Driver Loaded"));
00197                                 
00198                                 r = client.UnloadDeviceDriver();
00199                                 if (r!=KErrNone)
00200                                         {
00201                                         INFO_PRINTF2(_L("Unloading Device Driver Finished with error %d"), r);
00202                                         SetTestStepResult(EFail);
00203                                         break;
00204                                         }
00205                                 INFO_PRINTF1(_L("Device Driver Unloaded"));
00206                                 }
00207                                 break;
00208                                 
00209                         case 6:
00210                                 {
00211                                 // test case SampleProcessServer-0006
00212                                 // two test steps are running concurrently to
00213                                 // simulate two clients trying to connect to server
00214                                 // at the same time
00215                                 RProcessClient anotherClient;
00216                                 CleanupClosePushL(anotherClient);
00217                                 INFO_PRINTF1(_L("trying to connect to server"));
00218                                 r = anotherClient.Connect();
00219                                 INFO_PRINTF2(_L("Connected to Process Server with error %d"), r);
00220                                 if (KErrNone!=r)
00221                                         {
00222                                         SetTestStepResult(EFail);
00223                                         }
00224                                 CleanupStack::PopAndDestroy(&anotherClient);
00225                                 INFO_PRINTF1(_L("Close Handle to ProcessServer"));
00226                                 }
00227                                 break;
00228                                 
00229                         default:
00230                                 User::Panic(_L("Unrecognised Test Case IDs"), 1);
00231                         }
00232                 
00233                 if (id != 6)
00234                         {
00235                         CleanupStack::PopAndDestroy(&client); 
00236                         INFO_PRINTF1(_L("Close Handle to ProcessServer"));
00237                         }
00238                 
00239                 
00240 
00241                 }
00242           return TestStepResult();
00243         }
00244         
00245 
00246 
00247 //eof
00248 

Generated by  doxygen 1.6.2