os/graphics/fbs/fontandbitmapserver/tfbs/tfbsglyphdatapanic.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 // Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @internalComponent - Internal Symbian test code
    19 */
    20 
    21 #include <test/graphicsfontutils.h>
    22 #include <graphics/fbsglyphmetricsarray.h> 
    23 #include <graphics/fbsglyphdataiterator.h>
    24 #include "tfbsglyphdatapanic.h"
    25 
    26 _LIT(KTypefaceName, "DejaVu Sans Condensed");
    27 const TInt KNumGlyphCodes = 96;
    28 
    29 CTFbsGlyphDataPanic::CTFbsGlyphDataPanic(CTestStep* aStep):
    30     CTGraphicsBase(aStep)
    31     {
    32     }
    33 
    34 CTFbsGlyphDataPanic::~CTFbsGlyphDataPanic()
    35     {
    36     iSgDriver.Close();
    37     if (iTs)
    38          {
    39          iTs->ReleaseFont(iFont);
    40          delete iTs;
    41          }
    42     }
    43 
    44 void CTFbsGlyphDataPanic::ConstructL()
    45     {
    46     User::LeaveIfNull(iFbs = RFbsSession::GetSession());
    47     User::LeaveIfNull(iTs = (CFbsTypefaceStore*)CFbsTypefaceStore::NewL(NULL));
    48     User::LeaveIfError(iTs->GetNearestFontToDesignHeightInPixels((CFont*&)iFont, TFontSpec(KTypefaceName, 15)));
    49     User::LeaveIfError(iSgDriver.Open());
    50     
    51     //initialize the array with ASCII characters from 0020 to 007F
    52     CCharCodeConverter* converter = CCharCodeConverter::NewLC();
    53     converter->UseFontL(iFont);
    54     iGlyphCodes = new(ELeave) TUint[KNumGlyphCodes];
    55     for (TInt i = 0; i < KNumGlyphCodes; ++i)
    56         {
    57         TUint asciiCode = i + 0x20; 
    58         iGlyphCodes[i] = converter->GlyphCodeL(asciiCode);
    59         }
    60     CleanupStack::PopAndDestroy(1); // converter
    61     }
    62 
    63 void CTFbsGlyphDataPanic::RunTestCaseL(TInt /*aCurTestCase*/)
    64     {
    65     ((CTFbsGlyphDataPanicStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
    66     TInt testCase = -1;
    67     _LIT(KCaseNumber, "CaseNumber");
    68     TEST(iStep->GetIntFromConfig(iStep->ConfigSection(), KCaseNumber, testCase));
    69     
    70     switch(testCase)
    71         {
    72     case 1:
    73         TestGlyphDataIteratorNotInitializedNext();
    74         break;
    75     case 2:
    76         TestGlyphDataIteratorNotInitializedImage();
    77         break;
    78     case 3:
    79         TestGlyphDataIteratorNotInitializedMetrics();
    80         break;
    81     case 4:
    82         TestGlyphDataIteratorNotInitializedGlyphCode();
    83         break;
    84     case 5:
    85         TestGlyphDataIteratorClosedNext();
    86         break;
    87     case 6:
    88         TestGlyphDataIteratorClosedImage();
    89         break;
    90     case 7:
    91         TestGlyphDataIteratorClosedMetrics();
    92         break;
    93     case 8:
    94         TestGlyphDataIteratorClosedGlyphCode();
    95         break;
    96     case 9:
    97         TestGlyphDataIteratorDiscardUsedFont();
    98         break;
    99     case 10:
   100         TestGlyphMetricsArrayIndexNegative();
   101         break;
   102     case 11:
   103     	TestGlyphMetricsArrayIndexTooHigh();
   104         break;
   105     case 12:
   106     	TestGlyphDataIteratorOpenFailed();
   107     	break;
   108     default:
   109         break;
   110         }
   111     TEST(EFalse); // shouldn't reach this point as the test will panic at the end of each test case function
   112     
   113     ((CTFbsGlyphDataPanicStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   114     ((CTFbsGlyphDataPanicStep*)iStep)->CloseTMSGraphicsStep();
   115     TestComplete();     
   116     ((CTFbsGlyphDataPanicStep*)iStep)->RecordTestResultL();
   117     }
   118 
   119 /**
   120 @SYMTestCaseID      GRAPHICS-FBSERV-0651
   121 @SYMTestPriority    High
   122 @SYMTestType        UT
   123 @SYMTestStatus      Implemented
   124 @SYMPREQ            PREQ2678
   125 
   126 @SYMTestCaseDesc
   127 	To ensure that calling Next() on an unopened iterator will panic.
   128 
   129 @SYMTestActions
   130 	Call Next() on an RFbsGlyphDataIterator instance without opening it.
   131 
   132 @SYMTestExpectedResults
   133 	The call to Next() should panic with FBSCLI 31.
   134 */
   135 void CTFbsGlyphDataPanic::TestGlyphDataIteratorNotInitializedNext()
   136     {
   137     INFO_PRINTF1(_L("Ensure that Next() operation applied on null iterator will panic"));
   138     ((CTFbsGlyphDataPanicStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0651"));
   139     RFbsGlyphDataIterator iter;
   140     iter.Next(); //expect to panic here
   141     }
   142 
   143 /**
   144 @SYMTestCaseID      GRAPHICS-FBSERV-0652
   145 @SYMTestPriority    High
   146 @SYMTestType        UT
   147 @SYMTestStatus      Implemented
   148 @SYMPREQ            PREQ2678
   149 
   150 @SYMTestCaseDesc
   151 	To ensure that Image() function applied on an unopened iterator will panic.
   152 
   153 @SYMTestActions
   154 	Call Image() on an RFbsGlyphDataIterator instance without opening it.
   155 
   156 @SYMTestExpectedResults
   157 	The call to Image() should panic with FBSCLI 31.
   158 */
   159 void CTFbsGlyphDataPanic::TestGlyphDataIteratorNotInitializedImage()
   160     {
   161     INFO_PRINTF1(_L("Ensure that Image() operation applied on null iterator will panic"));
   162     ((CTFbsGlyphDataPanicStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0652"));
   163     RFbsGlyphDataIterator iter;
   164     iter.Image(); //expect to panic here
   165     }
   166 
   167 /**
   168 @SYMTestCaseID      GRAPHICS-FBSERV-0653
   169 @SYMTestPriority    High
   170 @SYMTestType        UT
   171 @SYMTestStatus      Implemented
   172 @SYMPREQ            PREQ2678
   173 
   174 @SYMTestCaseDesc
   175 	To ensure that Metrics() function applied on null iterator will panic.
   176 
   177 @SYMTestActions
   178 	Call Metrics() on an RFbsGlyphDataIterator instance without opening it.
   179 
   180 @SYMTestExpectedResults
   181 	The call to Metrics() should panic with FBSCLI 31.
   182 */
   183 void CTFbsGlyphDataPanic::TestGlyphDataIteratorNotInitializedMetrics()
   184     {
   185     INFO_PRINTF1(_L("Ensure that Metrics() operation applied on null iterator will panic"));
   186     ((CTFbsGlyphDataPanicStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0653"));
   187     RFbsGlyphDataIterator iter;
   188     iter.Metrics(); //expect to panic here
   189     }
   190 
   191 /**
   192 @SYMTestCaseID      GRAPHICS-FBSERV-0654
   193 @SYMTestPriority    High
   194 @SYMTestType        UT
   195 @SYMTestStatus      Implemented
   196 @SYMPREQ            PREQ2678
   197 
   198 @SYMTestCaseDesc
   199 	To ensure that calling GlyphCode() on an unopened iterator will panic.
   200 
   201 @SYMTestActions
   202 	Call GlyphCode() on an RFbsGlyphDataIterator instance without opening it.
   203 
   204 @SYMTestExpectedResults
   205 	The call to GlyphCode() should panic with FBSCLI 31.
   206 */
   207 void CTFbsGlyphDataPanic::TestGlyphDataIteratorNotInitializedGlyphCode()
   208     {
   209     INFO_PRINTF1(_L("Ensure that GlyphCode() operation applied on null iterator will panic"));
   210     ((CTFbsGlyphDataPanicStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0654"));
   211     RFbsGlyphDataIterator iter;
   212     iter.GlyphCode(); //expect to panic here
   213     }
   214 
   215 /**
   216 @SYMTestCaseID      GRAPHICS-FBSERV-0655
   217 @SYMTestPriority    High
   218 @SYMTestType        UT
   219 @SYMTestStatus      Implemented
   220 @SYMPREQ            PREQ2678
   221 
   222 @SYMTestCaseDesc
   223 	To ensure that calling Next() on an iterator which has been closed will panic.
   224 
   225 @SYMTestActions
   226 	i. Open the glyph data iterator with 1 glyph code.
   227 	ii. Call Next() to attempt to move the iterator past the end of the array of glyph codes.
   228 	iii. Call Close() and repeat ii.
   229 
   230 @SYMTestExpectedResults
   231 	The call to Next() should fail with KErrNotFound, signifying the iterator is still open.
   232 	The final call to Next() should panic with FBSCLI 31.
   233 */
   234 void CTFbsGlyphDataPanic::TestGlyphDataIteratorClosedNext()
   235     {
   236     INFO_PRINTF1(_L("Ensure that Next() operation applied on iterator which has been closed will panic"));
   237     ((CTFbsGlyphDataPanicStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0655"));
   238     RFbsGlyphDataIterator iter;
   239     TESTNOERROR(iter.Open(*iFont, iGlyphCodes, 1));
   240     TInt iterErr = iter.Next();
   241     TESTE(iterErr == KErrNotFound, iterErr);
   242     iter.Close();
   243     iter.Next(); //expect to panic here
   244     }
   245 
   246 /**
   247 @SYMTestCaseID      GRAPHICS-FBSERV-0656
   248 @SYMTestPriority    High
   249 @SYMTestType        UT
   250 @SYMTestStatus      Implemented
   251 @SYMPREQ            PREQ2678
   252 
   253 @SYMTestCaseDesc
   254 	To ensure that calling Image() on an iterator which has been closed will panic.
   255 
   256 @SYMTestActions
   257 	i. Open the glyph data iterator.
   258 	ii. Close the glyph data iterator.
   259 	iii. Call Image() on an RFbsGlyphDataIterator instance which has been closed.
   260 
   261 @SYMTestExpectedResults
   262 	The call to Image() should panic with FBSCLI 31.
   263 */
   264 void CTFbsGlyphDataPanic::TestGlyphDataIteratorClosedImage()
   265     {
   266     INFO_PRINTF1(_L("Ensure that Image() operation applied on iterator which has been closed will panic"));
   267     ((CTFbsGlyphDataPanicStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0656"));
   268     RFbsGlyphDataIterator iter;
   269     OpenAndCloseIterator(iter);
   270     iter.Image(); //expect to panic here
   271     }
   272 
   273 /**
   274 @SYMTestCaseID      GRAPHICS-FBSERV-0657
   275 @SYMTestPriority    High
   276 @SYMTestType        UT
   277 @SYMTestStatus      Implemented
   278 @SYMPREQ            PREQ2678
   279 
   280 @SYMTestCaseDesc
   281 	To ensure that calling Metrics() on an iterator which has been closed will panic.
   282 
   283 @SYMTestActions
   284 	i. Open the glyph data iterator.
   285 	ii. Close the glyph data iterator.
   286 	iii. Call Metrics() on an RFbsGlyphDataIterator instance which has been closed.
   287 
   288 @SYMTestExpectedResults
   289 	The call to Metrics() should panic with FBSCLI 31.
   290 */
   291 void CTFbsGlyphDataPanic::TestGlyphDataIteratorClosedMetrics()
   292     {
   293     INFO_PRINTF1(_L("Ensure that Metrics()operation applied on iterator which has been closed will panic"));
   294     ((CTFbsGlyphDataPanicStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0657"));
   295     RFbsGlyphDataIterator iter;
   296     OpenAndCloseIterator(iter);
   297     iter.Metrics(); //expect to panic here
   298     }
   299 
   300 /**
   301 @SYMTestCaseID      GRAPHICS-FBSERV-0658
   302 @SYMTestPriority    High
   303 @SYMTestType        UT
   304 @SYMTestStatus      In development
   305 @SYMPREQ            PREQ2678
   306 
   307 @SYMTestCaseDesc
   308 	To ensure that calling GlyphCode() on an iterator which has been closed will panic.
   309 
   310 @SYMTestActions
   311 	i. Open the glyph data iterator.
   312 	ii. Close the glyph data iterator.
   313 	iii. Call GlyphCode() on an RFbsGlyphDataIterator instance which has been closed.
   314 
   315 @SYMTestExpectedResults
   316 	The call to GlyphCode() should panic with FBSCLI 31.
   317 */
   318 void CTFbsGlyphDataPanic::TestGlyphDataIteratorClosedGlyphCode()
   319     {
   320     INFO_PRINTF1(_L("Ensure that GlyphCode() operation applied on iterator which has been closed will panic"));
   321     ((CTFbsGlyphDataPanicStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0658"));
   322     RFbsGlyphDataIterator iter;
   323     OpenAndCloseIterator(iter);
   324     iter.GlyphCode(); //expect to panic here
   325     }
   326 
   327 // the function opens and then closes an iterator
   328 void CTFbsGlyphDataPanic::OpenAndCloseIterator(RFbsGlyphDataIterator& aIterator) 
   329     {
   330     TESTNOERROR(aIterator.Open(*iFont, iGlyphCodes, 1));
   331     aIterator.Close();
   332     }
   333 
   334 /**
   335 @SYMTestCaseID      GRAPHICS-FBSERV-0647
   336 @SYMTestPriority    High
   337 @SYMTestType        UT
   338 @SYMTestStatus      Implemented
   339 @SYMPREQ            PREQ2678
   340 
   341 @SYMTestCaseDesc
   342 	To ensure that attempting to use an invalid Font handle will cause a panic when iterating through an RFbsGlyphDataIterator. 
   343 
   344 @SYMTestActions
   345 	i. Open the glyph data iterator.
   346 	ii. Release the font associated with the iterator.
   347 	iii. Attempt to use invalid Font handle by iterating through the iterator.
   348 
   349 @SYMTestExpectedResults
   350 	The call to Next() after the associated Font has been released should cause panic FBSERV -8 when the invalid Font handle is passed to FBServ.
   351 */
   352 void CTFbsGlyphDataPanic::TestGlyphDataIteratorDiscardUsedFont()
   353     {
   354     INFO_PRINTF1(_L("Ensure that attempting to use an invalid Font handle will cause a panic when iterating through an RFbsGlyphDataIterator"));
   355     ((CTFbsGlyphDataPanicStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0647"));
   356     
   357     RFbsGlyphDataIterator iter;
   358     TESTNOERROR(iter.Open(*iFont, iGlyphCodes, KNumGlyphCodes));
   359     iTs->ReleaseFont(iFont);
   360     
   361     for (TInt i = 0; i < KNumGlyphCodes; i++)
   362         {
   363         //should panic when attempt is made to use invalid Font handle
   364         iter.Next();
   365         }
   366 
   367     iter.Close(); //shouldn't reach this line. If for some reason the code doesn't panic test should fail.
   368     TEST(EFalse);  
   369     }
   370     
   371 
   372 /**
   373 @SYMTestCaseID      GRAPHICS-FBSERV-0648
   374 @SYMTestPriority    High
   375 @SYMTestType        UT
   376 @SYMTestStatus      Implemented
   377 @SYMPREQ            PREQ2678
   378 
   379 @SYMTestCaseDesc
   380 	To ensure that accessing the glyph metrics entry with negative index will cause a panic.
   381 
   382 @SYMTestActions
   383 	i. Retrieve glyph metrics array.
   384 	ii. Try to access glyph metrics entry with a negative index.
   385 
   386 @SYMTestExpectedResults
   387 	Should panic with FBSCLI 32.
   388 */
   389 void CTFbsGlyphDataPanic::TestGlyphMetricsArrayIndexNegative()
   390     {
   391     INFO_PRINTF1(_L("Ensure that accessing the glyph metrics entry with negative index will cause a panic"));
   392     ((CTFbsGlyphDataPanicStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0648"));
   393     RFbsGlyphMetricsArray glyphMetricsArray;
   394 
   395     // Retrieve list of metrics
   396     TESTNOERROR(glyphMetricsArray.Get(*iFont, iGlyphCodes, 2));
   397     TEST(2 == glyphMetricsArray.Count());
   398     glyphMetricsArray[-1];
   399     }
   400 
   401 /**
   402 @SYMTestCaseID      GRAPHICS-FBSERV-0649
   403 @SYMTestPriority    High
   404 @SYMTestType        UT
   405 @SYMTestStatus      Implemented
   406 @SYMPREQ            PREQ2678
   407 
   408 @SYMTestCaseDesc
   409 	To ensure that accessing the glyph metrics entry with an index greater than number
   410 	of elements in array will cause a panic.
   411 
   412 @SYMTestActions
   413 	i. Retrieve a glyph metrics array with total number of elements equals 2 
   414 	ii. Try to access glyph metrics entry with index equals 2.
   415 
   416 @SYMTestExpectedResults
   417 	Should panic with FBSCLI 32.
   418 */
   419 void CTFbsGlyphDataPanic::TestGlyphMetricsArrayIndexTooHigh()
   420     {
   421     INFO_PRINTF1(_L("Ensure that accessing the glyph metrics entry with index greater than number of elemnets in array will cause a panic"));
   422     ((CTFbsGlyphDataPanicStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0649"));
   423     RFbsGlyphMetricsArray glyphMetricsArray;
   424 
   425     // Retrieve list of metrics
   426     TESTNOERROR(glyphMetricsArray.Get(*iFont, iGlyphCodes, 2));
   427     TEST(2 == glyphMetricsArray.Count());
   428     glyphMetricsArray[2]; //expect to panic here as index varies 0..1
   429     }
   430 
   431 /**
   432 @SYMTestCaseID      GRAPHICS-FBSERV-0667
   433 @SYMTestPriority    High
   434 @SYMTestType        UT
   435 @SYMTestStatus      Implemented
   436 @SYMPREQ            PREQ2678
   437 
   438 @SYMTestCaseDesc
   439 	To ensure that if RFbsGlyphDataIterator::Open() fails, it is still in the closed state
   440 	and cannot be used.
   441 
   442 @SYMTestActions
   443 	i. Open an RFbsGlyphDataIterator on a font.  
   444 	ii. Attempt to open a second RFbsGlyphDataIterator on the same font.
   445 	ii. Attempt to use the properties of the iterator.
   446 
   447 @SYMTestExpectedResults
   448 	The call to GlyphCode() should panic with FBSCLI 31 since the iterator should be in a closed state.
   449 */
   450 void CTFbsGlyphDataPanic::TestGlyphDataIteratorOpenFailed()
   451 	{
   452     INFO_PRINTF1(_L("Ensure that if RFbsGlyphDataIterator::Open() fails, it is still in the closed state and cannot be used"));
   453     ((CTFbsGlyphDataPanicStep*)iStep)->SetTestStepID(_L("GRAPHICS-FBSERV-0667"));
   454    
   455     CFbsFont* bitmapFont = NULL;
   456     TInt err = iTs->GetNearestFontToDesignHeightInPixels((CFont*&)bitmapFont, TFontSpec(_L("Digital"), 14));
   457     TESTNOERROR(err);
   458     TEST(!bitmapFont->IsOpenFont());
   459     
   460     RFbsGlyphDataIterator iter;
   461     err = iter.Open(*bitmapFont, iGlyphCodes, 2);
   462     TEST(err == KErrNotSupported);
   463         
   464     iter.GlyphCode(); // Should panic here as iter should be closed.
   465     TEST(EFalse);     //shouldn't reach this line. If for some reason the code doesn't panic test should fail.
   466     
   467 	}
   468 //--------------
   469 __CONSTRUCT_STEP__(FbsGlyphDataPanic)
   470