commonui/test/t_glxzoomstatepublisher/t_glxzoomstatepublisher.cpp
changeset 23 74c9f037fd5d
equal deleted inserted replaced
5:f7f0874bfe7d 23:74c9f037fd5d
       
     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 /*
       
    19 -----------------------------------------------------------------------------
       
    20 This file has been generated with EUnit Pro
       
    21 http://www.sysopendigia.com/qualitykit
       
    22 -----------------------------------------------------------------------------
       
    23 */
       
    24 
       
    25 /**
       
    26  * @internal reviewed 5/02/2007 by Alex Birkett
       
    27  */
       
    28  
       
    29 // CLASS HEADER
       
    30 #include "t_glxzoomstatepublisher.h"
       
    31 
       
    32 // EXTERNAL INCLUDES
       
    33 #include <EUnitMacros.h>
       
    34 #include <EUnitDecorators.h>
       
    35 #include <cfcontextquery.h>
       
    36 #include <cfclient.h>
       
    37 #include <cflistener.h>
       
    38 
       
    39 // CODE UNDER TEST
       
    40 #include "glxzoomstatepublisher.h"
       
    41 
       
    42 // - Construction -----------------------------------------------------------
       
    43 
       
    44 T_GlxZoomStatePublisher* T_GlxZoomStatePublisher::NewL()
       
    45     {
       
    46     T_GlxZoomStatePublisher* self = T_GlxZoomStatePublisher::NewLC();
       
    47     CleanupStack::Pop();
       
    48     return self;
       
    49     }
       
    50 
       
    51 T_GlxZoomStatePublisher* T_GlxZoomStatePublisher::NewLC()
       
    52     {
       
    53     T_GlxZoomStatePublisher* self = new( ELeave ) T_GlxZoomStatePublisher;
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL();
       
    56     return self;
       
    57     }
       
    58 
       
    59 T_GlxZoomStatePublisher::~T_GlxZoomStatePublisher()
       
    60     {
       
    61     }
       
    62 
       
    63 T_GlxZoomStatePublisher::T_GlxZoomStatePublisher()
       
    64     {
       
    65     }
       
    66 
       
    67 void T_GlxZoomStatePublisher::ConstructL()
       
    68     {
       
    69     CEUnitTestSuiteClass::ConstructL();
       
    70     }
       
    71 
       
    72 // - Test methods -----------------------------------------------------------
       
    73 
       
    74 void T_GlxZoomStatePublisher::SetupL()
       
    75     {
       
    76     }
       
    77 
       
    78 void T_GlxZoomStatePublisher::Teardown()
       
    79     {
       
    80     }
       
    81 
       
    82 /*
       
    83  * Implementation of MCFListener, needed
       
    84  * since CCFClient takes a reference
       
    85  */
       
    86 class T_TemporaryListener : public MCFListener
       
    87     {
       
    88     private: // From MCFListener
       
    89         /// @ref MCFListener
       
    90         void ContextIndicationL(
       
    91             const CCFContextIndication& /*aChangedContext*/ )
       
    92             {
       
    93             // nothing to do
       
    94             }
       
    95         /// @ref MCFListener
       
    96         void ActionIndicationL(
       
    97             const CCFActionIndication& /*aActionToExecute*/ )
       
    98             {
       
    99             // nothing to do
       
   100             }
       
   101         /// @ref MCFListener
       
   102         void HandleContextFrameworkError( TCFError /*aError*/,
       
   103             const TDesC& /*aSource*/,
       
   104             const TDesC& /*aType*/ )
       
   105             {
       
   106             // nothing to do
       
   107             }
       
   108         /// @ref MCFListener
       
   109         TAny* Extension( const TUid& /*aExtensionUid*/ ) const
       
   110             {
       
   111             // nothing to do
       
   112             return NULL;
       
   113             }
       
   114     };
       
   115 
       
   116 void T_GlxZoomStatePublisher::T_TestL()
       
   117     {
       
   118     // need a listener even though we're not interested of the events
       
   119     T_TemporaryListener temp;
       
   120     // create client first
       
   121     CCFClient* client = NULL;
       
   122     TRAPD( err, 
       
   123         {
       
   124         client = CCFClient::NewL( temp );
       
   125         } );
       
   126     // if client creation failed, we dont have the context framework server running
       
   127     // and there is no point to continue with the test
       
   128     if( !client )
       
   129         {
       
   130         return;
       
   131         }
       
   132     CleanupStack::PushL( client );
       
   133 
       
   134     // publish state, no zoom keys
       
   135     NGlxZoomStatePublisher::PublishStateL( EFalse );
       
   136 
       
   137     // check that the context is there
       
   138     _LIT( KGlxContextSource, "Application" );
       
   139     _LIT( KGlxContextType, "Photos.Zoom" );
       
   140     _LIT( KGlxContextValueEnabled, "Enabled" );
       
   141     _LIT( KGlxContextValueDisabled, "Disabled" );
       
   142     
       
   143         {
       
   144         // make a query to see that the context is there
       
   145         CCFContextQuery* query = CCFContextQuery::NewLC();
       
   146         query->SetSourceL( KGlxContextSource );
       
   147         query->SetTypeL( KGlxContextType );
       
   148         RContextObjectArray result;
       
   149         TInt err = client->RequestContext( *query, result );
       
   150         EUNIT_ASSERT_EQUALS_DESC( KErrNone, err, "no error" );
       
   151         EUNIT_ASSERT_EQUALS_DESC( 1, result.Count(), "1 result" );
       
   152         EUNIT_ASSERT_EQUALS_DESC( KGlxContextValueDisabled(), result[ 0 ]->Value(), "value is disabled" );
       
   153         result.ResetAndDestroy();
       
   154         CleanupStack::PopAndDestroy( query );
       
   155         }
       
   156 
       
   157     // publish state, zoom keys on
       
   158     NGlxZoomStatePublisher::PublishStateL( ETrue );
       
   159 
       
   160         {
       
   161         // make a query to see that the context is there
       
   162         CCFContextQuery* query = CCFContextQuery::NewLC();
       
   163         query->SetSourceL( KGlxContextSource );
       
   164         query->SetTypeL( KGlxContextType );
       
   165         RContextObjectArray result;
       
   166         TInt err = client->RequestContext( *query, result );
       
   167         EUNIT_ASSERT_EQUALS_DESC( KErrNone, err, "no error" );
       
   168         EUNIT_ASSERT_EQUALS_DESC( 1, result.Count(), "1 result" );
       
   169         EUNIT_ASSERT_EQUALS_DESC( KGlxContextValueEnabled(), result[ 0 ]->Value(), "value is enabled" );
       
   170         result.ResetAndDestroy();
       
   171         CleanupStack::PopAndDestroy( query );
       
   172         }
       
   173 
       
   174     CleanupStack::PopAndDestroy( client );
       
   175     }
       
   176     
       
   177 
       
   178 // - EUnit test table -------------------------------------------------------
       
   179 
       
   180 EUNIT_BEGIN_TEST_TABLE(
       
   181     T_GlxZoomStatePublisher,
       
   182     "Test suite for NGlxZoomStatePublisher",
       
   183     "UNIT" )
       
   184 
       
   185 EUNIT_TEST(
       
   186     "PublishStateL test",
       
   187     "NGlxZoomStatePublisher",
       
   188     "PublishStateL",
       
   189     "FUNCTIONALITY",
       
   190     SetupL, T_TestL, Teardown )
       
   191 
       
   192 EUNIT_END_TEST_TABLE