websrv_pub/hostlet_connection_api/tsrc/bc/hostconn/src/hostletconnectioncases.cpp
changeset 0 62f9d29f7211
child 23 a1df79fa35b4
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:          ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 
       
    26 // INCLUDE FILES
       
    27 #include <e32math.h>
       
    28 #include "senhostletconnectionbctest.h"
       
    29 
       
    30 #include <SenFacet.h>
       
    31 
       
    32 
       
    33 //  EXTERNAL INCLUDES
       
    34 #include <SenServiceConnection.h>
       
    35 #include <SenServicePattern.h>
       
    36 
       
    37 
       
    38 
       
    39 //  INTERNAL INCLUDES
       
    40 #include <SenHttpTransportProperties.h>
       
    41 #include "SenHostletConnection.h"
       
    42 #include "testconsumer.h"
       
    43 #include "testhostlet.h"
       
    44 
       
    45 #include <SenTransportProperties.h>
       
    46 
       
    47 // EXTERNAL DATA STRUCTURES
       
    48 //extern  ?external_data;
       
    49 
       
    50 // EXTERNAL FUNCTION PROTOTYPES  
       
    51 //extern ?external_function( ?arg_type,?arg_type );
       
    52 
       
    53 // CONSTANTS
       
    54 //const ?type ?constant_var = ?constant;
       
    55 
       
    56 // MACROS
       
    57 //#define ?macro ?macro_def
       
    58 
       
    59 // LOCAL CONSTANTS AND MACROS
       
    60 //const ?type ?constant_var = ?constant;
       
    61 //#define ?macro_name ?macro_def
       
    62 
       
    63 // MODULE DATA STRUCTURES
       
    64 //enum ?declaration
       
    65 //typedef ?declaration
       
    66 
       
    67 // LOCAL FUNCTION PROTOTYPES
       
    68 //?type ?function_name( ?arg_type, ?arg_type );
       
    69 
       
    70 // FORWARD DECLARATIONS
       
    71 //class ?FORWARD_CLASSNAME;
       
    72 
       
    73 // ============================= LOCAL FUNCTIONS ===============================
       
    74 
       
    75 // -----------------------------------------------------------------------------
       
    76 // ?function_name ?description.
       
    77 // ?description
       
    78 // Returns: ?value_1: ?description
       
    79 //          ?value_n: ?description_line1
       
    80 //                    ?description_line2
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 /*
       
    84 ?type ?function_name(
       
    85     ?arg_type arg,  // ?description
       
    86     ?arg_type arg)  // ?description
       
    87     {
       
    88 
       
    89     ?code  // ?comment
       
    90 
       
    91     // ?comment
       
    92     ?code
       
    93     }
       
    94 */
       
    95 
       
    96 
       
    97 //Macro for Porting to STIF
       
    98 #define LOCAL_ASSERT(expression)	{if(!(expression)){return KErrArgument;}}
       
    99 #define LOCAL_VOID_ASSERT(expression)	{if(!(expression)){return ;}}
       
   100 
       
   101 namespace
       
   102     {
       
   103     _LIT8(KHostletEndpoint, "hostlet://UnitTestHostlet");
       
   104     _LIT8(KHostletEndpoint1, "hostlet://UnitTestHostlet-1");
       
   105     _LIT8(KHostletContract, "urn:nokia.com.serene:unit-test-hostlet");
       
   106     _LIT8(KHostletContract1, "urn:nokia.com.serene:unit-test-hostlet-1");  
       
   107     
       
   108     void threadMainL(TAny* aPtr)
       
   109         {
       
   110         TConsumerTestTask* pTask = (TConsumerTestTask*) aPtr;
       
   111         pTask->Execute();
       
   112         // Go safely out of scope (will destroy this thread)
       
   113         }
       
   114     
       
   115     TInt threadFunction(TAny* aPtr)
       
   116         {
       
   117         CTrapCleanup* pCleanup = CTrapCleanup::New();
       
   118         CActiveScheduler::Install(NULL); // remove one
       
   119         CActiveScheduler* pScheduler = new (ELeave) CActiveScheduler();
       
   120         CActiveScheduler::Install(pScheduler);
       
   121 
       
   122         TInt leaveCode(KErrNone);
       
   123         TRAP(leaveCode, threadMainL(aPtr));
       
   124 
       
   125         CActiveScheduler::Install(NULL); // uninstall scheduler
       
   126         delete pScheduler;
       
   127         delete pCleanup;
       
   128 
       
   129         return leaveCode;
       
   130         }
       
   131         
       
   132         
       
   133     TInt CreateThreadForConsumerTask(RThread& aThread, const TDesC& aThreadName, TConsumerTestTask& aTask)
       
   134         {
       
   135         TName threadName(aThreadName);
       
   136         // Append a random number to make it unique
       
   137         threadName.AppendNum(Math::Random(), EHex);
       
   138                 
       
   139 #ifdef EKA2
       
   140         RAllocator& heap = User::Allocator(); // RHeap is deprecated in EKA2
       
   141         return aThread.Create(threadName, // name
       
   142                               threadFunction,
       
   143                               KDefaultStackSize,
       
   144                               &heap,
       
   145                               &aTask);
       
   146 #else // EKA1
       
   147         RHeap& heap = User::Heap();
       
   148         return aThread.Create(threadName, // name
       
   149                               threadFunction,
       
   150                               KDefaultStackSize,
       
   151                               &heap,
       
   152                               &aTask);
       
   153 #endif // EKA        
       
   154         }      
       
   155     }   
       
   156 
       
   157 
       
   158 // ============================ MEMBER FUNCTIONS ===============================
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CSenServiceManagerBCTest::Case
       
   162 // Returns a test case by number.
       
   163 //
       
   164 // This function contains an array of all available test cases 
       
   165 // i.e pair of case name and test function. If case specified by parameter
       
   166 // aCaseNumber is found from array, then that item is returned.
       
   167 // 
       
   168 // The reason for this rather complicated function is to specify all the
       
   169 // test cases only in one place. It is not necessary to understand how
       
   170 // function pointers to class member functions works when adding new test
       
   171 // cases. See function body for instructions how to add new test case.
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 const TCaseInfo CSenHostletConnectionBCTest::Case ( 
       
   175     const TInt aCaseNumber ) const 
       
   176      {
       
   177 
       
   178     /**
       
   179     * To add new test cases, implement new test case function and add new 
       
   180     * line to KCases array specify the name of the case and the function 
       
   181     * doing the test case
       
   182     * In practice, do following
       
   183     * 1) Make copy of existing test case function and change its name
       
   184     *    and functionality. Note that the function must be added to 
       
   185     *    SenServiceManager_stif.cpp file and to SenServiceManager_stif.h 
       
   186     *    header file.
       
   187     *
       
   188     * 2) Add entry to following KCases array either by using:
       
   189     *
       
   190     * 2.1: FUNCENTRY or ENTRY macro
       
   191     * ENTRY macro takes two parameters: test case name and test case 
       
   192     * function name.
       
   193     *
       
   194     * FUNCENTRY macro takes only test case function name as a parameter and
       
   195     * uses that as a test case name and test case function name.
       
   196     *
       
   197     * Or
       
   198     *
       
   199     * 2.2: OOM_FUNCENTRY or OOM_ENTRY macro. Note that these macros are used
       
   200     * only with OOM (Out-Of-Memory) testing!
       
   201     *
       
   202     * OOM_ENTRY macro takes five parameters: test case name, test case 
       
   203     * function name, TBool which specifies is method supposed to be run using
       
   204     * OOM conditions, TInt value for first heap memory allocation failure and 
       
   205     * TInt value for last heap memory allocation failure.
       
   206     * 
       
   207     * OOM_FUNCENTRY macro takes test case function name as a parameter and uses
       
   208     * that as a test case name, TBool which specifies is method supposed to be
       
   209     * run using OOM conditions, TInt value for first heap memory allocation 
       
   210     * failure and TInt value for last heap memory allocation failure. 
       
   211     */ 
       
   212 
       
   213     static TCaseInfoInternal const KCases[] =
       
   214         {
       
   215         // To add new test cases, add new items to this array
       
   216         
       
   217         // NOTE: When compiled to GCCE, there must be Classname::
       
   218         // declaration in front of the method name, e.g. 
       
   219         // CSenServiceManagerBCTest::PrintTest. Otherwise the compiler
       
   220         // gives errors.
       
   221 		ENTRY("NewL - CSenHostletConnectionBCTest ", CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL),
       
   222     
       
   223 		ENTRY("NewLC - CSenHostletConnectionBCTest ", CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLCL),
       
   224 		
       
   225 		ENTRY("Identifier - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_IdentifierL), 
       
   226 		
       
   227 		ENTRY("FrameworkId - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_FrameworkIdL), 
       
   228 		
       
   229 		ENTRY("RequestUtf8 - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_RequestUtf8L), 
       
   230 		
       
   231 		ENTRY("ThreadId - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_ThreadIdL), 
       
   232 
       
   233 		ENTRY("ConsumerId - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_ConsumerIdL), 
       
   234 
       
   235 		ENTRY("RequestId - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_RequestIdL), 
       
   236 
       
   237 		ENTRY("NewLC - CSenHostletConnectionBCTest ", CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLC_3InvokesL),
       
   238 
       
   239 		ENTRY("RespondL1 - CSenHostletConnectionBCTest ", CSenHostletConnectionBCTest::UT_CSenHostletConnection_RespondL1L),
       
   240    
       
   241 		ENTRY("RespondL2 - CSenHostletConnectionBCTest ", CSenHostletConnectionBCTest::UT_CSenHostletConnection_RespondL2L),
       
   242 
       
   243 		ENTRY("RespondL3 - CSenHostletConnectionBCTest ", CSenHostletConnectionBCTest::UT_CSenHostletConnection_RespondL3L),
       
   244 
       
   245 		ENTRY("RespondL negative response code - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_Negative_ResponseCodeL),
       
   246     
       
   247 		ENTRY("RespondL self def URI - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_HC_SelfDef_URIL),
       
   248 /*    
       
   249 		ENTRY("RespondL delete HC after SC is created - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_Delete_HCL),
       
   250 */
       
   251 		ENTRY("NewL leaves with KErrSenEndpointReserved -CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_Two_Equal_UID3L),
       
   252          
       
   253 		ENTRY("RespondL Two HC with the same Endpoints UIDs - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_Two_Equal_EndpointsL),    
       
   254    
       
   255 		ENTRY("RespondL Two HC Two SC diff contracts - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_Two_HC_Two_SC1L),    
       
   256      
       
   257 		ENTRY("RespondL Two HC Two SC diff endpionts - CSenHostletConnectionBCTest",CSenHostletConnectionBCTest::UT_CSenHostletConnection_Two_HC_Two_SC2L),    
       
   258 
       
   259 		ENTRY("RespondL Two HC Two SC diff endpionts the same contract - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_Two_HC_Two_SC3L),    
       
   260       
       
   261 		ENTRY("RespondL Delete SC before calling HC::RespondL - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_DeleteSC_before_HCRespondLL),    
       
   262 
       
   263 		ENTRY("RespondL Call RespondL multipe times - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_RespondL_4multipleTimesL),    
       
   264 
       
   265 		ENTRY("RespondL SC::Cancel after request - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_SC_Cancel_After_RequestL),    
       
   266     
       
   267 		ENTRY("RespondL Set Expose Facet - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_Set_Expose_FacetL),    
       
   268 
       
   269 		ENTRY("HC responds with TP - ", CSenHostletConnectionBCTest::UT_CSenHostletConnection_RespondWithPropertiesL),    
       
   270 
       
   271 		//ENTRY("New REST SC + SubmitL Test - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_CreateConnAndSubmit_Rest_MultiThreadL),    
       
   272 /*
       
   273 		ENTRY("New WS-I SC + SubmitL Test - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_CreateConnAndSubmit_WSI_MultiThreadL),    
       
   274 
       
   275 
       
   276 		ENTRY("SendL WS-I Test - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_Send_WSIL),    
       
   277 
       
   278 		ENTRY("Desc EP + SendL WS-I Test - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_DescEndpoint_Send_WSIL),    
       
   279 */
       
   280 
       
   281 		ENTRY("SendL from 2 SCs to 1 HC - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_2SC1HCL), 
       
   282 
       
   283 /*
       
   284 // NOTE: following is used instead:
       
   285 // --> UT_CSenHostletConnection_CreateConnAndSubmit_Rest_MultiThreadL 
       
   286 		ENTRY("SubmitL (multit.), Rest Test - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_Submit_Rest_MultiThreadL),    
       
   287 
       
   288 // NOTE: following is used instead:
       
   289 // --> UT_CSenHostletConnection_CreateConnAndSubmit_Rest_MultiThreadL 
       
   290 		ENTRY("SubmitL (active), Rest Test - CSenHostletConnectionBCTest", CSenHostletConnectionBCTest::UT_CSenHostletConnection_Submit_Rest_ActiveL),
       
   291 */        
       
   292 	 	};
       
   293 
       
   294 	    // Verify that case number is valid
       
   295 	    if( (TUint) aCaseNumber >= sizeof( KCases ) / 
       
   296 	                               sizeof( TCaseInfoInternal ) )
       
   297 	        {
       
   298 	        // Invalid case, construct empty object
       
   299 	        TCaseInfo null( (const TText*) L"" );
       
   300 	        null.iMethod = NULL;
       
   301 	        null.iIsOOMTest = EFalse;
       
   302 	        null.iFirstMemoryAllocation = 0;
       
   303 	        null.iLastMemoryAllocation = 0;
       
   304 	        return null;
       
   305 	        } 
       
   306 
       
   307 	    // Construct TCaseInfo object and return it
       
   308 	    TCaseInfo tmp ( KCases[ aCaseNumber ].iCaseName );
       
   309 	    tmp.iMethod = KCases[ aCaseNumber ].iMethod;
       
   310 	    tmp.iIsOOMTest = KCases[ aCaseNumber ].iIsOOMTest;
       
   311 	    tmp.iFirstMemoryAllocation = KCases[ aCaseNumber ].iFirstMemoryAllocation;
       
   312 	    tmp.iLastMemoryAllocation = KCases[ aCaseNumber ].iLastMemoryAllocation;
       
   313 	    return tmp;
       
   314 
       
   315 	    }   
       
   316 
       
   317 //  METHODS
       
   318 
       
   319 void CSenHostletConnectionBCTest::SetupL ()
       
   320     {
       
   321     __UHEAP_MARK;
       
   322     }
       
   323 
       
   324 void CSenHostletConnectionBCTest::Teardown ()
       
   325     {
       
   326 //    User::After( 2 * 1000 * 1000 ); // temp tests
       
   327     __UHEAP_MARKEND;
       
   328     }
       
   329 
       
   330 void CSenHostletConnectionBCTest::StartActiveScheduler(TInt aNumberOfPendingOps)
       
   331     {
       
   332     iNumberOfPendingOps = aNumberOfPendingOps;
       
   333     CActiveScheduler::Start();
       
   334     }
       
   335        
       
   336 void CSenHostletConnectionBCTest::StopActiveScheduler ()
       
   337     {
       
   338     iNumberOfPendingOps--;
       
   339     if ( iNumberOfPendingOps == 0 )
       
   340         {
       
   341     	CActiveScheduler::Stop();
       
   342         }
       
   343     }
       
   344 
       
   345 void TConsumerTestTask::Execute()
       
   346     {
       
   347     switch(iJob)
       
   348         {
       
   349         case(ECreateConnAndSubmit): // this is a very oddly orientated, wild case..
       
   350             {
       
   351             if(ipOwner)
       
   352                 {
       
   353                 CTestConsumer* pConsumer = CTestConsumer::NewL(ipOwner); // uses the default implementations for setstatus, handlemessage, handleerror
       
   354                 CleanupStack::PushL(pConsumer);
       
   355 
       
   356                 // Note, if NOT set, iEndpoint is typically KNullDesC8 (zero-lenght), which is OK, too.
       
   357                 CSenServicePattern* pPattern = CSenServicePattern::NewLC(iEndpoint, KHostletContract);
       
   358                 if(iFrameworkId.Length()>0)
       
   359                     {
       
   360                     pPattern->SetFrameworkIdL(iFrameworkId);
       
   361                     }
       
   362                 else
       
   363                     {
       
   364                     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);                        
       
   365                     }
       
   366                     
       
   367                 CSenServiceConnection* pConnection = CSenServiceConnection::NewL(*pConsumer, *pPattern);
       
   368                 CleanupStack::PopAndDestroy(pPattern);
       
   369                 CleanupStack::PushL(pConnection);
       
   370                 
       
   371                 // Construct service connection by starting active scheduler..
       
   372                 ipOwner->StartActiveScheduler(1);
       
   373                 
       
   374                 // Check that NO HandleErrorL callback was received:
       
   375                 LOCAL_VOID_ASSERT( pConsumer->iErrorCode == KErrNone );
       
   376                 
       
   377                 
       
   378                  // Check that the Status of the ServiceConnection
       
   379                 // is KSenConnectionStatusReady
       
   380                 LOCAL_VOID_ASSERT( pConsumer->iConnectionStatus == KSenConnectionStatusReady); 
       
   381 
       
   382                 // execution returns here EITHER when HandleMessageL or HandleErrorL has been invoked..
       
   383                 if(iProperties.Length()==0)
       
   384                     {
       
   385                     if(ipSoapMsg)
       
   386                         {
       
   387                         iStatusCode = pConnection->SubmitL(*ipSoapMsg, ipNotOwnedData);
       
   388                         }
       
   389                     else
       
   390                         {
       
   391                         iStatusCode = pConnection->SubmitL(iRequest, ipNotOwnedData);
       
   392                         }
       
   393                     }
       
   394                 else
       
   395                     {
       
   396                     if(ipSoapMsg)
       
   397                         {
       
   398                         iStatusCode = pConnection->SubmitL(*ipSoapMsg, iProperties, ipNotOwnedData);
       
   399                         }
       
   400                     else
       
   401                         {
       
   402                         iStatusCode = pConnection->SubmitL(iRequest, iProperties, ipNotOwnedData);
       
   403                         }
       
   404                     }
       
   405                 CleanupStack::PopAndDestroy(pConnection);
       
   406                 CleanupStack::PopAndDestroy(pConsumer);
       
   407                 }
       
   408            }
       
   409            break;
       
   410 
       
   411         case(ESubmit):
       
   412             {
       
   413             if(iProperties.Length()==0)
       
   414                 {
       
   415                 iStatusCode = iConnection.SubmitL(iRequest, ipNotOwnedData);
       
   416                 }
       
   417             else
       
   418                 {
       
   419                 iStatusCode = iConnection.SubmitL(iRequest, iProperties, ipNotOwnedData);
       
   420                 }
       
   421             }
       
   422             break;
       
   423 
       
   424         case(EActiveSubmit):
       
   425             {
       
   426             if ( ipActive)
       
   427                 {
       
   428                 // Perform blocking (sync) submit:
       
   429                 if(iProperties.Length()==0)
       
   430                     {
       
   431                     iStatusCode = iConnection.SubmitL(iRequest, ipNotOwnedData);
       
   432                     }
       
   433                 else
       
   434                     {
       
   435                     iStatusCode = iConnection.SubmitL(iRequest, iProperties, ipNotOwnedData);
       
   436                     }
       
   437                     
       
   438                 // Notify "owner" that blocking operation has completed
       
   439                 TRequestStatus* status = &ipActive->iStatus;
       
   440                 RThread owner;
       
   441                 owner.Open(ipActive->iOwnerThreadId);
       
   442                 owner.RequestComplete(status, CActiveConsumerTestTask::EDeliverResponse );
       
   443                 }
       
   444             }
       
   445             break;
       
   446            
       
   447         }
       
   448     }
       
   449 
       
   450 /////////////////////////////////////////////////////////////////////////////////////////////////
       
   451 // HELPER CLASS for SC (active) tasks:
       
   452 // Public METHODS
       
   453 
       
   454 CActiveConsumerTestTask* CActiveConsumerTestTask::NewL(TConsumerTestTask& aTask, const TDesC& aThreadName, CSenHostletConnectionBCTest& aOwner)
       
   455     {
       
   456     CActiveConsumerTestTask* pNew = CActiveConsumerTestTask::NewLC(aTask, aThreadName, aOwner);
       
   457     CleanupStack::Pop();
       
   458     return pNew;
       
   459     }
       
   460 
       
   461 CActiveConsumerTestTask* CActiveConsumerTestTask::NewLC(TConsumerTestTask& aTask, const TDesC& aThreadName, CSenHostletConnectionBCTest& aOwner)
       
   462     {
       
   463     CActiveConsumerTestTask* pNew = new (ELeave) CActiveConsumerTestTask(aTask, aOwner);
       
   464     CleanupStack::PushL(pNew);
       
   465     pNew->ConstructL(aThreadName);
       
   466     return pNew;
       
   467     }
       
   468 
       
   469 CActiveConsumerTestTask::CActiveConsumerTestTask(TConsumerTestTask& aTask, CSenHostletConnectionBCTest& aOwner)
       
   470     :   CActive(EPriorityStandard), 
       
   471         iTask(aTask),
       
   472         iOwner(aOwner)
       
   473     {
       
   474     CActiveScheduler::Add(this);    
       
   475     }
       
   476 
       
   477 CActiveConsumerTestTask::~CActiveConsumerTestTask()
       
   478     {
       
   479     if(IsActive())
       
   480         {
       
   481         Cancel(); // issues DoCancel();
       
   482         }
       
   483     iTaskThread.Close();
       
   484     }
       
   485 
       
   486 void CActiveConsumerTestTask::RunL()
       
   487     {
       
   488     switch(iStatus.Int())
       
   489         {
       
   490         case(EInvokeService):
       
   491             {
       
   492             iTaskThread.Resume();
       
   493             }
       
   494             break;
       
   495             
       
   496         case(EDeliverResponse):
       
   497             {
       
   498             iOwner.StopActiveScheduler(); // submit complete..
       
   499             }
       
   500             break;
       
   501          /* case defaul: // unknown */
       
   502         }
       
   503     }
       
   504 void CActiveConsumerTestTask::DoCancel()
       
   505     {
       
   506     iOwner.StopActiveScheduler();
       
   507     }
       
   508     
       
   509 // Private METHODS
       
   510 void CActiveConsumerTestTask::ConstructL(const TDesC& aThreadName)
       
   511     {
       
   512     RThread thread;
       
   513     iOwnerThreadId = thread.Id(); 
       
   514     
       
   515     TInt createThreadRetVal = CreateThreadForConsumerTask(iTaskThread, aThreadName, iTask);        
       
   516     User::LeaveIfError( createThreadRetVal );
       
   517     SetActive();
       
   518     }
       
   519     
       
   520     
       
   521 /////////////////////////////////////////////////////////////////////////////////////////////////
       
   522 
       
   523 void  CSenHostletConnectionBCTest::UT_CSenHostletConnection_WSI_DescribeServiceL(CSenXmlServiceDescription& aSD)
       
   524     {
       
   525     aSD.SetFrameworkIdL(KDefaultBasicWebServicesFrameworkID);
       
   526     aSD.SetEndPointL(KHostletEndpoint);
       
   527     aSD.SetContractL(KHostletContract);
       
   528     }
       
   529 
       
   530 void  CSenHostletConnectionBCTest::UT_CSenHostletConnection_WSI_DescribeService_2L(CSenXmlServiceDescription& aSD)
       
   531     {
       
   532     aSD.SetFrameworkIdL(KDefaultBasicWebServicesFrameworkID);
       
   533     aSD.SetContractL(KHostletContract);
       
   534     }
       
   535 
       
   536 
       
   537 void CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_SetStatus(CSenHostletConnectionBCTest* apTestSuite,
       
   538                                                                     TInt aStatus )
       
   539    {
       
   540     switch( aStatus )
       
   541         {
       
   542         case KSenConnectionStatusReady:
       
   543             {
       
   544             apTestSuite->StopActiveScheduler(); // otherwise failed SC construction is reported via HandleErrorL(!)
       
   545             }
       
   546             break;
       
   547         case KSenConnectionStatusNew:
       
   548         case KSenConnectionStatusExpired:
       
   549         default:            
       
   550             break;
       
   551         }
       
   552     }
       
   553 
       
   554 
       
   555 
       
   556 // not in use atm:
       
   557 void CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleMessageL(CSenHostletConnectionBCTest* /* apTestSuite */, const TDesC8& /* aMessage*/ )
       
   558     {
       
   559     }
       
   560 
       
   561 //used by UT_CSenHostletConnection_Negative_ResponseCodeL
       
   562 //used by UT_CSenHostletConnection_Delete_HCL
       
   563 void CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleErrorL(CSenHostletConnectionBCTest* apTestSuite, const TInt  /*aErrorCode*/ , const TDesC8& /* aMessage */)
       
   564     {
       
   565     apTestSuite->iWas_HandleErrorL_Accessed = ETrue;
       
   566     }
       
   567     
       
   568 //used by the UT_CSenHostletConnection_Negative_ResponseCodeL    
       
   569 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceL(CSenHostletConnectionBCTest*  apTestSuite , MSenHostletRequest&  /*aRequest*/ , MSenHostletResponse&  aResponse )
       
   570     {
       
   571     TInt alteredResponseCode = -148000;
       
   572     _LIT8(KAlteredResponse, "<Response><ReplyMessage>Response Altered in UT_CSenHostletConnection_NewLL_OnServiceL.</ReplyMessage><Request>%S</Request></Response>");
       
   573     apTestSuite->ipHostlet->iResponseCodes[apTestSuite->ipHostlet->iTxnIds.Count()-1] = alteredResponseCode;
       
   574     aResponse.SetResponseUtf8L(KAlteredResponse, alteredResponseCode);
       
   575     return KErrNone;
       
   576     }
       
   577     
       
   578 // not in use atm:    
       
   579 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceCompleteL(CSenHostletConnectionBCTest* /* apTestSuite */, const TInt /* aTxnId */, TInt /* aCompletionCode */, const TDesC8& /* aDesc */ )
       
   580     {
       
   581     return KErrNone;
       
   582     }    
       
   583     
       
   584 //used by the UT_CSenHostletConnection_DeleteSC_before_HCRespondLL method
       
   585 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnService1L(CSenHostletConnectionBCTest*  apTestSuite , MSenHostletRequest&  /*aRequest*/ , MSenHostletResponse&  /*aResponse*/ )
       
   586     {
       
   587     apTestSuite->ipConnection->Cancel();
       
   588     delete apTestSuite->ipConnection;
       
   589     apTestSuite->ipConnection = NULL;
       
   590     return KErrNone;
       
   591     }
       
   592     
       
   593 //used by UT_CSenHostletConnection_DeleteSC_before_HCRespondLL
       
   594 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceComplete1L(CSenHostletConnectionBCTest* apTestSuite, const TInt /* aTxnId */, TInt /*aCompletionCode*/ , const TDesC8& /* aDesc */ )
       
   595     {
       
   596 	apTestSuite->iWas_OnServiceL_Accessed = ETrue;
       
   597     return KErrNone;
       
   598     }        
       
   599 
       
   600 // used by the UT_CSenHostletConnection_RespondL_4multipleTimesL method
       
   601 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnService2L(CSenHostletConnectionBCTest*  apTestSuite , MSenHostletRequest&  /*aRequest*/ , MSenHostletResponse&  aResponse )
       
   602     {
       
   603     TInt respondRetCode = apTestSuite->ipHostletConnection->RespondL(aResponse);
       
   604     TInt respondRetCode1 = apTestSuite->ipHostletConnection->RespondL(aResponse);
       
   605 	LOCAL_ASSERT(respondRetCode == KErrNone);    
       
   606     LOCAL_ASSERT(respondRetCode1 == KErrAlreadyExists);
       
   607     return KErrNone;
       
   608     }
       
   609     
       
   610 // to be used (currently does nothing) by the UT_CSenHostletConnection_RespondL_4multipleTimesL method    
       
   611 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceComplete2L(CSenHostletConnectionBCTest* /* apTestSuite */, const TInt /* aTxnId */, TInt /*aCompletionCode*/ , const TDesC8& /* aDesc */ )
       
   612     {
       
   613     return KErrNone;
       
   614     }        
       
   615     
       
   616 //used by the UT_CSenHostletConnection_SC_Cancel_After_RequestL method
       
   617 void CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleError1L(CSenHostletConnectionBCTest* apTestSuite, const TInt  /* aErrorCode */, const TDesC8& /* aMessage */)
       
   618     {
       
   619 //    TInt a = aErrorCode;
       
   620     apTestSuite->iWas_HandleErrorL_Accessed = ETrue;
       
   621     }
       
   622 //used by the UT_CSenHostletConnection_SC_Cancel_After_RequestL method
       
   623 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnService3L(CSenHostletConnectionBCTest*  apTestSuite , MSenHostletRequest&  /*aRequest*/ , MSenHostletResponse&  /*aResponse*/ )
       
   624     {
       
   625    // apTestSuite->ipConnection->Cancel();
       
   626    //canceling request
       
   627     apTestSuite->ipConnection->CancelTransaction(apTestSuite->iTxnID);
       
   628     return KErrNone;
       
   629     }
       
   630 
       
   631 
       
   632 //used by the UT_CSenHostletConnection_RespondWithPropertiesL method in order to provide transport properties with the response
       
   633 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_RespondWithPropertiesL_OnServiceL(CSenHostletConnectionBCTest*  apTestSuite , MSenHostletRequest&  /*aRequest*/ , MSenHostletResponse&  aResponse )
       
   634     {
       
   635     TInt txn =          apTestSuite->ipHostlet->iTxnIds.Count()-1;
       
   636     TPtr8 response =    apTestSuite->ipHostlet->iResponses[txn]->Des();
       
   637 
       
   638     TInt responseCode = apTestSuite->ipHostlet->iResponseCodes[txn];
       
   639 
       
   640     CSenTransportProperties* pTransportProperties = CSenTransportProperties::NewLC();
       
   641     _LIT8(KTestCid, "test:cid");
       
   642     _LIT8(KTestFile, "c:\\test.file.txt");
       
   643     pTransportProperties->SetFileAttachmentL( KTestCid, KTestFile );
       
   644     
       
   645     if( apTestSuite->ipHostlet->iResponseProps.Append( pTransportProperties ) )
       
   646         {
       
   647         // error:
       
   648         CleanupStack::PopAndDestroy(pTransportProperties);
       
   649         return KErrNoMemory;
       
   650         }
       
   651     else
       
   652         {
       
   653         // ok
       
   654         CleanupStack::Pop(pTransportProperties);
       
   655         aResponse.SetResponseUtf8L(response, responseCode, pTransportProperties); // by default, all requests are "accepted"
       
   656         return KErrNone;
       
   657         }
       
   658     }
       
   659 
       
   660 
       
   661 
       
   662 //---------------------------------------------------------------
       
   663 // 							Test Cases
       
   664 //---------------------------------------------------------------
       
   665 
       
   666 
       
   667 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL(TTestResult& aResult)
       
   668     {
       
   669 	SetupL(); 
       
   670     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
   671     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
   672 
       
   673 //    ipHostlet = CTestHostlet::NewL(this,
       
   674 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceL,
       
   675 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceCompleteL);
       
   676 
       
   677 //    ipConsumer = CTestConsumer::NewL(this, 
       
   678 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleMessageL, 
       
   679 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleErrorL, 
       
   680 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_SetStatus);
       
   681 
       
   682     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
   683 
       
   684     CSenServicePattern* pPattern =
       
   685         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
   686     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
   687     
       
   688     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
   689     CleanupStack::PopAndDestroy(pPattern);
       
   690     
       
   691     // Construct service connection
       
   692     StartActiveScheduler(1);
       
   693     
       
   694     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
   695 
       
   696     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
   697 
       
   698     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
   699     
       
   700     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
   701     StartActiveScheduler(2);
       
   702 
       
   703     // ---- Following conditions MUST be met ----
       
   704 
       
   705     // 1. Hostlet receives request that consumer made
       
   706     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
   707 
       
   708     // 2. Consumer receives response that hostlet provided
       
   709     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
   710     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
   711 
       
   712     // 3. Hostlet receives completion code (delivery code)
       
   713     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
   714     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
   715     
       
   716     // --- Conditions END ---
       
   717     
       
   718     delete ipConnection;
       
   719     ipConnection = NULL;
       
   720     delete ipHostletConnection; 
       
   721     ipHostletConnection = NULL;
       
   722     delete ipHostlet;
       
   723     ipHostlet = NULL;
       
   724     delete ipConsumer;
       
   725     ipConsumer = NULL;
       
   726     Teardown();
       
   727     return KErrNone;
       
   728     }
       
   729 
       
   730     
       
   731 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLCL(TTestResult& aResult)
       
   732     {
       
   733 	SetupL(); 
       
   734     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
   735     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
   736 
       
   737 //    ipHostlet = CTestHostlet::NewL(this,
       
   738 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceL,
       
   739 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceCompleteL);
       
   740 
       
   741 //    ipConsumer = CTestConsumer::NewL(this, 
       
   742 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleMessageL, 
       
   743 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleErrorL, 
       
   744 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_SetStatus);
       
   745 
       
   746     ipHostletConnection = CSenHostletConnection::NewLC(*ipHostlet);
       
   747 
       
   748     CSenServicePattern* pPattern =
       
   749         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
   750     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
   751     
       
   752     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
   753     CleanupStack::PopAndDestroy(pPattern);
       
   754     
       
   755     // Construct service connection
       
   756     StartActiveScheduler(1);
       
   757     
       
   758     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
   759 
       
   760     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
   761 
       
   762     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
   763     
       
   764     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
   765     StartActiveScheduler(2);
       
   766 
       
   767     // ---- Following conditions MUST be met ----
       
   768 
       
   769     // 1. Hostlet receives request that consumer made
       
   770     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
   771 
       
   772     // 2. Consumer receives response that hostlet provided
       
   773     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
   774     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
   775 
       
   776     // 3. Hostlet receives completion code (delivery code)
       
   777     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
   778     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
   779     
       
   780     // --- Conditions END ---
       
   781     
       
   782     delete ipConnection;
       
   783     ipConnection = NULL;
       
   784     CleanupStack::PopAndDestroy(ipHostletConnection);
       
   785     //delete ipHostletConnection; 
       
   786     //ipHostletConnection = NULL;
       
   787     delete ipHostlet;
       
   788     ipHostlet = NULL;
       
   789     delete ipConsumer;
       
   790     ipConsumer = NULL;
       
   791     Teardown();
       
   792     return KErrNone;
       
   793     }
       
   794 
       
   795 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_IdentifierL(TTestResult& aResult)
       
   796     {
       
   797 	SetupL(); 
       
   798     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
   799     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
   800 
       
   801 //    ipHostlet = CTestHostlet::NewL(this,
       
   802 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceL,
       
   803 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceCompleteL);
       
   804 
       
   805 //    ipConsumer = CTestConsumer::NewL(this, 
       
   806 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleMessageL, 
       
   807 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleErrorL, 
       
   808 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_SetStatus);
       
   809 
       
   810     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
   811 
       
   812     CSenServicePattern* pPattern =
       
   813         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
   814     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
   815     
       
   816     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
   817     CleanupStack::PopAndDestroy(pPattern);
       
   818     
       
   819     TInt id;
       
   820     id = ipHostletConnection->Identifier();
       
   821     LOCAL_ASSERT( id  != KErrNotReady);
       
   822     TPtrC8 framework = ipHostlet->FrameworkId();
       
   823     // Construct service connection
       
   824     StartActiveScheduler(1);
       
   825     
       
   826     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
   827 
       
   828     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
   829 
       
   830     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
   831     
       
   832     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
   833     StartActiveScheduler(2);
       
   834 
       
   835     // ---- Following conditions MUST be met ----
       
   836 
       
   837     // 1. Hostlet receives request that consumer made
       
   838     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
   839 
       
   840     // 2. Consumer receives response that hostlet provided
       
   841     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
   842     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
   843 
       
   844     // 3. Hostlet receives completion code (delivery code)
       
   845     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
   846     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
   847     
       
   848     // --- Conditions END ---
       
   849     
       
   850     delete ipConnection;
       
   851     ipConnection = NULL;
       
   852     delete ipHostletConnection; 
       
   853     ipHostletConnection = NULL;
       
   854     delete ipHostlet;
       
   855     ipHostlet = NULL;
       
   856     delete ipConsumer;
       
   857     ipConsumer = NULL;
       
   858     Teardown();
       
   859     return KErrNone;
       
   860     }
       
   861 
       
   862 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_FrameworkIdL(TTestResult& aResult)
       
   863     {
       
   864 	SetupL(); 
       
   865     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
   866     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
   867 
       
   868 //    ipHostlet = CTestHostlet::NewL(this,
       
   869 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceL,
       
   870 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceCompleteL);
       
   871 
       
   872 //    ipConsumer = CTestConsumer::NewL(this, 
       
   873 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleMessageL, 
       
   874 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleErrorL, 
       
   875 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_SetStatus);
       
   876 
       
   877     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
   878 
       
   879     CSenServicePattern* pPattern =
       
   880         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
   881     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
   882     
       
   883     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
   884     CleanupStack::PopAndDestroy(pPattern);
       
   885     
       
   886     TInt id;
       
   887     id = ipHostletConnection->Identifier();
       
   888     LOCAL_ASSERT( id  != KErrNotReady);
       
   889     _LIT8(KFramework, "REST");
       
   890     TPtrC8 framework = ipHostlet->FrameworkId();
       
   891     LOCAL_ASSERT( framework == KFramework);
       
   892     // Construct service connection
       
   893     StartActiveScheduler(1);
       
   894     
       
   895     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
   896 
       
   897     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
   898 
       
   899     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
   900     
       
   901     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
   902     StartActiveScheduler(2);
       
   903 
       
   904     // ---- Following conditions MUST be met ----
       
   905 
       
   906     // 1. Hostlet receives request that consumer made
       
   907     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
   908 
       
   909     // 2. Consumer receives response that hostlet provided
       
   910     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
   911     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
   912 
       
   913     // 3. Hostlet receives completion code (delivery code)
       
   914     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
   915     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
   916     
       
   917     // --- Conditions END ---
       
   918     
       
   919     delete ipConnection;
       
   920     ipConnection = NULL;
       
   921     delete ipHostletConnection; 
       
   922     ipHostletConnection = NULL;
       
   923     delete ipHostlet;
       
   924     ipHostlet = NULL;
       
   925     delete ipConsumer;
       
   926     ipConsumer = NULL;
       
   927     Teardown();
       
   928     return KErrNone;
       
   929     }
       
   930 
       
   931 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_RequestUtf8L(TTestResult& aResult)
       
   932     {
       
   933 	SetupL(); 
       
   934     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
   935     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
   936 
       
   937 //    ipHostlet = CTestHostlet::NewL(this,
       
   938 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceL,
       
   939 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceCompleteL);
       
   940 
       
   941 //    ipConsumer = CTestConsumer::NewL(this, 
       
   942 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleMessageL, 
       
   943 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleErrorL, 
       
   944 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_SetStatus);
       
   945 
       
   946     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
   947 
       
   948     CSenServicePattern* pPattern =
       
   949         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
   950     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
   951     
       
   952     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
   953     CleanupStack::PopAndDestroy(pPattern);
       
   954     
       
   955     TInt id;
       
   956     id = ipHostletConnection->Identifier();
       
   957     LOCAL_ASSERT( id  != KErrNotReady);
       
   958     TPtrC8 request = ipHostlet->RequestUtf8();
       
   959     LOCAL_ASSERT( request == _L8(""));
       
   960     // Construct service connection
       
   961     StartActiveScheduler(1);
       
   962     
       
   963     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
   964 
       
   965     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
   966 
       
   967     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
   968     
       
   969     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
   970     StartActiveScheduler(2);
       
   971 
       
   972     // ---- Following conditions MUST be met ----
       
   973 
       
   974     // 1. Hostlet receives request that consumer made
       
   975     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
   976 
       
   977     // 2. Consumer receives response that hostlet provided
       
   978     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
   979     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
   980 
       
   981     // 3. Hostlet receives completion code (delivery code)
       
   982     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
   983     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
   984     
       
   985     // --- Conditions END ---
       
   986     
       
   987     delete ipConnection;
       
   988     ipConnection = NULL;
       
   989     delete ipHostletConnection; 
       
   990     ipHostletConnection = NULL;
       
   991     delete ipHostlet;
       
   992     ipHostlet = NULL;
       
   993     delete ipConsumer;
       
   994     ipConsumer = NULL;
       
   995     Teardown();
       
   996     return KErrNone;
       
   997     }
       
   998 
       
   999 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_ThreadIdL(TTestResult& aResult)
       
  1000     {
       
  1001 	SetupL(); 
       
  1002     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1003     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  1004 
       
  1005 //    ipHostlet = CTestHostlet::NewL(this,
       
  1006 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceL,
       
  1007 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceCompleteL);
       
  1008 
       
  1009 //    ipConsumer = CTestConsumer::NewL(this, 
       
  1010 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleMessageL, 
       
  1011 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleErrorL, 
       
  1012 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_SetStatus);
       
  1013 
       
  1014     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  1015 
       
  1016     CSenServicePattern* pPattern =
       
  1017         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  1018     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1019     
       
  1020     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  1021     CleanupStack::PopAndDestroy(pPattern);
       
  1022     
       
  1023     TInt id;
       
  1024     id = ipHostletConnection->Identifier();
       
  1025     LOCAL_ASSERT( id  != KErrNotReady);
       
  1026     TPtrC threadId = ipHostlet->ThreadId();
       
  1027     LOCAL_ASSERT( threadId == _L(""));
       
  1028     // Construct service connection
       
  1029     StartActiveScheduler(1);
       
  1030     
       
  1031     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1032 
       
  1033     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  1034 
       
  1035     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1036     
       
  1037     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  1038     StartActiveScheduler(2);
       
  1039 
       
  1040     // ---- Following conditions MUST be met ----
       
  1041 
       
  1042     // 1. Hostlet receives request that consumer made
       
  1043     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  1044 
       
  1045     // 2. Consumer receives response that hostlet provided
       
  1046     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  1047     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  1048 
       
  1049     // 3. Hostlet receives completion code (delivery code)
       
  1050     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  1051     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  1052     
       
  1053     // --- Conditions END ---
       
  1054     
       
  1055     delete ipConnection;
       
  1056     ipConnection = NULL;
       
  1057     delete ipHostletConnection; 
       
  1058     ipHostletConnection = NULL;
       
  1059     delete ipHostlet;
       
  1060     ipHostlet = NULL;
       
  1061     delete ipConsumer;
       
  1062     ipConsumer = NULL;
       
  1063     Teardown();
       
  1064     return KErrNone;
       
  1065     }
       
  1066 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_ConsumerIdL(TTestResult& aResult)
       
  1067 	{
       
  1068 	SetupL(); 
       
  1069     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1070     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  1071 
       
  1072 //    ipHostlet = CTestHostlet::NewL(this,
       
  1073 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceL,
       
  1074 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceCompleteL);
       
  1075 
       
  1076 //    ipConsumer = CTestConsumer::NewL(this, 
       
  1077 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleMessageL, 
       
  1078 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleErrorL, 
       
  1079 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_SetStatus);
       
  1080 
       
  1081     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  1082 
       
  1083     CSenServicePattern* pPattern =
       
  1084         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  1085     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1086     
       
  1087     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  1088     CleanupStack::PopAndDestroy(pPattern);
       
  1089     
       
  1090     TInt id;
       
  1091     id = ipHostletConnection->Identifier();
       
  1092     LOCAL_ASSERT( id  != KErrNotReady);
       
  1093     TPtrC8 consumerId = ipHostlet->ConsumerId();
       
  1094     LOCAL_ASSERT( consumerId == _L8(""));
       
  1095     // Construct service connection
       
  1096     StartActiveScheduler(1);
       
  1097     
       
  1098     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1099 
       
  1100     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  1101 
       
  1102     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1103     
       
  1104     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  1105     StartActiveScheduler(2);
       
  1106 
       
  1107     // ---- Following conditions MUST be met ----
       
  1108 
       
  1109     // 1. Hostlet receives request that consumer made
       
  1110     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  1111 
       
  1112     // 2. Consumer receives response that hostlet provided
       
  1113     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  1114     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  1115 
       
  1116     // 3. Hostlet receives completion code (delivery code)
       
  1117     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  1118     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  1119     
       
  1120     // --- Conditions END ---
       
  1121     
       
  1122     delete ipConnection;
       
  1123     ipConnection = NULL;
       
  1124     delete ipHostletConnection; 
       
  1125     ipHostletConnection = NULL;
       
  1126     delete ipHostlet;
       
  1127     ipHostlet = NULL;
       
  1128     delete ipConsumer;
       
  1129     ipConsumer = NULL;
       
  1130     Teardown();
       
  1131     return KErrNone;
       
  1132     }
       
  1133 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_RequestIdL(TTestResult& aResult)
       
  1134 	{
       
  1135 	SetupL(); 
       
  1136     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1137     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  1138 
       
  1139 //    ipHostlet = CTestHostlet::NewL(this,
       
  1140 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceL,
       
  1141 //                                   &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceCompleteL);
       
  1142 
       
  1143 //    ipConsumer = CTestConsumer::NewL(this, 
       
  1144 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleMessageL, 
       
  1145 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleErrorL, 
       
  1146 //                                     &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_SetStatus);
       
  1147 
       
  1148     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  1149 
       
  1150     CSenServicePattern* pPattern =
       
  1151         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  1152     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1153     
       
  1154     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  1155     CleanupStack::PopAndDestroy(pPattern);
       
  1156     
       
  1157     TInt id;
       
  1158     id = ipHostletConnection->Identifier();
       
  1159     LOCAL_ASSERT( id  != KErrNotReady);
       
  1160     TInt requestId = ipHostlet->RequestId();
       
  1161     LOCAL_ASSERT( requestId == KErrNone);
       
  1162     // Construct service connection
       
  1163     StartActiveScheduler(1);
       
  1164     
       
  1165     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1166 
       
  1167     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  1168 
       
  1169     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1170     
       
  1171     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  1172     StartActiveScheduler(2);
       
  1173 
       
  1174     // ---- Following conditions MUST be met ----
       
  1175 
       
  1176     // 1. Hostlet receives request that consumer made
       
  1177     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  1178 
       
  1179     // 2. Consumer receives response that hostlet provided
       
  1180     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  1181     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  1182 
       
  1183     // 3. Hostlet receives completion code (delivery code)
       
  1184     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  1185     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  1186     
       
  1187     // --- Conditions END ---
       
  1188     
       
  1189     delete ipConnection;
       
  1190     ipConnection = NULL;
       
  1191     delete ipHostletConnection; 
       
  1192     ipHostletConnection = NULL;
       
  1193     delete ipHostlet;
       
  1194     ipHostlet = NULL;
       
  1195     delete ipConsumer;
       
  1196     ipConsumer = NULL;
       
  1197     Teardown();
       
  1198     return KErrNone;		
       
  1199 	}
       
  1200 	
       
  1201 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLC_3InvokesL(TTestResult& aResult)
       
  1202     {
       
  1203 	SetupL(); 
       
  1204     // Try to send _two_ messages from ServiceConnection to HostletConnection
       
  1205     // and check that everything goes OK.
       
  1206 
       
  1207     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Abel\'] or containts[ab:N/ab:GIVEN,\'Abel\'] or containts[ab:TEL,\'Abel\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1208     _LIT8(KRequest2, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1209     _LIT8(KRequest3, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Clarice\'] or containts[ab:N/ab:GIVEN,\'Clarice\'] or containts[ab:TEL,\'Clarice\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1210     
       
  1211     // Construct Hostlet
       
  1212     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1213     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  1214 
       
  1215     // Construct ServiceConnection
       
  1216     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  1217     CSenServicePattern* pPattern =
       
  1218         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  1219     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1220     
       
  1221     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  1222     CleanupStack::PopAndDestroy(pPattern);
       
  1223     StartActiveScheduler(1);
       
  1224     
       
  1225     // Check that the Status of the ServiceConnection
       
  1226     // is KSenConnectionStatusReady
       
  1227     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady);
       
  1228     
       
  1229     // ServiceConnection is ready
       
  1230 
       
  1231     // => Send first request to the Hostlet
       
  1232     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  1233     
       
  1234     // Check that SendL returned transaction Id
       
  1235     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1236 
       
  1237     // => Send second request to the Hostlet
       
  1238     TInt transactionIdOrError2 = ipConnection->SendL(KRequest2);
       
  1239     
       
  1240     // => Send second request to the Hostlet
       
  1241     TInt transactionIdOrError3 = ipConnection->SendL(KRequest3);
       
  1242 
       
  1243     // Check that SendL returned transaction Id
       
  1244     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1245     
       
  1246     // Invoke service  THREE TIMES (one call to ServiceL), respond to consumer THREE TIMES => six async calls:
       
  1247     StartActiveScheduler(6);
       
  1248 
       
  1249     // ---- Following conditions MUST be met ----
       
  1250 
       
  1251     // 1. Hostlet receives request that consumer made
       
  1252 	LOCAL_ASSERT(*ipHostlet->iRequests[0] == KRequest);
       
  1253 	LOCAL_ASSERT(*ipHostlet->iRequests[1] == KRequest2);
       
  1254 	LOCAL_ASSERT(*ipHostlet->iRequests[2] == KRequest3);
       
  1255 	
       
  1256 	// 2. Consumer receives response that hostlet provided
       
  1257 	LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  1258 	LOCAL_ASSERT( *ipConsumer->iResponses[1] == *ipHostlet->iResponses[1]);
       
  1259 	LOCAL_ASSERT( *ipConsumer->iResponses[2] == *ipHostlet->iResponses[2]);
       
  1260 
       
  1261     // 3. Hostlet receives completion code (delivery code)
       
  1262 	LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  1263 	LOCAL_ASSERT( ipConsumer->iResponseCodes[1] == ipHostlet->iResponseCodes[1])
       
  1264 	LOCAL_ASSERT( ipConsumer->iResponseCodes[2] == ipHostlet->iResponseCodes[2])
       
  1265 
       
  1266 
       
  1267 	LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError);
       
  1268 	LOCAL_ASSERT( ipHostlet->iTxnIds[1] == transactionIdOrError2);
       
  1269 	LOCAL_ASSERT( ipHostlet->iTxnIds[2] == transactionIdOrError3);
       
  1270 
       
  1271     
       
  1272     // --- Conditions END ---
       
  1273     
       
  1274     delete ipConnection;
       
  1275     ipConnection = NULL;
       
  1276     delete ipHostletConnection; 
       
  1277     ipHostletConnection = NULL;
       
  1278     delete ipHostlet;
       
  1279     ipHostlet = NULL;
       
  1280     delete ipConsumer;
       
  1281     ipConsumer = NULL;
       
  1282     Teardown();
       
  1283     return KErrNone;
       
  1284     }
       
  1285 
       
  1286 
       
  1287 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_RespondL1L(TTestResult& aResult)
       
  1288     {
       
  1289 	SetupL(); 
       
  1290     // Try to send _one_ message from ServiceConnection to HostletConnection
       
  1291     // and check that everything goes OK.
       
  1292     
       
  1293     // Construct Hostlet
       
  1294     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1295     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  1296 
       
  1297     // Construct ServiceConnection
       
  1298     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  1299     CSenServicePattern* pPattern =
       
  1300         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  1301     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1302     
       
  1303     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  1304     CleanupStack::PopAndDestroy(pPattern);
       
  1305     StartActiveScheduler(1);
       
  1306     
       
  1307     // Check that the Status of the ServiceConnection
       
  1308     // is KSenConnectionStatusReady
       
  1309     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady);
       
  1310     
       
  1311     
       
  1312 	CSenTransportProperties* pProps = CSenTransportProperties::NewLC();
       
  1313 	pProps->SetPropertyL(_L8("KTestProperty"), _L8("KTestPropertyValue"));
       
  1314 	HBufC8* pPropsAsXml = pProps->AsUtf8LC();
       
  1315     TPtrC8 propertiesAsXml = pPropsAsXml->Des();
       
  1316     
       
  1317     // ServiceConnection is ready
       
  1318     // => Send request to the Hostlet
       
  1319     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1320     TInt transactionIdOrError = ipConnection->SendL(KRequest, propertiesAsXml);
       
  1321     
       
  1322     // Check that SendL returned transaction Id
       
  1323     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1324     
       
  1325     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  1326     StartActiveScheduler(2);
       
  1327 
       
  1328     // ---- Following conditions MUST be met ----
       
  1329 
       
  1330     // 1. Hostlet receives request that consumer made
       
  1331     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  1332 
       
  1333     // 2. Consumer receives response that hostlet provided
       
  1334     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  1335     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  1336 
       
  1337     // 3. Hostlet receives completion code (delivery code)
       
  1338     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  1339     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  1340     
       
  1341     // 4. The properties that were sent via SC were received in HC
       
  1342     MSenProperties::TSenPropertiesClassType type = ipHostlet->iRequestPropTypes[0];
       
  1343     TPtrC8 properties = ipHostlet->iRequestProps[0]->Des();
       
  1344 
       
  1345     LOCAL_ASSERT( properties == propertiesAsXml );
       
  1346     
       
  1347     // --- Conditions END ---
       
  1348 
       
  1349     CleanupStack::PopAndDestroy( pPropsAsXml );
       
  1350     CleanupStack::PopAndDestroy( pProps );
       
  1351     
       
  1352     
       
  1353     delete ipConnection;
       
  1354     ipConnection = NULL;
       
  1355     delete ipHostletConnection; 
       
  1356     ipHostletConnection = NULL;
       
  1357     delete ipHostlet;
       
  1358     ipHostlet = NULL;
       
  1359     delete ipConsumer;
       
  1360     ipConsumer = NULL;
       
  1361     Teardown();
       
  1362     return KErrNone;
       
  1363     }
       
  1364 
       
  1365 
       
  1366 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_RespondL2L(TTestResult& aResult)
       
  1367     {
       
  1368 	SetupL(); 
       
  1369     // Try to send _two_ messages from ServiceConnection to HostletConnection
       
  1370     // and check that everything goes OK.
       
  1371 
       
  1372     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1373     
       
  1374     // Construct Hostlet
       
  1375     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1376     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  1377 
       
  1378     // Construct ServiceConnection
       
  1379     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  1380     CSenServicePattern* pPattern =
       
  1381         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  1382     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1383     
       
  1384     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  1385     CleanupStack::PopAndDestroy(pPattern);
       
  1386     StartActiveScheduler(1);
       
  1387     
       
  1388     // Check that the Status of the ServiceConnection
       
  1389     // is KSenConnectionStatusReady
       
  1390     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady);
       
  1391     
       
  1392     // ServiceConnection is ready
       
  1393 
       
  1394     // => Send first request to the Hostlet
       
  1395     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  1396     
       
  1397     // Check that SendL returned transaction Id
       
  1398     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1399 
       
  1400     // => Send second request to the Hostlet
       
  1401     TInt transactionIdOrError2 = ipConnection->SendL(KRequest);
       
  1402     
       
  1403     // Check that SendL returned transaction Id
       
  1404     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1405     
       
  1406     // Invoke service  TWICE (one call to ServiceL), respond to consumer TWICE => four calls:
       
  1407     StartActiveScheduler(4);
       
  1408 
       
  1409     // ---- Following conditions MUST be met ----
       
  1410 
       
  1411     // 1. Hostlet receives request that consumer made
       
  1412     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  1413     LOCAL_ASSERT( *ipHostlet->iRequests[1] == KRequest);    
       
  1414 
       
  1415     // 2. Consumer receives response that hostlet provided
       
  1416     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  1417     LOCAL_ASSERT( *ipConsumer->iResponses[1] == *ipHostlet->iResponses[1]);
       
  1418     
       
  1419     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  1420     LOCAL_ASSERT( ipConsumer->iResponseCodes[1] == ipHostlet->iResponseCodes[1])
       
  1421     
       
  1422     // 3. Hostlet receives completion code (delivery code)
       
  1423     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError)
       
  1424     LOCAL_ASSERT( ipHostlet->iTxnIds[1] == transactionIdOrError2)
       
  1425     
       
  1426     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  1427     LOCAL_ASSERT( ipHostlet->iCompletionCodes[1] == KErrNone ); // true in this "OK" -test case   
       
  1428     
       
  1429     // --- Conditions END ---
       
  1430     
       
  1431     delete ipConnection;
       
  1432     ipConnection = NULL;
       
  1433     delete ipHostletConnection; 
       
  1434     ipHostletConnection = NULL;
       
  1435     delete ipHostlet;
       
  1436     ipHostlet = NULL;
       
  1437     delete ipConsumer;
       
  1438     ipConsumer = NULL;
       
  1439     Teardown();
       
  1440     return KErrNone;
       
  1441     }
       
  1442 
       
  1443 
       
  1444 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_RespondL3L(TTestResult& aResult)
       
  1445     {
       
  1446     	//Memory leak detection is not supported since Symbian 9.0 (EKA2 kernel) environments.
       
  1447     	//This this is added to handle thread handle leak in testmodule0
       
  1448     TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles);
       
  1449 	SetupL(); 
       
  1450     // Try to send _one_ message from ServiceConnection to HostletConnection
       
  1451     // and check that everything goes OK.
       
  1452     
       
  1453     // Construct Hostlet
       
  1454     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1455     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  1456 
       
  1457     // Construct ServiceConnection
       
  1458     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  1459     CSenServicePattern* pPattern =
       
  1460         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  1461     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1462     
       
  1463     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  1464     CleanupStack::PopAndDestroy(pPattern);
       
  1465     StartActiveScheduler(1);
       
  1466     
       
  1467     // Check that the Status of the ServiceConnection
       
  1468     // is KSenConnectionStatusReady
       
  1469     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady);
       
  1470     
       
  1471     // Construct 2. ServiceConnection
       
  1472     CTestConsumer* pConsumer2 = CTestConsumer::NewLC(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  1473 
       
  1474     CSenServicePattern* pPattern2 =
       
  1475         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  1476     pPattern2->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1477     CSenServiceConnection* pConnection2 = CSenServiceConnection::NewL(*pConsumer2, *pPattern2);
       
  1478     CleanupStack::PopAndDestroy(pPattern2);
       
  1479     CleanupStack::PushL(pConnection2);
       
  1480     StartActiveScheduler(1);
       
  1481     
       
  1482     // Check that the Status of the ServiceConnection
       
  1483     // is KSenConnectionStatusReady
       
  1484     LOCAL_ASSERT( pConsumer2->iConnectionStatus == KSenConnectionStatusReady);
       
  1485     
       
  1486 	CSenTransportProperties* pProps = CSenTransportProperties::NewLC();
       
  1487 	pProps->SetPropertyL(_L8("KTestProperty"), _L8("KTestPropertyValue"));
       
  1488 	HBufC8* pPropsAsXml = pProps->AsUtf8LC();
       
  1489     TPtrC8 propertiesAsXml = pPropsAsXml->Des();
       
  1490     
       
  1491     // ServiceConnection is ready
       
  1492     // => Send request to the Hostlet
       
  1493     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1494     TInt transactionIdOrError = ipConnection->SendL(KRequest, propertiesAsXml);
       
  1495     
       
  1496     // Check that SendL returned transaction Id
       
  1497     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1498     
       
  1499     // 2. ServiceConnection is ready
       
  1500     // => Send 2. request to the Hostlet
       
  1501     TInt transactionIdOrError2 = pConnection2->SendL(KRequest, propertiesAsXml);
       
  1502     
       
  1503     // Check that SendL returned transaction Id
       
  1504     LOCAL_ASSERT(transactionIdOrError2 > KErrNone);
       
  1505     
       
  1506     // Invoke service  TWICE (two calls to ServiceL), respond to consumer TWICE => four calls
       
  1507     StartActiveScheduler(4);
       
  1508 
       
  1509     // ---- Following conditions MUST be met ----
       
  1510 
       
  1511     // 1. Hostlet receives request that consumer made
       
  1512     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  1513 
       
  1514     // 2. Consumer receives response that hostlet provided
       
  1515     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  1516     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  1517 
       
  1518     // 3. Hostlet receives completion code (delivery code)
       
  1519     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  1520     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  1521     
       
  1522     // 4. The properties that were sent via SC were received in HC
       
  1523     MSenProperties::TSenPropertiesClassType type = ipHostlet->iRequestPropTypes[0];
       
  1524     TPtrC8 properties = ipHostlet->iRequestProps[0]->Des();
       
  1525 
       
  1526     LOCAL_ASSERT( properties == propertiesAsXml );
       
  1527     
       
  1528     // --- Conditions END ---
       
  1529 
       
  1530     CleanupStack::PopAndDestroy( pPropsAsXml );
       
  1531     CleanupStack::PopAndDestroy( pProps );
       
  1532     
       
  1533     
       
  1534     delete ipConnection;
       
  1535     ipConnection = NULL;
       
  1536     delete ipHostletConnection; 
       
  1537     ipHostletConnection = NULL;
       
  1538     delete ipHostlet;
       
  1539     ipHostlet = NULL;
       
  1540     delete ipConsumer;
       
  1541     ipConsumer = NULL;
       
  1542     
       
  1543     CleanupStack::PopAndDestroy(pConnection2);
       
  1544     CleanupStack::PopAndDestroy(pConsumer2);
       
  1545     Teardown();
       
  1546     return KErrNone;
       
  1547     }
       
  1548 
       
  1549 
       
  1550 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_Negative_ResponseCodeL(TTestResult& aResult)
       
  1551     {
       
  1552 	SetupL(); 
       
  1553        
       
  1554  	iWas_HandleErrorL_Accessed = EFalse;
       
  1555     ipHostlet = CTestHostlet::NewL(this,
       
  1556                                    &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceL,
       
  1557                                    NULL);
       
  1558 
       
  1559     ipConsumer = CTestConsumer::NewL(this, 
       
  1560                                      NULL, 
       
  1561                                      &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleErrorL, 
       
  1562                                      NULL);
       
  1563 
       
  1564     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  1565 	
       
  1566     CSenServicePattern* pPattern =
       
  1567         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  1568     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1569     
       
  1570     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  1571     CleanupStack::PopAndDestroy(pPattern);
       
  1572     
       
  1573     // Construct service connection
       
  1574     StartActiveScheduler(1);
       
  1575     
       
  1576     
       
  1577     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1578 
       
  1579     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  1580     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1581     
       
  1582     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  1583     StartActiveScheduler(2);
       
  1584     // ---- Following conditions MUST be met ----
       
  1585 
       
  1586     // 1. Hostlet receives request that consumer made
       
  1587     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  1588 
       
  1589     // 2. Consumer receives response that hostlet provided
       
  1590     
       
  1591     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  1592     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  1593     
       
  1594     
       
  1595  	// 3. Hostlet receives completion code (delivery code)
       
  1596     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  1597     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone );
       
  1598     
       
  1599     //4. HandleErrorL accesed after negative iResponseCodes
       
  1600     LOCAL_ASSERT( iWas_HandleErrorL_Accessed );
       
  1601     
       
  1602     // --- Conditions END ---
       
  1603     
       
  1604     delete ipConnection;
       
  1605     ipConnection = NULL;
       
  1606     delete ipHostletConnection; 
       
  1607     ipHostletConnection = NULL;
       
  1608     delete ipHostlet;
       
  1609     ipHostlet = NULL;
       
  1610     delete ipConsumer;
       
  1611     ipConsumer = NULL;
       
  1612     Teardown();
       
  1613     return KErrNone;
       
  1614     }
       
  1615   
       
  1616     
       
  1617  
       
  1618 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_HC_SelfDef_URIL(TTestResult& aResult)
       
  1619     {
       
  1620 	SetupL(); 
       
  1621                                      
       
  1622   	ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1623   	ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  1624 
       
  1625   
       
  1626   	ipHostlet->ipHostletDescription->SetEndPointL(KHostletEndpoint);	
       
  1627   	ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  1628     
       
  1629 
       
  1630   	CSenServicePattern* pPattern =
       
  1631 		    CSenServicePattern::NewLC(KHostletEndpoint, KNullDesC8);
       
  1632 
       
  1633     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1634     
       
  1635     
       
  1636     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  1637     CleanupStack::PopAndDestroy(pPattern);
       
  1638     
       
  1639     // Construct service connection
       
  1640     StartActiveScheduler(1);
       
  1641 
       
  1642 	// Check that the Status of the ServiceConnection
       
  1643     // is KSenConnectionStatusReady
       
  1644     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady);    
       
  1645    
       
  1646     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1647 
       
  1648     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  1649     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1650     
       
  1651     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  1652     StartActiveScheduler(2);
       
  1653     // ---- Following conditions MUST be met ----
       
  1654 
       
  1655     // 1. Hostlet receives request that consumer made
       
  1656     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  1657 
       
  1658     // 2. Consumer receives response that hostlet provided
       
  1659     
       
  1660     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  1661     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  1662     
       
  1663     
       
  1664  	// 3. Hostlet receives completion code (delivery code)
       
  1665     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  1666     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  1667     
       
  1668     // --- Conditions END ---
       
  1669     
       
  1670     delete ipConnection;
       
  1671     ipConnection = NULL;
       
  1672     delete ipHostletConnection; 
       
  1673     ipHostletConnection = NULL;
       
  1674     delete ipHostlet;
       
  1675     ipHostlet = NULL;
       
  1676     delete ipConsumer;
       
  1677     ipConsumer = NULL;
       
  1678     Teardown();
       
  1679     return KErrNone;
       
  1680     }
       
  1681    
       
  1682 /*
       
  1683 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_Delete_HCL(TTestResult& aResult)
       
  1684     {
       
  1685 	SetupL(); 
       
  1686      
       
  1687     iWas_HandleErrorL_Accessed = EFalse;                              
       
  1688     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1689     ipConsumer = CTestConsumer::NewL(this, 
       
  1690                                      NULL, 
       
  1691                                      &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleErrorL, 
       
  1692                                      NULL);
       
  1693 
       
  1694     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  1695 
       
  1696     CSenServicePattern* pPattern =
       
  1697         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  1698     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1699     
       
  1700     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  1701     CleanupStack::PopAndDestroy(pPattern);
       
  1702     
       
  1703     // Construct service connection
       
  1704     StartActiveScheduler(1);
       
  1705     
       
  1706     //delete Hostlet Connection
       
  1707     delete ipHostletConnection; 
       
  1708     ipHostletConnection = NULL;
       
  1709     
       
  1710     
       
  1711     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1712 
       
  1713     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  1714 
       
  1715     // ---- Following conditions MUST be met ----
       
  1716     LOCAL_ASSERT(transactionIdOrError == KErrSenHostNotAvailable);
       
  1717 
       
  1718     // Start waiting for HandleError Callback which is caused
       
  1719     // by error in SendL
       
  1720     StartActiveScheduler(1);
       
  1721     // Callback was get => Check that callback was HandleError
       
  1722     LOCAL_ASSERT( iWas_HandleErrorL_Accessed );
       
  1723     
       
  1724     // --- Conditions END ---
       
  1725     
       
  1726     delete ipConnection;
       
  1727     ipConnection = NULL;
       
  1728     
       
  1729     delete ipHostlet;
       
  1730     ipHostlet = NULL;
       
  1731     delete ipConsumer;
       
  1732     ipConsumer = NULL;
       
  1733   
       
  1734     Teardown();
       
  1735     return KErrNone;
       
  1736     }
       
  1737     
       
  1738     
       
  1739 */
       
  1740 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_Two_Equal_UID3L(TTestResult& aResult)
       
  1741     {
       
  1742 	SetupL(); 
       
  1743     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1744 
       
  1745     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  1746  	
       
  1747  	//Check if CSenHostletConnection::NewL leaves with KErrSenEndpointReserved
       
  1748 /*	EUNIT_ASSERT_SPECIFIC_LEAVE(ipHostletConnection1 = CSenHostletConnection::NewL(*ipHostlet),KErrSenEndpointReserved);*/
       
  1749 	TRAPD(res,ipHostletConnection1 = CSenHostletConnection::NewL(*ipHostlet)) ;
       
  1750 	User::LeaveIfError(res == KErrSenEndpointReserved);
       
  1751 
       
  1752   
       
  1753     delete ipHostletConnection; 
       
  1754     ipHostletConnection = NULL;
       
  1755     delete ipHostlet;
       
  1756     ipHostlet = NULL;
       
  1757     Teardown();
       
  1758     return KErrNone;
       
  1759     }
       
  1760    
       
  1761 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_Two_Equal_EndpointsL(TTestResult& aResult)
       
  1762     {
       
  1763 	SetupL(); 
       
  1764     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1765 	ipHostlet->ipHostletDescription->SetEndPointL(KHostletEndpoint);
       
  1766     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  1767  
       
  1768  	//Check if CSenHostletConnection::NewL leaves with KErrSenEndpointReserved
       
  1769 	/*EUNIT_ASSERT_SPECIFIC_LEAVE(ipHostletConnection1 = CSenHostletConnection::NewL(*ipHostlet),KErrSenEndpointReserved);*/
       
  1770 	TRAPD(res,ipHostletConnection1 = CSenHostletConnection::NewL(*ipHostlet)) ;
       
  1771 	User::LeaveIfError(res == KErrSenEndpointReserved);
       
  1772   
       
  1773     delete ipHostletConnection; 
       
  1774     ipHostletConnection = NULL;
       
  1775     delete ipHostlet;
       
  1776     ipHostlet = NULL;
       
  1777     Teardown();
       
  1778     return KErrNone;
       
  1779     }
       
  1780  
       
  1781 
       
  1782 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_Two_HC_Two_SC1L(TTestResult& aResult)
       
  1783     {
       
  1784     	//Memory leak detection is not supported since Symbian 9.0 (EKA2 kernel) environments.
       
  1785     	//This this is added to handle thread handle leak in testmodule0
       
  1786      TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles);
       
  1787 	SetupL(); 
       
  1788    
       
  1789     //First pair of HC and SC
       
  1790     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1791     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  1792 
       
  1793     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  1794 
       
  1795     CSenServicePattern* pPattern =
       
  1796         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  1797     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1798     
       
  1799     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  1800     CleanupStack::PopAndDestroy(pPattern);
       
  1801     
       
  1802     // Construct service connection
       
  1803     StartActiveScheduler(1);
       
  1804     
       
  1805     // Check that the Status of the ServiceConnection
       
  1806     // is KSenConnectionStatusReady
       
  1807     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady); 
       
  1808 	
       
  1809 	
       
  1810 	//Second pair of HC and SC
       
  1811     ipHostlet1 = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1812     ipConsumer1 = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  1813 
       
  1814 	ipHostlet1->ipHostletDescription->SetContractL(KHostletContract1);
       
  1815     ipHostletConnection1 = CSenHostletConnection::NewL(*ipHostlet1);
       
  1816 
       
  1817     CSenServicePattern* pPattern1 =
       
  1818         CSenServicePattern::NewLC(KNullDesC8, KHostletContract1);
       
  1819     pPattern1->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1820     
       
  1821     ipConnection1 = CSenServiceConnection::NewL(*ipConsumer1, *pPattern1);
       
  1822     CleanupStack::PopAndDestroy(pPattern1);
       
  1823     
       
  1824     // Construct service connection
       
  1825     StartActiveScheduler(1); 
       
  1826     
       
  1827     // Check that the Status of the ServiceConnection
       
  1828     // is KSenConnectionStatusReady
       
  1829     LOCAL_ASSERT( ipConsumer1->iConnectionStatus == KSenConnectionStatusReady); 
       
  1830     
       
  1831     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1832     _LIT8(KRequest1, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob1\'] or containts[ab:N/ab:GIVEN,\'Bob1\'] or containts[ab:TEL,\'Bob1\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1833 
       
  1834 	ipUsedHostletConnection = ipHostletConnection;
       
  1835 	
       
  1836     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  1837     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1838     
       
  1839     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  1840     StartActiveScheduler(2);
       
  1841     
       
  1842     ipUsedHostletConnection = ipHostletConnection1;
       
  1843     transactionIdOrError = ipConnection1->SendL(KRequest1);
       
  1844     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1845     
       
  1846     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  1847     StartActiveScheduler(2);
       
  1848  
       
  1849     // ---- Following conditions MUST be met ----
       
  1850 	
       
  1851 	// First pair of the HC and SC
       
  1852     // 1. Hostlet receives request that consumer made
       
  1853     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  1854 
       
  1855     // 2. Consumer receives response that hostlet provided
       
  1856     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  1857     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  1858 
       
  1859     // 3. Hostlet receives completion code (delivery code)
       
  1860     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  1861     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  1862 	
       
  1863 	// Second pair of the HC and SC
       
  1864 	// 1. Hostlet receives request that consumer made
       
  1865     LOCAL_ASSERT( *ipHostlet1->iRequests[0] == KRequest1);
       
  1866 
       
  1867     // 2. Consumer receives response that hostlet provided
       
  1868     LOCAL_ASSERT( *ipConsumer1->iResponses[0] == *ipHostlet1->iResponses[0]);
       
  1869     LOCAL_ASSERT( ipConsumer1->iResponseCodes[0] == ipHostlet1->iResponseCodes[0])
       
  1870 
       
  1871     // 3. Hostlet receives completion code (delivery code)
       
  1872     LOCAL_ASSERT( ipHostlet1->iTxnIds[0] == transactionIdOrError );
       
  1873     LOCAL_ASSERT( ipHostlet1->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  1874 	
       
  1875     // --- Conditions END ---
       
  1876     
       
  1877 	ipUsedHostletConnection = NULL;  
       
  1878 	
       
  1879     delete ipConnection;
       
  1880     ipConnection = NULL;
       
  1881     delete ipHostletConnection; 
       
  1882     ipHostletConnection = NULL;
       
  1883     delete ipHostlet;
       
  1884     ipHostlet = NULL;
       
  1885     delete ipConsumer;
       
  1886     ipConsumer = NULL;
       
  1887 
       
  1888     delete ipConnection1;
       
  1889     ipConnection1 = NULL;
       
  1890     delete ipHostletConnection1; 
       
  1891     ipHostletConnection1 = NULL;
       
  1892     delete ipHostlet1;
       
  1893     ipHostlet1 = NULL;
       
  1894     delete ipConsumer1;
       
  1895     ipConsumer1 = NULL;
       
  1896     
       
  1897     Teardown();
       
  1898     return KErrNone;
       
  1899     }
       
  1900 
       
  1901       
       
  1902 
       
  1903 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_Two_HC_Two_SC2L(TTestResult& aResult)
       
  1904     {
       
  1905     	//Memory leak detection is not supported since Symbian 9.0 (EKA2 kernel) environments.
       
  1906     	//This this is added to handle thread handle leak in testmodule0
       
  1907      TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles);
       
  1908 	SetupL(); 
       
  1909    
       
  1910     //First pair of HC and SC
       
  1911     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1912     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  1913     
       
  1914 	ipHostlet->ipHostletDescription->SetEndPointL(KHostletEndpoint);
       
  1915 	ipHostlet->ipHostletDescription->SetContractL(KNullDesC8);
       
  1916     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  1917 
       
  1918     CSenServicePattern* pPattern =
       
  1919         CSenServicePattern::NewLC(KHostletEndpoint, KNullDesC8);
       
  1920     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1921     
       
  1922     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  1923     CleanupStack::PopAndDestroy(pPattern);
       
  1924     
       
  1925     // Construct service connection
       
  1926     StartActiveScheduler(1);
       
  1927     
       
  1928  	// Check that the Status of the ServiceConnection
       
  1929     // is KSenConnectionStatusReady
       
  1930     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady); 
       
  1931 
       
  1932 	
       
  1933 	//Second pair of HC and SC
       
  1934     ipHostlet1 = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  1935     ipConsumer1 = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  1936 
       
  1937 
       
  1938 	ipHostlet1->ipHostletDescription->SetEndPointL(KHostletEndpoint1);
       
  1939 	ipHostlet1->ipHostletDescription->SetContractL(KNullDesC8);
       
  1940     ipHostletConnection1 = CSenHostletConnection::NewL(*ipHostlet1);
       
  1941 
       
  1942     CSenServicePattern* pPattern1 =
       
  1943         CSenServicePattern::NewLC(KHostletEndpoint1, KNullDesC8);
       
  1944     pPattern1->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  1945     
       
  1946     ipConnection1 = CSenServiceConnection::NewL(*ipConsumer1, *pPattern1);
       
  1947     CleanupStack::PopAndDestroy(pPattern1);
       
  1948     
       
  1949     // Construct service connection
       
  1950     StartActiveScheduler(1);   
       
  1951     
       
  1952     // Check that the Status of the ServiceConnection
       
  1953     // is KSenConnectionStatusReady
       
  1954     LOCAL_ASSERT( ipConsumer1->iConnectionStatus == KSenConnectionStatusReady); 
       
  1955     
       
  1956     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1957     _LIT8(KRequest1, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob1\'] or containts[ab:N/ab:GIVEN,\'Bob1\'] or containts[ab:TEL,\'Bob1\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  1958 
       
  1959 	ipUsedHostletConnection = ipHostletConnection;
       
  1960     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  1961     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1962     
       
  1963     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  1964     StartActiveScheduler(2);
       
  1965     
       
  1966     ipUsedHostletConnection = ipHostletConnection1;
       
  1967     transactionIdOrError = ipConnection1->SendL(KRequest1);
       
  1968     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  1969     
       
  1970     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  1971     StartActiveScheduler(2);
       
  1972  
       
  1973     // ---- Following conditions MUST be met ----
       
  1974 	
       
  1975 	// First pair of the HC and SC
       
  1976     // 1. Hostlet receives request that consumer made
       
  1977     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  1978 
       
  1979     // 2. Consumer receives response that hostlet provided
       
  1980     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  1981     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  1982 
       
  1983     // 3. Hostlet receives completion code (delivery code)
       
  1984     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  1985     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  1986 	
       
  1987 	// Second pair of the HC and SC
       
  1988 	// 1. Hostlet receives request that consumer made
       
  1989     LOCAL_ASSERT( *ipHostlet1->iRequests[0] == KRequest1);
       
  1990 
       
  1991     // 2. Consumer receives response that hostlet provided
       
  1992     LOCAL_ASSERT( *ipConsumer1->iResponses[0] == *ipHostlet1->iResponses[0]);
       
  1993     LOCAL_ASSERT( ipConsumer1->iResponseCodes[0] == ipHostlet1->iResponseCodes[0])
       
  1994 
       
  1995     // 3. Hostlet receives completion code (delivery code)
       
  1996     LOCAL_ASSERT( ipHostlet1->iTxnIds[0] == transactionIdOrError );
       
  1997     LOCAL_ASSERT( ipHostlet1->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  1998 	
       
  1999     // --- Conditions END ---
       
  2000     
       
  2001 	ipUsedHostletConnection = NULL;  
       
  2002 	
       
  2003     delete ipConnection;
       
  2004     ipConnection = NULL;
       
  2005     delete ipHostletConnection; 
       
  2006     ipHostletConnection = NULL;
       
  2007     delete ipHostlet;
       
  2008     ipHostlet = NULL;
       
  2009     delete ipConsumer;
       
  2010     ipConsumer = NULL;
       
  2011 
       
  2012     delete ipConnection1;
       
  2013     ipConnection1 = NULL;
       
  2014     delete ipHostletConnection1; 
       
  2015     ipHostletConnection1 = NULL;
       
  2016     delete ipHostlet1;
       
  2017     ipHostlet1 = NULL;
       
  2018     delete ipConsumer1;
       
  2019     ipConsumer1 = NULL;
       
  2020     
       
  2021     Teardown();
       
  2022     return KErrNone;
       
  2023     }
       
  2024 
       
  2025 
       
  2026  TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_Two_HC_Two_SC3L(TTestResult& aResult)
       
  2027     {
       
  2028     	//Memory leak detection is not supported since Symbian 9.0 (EKA2 kernel) environments.
       
  2029     	//This this is added to handle thread handle leak in testmodule0
       
  2030     TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles);
       
  2031 	SetupL(); 
       
  2032    
       
  2033     //First pair of HC and SC
       
  2034     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  2035     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  2036     
       
  2037 	ipHostlet->ipHostletDescription->SetEndPointL(KHostletEndpoint);
       
  2038 	ipHostlet->ipHostletDescription->SetContractL(KNullDesC8);
       
  2039     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  2040 
       
  2041     CSenServicePattern* pPattern =
       
  2042         CSenServicePattern::NewLC(KHostletEndpoint, KNullDesC8);
       
  2043     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  2044     
       
  2045     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  2046     CleanupStack::PopAndDestroy(pPattern);
       
  2047     
       
  2048     // Construct service connection
       
  2049     StartActiveScheduler(1);
       
  2050  	// Check that the Status of the ServiceConnection
       
  2051     // is KSenConnectionStatusReady
       
  2052     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady); 	
       
  2053     
       
  2054 	//Second pair of HC and SC
       
  2055     ipHostlet1 = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  2056     ipConsumer1 = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  2057 
       
  2058 
       
  2059 	ipHostlet1->ipHostletDescription->SetEndPointL(KHostletEndpoint1);
       
  2060 	ipHostlet1->ipHostletDescription->SetContractL(KNullDesC8);
       
  2061     ipHostletConnection1 = CSenHostletConnection::NewL(*ipHostlet1);
       
  2062 
       
  2063     CSenServicePattern* pPattern1 =
       
  2064         CSenServicePattern::NewLC(KHostletEndpoint1, KNullDesC8);
       
  2065     pPattern1->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  2066     
       
  2067     ipConnection1 = CSenServiceConnection::NewL(*ipConsumer1, *pPattern1);
       
  2068     CleanupStack::PopAndDestroy(pPattern1);
       
  2069     
       
  2070     // Construct service connection
       
  2071     StartActiveScheduler(1);    
       
  2072  	// Check that the Status of the ServiceConnection
       
  2073     // is KSenConnectionStatusReady	
       
  2074     LOCAL_ASSERT( ipConsumer1->iConnectionStatus == KSenConnectionStatusReady);     
       
  2075     
       
  2076     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  2077     _LIT8(KRequest1, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob1\'] or containts[ab:N/ab:GIVEN,\'Bob1\'] or containts[ab:TEL,\'Bob1\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  2078 
       
  2079 	ipUsedHostletConnection = ipHostletConnection;
       
  2080     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  2081     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  2082     
       
  2083     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  2084     StartActiveScheduler(2);
       
  2085     
       
  2086     ipUsedHostletConnection = ipHostletConnection1;
       
  2087     transactionIdOrError = ipConnection1->SendL(KRequest1);
       
  2088     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  2089     
       
  2090     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  2091     StartActiveScheduler(2);
       
  2092  
       
  2093     // ---- Following conditions MUST be met ----
       
  2094 	
       
  2095 	// First pair of the HC and SC
       
  2096     // 1. Hostlet receives request that consumer made
       
  2097     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  2098 
       
  2099     // 2. Consumer receives response that hostlet provided
       
  2100     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  2101     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  2102 
       
  2103     // 3. Hostlet receives completion code (delivery code)
       
  2104     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  2105     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  2106 	
       
  2107 	// Second pair of the HC and SC
       
  2108 	// 1. Hostlet receives request that consumer made
       
  2109     LOCAL_ASSERT( *ipHostlet1->iRequests[0] == KRequest1);
       
  2110 
       
  2111     // 2. Consumer receives response that hostlet provided
       
  2112     LOCAL_ASSERT( *ipConsumer1->iResponses[0] == *ipHostlet1->iResponses[0]);
       
  2113     LOCAL_ASSERT( ipConsumer1->iResponseCodes[0] == ipHostlet1->iResponseCodes[0])
       
  2114 
       
  2115     // 3. Hostlet receives completion code (delivery code)
       
  2116     LOCAL_ASSERT( ipHostlet1->iTxnIds[0] == transactionIdOrError );
       
  2117     LOCAL_ASSERT( ipHostlet1->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  2118 	
       
  2119     // --- Conditions END ---
       
  2120     
       
  2121 	ipUsedHostletConnection = NULL;  
       
  2122 	
       
  2123     delete ipConnection;
       
  2124     ipConnection = NULL;
       
  2125     delete ipHostletConnection; 
       
  2126     ipHostletConnection = NULL;
       
  2127     delete ipHostlet;
       
  2128     ipHostlet = NULL;
       
  2129     delete ipConsumer;
       
  2130     ipConsumer = NULL;
       
  2131 
       
  2132     delete ipConnection1;
       
  2133     ipConnection1 = NULL;
       
  2134     delete ipHostletConnection1; 
       
  2135     ipHostletConnection1 = NULL;
       
  2136     delete ipHostlet1;
       
  2137     ipHostlet1 = NULL;
       
  2138     delete ipConsumer1;
       
  2139     ipConsumer1 = NULL;
       
  2140     Teardown();
       
  2141     return KErrNone;
       
  2142     }
       
  2143 
       
  2144     
       
  2145 
       
  2146 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_DeleteSC_before_HCRespondLL(TTestResult& aResult)
       
  2147     {
       
  2148 	SetupL(); 
       
  2149 	iWas_OnServiceL_Accessed = false;     
       
  2150     ipHostlet = CTestHostlet::NewL(this,
       
  2151                                    &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnService1L,
       
  2152                                    &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceComplete1L);
       
  2153 
       
  2154     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  2155 
       
  2156 
       
  2157 
       
  2158     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  2159 
       
  2160     CSenServicePattern* pPattern =
       
  2161         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  2162     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  2163     
       
  2164     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  2165     CleanupStack::PopAndDestroy(pPattern);
       
  2166     
       
  2167     // Construct service connection
       
  2168     StartActiveScheduler(1);
       
  2169     
       
  2170     // Check that the Status of the ServiceConnection
       
  2171     // is KSenConnectionStatusReady
       
  2172     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady); 
       
  2173     
       
  2174     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  2175 
       
  2176     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  2177     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  2178     
       
  2179     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  2180     StartActiveScheduler(1);
       
  2181     
       
  2182 
       
  2183     // ---- Following conditions MUST be met ----
       
  2184 
       
  2185     // 1. Hostlet receives request that consumer made
       
  2186     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  2187     
       
  2188 	// 2. onServiceL accesed
       
  2189     LOCAL_ASSERT( iWas_OnServiceL_Accessed ); 
       
  2190 
       
  2191     // 3. Hostlet receives completion code (delivery code)
       
  2192     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] < KErrNone ); 
       
  2193 
       
  2194     // --- Conditions END ---
       
  2195  
       
  2196     
       
  2197     delete ipHostletConnection; 
       
  2198     ipHostletConnection = NULL;
       
  2199     delete ipHostlet;
       
  2200     ipHostlet = NULL;
       
  2201     delete ipConsumer;
       
  2202     ipConsumer = NULL; 
       
  2203     Teardown();
       
  2204     return KErrNone;
       
  2205     }
       
  2206 
       
  2207       
       
  2208  TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_RespondL_4multipleTimesL(TTestResult& aResult)
       
  2209     {
       
  2210 	SetupL(); 
       
  2211     ipHostlet = CTestHostlet::NewL(this,
       
  2212                                    &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnService2L,
       
  2213                                    &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnServiceComplete2L);
       
  2214 
       
  2215     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  2216 
       
  2217 
       
  2218 
       
  2219     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  2220 
       
  2221     CSenServicePattern* pPattern =
       
  2222         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  2223     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  2224     
       
  2225     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  2226     CleanupStack::PopAndDestroy(pPattern);
       
  2227     
       
  2228     // Construct service connection
       
  2229     StartActiveScheduler(1);
       
  2230     
       
  2231     // Check that the Status of the ServiceConnection
       
  2232     // is KSenConnectionStatusReady
       
  2233     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady); 
       
  2234     
       
  2235     
       
  2236     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  2237 
       
  2238 	
       
  2239     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  2240     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  2241     
       
  2242     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  2243     StartActiveScheduler(2);
       
  2244    
       
  2245 
       
  2246     // ---- Following conditions MUST be met ----
       
  2247     
       
  2248    
       
  2249     // --- Conditions END ---
       
  2250   
       
  2251     delete ipConnection;
       
  2252     ipConnection = NULL;
       
  2253     delete ipHostletConnection; 
       
  2254     ipHostletConnection = NULL;
       
  2255     delete ipHostlet;
       
  2256     ipHostlet = NULL;
       
  2257     delete ipConsumer;
       
  2258     ipConsumer = NULL; 
       
  2259     Teardown();
       
  2260     return KErrNone;
       
  2261     }
       
  2262      
       
  2263 
       
  2264 
       
  2265 
       
  2266  TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_SC_Cancel_After_RequestL(TTestResult& aResult)
       
  2267  {
       
  2268 	SetupL(); 
       
  2269  	
       
  2270  	iWas_HandleErrorL_Accessed = EFalse;
       
  2271  	
       
  2272     
       
  2273     ipHostlet = CTestHostlet::NewL(this,
       
  2274                                    &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_OnService3L,
       
  2275                                    NULL);
       
  2276 
       
  2277     ipConsumer = CTestConsumer::NewL(this, 
       
  2278                                      NULL, 
       
  2279                                      &CSenHostletConnectionBCTest::UT_CSenHostletConnection_NewLL_HandleError1L, 
       
  2280                                      NULL);
       
  2281                                      
       
  2282                                      
       
  2283     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  2284 
       
  2285     CSenServicePattern* pPattern =
       
  2286         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  2287     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  2288     
       
  2289     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  2290     CleanupStack::PopAndDestroy(pPattern);
       
  2291     
       
  2292     // Construct service connection
       
  2293     StartActiveScheduler(1);
       
  2294     
       
  2295     // Check that the Status of the ServiceConnection
       
  2296     // is KSenConnectionStatusReady
       
  2297     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady); 
       
  2298     
       
  2299     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  2300 
       
  2301     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  2302     iTxnID=transactionIdOrError;
       
  2303     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  2304     
       
  2305     //ipConnection->Cancel(); 
       
  2306     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  2307     StartActiveScheduler(2);
       
  2308     
       
  2309 	  	
       
  2310 	  	
       
  2311     //
       
  2312     // ---- Following conditions MUST be met ----
       
  2313 	
       
  2314     //1 KErrSenCancelled reported
       
  2315     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == KErrSenCancelled);
       
  2316     
       
  2317     //2. HandleErrorL accesed after negative iResponseCodes
       
  2318     LOCAL_ASSERT( iWas_HandleErrorL_Accessed );
       
  2319     // --- Conditions END ---
       
  2320     
       
  2321     delete ipConnection;
       
  2322     ipConnection = NULL;
       
  2323     delete ipHostletConnection; 
       
  2324     ipHostletConnection = NULL;
       
  2325     delete ipHostlet;
       
  2326     ipHostlet = NULL;
       
  2327     delete ipConsumer;
       
  2328     ipConsumer = NULL;
       
  2329     
       
  2330     Teardown();
       
  2331     return KErrNone;
       
  2332     }
       
  2333 
       
  2334     
       
  2335  TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_Set_Expose_FacetL(TTestResult& aResult)
       
  2336  {
       
  2337 	SetupL(); 
       
  2338     
       
  2339     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  2340     
       
  2341 	CSenFacet* pExposed = CSenFacet::NewL();
       
  2342     CleanupStack::PushL(pExposed);
       
  2343     pExposed->SetNameL(KExposeLocalServiceFacet); // from MSenServiceDescription.h
       
  2344     ipHostlet->ipHostletDescription->SetFacetL(*pExposed);
       
  2345     CleanupStack::PopAndDestroy(); // pExposed
       
  2346     
       
  2347     RFacetArray facets;
       
  2348 	ipHostlet->ipHostletDescription->FacetsL(facets);
       
  2349 	
       
  2350 	LOCAL_ASSERT(facets[0]->Name() == KExposeLocalServiceFacet);
       
  2351     
       
  2352     facets.ResetAndDestroy();
       
  2353     delete ipHostlet;
       
  2354     ipHostlet = NULL;
       
  2355       
       
  2356     Teardown();
       
  2357     return KErrNone;
       
  2358     }
       
  2359     
       
  2360 /*
       
  2361 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_CreateConnAndSubmit_Rest_MultiThreadL(TTestResult& aResult)
       
  2362     {
       
  2363 	SetupL(); 
       
  2364     // uses default implementations for servicel and onservicecompletel    
       
  2365     ipHostlet = CTestHostlet::NewL(this);   
       
  2366     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  2367    
       
  2368     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  2369 	
       
  2370 	HBufC8* pResponseTo = NULL;
       
  2371 
       
  2372     // Invoke service once. But, due this is performed synchronously within the SAME PROCESS, we need
       
  2373     // another thread (otherwise ActiveScheduler cannot serve this WS request, ServiceL is never invoked).
       
  2374     
       
  2375     TConsumerTestTask task( *ipConnection, 
       
  2376                             KRequest, 
       
  2377                             KDefaultRestServicesFrameworkID, 
       
  2378                             TConsumerTestTask::ECreateConnAndSubmit, 
       
  2379                             pResponseTo );
       
  2380     task.ipOwner = this;
       
  2381     
       
  2382     RThread localThread;
       
  2383     _LIT(KThreadName, "tSubmitRestFromThread_");
       
  2384     
       
  2385     TInt createThreadRetVal = CreateThreadForConsumerTask(localThread, KThreadName, task);
       
  2386     
       
  2387     LOCAL_ASSERT( createThreadRetVal == KErrNone );
       
  2388     
       
  2389     localThread.Resume(); // start the thread. 
       
  2390     
       
  2391     // Would NOT work: // TInt transactionIdOrError = ipConnection->SubmitL(KRequest, pResponseTo);
       
  2392                        // LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  2393     
       
  2394     
       
  2395     // Respond to consumer ONCE => only one call..
       
  2396     StartActiveScheduler(1);
       
  2397     
       
  2398     // Push the local pointer to the response descriptor into cleanupstack:
       
  2399     CleanupStack::PushL(pResponseTo);
       
  2400 
       
  2401     // ---- Following conditions MUST be met ----
       
  2402 
       
  2403     // SubmitL must return KErrNone(!)
       
  2404     // Note: from Submit, one cannot get TXN ID, but either OK (KErrNone) or an error
       
  2405  //   LOCAL_ASSERT( task.iStatusCode == KErrNone );
       
  2406 
       
  2407 
       
  2408     // 1. Hostlet receives request that consumer made
       
  2409     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  2410 
       
  2411     // 2. Consumer receives response that hostlet provided
       
  2412     LOCAL_ASSERT( *pResponseTo == *ipHostlet->iResponses[0]);
       
  2413     
       
  2414 
       
  2415     // 3. Hostlet receives completion code (delivery code)
       
  2416     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  2417     
       
  2418     // --- Conditions END ---
       
  2419     
       
  2420     CleanupStack::PopAndDestroy(pResponseTo);
       
  2421     
       
  2422     localThread.Close();
       
  2423     delete ipConnection;
       
  2424     ipConnection = NULL;
       
  2425     delete ipHostletConnection; 
       
  2426     ipHostletConnection = NULL;
       
  2427     delete ipHostlet;
       
  2428     ipHostlet = NULL;
       
  2429     delete ipConsumer;
       
  2430     ipConsumer = NULL;
       
  2431     Teardown();
       
  2432     return KErrNone;
       
  2433     }
       
  2434 */    
       
  2435     
       
  2436 
       
  2437 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_Submit_Rest_MultiThreadL(TTestResult& aResult)
       
  2438     {
       
  2439 	SetupL(); 
       
  2440     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  2441     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  2442 
       
  2443 
       
  2444     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  2445 
       
  2446     CSenServicePattern* pPattern =
       
  2447         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  2448     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  2449     
       
  2450     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  2451     CleanupStack::PopAndDestroy(pPattern);
       
  2452     
       
  2453     // Construct service connection
       
  2454     StartActiveScheduler(1);
       
  2455     
       
  2456     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  2457 	
       
  2458 	HBufC8* pResponseTo = NULL;
       
  2459 
       
  2460     // Invoke service once. But, due this is performed synchronously within the SAME PROCESS, we need
       
  2461     // another thread (otherwise ActiveScheduler cannot serve this WS request, ServiceL is never invoked).
       
  2462     
       
  2463     TConsumerTestTask task( *ipConnection, 
       
  2464                             KRequest, 
       
  2465                             KDefaultRestServicesFrameworkID, // not used by this test case..
       
  2466                             TConsumerTestTask::ESubmit, 
       
  2467                             pResponseTo);
       
  2468     
       
  2469     RThread localThread;
       
  2470     _LIT(KThreadName, "tSubmitRestFromThread_");
       
  2471     
       
  2472     TInt createThreadRetVal = CreateThreadForConsumerTask(localThread, KThreadName, task);
       
  2473     
       
  2474     LOCAL_ASSERT( createThreadRetVal == KErrNone );
       
  2475     
       
  2476     localThread.Resume(); // start the thread. 
       
  2477     
       
  2478     // Would NOT work: // TInt transactionIdOrError = ipConnection->SubmitL(KRequest, pResponseTo);
       
  2479                        // LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  2480     
       
  2481     // Respond to consumer ONCE => only one call..
       
  2482     StartActiveScheduler(1);
       
  2483     
       
  2484     // Push the local pointer to the response descriptor into cleanupstack:
       
  2485     CleanupStack::PushL(pResponseTo);
       
  2486     
       
  2487     // ---- Following conditions MUST be met ----
       
  2488 
       
  2489     // SubmitL must return KErrNone(!)
       
  2490     // Note: from Submit, one cannot get TXN ID, but either OK (KErrNone) or an error
       
  2491     LOCAL_ASSERT( task.iStatusCode == KErrNone ); 
       
  2492 
       
  2493 
       
  2494     // 1. Hostlet receives request that consumer made
       
  2495     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  2496 
       
  2497     // 2. Consumer receives response that hostlet provided
       
  2498     LOCAL_ASSERT( *pResponseTo == *ipHostlet->iResponses[0]);
       
  2499     
       
  2500 
       
  2501     // 3. Hostlet receives completion code (delivery code)
       
  2502     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  2503     
       
  2504     // --- Conditions END ---
       
  2505 
       
  2506     CleanupStack::PopAndDestroy(pResponseTo);    
       
  2507     delete ipConnection;
       
  2508     ipConnection = NULL;
       
  2509     delete ipHostletConnection; 
       
  2510     ipHostletConnection = NULL;
       
  2511     delete ipHostlet;
       
  2512     ipHostlet = NULL;
       
  2513     delete ipConsumer;
       
  2514     ipConsumer = NULL;
       
  2515     Teardown();
       
  2516     return KErrNone;
       
  2517     }
       
  2518     
       
  2519 
       
  2520 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_Submit_Rest_ActiveL(TTestResult& aResult)
       
  2521     {
       
  2522 	SetupL(); 
       
  2523     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  2524     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  2525 
       
  2526 
       
  2527     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  2528     CSenServicePattern* pPattern = CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  2529     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  2530   
       
  2531     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  2532     CleanupStack::PopAndDestroy(pPattern);
       
  2533     
       
  2534     // Construct service connection
       
  2535     StartActiveScheduler(1);
       
  2536     
       
  2537     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  2538 	
       
  2539 	HBufC8* pResponseTo = NULL;
       
  2540 
       
  2541     // Invoke service once. But, due this is performed synchronously within the SAME PROCESS, we need
       
  2542     // another thread (otherwise ActiveScheduler cannot serve this WS request, ServiceL is never invoked).
       
  2543     
       
  2544     TConsumerTestTask task( *ipConnection, 
       
  2545                             KRequest, 
       
  2546                             KDefaultRestServicesFrameworkID, // not used by this test case atm
       
  2547                             TConsumerTestTask::EActiveSubmit, 
       
  2548                             pResponseTo);
       
  2549 
       
  2550     _LIT(KThreadName, "tSubmitRestFromAO_");
       
  2551     CActiveConsumerTestTask* pActiveTask = CActiveConsumerTestTask::NewLC(task, KThreadName(), *this); // push pActiveTask
       
  2552     task.ipActive = pActiveTask;
       
  2553     
       
  2554     if(!pActiveTask->IsActive())
       
  2555         {
       
  2556 	SetupL(); 
       
  2557         pActiveTask->SetActive();
       
  2558         Teardown();
       
  2559     return KErrNone;
       
  2560     }
       
  2561 
       
  2562     pActiveTask->iStatus = KRequestPending;
       
  2563     TRequestStatus* status = &pActiveTask->iStatus;
       
  2564     User::RequestComplete( status, CActiveConsumerTestTask::EInvokeService );
       
  2565     
       
  2566     // Would NOT work: // TInt transactionIdOrError = ipConnection->SubmitL(KRequest, pResponseTo);
       
  2567                        // LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  2568     
       
  2569     // Submit a single request (via help of an AO!), respond to consumer ONCE,  => two calls
       
  2570     StartActiveScheduler(2);
       
  2571 
       
  2572     // Push the local pointer to the response descriptor into cleanupstack:
       
  2573     CleanupStack::PushL(pResponseTo);
       
  2574 
       
  2575     // ---- Following conditions MUST be met ----
       
  2576 
       
  2577     // SubmitL must return KErrNone(!)
       
  2578     // Note: from Submit, one cannot get TXN ID, but either OK (KErrNone) or an error
       
  2579     LOCAL_ASSERT( task.iStatusCode == KErrNone );
       
  2580 
       
  2581 
       
  2582     // 1. Hostlet receives request that consumer made
       
  2583     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  2584 
       
  2585     // 2. Consumer receives response that hostlet provided
       
  2586     LOCAL_ASSERT( *pResponseTo == *ipHostlet->iResponses[0]);
       
  2587     
       
  2588 
       
  2589     // 3. Hostlet receives completion code (delivery code)
       
  2590     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  2591     
       
  2592     // --- Conditions END ---
       
  2593 
       
  2594     CleanupStack::PopAndDestroy(pResponseTo);
       
  2595     delete ipConnection;
       
  2596     ipConnection = NULL;
       
  2597     delete ipHostletConnection; 
       
  2598     ipHostletConnection = NULL;
       
  2599     delete ipHostlet;
       
  2600     ipHostlet = NULL;
       
  2601     delete ipConsumer;
       
  2602     ipConsumer = NULL;
       
  2603     
       
  2604     Teardown();
       
  2605     return KErrNone;
       
  2606     }
       
  2607     
       
  2608 /*
       
  2609 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_CreateConnAndSubmit_WSI_MultiThreadL(TTestResult& aResult)
       
  2610     {
       
  2611 	SetupL(); 
       
  2612     // This test case uses default implementations for servicel and onservicecompletel, 
       
  2613     // BUT(!) describeservicel has been overridden!
       
  2614     ipHostlet = CTestHostlet::NewL(this, NULL, NULL, CSenHostletConnectionBCTest::UT_CSenHostletConnection_WSI_DescribeServiceL);   
       
  2615 
       
  2616 // variant point 1:
       
  2617 //    ipHostlet = CTestHostlet::NewL(this);   
       
  2618     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  2619    
       
  2620 	CSenSoapMessage* pSoapMessage = CreateAuthRequestLC();
       
  2621 	HBufC8* pAsXml = pSoapMessage->AsXmlL();
       
  2622 	CleanupStack::PushL(pAsXml);
       
  2623 	TPtrC8 request = pAsXml->Des();
       
  2624 	
       
  2625 	CSenTransportProperties* pProps = CSenTransportProperties::NewLC(); // push pProps
       
  2626 	pProps->SetPropertyL(_L8("KTestProperty"), _L8("KTestPropertyValue"));
       
  2627 	HBufC8* pPropsAsXml = pProps->AsUtf8L();
       
  2628 	CleanupStack::PopAndDestroy(pProps);
       
  2629 
       
  2630 	CleanupStack::PushL(pPropsAsXml);
       
  2631 	TPtrC8 properties = pPropsAsXml->Des();
       
  2632 
       
  2633 	
       
  2634 	HBufC8* pResponseTo = NULL;
       
  2635 
       
  2636     // Invoke service once. But, due this is performed synchronously within the SAME PROCESS, we need
       
  2637     // another thread (otherwise ActiveScheduler cannot serve this WS request, ServiceL is never invoked).
       
  2638     
       
  2639 
       
  2640     // NOTE-NOTE: if WS-I is used instead of REST, timing changes and race-codition occurs
       
  2641     
       
  2642     TConsumerTestTask task( *ipConnection, // not used in this test case
       
  2643                             request,       // not used in this test case
       
  2644                             KDefaultBasicWebServicesFrameworkID,
       
  2645                             TConsumerTestTask::ECreateConnAndSubmit, 
       
  2646                             pResponseTo);
       
  2647     task.ipOwner = this;
       
  2648 
       
  2649     task.iEndpoint.Set(KHostletEndpoint);
       
  2650 // variant point 2:
       
  2651     // -- comment out above line: task.iEndpoint.Set(KHostletEndpoint);
       
  2652 
       
  2653     task.ipSoapMsg = pSoapMessage;
       
  2654 
       
  2655     task.iProperties.Set(properties); 
       
  2656     
       
  2657     RThread localThread;
       
  2658     _LIT(KThreadName, "tSubmitWsiFromThread_");
       
  2659     
       
  2660     TInt createThreadRetVal = CreateThreadForConsumerTask(localThread, KThreadName, task);
       
  2661     
       
  2662     LOCAL_ASSERT( createThreadRetVal == KErrNone );
       
  2663     
       
  2664     // Now start the thread that will execute SubmitL:
       
  2665     localThread.Resume(); // start the thread
       
  2666     
       
  2667     // Would NOT work: // TInt transactionIdOrError = ipConnection->SubmitL(KRequest, pResponseTo);
       
  2668                        // LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  2669     
       
  2670     // Respond to consumer ONCE => only one call..
       
  2671     StartActiveScheduler(1);
       
  2672 
       
  2673     
       
  2674     // Push the local pointer to the response descriptor into cleanupstack:
       
  2675     CleanupStack::PushL(pResponseTo);
       
  2676 
       
  2677     // ---- Following conditions MUST be met ----
       
  2678 
       
  2679     // SubmitL must return KErrNone(!)
       
  2680     // Note: from Submit, one cannot get TXN ID, but either OK (KErrNone) or an error
       
  2681     //LOCAL_ASSERT( task.iStatusCode == KErrNone );
       
  2682 
       
  2683 
       
  2684     // 1. Hostlet receives request that consumer made
       
  2685     LOCAL_ASSERT( *ipHostlet->iRequests[0] == request);
       
  2686 
       
  2687     // 2. Consumer receives response that hostlet provided
       
  2688     //LOCAL_ASSERT( *pResponseTo == *ipHostlet->iResponses[0]);
       
  2689     
       
  2690 
       
  2691     // 3. Hostlet receives completion code (delivery code)
       
  2692     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  2693     
       
  2694     // --- Conditions END ---
       
  2695     
       
  2696     // Response received, de-alloc response, request properties, request as XML descs and SOAP-MSG obj
       
  2697     CleanupStack::PopAndDestroy( pResponseTo );
       
  2698 
       
  2699     CleanupStack::PopAndDestroy( pPropsAsXml );
       
  2700 
       
  2701 	CleanupStack::PopAndDestroy( pAsXml );
       
  2702 
       
  2703 	CleanupStack::PopAndDestroy( pSoapMessage );
       
  2704     
       
  2705     localThread.Close();
       
  2706     delete ipConnection;
       
  2707     ipConnection = NULL;
       
  2708     delete ipHostletConnection; 
       
  2709     ipHostletConnection = NULL;
       
  2710     delete ipHostlet;
       
  2711     ipHostlet = NULL;
       
  2712     delete ipConsumer;
       
  2713     ipConsumer = NULL;
       
  2714     Teardown();
       
  2715     return KErrNone;
       
  2716     }
       
  2717     
       
  2718 */
       
  2719 
       
  2720     
       
  2721 
       
  2722 /*    
       
  2723 // DOES NOT WORK, submit blocks the single ActiveScheduler...    
       
  2724 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_Submit_WSIL(TTestResult& aResult)
       
  2725     {
       
  2726 	SetupL(); 
       
  2727     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  2728     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  2729 
       
  2730     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  2731 
       
  2732     CSenServicePattern* pPattern =
       
  2733          CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  2734     pPattern->SetFrameworkIdL(KDefaultBasicWebServicesFrameworkID);
       
  2735     
       
  2736     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  2737     CleanupStack::PopAndDestroy(pPattern);
       
  2738     
       
  2739     // Construct service connection
       
  2740     StartActiveScheduler(1);
       
  2741     
       
  2742      // Check that the Status of the ServiceConnection
       
  2743     // is KSenConnectionStatusReady
       
  2744     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady); 
       
  2745     
       
  2746 	CSenSoapMessage* pSOAPMessage = CreateAuthRequestLC();
       
  2747 	HBufC8* pAsXml = pSOAPMessage->AsXmlL(); 
       
  2748 	CleanupStack::PushL(pAsXml);
       
  2749 	
       
  2750 	CSenTransportProperties* pProps = CSenTransportProperties::NewLC();
       
  2751 	pProps->SetPropertyL(_L8("KTestProperty"), _L8("KTestPropertyValue"));
       
  2752 	HBufC8* pPropsAsXml = pProps->AsUtf8LC();
       
  2753 	
       
  2754 	HBufC8* pResponseTo = NULL;
       
  2755 	
       
  2756     TInt transactionIdOrError = ipConnection->SubmitL(*pSOAPMessage, *pPropsAsXml, pResponseTo);
       
  2757     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  2758     
       
  2759     
       
  2760     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  2761     StartActiveScheduler(2);
       
  2762 
       
  2763     // ---- Following conditions MUST be met ----
       
  2764 
       
  2765     // 1. Hostlet receives request that consumer made
       
  2766     LOCAL_ASSERT( *ipHostlet->iRequests[0] == *pAsXml);
       
  2767 
       
  2768     // 2. Consumer receives response that hostlet provided
       
  2769     LOCAL_ASSERT( *pResponseTo == *ipHostlet->iResponses[0]);
       
  2770     
       
  2771     // 3. Hostlet receives completion code (delivery code)
       
  2772     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  2773     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  2774     
       
  2775     // --- Conditions END ---
       
  2776     
       
  2777     CleanupStack::PopAndDestroy(pPropsAsXml);
       
  2778     CleanupStack::PopAndDestroy(pProps);
       
  2779     CleanupStack::PopAndDestroy(pAsXml);
       
  2780     CleanupStack::PopAndDestroy(pSOAPMessage);
       
  2781 	delete ipConnection;
       
  2782     ipConnection = NULL;
       
  2783     delete ipHostletConnection; 
       
  2784     ipHostletConnection = NULL;
       
  2785     delete ipHostlet;
       
  2786     ipHostlet = NULL;
       
  2787     delete ipConsumer;
       
  2788     ipConsumer = NULL;
       
  2789     
       
  2790     Teardown();
       
  2791     return KErrNone;
       
  2792     }
       
  2793     
       
  2794 */
       
  2795 /*
       
  2796 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_Send_WSIL()
       
  2797     {
       
  2798 	SetupL(); 
       
  2799    // This case uses default implementations for servicel and onservicecompletel:
       
  2800     ipHostlet = CTestHostlet::NewL(this, NULL, NULL, CSenHostletConnectionBCTest::UT_CSenHostletConnection_WSI_DescribeService_2L);
       
  2801 
       
  2802     // This case uses the default implementations for setstatus, handlemessage, handleerror:
       
  2803     ipConsumer = CTestConsumer::NewL(this); 
       
  2804 
       
  2805     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  2806 
       
  2807     CSenServicePattern* pPattern = CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  2808     // Choose WS-I service invokation framework
       
  2809     pPattern->SetFrameworkIdL(KDefaultBasicWebServicesFrameworkID);
       
  2810     
       
  2811     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  2812     CleanupStack::PopAndDestroy(pPattern);
       
  2813     
       
  2814     // Construct service connection
       
  2815     StartActiveScheduler(1);
       
  2816 
       
  2817     // Check that NO HandleErrorL callback was received:
       
  2818     LOCAL_ASSERT( ipConsumer->iErrorCode == KErrSenHostNotAvailable );
       
  2819 
       
  2820     // Check that the Status of the ServiceConnection
       
  2821     // is KSenConnectionStatusReady
       
  2822     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusCreateFailed); 
       
  2823     
       
  2824 /*
       
  2825     // Check that NO HandleErrorL callback was received:
       
  2826     LOCAL_ASSERT( ipConsumer->iErrorCode == KErrNone );
       
  2827     
       
  2828     
       
  2829      // Check that the Status of the ServiceConnection
       
  2830     // is KSenConnectionStatusReady
       
  2831     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady); 
       
  2832     
       
  2833 	CSenSoapMessage* pSOAPMessage = CreateAuthRequestLC();
       
  2834 	HBufC8* pAsXml = pSOAPMessage->AsXmlL(); 
       
  2835 	CleanupStack::PushL(pAsXml);
       
  2836 	TPtrC8 request = pAsXml->Des();
       
  2837 	
       
  2838     TInt transactionIdOrError = ipConnection->SendL(*pSOAPMessage);
       
  2839     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  2840     
       
  2841     // Invoke service  ONCE (one SendL calling ServiceL), respond to consumer ONCE => two calls
       
  2842     StartActiveScheduler(2);
       
  2843 
       
  2844     // ---- Following conditions MUST be met ----
       
  2845 
       
  2846     // 1. Hostlet receives request that consumer made
       
  2847     LOCAL_ASSERT( *ipHostlet->iRequests[0] == request);
       
  2848 
       
  2849     // 2. Consumer receives response that hostlet provided
       
  2850     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  2851     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  2852 
       
  2853     // 3. Hostlet receives completion code (delivery code)
       
  2854     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  2855     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  2856    
       
  2857     
       
  2858     // --- Conditions END ---
       
  2859 
       
  2860     CleanupStack::PopAndDestroy(pAsXml);
       
  2861     CleanupStack::PopAndDestroy(pSOAPMessage);
       
  2862      */
       
  2863      /*
       
  2864 	delete ipConnection;
       
  2865     ipConnection = NULL;
       
  2866     
       
  2867     delete ipHostletConnection; 
       
  2868     ipHostletConnection = NULL;
       
  2869     
       
  2870     delete ipConsumer;
       
  2871     ipConsumer = NULL;
       
  2872     
       
  2873     delete ipHostlet;
       
  2874     ipHostlet = NULL;
       
  2875     
       
  2876     Teardown();
       
  2877     return KErrNone;
       
  2878     }
       
  2879 
       
  2880     */
       
  2881 /*
       
  2882 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_DescEndpoint_Send_WSIL()
       
  2883     {
       
  2884 	SetupL(); 
       
  2885     // This case uses default implementations for servicel and onservicecompletel:
       
  2886     // NOTE: for ALL OTHER BUT REST hostlets, one must DESCRIBE framework ID
       
  2887     // via MSenHostlet::DescribeServiceL(!)
       
  2888     ipHostlet = CTestHostlet::NewL(this, NULL, NULL, CSenHostletConnectionBCTest::UT_CSenHostletConnection_WSI_DescribeServiceL);
       
  2889 
       
  2890     // This case uses the default implementations for setstatus, handlemessage, handleerror:
       
  2891     ipConsumer = CTestConsumer::NewL(this); 
       
  2892 
       
  2893     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  2894 
       
  2895     CSenServicePattern* pPattern = CSenServicePattern::NewLC(KHostletEndpoint, KHostletContract);
       
  2896     // Choose WS-I service invokation framework
       
  2897     pPattern->SetFrameworkIdL(KDefaultBasicWebServicesFrameworkID);
       
  2898     
       
  2899     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  2900     CleanupStack::PopAndDestroy(pPattern);
       
  2901     
       
  2902     // Construct service connection
       
  2903     StartActiveScheduler(1);
       
  2904 
       
  2905     // Check that NO HandleErrorL callback was received:
       
  2906     LOCAL_ASSERT( ipConsumer->iErrorCode == KErrNone );
       
  2907     
       
  2908     
       
  2909      // Check that the Status of the ServiceConnection
       
  2910     // is KSenConnectionStatusReady
       
  2911     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady); 
       
  2912     
       
  2913 	CSenSoapMessage* pSOAPMessage = CreateAuthRequestLC();
       
  2914 	HBufC8* pAsXml = pSOAPMessage->AsXmlL(); 
       
  2915 	CleanupStack::PushL(pAsXml);
       
  2916 	TPtrC8 request = pAsXml->Des();
       
  2917 	
       
  2918     TInt transactionIdOrError = ipConnection->SendL(*pSOAPMessage);
       
  2919     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  2920     
       
  2921     // Invoke service  ONCE (one SendL calling ServiceL), respond to consumer ONCE => two calls
       
  2922     StartActiveScheduler(2);
       
  2923 
       
  2924     // ---- Following conditions MUST be met ----
       
  2925 
       
  2926     // 1. Hostlet receives request that consumer made
       
  2927     LOCAL_ASSERT( *ipHostlet->iRequests[0] == request);
       
  2928 
       
  2929     // 2. Consumer receives response that hostlet provided
       
  2930     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  2931     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  2932 
       
  2933     // 3. Hostlet receives completion code (delivery code)
       
  2934     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  2935     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  2936     
       
  2937     
       
  2938     // --- Conditions END ---
       
  2939 
       
  2940     CleanupStack::PopAndDestroy(pAsXml);
       
  2941     CleanupStack::PopAndDestroy(pSOAPMessage);
       
  2942     
       
  2943 	delete ipConnection;
       
  2944     ipConnection = NULL;
       
  2945     
       
  2946     delete ipHostletConnection; 
       
  2947     ipHostletConnection = NULL;
       
  2948     
       
  2949     delete ipConsumer;
       
  2950     ipConsumer = NULL;
       
  2951     
       
  2952     delete ipHostlet;
       
  2953     ipHostlet = NULL;
       
  2954     
       
  2955     Teardown();
       
  2956     return KErrNone;
       
  2957     }
       
  2958 
       
  2959 
       
  2960 */
       
  2961 
       
  2962 // Leaks memory
       
  2963 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_2SC1HCL(TTestResult& aResult)
       
  2964     {
       
  2965     	//Memory leak detection is not supported since Symbian 9.0 (EKA2 kernel) environments.
       
  2966     	//This this is added to handle thread handle leak in testmodule0
       
  2967     TestModuleIf().SetBehavior( CTestModuleIf::ETestLeaksHandles );
       
  2968 	SetupL(); 
       
  2969    
       
  2970     // The only HC
       
  2971     ipHostlet = CTestHostlet::NewL(this);   // uses default implementations for servicel and onservicecompletel
       
  2972     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  2973 
       
  2974 	
       
  2975 	// First SC
       
  2976 	ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  2977 	    CSenServicePattern* pPattern =
       
  2978         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  2979     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  2980     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  2981     CleanupStack::PopAndDestroy(pPattern);
       
  2982     
       
  2983     // Construct service connection
       
  2984     StartActiveScheduler(1);
       
  2985     
       
  2986     // Check that the Status of the ServiceConnection
       
  2987     // is KSenConnectionStatusReady
       
  2988     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady); 
       
  2989 
       
  2990 	// Second SC
       
  2991     ipConsumer1 = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  2992     CSenServicePattern* pPattern1 =
       
  2993         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  2994     pPattern1->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  2995     ipConnection1 = CSenServiceConnection::NewL(*ipConsumer1, *pPattern1);
       
  2996     CleanupStack::PopAndDestroy(pPattern1);
       
  2997     
       
  2998     // Construct service connection
       
  2999     StartActiveScheduler(1); 
       
  3000     
       
  3001     // Check that the Status of the ServiceConnection
       
  3002     // is KSenConnectionStatusReady
       
  3003     LOCAL_ASSERT( ipConsumer1->iConnectionStatus == KSenConnectionStatusReady); 
       
  3004     
       
  3005     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  3006     _LIT8(KRequest1, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob1\'] or containts[ab:N/ab:GIVEN,\'Bob1\'] or containts[ab:TEL,\'Bob1\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  3007 
       
  3008 	
       
  3009     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  3010     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  3011     
       
  3012     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  3013     StartActiveScheduler(2);
       
  3014     
       
  3015     TInt transactionIdOrError1 = ipConnection1->SendL(KRequest1);
       
  3016     LOCAL_ASSERT(transactionIdOrError1 > KErrNone);
       
  3017     
       
  3018     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  3019     StartActiveScheduler(2);
       
  3020  
       
  3021     // ---- Following conditions MUST be met ----
       
  3022 	
       
  3023 	// First SC
       
  3024     // 1. Hostlet receives request that consumer made
       
  3025     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  3026 
       
  3027     // 2. The 1st Consumer receives response that hostlet provided
       
  3028     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  3029     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  3030 
       
  3031     // 3. Hostlet receives completion code from 1st Consumer (delivery code)
       
  3032     //We should check TxnID as after Dispatcher Implementation VTxnID get return from SendL
       
  3033     //LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  3034     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  3035 	
       
  3036 	// Second SC
       
  3037 	// 1. Hostlet receives request that consumer made
       
  3038     LOCAL_ASSERT( *ipHostlet->iRequests[1] == KRequest1);
       
  3039 
       
  3040     // 2. The 2nd Consumer receives response that hostlet provided
       
  3041     LOCAL_ASSERT( *ipConsumer1->iResponses[0] == *ipHostlet->iResponses[1]);
       
  3042     LOCAL_ASSERT( ipConsumer1->iResponseCodes[0] == ipHostlet->iResponseCodes[1])
       
  3043 
       
  3044     // 3. Hostlet receives completion code from 2nd Consumer (delivery code)
       
  3045    // LOCAL_ASSERT( ipHostlet->iTxnIds[1] == transactionIdOrError1 );
       
  3046     LOCAL_ASSERT( ipHostlet->iCompletionCodes[1] == KErrNone ); // true in this "OK" -test case
       
  3047 	
       
  3048     // --- Conditions END ---
       
  3049     delete ipHostletConnection; 
       
  3050     ipHostletConnection = NULL;
       
  3051 
       
  3052     delete ipHostlet;
       
  3053     ipHostlet = NULL;
       
  3054 
       
  3055     delete ipConnection;
       
  3056     ipConnection = NULL;
       
  3057 
       
  3058     delete ipConsumer;
       
  3059     ipConsumer = NULL;
       
  3060 
       
  3061     delete ipConnection1;
       
  3062     ipConnection1 = NULL;
       
  3063 
       
  3064     delete ipConsumer1;
       
  3065     ipConsumer1 = NULL;
       
  3066     
       
  3067     Teardown();
       
  3068     return KErrNone;
       
  3069     }
       
  3070  
       
  3071     
       
  3072 TInt CSenHostletConnectionBCTest::UT_CSenHostletConnection_RespondWithPropertiesL(TTestResult& aResult)
       
  3073     {
       
  3074 	SetupL(); 
       
  3075     // Try to send one message  from ServiceConnection to HostletConnection,
       
  3076     // which provides response (TRANSPORT) properties to the response message
       
  3077     
       
  3078     // Construct Hostlet
       
  3079     
       
  3080     ipHostlet = CTestHostlet::NewL(this, &CSenHostletConnectionBCTest::UT_CSenHostletConnection_RespondWithPropertiesL_OnServiceL);
       
  3081     ipHostletConnection = CSenHostletConnection::NewL(*ipHostlet);
       
  3082 
       
  3083     // Construct ServiceConnection
       
  3084     ipConsumer = CTestConsumer::NewL(this); // uses the default implementations for setstatus, handlemessage, handleerror
       
  3085     CSenServicePattern* pPattern =
       
  3086         CSenServicePattern::NewLC(KNullDesC8, KHostletContract);
       
  3087     pPattern->SetFrameworkIdL(KDefaultRestServicesFrameworkID);
       
  3088     
       
  3089     ipConnection = CSenServiceConnection::NewL(*ipConsumer, *pPattern);
       
  3090     CleanupStack::PopAndDestroy(pPattern);
       
  3091     StartActiveScheduler(1);
       
  3092     
       
  3093     // Check that the Status of the ServiceConnection
       
  3094     // is KSenConnectionStatusReady
       
  3095     LOCAL_ASSERT( ipConsumer->iConnectionStatus == KSenConnectionStatusReady);
       
  3096     
       
  3097     // ServiceConnection is ready
       
  3098     // => Send request to the Hostlet
       
  3099     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  3100     TInt transactionIdOrError = ipConnection->SendL(KRequest);
       
  3101     
       
  3102     // Check that SendL returned transaction Id
       
  3103     LOCAL_ASSERT(transactionIdOrError > KErrNone);
       
  3104     
       
  3105     // Invoke service  ONCE (one call to ServiceL), respond to consumer ONCE => two calls
       
  3106     StartActiveScheduler(2);
       
  3107 
       
  3108     // ---- Following conditions MUST be met ----
       
  3109 
       
  3110     // 1. Hostlet receives request that consumer made
       
  3111     LOCAL_ASSERT( *ipHostlet->iRequests[0] == KRequest);
       
  3112 
       
  3113     // 2. Consumer receives response that hostlet provided
       
  3114     LOCAL_ASSERT( *ipConsumer->iResponses[0] == *ipHostlet->iResponses[0]);
       
  3115     LOCAL_ASSERT( ipConsumer->iResponseCodes[0] == ipHostlet->iResponseCodes[0])
       
  3116 
       
  3117     // 3. Hostlet receives completion code (delivery code)
       
  3118     LOCAL_ASSERT( ipHostlet->iTxnIds[0] == transactionIdOrError );
       
  3119     LOCAL_ASSERT( ipHostlet->iCompletionCodes[0] == KErrNone ); // true in this "OK" -test case
       
  3120     
       
  3121     MSenProperties* pHostletProps = ipHostlet->iResponseProps[0];
       
  3122     
       
  3123     LOCAL_ASSERT( ipHostlet->iResponseProps[0] != NULL ); // The tp that was sent
       
  3124     LOCAL_ASSERT( ipConsumer->iResponseProperties[0] != NULL); // The tp that was received
       
  3125     
       
  3126     
       
  3127     
       
  3128     
       
  3129     HBufC8* pSerializedPropsSentByHC = ipHostlet->iResponseProps[0]->AsUtf8LC(); // push
       
  3130     HBufC8* pSerializedPropsReceivedBySC = ipConsumer->iResponseProperties[0]->AsUtf8LC(); // push
       
  3131 
       
  3132     LOCAL_ASSERT( *pSerializedPropsSentByHC == *pSerializedPropsReceivedBySC );
       
  3133     
       
  3134     /*EUNIT_PRINT(_L("=> Properties that HC sent:"));*/
       
  3135     RDebug::Print (_L("=> Properties that HC sent:"));
       
  3136     RDebug::RawPrint(*pSerializedPropsSentByHC);
       
  3137     RDebug::Print(_L("=> Properties that SC received:"));
       
  3138     RDebug::RawPrint(*pSerializedPropsReceivedBySC);
       
  3139     
       
  3140     CleanupStack::PopAndDestroy(pSerializedPropsReceivedBySC); // SC's TP AsUtf8LC
       
  3141     CleanupStack::PopAndDestroy(pSerializedPropsSentByHC); // HC's TP AsUtf8LC
       
  3142     
       
  3143     
       
  3144     // --- Conditions END ---
       
  3145     
       
  3146     delete ipConnection;
       
  3147     ipConnection = NULL;
       
  3148     delete ipHostletConnection; 
       
  3149     ipHostletConnection = NULL;
       
  3150     delete ipHostlet;
       
  3151     ipHostlet = NULL;
       
  3152     delete ipConsumer;
       
  3153     ipConsumer = NULL;
       
  3154    	Teardown();
       
  3155     return KErrNone;
       
  3156     }
       
  3157     
       
  3158            
       
  3159     
       
  3160 CSenSoapMessage* CSenHostletConnectionBCTest::CreateAuthRequestLC()
       
  3161     {
       
  3162     _LIT8(KRequest, "<ab:Query xmlns:ab=\"urn:nokia:test:addrbook:2004-09\"><ab:QueryItem><ab:Select>/ab:Card[containts[ab:N/ab:FAMILY,\'Bob\'] or containts[ab:N/ab:GIVEN,\'Bob\'] or containts[ab:TEL,\'Bob\']]</ab:Select></ab:QueryItem></ab:Query>");
       
  3163     CSenSoapMessage* pSOAPMessage = CSenSoapMessage::NewL();
       
  3164     CleanupStack::PushL(pSOAPMessage);
       
  3165 
       
  3166     //xxxxxxxx*************** CorrelationHeader starts ***************************
       
  3167     CSenBaseElement* pElement = CSenBaseElement::NewL(KHostletContract, _L8("Correlation"), _L8("sb:Correlation"));
       
  3168     CleanupStack::PushL(pElement);
       
  3169 
       
  3170     pElement->AddAttrL(_L8("messageID"),_L8(""));
       
  3171     pElement->AddAttrL(_L8("refToMessageID"),_L8(""));
       
  3172 
       
  3173     TTime t;
       
  3174     t.HomeTime();
       
  3175     TBuf8<SenDateUtils::KXmlDateTimeMaxLength> ts;
       
  3176     SenDateUtils::ToXmlDateTimeUtf8L(ts, t);
       
  3177     pElement->AddAttrL(_L8("timestamp"), ts);
       
  3178 
       
  3179     pSOAPMessage->AddHeaderL(*pElement); // pElement will be owned by pSOAPMessage
       
  3180     CleanupStack::Pop(pElement);
       
  3181     //************************ CorrelationHeader ends ****************************
       
  3182 
       
  3183     pSOAPMessage->SetBodyL(KRequest);
       
  3184     return pSOAPMessage;    
       
  3185     }
       
  3186 //  END OF FILE