imagingandcamerafws/imaginginttest/src/TestImageDecoderDRM.cpp
changeset 0 40261b775718
child 41 f7bf1ed8db72
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     1 // Copyright (c) 2004-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 // Integration test.
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <testframework.h>
       
    19 
       
    20 #include "TestImageDecoderDRM.h"
       
    21 
       
    22 const TInt KMimeMaxLength = 256;
       
    23 
       
    24 _LIT(KJpegRefFile, "jfif444.mbm"); // Reference filename
       
    25 _LIT(KDefaultRightsUniqueId, "ICLTestjfif444Id001"); // Unique Id of the content
       
    26 
       
    27 // Positive Test
       
    28 
       
    29 /**
       
    30 *
       
    31 * Ctor for CTestImageDecDrmEnableAgentUI
       
    32 *
       
    33 * @param const TDesC& aTestName: Name of this test step used by the script file.
       
    34 *
       
    35 * @return CTestImageDecDrmEnableAgentUI*: 
       
    36 *                           Constructed CTestImageDecDrmEnableAgentUI object
       
    37 *
       
    38 */
       
    39 CTestImageDecDrmEnableAgentUI* CTestImageDecDrmEnableAgentUI::NewL(const TDesC& aTestName)
       
    40     {
       
    41     return new (ELeave) CTestImageDecDrmEnableAgentUI(aTestName);
       
    42     }
       
    43 
       
    44 /**
       
    45 *
       
    46 * Test step constructor.
       
    47 * Each test step initialises its own name.
       
    48 *
       
    49 * @param const TDesC& aTestName: Name of this test step.
       
    50 *
       
    51 */
       
    52 CTestImageDecDrmEnableAgentUI::CTestImageDecDrmEnableAgentUI(const TDesC& aTestName): 
       
    53     CTestStepConversion(aTestName)
       
    54     {
       
    55     iHeapSize = 500000;
       
    56     }
       
    57 
       
    58 /**
       
    59 *
       
    60 * Do the test step.
       
    61 * Each test step must supply an implementation for DoTestStepL.
       
    62 *
       
    63 * @return TVerdict: The result of the test step.
       
    64 *
       
    65 */
       
    66 TVerdict CTestImageDecDrmEnableAgentUI::DoTestStepL()
       
    67     {
       
    68     TVerdict result = EPass;
       
    69     if (iTestStepName.Compare(_L("MM-ICL-FRM-I-0761-HP")) == 0)
       
    70         {
       
    71         result = TestStep_I_0761L();
       
    72         }
       
    73 
       
    74     return result;
       
    75     }
       
    76 
       
    77 /**
       
    78 *
       
    79 * Test Step.
       
    80 *
       
    81 * @return TVerdict: The result of the test step.
       
    82 *
       
    83 */
       
    84 TVerdict CTestImageDecDrmEnableAgentUI::TestStep_I_0761L()
       
    85     {
       
    86     // Dummy Hal call for heap balance on target
       
    87     if (DummyHalCall() != KErrNone)
       
    88         {
       
    89         return EInconclusive;
       
    90         }
       
    91 
       
    92     __MM_HEAP_MARK;
       
    93 
       
    94     TInt err = KErrNone;
       
    95     err = RFbsSession::Connect();
       
    96     if (err != KErrNone)
       
    97         {
       
    98         INFO_PRINTF2(_L("RFbsSession::Connect() failed, err = %d"), err);
       
    99         return EInconclusive;
       
   100         }
       
   101 
       
   102     // Open and decode the image
       
   103     TRAP(err, OpenImageAndDecodeFromFileSourceL(iFileNameSrc, KDefaultRightsUniqueId, EView));
       
   104 
       
   105     RFbsSession::Disconnect();
       
   106     
       
   107     __MM_HEAP_MARKEND;
       
   108 
       
   109     if (err == KErrNone)
       
   110         {
       
   111         return EPass;
       
   112         }
       
   113     else
       
   114         {
       
   115         INFO_PRINTF2(_L("Error in opening/decoding the image : %d"), err);
       
   116         return EFail;
       
   117         }
       
   118     }
       
   119 
       
   120 /**
       
   121 *
       
   122 * Opens the image for 'the intent' and decodes.
       
   123 *
       
   124 * @param const TDesC& aFileName: Name of the data file.
       
   125 * @param const TDesC& aUniqueId: Unique Id of the content file.
       
   126 * @param ContentAccess::TIntent aIntent: Intent for opening the content file.
       
   127 *
       
   128 * @leave err: Leaves with 'err'.
       
   129 *
       
   130 */
       
   131 void CTestImageDecDrmEnableAgentUI::OpenImageAndDecodeFromFileSourceL(
       
   132     const TDesC& aFileName, 
       
   133     const TDesC& aUniqueId, 
       
   134     ContentAccess::TIntent aIntent)
       
   135     {
       
   136     // Get the path
       
   137     TFileName theSourceFilename;
       
   138     Directory(EInput, theSourceFilename);
       
   139     theSourceFilename.Append(aFileName);
       
   140 
       
   141     User::LeaveIfError(iFs.Connect());
       
   142 
       
   143     // Get the MIME type from ini file
       
   144     TBuf8<KMimeMaxLength> mimeType;
       
   145     ReadMimeTypeFromConfig(mimeType);
       
   146 
       
   147     INFO_PRINTF4(_L("Opening the file %S for intent %d, having Unique Id %S."), &theSourceFilename, aIntent, &aUniqueId);
       
   148     TMMFileSource fileSource(theSourceFilename, aUniqueId, aIntent);
       
   149 
       
   150     // Open the image and create an image decoder
       
   151     TInt err = KErrNone;
       
   152     CImageDecoder* imageDecoder = NULL;
       
   153     TRAP(err, imageDecoder = CImageDecoder::FileNewL(iFs, fileSource, mimeType));
       
   154 
       
   155     if (err != KErrNone)
       
   156         {
       
   157         INFO_PRINTF3(_L("Cannot open file: %S. Unexpected Error: %d"), &theSourceFilename, err);
       
   158         User::Leave(err);
       
   159         }
       
   160 
       
   161     if (imageDecoder == NULL)
       
   162         {
       
   163         INFO_PRINTF1(_L("ImageDecoder is NULL!"));
       
   164         User::Leave(err);
       
   165         }
       
   166     CleanupStack::PushL(imageDecoder);
       
   167 
       
   168     INFO_PRINTF4(_L("The file %S for intent %d, having Unique Id %S had been opened."), &theSourceFilename, aIntent, &aUniqueId);
       
   169 
       
   170     INFO_PRINTF1(_L("Enabling Agent's user interface for errors and confirmation requests."));
       
   171     err = imageDecoder->SetAgentProperty(EAgentPropertyAgentUI, 1);
       
   172 
       
   173     if (err != KErrNone)
       
   174         {
       
   175         INFO_PRINTF2(_L("SetAgentProperty(EAgentPropertyAgentUI, 1) failed with %d"), err);
       
   176         INFO_PRINTF1(_L("\tFailure is expected, as RTA does not support this feature."));
       
   177         INFO_PRINTF1(_L("\tContinue test."));
       
   178         }
       
   179 
       
   180     // Create an active listener and push it on the cleanup stack
       
   181     CActiveListener* activeListener = new (ELeave) CActiveListener;
       
   182     CleanupStack::PushL(activeListener);
       
   183 
       
   184     const TFrameInfo* theFrameInfo = &imageDecoder->FrameInfo();
       
   185 
       
   186     // Create the destination bitmap
       
   187     CFbsBitmap* destBitmap = new (ELeave) CFbsBitmap;
       
   188     CleanupStack::PushL(destBitmap);
       
   189 
       
   190     // Create the destination bitmap with the specified size and display mode
       
   191     User::LeaveIfError(destBitmap->Create(
       
   192         theFrameInfo->iOverallSizeInPixels,
       
   193         theFrameInfo->iFrameDisplayMode));
       
   194 
       
   195     activeListener ->InitialiseActiveListener();
       
   196 
       
   197     // Decode the image
       
   198     imageDecoder->Convert(&activeListener->iStatus, *destBitmap, 0);
       
   199     CActiveScheduler::Start();
       
   200 
       
   201     err = activeListener->iStatus.Int();
       
   202     if (err == KErrNone)
       
   203         {
       
   204         INFO_PRINTF4(_L("Conversion of file %S for intent %d, having Unique Id %S was successfull!"), &theSourceFilename, aIntent, &aUniqueId);
       
   205         }
       
   206     else
       
   207         {
       
   208         INFO_PRINTF2(_L("Failed during conversion of the file: %S"), &theSourceFilename);
       
   209 
       
   210         // imageDecoder, activeListener, destBitmap
       
   211         CleanupStack::PopAndDestroy(3, imageDecoder);
       
   212         User::Leave(err);
       
   213         }
       
   214 
       
   215     // Get the reference filename
       
   216     TFileName refFilename;
       
   217     TBuf<KLenBufferExtension> extension;
       
   218     Directory(EReference, refFilename);
       
   219     refFilename.Append(KJpegRefFile);
       
   220 
       
   221     if (err == KErrNone)
       
   222         {
       
   223         // Check the bitmaps
       
   224         INFO_PRINTF2(_L("Comparison of the decoded file having Unique Id: %S."), &aUniqueId);
       
   225         err = CheckBitmapL(*destBitmap, refFilename);
       
   226         }
       
   227 
       
   228     // imageDecoder, activeListener, destBitmap
       
   229     CleanupStack::PopAndDestroy(3, imageDecoder);
       
   230     User::Leave(err);
       
   231     }