uiaccelerator_plat/alf_visual_api/tsrc/src/testplatalfvisualblocksroster.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2002 - 2007 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:  test functions for alfroster.h
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // [INCLUDE FILES]
       
    21 #include <alf/alfroster.h>
       
    22 #include <alf/alfmetric.h>
       
    23 
       
    24 #include "testplatalfvisual.h"
       
    25 
       
    26 
       
    27 // CONSTANTS
       
    28 const TInt KNum3 = 3;
       
    29 const TInt KNum4 = 4;
       
    30 const TInt KNum5 = 5;
       
    31 const TReal32 KMagnitude = 5;
       
    32 const TInt KControlId = 222;
       
    33 
       
    34 
       
    35 // FORWARD DECLARATION
       
    36 //class CTestControlGroupOrderChangedObserver for testing CAlfRoster
       
    37 class CTestControlGroupOrderChangedObserver
       
    38 : public CBase, public MAlfControlGroupOrderChangedObserver
       
    39     {
       
    40 public:
       
    41     /**
       
    42      * Default constructor
       
    43      */
       
    44     CTestControlGroupOrderChangedObserver( CAlfRoster& aRoster )
       
    45     : iRoster( aRoster ), iNoOfCalls( 0 )
       
    46         {}
       
    47     
       
    48     /**
       
    49      * Default destructor
       
    50      */
       
    51     ~CTestControlGroupOrderChangedObserver()
       
    52         {
       
    53         iRoster.RemoveControlGroupOrderChangedObserver( *this );
       
    54         }
       
    55     
       
    56     /**
       
    57      * ConstructL
       
    58      */
       
    59     void ConstructL()
       
    60         {
       
    61         iRoster.AddControlGroupOrderChangedObserverL( *this );
       
    62         }
       
    63     
       
    64     /**
       
    65      * From MAlfControlGroupOrderChangedObserver
       
    66      */
       
    67     void NotifyControlGroupOrderChanged()
       
    68         {
       
    69         iNoOfCalls++;
       
    70         }
       
    71     
       
    72     /**
       
    73      * Accessor to the number of calls to the callback method
       
    74      */
       
    75     TInt NumberOfCalls() const
       
    76         {
       
    77         return iNoOfCalls;
       
    78         }
       
    79     
       
    80 private:
       
    81     /** Roster to which this callback object is added to. */
       
    82     CAlfRoster& iRoster;
       
    83     
       
    84     /**
       
    85      * Number of calls to the callback method
       
    86      */
       
    87     TInt iNoOfCalls;
       
    88     };
       
    89 
       
    90 
       
    91 // ============================ MEMBER FUNCTIONS ===============================
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CTestPlatAlfVisual::TestRosterCtrlGroupMethodsL
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 TInt CTestPlatAlfVisual::TestRosterCtrlGroupMethodsL( CStifItemParser& /*aItem*/ )
       
    98     {
       
    99     // Print to UI
       
   100     _LIT( KTestPlatAlfVisual, "TestPlatAlfVisual" );
       
   101     _LIT( KTestRosterCtrlGroupMethodsL, "TestRosterCtrlGroupMethodsL" );
       
   102     TestModuleIf().Printf( 0, KTestPlatAlfVisual, KTestRosterCtrlGroupMethodsL );
       
   103     // Print to log file
       
   104     iLog->Log( KTestRosterCtrlGroupMethodsL );
       
   105     
       
   106     CAlfRoster* roster = &( iAlfDisplay->Roster() );
       
   107     STIF_ASSERT_NOT_NULL( roster );
       
   108     
       
   109     CAlfControlGroup& group1 = iAlfEnv->NewControlGroupL( 2 );
       
   110     CAlfControlGroup& group2 = iAlfEnv->NewControlGroupL( KNum3 );
       
   111     CAlfControlGroup& group3 = iAlfEnv->NewControlGroupL( KNum4 );
       
   112     CAlfControlGroup& group4 = iAlfEnv->NewControlGroupL( KNum5 );
       
   113     
       
   114     STIF_ASSERT_EQUALS( KErrNotFound, roster->Find( group1 ) );
       
   115     STIF_ASSERT_EQUALS( 0, roster->Count() );
       
   116     
       
   117     // Create controls and append them to control group 1
       
   118     CAlfControl* control = new (ELeave) CAlfControl;
       
   119     CleanupStack::PushL( control );
       
   120     control->ConstructL( *iAlfEnv );
       
   121     group1.AppendL( control );
       
   122     CleanupStack::Pop( control );
       
   123     CAlfControl* control1 = new (ELeave) CAlfControl;
       
   124     CleanupStack::PushL( control1 );
       
   125     control1->ConstructL( *iAlfEnv );
       
   126     group1.AppendL( control1 );
       
   127     CleanupStack::Pop( control1 );
       
   128     
       
   129     roster->ShowL( group1 );
       
   130     STIF_ASSERT_EQUALS( 1, roster->Count() );
       
   131     roster->ShowL( group2 );
       
   132     STIF_ASSERT_EQUALS( 2, roster->Count() );
       
   133     roster->ShowL( group3 );
       
   134     STIF_ASSERT_EQUALS( KNum3, roster->Count() );
       
   135     roster->ShowL( group4 );
       
   136     STIF_ASSERT_EQUALS( KNum4, roster->Count() );
       
   137     
       
   138     STIF_ASSERT_EQUALS( 0, roster->Find( group1 ) );
       
   139     STIF_ASSERT_EQUALS( 1, roster->Find( group2 ) );
       
   140     STIF_ASSERT_EQUALS( 2, roster->Find( group3 ) );
       
   141     STIF_ASSERT_EQUALS( KNum3, roster->Find( group4 ) );
       
   142     
       
   143     if ( roster->Count() > 0 )
       
   144         {
       
   145         STIF_ASSERT_EQUALS( &group1, &roster->ControlGroup( 0 ) );
       
   146         }
       
   147     
       
   148     // Verify that the controls are shown
       
   149     STIF_ASSERT_EQUALS( iAlfDisplay, control->Display() );
       
   150     STIF_ASSERT_EQUALS( iAlfDisplay, control1->Display() );
       
   151     
       
   152     roster->ShowL( group3, KAlfRosterShowAtBottom );
       
   153     
       
   154     STIF_ASSERT_EQUALS( 0, roster->Find( group3 ) );
       
   155     STIF_ASSERT_EQUALS( 1, roster->Find( group1 ) );
       
   156     STIF_ASSERT_EQUALS( 2, roster->Find( group2 ) ); 
       
   157     STIF_ASSERT_EQUALS( KNum3, roster->Find( group4 ) );
       
   158     
       
   159     if ( roster->Count() > 0 )
       
   160         {
       
   161         STIF_ASSERT_EQUALS( &group3, &roster->ControlGroup( 0 ) );
       
   162         }
       
   163     
       
   164     roster->ShowL( group3, KNum3 );
       
   165      
       
   166     STIF_ASSERT_EQUALS( 0, roster->Find( group1 ) );
       
   167     STIF_ASSERT_EQUALS( 1, roster->Find( group2 ) ); 
       
   168     STIF_ASSERT_EQUALS( 2, roster->Find( group4 ) );
       
   169     STIF_ASSERT_EQUALS( KNum3, roster->Find( group3 ) );
       
   170     
       
   171     if ( roster->Count() > 0 )
       
   172         {
       
   173         STIF_ASSERT_EQUALS( &group1, &roster->ControlGroup( 0 ) );
       
   174         }
       
   175     
       
   176     // Focus the appended control
       
   177     roster->SetFocus( *control );
       
   178     STIF_ASSERT_TRUE( control->Focus() );
       
   179     
       
   180     roster->Hide( group1 );
       
   181     STIF_ASSERT_EQUALS( KErrNotFound, roster->Find( group1 ) );
       
   182     STIF_ASSERT_EQUALS( KNum3, roster->Count() );
       
   183     roster->Hide( group2 );
       
   184     STIF_ASSERT_EQUALS( 2, roster->Count() );
       
   185     roster->Hide( group3 );
       
   186     STIF_ASSERT_EQUALS( 1, roster->Count() );
       
   187     roster->Hide( group4 );
       
   188     STIF_ASSERT_EQUALS( 0, roster->Count() );
       
   189     
       
   190     // Verify that focus was removed from control and 
       
   191     // that the control was hidden
       
   192     STIF_ASSERT_FALSE( control->Focus() );
       
   193     STIF_ASSERT_NULL( control->Display() );
       
   194     
       
   195     // Add a control to a hidden control group
       
   196     // Create controls and append them to iAlfCtrlGroup
       
   197     CAlfControl* control2 = new (ELeave) CAlfControl;
       
   198     CleanupStack::PushL( control2 );
       
   199     control2->ConstructL( *iAlfEnv );
       
   200     group1.AppendL( control2 );
       
   201     CleanupStack::Pop( control2 );
       
   202     
       
   203     // Verify that the control2 is not shown
       
   204     STIF_ASSERT_NULL( control2->Display() );
       
   205     
       
   206     return KErrNone;
       
   207     }
       
   208 
       
   209 // -----------------------------------------------------------------------------
       
   210 // CTestPlatAlfVisual::TestRosterCtrlMethodsL
       
   211 // -----------------------------------------------------------------------------
       
   212 //
       
   213 TInt CTestPlatAlfVisual::TestRosterCtrlMethodsL( CStifItemParser& /*aItem*/ )
       
   214     {
       
   215     // Print to UI
       
   216     _LIT( KTestPlatAlfVisual, "TestPlatAlfVisual" );
       
   217     _LIT( KTestRosterCtrlMethodsL, "TestRosterCtrlMethodsL" );
       
   218     TestModuleIf().Printf( 0, KTestPlatAlfVisual, KTestRosterCtrlMethodsL );
       
   219     // Print to log file
       
   220     iLog->Log( KTestRosterCtrlMethodsL );
       
   221     
       
   222     CAlfRoster* roster = &( iAlfDisplay->Roster() );
       
   223     STIF_ASSERT_NOT_NULL( roster );
       
   224     STIF_ASSERT_NULL( roster->FindControl( KControlId ) );
       
   225     iAlfCtl->SetId( KControlId );
       
   226     roster->ShowL( *iAlfCtrlGroup );
       
   227     roster->SetFocus( *iAlfCtl );
       
   228     STIF_ASSERT_TRUE( iAlfCtl->Focus() );
       
   229     STIF_ASSERT_EQUALS( iAlfCtl, roster->FindControl( KControlId ) );
       
   230     roster->ClearFocus();
       
   231     roster->Hide( *iAlfCtrlGroup );
       
   232     STIF_ASSERT_FALSE( iAlfCtl->Focus() );
       
   233     
       
   234     return KErrNone;
       
   235     }
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CTestPlatAlfVisual::TestRosterVisualMethodsL
       
   239 // -----------------------------------------------------------------------------
       
   240 //
       
   241 TInt CTestPlatAlfVisual::TestRosterVisualMethodsL( CStifItemParser& /*aItem*/ )
       
   242     {
       
   243     // Print to UI
       
   244     _LIT( KTestPlatAlfVisual, "TestPlatAlfVisual" );
       
   245     _LIT( KTestRosterVisualMethodsL, "TestRosterVisualMethodsL" );
       
   246     TestModuleIf().Printf( 0, KTestPlatAlfVisual, KTestRosterVisualMethodsL );
       
   247     // Print to log file
       
   248     iLog->Log( KTestRosterVisualMethodsL );
       
   249     
       
   250     CAlfRoster* roster = &( iAlfDisplay->Roster() );
       
   251     STIF_ASSERT_NOT_NULL( roster );
       
   252     
       
   253     CAlfLayout* layout = CAlfLayout::AddNewL( *iAlfCtl );
       
   254     
       
   255     roster->ShowL( *iAlfCtrlGroup );
       
   256     
       
   257     TInt err = KErrNone;
       
   258 //    TRAP( err, roster->ShowVisualL( *layout ) );
       
   259 //    roster->MoveVisualToFront( *layout );
       
   260     roster->HideVisual( *layout );
       
   261     if ( err != KErrNone )
       
   262         {
       
   263         return KErrNone;
       
   264         }
       
   265     
       
   266     return KErrNone;
       
   267     }
       
   268 
       
   269 // -----------------------------------------------------------------------------
       
   270 // CTestPlatAlfVisual::TestRosterPointerEventObserverMethodsL
       
   271 // -----------------------------------------------------------------------------
       
   272 //
       
   273 TInt CTestPlatAlfVisual::TestRosterPointerEventObserverMethodsL( CStifItemParser& /*aItem*/ )
       
   274     {
       
   275     // Print to UI
       
   276     _LIT( KTestPlatAlfVisual, "TestPlatAlfVisual" );
       
   277     _LIT( KTestRosterPointerEventObserverMethodsL, "TestRosterPointerEventObserverMethodsL" );
       
   278     TestModuleIf().Printf( 0, KTestPlatAlfVisual, KTestRosterPointerEventObserverMethodsL );
       
   279     // Print to log file
       
   280     iLog->Log( KTestRosterPointerEventObserverMethodsL );
       
   281     
       
   282     CAlfRoster* roster = &( iAlfDisplay->Roster() );
       
   283     STIF_ASSERT_NOT_NULL( roster );
       
   284     
       
   285     STIF_ASSERT_EQUALS( KErrNone,
       
   286             roster->AddPointerEventObserver( EAlfPointerEventReportDrag, *iAlfCtl ) );
       
   287     STIF_ASSERT_EQUALS( KErrNone,
       
   288             roster->AddPointerEventObserver( EAlfPointerEventReportLongTap, *iAlfCtl ) );
       
   289     STIF_ASSERT_EQUALS( KErrNone,
       
   290             roster->AddPointerEventObserver( EAlfPointerEventReportUnhandled, *iAlfCtl ) );
       
   291     
       
   292     STIF_ASSERT_EQUALS( KErrNone,
       
   293             roster->RemovePointerEventObserver( EAlfPointerEventReportDrag, *iAlfCtl ) );
       
   294     STIF_ASSERT_EQUALS( KErrNone,
       
   295             roster->RemovePointerEventObserver( EAlfPointerEventReportLongTap, *iAlfCtl ) );
       
   296     STIF_ASSERT_EQUALS( KErrNone,
       
   297             roster->RemovePointerEventObserver( EAlfPointerEventReportUnhandled, *iAlfCtl ) );
       
   298     
       
   299     STIF_ASSERT_EQUALS( KErrNone,
       
   300             roster->SetPointerEventObservers( EAlfPointerEventReportDrag, *iAlfCtl ) );
       
   301     STIF_ASSERT_EQUALS(
       
   302             KErrNone,
       
   303             roster->SetPointerEventObservers(
       
   304                     EAlfPointerEventReportDrag | EAlfPointerEventReportUnhandled,
       
   305                     *iAlfCtl
       
   306                     )
       
   307             );
       
   308     STIF_ASSERT_EQUALS( KErrNone,
       
   309             roster->SetPointerEventObservers( EAlfPointerEventReportLongTap, *iAlfCtl ) );
       
   310     STIF_ASSERT_EQUALS( KErrNone
       
   311             , roster->SetPointerEventObservers( 0, *iAlfCtl ) );
       
   312     
       
   313     return KErrNone;
       
   314     }
       
   315 
       
   316 // -----------------------------------------------------------------------------
       
   317 // CTestPlatAlfVisual::TestRosterSetPointerDragThresholdL
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 TInt CTestPlatAlfVisual::TestRosterSetPointerDragThresholdL( CStifItemParser& /*aItem*/ )
       
   321     {
       
   322     // Print to UI
       
   323     _LIT( KTestPlatAlfVisual, "TestPlatAlfVisual" );
       
   324     _LIT( KTestRosterSetPointerDragThresholdL, "TestRosterSetPointerDragThresholdL" );
       
   325     TestModuleIf().Printf( 0, KTestPlatAlfVisual, KTestRosterSetPointerDragThresholdL );
       
   326     // Print to log file
       
   327     iLog->Log( KTestRosterSetPointerDragThresholdL );
       
   328     
       
   329     CAlfRoster* roster = &( iAlfDisplay->Roster() );
       
   330     STIF_ASSERT_NOT_NULL( roster );
       
   331     
       
   332     STIF_ASSERT_EQUALS( KErrNone,
       
   333             roster->SetPointerEventObservers( EAlfPointerEventReportDrag, *iAlfCtl ) );
       
   334     STIF_ASSERT_EQUALS(
       
   335             KErrNone,
       
   336             roster->SetPointerDragThreshold(
       
   337                     *iAlfCtl,
       
   338                     TAlfXYMetric( KMagnitude, KMagnitude )
       
   339                     )
       
   340             );
       
   341     STIF_ASSERT_EQUALS(
       
   342             KErrNone,
       
   343             roster->SetPointerDragThreshold(
       
   344                     *iAlfCtl,
       
   345                     TAlfXYMetric(
       
   346                             TAlfMetric( KMagnitude, EAlfUnitS60 ),
       
   347                             TAlfMetric( 0.2, EAlfUnitRelativeToDisplay )
       
   348                             )
       
   349                     )
       
   350             );
       
   351     
       
   352     return KErrNone;
       
   353     }
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CTestPlatAlfVisual::TestRosterDisableLongTapEventsWhenDraggingL
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 TInt CTestPlatAlfVisual::TestRosterDisableLongTapEventsWhenDraggingL( CStifItemParser& /*aItem*/ )
       
   360     {
       
   361     // Print to UI
       
   362     _LIT( KTestPlatAlfVisual, "TestPlatAlfVisual" );
       
   363     _LIT( KTestRosterDisableLongTapEventsWhenDraggingL, "TestRosterDisableLongTapEventsWhenDraggingL" );
       
   364     TestModuleIf().Printf( 0, KTestPlatAlfVisual, KTestRosterDisableLongTapEventsWhenDraggingL );
       
   365     // Print to log file
       
   366     iLog->Log( KTestRosterDisableLongTapEventsWhenDraggingL );
       
   367     
       
   368     CAlfRoster* roster = &( iAlfDisplay->Roster() );
       
   369     STIF_ASSERT_NOT_NULL( roster );
       
   370     
       
   371     STIF_ASSERT_EQUALS( KErrNone,
       
   372             roster->SetPointerEventObservers( EAlfPointerEventReportDrag, *iAlfCtl ) );
       
   373     STIF_ASSERT_EQUALS( KErrNone,
       
   374             roster->DisableLongTapEventsWhenDragging( *iAlfCtl ));
       
   375     STIF_ASSERT_EQUALS( KErrNone,
       
   376             roster->DisableLongTapEventsWhenDragging( *iAlfCtl, EFalse ) );
       
   377     
       
   378     
       
   379     return KErrNone;
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CTestPlatAlfVisual::TestRosterCtrlGroupOrderChangedObserverL
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 TInt CTestPlatAlfVisual::TestRosterCtrlGroupOrderChangedObserverL( CStifItemParser& /*aItem*/ )
       
   387     {
       
   388     // Print to UI
       
   389     _LIT( KTestPlatAlfVisual, "TestPlatAlfVisual" );
       
   390     _LIT( KTestRosterCtrlGroupOrderChangedObserverL, "TestRosterCtrlGroupOrderChangedObserverL" );
       
   391     TestModuleIf().Printf( 0, KTestPlatAlfVisual, KTestRosterCtrlGroupOrderChangedObserverL );
       
   392     // Print to log file
       
   393     iLog->Log( KTestRosterCtrlGroupOrderChangedObserverL );
       
   394     
       
   395     CAlfRoster* roster = &( iAlfDisplay->Roster() );
       
   396     STIF_ASSERT_NOT_NULL( roster );
       
   397     // Create test control groups
       
   398     CAlfControlGroup& group2 = iAlfEnv->NewControlGroupL( 2 );
       
   399     CAlfControlGroup& group3 = iAlfEnv->NewControlGroupL( KNum3 );
       
   400     
       
   401     // Show first control group [Roster: cg1]
       
   402     roster->ShowL( *iAlfCtrlGroup );
       
   403     
       
   404     // Create an observer
       
   405     CTestControlGroupOrderChangedObserver* observer =
       
   406                 new ( ELeave ) CTestControlGroupOrderChangedObserver( *roster );
       
   407     CleanupStack::PushL( observer );
       
   408     observer->ConstructL();
       
   409     
       
   410     // Show second control group [Roster: cg2, cg1]
       
   411     roster->ShowL( group2 );
       
   412               
       
   413     // Remove observer
       
   414     roster->RemoveControlGroupOrderChangedObserver( *observer );
       
   415     
       
   416     // Swap order of control group 1 and 2 [Roster: cg1, cg2]
       
   417     roster->ShowL( *iAlfCtrlGroup );
       
   418     
       
   419     // Re-add observer
       
   420     roster->AddControlGroupOrderChangedObserverL( *observer );
       
   421     
       
   422     // Reswap order of control group 1 and 2 [Roster: cg2, cg1]
       
   423     roster->ShowL( group2 );
       
   424 
       
   425     // Don't modify the order of control groups [Roster: cg2, cg1]
       
   426     roster->ShowL( group2 );
       
   427 
       
   428     // Delete control group 2 [Roster: cg1]
       
   429     iAlfEnv->DeleteControlGroup( 2 );
       
   430     
       
   431     // Show new control group [Roster: cg3, cg1]
       
   432     roster->ShowL( group3 );
       
   433     
       
   434     // Hide old control group [Roster: cg3]
       
   435     roster->Hide( *iAlfCtrlGroup );
       
   436     
       
   437     // Hide hidden control group [Roster: cg3]
       
   438     roster->Hide( *iAlfCtrlGroup );
       
   439 
       
   440     // Hide last control group [Roster: ]
       
   441     roster->Hide( group3 );
       
   442     
       
   443     CleanupStack::PopAndDestroy( observer );
       
   444     
       
   445     // Verify that control group order change does not panic
       
   446     roster->ShowL( *iAlfCtrlGroup );
       
   447     
       
   448     return KErrNone;
       
   449     }
       
   450 
       
   451 
       
   452 //  [End of File]