classicui_pub/grids_api/tsrc/src/testsdkgridsblocksakngridm.cpp
changeset 0 2f259fa3e83a
equal deleted inserted replaced
-1:000000000000 0:2f259fa3e83a
       
     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 akngridm.h
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 /*
       
    20  * Include files
       
    21  */
       
    22 #include <akngridm.h>
       
    23 #include <badesca.h>
       
    24 
       
    25 #include "testsdkgrids.h"
       
    26 
       
    27 const TInt KSize = 5;
       
    28 const TInt KThree = 3;
       
    29 const TInt KSix = 6;
       
    30 const TInt KFour = 4;
       
    31 const TInt KZero = 0;
       
    32 
       
    33 _LIT(KTom, "Tom");
       
    34 _LIT(KJack, "Jack");
       
    35 _LIT(KMary, "Mary");
       
    36 
       
    37 // -----------------------------------------------------------------------------
       
    38 // CTestSDKGrids::TestGridsGridmConstructorAndDestructorL
       
    39 // -----------------------------------------------------------------------------
       
    40 //
       
    41 TInt CTestSDKGrids::TestGridsGridmConstructorAndDestructorL( CStifItemParser& /*aItem*/ )
       
    42     {
       
    43     CAknGridM* grid = new( ELeave ) CAknGridM;
       
    44     CleanupStack::PushL( grid );
       
    45     STIF_ASSERT_NOT_NULL( grid );
       
    46 
       
    47     CleanupStack::PopAndDestroy( grid );
       
    48     return KErrNone;
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CTestSDKGrids::TestGridsGridmNumberOfItemsL
       
    53 // -----------------------------------------------------------------------------
       
    54 //
       
    55 TInt CTestSDKGrids::TestGridsGridmNumberOfItemsL( CStifItemParser& /*aItem*/ )
       
    56     {
       
    57     CAknGridM* grid = new( ELeave ) CAknGridM;
       
    58     CleanupStack::PushL( grid );
       
    59 
       
    60     CDesCArrayFlat* arr = new( ELeave ) CDesCArrayFlat( KSize );
       
    61     CleanupStack::PushL( arr );
       
    62 
       
    63     HBufC* buf1 = KTom().AllocLC();
       
    64     HBufC* buf2 = KJack().AllocLC();
       
    65     HBufC* buf3 = KMary().AllocLC();
       
    66     
       
    67     arr->AppendL(*buf1);
       
    68     arr->AppendL(*buf2);
       
    69     arr->AppendL(*buf3);
       
    70 
       
    71     grid->SetItemTextArray( arr );
       
    72 
       
    73     TInt numberofitem = grid->NumberOfItems();
       
    74     STIF_ASSERT_EQUALS( numberofitem, KThree );
       
    75 
       
    76     grid->SetStartCells( KThree );
       
    77     numberofitem = grid->NumberOfItems();
       
    78     STIF_ASSERT_EQUALS( KSix, numberofitem );
       
    79 
       
    80     CleanupStack::PopAndDestroy( buf3 );
       
    81     CleanupStack::PopAndDestroy( buf2 );
       
    82     CleanupStack::PopAndDestroy( buf1 );
       
    83     CleanupStack::Pop( arr );
       
    84     CleanupStack::PopAndDestroy( grid );
       
    85     return KErrNone;
       
    86     }
       
    87 
       
    88 // -----------------------------------------------------------------------------
       
    89 // CTestSDKGrids::TestGridsGridmIndexContainsDataL
       
    90 // -----------------------------------------------------------------------------
       
    91 //
       
    92 TInt CTestSDKGrids::TestGridsGridmIndexContainsDataL( CStifItemParser& /*aItem*/ )
       
    93     {
       
    94     CAknGridM* grid = new( ELeave ) CAknGridM;
       
    95     CleanupStack::PushL( grid );
       
    96 
       
    97     CDesCArrayFlat* arr = new(ELeave)CDesCArrayFlat(KSize);
       
    98     CleanupStack::PushL( arr );
       
    99 
       
   100     HBufC* buf1 = KTom().AllocLC();
       
   101     HBufC* buf2 = KJack().AllocLC();
       
   102     HBufC* buf3 = KMary().AllocLC();
       
   103 
       
   104     arr->AppendL(*buf1);
       
   105     arr->AppendL(*buf2);
       
   106     arr->AppendL(*buf3);
       
   107 
       
   108     grid->SetItemTextArray( arr );
       
   109 
       
   110     TBool flag = grid->IndexContainsData( KThree );
       
   111     STIF_ASSERT_FALSE( flag );
       
   112 
       
   113     flag = grid->IndexContainsData( KSix );
       
   114     STIF_ASSERT_FALSE( flag );
       
   115 
       
   116     grid->SetStartCells( KThree );
       
   117     flag = grid->IndexContainsData( KSix );
       
   118     STIF_ASSERT_FALSE( flag );
       
   119 
       
   120     flag = grid->IndexContainsData( KThree );
       
   121     STIF_ASSERT_TRUE( flag );
       
   122 
       
   123     flag = grid->IndexContainsData( KFour );
       
   124     STIF_ASSERT_TRUE( flag );
       
   125 
       
   126     CleanupStack::PopAndDestroy( buf3 );
       
   127     CleanupStack::PopAndDestroy( buf2 );
       
   128     CleanupStack::PopAndDestroy( buf1 );
       
   129     CleanupStack::Pop( arr );
       
   130     CleanupStack::PopAndDestroy( grid );
       
   131     return KErrNone;
       
   132     }
       
   133 
       
   134 // -----------------------------------------------------------------------------
       
   135 // CTestSDKGrids::TestGridsGridmNumberOfDataL
       
   136 // -----------------------------------------------------------------------------
       
   137 //
       
   138 TInt CTestSDKGrids::TestGridsGridmNumberOfDataL( CStifItemParser& /*aItem*/ )
       
   139     {
       
   140     CAknGridM* grid = new( ELeave ) CAknGridM;
       
   141     CleanupStack::PushL( grid );
       
   142 
       
   143     CDesCArrayFlat* arr = new(ELeave)CDesCArrayFlat(KSize);
       
   144     CleanupStack::PushL( arr );
       
   145 
       
   146     HBufC* buf1 = KTom().AllocLC();
       
   147     HBufC* buf2 = KJack().AllocLC();
       
   148     HBufC* buf3 = KMary().AllocLC();
       
   149 
       
   150     arr->AppendL(*buf1);
       
   151     arr->AppendL(*buf2);
       
   152     arr->AppendL(*buf3);
       
   153 
       
   154     grid->SetItemTextArray( arr );
       
   155 
       
   156     TInt numberofdata = grid->NumberOfData();
       
   157     STIF_ASSERT_EQUALS( KThree, numberofdata );
       
   158 
       
   159     CleanupStack::PopAndDestroy( buf3 );
       
   160     CleanupStack::PopAndDestroy( buf2 );
       
   161     CleanupStack::PopAndDestroy( buf1 );
       
   162     CleanupStack::Pop( arr );
       
   163     CleanupStack::PopAndDestroy( grid );
       
   164     return KErrNone;
       
   165     }
       
   166 
       
   167 // -----------------------------------------------------------------------------
       
   168 // CTestSDKGrids::TestGridsGridmSetStartCellsL
       
   169 // -----------------------------------------------------------------------------
       
   170 //
       
   171 TInt CTestSDKGrids::TestGridsGridmSetStartCellsL( CStifItemParser& /*aItem*/ )
       
   172     {
       
   173     CAknGridM* grid = new( ELeave ) CAknGridM;
       
   174     CleanupStack::PushL( grid );
       
   175 
       
   176     CDesCArrayFlat* arr = new(ELeave)CDesCArrayFlat(KSize);
       
   177     CleanupStack::PushL( arr );
       
   178 
       
   179 	HBufC* buf1 = KTom().AllocLC();
       
   180 
       
   181     arr->AppendL(*buf1);
       
   182 
       
   183     grid->SetItemTextArray( arr );
       
   184 
       
   185     TInt cells = grid->IndexOfFirstDataItem();
       
   186     STIF_ASSERT_EQUALS( KZero, cells );
       
   187 
       
   188     grid->SetStartCells( KThree );
       
   189     cells = grid->IndexOfFirstDataItem();
       
   190     STIF_ASSERT_EQUALS( KThree, cells );
       
   191 
       
   192     CleanupStack::PopAndDestroy( buf1 );
       
   193     CleanupStack::Pop( arr );
       
   194     CleanupStack::PopAndDestroy( grid );
       
   195     return KErrNone;
       
   196     }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CTestSDKGrids::TestGridsGridmIndexOfFirstDataItemL
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 TInt CTestSDKGrids::TestGridsGridmIndexOfFirstDataItemL( CStifItemParser& /*aItem*/ )
       
   203     {
       
   204     CAknGridM* grid = new( ELeave ) CAknGridM;
       
   205     CleanupStack::PushL( grid );
       
   206 
       
   207     grid->SetStartCells( KThree );
       
   208 
       
   209     CDesCArrayFlat* arr = new(ELeave)CDesCArrayFlat(KSize);
       
   210     CleanupStack::PushL( arr );
       
   211 
       
   212     HBufC* buf1 = KTom().AllocLC();
       
   213 
       
   214     arr->AppendL(*buf1);
       
   215 
       
   216     grid->SetItemTextArray( arr );
       
   217 
       
   218     TInt firstdataitemindex = grid->IndexOfFirstDataItem();
       
   219     STIF_ASSERT_EQUALS( KThree, firstdataitemindex );
       
   220 
       
   221     CleanupStack::PopAndDestroy( buf1 );
       
   222     CleanupStack::Pop( arr );
       
   223     CleanupStack::PopAndDestroy( grid );
       
   224     return KErrNone;
       
   225     }
       
   226 
       
   227 // -----------------------------------------------------------------------------
       
   228 // CTestSDKGrids::TestGridsGridmIndexOfLastDataItemL
       
   229 // -----------------------------------------------------------------------------
       
   230 //
       
   231 TInt CTestSDKGrids::TestGridsGridmIndexOfLastDataItemL( CStifItemParser& /*aItem*/ )
       
   232     {
       
   233     CAknGridM* grid = new( ELeave ) CAknGridM;
       
   234     CleanupStack::PushL( grid );
       
   235 
       
   236     CDesCArrayFlat* arr = new(ELeave)CDesCArrayFlat(KSize);
       
   237     CleanupStack::PushL( arr );
       
   238 
       
   239     HBufC* buf1 = KTom().AllocLC();
       
   240 
       
   241     arr->AppendL(*buf1);
       
   242 
       
   243     grid->SetItemTextArray( arr );
       
   244 
       
   245     TInt lastdataitemindex = grid->IndexOfLastDataItem();
       
   246     STIF_ASSERT_EQUALS( KZero, lastdataitemindex );
       
   247 
       
   248     grid->SetStartCells( KThree );
       
   249 
       
   250     lastdataitemindex = grid->IndexOfLastDataItem();
       
   251     STIF_ASSERT_EQUALS( KThree, lastdataitemindex );
       
   252 
       
   253     CleanupStack::PopAndDestroy( buf1 );
       
   254     CleanupStack::Pop( arr );
       
   255     CleanupStack::PopAndDestroy( grid );
       
   256     return KErrNone;
       
   257     }
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CTestSDKGrids::TestGridsGridmItemTextL
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 TInt CTestSDKGrids::TestGridsGridmItemTextL( CStifItemParser& /*aItem*/ )
       
   264     {   
       
   265     CAknGridM* grid = new( ELeave ) CAknGridM;
       
   266     CleanupStack::PushL( grid );
       
   267 
       
   268     CDesCArrayFlat* arr = new(ELeave)CDesCArrayFlat(KSize);
       
   269     CleanupStack::PushL( arr );
       
   270 
       
   271     HBufC* buf1 = KTom().AllocLC();
       
   272 
       
   273     arr->AppendL(*buf1);
       
   274 
       
   275     grid->SetItemTextArray( arr );
       
   276 
       
   277     TBufC<10> buf ( KTom ); 
       
   278     TPtrC comparetext( buf );
       
   279     TPtrC returntext = grid->ItemText( KZero );
       
   280     STIF_ASSERT_EQUALS( comparetext, returntext );
       
   281 
       
   282     grid->SetStartCells( KThree );
       
   283     TPtrC returntexttwo = grid->ItemText( KThree );
       
   284     STIF_ASSERT_EQUALS( comparetext, returntexttwo );
       
   285 
       
   286     CleanupStack::PopAndDestroy( buf1 );
       
   287     CleanupStack::Pop( arr );
       
   288     CleanupStack::PopAndDestroy( grid );
       
   289     return KErrNone;
       
   290     }
       
   291 
       
   292 /*
       
   293  * End files
       
   294  */