examples/Base/IPC/AdvancedClientServerExample/test/te_ThreadClientServerTest/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 
00031 
00035 #include "MainTestStep.h"
00036 #include "Te_ThreadClientServerTestSuiteDefs.h"
00037 
00038 //common descriptors
00039 _LIT(KTestCaseId, "tc_id");
00040 _LIT8(KTestData, "abcdefghijklmnopqrstuvwxyz");
00041 
00045 CMainTestStep::~CMainTestStep()
00046         {
00047         }
00051 CMainTestStep::CMainTestStep(CTe_ThreadClientServerTestSuite& aParent)
00052 :CTe_ThreadClientServerTestSuiteStepBase(aParent)
00053         {
00054         // **MUST** call SetTestStepName in the constructor as the controlling
00055         // framework uses the test step name immediately following construction to set
00056         // up the step's unique logging ID.
00057         SetTestStepName(KMainTestStep);
00058         }
00065 TVerdict CMainTestStep::doTestStepL()
00066         {
00067           if (TestStepResult()==EPass)
00068                 {
00069                 // get the test case id from ini file
00070                 TInt id;
00071                 if (!GetIntFromConfig(ConfigSection(),KTestCaseId,id))
00072                         {
00073                         User::Panic(_L("Cannot fetch test case id value from ini file"), 1);
00074                         }
00075                         
00076                 RThreadClient& client = iParent.Handler();
00077                 if (id != 6)
00078                         {
00079                         //common setting for all test cases except test case SampleThreadServer-0006
00080                         CleanupClosePushL(client);
00081                         User::LeaveIfError(client.Connect());
00082                         INFO_PRINTF1(_L("Connected to Thread Server"));
00083                         }
00084         
00085                 // common variables used in test cases
00086                 TInt r;
00087                 TRequestStatus status;
00088                 
00089                 switch (id)
00090                         {
00091                         case 1: 
00092                                 {
00093                                 // Test case "SampleThreadServer-0001"
00094                                 // Check the device driver (both LDD and PDD) have been loaded when 
00095                                 // client has connected to server
00096                                 _LIT(KSampleDriverLddFileName,"DRIVER1_LDD");
00097                                 _LIT(KSampleDriverPddFileName,"DRIVER1_PDD");
00098                                 INFO_PRINTF1(_L("Trying to load the same device driver Pdd"));
00099                                 r = User::LoadPhysicalDevice(KSampleDriverPddFileName);
00100                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrAlreadyExists,r);
00101                                 if (r!= KErrAlreadyExists)
00102                                         {
00103                                         SetTestStepResult(EFail);
00104                                         break;
00105                                         }
00106                                 
00107                                 INFO_PRINTF1(_L("Trying to load the same device driver Ldd"));
00108                                 r = User::LoadLogicalDevice(KSampleDriverLddFileName);
00109                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrAlreadyExists,r);
00110                                 if (r!= KErrAlreadyExists)
00111                                         {
00112                                         SetTestStepResult(EFail);
00113                                         }
00114                                 }
00115                                 break;
00116                                 
00117                         case 2:
00118                                 {
00119                                 // Test case "SampleThreadServer-0002"
00120                                 // Issue asynchronous request to server
00121                                 User::LeaveIfError(client.OpenDriver());
00122                                 INFO_PRINTF1(_L("Device Driver Opened"));
00123                                 
00124                                 INFO_PRINTF1(_L("Sending Data 1"));
00125                                 client.Send(KTestData,status);
00126                                 User::WaitForRequest(status);
00127                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrNone,status.Int());
00128                                 if (status.Int()!=KErrNone)
00129                                         {
00130                                         SetTestStepResult(EFail);
00131                                         }
00132                                 }
00133                                 break;
00134                                 
00135                         case 3:
00136                                 {
00137                                 // Test case "SampleThreadServer-0003"
00138                                 // Cancel outstanding asynchronous request
00139                                 User::LeaveIfError(client.OpenDriver());
00140                                 INFO_PRINTF1(_L("Device Driver Opened"));
00141                                 
00142                                 INFO_PRINTF1(_L("Sending Data 2"));
00143                                 client.Send(KTestData,status);
00144                                 INFO_PRINTF1(_L("Cancel Sending Data 2"));
00145                                 client.SendCancel();
00146                                 User::WaitForRequest(status);
00147                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrCancel,status.Int());
00148                                 if (status!=KErrCancel)
00149                                         {
00150                                         SetTestStepResult(EFail);
00151                                         }
00152                                 }
00153                                 break;
00154                                 
00155                         case 4:
00156                                 {
00157                                 // Test case "SampleThreadServer-0004"
00158                                 // Issue two synchronous requests to server
00159                                 User::LeaveIfError(client.OpenDriver());
00160                                 INFO_PRINTF1(_L("Device Driver Opened"));
00161                                 
00162                                 INFO_PRINTF1(_L("Sending Data 3"));
00163                                 client.Send(KTestData,status);
00164                                 
00165                                 TRequestStatus status2;
00166                                 INFO_PRINTF1(_L("Sending Data 4"));
00167                                 client.Send(KTestData,status2);
00168                                 
00169                                 User::WaitForRequest(status);
00170                                 INFO_PRINTF1(_L("Finished Sending Data 3"));
00171                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrNone,status.Int());
00172                                 if (status!=KErrNone)
00173                                         {
00174                                         SetTestStepResult(EFail);
00175                                         }
00176                                 User::WaitForRequest(status2);
00177                                 INFO_PRINTF1(_L("Finished Sending Data 4"));
00178                                 INFO_PRINTF3(_L("Expect Error %d : Receive Error %d"), KErrNone,status2.Int());
00179                                 if (status2!=KErrNone)
00180                                         {
00181                                         SetTestStepResult(EFail);
00182                                         }
00183                                 }
00184                                 break;
00185                         
00186                         case 5:
00187                                 {
00188                                 // Test case "SampleThreadServer-0005"
00189                                 // Repeatly loading and unloading device driver using client APIs
00190                                 r = client.LoadDeviceDriver();
00191                                 if (r!=KErrNone)
00192                                         {
00193                                         INFO_PRINTF2(_L("Loading Device Driver Finished with error %d"), r);
00194                                         SetTestStepResult(EFail);
00195                                         break;
00196                                         }
00197                                 INFO_PRINTF1(_L("Device Driver Loaded"));
00198                                 
00199                                 r = client.UnloadDeviceDriver();
00200                                 if (r!=KErrNone)
00201                                         {
00202                                         INFO_PRINTF2(_L("Unloading Device Driver Finished with error %d"), r);
00203                                         SetTestStepResult(EFail);
00204                                         break;
00205                                         }
00206                                 INFO_PRINTF1(_L("Device Driver Unloaded"));
00207                                 }
00208                                 break;
00209                                 
00210                         case 6:
00211                                 {
00212                                 // test case SampleThreadServer-0006
00213                                 // two test steps are running concurrently to
00214                                 // simulate two clients trying to connect to server
00215                                 // at the same time
00216                                 RThreadClient anotherClient;
00217                                 CleanupClosePushL(anotherClient);
00218                                 INFO_PRINTF1(_L("trying to connect to server"));
00219                                 r = anotherClient.Connect();
00220                                 INFO_PRINTF2(_L("Connected to Process Server with error %d"), r);
00221                                 if (KErrNone!=r)
00222                                         {
00223                                         SetTestStepResult(EFail);
00224                                         }
00225                                 CleanupStack::PopAndDestroy(&anotherClient);
00226                                 INFO_PRINTF1(_L("Close Handle to ThreadServer"));
00227                                 }
00228                                 break;
00229                                 
00230                         default:
00231                                 User::Panic(_L("Unregonised Test Case IDs"), 1);
00232                         }
00233                 
00234                 if (id != 6)
00235                         {
00236                         CleanupStack::PopAndDestroy(&client); 
00237                         INFO_PRINTF1(_L("Close Handle to ThreadServer"));
00238                         }
00239                 
00240                 
00241 
00242                 }
00243           return TestStepResult();
00244         }
00245 
00246 
00247 
00248 //eof
00249 

Generated by  doxygen 1.6.2