classicui_pub/notes_api/tsrc/src/testsdknotesblockseikprogi.cpp
changeset 0 2f259fa3e83a
child 23 3d340a0166ff
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 EIKPROGI.H
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <eikprogi.h>
       
    20 #include <barsread.h>
       
    21 #include <coemain.h>
       
    22 #include <coeaui.h>
       
    23 #include <gulbordr.h>
       
    24 #include <aknsconstants.h>
       
    25 #include <e32base.h>
       
    26 #include <s32mem.h>
       
    27 #include <testsdknotes.rsg>
       
    28 
       
    29 #include "testsdknotesprogressinfo.h"
       
    30 #include "testsdknotes.h"
       
    31 
       
    32 const TInt KLength = 10;
       
    33 // ============================ MEMBER FUNCTIONS ===============================
       
    34 
       
    35 // -----------------------------------------------------------------------------
       
    36 // CTestSDKNotes::TestNPIDeconstructorL
       
    37 // -----------------------------------------------------------------------------
       
    38 TInt CTestSDKNotes::TestNPIDeconstructorL( CStifItemParser& /*aItem*/ )
       
    39     {
       
    40     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo;
       
    41     CleanupStack::PushL( progress );
       
    42     STIF_ASSERT_NOT_NULL( progress );
       
    43     
       
    44     CleanupStack::Pop( progress );
       
    45     delete progress;
       
    46     
       
    47     return KErrNone;
       
    48     
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CTestSDKNotes::TestNPICEikProgressInfoL
       
    53 // -----------------------------------------------------------------------------
       
    54 TInt CTestSDKNotes::TestNPICEikProgressInfoL( CStifItemParser& /*aItem*/ )
       
    55     {
       
    56     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo;
       
    57     CleanupStack::PushL( progress );
       
    58     STIF_ASSERT_NOT_NULL( progress );
       
    59     
       
    60     CleanupStack::PopAndDestroy( progress );
       
    61     
       
    62     return KErrNone;
       
    63     
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CTestSDKNotes::TestNPICEikProgressInfoSinfoL
       
    68 // -----------------------------------------------------------------------------
       
    69 TInt CTestSDKNotes::TestNPICEikProgressInfoSinfoL( CStifItemParser& /*aItem*/ )
       
    70     {
       
    71     CEikProgressInfo::SInfo sInfo;
       
    72     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo( sInfo );
       
    73     CleanupStack::PushL( progress );
       
    74     STIF_ASSERT_NOT_NULL( progress );
       
    75     
       
    76     CEikProgressInfo::SInfo sInfoGet = progress->Info();
       
    77     STIF_ASSERT_TRUE( sInfo.iFinalValue == sInfoGet.iFinalValue );
       
    78     STIF_ASSERT_TRUE( sInfo.iHeight == sInfoGet.iHeight );
       
    79     STIF_ASSERT_TRUE( sInfo.iSplitsInBlock == sInfoGet.iSplitsInBlock );
       
    80     STIF_ASSERT_TRUE( sInfo.iTextType == sInfoGet.iTextType );
       
    81     STIF_ASSERT_TRUE( sInfo.iWidth == sInfoGet.iWidth );
       
    82 
       
    83     CleanupStack::PopAndDestroy( progress );
       
    84     
       
    85     return KErrNone;
       
    86     
       
    87     }
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 // CTestSDKNotes::TestNPIIncrementAndDrawL
       
    91 // -----------------------------------------------------------------------------
       
    92 TInt CTestSDKNotes::TestNPIIncrementAndDrawL( CStifItemParser& /*aItem*/ )
       
    93     {
       
    94     CEikProgressInfo::SInfo sInfo;
       
    95     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo( sInfo );
       
    96     CleanupStack::PushL( progress );
       
    97     STIF_ASSERT_NOT_NULL( progress );
       
    98     
       
    99     TResourceReader reader;
       
   100     CCoeEnv::Static()->CreateResourceReaderLC( reader, R_TESTSDK_NOTESPROGI );
       
   101     progress->ConstructFromResourceL( reader );
       
   102     CleanupStack::PopAndDestroy();
       
   103     
       
   104     progress->SetFinalValue( KLength );
       
   105     progress->IncrementAndDraw( 1 );
       
   106     
       
   107     CleanupStack::PopAndDestroy( progress );
       
   108     
       
   109     return KErrNone;
       
   110     
       
   111     }
       
   112 
       
   113 // -----------------------------------------------------------------------------
       
   114 // CTestSDKNotes::TestNPISetAndDrawL
       
   115 // -----------------------------------------------------------------------------
       
   116 TInt CTestSDKNotes::TestNPISetAndDrawL( CStifItemParser& /*aItem*/ )
       
   117     {
       
   118     CEikProgressInfo::SInfo sInfo;
       
   119     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo( sInfo );
       
   120     CleanupStack::PushL( progress );
       
   121     STIF_ASSERT_NOT_NULL( progress );
       
   122     
       
   123     progress->SetFinalValue( KLength );
       
   124     TInt length = KLength + 1;
       
   125     progress->SetAndDraw( length );
       
   126     
       
   127     CleanupStack::PopAndDestroy( progress );
       
   128     
       
   129     progress = new (ELeave) CEikProgressInfo( sInfo );
       
   130     CleanupStack::PushL( progress );
       
   131     STIF_ASSERT_NOT_NULL( progress );
       
   132         
       
   133     progress->SetFinalValue( KLength );
       
   134     progress->SetFinalValue( -1 );
       
   135     
       
   136     CleanupStack::PopAndDestroy( progress );
       
   137     
       
   138     return KErrNone;
       
   139     
       
   140     }
       
   141 
       
   142 // -----------------------------------------------------------------------------
       
   143 // CTestSDKNotes::TestNPIConstructFromResourceL
       
   144 // -----------------------------------------------------------------------------
       
   145 TInt CTestSDKNotes::TestNPIConstructFromResourceL( CStifItemParser& /*aItem*/ )
       
   146     {
       
   147     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo;
       
   148     CleanupStack::PushL( progress );
       
   149     STIF_ASSERT_NOT_NULL( progress );
       
   150     
       
   151     TResourceReader reader;
       
   152     CCoeEnv::Static()->CreateResourceReaderLC( reader, R_TESTSDK_NOTESPROGI );
       
   153     progress->ConstructFromResourceL( reader );
       
   154     
       
   155     CEikProgressInfo::SInfo sInfoGet = progress->Info();
       
   156     const TInt KFinalValue = 200;
       
   157     const TInt KWidth = 120;
       
   158     STIF_ASSERT_TRUE( sInfoGet.iFinalValue == KFinalValue );
       
   159     STIF_ASSERT_TRUE( sInfoGet.iHeight == KLength );
       
   160     STIF_ASSERT_TRUE( sInfoGet.iSplitsInBlock == 0 );
       
   161     STIF_ASSERT_TRUE( sInfoGet.iTextType == 0 );
       
   162     STIF_ASSERT_TRUE( sInfoGet.iWidth == KWidth );
       
   163     
       
   164     CleanupStack::PopAndDestroy( 2 );
       
   165     
       
   166     return KErrNone;
       
   167     
       
   168     }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CTestSDKNotes::TestNPISetLayoutL
       
   172 // -----------------------------------------------------------------------------
       
   173 TInt CTestSDKNotes::TestNPISetLayoutL( CStifItemParser& /*aItem*/ )
       
   174     {
       
   175     CEikProgressInfo::SInfo sInfo;
       
   176     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo( sInfo );
       
   177     CleanupStack::PushL( progress );
       
   178     STIF_ASSERT_NOT_NULL( progress );
       
   179     
       
   180     CEikProgressInfo::SLayout sLayout;
       
   181     progress->SetLayout( sLayout );
       
   182     
       
   183     CEikProgressInfo::SLayout sLayoutGet = progress->Layout();
       
   184     STIF_ASSERT_TRUE( sLayout.iEmptyColor == sLayoutGet.iEmptyColor );
       
   185     STIF_ASSERT_TRUE( sLayout.iEmptyTextColor == sLayoutGet.iEmptyTextColor );
       
   186     STIF_ASSERT_TRUE( sLayout.iFillColor == sLayoutGet.iFillColor );
       
   187     STIF_ASSERT_TRUE( sLayout.iFillTextColor == sLayoutGet.iFillTextColor );
       
   188     STIF_ASSERT_TRUE( sLayout.iFont == sLayoutGet.iFont );
       
   189     STIF_ASSERT_TRUE( sLayout.iGapBetweenBlocks == sLayoutGet.iGapBetweenBlocks );
       
   190     
       
   191     CleanupStack::PopAndDestroy( progress );
       
   192     
       
   193     return KErrNone;
       
   194     
       
   195     }
       
   196 
       
   197 // -----------------------------------------------------------------------------
       
   198 // CTestSDKNotes::TestNPISetBorderL
       
   199 // -----------------------------------------------------------------------------
       
   200 TInt CTestSDKNotes::TestNPISetBorderL( CStifItemParser& /*aItem*/ )
       
   201     {
       
   202     CEikProgressInfo::SInfo sInfo;
       
   203     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo( sInfo );
       
   204     CleanupStack::PushL( progress );
       
   205     STIF_ASSERT_NOT_NULL( progress );
       
   206     
       
   207     TGulBorder gulBorder;
       
   208     progress->SetBorder( gulBorder );
       
   209     
       
   210     CleanupStack::PopAndDestroy( progress );
       
   211     
       
   212     return KErrNone;
       
   213     
       
   214     }
       
   215 
       
   216 // -----------------------------------------------------------------------------
       
   217 // CTestSDKNotes::TestNPISetFinalValueL
       
   218 // -----------------------------------------------------------------------------
       
   219 TInt CTestSDKNotes::TestNPISetFinalValueL( CStifItemParser& aItem )
       
   220     {
       
   221     return TestNPIIncrementAndDrawL( aItem );
       
   222     
       
   223     }
       
   224 
       
   225 // -----------------------------------------------------------------------------
       
   226 // CTestSDKNotes::TestNPIConstructL
       
   227 // -----------------------------------------------------------------------------
       
   228 TInt CTestSDKNotes::TestNPIConstructL( CStifItemParser& /*aItem*/ )
       
   229     {
       
   230     CEikProgressInfo::SInfo sInfo;
       
   231     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo( sInfo );
       
   232     CleanupStack::PushL( progress );
       
   233     STIF_ASSERT_NOT_NULL( progress );
       
   234     
       
   235     progress->ConstructL();
       
   236     CleanupStack::PopAndDestroy( progress );
       
   237     
       
   238     return KErrNone;
       
   239     
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // CTestSDKNotes::TestNPIInfoL
       
   244 // -----------------------------------------------------------------------------
       
   245 TInt CTestSDKNotes::TestNPIInfoL( CStifItemParser& aItem )
       
   246     {
       
   247     return TestNPICEikProgressInfoSinfoL( aItem );
       
   248     
       
   249     }
       
   250 
       
   251 // -----------------------------------------------------------------------------
       
   252 // CTestSDKNotes::TestNPILayoutL
       
   253 // -----------------------------------------------------------------------------
       
   254 TInt CTestSDKNotes::TestNPILayoutL( CStifItemParser& aItem )
       
   255     {
       
   256     return TestNPISetLayoutL( aItem );
       
   257     
       
   258     }
       
   259 
       
   260 // -----------------------------------------------------------------------------
       
   261 // CTestSDKNotes::TestNPICurrentValueL
       
   262 // -----------------------------------------------------------------------------
       
   263 TInt CTestSDKNotes::TestNPICurrentValueL( CStifItemParser& /*aItem*/ )
       
   264     {
       
   265     CEikProgressInfo::SInfo sInfo;
       
   266     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo( sInfo );
       
   267     CleanupStack::PushL( progress );
       
   268     STIF_ASSERT_NOT_NULL( progress );
       
   269     progress->ConstructL();
       
   270     
       
   271     TInt currentValue = progress->CurrentValue();
       
   272     STIF_ASSERT_EQUALS( currentValue, 0 );
       
   273     
       
   274     CleanupStack::PopAndDestroy( progress );
       
   275     
       
   276     return KErrNone;
       
   277     
       
   278     }
       
   279 
       
   280 // -----------------------------------------------------------------------------
       
   281 // CTestSDKNotes::TestNPIEvaluateTextL
       
   282 // -----------------------------------------------------------------------------
       
   283 TInt CTestSDKNotes::TestNPIEvaluateTextL( CStifItemParser& /*aItem*/ )
       
   284     {
       
   285     CEikProgressInfo::SInfo sInfo;
       
   286     sInfo.iTextType = EEikProgressTextPercentage;
       
   287     CTestSDKNotesProgressInfo* progress = CTestSDKNotesProgressInfo::NewLC( sInfo );
       
   288     STIF_ASSERT_NOT_NULL( progress );
       
   289     
       
   290     TBuf<KLength> stackBuf;
       
   291     progress->EvaluateText( stackBuf );
       
   292     CleanupStack::PopAndDestroy( progress );
       
   293     
       
   294     return KErrNone;
       
   295     
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // CTestSDKNotes::TestNPIActivateL
       
   300 // -----------------------------------------------------------------------------
       
   301 TInt CTestSDKNotes::TestNPIActivateL( CStifItemParser& /*aItem*/ )
       
   302     {
       
   303     CEikProgressInfo::SInfo sInfo;
       
   304     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo( sInfo );
       
   305     CleanupStack::PushL( progress );
       
   306     STIF_ASSERT_NOT_NULL( progress );
       
   307     progress->ConstructL();
       
   308     
       
   309     progress->ActivateL();
       
   310     
       
   311     CleanupStack::PopAndDestroy( progress );
       
   312     
       
   313     return KErrNone;
       
   314     
       
   315     }
       
   316 
       
   317 // -----------------------------------------------------------------------------
       
   318 // CTestSDKNotes::TestNPIMinimumSizeL
       
   319 // -----------------------------------------------------------------------------
       
   320 TInt CTestSDKNotes::TestNPIMinimumSizeL( CStifItemParser& /*aItem*/ )
       
   321     {
       
   322     CEikProgressInfo::SInfo sInfo;
       
   323     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo( sInfo );
       
   324     CleanupStack::PushL( progress );
       
   325     STIF_ASSERT_NOT_NULL( progress );
       
   326     progress->ConstructL();
       
   327     
       
   328     TSize size = progress->MinimumSize();
       
   329     TPoint point = size.AsPoint();
       
   330     STIF_ASSERT_NOT_EQUALS( 0, point.iX );
       
   331     STIF_ASSERT_NOT_EQUALS( 0, point.iY );
       
   332     
       
   333     CleanupStack::PopAndDestroy( progress );
       
   334     
       
   335     return KErrNone;
       
   336     
       
   337     }
       
   338 
       
   339 // -----------------------------------------------------------------------------
       
   340 // CTestSDKNotes::TestNPISizeChangedL
       
   341 // -----------------------------------------------------------------------------
       
   342 TInt CTestSDKNotes::TestNPISizeChangedL( CStifItemParser& /*aItem*/ )
       
   343     {
       
   344     CEikProgressInfo::SInfo sInfo;
       
   345     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo( sInfo );
       
   346     CleanupStack::PushL( progress );
       
   347     STIF_ASSERT_NOT_NULL( progress );
       
   348     progress->ConstructL();
       
   349     
       
   350     progress->SizeChanged();
       
   351     
       
   352     CleanupStack::PopAndDestroy( progress );
       
   353     
       
   354     return KErrNone;
       
   355     }
       
   356 
       
   357 // -----------------------------------------------------------------------------
       
   358 // CTestSDKNotes::TestNPIGetColorUseListL
       
   359 // -----------------------------------------------------------------------------
       
   360 TInt CTestSDKNotes::TestNPIGetColorUseListL( CStifItemParser& /*aItem*/ )
       
   361     {
       
   362     CEikProgressInfo::SInfo sInfo;
       
   363     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo( sInfo );
       
   364     CleanupStack::PushL( progress );
       
   365     STIF_ASSERT_NOT_NULL( progress );
       
   366     progress->ConstructL();
       
   367     
       
   368     CArrayFix <TCoeColorUse>* colorUseList = new( ELeave ) CArrayFix <TCoeColorUse>( ( TBufRep )CBufFlat::NewL, 1 );
       
   369     CleanupStack::PushL( colorUseList );
       
   370     progress->GetColorUseListL( *colorUseList );
       
   371     STIF_ASSERT_NOT_NULL( colorUseList );
       
   372     
       
   373     CleanupStack::PopAndDestroy( colorUseList );
       
   374     CleanupStack::PopAndDestroy( progress );
       
   375     
       
   376     return KErrNone;
       
   377     
       
   378     }
       
   379 
       
   380 // -----------------------------------------------------------------------------
       
   381 // CTestSDKNotes::TestNPIHandleResourceChangeL
       
   382 // -----------------------------------------------------------------------------
       
   383 TInt CTestSDKNotes::TestNPIHandleResourceChangeL( CStifItemParser& /*aItem*/ )
       
   384     {
       
   385     CEikProgressInfo::SInfo sInfo;
       
   386     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo( sInfo );
       
   387     CleanupStack::PushL( progress );
       
   388     STIF_ASSERT_NOT_NULL( progress );
       
   389     progress->ConstructL();
       
   390     
       
   391     const TInt KBCTestNoteProgressbarMaxLength = 256;
       
   392     progress->HandleResourceChange( KAknsMessageSkinChange );
       
   393     progress->HandleResourceChange( KBCTestNoteProgressbarMaxLength );
       
   394     
       
   395     CleanupStack::PopAndDestroy( progress );
       
   396     
       
   397     return KErrNone;
       
   398     
       
   399     }
       
   400 
       
   401 // -----------------------------------------------------------------------------
       
   402 // CTestSDKNotes::TestNPIHandlePointerEventL
       
   403 // -----------------------------------------------------------------------------
       
   404 TInt CTestSDKNotes::TestNPIHandlePointerEventL( CStifItemParser& /*aItem*/ )
       
   405     {
       
   406     CEikProgressInfo::SInfo sInfo;
       
   407     CEikProgressInfo* progress = new (ELeave) CEikProgressInfo( sInfo );
       
   408     CleanupStack::PushL( progress );
       
   409     STIF_ASSERT_NOT_NULL( progress );
       
   410     progress->ConstructL();
       
   411     
       
   412     TPointerEvent event;
       
   413     event.iType = TPointerEvent::EButton1Down;
       
   414     event.iModifiers = 0;
       
   415     TPoint eventPos( 10, 30 );
       
   416     event.iPosition = eventPos;
       
   417     event.iParentPosition = eventPos;
       
   418     
       
   419     progress->HandlePointerEventL( event );
       
   420     
       
   421     CleanupStack::PopAndDestroy( progress );
       
   422     
       
   423     return KErrNone;
       
   424     
       
   425     }
       
   426 
       
   427 // -----------------------------------------------------------------------------
       
   428 // CTestSDKNotes::TestNPIWriteInternalStateL
       
   429 // -----------------------------------------------------------------------------
       
   430 TInt CTestSDKNotes::TestNPIWriteInternalStateL( CStifItemParser& /*aItem*/ )
       
   431     {
       
   432     CEikProgressInfo::SInfo sInfo;
       
   433     sInfo.iTextType = EEikProgressTextPercentage;
       
   434     CTestSDKNotesProgressInfo* progress = CTestSDKNotesProgressInfo::NewLC( sInfo );
       
   435     STIF_ASSERT_NOT_NULL( progress );
       
   436     
       
   437     const TInt size = 2000;
       
   438     CBufFlat* buf = CBufFlat::NewL( size );
       
   439     STIF_ASSERT_EQUALS( 0, buf->Ptr( 0 ).Length() );
       
   440     CleanupStack::PushL( buf );
       
   441     
       
   442     RBufWriteStream stream;
       
   443     CleanupClosePushL( stream );
       
   444     stream.Open( *buf );
       
   445     progress->WriteInternalStateL( stream );
       
   446     stream.CommitL();
       
   447     stream.Close();
       
   448     
       
   449     CleanupStack::PopAndDestroy( &stream );
       
   450     CleanupStack::PopAndDestroy( buf );
       
   451     CleanupStack::PopAndDestroy( progress );
       
   452     
       
   453     return KErrNone;
       
   454     
       
   455     }