multimediacommsengine/mmcefloorctrlplugin/tsrc/ut_floorctrlplugin/src/UT_CFCConnectionContainer.cpp
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2004 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:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 //  CLASS HEADER
       
    22 #include "ut_cfcconnectioncontainer.h"
       
    23 
       
    24 //  EXTERNAL INCLUDES
       
    25 
       
    26 #include <e32math.h>
       
    27 #include <e32svr.h>
       
    28 #include <digia/eunit/eunitmacros.h>
       
    29 #include <digia/eunit/teunitassertioninfo.h>
       
    30 
       
    31 //  INTERNAL INCLUDES
       
    32 #include "fcconnectioncontainer.h"
       
    33 const TUint KIAPID = 6;
       
    34 // CONSTRUCTION
       
    35 UT_CFCConnectionContainer* UT_CFCConnectionContainer::NewL()
       
    36     {
       
    37     UT_CFCConnectionContainer* self = UT_CFCConnectionContainer::NewLC(); 
       
    38     CleanupStack::Pop(self);
       
    39     return self;
       
    40     }
       
    41 
       
    42 UT_CFCConnectionContainer* UT_CFCConnectionContainer::NewLC()
       
    43     {
       
    44     UT_CFCConnectionContainer* self = new( ELeave ) UT_CFCConnectionContainer();
       
    45     CleanupStack::PushL( self );
       
    46 	self->ConstructL(); 
       
    47     return self;
       
    48     }
       
    49 
       
    50 // Destructor (virtual by CBase)
       
    51 UT_CFCConnectionContainer::~UT_CFCConnectionContainer()
       
    52     {
       
    53     }
       
    54 
       
    55 // Default constructor
       
    56 UT_CFCConnectionContainer::UT_CFCConnectionContainer()
       
    57     {
       
    58     }
       
    59 
       
    60 // Second phase construct
       
    61 void UT_CFCConnectionContainer::ConstructL()
       
    62     {
       
    63     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
    64     // It generates the test case table.
       
    65     CEUnitTestSuiteClass::ConstructL();
       
    66     }
       
    67 
       
    68 //  METHODS
       
    69 
       
    70 
       
    71 
       
    72 void UT_CFCConnectionContainer::SetupL(  )
       
    73     {
       
    74 	iConnection = CFCConnectionContainer::NewL(*this);
       
    75 	User::LeaveIfError( iSocketServ.Connect( KESockDefaultMessageSlots) );
       
    76     } 
       
    77 
       
    78 void UT_CFCConnectionContainer::Teardown(  )
       
    79     {
       
    80 	if(iConnection)
       
    81 		{
       
    82 		iConnection->CloseConnection();
       
    83 		}
       
    84 	delete iConnection;
       
    85 	iConnection=NULL;	
       
    86 	iSocketServ.Close();
       
    87     }
       
    88 
       
    89 void UT_CFCConnectionContainer::UT_CFCConnectionContainer_NewLL(  )
       
    90     {
       
    91     iConnection->OpenConnection(KIAPID, iSocketServ  );
       
    92     CFCConnectionContainer* tmpConn=CFCConnectionContainer::NewL(*this);
       
    93     tmpConn->OpenConnection(KIAPID, iSocketServ  );
       
    94     iConnection->Cancel(); 
       
    95     iConnection->RunL(); 
       
    96     
       
    97     EUNIT_ASSERT( iErr==0);//Connection has opened
       
    98  	if(tmpConn)
       
    99 		{
       
   100 		tmpConn->CloseConnection();
       
   101 		}
       
   102 	delete tmpConn;
       
   103 	tmpConn=NULL;
       
   104     }
       
   105 
       
   106 void UT_CFCConnectionContainer::UT_CFCConnectionContainer_ConnectionL(  )
       
   107     {
       
   108     TBuf<KMaxName> aName1;
       
   109     TBuf<KMaxName> aName2;
       
   110     TInt err1;
       
   111     TInt err2;
       
   112     iConnection->OpenConnection(KIAPID, iSocketServ  );
       
   113     RConnection& tmp= iConnection->Connection();
       
   114     err1=tmp.Name(aName1);
       
   115     tmp.Close();
       
   116     iConnection->CloseConnection();
       
   117     iConnection->OpenConnection(KIAPID, iSocketServ  );
       
   118     RConnection& tmp2= iConnection->Connection();
       
   119     err2=tmp2.Name(aName2);
       
   120     
       
   121     iConnection->Cancel();
       
   122     iConnection->RunL();
       
   123         
       
   124     if (err1==KErrNone & err2==KErrNone)
       
   125     	{
       
   126     	EUNIT_ASSERT( aName1==aName2 );
       
   127     	}
       
   128 	tmp2.Close();
       
   129    	}
       
   130 
       
   131 void UT_CFCConnectionContainer::UT_CFCConnectionContainer_OpenConnectionL(  )
       
   132     {
       
   133     iConnection->OpenConnection(KIAPID, iSocketServ );
       
   134     CFCConnectionContainer* tmpConn=CFCConnectionContainer::NewL(*this);
       
   135     tmpConn->OpenConnection(KIAPID, iSocketServ );
       
   136     iConnection->Cancel(); 
       
   137     iConnection->RunL(); 
       
   138     
       
   139     EUNIT_ASSERT( iErr==0);//Connection has opened
       
   140     if(tmpConn)
       
   141 		{
       
   142 		tmpConn->CloseConnection();
       
   143 		}
       
   144 	delete tmpConn;
       
   145 	tmpConn=NULL;
       
   146     }
       
   147  
       
   148 
       
   149 
       
   150 void UT_CFCConnectionContainer::UT_CFCConnectionContainer_CloseConnectionL(  )
       
   151     {
       
   152     iConnection->OpenConnection(KIAPID, iSocketServ );
       
   153     iConnection->CloseConnection();
       
   154     CFCConnectionContainer* tmpConn=CFCConnectionContainer::NewL(*this);
       
   155     tmpConn->OpenConnection(KIAPID, iSocketServ );
       
   156     iConnection->Cancel(); 
       
   157     iConnection->RunL(); 
       
   158     
       
   159     EUNIT_ASSERT( iErr==0);//Connection has opened
       
   160     if(tmpConn)
       
   161 		{
       
   162 		tmpConn->CloseConnection();
       
   163 		}
       
   164 	delete tmpConn;
       
   165 	tmpConn=NULL;
       
   166     }
       
   167     
       
   168 void UT_CFCConnectionContainer::UT_CFCConnectionContainer_TestRunLL(  )
       
   169 	{
       
   170 	TRequestStatus* status = &iConnection->iStatus;
       
   171     User::RequestComplete(status, KErrCancel);
       
   172     iConnection->RunL();
       
   173     EUNIT_ASSERT( iErr==KErrNone);
       
   174    	iConnection->Cancel();
       
   175    	User::WaitForAnyRequest();
       
   176 	}
       
   177 
       
   178 
       
   179 void UT_CFCConnectionContainer::UT_CFCConnectionContainer_TestDoCancelL(  )
       
   180 	{
       
   181 	RConnection& temp = iConnection->Connection();
       
   182 	User::LeaveIfError(temp.Open(iSocketServ));
       
   183 	TRequestStatus* status = &iConnection->iStatus;
       
   184 	User::RequestComplete(status, KRequestPending);
       
   185 	iConnection->DoCancel();
       
   186 	User::WaitForAnyRequest();
       
   187 	iConnection->Cancel();
       
   188 	User::WaitForAnyRequest();
       
   189 	}
       
   190 
       
   191 void UT_CFCConnectionContainer::ConnectionStarted( TInt aError )
       
   192 	{
       
   193 	iErr= aError;
       
   194 	}
       
   195 
       
   196 //  TEST TABLE
       
   197 
       
   198 EUNIT_BEGIN_TEST_TABLE( 
       
   199     UT_CFCConnectionContainer,
       
   200     "UT_CFCConnectionContainer",
       
   201     "UNIT" )
       
   202 
       
   203 EUNIT_TEST(
       
   204     "NewL - test ",
       
   205     "CFCConnectionContainer",
       
   206     "NewL",
       
   207     "FUNCTIONALITY",
       
   208     SetupL, UT_CFCConnectionContainer_NewLL, Teardown)
       
   209 
       
   210 EUNIT_TEST(
       
   211     "Connection - test ",
       
   212     "CFCConnectionContainer",
       
   213     "Connection",
       
   214     "FUNCTIONALITY",
       
   215     SetupL, UT_CFCConnectionContainer_ConnectionL, Teardown)
       
   216 
       
   217 EUNIT_TEST(
       
   218     "OpenConnection - test ",
       
   219     "CFCConnectionContainer",
       
   220     "OpenConnection",
       
   221     "FUNCTIONALITY",
       
   222     SetupL, UT_CFCConnectionContainer_OpenConnectionL, Teardown)
       
   223     
       
   224 EUNIT_TEST(
       
   225     "CloseConnection - test ",
       
   226     "CFCConnectionContainer",
       
   227     "CloseConnection",
       
   228     "FUNCTIONALITY",
       
   229     SetupL, UT_CFCConnectionContainer_CloseConnectionL, Teardown)
       
   230 
       
   231 EUNIT_TEST(
       
   232     "RunL - test ",
       
   233     "CFCConnectionContainer",
       
   234     "RunL",
       
   235     "FUNCTIONALITY",
       
   236     SetupL, UT_CFCConnectionContainer_TestRunLL, Teardown)
       
   237 
       
   238 EUNIT_TEST(
       
   239     "DoCancel - test ",
       
   240     "CFCConnectionContainer",
       
   241     "DoCancel",
       
   242     "FUNCTIONALITY",
       
   243     SetupL, UT_CFCConnectionContainer_TestDoCancelL, Teardown)
       
   244 
       
   245 
       
   246 EUNIT_END_TEST_TABLE
       
   247 
       
   248 //  END OF FILE