graphicsresourceservices/graphicsresourceimplementation/test/src/tsggenericmanual.cpp
changeset 36 01a6848ebfd7
child 103 2717213c588a
equal deleted inserted replaced
0:5d03bc08d59c 36:01a6848ebfd7
       
     1 // Copyright (c) 2007-2009 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 // Tests for manual execution.
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Graphics Resource API Conformance Test Suite
       
    20 */
       
    21 
       
    22 #include "tsggenericmanual.h"
       
    23 
       
    24 CTSgGenericManual::CTSgGenericManual(TBool aConformanceTests) :
       
    25 	CTSgTestStepBase(aConformanceTests)
       
    26 	{
       
    27 	INFO_PRINTF1(_L("Graphics resource component test - Generic Manual Tests.\r\n"));
       
    28 	}
       
    29 
       
    30 CTSgGenericManual::~CTSgGenericManual()
       
    31 	{
       
    32 	}
       
    33 
       
    34 /**
       
    35 This is intented to be used for TestStressResourceLeakL (GRAPHICS-RESOURCE-0050) test. 
       
    36 It creates images until the memory full situation. The images are kept in the passed RArray of RSgImage. 
       
    37 The returned error code is expected to be either KErrNoMemory or KErrNoGraphicsMemory.
       
    38 */
       
    39 TInt CTSgGenericManual::CreateImages(const TSgImageInfo& aInfo, RArray<RSgImage>& aTestImages)
       
    40     {
       
    41     TInt err = KErrNone;
       
    42     while(err == KErrNone)
       
    43         {
       
    44         RSgImage image;
       
    45         err = image.Create(aInfo);
       
    46         if(err == KErrNone)
       
    47             {
       
    48             err = aTestImages.Append(image);
       
    49             }
       
    50         }    
       
    51     return err;
       
    52     }
       
    53 
       
    54 void CTSgGenericManual::DestroyImages(RArray<RSgImage>& aTestImages)
       
    55     {
       
    56     TInt count = aTestImages.Count();
       
    57     for(TInt i=0; i<count; ++i)
       
    58         {
       
    59         aTestImages[i].Close();
       
    60         }   
       
    61     aTestImages.Reset();    
       
    62     }
       
    63 
       
    64 /** 
       
    65 @leave Gets system wide error code
       
    66 @return TVerdict code
       
    67 */
       
    68 TVerdict CTSgGenericManual::doTestStepL()
       
    69 	{	
       
    70     SetTestStepID(_L("GRAPHICS-RESOURCE-0050"));
       
    71     INFO_PRINTF1(_L("RSgImage generic resource leak stress test.\r\n"));
       
    72     TestStressResourceLeakL();
       
    73 	RecordTestResultL();
       
    74 	
       
    75 	return TestStepResult();
       
    76 	}
       
    77 
       
    78 /**
       
    79 @SYMTestCaseID          GRAPHICS-RESOURCE-0050
       
    80 @SYMTestCaseDesc        RSgImage exhaustive and resource leak test
       
    81 @SYMPREQ                PREQ2637
       
    82 @SYMFssID               RSgImage::Create(const TSgImageInfo&, const TAny*, TInt)
       
    83                         RSgImage::Close() 
       
    84 @SYMTestPriority        Medium
       
    85 @SYMTestType            CT
       
    86 @SYMTestPurpose         To ensure no resource leaks while creating and destroying RSgImage multiple times
       
    87 @SYMTestActions         Create images until it returns no memomy error. Close the created images and          
       
    88                         create as many images as possible until memory is full. Test the number of images
       
    89                         created and also for each iteration the number of images created to be the same.
       
    90 @SYMTestExpectedResults There should be no panics or leaves.
       
    91  */
       
    92 void CTSgGenericManual::TestStressResourceLeakL()
       
    93     {
       
    94     TestOpenDriverL();
       
    95     
       
    96     const TInt KNumIterations = 100000;
       
    97     TSgImageInfo info;
       
    98     info.iPixelFormat = EUidPixelFormatRGB_565;
       
    99     info.iSizeInPixels = TSize(1, 1);
       
   100     info.iUsage = ESgUsageBitOpenVgImage;
       
   101     
       
   102     RArray<RSgImage> testImages;    
       
   103     
       
   104     TInt count(0);
       
   105     TInt err = KErrNone;
       
   106     for(TInt i=0; i<KNumIterations && (err == KErrNone); ++i) 
       
   107         {
       
   108         err = CreateImages(info, testImages);
       
   109         TInt thisCount = testImages.Count();
       
   110         DestroyImages(testImages);
       
   111 
       
   112         if (err == KErrNoMemory || err == KErrNoGraphicsMemory)
       
   113         	{
       
   114         	err = KErrNone;
       
   115         	}
       
   116         else if (err != KErrNone)
       
   117         	{
       
   118         	ERR_PRINTF2(_L("Create images error [%d]"), err);
       
   119         	SetTestStepResult(EFail);
       
   120         	}
       
   121       
       
   122         if(i > 0 && count != thisCount)
       
   123             {
       
   124             ERR_PRINTF4(_L("Mismatch @ iteration %d : Was %d, now %d"), i,  count, thisCount);
       
   125             }        
       
   126         count = thisCount;
       
   127         }
       
   128     
       
   129     INFO_PRINTF2(_L("%d images created \r\n"), count);
       
   130     TestCloseDriver();
       
   131     }
       
   132