phoneapp/phonemediatorcenter/tsrc/ut_mediatormessagefactory/src/T_MediatorMessageFactory.cpp
changeset 77 2be0b271d017
equal deleted inserted replaced
72:c76a0b1755b9 77:2be0b271d017
       
     1 /*
       
     2 * Copyright (c) 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:
       
    15 *
       
    16 */
       
    17 
       
    18 #include "T_MediatorMessageFactory.h"
       
    19 #include <EUnitMacros.h>
       
    20 #include <EUnitDecorators.h>
       
    21 
       
    22 #include "pevirtualengine.h"
       
    23 
       
    24 #include "CPhoneMediatorMessageFactory.h"
       
    25 #include "MPhoneMediatorMessage.h"
       
    26 
       
    27 #include "CPhoneDataPortMessage.h"
       
    28 
       
    29 CPhoneDataPortMessage* CDataPortMessage_NewLReturnValue;
       
    30 MPEEngineInfo* CDataPortMessage_NewLEngineInfo;
       
    31 
       
    32 // - Construction -----------------------------------------------------------
       
    33 
       
    34 T_MediatorMessageFactory* T_MediatorMessageFactory::NewL()
       
    35     {
       
    36     T_MediatorMessageFactory* self = T_MediatorMessageFactory::NewLC();
       
    37     CleanupStack::Pop();
       
    38     return self;
       
    39     }
       
    40 
       
    41 T_MediatorMessageFactory* T_MediatorMessageFactory::NewLC()
       
    42     {
       
    43     T_MediatorMessageFactory* self = new( ELeave ) T_MediatorMessageFactory();
       
    44     CleanupStack::PushL( self );
       
    45     self->ConstructL();
       
    46     return self;
       
    47     }
       
    48 
       
    49 T_MediatorMessageFactory::~T_MediatorMessageFactory()
       
    50     {
       
    51     }
       
    52 
       
    53 T_MediatorMessageFactory::T_MediatorMessageFactory()
       
    54     {
       
    55     }
       
    56 
       
    57 void T_MediatorMessageFactory::ConstructL()
       
    58     {
       
    59     CEUnitTestSuiteClass::ConstructL();
       
    60     }
       
    61 
       
    62 // - Test methods -----------------------------------------------------------
       
    63 
       
    64 
       
    65 
       
    66 void T_MediatorMessageFactory::SetupL(  )
       
    67     {
       
    68     MPEEngineInfo* info = reinterpret_cast<MPEEngineInfo*>(0xdeadbeef); // No access to engine info needed in tests.
       
    69     iFactory = CPhoneMediatorMessageFactory::NewL( *info );
       
    70     }
       
    71     
       
    72 
       
    73 void T_MediatorMessageFactory::Teardown(  )
       
    74     {
       
    75     delete iFactory;
       
    76     }
       
    77     
       
    78 
       
    79 void T_MediatorMessageFactory::TestCreatingMessageL(  )
       
    80     {
       
    81     CDataPortMessage_NewLReturnValue = reinterpret_cast<CPhoneDataPortMessage*>(0x12341234);  
       
    82     
       
    83     MPhoneMediatorMessage* msg = iFactory->CreateMessageL( MEngineMonitor::EPEMessageDataPortLoaned, 0 );
       
    84     
       
    85     // Compare pointers
       
    86     EUNIT_ASSERT( CDataPortMessage_NewLReturnValue == static_cast<CPhoneDataPortMessage*>(msg) );
       
    87     EUNIT_ASSERT( CDataPortMessage_NewLEngineInfo == reinterpret_cast<MPEEngineInfo*>(0xdeadbeef) );
       
    88     
       
    89     // Do not delete the msg, because msg is not really created
       
    90     }
       
    91     
       
    92 void T_MediatorMessageFactory::TestNoMessageForEngineMessageL()
       
    93     {
       
    94     MPhoneMediatorMessage* msg = 
       
    95         iFactory->CreateMessageL( static_cast<MEngineMonitor::TPEMessagesFromPhoneEngine>( -1 ), 0 );
       
    96     EUNIT_ASSERT( msg == NULL );
       
    97     }
       
    98 // - EUnit test table -------------------------------------------------------
       
    99 
       
   100 EUNIT_BEGIN_TEST_TABLE(
       
   101     T_MediatorMessageFactory,
       
   102     "Unittests for CPhoneMediatorMessageFactory",
       
   103     "UNIT" )
       
   104 
       
   105 EUNIT_TEST(
       
   106     "Create message",
       
   107     "CreateMessageL",
       
   108     "CPhoneMediatorMessageFactory",
       
   109     "FUNCTIONALITY",
       
   110     SetupL, TestCreatingMessageL, Teardown)
       
   111 
       
   112 EUNIT_TEST(
       
   113     "No message to create for pe message",
       
   114     "CreateMessageL",
       
   115     "CPhoneMediatorMessageFactory",
       
   116     "FUNCTIONALITY",
       
   117     SetupL, TestNoMessageForEngineMessageL, Teardown)
       
   118     
       
   119 
       
   120 EUNIT_END_TEST_TABLE