mmmw_plat/openmax_al_api/tsrc/openmaxaltestmodule/src/metadata/openmaxalmetadataextractionitftests.cpp
changeset 16 43d09473c595
equal deleted inserted replaced
14:80975da52420 16:43d09473c595
       
     1 /*
       
     2 * Copyright (c) 2009 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: This file contains testclass implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 // [INCLUDE FILES] - do not remove
       
    19 #include <e32svr.h>
       
    20 #include <StifParser.h>
       
    21 #include <StifTestInterface.h>
       
    22 #include "openmaxaltestmodule.h"
       
    23 
       
    24 #include <stdlib.h>
       
    25 #include <string.h>
       
    26 
       
    27 // EXTERNAL DATA STRUCTURES
       
    28 //extern  ?external_data;
       
    29 
       
    30 // EXTERNAL FUNCTION PROTOTYPES  
       
    31 //extern ?external_function( ?arg_type,?arg_type );
       
    32 
       
    33 // CONSTANTS
       
    34 //const ?type ?constant_var = ?constant;
       
    35 
       
    36 // MACROS
       
    37 //#define ?macro ?macro_def
       
    38 
       
    39 // LOCAL CONSTANTS AND MACROS
       
    40 //const ?type ?constant_var = ?constant;
       
    41 //#define ?macro_name ?macro_def
       
    42 
       
    43 // MODULE DATA STRUCTURES
       
    44 //enum ?declaration
       
    45 //typedef ?declaration
       
    46 
       
    47 // LOCAL FUNCTION PROTOTYPES
       
    48 //?type ?function_name( ?arg_type, ?arg_type );
       
    49 
       
    50 // FORWARD DECLARATIONS
       
    51 //class ?FORWARD_CLASSNAME;
       
    52 
       
    53 // ============================= LOCAL FUNCTIONS ===============================
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // ?function_name ?description.
       
    57 // ?description
       
    58 // Returns: ?value_1: ?description
       
    59 //          ?value_n: ?description_line1
       
    60 //                    ?description_line2
       
    61 // -----------------------------------------------------------------------------
       
    62 //
       
    63 /*
       
    64 ?type ?function_name(
       
    65     ?arg_type arg,  // ?description
       
    66     ?arg_type arg)  // ?description
       
    67     {
       
    68 
       
    69     ?code  // ?comment
       
    70 
       
    71     // ?comment
       
    72     ?code
       
    73     }
       
    74 */
       
    75 
       
    76 TInt COpenMAXALTestModule::al_metadataextractionitf_GetItemCount( CStifItemParser& aItem )
       
    77 {
       
    78     iLog->Log( _L("al_metadataextractionitf_GetItemCount >>") );
       
    79     
       
    80     TInt status(KErrNotFound);
       
    81     XAresult res;
       
    82     XAuint32 numItems = 0;
       
    83     if(m_MetadataExtractionItf)
       
    84     {
       
    85         res = (*m_MetadataExtractionItf)->GetItemCount(
       
    86                  m_MetadataExtractionItf, &numItems);              
       
    87         status = MapErr(res);
       
    88             
       
    89         TInt expectedNum = 0;
       
    90         if(aItem.GetNextInt(expectedNum) == KErrNone)
       
    91         {				
       
    92 			if((status==KErrNone) && (expectedNum != numItems))
       
    93 			{
       
    94                 status = KErrGeneral;
       
    95 			}
       
    96 		}
       
    97 			
       
    98 		iLog->Log( _L("The number of Metadata Items:%d Expected: %d"), numItems, expectedNum );
       
    99   }
       
   100 	
       
   101   iLog->Log( _L("al_metadataextractionitf_GetItemCount (%d) <<"), status );
       
   102   return status;
       
   103 }
       
   104 
       
   105 TInt COpenMAXALTestModule::al_metadataextractionitf_GetKeySize( CStifItemParser& aItem )
       
   106 {
       
   107     iLog->Log( _L("al_metadataextractionitf_GetKeySize >>") );
       
   108     
       
   109     TInt status(KErrNotFound);
       
   110     XAresult res;
       
   111     XAuint32 keySize = 0;
       
   112     if(m_MetadataExtractionItf)
       
   113     {
       
   114         TInt index;
       
   115         if(aItem.GetNextInt(index) == KErrNone)
       
   116         {
       
   117             res     = (*m_MetadataExtractionItf)->GetKeySize(
       
   118                         m_MetadataExtractionItf, index, &keySize);              
       
   119             status  = MapErr(res);
       
   120   			
       
   121             TInt expectedSize = 0;
       
   122             if(aItem.GetNextInt(expectedSize) == KErrNone)
       
   123 			{	      
       
   124                 if((status==KErrNone) && (expectedSize != keySize))
       
   125                 {
       
   126                     status = KErrNotFound;
       
   127                 }
       
   128 			}
       
   129 			iLog->Log( _L("KeySize[%d]: %d Expected Size:%d"), index, keySize, expectedSize);				
       
   130 		}
       
   131 	}
       
   132 	
       
   133 	iLog->Log( _L("al_metadataextractionitf_GetKeySize (%d) <<"), status );
       
   134   return status;
       
   135 }
       
   136 
       
   137 TInt COpenMAXALTestModule::al_metadataextractionitf_GetKey( CStifItemParser& aItem )
       
   138 {
       
   139     iLog->Log( _L("al_metadataextractionitf_GetKey >>") );
       
   140     
       
   141     TInt status(KErrNotFound);
       
   142     XAresult res;
       
   143     XAMetadataInfo *key = NULL;
       
   144     
       
   145     if(m_MetadataExtractionItf)
       
   146     {
       
   147         TPtrC keyToFind;
       
   148         if(aItem.GetNextString(keyToFind) == KErrNone)
       
   149         {
       
   150             HBufC *pB = HBufC16::NewL(keyToFind.Size());
       
   151             TPtr tP = pB->Des();
       
   152             tP.Copy(keyToFind);
       
   153             iLog->Log( _L("Expected Key: %S"), pB);
       
   154             delete pB;
       
   155   		
       
   156             XAuint32 numItems = 0;
       
   157             res = (*m_MetadataExtractionItf)->GetItemCount(m_MetadataExtractionItf, &numItems);              
       
   158 
       
   159             for(int i = 0; (i < numItems) && (MapErr(res) == KErrNone) && (status == KErrNotFound); i++)
       
   160             {
       
   161                 XAuint32 keySize = 0;
       
   162                 res = (*m_MetadataExtractionItf)->GetKeySize(
       
   163                        m_MetadataExtractionItf, i, &keySize);  
       
   164       
       
   165                 if(MapErr(res) == KErrNone)
       
   166                 {
       
   167                     key = (XAMetadataInfo *)calloc(keySize,1);
       
   168                     if(key)
       
   169                     {
       
   170                         res = (*m_MetadataExtractionItf)->GetKey(
       
   171                                         m_MetadataExtractionItf, i , keySize, key);              
       
   172                         status = MapErr(res);
       
   173                         if(status==KErrNone)
       
   174                         {
       
   175                             HBufC*   temp  = NULL;
       
   176                             if(key->encoding == XA_CHARACTERENCODING_ASCII)
       
   177                             {
       
   178                                 TPtrC8 des((TUint8*)(key->data), key->size-1 );
       
   179                                 temp = HBufC16::NewL(key->size-1);
       
   180                                 TPtr tempPtr = temp->Des();
       
   181                                 tempPtr.Copy(des);                        
       
   182                                 iLog->Log( _L("Key[%d]: %S"), i, temp);
       
   183 							}
       
   184 							else if(key->encoding == XA_CHARACTERENCODING_UTF16LE)
       
   185 							{
       
   186                                 TPtrC des((const TUint16*)key->data, key->size/2 - 1);
       
   187                                 temp = HBufC16::NewL(key->size/2 - 1);
       
   188                                 TPtr tempPtr = temp->Des();
       
   189                                 tempPtr.Copy(des);                        
       
   190                                 iLog->Log( _L("Key[%d]: %S"), i, temp);
       
   191 							}
       
   192 									
       
   193 							if(temp && !keyToFind.Compare(temp->Des()))
       
   194 							{
       
   195 								status = KErrNone;
       
   196 							}
       
   197 							else
       
   198 							{
       
   199 								status = KErrNotFound;
       
   200 							}
       
   201 							
       
   202 							if(temp)
       
   203 							{
       
   204 								delete temp;
       
   205 							}
       
   206 						}//end if(status==KErrNone)
       
   207 						
       
   208 						free(key);
       
   209                     }//end if(key)
       
   210                 }//end if(MapErr(res) == KErrNone)
       
   211             }//end for
       
   212         }//end if(aItem.GetNextString(index) == KErrNone)
       
   213     }//end if(m_MetadataExtractionItf)
       
   214         
       
   215     iLog->Log( _L("al_metadataextractionitf_GetKey (%d)<<"), status );
       
   216     return status;
       
   217 }
       
   218 
       
   219 
       
   220 TInt COpenMAXALTestModule::al_metadataextractionitf_GetValueSize( CStifItemParser& aItem )
       
   221 {
       
   222     iLog->Log( _L("al_metadataextractionitf_GetValueSize >>") );
       
   223     
       
   224     TInt status(KErrNotFound);
       
   225     XAresult res;
       
   226     XAuint32 valueSize = 0;
       
   227     if(m_MetadataExtractionItf)
       
   228     {
       
   229         TInt index;
       
   230         if(aItem.GetNextInt(index) == KErrNone)
       
   231         {
       
   232             res     = (*m_MetadataExtractionItf)->GetValueSize(
       
   233                             m_MetadataExtractionItf, index, &valueSize);              
       
   234             status  = MapErr(res);
       
   235 			iLog->Log( _L("ValueSize[%d]: %d"), index, valueSize);
       
   236         }
       
   237     }
       
   238    
       
   239    iLog->Log( _L("al_metadataextractionitf_GetValueSize (%d) <<"), status );
       
   240    return status;
       
   241 }
       
   242 
       
   243 
       
   244 
       
   245 TInt COpenMAXALTestModule::al_metadataextractionitf_GetValue( CStifItemParser& aItem )
       
   246 {
       
   247     iLog->Log( _L("al_metadataextractionitf_GetValue >>") );
       
   248     
       
   249     TInt status(KErrNotFound);
       
   250     XAresult res;
       
   251     
       
   252     XAMetadataInfo *key = NULL;
       
   253     
       
   254     if(m_MetadataExtractionItf)
       
   255     {
       
   256         TInt index;
       
   257         
       
   258         //Find Key Index
       
   259         TPtrC keyToFind;
       
   260         if(aItem.GetNextString(keyToFind) == KErrNone)
       
   261         {
       
   262             HBufC *pB = HBufC16::NewL(keyToFind.Size());
       
   263             TPtr tP = pB->Des();
       
   264             tP.Copy(keyToFind);
       
   265             iLog->Log( _L("Expected Key: %S"), pB);
       
   266             delete pB;
       
   267             
       
   268             XAuint32 numItems = 0;
       
   269             res = (*m_MetadataExtractionItf)->GetItemCount(m_MetadataExtractionItf, &numItems);              
       
   270     
       
   271             for(index = 0; (index < numItems) && (MapErr(res) == KErrNone) && (status == KErrNotFound); index++)
       
   272             {
       
   273                 XAuint32 keySize = 0;
       
   274                 res = (*m_MetadataExtractionItf)->GetKeySize(
       
   275                        m_MetadataExtractionItf, index, &keySize);  
       
   276           
       
   277                 if(MapErr(res) == KErrNone)
       
   278                 {
       
   279                     key = (XAMetadataInfo *)calloc(keySize,1);
       
   280                     if(key)
       
   281                     {
       
   282                         res = (*m_MetadataExtractionItf)->GetKey(
       
   283                                         m_MetadataExtractionItf, index , keySize, key);              
       
   284                         status = MapErr(res);
       
   285                         if(status==KErrNone)
       
   286                         {
       
   287                             HBufC*   temp  = NULL;
       
   288                             TDesC16* pdesc = NULL;
       
   289                                     
       
   290                             if(key->encoding == XA_CHARACTERENCODING_ASCII)
       
   291                             {
       
   292                                 TPtrC8 des((TUint8*)(key->data), key->size - 1 );
       
   293                                 temp = HBufC16::NewL(key->size - 1);
       
   294                                 TPtr tempPtr = temp->Des();
       
   295                                 tempPtr.Copy(des);                        
       
   296                                 iLog->Log( _L("Key[%d]: %S"), index, temp);
       
   297                                 pdesc = &tempPtr;
       
   298                             }
       
   299                             else if(key->encoding == XA_CHARACTERENCODING_UTF16LE)
       
   300                             {
       
   301                                 TPtrC des((const TUint16*)key->data, key->size/2 - 1);
       
   302                                 temp = HBufC16::NewL(key->size/2 - 1);
       
   303                                 TPtr tempPtr = temp->Des();
       
   304                                 tempPtr.Copy(des);                        
       
   305                                 iLog->Log( _L("Key[%d]: %S"), index, temp);
       
   306                                 pdesc = &tempPtr;
       
   307                             }
       
   308                                         
       
   309                             if(!keyToFind.Compare(*pdesc))
       
   310                             {
       
   311                                 status = KErrNone;
       
   312                             }
       
   313                             else
       
   314                             {
       
   315                                 status = KErrNotFound;
       
   316                             }
       
   317                             
       
   318                             if(temp)
       
   319                             {
       
   320                                 delete temp;
       
   321                             }
       
   322                         }//end if(status==KErrNone)
       
   323                             
       
   324                         free(key);
       
   325                     }//end if(key)
       
   326                 }//end if(MapErr(res) == KErrNone)
       
   327             }//end for
       
   328         }//end if(aItem.GetNextString(index) == KErrNone)
       
   329             
       
   330         if((status == KErrNone) && (--index >= 0))
       
   331         {
       
   332             XAMetadataInfo *value = NULL;
       
   333             XAuint32 valueSize;
       
   334         
       
   335             res = (*m_MetadataExtractionItf)->GetValueSize(
       
   336                                    m_MetadataExtractionItf, index, &valueSize);  
       
   337                 
       
   338             if(MapErr(res) == KErrNone)
       
   339             {
       
   340                 value = (XAMetadataInfo *)calloc(valueSize,1);
       
   341                 if(value)
       
   342                 {
       
   343                     res = (*m_MetadataExtractionItf)->GetValue(
       
   344                             m_MetadataExtractionItf, index, valueSize, value);              
       
   345                     status = MapErr(res);
       
   346 
       
   347                     HBufC*   temp  = NULL;
       
   348                     if(status == KErrNone)
       
   349                     {
       
   350                         if(value->encoding == XA_CHARACTERENCODING_ASCII)
       
   351                         {
       
   352                             TPtrC8 des((TUint8*)(value->data), value->size - 1 );
       
   353                             temp = HBufC16::NewL(value->size - 1);
       
   354                             TPtr tempPtr = temp->Des();
       
   355                             tempPtr.Copy(des);
       
   356                             iLog->Log( _L("Value[%d]: %S"), index, temp);
       
   357                         }
       
   358                         else if(value->encoding == XA_CHARACTERENCODING_UTF16LE)
       
   359                         {
       
   360                             TPtrC des((const TUint16*)value->data, value->size/2 - 1);
       
   361                             temp = HBufC16::NewL(value->size/2 - 1);
       
   362                             TPtr tempPtr = temp->Des();
       
   363                             tempPtr.Copy(des);
       
   364                             iLog->Log( _L("Value[%d]: %S"), index, temp);
       
   365                        }
       
   366                         else
       
   367                         {
       
   368                             iLog->Log( _L("Value[%d]: <Binary Value>"), index);
       
   369                         }					
       
   370 
       
   371                         if(value->encoding != XA_CHARACTERENCODING_BINARY)
       
   372                         {            
       
   373                             TPtrC expectedValue;
       
   374                             if(aItem.GetNextString(expectedValue) == KErrNone)
       
   375                             {            
       
   376                                 HBufC *pB = HBufC16::NewL(expectedValue.Size());
       
   377                                 TPtr tP = pB->Des();
       
   378                                 tP.Copy(expectedValue);
       
   379                                 iLog->Log( _L("Expected Value: %S"), pB);
       
   380 								iLog->Log(_L("Size: Expected(%d), Actual(%d)"),expectedValue.Size(), temp->Des().Size());
       
   381                                 delete pB;
       
   382                                 if(temp && !expectedValue.Compare(temp->Des()))
       
   383                                 {
       
   384                                     status = KErrNone;
       
   385                                 }
       
   386                                 else
       
   387                                 {
       
   388                                     status = KErrNotFound;
       
   389                                 }
       
   390                             }
       
   391                         }
       
   392                                
       
   393                         if(temp)
       
   394                         {
       
   395                             delete temp;
       
   396                         }
       
   397                     }//end if(status == KErrNone)
       
   398                     delete value;
       
   399                 }//end if(value)
       
   400             }//end if(MapErr(res) == KErrNone)
       
   401         }//end if(status == KErrNone)   
       
   402     }//end   if(m_MetadataExtractionItf)
       
   403 	
       
   404     iLog->Log( _L("al_metadataextractionitf_GetValue (%d)<<"), status );
       
   405     return status;
       
   406 }
       
   407 
       
   408 TInt COpenMAXALTestModule::al_metadataextractionitf_AddKeyFilter( CStifItemParser& /*aItem */)
       
   409 {
       
   410     iLog->Log( _L("al_metadataextractionitf_AddKeyFilter >>") );
       
   411     TInt status(KErrNotFound);
       
   412     if(m_MetadataExtractionItf)
       
   413     {
       
   414 		XAresult res = (*m_MetadataExtractionItf)->AddKeyFilter(m_MetadataExtractionItf,
       
   415 			        		                                       0, NULL, 0, NULL, 0, 0);
       
   416 		status = res;
       
   417     }
       
   418 
       
   419 	iLog->Log( _L("al_metadataextractionitf_AddKeyFilter (%d)<<"), status );	
       
   420 
       
   421 	return status;
       
   422 }
       
   423 
       
   424 TInt COpenMAXALTestModule::al_metadataextractionitf_ClearKeyFilter( CStifItemParser& /*aItem*/ )
       
   425 {
       
   426     iLog->Log( _L("al_metadataextractionitf_ClearKeyFilter >>") );
       
   427     TInt status(KErrNotFound);
       
   428     if(m_MetadataExtractionItf)
       
   429     {
       
   430 	    XAresult res    = (*m_MetadataExtractionItf)->ClearKeyFilter(m_MetadataExtractionItf);
       
   431 
       
   432 		status = res;
       
   433     }
       
   434 
       
   435 	iLog->Log( _L("al_metadataextractionitf_ClearKeyFilter (%d)<<"), status );
       
   436 
       
   437 	return status;
       
   438 }
       
   439 
       
   440 TInt COpenMAXALTestModule::al_metadataextractionitf_GetCoverArt( CStifItemParser& /*aItem*/ )
       
   441 {
       
   442     iLog->Log( _L("al_metadataextractionitf_GetCoverArt >>") );
       
   443 
       
   444     TInt status(KErrNotFound);
       
   445     XAresult res;
       
   446     
       
   447     if(m_MetadataExtractionItf)
       
   448     {
       
   449         XAuint32 numItems = 0;
       
   450         res = (*m_MetadataExtractionItf)->GetItemCount(
       
   451                     m_MetadataExtractionItf, &numItems);              
       
   452 
       
   453         for(int i = 0; (i < numItems) && (MapErr(res) == KErrNone) ; i++)
       
   454         {
       
   455             XAuint32 keySize = 0;
       
   456             res = (*m_MetadataExtractionItf)->GetKeySize(
       
   457                         m_MetadataExtractionItf, i, &keySize);  
       
   458                      
       
   459             if(MapErr(res) == KErrNone)
       
   460             {
       
   461                 XAMetadataInfo* key = (XAMetadataInfo *)calloc(keySize,1);
       
   462                 if(key)
       
   463                 {
       
   464                     res = (*m_MetadataExtractionItf)->GetKey(
       
   465                              m_MetadataExtractionItf, i, keySize, key);              
       
   466 
       
   467                     if(MapErr(res) == KErrNone)
       
   468                     {
       
   469                         if( key->encoding == XA_CHARACTERENCODING_ASCII)
       
   470                         {
       
   471                             if(!strcmp((const char*)key->data, "attachedpicture"))
       
   472                             {
       
   473                                 XAuint32 valueSize;
       
   474                                 res = (*m_MetadataExtractionItf)->GetValueSize(
       
   475                                               m_MetadataExtractionItf, i, &valueSize);  
       
   476                                 if(MapErr(res) == KErrNone)
       
   477                                 {
       
   478                                     XAMetadataInfo* value = (XAMetadataInfo *)calloc(valueSize,1);
       
   479                                     if(value)
       
   480                                     {
       
   481                                         res = (*m_MetadataExtractionItf)->GetValue(
       
   482                                                 m_MetadataExtractionItf, i, valueSize, value);              
       
   483                                         if((MapErr(res) == KErrNone) && 
       
   484                                            (value->encoding == XA_CHARACTERENCODING_BINARY))
       
   485                                         {
       
   486                                             iLog->Log( _L("CoverArt[%d] Size: %d"), i, value->size );
       
   487                                         }
       
   488                                         free(value);
       
   489                                     }
       
   490                                 
       
   491                                     break;
       
   492                                 }
       
   493                             }            
       
   494                         }
       
   495                         free(key);
       
   496                     }
       
   497                 }
       
   498              }
       
   499         }// end for
       
   500         
       
   501         status = MapErr(res);
       
   502     }//end if(m_MetadataExtractionItf)
       
   503     
       
   504     return status;
       
   505 }