graphicscomposition/openwfsupport/test/tstreamoperation/tnativestream.cpp
changeset 0 5d03bc08d59c
child 19 bbf46f59e123
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 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 // Implementation of Test class for OpenWfc Native Stream 
       
    15 // 
       
    16 //
       
    17 
       
    18 #include <graphics/symbianstream.h>
       
    19 #include <graphics/streammap.h>
       
    20 #include <graphics/compositionsurfaceupdate.h>
       
    21 #include <graphics/extensioncontainer.h>
       
    22 #include <graphics/suerror.h>
       
    23 #include <test/extendtef.h>
       
    24 #include <dispchannel.h>
       
    25 #include <hal.h>
       
    26 #include "tnativestream.h"
       
    27 #include "surfaceutility.h"
       
    28 #include "owftestexithelper.inl"
       
    29 
       
    30 #define BUFFER_READ_HANDLE_BASE  0x100
       
    31 #define BUFFER_WRITE_HANDLE_BASE 0x200
       
    32 #define INDEX_TO_READ_HANDLE(x)  ((SymbianStreamBuffer) ((x)+BUFFER_READ_HANDLE_BASE))
       
    33 #define INDEX_TO_WRITE_HANDLE(x)  ((SymbianStreamBuffer) ((x)+BUFFER_WRITE_HANDLE_BASE))
       
    34 #define BUFFER_READ_HANDLE_TO_INDEX(x)  (TInt) (x > 0 ? (x&0xFF) : (x-BUFFER_READ_HANDLE_BASE))
       
    35 #define BUFFER_WRITE_HANDLE_TO_INDEX(x)  (TInt) (x > 0 ? (x&0xFF) : (x-BUFFER_WRITE_HANDLE_BASE))
       
    36 #define WFC_INVALID_HANDLE NULL
       
    37 #define KGrowCleanupStack   12
       
    38 #define KCompositorVersion 0x01023456
       
    39 #define KCompositorVersionMajor 0x1
       
    40 #define KCompositorVersionMinor 0x2
       
    41 #define KCompositorVersionRevision 0x3456
       
    42 
       
    43 void PopHeap(void* aHeapPtr)
       
    44     {
       
    45     User::SwitchHeap((RHeap*)aHeapPtr);
       
    46     }
       
    47 
       
    48 void GrowCleanupStackL()
       
    49     {
       
    50     TInt n = KGrowCleanupStack;
       
    51     while(n--)
       
    52         {
       
    53         CleanupStack::PushL((CBase*)NULL);
       
    54         }
       
    55     CleanupStack::Pop(KGrowCleanupStack);
       
    56     }
       
    57 
       
    58 // Helper functions
       
    59 /* supported external image formats */
       
    60 enum OWF_PIXEL_FORMAT   {
       
    61     OWF_IMAGE_NOT_SUPPORTED = 0,
       
    62     OWF_IMAGE_ARGB8888      = 0x8888,
       
    63     OWF_IMAGE_XRGB8888      = 0xf888,
       
    64     OWF_IMAGE_RGB888        = 0x888,
       
    65     OWF_IMAGE_RGB565        = 0x565,
       
    66     OWF_IMAGE_L32           = 0xA32,
       
    67     OWF_IMAGE_L16           = 0xA16,
       
    68     OWF_IMAGE_L8            = 0xA8,
       
    69     OWF_IMAGE_L1            = 0xA1,
       
    70     OWF_IMAGE_ARGB_INTERNAL = 0x666 /* OWFpixel rep */
       
    71 } ;
       
    72 
       
    73 struct CTestNativeStream::OWF_IMAGE_FORMAT{
       
    74     OWF_PIXEL_FORMAT        pixelFormat;
       
    75     bool              linear;
       
    76     bool              premultiplied;
       
    77     int                  rowPadding; /* row alignment, in bytes */
       
    78 } ;
       
    79 
       
    80 TInt CTestNativeStream::BytesPerPixel(TUidPixelFormat aPixelFormat)
       
    81     {
       
    82     switch (aPixelFormat)
       
    83         {
       
    84         case EUidPixelFormatXRGB_8888:
       
    85         case EUidPixelFormatARGB_8888:
       
    86         case EUidPixelFormatBGRX_8888:
       
    87         case EUidPixelFormatXBGR_8888:
       
    88         case EUidPixelFormatBGRA_8888:
       
    89         case EUidPixelFormatABGR_8888:  
       
    90         case EUidPixelFormatABGR_8888_PRE:
       
    91         case EUidPixelFormatARGB_8888_PRE:
       
    92         case EUidPixelFormatBGRA_8888_PRE:
       
    93         case EUidPixelFormatARGB_2101010:
       
    94         case EUidPixelFormatABGR_2101010:
       
    95             return 4;
       
    96         case EUidPixelFormatBGR_888:
       
    97         case EUidPixelFormatRGB_888:
       
    98             return 3;
       
    99         case EUidPixelFormatXRGB_4444:
       
   100         case EUidPixelFormatARGB_4444:
       
   101         case EUidPixelFormatXBGR_4444:
       
   102         case EUidPixelFormatRGB_565:
       
   103         case EUidPixelFormatBGR_565:
       
   104         case EUidPixelFormatARGB_1555:
       
   105         case EUidPixelFormatXRGB_1555:
       
   106         case EUidPixelFormatARGB_8332:
       
   107         case EUidPixelFormatBGRX_5551:
       
   108         case EUidPixelFormatBGRA_5551:
       
   109         case EUidPixelFormatBGRA_4444:
       
   110         case EUidPixelFormatBGRX_4444:
       
   111         case EUidPixelFormatAP_88:
       
   112             return  2;
       
   113         case EUidPixelFormatRGB_332:
       
   114         case EUidPixelFormatBGR_332:
       
   115         case EUidPixelFormatA_8:
       
   116         case EUidPixelFormatL_8:
       
   117             return  1;
       
   118         case EUidPixelFormatP_8:
       
   119             return -1;
       
   120         case EUidPixelFormatP_4:
       
   121         case EUidPixelFormatL_4:
       
   122             return -2;
       
   123         case EUidPixelFormatL_2:
       
   124         case EUidPixelFormatP_2:
       
   125             return -4;
       
   126         case EUidPixelFormatL_1 :
       
   127             return -8;
       
   128         default:
       
   129             {
       
   130             return 0;
       
   131             }
       
   132         }
       
   133     }
       
   134 
       
   135 /*****************************************
       
   136  * Helper Creates Surface from OWF spec 
       
   137  * 
       
   138  *
       
   139  */
       
   140 TSurfaceId CTestNativeStream::helperCreateSurfaceL(khronos_int32_t width,
       
   141         khronos_int32_t height,
       
   142         const OWF_IMAGE_FORMAT*   format,
       
   143         khronos_int32_t nbufs,
       
   144         TUidPixelFormat overridePixelFormat)
       
   145 	{
       
   146 	RSurfaceManager::TSurfaceCreationAttributesBuf bf;
       
   147 	RSurfaceManager::TSurfaceCreationAttributes& b = bf();
       
   148 	
       
   149 	TBool premultiplied = format->premultiplied;
       
   150 	OWF_PIXEL_FORMAT pixelFormat = format->pixelFormat;
       
   151 	khronos_int32_t bytesPerPixel = 0;
       
   152 	
       
   153 	if (overridePixelFormat != EUidPixelFormatUnknown)
       
   154 	    {
       
   155         bytesPerPixel = BytesPerPixel(overridePixelFormat);
       
   156         b.iAlignment = 4;
       
   157         b.iPixelFormat = overridePixelFormat;
       
   158 	    }
       
   159 	else
       
   160 	    {
       
   161         switch(pixelFormat)
       
   162             {
       
   163             case OWF_IMAGE_RGB565:
       
   164                 b.iPixelFormat = EUidPixelFormatRGB_565;
       
   165                 bytesPerPixel = 2;
       
   166                 b.iAlignment = 4;
       
   167                 break;
       
   168             case OWF_IMAGE_ARGB8888:
       
   169                 {
       
   170                 if (premultiplied)
       
   171                     {
       
   172                     b.iPixelFormat = EUidPixelFormatARGB_8888_PRE;
       
   173                     }
       
   174                 else
       
   175                     {
       
   176                     b.iPixelFormat = EUidPixelFormatARGB_8888;
       
   177                     }
       
   178                 bytesPerPixel = 4;
       
   179                 b.iAlignment = 4;
       
   180                 break;
       
   181                 }
       
   182             case OWF_IMAGE_XRGB8888 :
       
   183                 b.iPixelFormat = EUidPixelFormatXRGB_8888;
       
   184                 bytesPerPixel = 4;
       
   185                 b.iAlignment = 4;
       
   186                 break;
       
   187             case OWF_IMAGE_L8 :
       
   188                 b.iPixelFormat = EUidPixelFormatA_8;
       
   189                 bytesPerPixel = 1;
       
   190                 b.iAlignment = 4;
       
   191                 break;
       
   192             case OWF_IMAGE_L1 :
       
   193                 b.iPixelFormat = EUidPixelFormatL_1;
       
   194                 bytesPerPixel = -8;
       
   195                 b.iAlignment = 4;
       
   196                 break;
       
   197             default:
       
   198                 User::Leave(KErrNotSupported);	
       
   199                 break;
       
   200             }
       
   201 	    }
       
   202 	
       
   203 	b.iSize.iWidth = width;
       
   204 	b.iSize.iHeight = height;
       
   205 	b.iBuffers = nbufs;								// number of buffers in the surface
       
   206 	b.iOffsetToFirstBuffer = 0;						// way of reserving space before the surface pixel data
       
   207 	if (bytesPerPixel >= 0)
       
   208 	    {
       
   209 	    b.iStride = bytesPerPixel * width;	// number of bytes between start of one line and start of next	
       
   210 	    }
       
   211 	else
       
   212 	    {
       
   213 	    b.iStride = (width-(bytesPerPixel+1)) / (-bytesPerPixel);
       
   214 	    }
       
   215 	b.iContiguous = EFalse;
       
   216 	b.iMappable = ETrue;
       
   217 	
       
   218 	TSurfaceId surface = TSurfaceId::CreateNullId();
       
   219 	User::LeaveIfError(iUtility->Manager().CreateSurface(bf, surface));
       
   220 	
       
   221 	return surface;
       
   222 	}
       
   223 
       
   224 SymbianStreamType CTestNativeStream::helperCreateImageStream(khronos_int32_t width,
       
   225                                  khronos_int32_t height,
       
   226                                  const OWF_IMAGE_FORMAT*  format,
       
   227                                  khronos_int32_t nbufs,
       
   228                                  TUidPixelFormat overridePixelFormat)
       
   229 	{
       
   230 	TSurfaceId surface;
       
   231 	
       
   232 	TRAPD(err,surface = helperCreateSurfaceL(width, height, format, nbufs, overridePixelFormat));
       
   233 	if (err)
       
   234 	    {
       
   235 	    return WFC_INVALID_HANDLE;
       
   236 	    }
       
   237 	SymbianStreamType ns;
       
   238 	SymbianStreamAcquire(&surface, &ns);
       
   239 	
       
   240 	iUtility->Manager().CloseSurface(surface);
       
   241 	
       
   242 	return ns;
       
   243 	}
       
   244 
       
   245 RSemaphore      gSemaphore;
       
   246 
       
   247 TGlobalNativeStreamVar	gVarInstance={0};
       
   248 const TGlobalNativeStreamVar& TGlobalNativeStreamVar::Instance()
       
   249 	{
       
   250 	return gVarInstance;
       
   251 	}
       
   252 
       
   253 void TGlobalNativeStreamVar::SetSurfaceID(TSurfaceId aSurfaceID)
       
   254     {
       
   255     iSurfaceID = aSurfaceID;
       
   256     }
       
   257 
       
   258 void TGlobalNativeStreamVar::SetTestComplete(TBool aTestComplete)
       
   259     {
       
   260     iTestComplete = aTestComplete;
       
   261     }
       
   262 
       
   263 void TGlobalNativeStreamVar::SetBuffers(TInt aBuffers)
       
   264     {
       
   265     iBuffers = aBuffers;
       
   266     }
       
   267 
       
   268 TSurfaceId TGlobalNativeStreamVar::SurfaceID() const
       
   269     {
       
   270     return iSurfaceID;
       
   271     }
       
   272 
       
   273 TBool TGlobalNativeStreamVar::TestComplete() const
       
   274     {
       
   275     return iTestComplete;
       
   276     }
       
   277 
       
   278 TInt TGlobalNativeStreamVar::Buffers() const
       
   279     {
       
   280     return iBuffers;
       
   281     }
       
   282 
       
   283 /*
       
   284  * CTestNativeStream implementation
       
   285  * 
       
   286  * 
       
   287  * 
       
   288  * 
       
   289  */
       
   290 
       
   291 CTestNativeStream::CTestNativeStream(): iUtility(this)
       
   292 	{
       
   293 	// No implementation required
       
   294 	}
       
   295 
       
   296 CTestNativeStream::~CTestNativeStream()
       
   297 	{
       
   298 	DeleteOwfSingletons();
       
   299 	}
       
   300 
       
   301 void CTestNativeStream::SetupL()
       
   302 	{
       
   303 	TRAPD(err_FailedToCreateSurfaceUtility, iUtility = CSurfaceUtility::NewL( NULL ));
       
   304 	ASSERT_EQUALS(err_FailedToCreateSurfaceUtility,KErrNone);
       
   305 	DefineOwfSingletonKeys();
       
   306 	}
       
   307 
       
   308 /**
       
   309  * test Suite furniture 
       
   310  **/
       
   311 void CTestNativeStream::TearDownL()
       
   312 	{
       
   313 	delete iUtility();
       
   314 	}
       
   315 
       
   316 /**
       
   317 WFC context callback function invoked by native stream when the stream's content
       
   318 is updated. For testing, we simply call a class member function that checks that the
       
   319 correct native stream handle and events mask were supplied.
       
   320 */
       
   321 void CTestNativeStream::SourceStreamUpdatedCallback(
       
   322         SymbianStreamType aNs, khronos_int32_t aEvents, void* aData, void* aParam)
       
   323     {
       
   324     (void)aData;
       
   325     if (aEvents == ESOWF_ObserverReturnDefaultEvent && aParam)
       
   326         {
       
   327         SYMOWF_DEFAULT_EVENT_PARAM* parameter = (SYMOWF_DEFAULT_EVENT_PARAM*) aParam;
       
   328         if ((parameter->length) == sizeof(SYMOWF_DEFAULT_EVENT_PARAM))
       
   329             {
       
   330             parameter->event = ESOWF_EventUpdated;
       
   331             }
       
   332         return;
       
   333         }
       
   334         
       
   335     ASSERT(CTestNativeStream::iTester);
       
   336     CTestNativeStream::iTester->CheckSourceStreamUpdated(aNs, aParam);
       
   337     }
       
   338 
       
   339 void CTestNativeStream::CheckSourceStreamUpdated(SymbianStreamType aNs, void* aParam)
       
   340     {
       
   341     RHeap *h1 = &(User::Heap());
       
   342     if (aParam)
       
   343         {
       
   344         ASSERT_EQUALS(iNs, aNs);
       
   345         SYMOWF_CONTENT_UPDATED_PARAM* param = (SYMOWF_CONTENT_UPDATED_PARAM*) aParam;
       
   346         ASSERT_TRUE(param->id == SYM_CONTENT_UPDATE_BEGIN || 
       
   347                     param->id == SYM_CONTENT_UPDATE_END ||
       
   348                     param->id == SYM_CONTENT_UPDATE);
       
   349 
       
   350         iSourceStreamUpdatedCalled++;
       
   351         iStreamUpdatedParameter = param->id; 
       
   352         switch(param->id)
       
   353             {
       
   354             case SYM_CONTENT_UPDATE_BEGIN:
       
   355                 param->immediateAvailable = iImmediateAvailable;
       
   356                 param->immediateVisibility = iImmediateVisible;
       
   357                 param->serialNumber = iStreamUpdatedSerialNumber;
       
   358                 break;
       
   359                 
       
   360             case SYM_CONTENT_UPDATE:
       
   361             case SYM_CONTENT_UPDATE_END:
       
   362                 ASSERT_EQUALS(iExpectedSourceStreamUpdatedEventMask, param->par);        
       
   363                 iContextUpdatedFlags |= param->par & (~ESOWF_EventUpdated);    
       
   364                 break;
       
   365             default:
       
   366                 break;
       
   367             }
       
   368         }
       
   369     else
       
   370         {
       
   371         iSourceStreamUpdatedCalled++;
       
   372         }
       
   373         
       
   374     }
       
   375 
       
   376 /**
       
   377 Remove the native stream notifications. The creator of the source is responsible
       
   378 for destroying the native stream. 
       
   379 
       
   380 Now with the new SymbianStreamRemoveObserver function we need to pass in an observer
       
   381 */
       
   382 void CTestNativeStream::RemoveNsNotifications()
       
   383     {
       
   384     SymbianStreamRemoveObserver(iNs, &iScreenNo, ESOWF_EventAvailable);
       
   385     SymbianStreamRemoveObserver(iNs, &iScreenNo, ESOWF_EventDisplayed);
       
   386     SymbianStreamRemoveObserver(iNs, &iScreenNo, ESOWF_EventDisplayedX);
       
   387     }
       
   388 
       
   389 CTestNativeStream* CTestNativeStream::iTester = NULL;
       
   390 
       
   391 // Create a suite of all the tests
       
   392 CTestSuite* CTestNativeStream::CreateSuiteL(const TDesC& aName)
       
   393 	{
       
   394 	SymbianStreamRegisterScreenNotifications(0, 10, KCompositorVersion);
       
   395 	SUB_SUITE_OPT(CTestNativeStream,NULL);
       
   396 
       
   397 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0100L);
       
   398 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0101L);
       
   399 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0102L);
       
   400 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0103L);
       
   401 		
       
   402 		// Test with 1, 2 and 3 buffers
       
   403 		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0104L,1,4);
       
   404 		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0105L,1,4);
       
   405 		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0106L,1,4);
       
   406 		
       
   407 		// Concurrent tests
       
   408 		ADD_TEST_STEP_PARAM_RANGE(CreateSharedNativeStreamL,1,4);
       
   409 		ADD_THIS_TEST_STEP(DestroySharedNativeStreamL);
       
   410 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0107_1L);
       
   411 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0107_2L);
       
   412 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0107_3L);
       
   413 		
       
   414 		// Test SUS with OpenWF pipeline
       
   415 		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0108L, 1, 4);
       
   416 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0109L);
       
   417 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0110L);
       
   418 		
       
   419 		// Test various cases for Native Stream callbacks
       
   420 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0111L);
       
   421 		// Test multithreaded cases for Native Stream callbacks
       
   422 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0112_1L);
       
   423 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0112_2L);
       
   424 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0112_3L);
       
   425 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0112_4L);
       
   426 		
       
   427 		// Notification tests
       
   428 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0113L);
       
   429 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0114L);
       
   430 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0115L);
       
   431 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0116L);
       
   432 		
       
   433 		// Notification cancel
       
   434 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0117_1L);
       
   435 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0117_2L);
       
   436 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0117_3L);
       
   437 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0117_4L);
       
   438 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0118_1L);
       
   439 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0118_2L);
       
   440 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0118_3L);
       
   441 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0118_4L);
       
   442 		
       
   443 		// Notification overflow
       
   444 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0119_1L);
       
   445 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0119_2L);
       
   446 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0119_3L);
       
   447 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0120_1L);
       
   448 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0120_2L);
       
   449 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0120_3L);
       
   450 		
       
   451 		// Notifications cancelled due to removal of source observer
       
   452 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0122L);
       
   453 		
       
   454 		// Sym native stream add/remove observers
       
   455 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0130L);
       
   456 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0131L);
       
   457 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0132L);
       
   458 		
       
   459 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0133L);
       
   460 
       
   461 		// Test with 1, 2 and 3 buffers
       
   462 		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0140L,1,4);
       
   463 		ADD_TEST_STEP_PARAM_RANGE(GRAPHICS_OPENWFC_NATIVESTREAM_0141L,1,4);
       
   464 		ADD_THIS_TEST_STEP(GRAPHICS_OPENWFC_NATIVESTREAM_0142L);
       
   465 
       
   466 	END_SUITE;	
       
   467 	
       
   468 	}
       
   469 
       
   470 // This handles any non-member uses of the extended ASSERT_XXX macros
       
   471 void TefUnitFailLeaveL()
       
   472 	{
       
   473 	User::Leave(KErrTEFUnitFail);
       
   474 	}
       
   475 
       
   476 SymbianStreamType CTestNativeStream::NsCheckL(const TSurfaceId aId, TInt aCheck, TBool aFind)
       
   477 	{
       
   478 	// Acquire (create OR find) the stream
       
   479 	SymbianStreamType ns = NULL;
       
   480 	TInt err;
       
   481 	if (aFind)
       
   482 		{
       
   483 		err = (TInt)SymbianStreamFind(&aId, &ns);
       
   484 		}
       
   485 	else
       
   486 		{
       
   487 		err = SymbianStreamAcquire(&aId, &ns);
       
   488 		}
       
   489 	ASSERT_TRUE(err == KErrNone);
       
   490 	// Check the hash map count
       
   491 	ASSERT_EQUALS((COpenWfcStreamMap::InstanceL().Count()), aCheck);
       
   492     SymbianStreamBuffer bufferHandle;
       
   493     err = SymbianStreamAcquireReadBuffer(ns,&bufferHandle);
       
   494     ASSERT_TRUE(err == KErrNone);
       
   495     long bufferIndex;
       
   496     const TSurfaceId* checkId = NULL;
       
   497     err = SymbianStreamGetBufferId(ns,bufferHandle,&bufferIndex,&checkId);
       
   498     ASSERT_TRUE(err == KErrNone);
       
   499     SymbianStreamReleaseReadBuffer(ns,bufferHandle);
       
   500 	ASSERT_NOT_NULL(checkId);
       
   501 	ASSERT_EQUALS(*checkId, aId);
       
   502 	return ns;
       
   503 	}
       
   504 
       
   505 void CTestNativeStream::CreateSharedNativeStreamL(TInt aBuffers)
       
   506 	{
       
   507     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
   508     GrowCleanupStackL();
       
   509     
       
   510 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
   511 	
       
   512 	gVarInstance.SetTestComplete(EFalse);
       
   513 	gVarInstance.SetBuffers(aBuffers);
       
   514 	
       
   515 	TSize surfaceSize(TSize(100,100));
       
   516 	khronos_int32_t width = surfaceSize.iWidth;
       
   517 	khronos_int32_t height = surfaceSize.iHeight;
       
   518 	
       
   519 	OWF_IMAGE_FORMAT pixelFormat =
       
   520 		{
       
   521 		OWF_IMAGE_ARGB8888,
       
   522 		ETrue,
       
   523 		ETrue,
       
   524 		4
       
   525 		};	
       
   526 	
       
   527 	// Create the first stream
       
   528 	SymbianStreamType ns=helperCreateImageStream(width,
       
   529 													height,
       
   530 													&pixelFormat,
       
   531 													aBuffers);
       
   532 	ASSERT_TRUE(ns);
       
   533 	
       
   534     SymbianStreamBuffer bufferHandle;
       
   535     SymbianStreamAcquireReadBuffer(ns,&bufferHandle);
       
   536     long bufferIndex;
       
   537     const TSurfaceId* checkId = NULL;
       
   538     TInt err = SymbianStreamGetBufferId(ns,bufferHandle,&bufferIndex,&checkId);
       
   539     ASSERT_TRUE(err == KErrNone);
       
   540     SymbianStreamReleaseReadBuffer(ns,bufferHandle);
       
   541 	gVarInstance.SetSurfaceID(*checkId);
       
   542     gSemaphore.CreateLocal(1);
       
   543     gSemaphore.Wait(); 
       
   544     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
   545 	}
       
   546 
       
   547 void CTestNativeStream::DestroySharedNativeStreamL()
       
   548 	{
       
   549 	GrowCleanupStackL();
       
   550 	
       
   551 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(COpenWfcStreamMap::InstanceL().GetMainHeap())));
       
   552 	
       
   553 	gSemaphore.Close();
       
   554 	TSurfaceId id = gVarInstance.SurfaceID();
       
   555 	SymbianStreamType ns;
       
   556 	TInt err = SymbianStreamFind(&id,&ns);
       
   557 	ASSERT_TRUE(err == KErrNone);
       
   558 	ASSERT_TRUE(ns);
       
   559 	// Decrease stream's reference count by one. This removes reference added by owfNativeStreamFind()
       
   560 	SymbianStreamRemoveReference(ns);
       
   561 	// Decrease stream's reference count by one to make reference count zero, and destroy the stream
       
   562 	SymbianStreamRemoveReference(ns);
       
   563 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
   564 	}
       
   565 
       
   566 // Test observers
       
   567 void TestUpdateCallback(SymbianStreamType aStream, khronos_int32_t aEvent, void* aData, void* aParam)
       
   568     {
       
   569     (void) aStream;
       
   570     switch (aEvent)
       
   571         {
       
   572         case ESOWF_ObserverReturnDefaultEvent:
       
   573             if (aParam)
       
   574                 {
       
   575                 SYMOWF_DEFAULT_EVENT_PARAM* parameter = (SYMOWF_DEFAULT_EVENT_PARAM*) aParam;
       
   576                 if ((parameter->length) == sizeof(SYMOWF_DEFAULT_EVENT_PARAM))
       
   577                     {
       
   578                     parameter->event = ESOWF_EventUpdated;
       
   579                     }
       
   580                 }
       
   581             return;
       
   582             
       
   583         case ESOWF_EventUpdated:
       
   584             {
       
   585             TInt* localNumber = (TInt*)aData;
       
   586              ++(*localNumber);
       
   587             }
       
   588             break;
       
   589         default:
       
   590             break;
       
   591         }
       
   592     }
       
   593 
       
   594 // Test compose target
       
   595 void TestComposedCallback(SymbianStreamType aStream, khronos_int32_t aEvent, void* aData, void* aParam)
       
   596     {
       
   597     (void) aStream;
       
   598     switch (aEvent)
       
   599         {
       
   600         case ESOWF_ObserverReturnDefaultEvent:
       
   601             if (aParam)
       
   602                 {
       
   603                 SYMOWF_DEFAULT_EVENT_PARAM* parameter = (SYMOWF_DEFAULT_EVENT_PARAM*) aParam;
       
   604                 if ((parameter->length) == sizeof(SYMOWF_DEFAULT_EVENT_PARAM))
       
   605                     {
       
   606                     parameter->event = ESOWF_EventComposed;
       
   607                     }
       
   608                 }
       
   609             return;
       
   610             
       
   611         case ESOWF_EventComposed:
       
   612             {
       
   613             TInt* localNumber = (TInt*)aData;
       
   614              ++(*localNumber);
       
   615             }
       
   616             break;
       
   617         default:
       
   618             break;
       
   619         }
       
   620     }
       
   621 
       
   622 /**
       
   623 @SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0100
       
   624 @SYMTestCaseDesc		Create a native stream using SymbianStreamAcquire()
       
   625 @SYMREQ					
       
   626 @SYMPREQ				PREQ2400
       
   627 @SYMTestType			CT
       
   628 @SYMTestPriority		
       
   629 @SYMTestPurpose			Verify native stream objects can be created and persist unique surface ID values
       
   630 @SYMTestActions	
       
   631 		Create two surfaces,
       
   632 		Create two streams from the surfaces
       
   633 		Read back the surface Ids from the streams
       
   634 @SYMTestExpectedResults
       
   635 		The surface IDs should be non-null and unique
       
   636 		The streams should be non-null and unique
       
   637 		The returned surface Ids should match the constructed IDs
       
   638  **/		
       
   639 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0100L()
       
   640 	{
       
   641 	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
   642 	TRAPD(err, GrowCleanupStackL());
       
   643 	ASSERT_TRUE(err == KErrNone);
       
   644 	
       
   645 	TInt count = COpenWfcStreamMap::InstanceL().Count();
       
   646 	TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100),EUidPixelFormatARGB_8888_PRE,400,2);
       
   647 	ASSERT_FALSE(surface.IsNull());
       
   648 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
   649 	SymbianStreamType ns;
       
   650 	err = SymbianStreamAcquire(&surface, &ns);
       
   651 	ASSERT_TRUE(err == KErrNone);
       
   652     SymbianStreamBuffer bufferHandle;
       
   653     err = SymbianStreamAcquireReadBuffer(ns, &bufferHandle);
       
   654     ASSERT_TRUE(err == KErrNone);
       
   655     long bufferIndex;
       
   656     const TSurfaceId* getId = NULL;
       
   657     err = SymbianStreamGetBufferId(ns,bufferHandle,&bufferIndex,&getId);
       
   658     ASSERT_TRUE(err == KErrNone);
       
   659     err = SymbianStreamReleaseReadBuffer(ns,bufferHandle);
       
   660     ASSERT_TRUE(err == KErrNone);
       
   661 	ASSERT_EQUALS(*getId,surface);
       
   662 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
   663 	
       
   664 	TSurfaceId surface2=iUtility->CreateSurfaceL(TSize(100,100),EUidPixelFormatARGB_8888_PRE,400,2);
       
   665 	ASSERT_FALSE(surface2.IsNull());
       
   666 	ASSERT_NOT_EQUALS(surface,surface2);
       
   667 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
   668 	SymbianStreamType ns2;
       
   669 	err = SymbianStreamAcquire(&surface2,&ns2);
       
   670 	ASSERT_TRUE(err == KErrNone);
       
   671 	ASSERT_TRUE(ns2);
       
   672 	ASSERT_NOT_EQUALS(ns,ns2);
       
   673 	ASSERT_EQUALS((COpenWfcStreamMap::InstanceL().Count()), count + 2);
       
   674 	err = SymbianStreamAcquireReadBuffer(ns2,&bufferHandle);
       
   675 	ASSERT_TRUE(err == KErrNone);
       
   676     const TSurfaceId* getId2 = NULL;
       
   677     err = SymbianStreamGetBufferId(ns2,bufferHandle,&bufferIndex,&getId2);
       
   678     ASSERT_TRUE(err == KErrNone);
       
   679     err = SymbianStreamReleaseReadBuffer(ns2,bufferHandle);
       
   680     ASSERT_TRUE(err == KErrNone);
       
   681 	ASSERT_NOT_NULL(getId2);
       
   682 	ASSERT_EQUALS(*getId2,surface2);
       
   683 	
       
   684 	SymbianStreamRemoveReference(ns);
       
   685 	ASSERT_EQUALS((COpenWfcStreamMap::InstanceL().Count()), count + 1);
       
   686 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
   687 	iUtility->DestroySurface(surface);
       
   688 	
       
   689 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
   690 	SymbianStreamRemoveReference(ns2);
       
   691 	ASSERT_EQUALS((COpenWfcStreamMap::InstanceL().Count()), count);
       
   692 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
   693 	iUtility->DestroySurface(surface2);
       
   694 	}
       
   695 
       
   696 /**
       
   697 @SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0101
       
   698 @SYMTestCaseDesc		Create a native stream using SymbianStreamCreateImageStream()
       
   699 @SYMREQ					
       
   700 @SYMPREQ				PREQ2400
       
   701 @SYMTestType			CT
       
   702 @SYMTestPriority		
       
   703 @SYMTestPurpose			Verify native stream objects can be created and persist unique surface ID values
       
   704 @SYMTestActions	
       
   705 		Create two streams from the parameters passed in
       
   706 		Read back the surface Ids from the streams
       
   707 @SYMTestExpectedResults
       
   708 		The surface IDs should be non-null and unique
       
   709 		The streams should be non-null and unique
       
   710  **/
       
   711 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0101L()
       
   712 	{
       
   713 	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
   714 	TRAPD(err, GrowCleanupStackL());
       
   715 	ASSERT_TRUE(err == KErrNone);
       
   716 	
       
   717 	TSize surfaceSize(TSize(100,100));
       
   718 	TInt width = surfaceSize.iWidth;
       
   719 	TInt height = surfaceSize.iHeight;
       
   720 	TInt buffers = 2;
       
   721 
       
   722 	OWF_IMAGE_FORMAT pixelFormat =
       
   723 		{
       
   724 		OWF_IMAGE_ARGB8888,
       
   725 	    ETrue,
       
   726 	    ETrue,
       
   727 	    4
       
   728 	    };	
       
   729 	
       
   730 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
   731 	
       
   732 	// Create the first stream
       
   733 	SymbianStreamType ns=helperCreateImageStream(width,
       
   734 													height,
       
   735 													&pixelFormat,
       
   736 													buffers);
       
   737 	ASSERT_TRUE(ns);
       
   738     SymbianStreamBuffer bufferHandle;
       
   739     err = SymbianStreamAcquireReadBuffer(ns,&bufferHandle);
       
   740     ASSERT_TRUE(err == KErrNone);
       
   741     long bufferIndex;
       
   742     const TSurfaceId* getId = NULL;
       
   743     err = SymbianStreamGetBufferId(ns,bufferHandle,&bufferIndex,&getId);
       
   744     ASSERT_TRUE(err == KErrNone);
       
   745     err = SymbianStreamReleaseReadBuffer(ns,bufferHandle);
       
   746     ASSERT_TRUE(err == KErrNone);
       
   747 	
       
   748 	// Create the second stream
       
   749 	SymbianStreamType ns2=helperCreateImageStream(width,
       
   750 													height,
       
   751 													&pixelFormat,
       
   752 													buffers);
       
   753 	ASSERT_TRUE(ns2);
       
   754 	
       
   755     err = SymbianStreamAcquireReadBuffer(ns2,&bufferHandle);
       
   756     ASSERT_TRUE(err == KErrNone);
       
   757     const TSurfaceId* getId2 = NULL;
       
   758     err = SymbianStreamGetBufferId(ns2,bufferHandle,&bufferIndex,&getId2);
       
   759     ASSERT_TRUE(err == KErrNone);
       
   760     err = SymbianStreamReleaseReadBuffer(ns2,bufferHandle);
       
   761     ASSERT_TRUE(err == KErrNone);
       
   762 	ASSERT_NOT_NULL(getId2);
       
   763 	
       
   764 	ASSERT_NOT_EQUALS(ns,ns2);
       
   765 	ASSERT_NOT_EQUALS(getId,getId2);
       
   766 	
       
   767 	SymbianStreamRemoveReference(ns);
       
   768 	SymbianStreamRemoveReference(ns2);
       
   769 	
       
   770 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
   771 	}
       
   772 
       
   773 /**
       
   774 @SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0102
       
   775 @SYMTestCaseDesc		Create a native stream 2
       
   776 @SYMREQ					
       
   777 @SYMPREQ				PREQ2400
       
   778 @SYMTestType			CT
       
   779 @SYMTestPriority		
       
   780 @SYMTestPurpose			Verify native stream objects can be created and persist unique surface ID values
       
   781 @SYMTestActions	
       
   782 		Create two surfaces,
       
   783 		Create two streams from the surfaces
       
   784 		Read back the surface Ids from the streams
       
   785 		Acquire multiple time the native streams
       
   786 		Find native streams
       
   787 @SYMTestExpectedResults
       
   788 		The surface IDs should be non-null and unique
       
   789 		The streams should be non-null and unique
       
   790 		The returned surface Ids should match the constructed IDs
       
   791 		The hash map counter should be updated accordingly when native streams are created or destroyed
       
   792  **/		
       
   793 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0102L()
       
   794 	{
       
   795 	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
   796 	TRAPD(err, GrowCleanupStackL());
       
   797 	ASSERT_TRUE(err == KErrNone);
       
   798 	
       
   799 	COpenWfcStreamMap& singleton = COpenWfcStreamMap::InstanceL();
       
   800 	TInt check = COpenWfcStreamMap::InstanceL().Count() + 1;
       
   801 	// Create the first surface
       
   802 	TSurfaceId surfaceId1 = iUtility->CreateSurfaceL(TSize(100, 100), EUidPixelFormatARGB_8888_PRE, 400, 2);
       
   803 	ASSERT_FALSE(surfaceId1.IsNull());
       
   804 	
       
   805 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
   806 	SymbianStreamType ns1 = NsCheckL(surfaceId1, check, EFalse);
       
   807 	
       
   808 	TSurfaceId surfaceId2;
       
   809 	surfaceId2.CreateNullId();
       
   810 	SymbianStreamType ns2;
       
   811 	err = SymbianStreamFind(&surfaceId2,&ns2);
       
   812 	ASSERT_TRUE(err == KErrNotFound);
       
   813 	ASSERT_FALSE(ns2);
       
   814 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
   815 	
       
   816 	// Create the second surface
       
   817 	surfaceId2 = iUtility->CreateSurfaceL(TSize(100, 100), EUidPixelFormatARGB_8888_PRE, 400, 2);
       
   818 	ASSERT_FALSE(surfaceId2.IsNull()); 
       
   819 	
       
   820 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
   821 	err = SymbianStreamFind(&surfaceId2,&ns2);
       
   822 	ASSERT_TRUE(err == KErrNotFound);
       
   823 	ASSERT_FALSE(ns2);
       
   824 	
       
   825 	ns2 = NsCheckL(surfaceId2, ++check, EFalse);
       
   826 	
       
   827 	NsCheckL(surfaceId1, check, EFalse);
       
   828 	
       
   829 	NsCheckL(surfaceId1, check, ETrue);
       
   830 	
       
   831 	NsCheckL(surfaceId2, check, ETrue);
       
   832 	
       
   833 	SymbianStreamRemoveReference(ns1);
       
   834 	ASSERT_EQUALS((singleton.Count()), check);
       
   835 	
       
   836 	SymbianStreamRemoveReference(ns2);
       
   837 	ASSERT_EQUALS((singleton.Count()), check);
       
   838 	
       
   839 	SymbianStreamRemoveReference(ns2);
       
   840 	ASSERT_EQUALS((singleton.Count()), --check);
       
   841 
       
   842 	SymbianStreamRemoveReference(ns1);
       
   843 	ASSERT_EQUALS((singleton.Count()), check);
       
   844 	
       
   845 	SymbianStreamRemoveReference(ns1);
       
   846 	ASSERT_EQUALS((singleton.Count()), --check);
       
   847 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
   848 	
       
   849 	iUtility->DestroySurface(surfaceId1);
       
   850 	iUtility->DestroySurface(surfaceId2);
       
   851 	
       
   852 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
   853 	err = SymbianStreamFind(&surfaceId2,&ns2);
       
   854 	ASSERT_TRUE(err == KErrNotFound);
       
   855 	ASSERT_FALSE(ns2);
       
   856 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
   857 	}
       
   858 
       
   859 struct SupportedFormats
       
   860     {
       
   861     TUidPixelFormat symbianPixelFormat;
       
   862     } supportedFormats[]=
       
   863     {
       
   864         EUidPixelFormatXRGB_8888,
       
   865         EUidPixelFormatARGB_8888,
       
   866         EUidPixelFormatBGRX_8888,
       
   867         EUidPixelFormatXBGR_8888,
       
   868         EUidPixelFormatBGRA_8888,
       
   869         EUidPixelFormatABGR_8888, 
       
   870         EUidPixelFormatABGR_8888_PRE,
       
   871         EUidPixelFormatARGB_8888_PRE,
       
   872         EUidPixelFormatBGRA_8888_PRE,
       
   873         EUidPixelFormatARGB_2101010,
       
   874         EUidPixelFormatABGR_2101010,
       
   875         EUidPixelFormatBGR_888,
       
   876         EUidPixelFormatRGB_888,
       
   877         EUidPixelFormatXRGB_4444,
       
   878         EUidPixelFormatARGB_4444,
       
   879         EUidPixelFormatXBGR_4444,
       
   880         EUidPixelFormatRGB_565,
       
   881         EUidPixelFormatBGR_565,
       
   882         EUidPixelFormatARGB_1555,
       
   883         EUidPixelFormatXRGB_1555,
       
   884         EUidPixelFormatARGB_8332,
       
   885         EUidPixelFormatBGRX_5551,
       
   886         EUidPixelFormatBGRA_5551,
       
   887         EUidPixelFormatBGRA_4444,
       
   888         EUidPixelFormatBGRX_4444,
       
   889         EUidPixelFormatAP_88,
       
   890         EUidPixelFormatRGB_332,
       
   891         EUidPixelFormatBGR_332,
       
   892         EUidPixelFormatA_8,
       
   893         EUidPixelFormatL_8,
       
   894         EUidPixelFormatP_8,
       
   895         EUidPixelFormatP_4,
       
   896         EUidPixelFormatL_4,
       
   897         EUidPixelFormatL_2,
       
   898         EUidPixelFormatP_2,
       
   899         EUidPixelFormatL_1
       
   900     };
       
   901 
       
   902 /**
       
   903 @SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0103
       
   904 @SYMTestCaseDesc		Retrieve stream attributes using SymbianStreamGetHeader()
       
   905 @SYMREQ					
       
   906 @SYMPREQ				PREQ2400
       
   907 @SYMTestType			CT
       
   908 @SYMTestPriority		
       
   909 @SYMTestPurpose			Verify native stream object attributes can be retrieved.
       
   910 @SYMTestActions	
       
   911 		Create a native stream based on a supported image/pixel format
       
   912 		Retrieve all of the stream attributes
       
   913 		Retreive none of the stream attributes
       
   914 @SYMTestExpectedResults
       
   915 		The retrieved attributes should match the parameters used to create the surface stream
       
   916 		Retrieving no attributes should not cause a crash
       
   917  **/
       
   918 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0103L()
       
   919 	{
       
   920 	// Native stream attributes
       
   921     TSize surfaceSize(TSize(100,50));
       
   922     khronos_int32_t width = surfaceSize.iWidth;
       
   923     khronos_int32_t height = surfaceSize.iHeight;
       
   924     khronos_int32_t numBuffers = 2;
       
   925     
       
   926     for (TInt x=0; x<sizeof(supportedFormats)/sizeof(supportedFormats[0]); x++)
       
   927         {
       
   928         INFO_PRINTF2(_L("Pixel format %x"),supportedFormats[x]);
       
   929         khronos_int32_t streamPixelSize = BytesPerPixel(supportedFormats[x].symbianPixelFormat);
       
   930         
       
   931         OWF_IMAGE_FORMAT pixelFormat =
       
   932             {
       
   933             OWF_IMAGE_NOT_SUPPORTED,
       
   934             EFalse,
       
   935             EFalse,
       
   936             2
       
   937             };  
       
   938         
       
   939         SymbianStreamType ns=helperCreateImageStream(width,
       
   940                                                      height,
       
   941                                                      &pixelFormat,
       
   942                                                      numBuffers,
       
   943                                                      supportedFormats[x].symbianPixelFormat);      //will ignore pixelFormat
       
   944         ASSERT_TRUE(ns);
       
   945         
       
   946         // Store the retrieved attributes
       
   947         TInt32 attWidth = 0;
       
   948         TInt32 attHeight = 0;
       
   949         TInt32 attStreamStride = 0;
       
   950         TUidPixelFormat attStreamFormat = EUidPixelFormatUnknown;
       
   951         TInt32 attStreamPixelSize = 0;
       
   952         
       
   953         SymbianStreamGetHeader(ns, &attWidth, &attHeight, &attStreamStride, &attStreamFormat, &attStreamPixelSize);		
       
   954             
       
   955         ASSERT_EQUALS(attWidth, width);
       
   956         ASSERT_EQUALS(attHeight, height);
       
   957         ASSERT_EQUALS(attStreamFormat, supportedFormats[x].symbianPixelFormat);
       
   958         if (BytesPerPixel(supportedFormats[x].symbianPixelFormat) > 0)
       
   959             {
       
   960             ASSERT_EQUALS(attStreamStride, (streamPixelSize * width));
       
   961             }
       
   962         else
       
   963             {
       
   964             ASSERT_EQUALS(attStreamStride, (width-(streamPixelSize+1)) / (-streamPixelSize));
       
   965             }
       
   966         ASSERT_EQUALS(attStreamPixelSize, (TInt32)BytesPerPixel(supportedFormats[x].symbianPixelFormat));	
       
   967             
       
   968         SymbianStreamGetHeader(ns, NULL, NULL, NULL, NULL, NULL);
       
   969         
       
   970         SymbianStreamRemoveReference(ns);
       
   971         }
       
   972 	}
       
   973 
       
   974 /**
       
   975 @SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0104
       
   976 @SYMTestCaseDesc		Acquire write/read buffers and retrieve the buffer ptr (single threaded test).
       
   977 @SYMREQ					
       
   978 @SYMPREQ				PREQ2400
       
   979 @SYMTestType			CT
       
   980 @SYMTestPriority		
       
   981 @SYMTestPurpose         Verify owfNativeStreamAcquireWriteBuffer(), owfNativeStreamReleaseWriteBuffer(),
       
   982                         owfNativeStreamAcquireReadBuffer() and owfNativeStreamReleaseReadBuffer() methods
       
   983 						work as expected.
       
   984 						
       
   985 @SYMTestActions	
       
   986 		Create a native stream 
       
   987 		For each buffer:
       
   988 		- Acquire the write buffer (wB)
       
   989 		- Get the write buffer ptr (pWB)
       
   990 		- Release the write buffer
       
   991 		- Acquire the read buffer (rB)
       
   992 		- Get the read buffer ptr (pRB)
       
   993 		- Release the read buffer	
       
   994 		Repeat for each buffer. Finally:
       
   995 		Acquire the write buffer
       
   996 		Release the write buffer	
       
   997 @SYMTestExpectedResults
       
   998 		For each buffer of the native stream, check:
       
   999 		- The read buffer (rB) should be the same as the write buffer (wB)
       
  1000 		- The read buffer address (pRB) should be the same as the write buffer address (pWB)
       
  1001 		If the number of buffers > 1, check:
       
  1002 		- The write buffer number from the previous acquire write buffer call should not be the same 
       
  1003 		as the write buffer number from the next acquire write buffer call
       
  1004 		The final acquire/release write/read calls should check:
       
  1005 		The write buffer number should acquire the first buffer number
       
  1006  **/
       
  1007 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0104L(TInt aNumBuffers)
       
  1008 	{
       
  1009 	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  1010 	TRAPD(err, GrowCleanupStackL());
       
  1011 	ASSERT_TRUE(err == KErrNone);
       
  1012 
       
  1013 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  1014 	
       
  1015 	ASSERT_TRUE(aNumBuffers > 0);
       
  1016 	
       
  1017 	TSize surfaceSize(TSize(100,100));
       
  1018 	khronos_int32_t width = surfaceSize.iWidth;
       
  1019 	khronos_int32_t height = surfaceSize.iHeight;
       
  1020 	
       
  1021 	OWF_IMAGE_FORMAT pixelFormat =
       
  1022 		{
       
  1023 		OWF_IMAGE_ARGB8888,
       
  1024 	    ETrue,
       
  1025 	    ETrue,
       
  1026 	    aNumBuffers
       
  1027 	    };	
       
  1028 	
       
  1029 	SymbianStreamType ns=helperCreateImageStream(width,
       
  1030 													height,
       
  1031 													&pixelFormat,
       
  1032 													aNumBuffers);
       
  1033 	ASSERT_TRUE(ns);
       
  1034 	
       
  1035 	TUint8 *pWriteBuffer = NULL;
       
  1036 	TUint8 *pReadBuffer = NULL;
       
  1037 	TUint8 *pPrevWriteBuffer = pWriteBuffer;
       
  1038 	khronos_int32_t writeBuffer;
       
  1039 	khronos_int32_t readBuffer;
       
  1040 	khronos_int32_t bufferIndexWrite;
       
  1041 	khronos_int32_t bufferIndexRead;
       
  1042 	khronos_int32_t bufferIndexWriteFirst;
       
  1043 	khronos_int32_t bufferIndexWriteFinal;
       
  1044 	khronos_int32_t finalWriteBuffer;
       
  1045 	const TSurfaceId* getId = NULL;
       
  1046 	
       
  1047 	TInt bufferCount = aNumBuffers;
       
  1048 	
       
  1049 	// Loop through the buffers
       
  1050 	for (TInt count=0; count<bufferCount; count++)
       
  1051 		{
       
  1052 		// Acquire the write buffer
       
  1053 		err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer);
       
  1054 		ASSERT_TRUE(err == KErrNone);
       
  1055 		err = SymbianStreamGetBufferId(ns,writeBuffer,&bufferIndexWrite,&getId);
       
  1056 		ASSERT_TRUE(err == KErrNone);
       
  1057 		
       
  1058 		if (count == 0)
       
  1059 		    {
       
  1060 		    bufferIndexWriteFirst = bufferIndexWrite;
       
  1061 		    }
       
  1062 		
       
  1063 		err = SymbianStreamGetBufferPointer(ns,writeBuffer,reinterpret_cast<void**>(&pWriteBuffer));
       
  1064 		ASSERT_TRUE(err == KErrNone);
       
  1065 		ASSERT_NOT_NULL(pWriteBuffer);
       
  1066 		
       
  1067 		err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer);
       
  1068 		ASSERT_TRUE(err == KErrNone);
       
  1069 		
       
  1070 		// Acquire the read buffer
       
  1071 		err = SymbianStreamAcquireReadBuffer(ns,&readBuffer);
       
  1072 		ASSERT_TRUE(err == KErrNone);
       
  1073 		err = SymbianStreamGetBufferId(ns,writeBuffer,&bufferIndexRead,&getId);
       
  1074 		ASSERT_TRUE(err == KErrNone);
       
  1075 		
       
  1076 		err = SymbianStreamGetBufferPointer(ns,readBuffer,reinterpret_cast<void**>(&pReadBuffer));
       
  1077 		ASSERT_TRUE(err == KErrNone);
       
  1078 		ASSERT_NOT_NULL(pReadBuffer);
       
  1079 		
       
  1080 		err = SymbianStreamReleaseReadBuffer(ns,readBuffer);
       
  1081 		ASSERT_TRUE(err == KErrNone);
       
  1082 		
       
  1083 		// Life-cycle checks
       
  1084 		ASSERT_EQUALS(bufferIndexWrite, bufferIndexRead)
       
  1085 		ASSERT_SAME(pWriteBuffer, pReadBuffer);
       
  1086 		
       
  1087 		if (count > 0)
       
  1088 			{
       
  1089 			ASSERT_NOT_SAME(pWriteBuffer, pPrevWriteBuffer);
       
  1090 			}
       
  1091 		
       
  1092 		pPrevWriteBuffer = pWriteBuffer;
       
  1093 		}	
       
  1094 
       
  1095 	// The next acquire write/reads should return the first buffer (0).
       
  1096 
       
  1097 	err = SymbianStreamAcquireWriteBuffer(ns,&finalWriteBuffer);
       
  1098 	ASSERT_TRUE(err == KErrNone);
       
  1099 	err = SymbianStreamGetBufferId(ns,finalWriteBuffer,&bufferIndexWriteFinal,&getId);
       
  1100 	ASSERT_TRUE(err == KErrNone);
       
  1101 	err = SymbianStreamReleaseWriteBuffer(ns,finalWriteBuffer);
       
  1102 	ASSERT_TRUE(err == KErrNone);
       
  1103 	
       
  1104 	// Final checks
       
  1105 	ASSERT_EQUALS(bufferIndexWriteFinal, bufferIndexWriteFirst);
       
  1106 	
       
  1107 	SymbianStreamRemoveReference(ns);
       
  1108 	
       
  1109 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  1110 	}
       
  1111 
       
  1112 /**
       
  1113 @SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0105
       
  1114 @SYMTestCaseDesc		Create a native stream and acquire a write buffer which is written to (single threaded test)
       
  1115 @SYMREQ					
       
  1116 @SYMPREQ				PREQ2400
       
  1117 @SYMTestType			CT
       
  1118 @SYMTestPriority		
       
  1119 @SYMTestPurpose			Verify native stream buffers can be written to and read from.
       
  1120 @SYMTestActions	
       
  1121 		Create a surface and fill it Red
       
  1122 		Create a native stream surface with the same surface properties (size, pixel format etc.)
       
  1123 		Acquire the native stream write buffer
       
  1124 		Fill the native stream surface Red
       
  1125 		Release the write buffer
       
  1126 		Acquire the native stream read buffer
       
  1127 		Compare the pixel data of the surface to the native stream surface
       
  1128 		Fill the Blue
       
  1129 		Compare the pixel data of the surface to the native stream surface
       
  1130 @SYMTestExpectedResults
       
  1131 		The surface pixel data is the same as the native stream surface pixel data
       
  1132 		After the surface pixel data is changed to Blue, the native stream surface should not be the same
       
  1133  **/
       
  1134 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0105L(TInt aNumBuffers)
       
  1135 	{
       
  1136 	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  1137 	TRAPD(err, GrowCleanupStackL());
       
  1138 	ASSERT_TRUE(err == KErrNone);
       
  1139 	
       
  1140 	// Surface properties
       
  1141 	TSize surfaceSize(TSize(100,100));
       
  1142 	
       
  1143 	// Create the comparison surface and fill it Red
       
  1144 	TSurfaceId surface;
       
  1145 	TRAP(err, surface = iUtility->CreateSurfaceL(TSize(surfaceSize.iWidth,surfaceSize.iHeight), 
       
  1146 			EUidPixelFormatXRGB_8888, surfaceSize.iWidth * 4));
       
  1147 	
       
  1148 	TRAP(err, iUtility->FillSurfaceL(surface, 0, KRgbRed));
       
  1149 	
       
  1150 	// Native stream
       
  1151 	khronos_int32_t width = surfaceSize.iWidth;
       
  1152 	khronos_int32_t height = surfaceSize.iHeight;
       
  1153 	
       
  1154 	OWF_IMAGE_FORMAT pixelFormatXRGB888 =
       
  1155 		{
       
  1156 		OWF_IMAGE_XRGB8888,
       
  1157 	    ETrue,
       
  1158 	    EFalse,
       
  1159 	    4
       
  1160 	    };	
       
  1161 	
       
  1162 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  1163 	
       
  1164 	SymbianStreamType ns1=helperCreateImageStream(width,
       
  1165 													height,
       
  1166 													&pixelFormatXRGB888,
       
  1167 													aNumBuffers);
       
  1168 	ASSERT_TRUE(ns1);
       
  1169 	
       
  1170 	
       
  1171     SymbianStreamBuffer bufferHandle;
       
  1172     err = SymbianStreamAcquireReadBuffer(ns1,&bufferHandle);
       
  1173     ASSERT_TRUE(err == KErrNone);
       
  1174     long bufferIndex;
       
  1175     const TSurfaceId* nSurface = NULL;
       
  1176     err = SymbianStreamGetBufferId(ns1,bufferHandle,&bufferIndex,&nSurface);
       
  1177     ASSERT_TRUE(err == KErrNone);
       
  1178     err = SymbianStreamReleaseReadBuffer(ns1,bufferHandle);
       
  1179     ASSERT_TRUE(err == KErrNone);
       
  1180 	ASSERT_NOT_NULL(nSurface);
       
  1181 	
       
  1182 	TSurfaceId* nsSurface = const_cast<TSurfaceId*>(nSurface);
       
  1183 	
       
  1184 	// Acquire write buffer. With 3 buffers we should return buffer 1
       
  1185 	khronos_int32_t writeBuffer1;
       
  1186 	err = SymbianStreamAcquireWriteBuffer(ns1,&writeBuffer1);
       
  1187 	ASSERT_TRUE(err == KErrNone);
       
  1188 	
       
  1189 	TUint8 *pWriteBuffer1 = NULL;
       
  1190 	err = SymbianStreamGetBufferPointer(ns1,writeBuffer1,reinterpret_cast<void**>(&pWriteBuffer1));
       
  1191 	ASSERT_TRUE(err == KErrNone);
       
  1192 	ASSERT_NOT_NULL(pWriteBuffer1);
       
  1193 	
       
  1194 	TRAP(err, iUtility->FillNativeStreamSurfaceL(*nsSurface, pWriteBuffer1, KRgbRed));
       
  1195 	
       
  1196 	err = SymbianStreamReleaseWriteBuffer(ns1, writeBuffer1);
       
  1197 	ASSERT_TRUE(err == KErrNone);
       
  1198 	
       
  1199 	// Now we should compare to see if the pixels are the same
       
  1200 	khronos_int32_t readBuffer1;
       
  1201 	err = SymbianStreamAcquireReadBuffer(ns1,&readBuffer1);
       
  1202 	ASSERT_TRUE(err == KErrNone);
       
  1203 	
       
  1204 	TUint8 *pReadBuffer1 = NULL;
       
  1205 	err = SymbianStreamGetBufferPointer(ns1,readBuffer1,reinterpret_cast<void**>(&pReadBuffer1));
       
  1206 	ASSERT_TRUE(err == KErrNone);
       
  1207 	ASSERT_NOT_NULL(pReadBuffer1);
       
  1208 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  1209 	ASSERT_TRUE(iUtility->CompareSurfacesL(surface, 0, *nsSurface, pReadBuffer1));	
       
  1210 	
       
  1211 	// Finally, change the surface to blue. The pixels should now be different
       
  1212 	TRAP(err, iUtility->FillSurfaceL(surface, 0, KRgbBlue));
       
  1213 	ASSERT_FALSE(iUtility->CompareSurfacesL(surface, 0, *nsSurface, pReadBuffer1));	
       
  1214 	
       
  1215 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  1216 	err = SymbianStreamReleaseReadBuffer(ns1,readBuffer1);
       
  1217 	ASSERT_TRUE(err == KErrNone);
       
  1218 	SymbianStreamRemoveReference(ns1);
       
  1219 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  1220 	}
       
  1221 
       
  1222 /**
       
  1223 @SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0106
       
  1224 @SYMTestCaseDesc		Negative test - Attempt to acquire a write buffer when the write buffer has not been released (single threaded test)
       
  1225 @SYMREQ					
       
  1226 @SYMPREQ				PREQ2400
       
  1227 @SYMTestType			CT
       
  1228 @SYMTestPriority		
       
  1229 @SYMTestPurpose			Verify an invalid handle is returned to the calling thread if the write buffer has not been released
       
  1230 @SYMTestActions	
       
  1231 		Create a native stream surface with 1 buffer
       
  1232 		Acquire the native stream write buffer
       
  1233 		Acquire the native stream write buffer again
       
  1234 @SYMTestExpectedResults
       
  1235 		The 2nd acquire write buffer call should return OWF_INVALID_HANDLE if not single buffered.
       
  1236  **/
       
  1237 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0106L(TInt aNumBuffers)
       
  1238 	{
       
  1239 	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  1240 	TRAPD(err, GrowCleanupStackL());
       
  1241 	ASSERT_TRUE(err == KErrNone);
       
  1242 
       
  1243 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  1244 	
       
  1245 	// Create the first stream (ARGB_8888_PRE)
       
  1246 	TSize surfaceSize(TSize(100,100));
       
  1247 	khronos_int32_t width = surfaceSize.iWidth;
       
  1248 	khronos_int32_t height = surfaceSize.iHeight;
       
  1249 	
       
  1250 	OWF_IMAGE_FORMAT pixelFormatARGB888Pre =
       
  1251 		{
       
  1252 		OWF_IMAGE_ARGB8888,
       
  1253 	    ETrue,
       
  1254 	    EFalse,
       
  1255 	    4
       
  1256 	    };	
       
  1257 	
       
  1258 	SymbianStreamType ns1=helperCreateImageStream(width,
       
  1259 													height,
       
  1260 													&pixelFormatARGB888Pre,
       
  1261 													aNumBuffers);
       
  1262 	ASSERT_TRUE(ns1);
       
  1263 	
       
  1264 	// Acquire write buffer. With just 1 buffer we should return buffer 0
       
  1265 	khronos_int32_t writeBuffer1;
       
  1266 	err = SymbianStreamAcquireWriteBuffer(ns1,&writeBuffer1);
       
  1267 	ASSERT_TRUE(err != KErrBadHandle);
       
  1268 	
       
  1269 	// Try and acquire the write buffer again before we have released it
       
  1270 	khronos_int32_t writeBuffer2;
       
  1271 	err = SymbianStreamAcquireWriteBuffer(ns1,&writeBuffer2);
       
  1272 	ASSERT_TRUE(err != KErrBadHandle);
       
  1273 	if (aNumBuffers == 1)
       
  1274 	    {
       
  1275 	    ASSERT_EQUALS(writeBuffer2, writeBuffer1); 	    
       
  1276 	    }
       
  1277 	else
       
  1278 	    {
       
  1279 	    ASSERT_EQUALS(writeBuffer2, (khronos_int32_t)0); 	    
       
  1280 	    }
       
  1281 	
       
  1282 	err = SymbianStreamReleaseWriteBuffer(ns1,writeBuffer1);
       
  1283 	ASSERT_TRUE(err != KErrBadHandle);
       
  1284 	
       
  1285 	err = SymbianStreamAcquireWriteBuffer(ns1, &writeBuffer2);
       
  1286 	ASSERT_TRUE(err != KErrBadHandle);
       
  1287 	TUint8 *pWriteBuffer2 = NULL;
       
  1288 	err = SymbianStreamGetBufferPointer(ns1,writeBuffer2,reinterpret_cast<void**>(&pWriteBuffer2));
       
  1289 	ASSERT_TRUE(err != KErrBadHandle);
       
  1290 	ASSERT_NOT_NULL(pWriteBuffer2);
       
  1291 	
       
  1292 	SymbianStreamRemoveReference(ns1);
       
  1293 	
       
  1294 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  1295 	}
       
  1296 
       
  1297 /**
       
  1298 @SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0107
       
  1299 @SYMTestCaseDesc		Attempt to acquire a write buffer when the write buffer has not been released (multi threaded tests)
       
  1300 @SYMREQ					
       
  1301 @SYMPREQ				PREQ2400
       
  1302 @SYMTestType			CT
       
  1303 @SYMTestPriority		
       
  1304 @SYMTestPurpose			Verify an invalid handle is returned to the calling thread if the write buffer has not been released
       
  1305 @SYMTestActions	
       
  1306 		Create a shared native stream surface to be used by multiple threads
       
  1307 		Thread 1 acquires the shared native stream and acquires the write buffer
       
  1308 		Thread 2 acquires the shared native stream and attempts to acquire the write buffer
       
  1309 		Thread 3 acquires the shared native stream and attempts to acquire the write buffer
       
  1310 		Thread 1 releases the write buffer
       
  1311 		Thread 2 acquires the write buffer
       
  1312 		Thread 2 releases the write buffer
       
  1313 @SYMTestExpectedResults
       
  1314 		OWF_INVALID_HANDLE returned when Thread 2 and Thread 3 attempt to acquire the write buffer
       
  1315 		when Thread 1 has already acquired it
       
  1316  **/
       
  1317 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0107_1L()
       
  1318 	{
       
  1319     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  1320     TRAPD(err, GrowCleanupStackL());
       
  1321     ASSERT_TRUE(err == KErrNone);
       
  1322         
       
  1323     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  1324 	INFO_PRINTF2(_L("** GRAPHICS_OPENWFC_NATIVESTREAM_0107 - %i buffers **"), gVarInstance.Buffers());
       
  1325 	INFO_PRINTF1(_L("Thread 1 - start"));
       
  1326 	TSurfaceId surface = gVarInstance.SurfaceID();
       
  1327 	SymbianStreamType ns;
       
  1328 	err = SymbianStreamAcquire(&surface,&ns);
       
  1329 	ASSERT_TRUE(err == KErrNone);
       
  1330 	ASSERT_TRUE(ns);
       
  1331 	
       
  1332 	khronos_int32_t writeBuffer1;
       
  1333 	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer1);
       
  1334 	ASSERT_TRUE(err != KErrBadHandle);
       
  1335 	
       
  1336 	khronos_int32_t bufferIndex;
       
  1337 	const TSurfaceId* getId = NULL;
       
  1338 	err = SymbianStreamGetBufferId(ns,writeBuffer1,&bufferIndex,&getId);
       
  1339 	ASSERT_TRUE(err == KErrNone);
       
  1340 	ASSERT_EQUALS(*getId, surface);
       
  1341 	ASSERT_EQUALS(bufferIndex, (khronos_int32_t)1);
       
  1342 	INFO_PRINTF2(_L("Thread 1 - Write buffer %i acquired"), bufferIndex);
       
  1343 	
       
  1344 	gSemaphore.Signal(2); // Thread 2 and 3 ready to run
       
  1345 	
       
  1346 	gSemaphore.Wait();
       
  1347 	err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer1);
       
  1348 	ASSERT_TRUE(err == KErrNone);
       
  1349 	SymbianStreamRemoveReference(ns);
       
  1350 	INFO_PRINTF2(_L("Thread 1 - Write buffer %i released"), bufferIndex);
       
  1351 
       
  1352 	gSemaphore.Signal();	
       
  1353     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one    
       
  1354 	}
       
  1355 
       
  1356 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0107_2L()
       
  1357 	{
       
  1358     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  1359     TRAPD(err, GrowCleanupStackL());
       
  1360     ASSERT_TRUE(err == KErrNone);
       
  1361         
       
  1362     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  1363 	gSemaphore.Wait(); // Semaphore count becomes -1
       
  1364 	INFO_PRINTF1(_L("Thread 2 - Start"));
       
  1365 	TSurfaceId surface = gVarInstance.SurfaceID();
       
  1366 	SymbianStreamType ns;
       
  1367 	err = SymbianStreamAcquire(&surface,&ns);
       
  1368 	ASSERT_TRUE(err == KErrNone);
       
  1369 	ASSERT_TRUE(ns);
       
  1370 
       
  1371 	khronos_int32_t writeBuffer1;
       
  1372 	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer1);
       
  1373 	ASSERT_TRUE(err != KErrBadHandle);
       
  1374 	INFO_PRINTF1(_L("Thread 2 - Attempt to acquire the write buffer"));
       
  1375 	ASSERT_FALSE(writeBuffer1);
       
  1376 	INFO_PRINTF1(_L("Thread 2 - Write buffer already in use by Thread 1!"));
       
  1377     
       
  1378 	gSemaphore.Signal();
       
  1379 	
       
  1380 	gSemaphore.Wait();
       
  1381 	
       
  1382 	khronos_int32_t writeBuffer2;
       
  1383 	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer2);
       
  1384 	ASSERT_TRUE(err != KErrBadHandle);
       
  1385 	khronos_int32_t bufferIndex;
       
  1386 	const TSurfaceId* getId = NULL;
       
  1387 	err = SymbianStreamGetBufferId(ns,writeBuffer2,&bufferIndex,&getId);
       
  1388 	ASSERT_TRUE(err == KErrNone);
       
  1389 	ASSERT_FALSE(bufferIndex);
       
  1390 	INFO_PRINTF2(_L("Thread 2 - Write buffer %i acquired"), bufferIndex);
       
  1391 	
       
  1392 	err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer2);
       
  1393 	ASSERT_TRUE(err == KErrNone);
       
  1394 	SymbianStreamRemoveReference(ns);
       
  1395 	INFO_PRINTF2(_L("Thread 2 - Write buffer %i released"), bufferIndex);
       
  1396     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one    
       
  1397 	}
       
  1398 
       
  1399 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0107_3L()
       
  1400 	{
       
  1401     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  1402     TRAPD(err, GrowCleanupStackL());
       
  1403     ASSERT_TRUE(err == KErrNone);
       
  1404         
       
  1405     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  1406 	gSemaphore.Wait(); // Semaphore count is -2
       
  1407 	INFO_PRINTF1(_L("Thread 3 - start"));
       
  1408 	TSurfaceId surface = gVarInstance.SurfaceID();
       
  1409 	SymbianStreamType ns;
       
  1410 	err = SymbianStreamAcquire(&surface,&ns);
       
  1411 	ASSERT_TRUE(err == KErrNone);
       
  1412 	ASSERT_TRUE(ns);
       
  1413 
       
  1414  	khronos_int32_t writeBuffer1;
       
  1415  	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer1);
       
  1416  	ASSERT_TRUE(err != KErrBadHandle);
       
  1417  	INFO_PRINTF1(_L("Thread 3 - Attempt to acquire the write buffer"));
       
  1418 	ASSERT_FALSE(writeBuffer1);
       
  1419 	INFO_PRINTF1(_L("Thread 3 - Write buffer already in use by Thread 1!"));
       
  1420 
       
  1421     SymbianStreamRemoveReference(ns);
       
  1422     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one    
       
  1423 	}
       
  1424 
       
  1425 
       
  1426 /**
       
  1427 @SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0108
       
  1428 @SYMTestCaseDesc		Content updates on valid and invalid buffers
       
  1429 @SYMREQ					
       
  1430 @SYMPREQ				PREQ2400
       
  1431 @SYMTestType			CT
       
  1432 @SYMTestPriority		
       
  1433 @SYMTestPurpose			Verify native streams can handle content updates for valid and invalid buffer numbers
       
  1434 @SYMTestActions	
       
  1435 		Create a surface with 4 buffers,
       
  1436 		Create a stream from this surface,
       
  1437 		Add an observer to listen out for content updates to the stream,
       
  1438 		Set valid and invalid buffer numbers to be used in content updates
       
  1439 @SYMTestExpectedResults
       
  1440 		For valid buffers, the read buffers should be set correctly and observer 
       
  1441 		callback method is called.
       
  1442  **/		
       
  1443 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0108L(TInt aBuffers)
       
  1444 	{
       
  1445 	aBuffers = 3;
       
  1446 	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  1447 	TRAPD(err, GrowCleanupStackL());
       
  1448 	ASSERT_TRUE(err == KErrNone);
       
  1449 
       
  1450 	iScreenNo = 0;
       
  1451 	TInt localNumber = 0;
       
  1452 	
       
  1453 	TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, aBuffers);
       
  1454 	ASSERT_FALSE(surface.IsNull());
       
  1455 	
       
  1456 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  1457 	SymbianStreamType ns;
       
  1458 	err = SymbianStreamAcquire(&surface,&ns);
       
  1459     ASSERT_TRUE(err == KErrNone);
       
  1460 	ASSERT_TRUE(ns);
       
  1461 	
       
  1462 	err = SymbianStreamAddObserver(ns, TestUpdateCallback, &localNumber);
       
  1463 	ASSERT_TRUE(err == KErrNone);
       
  1464 	khronos_int32_t bufferIndex = 0; 
       
  1465 	khronos_int32_t buffersIndex = 0;
       
  1466 	khronos_int32_t lastValidBufnum = 0;
       
  1467 	
       
  1468 	const TSurfaceId* getId = NULL;
       
  1469     CExtensionContainer* updateExtension = NULL;
       
  1470     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  1471     ASSERT_TRUE(err == KErrNone);
       
  1472     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  1473     ASSERT_NOT_NULL(updateProxy);
       
  1474 	// Valid inputs
       
  1475 	for (TInt i = 0; i < aBuffers; ++i)
       
  1476 		{
       
  1477 		buffersIndex = (aBuffers + i) % aBuffers;
       
  1478 
       
  1479  		
       
  1480         updateProxy->ContentUpdated(surface,                    //aSurface
       
  1481                                     buffersIndex,               //aBuffer
       
  1482                                     NULL,                       //aRegion
       
  1483                                     NULL,                       //aStatusConsumed
       
  1484                                     NULL,                       //aStatusDisplayed
       
  1485                                     NULL,                       //aTimeStamp
       
  1486                                     NULL,                       //aStatusDispXTimes
       
  1487                                     NULL                        //aDisplayedXTimes
       
  1488                                     );	
       
  1489 		
       
  1490 		// The test can pass without a delay when running locally, but fails on ONB. Insert a delay here temporarily to see if it makes any difference
       
  1491         User::After(10000); //10 ms delay
       
  1492 		khronos_int32_t readBuffer;
       
  1493 		err = SymbianStreamAcquireReadBuffer(ns,&readBuffer);
       
  1494 		ASSERT_TRUE(err == KErrNone);
       
  1495 		err = SymbianStreamGetBufferId(ns,readBuffer,&bufferIndex,&getId);
       
  1496 		ASSERT_TRUE(err == KErrNone);
       
  1497 		err = SymbianStreamReleaseReadBuffer(ns, readBuffer);
       
  1498 		ASSERT_TRUE(err == KErrNone);
       
  1499 		ASSERT_TRUE(bufferIndex == buffersIndex);
       
  1500 		
       
  1501         // The test can pass without a delay when running locally, but fails on ONB. Insert a delay here temporarily to see if it makes any difference
       
  1502         User::After(10000); //10 ms delay
       
  1503 		ASSERT_EQUALS((i+1),localNumber);
       
  1504 		}
       
  1505 	
       
  1506 	// Reset number for negative tests
       
  1507 	localNumber = 0;
       
  1508 	lastValidBufnum = buffersIndex;
       
  1509 	
       
  1510 	// Invalid inputs
       
  1511 	TInt invalidBuffersIndex[] = {-1, -256, aBuffers+29, 10000, -10000, aBuffers};
       
  1512 	TInt size = sizeof(invalidBuffersIndex) / sizeof(invalidBuffersIndex[0]);
       
  1513 	
       
  1514 	for (TInt i = 0; i < size; ++i)
       
  1515 		{
       
  1516 		updateProxy->ContentUpdated(surface,                    //aSurface
       
  1517                                     invalidBuffersIndex[i],     //aBuffer
       
  1518                                     NULL,                       //aRegion
       
  1519                                     NULL,                       //aStatusConsumed
       
  1520                                     NULL,                       //aStatusDisplayed
       
  1521                                     NULL,                       //aTimeStamp
       
  1522                                     NULL,                       //aStatusDispXTimes
       
  1523                                     NULL                        //aDisplayedXTimes
       
  1524                                     );
       
  1525         
       
  1526 		User::After(10000); //10 ms delay
       
  1527 		khronos_int32_t readBuffer;
       
  1528 		err = SymbianStreamAcquireReadBuffer(ns,&readBuffer);
       
  1529 		ASSERT_TRUE(err == KErrNone);
       
  1530 		err = SymbianStreamGetBufferId(ns,readBuffer,&bufferIndex,&getId);
       
  1531 		ASSERT_TRUE(err == KErrNone);
       
  1532 		err = SymbianStreamReleaseReadBuffer(ns, readBuffer);
       
  1533 		ASSERT_TRUE(err == KErrNone);
       
  1534 		ASSERT_TRUE(bufferIndex == lastValidBufnum);
       
  1535 		ASSERT_EQUALS(0,localNumber);
       
  1536 		}
       
  1537 	SymbianStreamRemoveReference(ns);
       
  1538 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  1539 	}
       
  1540 
       
  1541 /**
       
  1542 @SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0109
       
  1543 @SYMTestCaseDesc		Test multiple acquire/release read/write buffer calls
       
  1544 @SYMREQ					
       
  1545 @SYMPREQ				PREQ2400
       
  1546 @SYMTestType			CT
       
  1547 @SYMTestPriority		
       
  1548 @SYMTestPurpose			Verify the buffer index is correctly set
       
  1549 @SYMTestActions	
       
  1550 		Create a surface with 4 buffers,
       
  1551 		Call acquire/release read/write buffer functions and to Submit an update to the surface
       
  1552 @SYMTestExpectedResults
       
  1553 		Verify that acquire/release read/write buffer functions honour SUS update
       
  1554 		Verify that the update callback function is called when the native stream is updated
       
  1555  **/		
       
  1556 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0109L()
       
  1557 	{
       
  1558 	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  1559 	TRAPD(err, GrowCleanupStackL());
       
  1560 	ASSERT_TRUE(err == KErrNone);
       
  1561 	
       
  1562 	iScreenNo = 0;
       
  1563 	TInt localNumber = 0;
       
  1564 	TInt count = 0;
       
  1565 	khronos_int32_t bufferIndexRead;
       
  1566 	khronos_int32_t bufferIndexWrite;
       
  1567 	
       
  1568 	TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  1569 	ASSERT_FALSE(surface.IsNull());
       
  1570 	
       
  1571 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  1572 	SymbianStreamType ns;
       
  1573 	err = SymbianStreamAcquire(&surface,&ns);
       
  1574 	ASSERT_TRUE(err == KErrNone);
       
  1575 	ASSERT_TRUE(ns);
       
  1576 	
       
  1577 	err = SymbianStreamAddObserver(ns, TestComposedCallback, &localNumber);
       
  1578 	ASSERT_TRUE(err == KErrNone);
       
  1579 	err = SymbianStreamAddObserver(ns, TestUpdateCallback, &localNumber);
       
  1580 	ASSERT_TRUE(err == KErrNone);
       
  1581 	
       
  1582 	khronos_int32_t readBuffer1;
       
  1583 	err = SymbianStreamAcquireReadBuffer(ns,&readBuffer1);
       
  1584 	ASSERT_TRUE(err == KErrNone);
       
  1585 	const TSurfaceId* getId = NULL;
       
  1586 	err = SymbianStreamGetBufferId(ns,readBuffer1,&bufferIndexRead,&getId);
       
  1587 	ASSERT_TRUE(err == KErrNone);
       
  1588 	err = SymbianStreamReleaseReadBuffer(ns, readBuffer1);
       
  1589 	ASSERT_TRUE(err == KErrNone);
       
  1590 	ASSERT_TRUE(bufferIndexRead == 0);
       
  1591 	
       
  1592 	khronos_int32_t writeBuffer1;
       
  1593 	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer1);
       
  1594 	ASSERT_TRUE(err == KErrNone);
       
  1595 	
       
  1596 	khronos_int32_t readBuffer2;
       
  1597 	err = SymbianStreamAcquireReadBuffer(ns,&readBuffer2);
       
  1598 	ASSERT_TRUE(err == KErrNone);
       
  1599 	err = SymbianStreamGetBufferId(ns,readBuffer2,&bufferIndexRead,&getId);
       
  1600 	ASSERT_TRUE(err == KErrNone);
       
  1601 	err = SymbianStreamReleaseReadBuffer(ns, readBuffer2);
       
  1602 	ASSERT_TRUE(err == KErrNone);
       
  1603 	ASSERT_TRUE(bufferIndexRead == 0);
       
  1604 	err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer1);
       
  1605 	ASSERT_TRUE(err == KErrNone);
       
  1606 	
       
  1607 	ASSERT_EQUALS((++count),localNumber);
       
  1608 	
       
  1609 	khronos_int32_t readBuffer3;
       
  1610 	err = SymbianStreamAcquireReadBuffer(ns,&readBuffer3);
       
  1611 	ASSERT_TRUE(err == KErrNone);
       
  1612 	err = SymbianStreamGetBufferId(ns,readBuffer3,&bufferIndexRead,&getId);
       
  1613 	ASSERT_TRUE(err == KErrNone);
       
  1614 	err = SymbianStreamReleaseReadBuffer(ns, readBuffer3);
       
  1615 	ASSERT_TRUE(err == KErrNone);
       
  1616 	ASSERT_TRUE(bufferIndexRead == 1);
       
  1617 	
       
  1618 	khronos_int32_t writeBuffer2;
       
  1619 	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer2);
       
  1620 	ASSERT_TRUE(err == KErrNone);
       
  1621 	err = SymbianStreamGetBufferId(ns,writeBuffer2,&bufferIndexWrite,&getId);
       
  1622 	ASSERT_TRUE(err == KErrNone);
       
  1623 	ASSERT_TRUE((bufferIndexRead + 1) == bufferIndexWrite);
       
  1624 	
       
  1625 	khronos_int32_t readBuffer4;
       
  1626 	err = SymbianStreamAcquireReadBuffer(ns,&readBuffer4);
       
  1627 	ASSERT_TRUE(err == KErrNone);
       
  1628 	err = SymbianStreamGetBufferId(ns,readBuffer4,&bufferIndexRead,&getId);
       
  1629 	ASSERT_TRUE(err == KErrNone);
       
  1630 	err = SymbianStreamReleaseReadBuffer(ns, readBuffer4);
       
  1631 	ASSERT_TRUE(err == KErrNone);
       
  1632 	ASSERT_TRUE(bufferIndexRead == (bufferIndexWrite - 1));
       
  1633 
       
  1634     CExtensionContainer* updateExtension = NULL;
       
  1635     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  1636     ASSERT_TRUE(err == KErrNone);
       
  1637     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  1638     ASSERT_NOT_NULL(updateProxy);
       
  1639     
       
  1640     updateProxy->ContentUpdated(surface,                    //aSurface
       
  1641                                 0,                          //aBuffer
       
  1642                                 NULL,                       //aRegion
       
  1643                                 NULL,                       //aStatusConsumed
       
  1644                                 NULL,                       //aStatusDisplayed
       
  1645                                 NULL,                       //aTimeStamp
       
  1646                                 NULL,                       //aStatusDispXTimes
       
  1647                                 NULL                        //aDisplayedXTimes
       
  1648                                 );  	
       
  1649 	
       
  1650 	ASSERT_EQUALS((++count),localNumber);
       
  1651 	
       
  1652 	khronos_int32_t readBuffer5;
       
  1653 	err = SymbianStreamAcquireReadBuffer(ns,&readBuffer5);
       
  1654 	ASSERT_TRUE(err == KErrNone);
       
  1655 	err = SymbianStreamGetBufferId(ns,readBuffer5,&bufferIndexRead,&getId);
       
  1656 	ASSERT_TRUE(err == KErrNone);
       
  1657 	err = SymbianStreamReleaseReadBuffer(ns, readBuffer5);
       
  1658 	ASSERT_TRUE(err == KErrNone);
       
  1659 	ASSERT_TRUE(bufferIndexRead == 0);
       
  1660 	err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer2);
       
  1661 	ASSERT_TRUE(err == KErrNone);
       
  1662 	
       
  1663 	ASSERT_EQUALS((++count),localNumber);
       
  1664 	
       
  1665 	khronos_int32_t readBuffer6;
       
  1666 	err = SymbianStreamAcquireReadBuffer(ns,&readBuffer6);
       
  1667 	ASSERT_TRUE(err == KErrNone);
       
  1668 	err = SymbianStreamGetBufferId(ns,readBuffer6,&bufferIndexRead,&getId);
       
  1669 	ASSERT_TRUE(err == KErrNone);
       
  1670 	err = SymbianStreamReleaseReadBuffer(ns, readBuffer6);
       
  1671 	ASSERT_TRUE(err == KErrNone);
       
  1672 	ASSERT_TRUE(bufferIndexRead == 0);
       
  1673 	
       
  1674 	khronos_int32_t writeBuffer3;
       
  1675 	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer3);
       
  1676 	ASSERT_TRUE(err == KErrNone);
       
  1677 	err = SymbianStreamGetBufferId(ns,writeBuffer3,&bufferIndexWrite,&getId);
       
  1678 	ASSERT_TRUE(err == KErrNone);
       
  1679 	ASSERT_TRUE(bufferIndexWrite == 1);
       
  1680 	err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer3);
       
  1681 	ASSERT_TRUE(err == KErrNone);
       
  1682 	
       
  1683 	khronos_int32_t readBuffer7;
       
  1684 	err = SymbianStreamAcquireReadBuffer(ns,&readBuffer7);
       
  1685 	ASSERT_TRUE(err == KErrNone);
       
  1686 	err = SymbianStreamGetBufferId(ns,readBuffer7,&bufferIndexRead,&getId);
       
  1687 	ASSERT_TRUE(err == KErrNone);
       
  1688 	err = SymbianStreamReleaseReadBuffer(ns, readBuffer7);
       
  1689 	ASSERT_TRUE(err == KErrNone);
       
  1690 	ASSERT_TRUE(bufferIndexRead == 1);
       
  1691 	
       
  1692 	SymbianStreamRemoveReference(ns);
       
  1693 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  1694 	}
       
  1695 
       
  1696 /**
       
  1697 @SYMTestCaseID			GFX_OPENWFC_NATIVESTREAM_0110
       
  1698 @SYMTestCaseDesc		Verify that the update observer callback function is called after a
       
  1699                         acquireWriteBuffer/releaseWriteBuffer call.
       
  1700 @SYMREQ					
       
  1701 @SYMPREQ				PREQ2400
       
  1702 @SYMTestType			CT
       
  1703 @SYMTestPriority		
       
  1704 @SYMTestPurpose			
       
  1705 @SYMTestActions	
       
  1706 		Create a surface with 1 buffer
       
  1707 		Add an observer to listen out for content updates to the stream
       
  1708 		Call acquire/release write buffer functions
       
  1709 @SYMTestExpectedResults
       
  1710 		Verify that the release write buffer function notifies any observers listening and the 
       
  1711 		observer callback function is called.
       
  1712  **/		
       
  1713 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0110L()
       
  1714 	{
       
  1715 	RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  1716 	TRAPD(err, GrowCleanupStackL());
       
  1717 	ASSERT_TRUE(err == KErrNone);
       
  1718 	
       
  1719 	TInt localNumber = 0;
       
  1720 	
       
  1721 	TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 1);
       
  1722 	ASSERT_FALSE(surface.IsNull());
       
  1723 	
       
  1724 	CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  1725 	SymbianStreamType ns;
       
  1726 	err = SymbianStreamAcquire(&surface,&ns);
       
  1727 	ASSERT_TRUE(err == KErrNone);
       
  1728 	ASSERT_TRUE(ns);
       
  1729 	
       
  1730 	err = SymbianStreamAddObserver(ns, TestComposedCallback, &localNumber);
       
  1731 	ASSERT_TRUE(err == KErrNone);
       
  1732 	
       
  1733 	khronos_int32_t writeBuffer1;
       
  1734 	err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer1);
       
  1735 	ASSERT_TRUE(err == KErrNone);
       
  1736 	err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer1);
       
  1737 	ASSERT_TRUE(err == KErrNone);
       
  1738 	
       
  1739 	if (localNumber == 0)
       
  1740 		{
       
  1741 		User::After(1000000);
       
  1742 		}
       
  1743 	
       
  1744 	ASSERT_TRUE(localNumber == 1);    
       
  1745 	SymbianStreamRemoveReference(ns);
       
  1746 	CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  1747 	}
       
  1748 
       
  1749 /**
       
  1750 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0111
       
  1751 @SYMTestCaseDesc        Tests various cases including some negative cases for Native Stream callbacks
       
  1752 @SYMREQ                 
       
  1753 @SYMPREQ                PREQ2400
       
  1754 @SYMTestType            CT
       
  1755 @SYMTestPriority        
       
  1756 @SYMTestPurpose         
       
  1757 @SYMTestActions 
       
  1758         Create a surface with 1 buffer
       
  1759         Add an observer N times
       
  1760         Remove the same observer M (M <= N) times
       
  1761         Register Null observer
       
  1762         Unregister something that was never registered
       
  1763 @SYMTestExpectedResults
       
  1764         Verify that the observer is called (N - M) times
       
  1765         Verify that error case behaviour is correct
       
  1766  **/        
       
  1767 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0111L()
       
  1768     {
       
  1769     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  1770     TRAPD(err, GrowCleanupStackL());
       
  1771     ASSERT_TRUE(err == KErrNone);
       
  1772     
       
  1773     iScreenNo = 0;
       
  1774     
       
  1775     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 1);
       
  1776     ASSERT_FALSE(surface.IsNull());
       
  1777     
       
  1778     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  1779     SymbianStreamType ns;
       
  1780     err = SymbianStreamAcquire(&surface,&ns);
       
  1781     ASSERT_TRUE(err == KErrNone);    
       
  1782     ASSERT_TRUE(ns);
       
  1783     
       
  1784     TInt localNumber = 0;
       
  1785     err = SymbianStreamAddObserver(ns, NULL, &localNumber);
       
  1786     ASSERT_TRUE(err == KErrBadHandle);
       
  1787     err = SymbianStreamRemoveObserver(ns, &localNumber, ESOWF_EventComposed);
       
  1788     ASSERT_TRUE(err == KErrNotFound);
       
  1789     err = SymbianStreamRemoveObserver(ns, NULL, ESOWF_EventComposed);
       
  1790     ASSERT_TRUE(err == KErrNotFound);
       
  1791     err = SymbianStreamAddObserver(ns, TestUpdateCallback, &localNumber);
       
  1792     ASSERT_TRUE(err == KErrNone);
       
  1793     err = SymbianStreamRemoveObserver(ns, &localNumber, ESOWF_EventUpdated);
       
  1794     ASSERT_TRUE(err == KErrNone);
       
  1795     err = SymbianStreamRemoveObserver(ns, &localNumber, ESOWF_EventUpdated);
       
  1796     ASSERT_TRUE(err == KErrNotFound);
       
  1797     
       
  1798 #define N_TIMES 7
       
  1799 #define M_TIMES 3
       
  1800     
       
  1801     localNumber = 0;
       
  1802     TInt k = N_TIMES;
       
  1803     while (k--)
       
  1804         {
       
  1805         err = SymbianStreamAddObserver(ns, TestUpdateCallback, &localNumber);
       
  1806         ASSERT_TRUE(err != KErrBadHandle);
       
  1807         }
       
  1808     k = M_TIMES;
       
  1809 
       
  1810     CExtensionContainer* updateExtension = NULL;
       
  1811     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  1812     ASSERT_TRUE(err == KErrNone);
       
  1813     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  1814     ASSERT_NOT_NULL(updateProxy);
       
  1815     
       
  1816     updateProxy->ContentUpdated(surface,                    //aSurface
       
  1817                                 0,                          //aBuffer
       
  1818                                 NULL,                       //aRegion
       
  1819                                 NULL,                       //aStatusConsumed
       
  1820                                 NULL,                       //aStatusDisplayed
       
  1821                                 NULL,                       //aTimeStamp
       
  1822                                 NULL,                       //aStatusDispXTimes
       
  1823                                 NULL                        //aDisplayedXTimes
       
  1824                                 );  
       
  1825     
       
  1826     User::After(10000);
       
  1827     ASSERT_TRUE(localNumber == 1);
       
  1828     
       
  1829     while (k--)
       
  1830         {
       
  1831         err = SymbianStreamRemoveObserver(ns, &localNumber, ESOWF_EventUpdated);
       
  1832         ASSERT_TRUE(err != KErrBadHandle);
       
  1833         }
       
  1834     
       
  1835     updateProxy->ContentUpdated(surface,                    //aSurface
       
  1836                                 0,                          //aBuffer
       
  1837                                 NULL,                       //aRegion
       
  1838                                 NULL,                       //aStatusConsumed
       
  1839                                 NULL,                       //aStatusDisplayed
       
  1840                                 NULL,                       //aTimeStamp
       
  1841                                 NULL,                       //aStatusDispXTimes
       
  1842                                 NULL                        //aDisplayedXTimes
       
  1843                                 );      
       
  1844     
       
  1845     ASSERT_TRUE(localNumber == 1);
       
  1846     
       
  1847     SymbianStreamRemoveReference(ns);
       
  1848     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  1849     }
       
  1850 
       
  1851 /**
       
  1852 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0112
       
  1853 @SYMTestCaseDesc        Tests multithreaded cases for Native Stream callbacks
       
  1854 @SYMREQ                 
       
  1855 @SYMPREQ                PREQ2400
       
  1856 @SYMTestType            CT
       
  1857 @SYMTestPriority        
       
  1858 @SYMTestPurpose         
       
  1859 @SYMTestActions 
       
  1860         Create 3 threads and call add, remove, notify observers from
       
  1861         respective threads multiple times
       
  1862 @SYMTestExpectedResults
       
  1863         Verify that the observers work correctly in multithreaded environment
       
  1864  **/
       
  1865 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0112_1L()
       
  1866     {
       
  1867     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  1868     TRAPD(err, GrowCleanupStackL());
       
  1869     ASSERT_TRUE(err == KErrNone);
       
  1870         
       
  1871     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  1872     
       
  1873     INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_1L: Thread 1 start, Register Observer"));
       
  1874     TSurfaceId surface = gVarInstance.SurfaceID();
       
  1875     SymbianStreamType ns;
       
  1876     err = SymbianStreamAcquire(&surface,&ns);
       
  1877     ASSERT_TRUE(err == KErrNone);
       
  1878     ASSERT_TRUE(ns);
       
  1879     
       
  1880     gVarInstance.iMultithreadCounter = 0;
       
  1881 
       
  1882     TTimeIntervalMicroSeconds32 delay(32000), zeroDelay(0);
       
  1883     while (delay >= zeroDelay)
       
  1884         {
       
  1885         INFO_PRINTF2(_L("Thread 1 is going to add another observer after %i microsecond"), delay.Int());
       
  1886         User::AfterHighRes(delay);
       
  1887         SymbianStreamAddObserver(ns, TestUpdateCallback, &gVarInstance.iMultithreadCounter);
       
  1888         delay = delay.Int() - 43;
       
  1889         }
       
  1890     TInt count = 50;
       
  1891     while (count--)
       
  1892         {
       
  1893         INFO_PRINTF1(_L("Thread 1 is going to add another observer without delay"));
       
  1894         SymbianStreamAddObserver(ns, TestUpdateCallback, &gVarInstance.iMultithreadCounter);
       
  1895         }
       
  1896     INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_1L: Thread 1 exits"));
       
  1897     
       
  1898     SymbianStreamRemoveReference(ns);
       
  1899     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  1900     }
       
  1901 
       
  1902 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0112_2L()
       
  1903     {
       
  1904     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  1905     TRAPD(err, GrowCleanupStackL());
       
  1906     ASSERT_TRUE(err == KErrNone);
       
  1907 
       
  1908     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  1909     
       
  1910     INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_2L: Thread 2 start, Unregister Observer"));
       
  1911     TSurfaceId surface = gVarInstance.SurfaceID();
       
  1912     SymbianStreamType ns;
       
  1913     err = SymbianStreamAcquire(&surface,&ns);
       
  1914     ASSERT_TRUE(err == KErrNone);
       
  1915     ASSERT_TRUE(ns);
       
  1916     
       
  1917     TTimeIntervalMicroSeconds32 delay(32000), zeroDelay(0);
       
  1918     while (delay > zeroDelay)
       
  1919         {
       
  1920         INFO_PRINTF2(_L("Thread 2 is going to remove one observer after %i microsecond"), delay.Int());
       
  1921         User::AfterHighRes(delay);
       
  1922         SymbianStreamRemoveObserver(ns, &gVarInstance.iMultithreadCounter, ESOWF_EventUpdated);
       
  1923         delay = delay.Int() - 49;
       
  1924         }
       
  1925     TInt count = 50;
       
  1926     while (count--)
       
  1927         {
       
  1928         INFO_PRINTF1(_L("Thread 2 is going to remove one observer without delay"));
       
  1929         SymbianStreamRemoveObserver(ns, &gVarInstance.iMultithreadCounter, ESOWF_EventUpdated);
       
  1930         }
       
  1931     INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_2L: Thread 2 exits"));    
       
  1932     SymbianStreamRemoveReference(ns);
       
  1933     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  1934     }
       
  1935 
       
  1936 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0112_3L()
       
  1937     {
       
  1938     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  1939     TRAPD(err, GrowCleanupStackL());
       
  1940     ASSERT_TRUE(err == KErrNone);
       
  1941 
       
  1942     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  1943     
       
  1944     INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_2L: Thread 3 start, Notify Observer"));
       
  1945     TSurfaceId surface = gVarInstance.SurfaceID();
       
  1946     SymbianStreamType ns;
       
  1947     err = SymbianStreamAcquire(&surface,&ns);
       
  1948     ASSERT_TRUE(err == KErrNone);
       
  1949     ASSERT_TRUE(ns);
       
  1950     
       
  1951     khronos_int32_t bufferIndex;
       
  1952     TTimeIntervalMicroSeconds32 delay(32000), zeroDelay(0);
       
  1953     while (delay > zeroDelay)
       
  1954         {
       
  1955         khronos_int32_t writeBuffer;
       
  1956         err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer);
       
  1957         ASSERT_TRUE(err == KErrNone);
       
  1958         const TSurfaceId* getId = NULL;
       
  1959         err = SymbianStreamGetBufferId(ns,writeBuffer,&bufferIndex,&getId);
       
  1960         ASSERT_TRUE(err == KErrNone);
       
  1961         INFO_PRINTF2(_L("Thread 3 - Write buffer %i acquired"), bufferIndex);
       
  1962         
       
  1963         INFO_PRINTF2(_L("Thread 3 going to send notification after %i second"), delay.Int());
       
  1964         User::AfterHighRes(delay);
       
  1965         delay = delay.Int() - 58;
       
  1966         err = SymbianStreamReleaseWriteBuffer(ns, writeBuffer);
       
  1967         ASSERT_TRUE(err == KErrNone);
       
  1968         }
       
  1969     TInt count = 50;
       
  1970     while (count--)
       
  1971         {
       
  1972         khronos_int32_t writeBuffer;
       
  1973         err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer);
       
  1974         ASSERT_TRUE(err == KErrNone);
       
  1975         const TSurfaceId* getId = NULL;
       
  1976         err = SymbianStreamGetBufferId(ns,writeBuffer,&bufferIndex,&getId);
       
  1977         ASSERT_TRUE(err == KErrNone);
       
  1978         INFO_PRINTF2(_L("Thread 3 - Write buffer %i acquired"), bufferIndex);
       
  1979         
       
  1980         INFO_PRINTF1(_L("Thread 3 going to send notification without delay"));
       
  1981         err = SymbianStreamReleaseWriteBuffer(ns, writeBuffer);
       
  1982         ASSERT_TRUE(err == KErrNone);
       
  1983         }
       
  1984     INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_2L: Thread 3 exits"));
       
  1985     
       
  1986     SymbianStreamRemoveReference(ns);
       
  1987     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  1988     }
       
  1989 
       
  1990 /**
       
  1991 Submit updates to the native stream whilst observers are being added and removed. 
       
  1992 Do not run in parallel with 0112_3L 
       
  1993 */
       
  1994 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0112_4L()
       
  1995     {
       
  1996     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  1997     TRAPD(err, GrowCleanupStackL());
       
  1998     ASSERT_TRUE(err == KErrNone);
       
  1999 
       
  2000     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  2001     
       
  2002     INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_2L: Thread 3 start, Notify Observer"));
       
  2003     
       
  2004     TTimeIntervalMicroSeconds32 delay(32000), zeroDelay(0);
       
  2005     
       
  2006     iScreenNo = 0;
       
  2007     TRequestStatus displayedStatus, availableStatus, displayedXStatus;
       
  2008     TUint32 timeStamp = 0;
       
  2009     TInt bufferNo = 0;
       
  2010     TInt numBuffers = 2;
       
  2011     TInt displayedX = 5;
       
  2012 
       
  2013     CExtensionContainer* updateExtension = NULL;
       
  2014     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  2015     ASSERT_TRUE(err == KErrNone);
       
  2016     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  2017     ASSERT_NOT_NULL(updateProxy);
       
  2018     
       
  2019     while (delay > zeroDelay)
       
  2020         {        
       
  2021         INFO_PRINTF2(_L("Thread 0112_4 submitting update after %i second"), delay.Int());
       
  2022         User::AfterHighRes(delay);
       
  2023         delay = delay.Int() - 58;                
       
  2024         
       
  2025         updateProxy->ContentUpdated(gVarInstance.SurfaceID(),                    //aSurface
       
  2026                                     bufferNo,                   //aBuffer
       
  2027                                     NULL,                       //aRegion
       
  2028                                     &availableStatus,           //aStatusConsumed
       
  2029                                     &displayedStatus,           //aStatusDisplayed
       
  2030                                     &timeStamp,                 //aTimeStamp
       
  2031                                     &displayedXStatus,          //aStatusDispXTimes
       
  2032                                     &displayedX                 //aDisplayedXTimes
       
  2033                                     );                
       
  2034         
       
  2035         bufferNo = (bufferNo + 1) % numBuffers;        
       
  2036         }   
       
  2037     
       
  2038     TInt count = 50;
       
  2039     while (count--)
       
  2040         {
       
  2041         INFO_PRINTF1(_L("Thread 0112_4 Set notifications"));
       
  2042         INFO_PRINTF1(_L("Thread 0112_4 submitting update without delay"));
       
  2043 
       
  2044         updateProxy->ContentUpdated(gVarInstance.SurfaceID(),   //aSurface
       
  2045                                     bufferNo,                   //aBuffer
       
  2046                                     NULL,                       //aRegion
       
  2047                                     &availableStatus,           //aStatusConsumed
       
  2048                                     &displayedStatus,           //aStatusDisplayed
       
  2049                                     &timeStamp,                 //aTimeStamp
       
  2050                                     &displayedXStatus,          //aStatusDispXTimes
       
  2051                                     &displayedX                 //aDisplayedXTimes
       
  2052                                     );         
       
  2053         
       
  2054         bufferNo = (bufferNo + 1) % numBuffers;
       
  2055         }    
       
  2056     INFO_PRINTF1(_L("GRAPHICS_OPENWFC_NATIVESTREAM_0112_4L: Thread exits"));
       
  2057     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  2058     }
       
  2059 
       
  2060 /**
       
  2061 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0113
       
  2062 @SYMTestCaseDesc        Test displayed notification
       
  2063 @SYMREQ                 
       
  2064 @SYMPREQ                PREQ2400
       
  2065 @SYMTestType            CT
       
  2066 @SYMTestPriority        High
       
  2067 @SYMTestPurpose         Tests an end to end displayed notification.
       
  2068 @SYMTestActions
       
  2069 
       
  2070      1.  Create a surface
       
  2071      2.  Create a native stream for the surface
       
  2072      3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  2073      4.  Register for displayed notifications
       
  2074      5.  Submit an update to the surface
       
  2075      6.  The observer function should be invoked and verifies that stream and event parameters.
       
  2076      7.  The tester simulates the end of a composition by firing owfNativeStreanProcessNotifications
       
  2077      8.  Wait on the displayed request status. 
       
  2078      9.  Remove the source stream updated observer
       
  2079      10. Destroy the native stream.
       
  2080      
       
  2081      The test is then repeated but the compositor claims the native stream is not visible.
       
  2082         
       
  2083 @SYMTestExpectedResults
       
  2084     No errors, displayed status completed with KErrNone.
       
  2085         
       
  2086  **/
       
  2087 
       
  2088 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0113L()
       
  2089     {
       
  2090     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  2091     TRAPD(err, GrowCleanupStackL());
       
  2092     ASSERT_TRUE(err == KErrNone);
       
  2093     
       
  2094     iSourceStreamUpdatedCalled = 0;
       
  2095     iImmediateAvailable = EFalse;
       
  2096     iImmediateVisible = SYM_CONTENT_NOT_VISIBLE;
       
  2097     iContextUpdatedFlags = 0;
       
  2098     iScreenNo = 0;    
       
  2099     
       
  2100     for (TInt i = 0; i < 2; ++i)
       
  2101         {
       
  2102         TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  2103         ASSERT_FALSE(surface.IsNull());
       
  2104         CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  2105         
       
  2106         CTestNativeStream::iTester = this;
       
  2107         TBool visible = (i == 0);
       
  2108         
       
  2109         RHeap* threadHeap3 = &User::Heap();
       
  2110         err = SymbianStreamAcquire(&surface,&iNs);
       
  2111         ASSERT_TRUE(err == KErrNone);
       
  2112         ASSERT_TRUE(iNs);
       
  2113         
       
  2114         iExpectedSourceStreamUpdatedEventMask = 0;
       
  2115         err = SymbianStreamAddObserver(iNs, SourceStreamUpdatedCallback, this);
       
  2116         ASSERT_TRUE(err == KErrNone);
       
  2117         
       
  2118         TRequestStatus statusDisplayed;
       
  2119         TUint32 displayedTime;    
       
  2120 
       
  2121         CExtensionContainer* updateExtension = NULL;
       
  2122         err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  2123         ASSERT_TRUE(err == KErrNone);
       
  2124         MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  2125         ASSERT_NOT_NULL(updateProxy);
       
  2126         
       
  2127         iSourceStreamUpdatedCalled = 0;
       
  2128         updateProxy->ContentUpdated(surface,                    //aSurface
       
  2129                                     0,                          //aBuffer
       
  2130                                     NULL,                       //aRegion
       
  2131                                     NULL,                       //aStatusConsumed
       
  2132                                     &statusDisplayed,           //aStatusDisplayed
       
  2133                                     &displayedTime,             //aTimeStamp
       
  2134                                     NULL,                       //aStatusDispXTimes
       
  2135                                     NULL                        //aDisplayedXTimes
       
  2136                                     );
       
  2137         
       
  2138         ASSERT_TRUE(iSourceStreamUpdatedCalled == 1);
       
  2139         err = SymbianStreamRemoveObserver(iNs, this, ESOWF_EventUpdated);
       
  2140         ASSERT_TRUE(err == KErrNone);
       
  2141     
       
  2142         iExpectedSourceStreamUpdatedEventMask = ESOWF_EventDisplayed;
       
  2143         err = SymbianStreamAddExtendedObserver(iNs, SourceStreamUpdatedCallback, this, iScreenNo, ESOWF_EventUpdated);
       
  2144         ASSERT_TRUE(err == KErrNone);
       
  2145     
       
  2146         updateProxy->ContentUpdated(surface,                    //aSurface
       
  2147                                     0,                          //aBuffer
       
  2148                                     NULL,                       //aRegion
       
  2149                                     NULL,                       //aStatusConsumed
       
  2150                                     &statusDisplayed,           //aStatusDisplayed
       
  2151                                     &displayedTime,             //aTimeStamp
       
  2152                                     NULL,                       //aStatusDispXTimes
       
  2153                                     NULL                        //aDisplayedXTimes
       
  2154                                     );
       
  2155         
       
  2156         ASSERT_TRUE(iSourceStreamUpdatedCalled);
       
  2157         
       
  2158         // Pretend that a composition has occured
       
  2159         ++iStreamUpdatedSerialNumber; 
       
  2160         if (visible)
       
  2161             {
       
  2162             khronos_int32_t newNotificationsMask = 0;
       
  2163             SymbianStreamProcessNotifications(iNs, 
       
  2164                                                 ESOWF_EventDisplayed,
       
  2165                                                 iScreenNo,
       
  2166                                                 iStreamUpdatedSerialNumber, 
       
  2167                                                 &newNotificationsMask);
       
  2168     
       
  2169             // No updates during composition so newNotificationMask should still be zero 
       
  2170             ASSERT_TRUE(newNotificationsMask == 0);
       
  2171             }        
       
  2172         // Simulate multiple sources
       
  2173         SymbianStreamCheckVisible(iNs, ESOWF_EventDisplayed, iScreenNo, iStreamUpdatedSerialNumber); 
       
  2174         SymbianStreamCheckVisible(iNs, ESOWF_EventDisplayed, iScreenNo, iStreamUpdatedSerialNumber);
       
  2175         
       
  2176         // Make sure displayed event was completed
       
  2177         User::WaitForRequest(statusDisplayed);
       
  2178         if (visible)
       
  2179             {
       
  2180             ASSERT_EQUALS(statusDisplayed.Int(), KErrNone);
       
  2181             }
       
  2182         else
       
  2183             {
       
  2184             ASSERT_EQUALS(statusDisplayed.Int(), KErrNotVisible);
       
  2185             }
       
  2186         
       
  2187         err = SymbianStreamRemoveObserver(iNs, this, ESOWF_EventUpdated);
       
  2188         ASSERT_TRUE(err == KErrNone);
       
  2189         SymbianStreamRemoveReference(iNs);
       
  2190         CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one   
       
  2191         iUtility->DestroySurface(surface);
       
  2192         }
       
  2193     }
       
  2194 
       
  2195 /**
       
  2196 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0114
       
  2197 @SYMTestCaseDesc        Test available notification
       
  2198 @SYMREQ                 
       
  2199 @SYMPREQ                PREQ2400
       
  2200 @SYMTestType            CT
       
  2201 @SYMTestPriority        High
       
  2202 @SYMTestPurpose         Tests an end to end available notification.
       
  2203 @SYMTestActions
       
  2204 
       
  2205      1.  Create a surface
       
  2206      2.  Create a native stream for the surface
       
  2207      3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  2208      4.  Register for displayed notifications
       
  2209      5.  Submit an update to the surface
       
  2210      6.  The observer function should be invoked and verifies that stream and event parameters.
       
  2211      7.  The tester simulates the end of a composition by firing owfNativeStreanProcessNotifications
       
  2212      8.  Verify that available notification has not been sent.
       
  2213      9.  Send another display update to change the read buffer to buffer 1
       
  2214      10. Verify that the source-stream updated callback is invoked.
       
  2215      11. The tester simulates the end of a composition by firing owfNativeStreanProcessNotifications
       
  2216      12. Wait for available status to be completed
       
  2217      13. Remove the source stream updated observer
       
  2218      14. Destroy the native stream.
       
  2219      
       
  2220      The test is then repeated but the compositor claims the native stream is not visible.
       
  2221         
       
  2222 @SYMTestExpectedResults
       
  2223     No errors, available status completed with KErrNone.
       
  2224         
       
  2225  **/
       
  2226 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0114L()
       
  2227     {  
       
  2228     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  2229     TRAPD(err, GrowCleanupStackL());
       
  2230     ASSERT_TRUE(err == KErrNone);
       
  2231     
       
  2232     iScreenNo = 0;
       
  2233     iContextUpdatedFlags = 0;
       
  2234     iStreamUpdatedSerialNumber = 1;
       
  2235     iSourceStreamUpdatedCalled = 0;
       
  2236     // during compositio or first time after a commit
       
  2237     iImmediateAvailable = EFalse;
       
  2238     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  2239     
       
  2240     for (TInt i = 0; i < 2; ++i)
       
  2241         {
       
  2242         TBool visible = (i == 0);
       
  2243         TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  2244         ASSERT_FALSE(surface.IsNull());
       
  2245         CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  2246         
       
  2247         CTestNativeStream::iTester = this;
       
  2248         
       
  2249         err = SymbianStreamAcquire(&surface,&iNs);
       
  2250         ASSERT_TRUE(err == KErrNone);
       
  2251         ASSERT_TRUE(iNs);
       
  2252         
       
  2253         err = SymbianStreamAddExtendedObserver(iNs, SourceStreamUpdatedCallback, this, iScreenNo, ESOWF_EventUpdated);
       
  2254         ASSERT_TRUE(err == KErrNone);
       
  2255         
       
  2256         TRequestStatus statusAvailable;
       
  2257         iSourceStreamUpdatedCalled = 0;
       
  2258 
       
  2259         CExtensionContainer* updateExtension = NULL;
       
  2260         err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  2261         ASSERT_TRUE(err == KErrNone);
       
  2262         MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  2263         ASSERT_NOT_NULL(updateProxy);
       
  2264         
       
  2265         ASSERT_TRUE(iSourceStreamUpdatedCalled == 0);
       
  2266         
       
  2267         iExpectedSourceStreamUpdatedEventMask = 0;
       
  2268         //we are during a composition
       
  2269         ++iStreamUpdatedSerialNumber;
       
  2270         updateProxy->ContentUpdated(surface,                    //aSurface
       
  2271                                     0,                          //aBuffer
       
  2272                                     NULL,                       //aRegion
       
  2273                                     &statusAvailable,           //aStatusConsumed
       
  2274                                     NULL,                       //aStatusDisplayed
       
  2275                                     NULL,                       //aTimeStamp
       
  2276                                     NULL,                       //aStatusDispXTimes
       
  2277                                     NULL                        //aDisplayedXTimes
       
  2278                                     );
       
  2279         
       
  2280         // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  2281         ASSERT_TRUE(iSourceStreamUpdatedCalled == 2);
       
  2282         
       
  2283         // Available should only be compled when submit update is called with a different buffer no.
       
  2284         // if the stream is multi-buffered.
       
  2285         ASSERT_EQUALS(statusAvailable.Int(), KRequestPending);
       
  2286         
       
  2287         // Pretend that a composition has occured
       
  2288         khronos_int32_t newNotificationsMask = 0;
       
  2289         if (visible)
       
  2290             {            
       
  2291             SymbianStreamProcessNotifications(iNs, 
       
  2292                                               0, 
       
  2293                                               iScreenNo,
       
  2294                                               iStreamUpdatedSerialNumber,
       
  2295                                               &newNotificationsMask);
       
  2296     
       
  2297             // No updates during composition so newNotificationMask should still be zero 
       
  2298             ASSERT_TRUE(newNotificationsMask == 0);
       
  2299             SymbianStreamProcessNotifications(iNs, 
       
  2300                                               0, 
       
  2301                                               iScreenNo,
       
  2302                                               iStreamUpdatedSerialNumber,
       
  2303                                               &newNotificationsMask);
       
  2304     
       
  2305             // No updates during composition so newNotificationMask should still be zero 
       
  2306             ASSERT_TRUE(newNotificationsMask == 0);
       
  2307             }
       
  2308         SymbianStreamCheckVisible(iNs, ESOWF_EventAvailable, iScreenNo, iStreamUpdatedSerialNumber); 
       
  2309         SymbianStreamCheckVisible(iNs, ESOWF_EventAvailable, iScreenNo, iStreamUpdatedSerialNumber);        
       
  2310                 
       
  2311         // Available for buffer zero should not be completed yet
       
  2312         ASSERT_EQUALS(statusAvailable.Int(), KRequestPending);
       
  2313         
       
  2314         // Update and switch to buffer 1
       
  2315         iExpectedSourceStreamUpdatedEventMask = ESOWF_EventAvailable;
       
  2316         //we are during a composition
       
  2317         ++iStreamUpdatedSerialNumber;
       
  2318         updateProxy->ContentUpdated(surface,                    //aSurface
       
  2319                                     1,                          //aBuffer
       
  2320                                     NULL,                       //aRegion
       
  2321                                     NULL,                       //aStatusConsumed
       
  2322                                     NULL,                       //aStatusDisplayed
       
  2323                                     NULL,                       //aTimeStamp
       
  2324                                     NULL,                       //aStatusDispXTimes
       
  2325                                     NULL                        //aDisplayedXTimes
       
  2326                                     );
       
  2327         
       
  2328         ASSERT_TRUE(iSourceStreamUpdatedCalled == 4);
       
  2329         
       
  2330         // Consume update on buffer 1. This should make buffer 0 available
       
  2331         if (visible)
       
  2332             {
       
  2333             SymbianStreamProcessNotifications(iNs, 
       
  2334                                                 ESOWF_EventAvailable, 
       
  2335                                                 iScreenNo,
       
  2336                                                 iStreamUpdatedSerialNumber,
       
  2337                                                 &newNotificationsMask);
       
  2338             
       
  2339             ASSERT_TRUE(newNotificationsMask == 0);
       
  2340 
       
  2341             SymbianStreamProcessNotifications(iNs, 
       
  2342                                                 0, 
       
  2343                                                 iScreenNo,
       
  2344                                                 ++iStreamUpdatedSerialNumber,
       
  2345                                                 &newNotificationsMask);
       
  2346             ASSERT_TRUE(newNotificationsMask == 0);
       
  2347             }
       
  2348         SymbianStreamCheckVisible(iNs, ESOWF_EventAvailable, iScreenNo, iStreamUpdatedSerialNumber); 
       
  2349         SymbianStreamCheckVisible(iNs, ESOWF_EventAvailable, iScreenNo, iStreamUpdatedSerialNumber);        
       
  2350         
       
  2351         // Make sure displayed event was completed
       
  2352         User::WaitForRequest(statusAvailable);
       
  2353         if (visible)
       
  2354             {
       
  2355             ASSERT_EQUALS(statusAvailable.Int(), KErrNone);
       
  2356             }
       
  2357         else
       
  2358             {
       
  2359             ASSERT_EQUALS(statusAvailable.Int(), KErrNotVisible);
       
  2360             }
       
  2361 
       
  2362         err = SymbianStreamRemoveObserver(iNs, this, ESOWF_EventUpdated);
       
  2363         ASSERT_TRUE(err == KErrNone);
       
  2364         SymbianStreamRemoveReference(iNs);
       
  2365         CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one    
       
  2366         iUtility->DestroySurface(surface);
       
  2367         }
       
  2368     }
       
  2369 
       
  2370 /**
       
  2371 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0115
       
  2372 @SYMTestCaseDesc        Test displayed x times notification
       
  2373 @SYMREQ                 
       
  2374 @SYMPREQ                PREQ2400
       
  2375 @SYMTestType            CT
       
  2376 @SYMTestPriority        High
       
  2377 @SYMTestPurpose         Verify that the surface stream adaptation processes displayed x times
       
  2378                         notifications correctly.
       
  2379 @SYMTestActions
       
  2380 
       
  2381      1.  Create a surface
       
  2382      2.  Create a native stream for the surface
       
  2383      3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  2384      4.  Register for displayed notifications
       
  2385      5.  Submit an update to the surface
       
  2386      6.  The observer function should be invoked and verifies that stream and event parameters.
       
  2387      7.  The tester simulates the end of a composition by firing SymbianStreamProcessNotifications
       
  2388      8.  If X has not been reached yet verify that displayed x status is not completed then goto 6. 
       
  2389          Otherwise, goto step 9.   
       
  2390      9.  Verify displayed-x-times status is completed with KErrNone
       
  2391      10. Remove the observer
       
  2392      11. Destroy the native stream.
       
  2393      
       
  2394      The test is then repeated but the compositor claims the native stream is not visible.
       
  2395         
       
  2396 @SYMTestExpectedResults
       
  2397     No errors, displayed-x-times status completed with KErrNone.
       
  2398         
       
  2399 */
       
  2400 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0115L()
       
  2401     {
       
  2402     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  2403     TRAPD(err, GrowCleanupStackL());
       
  2404     ASSERT_TRUE(err == KErrNone);
       
  2405     
       
  2406     iScreenNo = 0;  
       
  2407     iContextUpdatedFlags = 0;
       
  2408     iStreamUpdatedSerialNumber = 1;
       
  2409     iImmediateAvailable = EFalse;
       
  2410     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  2411     
       
  2412     for (TInt i = 0; i < 2; ++i)
       
  2413         {
       
  2414         TBool visible = (i == 0);        
       
  2415         iSourceStreamUpdatedCalled = 0;
       
  2416         TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  2417         ASSERT_FALSE(surface.IsNull());
       
  2418         
       
  2419         CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  2420         err = SymbianStreamAcquire(&surface, &iNs);
       
  2421         ASSERT_TRUE(err == KErrNone);
       
  2422         ASSERT_TRUE(iNs);
       
  2423     
       
  2424         err = SymbianStreamAddExtendedObserver(iNs, SourceStreamUpdatedCallback, this, iScreenNo, ESOWF_EventUpdated);
       
  2425         ASSERT_TRUE(err == KErrNone);
       
  2426         
       
  2427         TRequestStatus statusDisplayedX;
       
  2428         TInt X = 5;
       
  2429 
       
  2430         CExtensionContainer* updateExtension = NULL;
       
  2431         err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  2432         ASSERT_TRUE(err == KErrNone);
       
  2433         MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  2434         ASSERT_NOT_NULL(updateProxy);
       
  2435         
       
  2436         iExpectedSourceStreamUpdatedEventMask = ESOWF_EventDisplayedX;
       
  2437         
       
  2438         updateProxy->ContentUpdated(surface,                    //aSurface
       
  2439                                     0,                          //aBuffer
       
  2440                                     NULL,                       //aRegion
       
  2441                                     NULL,                       //aStatusConsumed
       
  2442                                     NULL,                       //aStatusDisplayed
       
  2443                                     NULL,                       //aTimeStamp
       
  2444                                     &statusDisplayedX,          //aStatusDispXTimes
       
  2445                                     &X                          //aDisplayedXTimes
       
  2446                                     );        
       
  2447         
       
  2448         ASSERT_TRUE(iSourceStreamUpdatedCalled == 2);
       
  2449         
       
  2450         
       
  2451         khronos_int32_t events = ESOWF_EventDisplayedX;
       
  2452         for (TInt i = 0; i < X; ++i)
       
  2453             {            
       
  2454             // Pretend that a composition has occured
       
  2455             ++iStreamUpdatedSerialNumber;
       
  2456             
       
  2457             if (visible)
       
  2458                 {
       
  2459                 khronos_int32_t newNotificationsMask = 0;                        
       
  2460                 SymbianStreamProcessNotifications(iNs, 
       
  2461                                                     events, 
       
  2462                                                     iScreenNo, 
       
  2463                                                     iStreamUpdatedSerialNumber,
       
  2464                                                     &newNotificationsMask);
       
  2465             
       
  2466                 SymbianStreamCheckVisible(iNs, events, iScreenNo, iStreamUpdatedSerialNumber); 
       
  2467                 SymbianStreamCheckVisible(iNs, events, iScreenNo, iStreamUpdatedSerialNumber);   
       
  2468                 
       
  2469                 if (i < X -1)
       
  2470                     {
       
  2471                     ASSERT_TRUE(newNotificationsMask == ESOWF_EventDisplayedX);
       
  2472                     ASSERT_EQUALS(statusDisplayedX.Int(), KRequestPending);
       
  2473                     }
       
  2474                 else
       
  2475                     {
       
  2476                     ASSERT_TRUE(newNotificationsMask == 0);
       
  2477                     User::WaitForRequest(statusDisplayedX);
       
  2478                     ASSERT_EQUALS(statusDisplayedX.Int(), KErrNone);            
       
  2479                     }
       
  2480                 }
       
  2481             else
       
  2482                 {
       
  2483                 SymbianStreamCheckVisible(iNs, events, iScreenNo, iStreamUpdatedSerialNumber); 
       
  2484                 SymbianStreamCheckVisible(iNs, events, iScreenNo, iStreamUpdatedSerialNumber);            
       
  2485                 User::WaitForRequest(statusDisplayedX);
       
  2486                 ASSERT_EQUALS(statusDisplayedX.Int(), KErrNotVisible);
       
  2487                 break;
       
  2488                 }
       
  2489             }
       
  2490             
       
  2491         err = SymbianStreamRemoveObserver(iNs, this, ESOWF_EventUpdated);
       
  2492         ASSERT_TRUE(err == KErrNone);
       
  2493         SymbianStreamRemoveReference(iNs);
       
  2494         CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  2495         
       
  2496         iUtility->DestroySurface(surface);
       
  2497         }
       
  2498     }
       
  2499 
       
  2500 
       
  2501 /**
       
  2502 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0116
       
  2503 @SYMTestCaseDesc        Test all notifications together
       
  2504 @SYMREQ                 
       
  2505 @SYMPREQ                PREQ2400
       
  2506 @SYMTestType            CT
       
  2507 @SYMTestPriority        High
       
  2508 @SYMTestPurpose         Verify that the surface stream adaptation processes displayed x times
       
  2509                         notifications correctly.
       
  2510 @SYMTestActions
       
  2511 
       
  2512      1.  Create a surface
       
  2513      2.  Create a native stream for the surface
       
  2514      3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  2515      4.  Register available, displayed and displayed-x-times notifications.
       
  2516      5.  Submit an update to the surface
       
  2517      6.  Wait for the displayed notification to complete.
       
  2518      7.  The observer function should be invoked and verifies that stream and event parameters.
       
  2519      8.  The tester simulates the end of a composition by firing SymbianStreamProcessNotifications
       
  2520      9.  If X has not been reached yet verify that displayedx and available status is not completed 
       
  2521          then goto 5; otherwise, goto step 11.   
       
  2522      10. Verify displayed-x-times status is completed with KErrNone
       
  2523      11. Submit an update on a different buffer number
       
  2524      12. The tester simulates the end of a composition by firing SymbianStreamProcessNotifications
       
  2525      13. Verify that the available status is completed with KErrNone
       
  2526      14. Destroy the native stream.
       
  2527         
       
  2528 @SYMTestExpectedResults
       
  2529     No errors, displayed-x-times status completed with KErrNone.
       
  2530         
       
  2531 */
       
  2532 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0116L()
       
  2533     {
       
  2534     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  2535     TRAPD(err, GrowCleanupStackL());
       
  2536     ASSERT_TRUE(err == KErrNone);
       
  2537     
       
  2538     iScreenNo = 0; 
       
  2539     iContextUpdatedFlags = 0;
       
  2540     iStreamUpdatedSerialNumber = 1;
       
  2541     iSourceStreamUpdatedCalled = 0;
       
  2542     iImmediateAvailable = EFalse;
       
  2543     iImmediateVisible = SYM_CONTENT_VISIBLE;   
       
  2544     
       
  2545     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  2546     ASSERT_FALSE(surface.IsNull());
       
  2547     
       
  2548     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  2549     err = SymbianStreamAcquire(&surface, &iNs);
       
  2550     ASSERT_TRUE(err == KErrNone);
       
  2551     ASSERT_TRUE(iNs);
       
  2552     
       
  2553     err = SymbianStreamAddExtendedObserver(iNs, SourceStreamUpdatedCallback, this, iScreenNo, ESOWF_EventUpdated);
       
  2554     ASSERT_TRUE(err == KErrNone);
       
  2555     
       
  2556     TRequestStatus statusDisplayedX;
       
  2557     TRequestStatus statusAvailable;
       
  2558     TRequestStatus statusDisplayed;
       
  2559         
       
  2560     TInt X = 5;
       
  2561     TUint32 displayedTime = 0;
       
  2562 
       
  2563     CExtensionContainer* updateExtension = NULL;
       
  2564     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  2565     ASSERT_TRUE(err == KErrNone);
       
  2566     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  2567     ASSERT_NOT_NULL(updateProxy);
       
  2568     
       
  2569     // the composition is signalled as ongoing (busy system)
       
  2570     iImmediateAvailable = EFalse;
       
  2571     // we expect, initially that the composer is asked to check only for the displayed notifications
       
  2572     iExpectedSourceStreamUpdatedEventMask = ESOWF_EventDisplayedX | ESOWF_EventDisplayed;
       
  2573     
       
  2574     updateProxy->ContentUpdated(surface,                    //aSurface
       
  2575                                 0,                          //aBuffer
       
  2576                                 NULL,                       //aRegion
       
  2577                                 &statusAvailable,           //aStatusConsumed
       
  2578                                 &statusDisplayed,           //aStatusDisplayed
       
  2579                                 &displayedTime,             //aTimeStamp
       
  2580                                 &statusDisplayedX,          //aStatusDispXTimes
       
  2581                                 &X                          //aDisplayedXTimes
       
  2582                                 );     
       
  2583     
       
  2584     ASSERT_TRUE(iSourceStreamUpdatedCalled == 2);
       
  2585     // simulating the ongoing composition, the processing to be deferred for the following one
       
  2586     khronos_int32_t newNotificationsMask = 0;
       
  2587     SymbianStreamProcessNotifications(iNs, 
       
  2588                                         iExpectedSourceStreamUpdatedEventMask, 
       
  2589                                         iScreenNo,
       
  2590                                         iStreamUpdatedSerialNumber++,
       
  2591                                         &newNotificationsMask);
       
  2592 
       
  2593     ASSERT_TRUE(newNotificationsMask == iExpectedSourceStreamUpdatedEventMask);
       
  2594     
       
  2595     for (TInt i = 0; i < X; ++i)
       
  2596         {                                
       
  2597         // Pretend that a composition has occured
       
  2598                 
       
  2599         khronos_int32_t events = newNotificationsMask;
       
  2600         // we process the expected notifications
       
  2601         newNotificationsMask = 0;
       
  2602         SymbianStreamProcessNotifications(iNs, 
       
  2603                                             events, 
       
  2604                                             iScreenNo,
       
  2605                                             iStreamUpdatedSerialNumber++,
       
  2606                                             &newNotificationsMask);
       
  2607                 
       
  2608         // No updates during composition so newNotificationMask should still be zero 
       
  2609          
       
  2610         if (i == 0)
       
  2611             {
       
  2612             User::WaitForRequest(statusDisplayed);
       
  2613             ASSERT_EQUALS(statusDisplayed.Int(), KErrNone);
       
  2614             }
       
  2615         
       
  2616         
       
  2617         if (i < X - 1)
       
  2618             {
       
  2619             ASSERT_TRUE(newNotificationsMask == ESOWF_EventDisplayedX);
       
  2620             // Displayed X times for buffer zero should not be completed yet
       
  2621             ASSERT_EQUALS(statusDisplayedX.Int(), KRequestPending);
       
  2622             ASSERT_EQUALS(statusAvailable.Int(), KRequestPending);
       
  2623             }
       
  2624         else
       
  2625             {
       
  2626             ASSERT_TRUE(newNotificationsMask == 0);
       
  2627             User::WaitForRequest(statusDisplayedX);
       
  2628             ASSERT_EQUALS(statusDisplayedX.Int(), KErrNone);            
       
  2629             }
       
  2630         }
       
  2631     
       
  2632     // the composition is, still, signalled as ongoing (busy system)
       
  2633     iImmediateAvailable = EFalse;
       
  2634     // we expect, initially that the composer is asked to check only for the displayed notifications
       
  2635     iExpectedSourceStreamUpdatedEventMask = ESOWF_EventAvailable;
       
  2636     iUtility->SubmitUpdate(KAllScreens, surface, 1, 0);
       
  2637     ASSERT_TRUE(iSourceStreamUpdatedCalled == 4);
       
  2638     
       
  2639     SymbianStreamProcessNotifications(iNs, 
       
  2640                                         iExpectedSourceStreamUpdatedEventMask, 
       
  2641                                         iScreenNo,
       
  2642                                         iStreamUpdatedSerialNumber++,
       
  2643                                         &newNotificationsMask);
       
  2644     
       
  2645     User::WaitForRequest(statusAvailable);
       
  2646     ASSERT_EQUALS(statusAvailable.Int(), KErrNone);    
       
  2647     ASSERT_TRUE(newNotificationsMask == 0);
       
  2648     
       
  2649     SymbianStreamRemoveReference(iNs);
       
  2650     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  2651     
       
  2652     iUtility->DestroySurface(surface);
       
  2653     }
       
  2654 
       
  2655 /**
       
  2656 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0117_1
       
  2657 @SYMTestCaseDesc        Test displayed notification is cancelled when there are no registered SUS 
       
  2658                         notification observers
       
  2659 @SYMREQ                 
       
  2660 @SYMPREQ                PREQ2400
       
  2661 @SYMTestType            CT
       
  2662 @SYMTestPriority        High
       
  2663 @SYMTestPurpose         Verify that the surface stream adaptation cancels the displayed notification
       
  2664                         when the native stream has not registered any observers for SUS notifications
       
  2665 @SYMTestActions
       
  2666 
       
  2667      1.  Create a surface
       
  2668      2.  Create a native stream for the surface
       
  2669      3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  2670      4.  Do not add any SUS notification observers to the native stream
       
  2671      5.  Register for displayed notification.
       
  2672      6.  Submit an update to the surface
       
  2673      7.  The observer function should be invoked and verifies that stream and event parameters.
       
  2674      8.  The tester simulates the end of a composition by firing SymbianStreamProcessNotifications
       
  2675      9.  Verify displayed status is completed with KErrCancel
       
  2676      10. Destroy the native stream.
       
  2677         
       
  2678 @SYMTestExpectedResults
       
  2679     No errors, displayed status completed with KErrCancel.
       
  2680         
       
  2681 */
       
  2682 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0117_1L()
       
  2683     {
       
  2684     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  2685     TRAPD(err, GrowCleanupStackL());
       
  2686     ASSERT_TRUE(err == KErrNone);
       
  2687     
       
  2688     iScreenNo = 0;    
       
  2689     iContextUpdatedFlags = 0;
       
  2690     iStreamUpdatedSerialNumber = 1;
       
  2691     iSourceStreamUpdatedCalled = 0;
       
  2692     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  2693     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  2694     ASSERT_FALSE(surface.IsNull());
       
  2695     
       
  2696     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  2697     err = SymbianStreamAcquire(&surface, &iNs);
       
  2698     ASSERT_TRUE(err == KErrNone);
       
  2699     ASSERT_TRUE(iNs);
       
  2700     
       
  2701     // Do not add observers for SUS notifications!
       
  2702     
       
  2703     iExpectedSourceStreamUpdatedEventMask = 0;
       
  2704     err = SymbianStreamAddObserver(iNs, SourceStreamUpdatedCallback, this);
       
  2705     ASSERT_TRUE(err == KErrNone);
       
  2706     
       
  2707     TRequestStatus statusDisplayed;
       
  2708     TUint32 timeStamp = 0;
       
  2709 
       
  2710     CExtensionContainer* updateExtension = NULL;
       
  2711     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  2712     ASSERT_TRUE(err == KErrNone);
       
  2713     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  2714     ASSERT_NOT_NULL(updateProxy);
       
  2715     
       
  2716     updateProxy->ContentUpdated(surface,                    //aSurface
       
  2717                                 0,                          //aBuffer
       
  2718                                 NULL,                       //aRegion
       
  2719                                 NULL,                       //aStatusConsumed
       
  2720                                 &statusDisplayed,           //aStatusDisplayed
       
  2721                                 &timeStamp,                 //aTimeStamp
       
  2722                                 NULL,                       //aStatusDispXTimes
       
  2723                                 NULL                        //aDisplayedXTimes
       
  2724                                 );    
       
  2725     
       
  2726     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  2727     ASSERT_TRUE(iSourceStreamUpdatedCalled == 1);
       
  2728     
       
  2729     // Pretend that a composition has occured
       
  2730     khronos_int32_t notificationsMask = 0;
       
  2731     khronos_int32_t newNotificationsMask = 0;
       
  2732     
       
  2733     SymbianStreamProcessNotifications(iNs, 
       
  2734                                         ESOWF_EventAvailable | ESOWF_EventDisplayed |ESOWF_EventDisplayedX, 
       
  2735                                         iScreenNo,
       
  2736                                         ++iStreamUpdatedSerialNumber,
       
  2737                                         &newNotificationsMask);
       
  2738     
       
  2739     // No updates during composition so newNotificationMask should still be zero 
       
  2740     ASSERT_EQUALS(newNotificationsMask, notificationsMask);
       
  2741     
       
  2742     // The displayed notification should be cancelled as we have no observers registered
       
  2743     ASSERT_EQUALS(statusDisplayed.Int(), KErrCancel);
       
  2744     ASSERT_TRUE(timeStamp == 0);
       
  2745     
       
  2746     SymbianStreamRemoveReference(iNs);
       
  2747     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  2748     }
       
  2749 
       
  2750 /**
       
  2751 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0117_2
       
  2752 @SYMTestCaseDesc        Test displayed x times notification is cancelled when there are no registered SUS 
       
  2753                         notification observers
       
  2754 @SYMREQ                 
       
  2755 @SYMPREQ                PREQ2400
       
  2756 @SYMTestType            CT
       
  2757 @SYMTestPriority        High
       
  2758 @SYMTestPurpose         Verify that the surface stream adaptation cancels the displayed x times notification
       
  2759                         when the native stream has not registered any observers for SUS notifications
       
  2760 @SYMTestActions
       
  2761 
       
  2762      1.  Create a surface
       
  2763      2.  Create a native stream for the surface
       
  2764      3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  2765      4.  Do not add any SUS notification observers to the native stream
       
  2766      5.  Register for displayed x times notification.
       
  2767      6.  Submit an update to the surface
       
  2768      7.  The observer function should be invoked and verifies that stream and event parameters.
       
  2769      8.  The tester simulates the end of a composition by firing SymbianStreamProcessNotifications
       
  2770      9.  Verify displayed x time status is completed with KErrCancel
       
  2771      10. Destroy the native stream.
       
  2772         
       
  2773 @SYMTestExpectedResults
       
  2774     No errors, displayed x times status completed with KErrCancel.
       
  2775         
       
  2776 */
       
  2777 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0117_2L()
       
  2778     {
       
  2779     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  2780     TRAPD(err, GrowCleanupStackL());
       
  2781     ASSERT_TRUE(err == KErrNone);
       
  2782     
       
  2783     iScreenNo = 0;    
       
  2784     iContextUpdatedFlags = 0;
       
  2785     iStreamUpdatedSerialNumber = 1;
       
  2786     iSourceStreamUpdatedCalled = 0;
       
  2787     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  2788     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  2789     ASSERT_FALSE(surface.IsNull());
       
  2790     
       
  2791     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  2792     err = SymbianStreamAcquire(&surface, &iNs);
       
  2793     ASSERT_TRUE(err == KErrNone);
       
  2794     ASSERT_TRUE(iNs);
       
  2795     
       
  2796     // Do not add observers for SUS notifications!
       
  2797     
       
  2798     iExpectedSourceStreamUpdatedEventMask = 0;
       
  2799     err = SymbianStreamAddObserver(iNs, SourceStreamUpdatedCallback, this);
       
  2800     ASSERT_TRUE(err == KErrNone);
       
  2801     
       
  2802     TRequestStatus statusDisplayedX;
       
  2803     TInt X = 5;
       
  2804 
       
  2805     CExtensionContainer* updateExtension = NULL;
       
  2806     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  2807     ASSERT_TRUE(err == KErrNone);
       
  2808     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  2809     ASSERT_NOT_NULL(updateProxy);
       
  2810     
       
  2811     updateProxy->ContentUpdated(surface,                    //aSurface
       
  2812                                 0,                          //aBuffer
       
  2813                                 NULL,                       //aRegion
       
  2814                                 NULL,                       //aStatusConsumed
       
  2815                                 NULL,                       //aStatusDisplayed
       
  2816                                 NULL,                       //aTimeStamp
       
  2817                                 &statusDisplayedX,          //aStatusDispXTimes
       
  2818                                 &X                          //aDisplayedXTimes
       
  2819                                 );     
       
  2820 
       
  2821     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  2822     ASSERT_TRUE(iSourceStreamUpdatedCalled == 1);
       
  2823     
       
  2824     User::WaitForRequest(statusDisplayedX);
       
  2825     ASSERT_EQUALS(statusDisplayedX.Int(), KErrCancel);
       
  2826     
       
  2827     for (TInt i = 0; i < X; ++i)
       
  2828         {
       
  2829         // Pretend that a composition has occured
       
  2830         khronos_int32_t newNotificationsMask = 0;
       
  2831         SymbianStreamProcessNotifications(iNs, 
       
  2832                                             ESOWF_EventAvailable | ESOWF_EventDisplayed |ESOWF_EventDisplayedX, 
       
  2833                                             iScreenNo,
       
  2834                                             ++iStreamUpdatedSerialNumber,
       
  2835                                             &newNotificationsMask);
       
  2836         
       
  2837         // No updates during composition so newNotificationMask should still be zero 
       
  2838         ASSERT_TRUE(newNotificationsMask == 0);
       
  2839         }
       
  2840    
       
  2841     SymbianStreamRemoveReference(iNs);
       
  2842     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  2843     }
       
  2844 
       
  2845 /**
       
  2846 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0117_3
       
  2847 @SYMTestCaseDesc        Test available notification is cancelled when there are no registered SUS 
       
  2848                         notification observers
       
  2849 @SYMREQ                 
       
  2850 @SYMPREQ                PREQ2400
       
  2851 @SYMTestType            CT
       
  2852 @SYMTestPriority        High
       
  2853 @SYMTestPurpose         Verify that the surface stream adaptation cancels the available notification
       
  2854                         when the native stream has not registered any observers for SUS notifications
       
  2855 @SYMTestActions
       
  2856 
       
  2857      1.  Create a surface
       
  2858      2.  Create a native stream for the surface
       
  2859      3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  2860      4.  Do not add any SUS notification observers to the native stream
       
  2861      5.  Register for available notification.
       
  2862      6.  Submit an update to the surface
       
  2863      7.  The observer function should be invoked and verifies that stream and event parameters.
       
  2864      8.  The tester simulates the end of a composition by firing SymbianStreamProcessNotifications
       
  2865      9.  Verify available status is completed with KErrCancel
       
  2866      10. Destroy the native stream.
       
  2867         
       
  2868 @SYMTestExpectedResults
       
  2869     No errors, available status completed with KErrCancel.
       
  2870         
       
  2871 */
       
  2872 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0117_3L()
       
  2873     {
       
  2874     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  2875     TRAPD(err, GrowCleanupStackL());
       
  2876     ASSERT_TRUE(err == KErrNone);
       
  2877     
       
  2878     iScreenNo = 0;    
       
  2879     iContextUpdatedFlags = 0;
       
  2880     iStreamUpdatedSerialNumber = 1;
       
  2881     iSourceStreamUpdatedCalled = 0;
       
  2882     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  2883     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  2884     ASSERT_FALSE(surface.IsNull());
       
  2885     
       
  2886     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  2887     err = SymbianStreamAcquire(&surface, &iNs);
       
  2888     ASSERT_TRUE(err == KErrNone);
       
  2889     ASSERT_TRUE(iNs);
       
  2890     
       
  2891     // Do not add observers for SUS notifications!
       
  2892     
       
  2893     iExpectedSourceStreamUpdatedEventMask = 0;
       
  2894     err = SymbianStreamAddObserver(iNs, SourceStreamUpdatedCallback, this);
       
  2895     ASSERT_TRUE(err == KErrNone);
       
  2896     
       
  2897     TRequestStatus statusAvailable;
       
  2898 
       
  2899     CExtensionContainer* updateExtension = NULL;
       
  2900     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  2901     ASSERT_TRUE(err == KErrNone);
       
  2902     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  2903     ASSERT_NOT_NULL(updateProxy);
       
  2904     
       
  2905     updateProxy->ContentUpdated(surface,                    //aSurface
       
  2906                                 0,                          //aBuffer
       
  2907                                 NULL,                       //aRegion
       
  2908                                 &statusAvailable,           //aStatusConsumed
       
  2909                                 NULL,                       //aStatusDisplayed
       
  2910                                 NULL,                       //aTimeStamp
       
  2911                                 NULL,                       //aStatusDispXTimes
       
  2912                                 NULL                        //aDisplayedXTimes
       
  2913                                 ); 
       
  2914     
       
  2915     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  2916     ASSERT_TRUE(iSourceStreamUpdatedCalled == 1);
       
  2917     
       
  2918     // Available should only be completed when submit update is called with a different buffer no.
       
  2919     // But, when there are no registered SUS observers, the notification should complete immediately
       
  2920     // with KErrCancel
       
  2921     ASSERT_EQUALS(statusAvailable.Int(), KErrCancel);
       
  2922     
       
  2923     // Pretend that a composition has occured
       
  2924     khronos_int32_t newNotificationsMask = 0;
       
  2925     SymbianStreamProcessNotifications(iNs, 
       
  2926                                         ESOWF_EventAvailable | ESOWF_EventDisplayed |ESOWF_EventDisplayedX, 
       
  2927                                         iScreenNo,
       
  2928                                         ++iStreamUpdatedSerialNumber,
       
  2929                                         &newNotificationsMask);
       
  2930     
       
  2931     ASSERT_TRUE(newNotificationsMask == 0);
       
  2932     
       
  2933     // Update and switch to buffer 1
       
  2934     iExpectedSourceStreamUpdatedEventMask = 0;
       
  2935     iUtility->SubmitUpdate(KAllScreens, surface, 1, 0);    
       
  2936     ASSERT_TRUE(iSourceStreamUpdatedCalled == 2);
       
  2937     
       
  2938     // Consume update on buffer 1. This should make buffer 0 available
       
  2939     SymbianStreamProcessNotifications(iNs, 
       
  2940                                         ESOWF_EventAvailable | ESOWF_EventDisplayed |ESOWF_EventDisplayedX, 
       
  2941                                         iScreenNo,
       
  2942                                         ++iStreamUpdatedSerialNumber,
       
  2943                                         &newNotificationsMask);
       
  2944     
       
  2945     ASSERT_TRUE(newNotificationsMask == 0);
       
  2946     
       
  2947     User::WaitForRequest(statusAvailable);
       
  2948     ASSERT_EQUALS(statusAvailable.Int(), KErrCancel);
       
  2949    
       
  2950     SymbianStreamRemoveReference(iNs);
       
  2951     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  2952     }
       
  2953 
       
  2954 /**  
       
  2955 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0117_4
       
  2956 @SYMTestCaseDesc        Test all notifications are cancelled when there are no registered SUS 
       
  2957                         notification observers
       
  2958 @SYMREQ                 
       
  2959 @SYMPREQ                PREQ2400
       
  2960 @SYMTestType            CT
       
  2961 @SYMTestPriority        High
       
  2962 @SYMTestPurpose         Verify that the surface stream adaptation cancels all notifications
       
  2963                         when the native stream has not registered any observers for SUS notifications
       
  2964 @SYMTestActions
       
  2965 
       
  2966      1.  Create a surface
       
  2967      2.  Create a native stream for the surface
       
  2968      3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  2969      4.  Do not add any SUS notification observers to the native stream
       
  2970      5.  Register for displayed, available and displayed x times notifications
       
  2971      6.  Submit an update to the surface
       
  2972      7.  The observer function should be invoked and verifies that stream and event parameters
       
  2973      8.  The tester simulates the end of a composition by firing SymbianStreamProcessNotifications
       
  2974      9.  Verify all notification statuses completed with KErrCancel
       
  2975      10. Destroy the native stream.
       
  2976         
       
  2977 @SYMTestExpectedResults
       
  2978     No errors, all notification statuses completed with KErrCancel.
       
  2979         
       
  2980 */
       
  2981 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0117_4L()
       
  2982     {
       
  2983     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  2984     TRAPD(err, GrowCleanupStackL());
       
  2985     ASSERT_TRUE(err == KErrNone);
       
  2986     
       
  2987     iScreenNo = 0;    
       
  2988     iContextUpdatedFlags = 0;
       
  2989     iStreamUpdatedSerialNumber = 1;
       
  2990     iSourceStreamUpdatedCalled = 0;
       
  2991     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  2992     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  2993     ASSERT_FALSE(surface.IsNull());
       
  2994     
       
  2995     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  2996     err = SymbianStreamAcquire(&surface, &iNs);
       
  2997     ASSERT_TRUE(err == KErrNone);
       
  2998     ASSERT_TRUE(iNs);
       
  2999     
       
  3000     // Do not add observers for SUS notifications!
       
  3001     
       
  3002     iExpectedSourceStreamUpdatedEventMask = 0;
       
  3003     err = SymbianStreamAddObserver(iNs, SourceStreamUpdatedCallback, this);
       
  3004     ASSERT_TRUE(err == KErrNone);
       
  3005     
       
  3006     TRequestStatus statusDisplayedX;
       
  3007     TRequestStatus statusAvailable;
       
  3008     TRequestStatus statusDisplayed;
       
  3009     TInt X = 5;
       
  3010     TUint32 displayedTime = 0;
       
  3011 
       
  3012     CExtensionContainer* updateExtension = NULL;
       
  3013     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  3014     ASSERT_TRUE(err == KErrNone);
       
  3015     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  3016     ASSERT_NOT_NULL(updateProxy);
       
  3017     
       
  3018     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3019                                 0,                          //aBuffer
       
  3020                                 NULL,                       //aRegion
       
  3021                                 &statusAvailable,           //aStatusConsumed
       
  3022                                 &statusDisplayed,           //aStatusDisplayed
       
  3023                                 &displayedTime,             //aTimeStamp
       
  3024                                 &statusDisplayedX,          //aStatusDispXTimes
       
  3025                                 &X                          //aDisplayedXTimes
       
  3026                                 );     
       
  3027 
       
  3028     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  3029     ASSERT_TRUE(iSourceStreamUpdatedCalled == 1);
       
  3030     
       
  3031     for (TInt i = 0; i < X; ++i)
       
  3032         {                                
       
  3033         // Pretend that a composition has occured
       
  3034         khronos_int32_t newNotificationsMask = 0;
       
  3035                 
       
  3036         SymbianStreamProcessNotifications(iNs, 
       
  3037                                             ESOWF_EventAvailable | ESOWF_EventDisplayed |ESOWF_EventDisplayedX, 
       
  3038                                             iScreenNo,
       
  3039                                             ++iStreamUpdatedSerialNumber,
       
  3040                                             &newNotificationsMask);
       
  3041                 
       
  3042         // No updates during composition so newNotificationMask should still be zero 
       
  3043         ASSERT_TRUE(newNotificationsMask == 0);
       
  3044                 
       
  3045         if (i == 0)
       
  3046             {
       
  3047             User::WaitForRequest(statusDisplayed);
       
  3048             User::WaitForRequest(statusDisplayedX);
       
  3049             User::WaitForRequest(statusAvailable);
       
  3050             }
       
  3051 
       
  3052         ASSERT_EQUALS(statusAvailable.Int(), KErrCancel);            
       
  3053         ASSERT_EQUALS(statusDisplayed.Int(), KErrCancel);            
       
  3054         ASSERT_EQUALS(statusDisplayedX.Int(), KErrCancel);
       
  3055         }
       
  3056     
       
  3057     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3058                                 0,                          //aBuffer
       
  3059                                 NULL,                       //aRegion
       
  3060                                 NULL,                       //aStatusConsumed
       
  3061                                 NULL,                       //aStatusDisplayed
       
  3062                                 NULL,                       //aTimeStamp
       
  3063                                 NULL,                       //aStatusDispXTimes
       
  3064                                 NULL                        //aDisplayedXTimes
       
  3065                                 );    
       
  3066     
       
  3067     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  3068     ASSERT_TRUE(iSourceStreamUpdatedCalled == 2);
       
  3069     
       
  3070     khronos_int32_t newNotificationsMask = 0;
       
  3071     SymbianStreamProcessNotifications(iNs, 
       
  3072                                         ESOWF_EventAvailable | ESOWF_EventDisplayed |ESOWF_EventDisplayedX, 
       
  3073                                         iScreenNo,
       
  3074                                         ++iStreamUpdatedSerialNumber,
       
  3075                                         &newNotificationsMask);
       
  3076     
       
  3077     ASSERT_EQUALS(statusAvailable.Int(), KErrCancel);
       
  3078     ASSERT_TRUE(displayedTime == 0);
       
  3079     
       
  3080     SymbianStreamRemoveReference(iNs);
       
  3081     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  3082     }
       
  3083 
       
  3084 /**
       
  3085 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0118_1
       
  3086 @SYMTestCaseDesc        Test displayed notification is cancelled when content updated is called on  
       
  3087                         surface which is not registered with a native stream
       
  3088 @SYMREQ                 
       
  3089 @SYMPREQ                PREQ2400
       
  3090 @SYMTestType            CT
       
  3091 @SYMTestPriority        High
       
  3092 @SYMTestPurpose         Verify that the surface stream adaptation cancels the displayed notification
       
  3093                         added to a surface which does not have a native stream associated with it
       
  3094 @SYMTestActions
       
  3095 
       
  3096      1.  Create a surface
       
  3097      2.  Register for displayed notification.
       
  3098      3.  Submit an update to the surface
       
  3099      4.  Verify displayed status is completed with KErrSurfaceNotRegistered
       
  3100         
       
  3101 @SYMTestExpectedResults
       
  3102     No errors, displayed status completed with KErrSurfaceNotRegistered.
       
  3103         
       
  3104 */
       
  3105 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0118_1L()
       
  3106     {
       
  3107     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  3108     TRAPD(err, GrowCleanupStackL());
       
  3109     ASSERT_TRUE(err == KErrNone);
       
  3110     
       
  3111     iScreenNo = 0;    
       
  3112     iContextUpdatedFlags = 0;
       
  3113     iStreamUpdatedSerialNumber = 1;
       
  3114     iSourceStreamUpdatedCalled = 0;
       
  3115     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  3116     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  3117     ASSERT_FALSE(surface.IsNull());
       
  3118     
       
  3119     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  3120     TRequestStatus statusDisplayed;
       
  3121     TUint32 timeStamp = 0;
       
  3122 
       
  3123     CExtensionContainer* updateExtension = NULL;
       
  3124     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  3125     ASSERT_TRUE(err == KErrNone);
       
  3126     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  3127     ASSERT_NOT_NULL(updateProxy);
       
  3128     
       
  3129     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3130                                 0,                          //aBuffer
       
  3131                                 NULL,                       //aRegion
       
  3132                                 NULL,                       //aStatusConsumed
       
  3133                                 &statusDisplayed,           //aStatusDisplayed
       
  3134                                 &timeStamp,                 //aTimeStamp
       
  3135                                 NULL,                       //aStatusDispXTimes
       
  3136                                 NULL                        //aDisplayedXTimes
       
  3137                                 );    
       
  3138     
       
  3139     User::WaitForRequest(statusDisplayed);
       
  3140     
       
  3141     // The displayed notification should return with a surface registration error as there 
       
  3142     // isn't a native stream registered with surface...
       
  3143     ASSERT_EQUALS(statusDisplayed.Int(), KErrSurfaceNotRegistered);
       
  3144     ASSERT_TRUE(timeStamp == 0);
       
  3145     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  3146     }
       
  3147 
       
  3148 /**
       
  3149 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0118_2
       
  3150 @SYMTestCaseDesc        Test displayed x times notification is cancelled when content updated is called on  
       
  3151                         surface which is not registered with a native stream
       
  3152 @SYMREQ                 
       
  3153 @SYMPREQ                PREQ2400
       
  3154 @SYMTestType            CT
       
  3155 @SYMTestPriority        High
       
  3156 @SYMTestPurpose         Verify that the surface stream adaptation cancels the displayed x times notification
       
  3157                         added to a surface which does not have a native stream associated with it
       
  3158 @SYMTestActions
       
  3159 
       
  3160      1.  Create a surface
       
  3161      2.  Register for displayed x times notification.
       
  3162      3.  Submit an update to the surface
       
  3163      4.  Verify displayed x times status is completed with KErrSurfaceNotRegistered
       
  3164         
       
  3165 @SYMTestExpectedResults
       
  3166     No errors, displayed x times status completed with KErrSurfaceNotRegistered.
       
  3167         
       
  3168 */
       
  3169 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0118_2L()
       
  3170     {
       
  3171     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  3172     TRAPD(err, GrowCleanupStackL());
       
  3173     ASSERT_TRUE(err == KErrNone);
       
  3174     
       
  3175     iScreenNo = 0;    
       
  3176     iContextUpdatedFlags = 0;
       
  3177     iStreamUpdatedSerialNumber = 1;
       
  3178     iSourceStreamUpdatedCalled = 0;
       
  3179     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  3180     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  3181     ASSERT_FALSE(surface.IsNull());
       
  3182     
       
  3183     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  3184     
       
  3185     // Do not create a native stream for surface!
       
  3186     
       
  3187     TRequestStatus statusDisplayedXTimes;
       
  3188     TInt X = 5;
       
  3189 
       
  3190     CExtensionContainer* updateExtension = NULL;
       
  3191     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  3192     ASSERT_TRUE(err == KErrNone);
       
  3193     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  3194     ASSERT_NOT_NULL(updateProxy);
       
  3195     
       
  3196     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3197                                 0,                          //aBuffer
       
  3198                                 NULL,                       //aRegion
       
  3199                                 NULL,                       //aStatusConsumed
       
  3200                                 NULL,                       //aStatusDisplayed
       
  3201                                 NULL,                       //aTimeStamp
       
  3202                                 &statusDisplayedXTimes,     //aStatusDispXTimes
       
  3203                                 &X                          //aDisplayedXTimes
       
  3204                                 );
       
  3205     
       
  3206     User::WaitForRequest(statusDisplayedXTimes);
       
  3207     
       
  3208     // The displayed x times notification should return with a surface registration error as there 
       
  3209     // isn't a native stream registered with surface...
       
  3210     ASSERT_EQUALS(statusDisplayedXTimes.Int(), KErrSurfaceNotRegistered);
       
  3211     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  3212     }
       
  3213 
       
  3214 /**
       
  3215 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0118_3
       
  3216 @SYMTestCaseDesc        Test available notification is cancelled when content updated is called on  
       
  3217                         surface which is not registered with a native stream
       
  3218 @SYMREQ                 
       
  3219 @SYMPREQ                PREQ2400
       
  3220 @SYMTestType            CT
       
  3221 @SYMTestPriority        High
       
  3222 @SYMTestPurpose         Verify that the surface stream adaptation cancels the available notification
       
  3223                         added to a surface which does not have a native stream associated with it
       
  3224 @SYMTestActions
       
  3225 
       
  3226      1.  Create a surface
       
  3227      2.  Rregister for available notification.
       
  3228      3.  Submit an update to the surface
       
  3229      4.  Verify available status is completed with KErrSurfaceNotRegistered
       
  3230         
       
  3231 @SYMTestExpectedResults
       
  3232     No errors, available status completed with KErrSurfaceNotRegistered.
       
  3233         
       
  3234 */
       
  3235 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0118_3L()
       
  3236     {
       
  3237     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  3238     TRAPD(err, GrowCleanupStackL());
       
  3239     ASSERT_TRUE(err == KErrNone);
       
  3240     
       
  3241     iScreenNo = 0;    
       
  3242     iContextUpdatedFlags = 0;
       
  3243     iStreamUpdatedSerialNumber = 1;
       
  3244     iSourceStreamUpdatedCalled = 0;
       
  3245     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  3246     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  3247     ASSERT_FALSE(surface.IsNull());
       
  3248     
       
  3249     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  3250     
       
  3251     // Do not create a native stream for surface!
       
  3252     
       
  3253     TRequestStatus statusAvailable;
       
  3254 
       
  3255     CExtensionContainer* updateExtension = NULL;
       
  3256     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  3257     ASSERT_TRUE(err == KErrNone);
       
  3258     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  3259     ASSERT_NOT_NULL(updateProxy);
       
  3260     
       
  3261     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3262                                 0,                          //aBuffer
       
  3263                                 NULL,                       //aRegion
       
  3264                                 &statusAvailable,           //aStatusConsumed
       
  3265                                 NULL,                       //aStatusDisplayed
       
  3266                                 NULL,                       //aTimeStamp
       
  3267                                 NULL,                       //aStatusDispXTimes
       
  3268                                 NULL                        //aDisplayedXTimes
       
  3269                                 );
       
  3270     
       
  3271     User::WaitForRequest(statusAvailable);  
       
  3272     
       
  3273     // The available notification should return with a surface registration error as there 
       
  3274     // isn't a native stream registered with surface...
       
  3275     ASSERT_EQUALS(statusAvailable.Int(), KErrSurfaceNotRegistered);
       
  3276     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  3277     }
       
  3278 
       
  3279 /**
       
  3280 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0118_4
       
  3281 @SYMTestCaseDesc        Test all notifications are cancelled when content updated is called on  
       
  3282                         surface which is not registered with a native stream
       
  3283 @SYMREQ                 
       
  3284 @SYMPREQ                PREQ2400
       
  3285 @SYMTestType            CT
       
  3286 @SYMTestPriority        High
       
  3287 @SYMTestPurpose         Verify that the surface stream adaptation cancels all notifications
       
  3288                         added to a surface which does not have a native stream associated with it
       
  3289 @SYMTestActions
       
  3290 
       
  3291      1.  Create a surface
       
  3292      2.  Register for displayed, available and displayed x times notifications.
       
  3293      3.  Submit an update to the surface
       
  3294      4.  Verify all notification statuses completed with KErrSurfaceNotRegistered
       
  3295         
       
  3296 @SYMTestExpectedResults
       
  3297     No errors, all notification statuses completed with KErrSurfaceNotRegistered.
       
  3298         
       
  3299 */
       
  3300 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0118_4L()
       
  3301     {
       
  3302     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  3303     TRAPD(err, GrowCleanupStackL());
       
  3304     ASSERT_TRUE(err == KErrNone);
       
  3305     
       
  3306     iScreenNo = 0;    
       
  3307     iContextUpdatedFlags = 0;
       
  3308     iStreamUpdatedSerialNumber = 1;
       
  3309     iSourceStreamUpdatedCalled = 0;
       
  3310     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  3311     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  3312     ASSERT_FALSE(surface.IsNull());
       
  3313     
       
  3314     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  3315     
       
  3316     // Do not create a native stream for surface!
       
  3317     
       
  3318     TRequestStatus statusDisplayed, statusAvailable, statusDisplayedXTimes;
       
  3319     TInt X = 5;
       
  3320     TUint32 timeStamp = 0;
       
  3321 
       
  3322     CExtensionContainer* updateExtension = NULL;
       
  3323     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  3324     ASSERT_TRUE(err == KErrNone);
       
  3325     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  3326     ASSERT_NOT_NULL(updateProxy);
       
  3327     
       
  3328     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3329                                 0,                          //aBuffer
       
  3330                                 NULL,                       //aRegion
       
  3331                                 &statusAvailable,           //aStatusConsumed
       
  3332                                 &statusDisplayed,           //aStatusDisplayed
       
  3333                                 &timeStamp,                 //aTimeStamp
       
  3334                                 &statusDisplayedXTimes,     //aStatusDispXTimes
       
  3335                                 &X                          //aDisplayedXTimes
       
  3336                                 ); 
       
  3337     
       
  3338     User::WaitForRequest(statusDisplayed);
       
  3339     User::WaitForRequest(statusAvailable);
       
  3340     User::WaitForRequest(statusDisplayedXTimes);
       
  3341     
       
  3342     // All notifications should return with a surface registration error as there 
       
  3343     // isn't a native stream registered with surface...
       
  3344     ASSERT_EQUALS(statusDisplayed.Int(), KErrSurfaceNotRegistered);
       
  3345     ASSERT_EQUALS(statusAvailable.Int(), KErrSurfaceNotRegistered);
       
  3346     ASSERT_EQUALS(statusDisplayedXTimes.Int(), KErrSurfaceNotRegistered);
       
  3347     ASSERT_TRUE(timeStamp == 0);
       
  3348     
       
  3349     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  3350     }
       
  3351 
       
  3352 /**
       
  3353 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0119_1
       
  3354 @SYMTestCaseDesc        Test overflow conditions on notifications for displayed
       
  3355 @SYMREQ                 
       
  3356 @SYMPREQ                PREQ2400
       
  3357 @SYMTestType            CT
       
  3358 @SYMTestPriority        High
       
  3359 @SYMTestPurpose         Verify that the surface stream adaptation correctly handles duplicate displayed 
       
  3360                         notifications registered by SUS for content updates on the same screen and buffer
       
  3361 @SYMTestActions
       
  3362 
       
  3363      1.  Create a surface
       
  3364      2.  Create a native stream for the surface
       
  3365      3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  3366      4.  Register for displayed notification (d1)
       
  3367      5.  Submit an update to the surface
       
  3368      6.  Register for displayed notification (d2)
       
  3369      7.  Submit an update to the surface
       
  3370      8.  The observer function should be invoked and verifies that stream and event parameters.
       
  3371      9.  The tester simulates the end of a composition by firing SymbianStreamProcessNotifications
       
  3372      10. Verify d1 status is completed with KErrOverflow and d2 status is completed with KErrNone
       
  3373      11. Destroy the native stream
       
  3374         
       
  3375 @SYMTestExpectedResults
       
  3376     No errors, d1 status completed with KErrOverflow, d2 status completed with KErrNone.
       
  3377         
       
  3378 */
       
  3379 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0119_1L()
       
  3380     {
       
  3381     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  3382     TRAPD(err, GrowCleanupStackL());
       
  3383     ASSERT_TRUE(err == KErrNone);
       
  3384     
       
  3385     iScreenNo = 0;    
       
  3386     iContextUpdatedFlags = 0;
       
  3387     iStreamUpdatedSerialNumber = 1;
       
  3388     iSourceStreamUpdatedCalled = 0;
       
  3389     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  3390     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  3391     ASSERT_FALSE(surface.IsNull());
       
  3392     
       
  3393     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  3394     err = SymbianStreamAcquire(&surface, &iNs);
       
  3395     ASSERT_TRUE(err == KErrNone);
       
  3396     ASSERT_TRUE(iNs);;
       
  3397     
       
  3398     iExpectedSourceStreamUpdatedEventMask = ESOWF_EventDisplayed;
       
  3399     err = SymbianStreamAddExtendedObserver(iNs, SourceStreamUpdatedCallback, this, iScreenNo, ESOWF_EventUpdated);
       
  3400     ASSERT_TRUE(err == KErrNone);
       
  3401     
       
  3402     TRequestStatus statusDisplayed1, statusDisplayed2;
       
  3403     TUint32 timeStamp1 = 0;
       
  3404     TUint32 timeStamp2 = 0;
       
  3405 
       
  3406     CExtensionContainer* updateExtension = NULL;
       
  3407     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  3408     ASSERT_TRUE(err == KErrNone);
       
  3409     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  3410     ASSERT_NOT_NULL(updateProxy);
       
  3411     
       
  3412     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3413                                 0,                          //aBuffer
       
  3414                                 NULL,                       //aRegion
       
  3415                                 NULL,                       //aStatusConsumed
       
  3416                                 &statusDisplayed1,          //aStatusDisplayed
       
  3417                                 &timeStamp1,                //aTimeStamp
       
  3418                                 NULL,                       //aStatusDispXTimes
       
  3419                                 NULL                        //aDisplayedXTimes
       
  3420                                 );
       
  3421     
       
  3422     ASSERT_TRUE(iSourceStreamUpdatedCalled == 2);
       
  3423     
       
  3424     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3425                                 0,                          //aBuffer
       
  3426                                 NULL,                       //aRegion
       
  3427                                 NULL,                       //aStatusConsumed
       
  3428                                 &statusDisplayed2,          //aStatusDisplayed
       
  3429                                 &timeStamp2,                //aTimeStamp
       
  3430                                 NULL,                       //aStatusDispXTimes
       
  3431                                 NULL                        //aDisplayedXTimes
       
  3432                                 );
       
  3433     ASSERT_TRUE(iSourceStreamUpdatedCalled == 4);
       
  3434     
       
  3435     User::WaitForRequest(statusDisplayed1);
       
  3436     ASSERT_EQUALS(statusDisplayed1.Int(), KErrOverflow);
       
  3437     ASSERT_TRUE(timeStamp1 == 0);
       
  3438     
       
  3439     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  3440     ASSERT_TRUE(iSourceStreamUpdatedCalled);
       
  3441     
       
  3442     // Pretend that a composition has occured
       
  3443     khronos_int32_t newNotificationsMask = 0;
       
  3444     SymbianStreamProcessNotifications(iNs, 
       
  3445                                         iExpectedSourceStreamUpdatedEventMask, 
       
  3446                                         iScreenNo,
       
  3447                                         ++iStreamUpdatedSerialNumber,
       
  3448                                         &newNotificationsMask);
       
  3449     
       
  3450     ASSERT_TRUE(newNotificationsMask == 0);
       
  3451     
       
  3452     // Make sure displayed event was completed
       
  3453     User::WaitForRequest(statusDisplayed2);
       
  3454     ASSERT_EQUALS(statusDisplayed2.Int(), KErrNone);
       
  3455     ASSERT_TRUE(timeStamp2);
       
  3456     
       
  3457     SymbianStreamRemoveReference(iNs);
       
  3458     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  3459     }
       
  3460 
       
  3461 /**
       
  3462 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0119_2
       
  3463 @SYMTestCaseDesc        Test overflow conditions on notifications for displayed-x-times
       
  3464 @SYMREQ                 
       
  3465 @SYMPREQ                PREQ2400
       
  3466 @SYMTestType            CT
       
  3467 @SYMTestPriority        High
       
  3468 @SYMTestPurpose         Verify that the surface stream adaptation correctly handles duplicate displayed 
       
  3469                         x times notifications registered by SUS for content updates on the same screen
       
  3470                         and buffer
       
  3471 @SYMTestActions
       
  3472 
       
  3473      1.  Create a surface
       
  3474      2.  Create a native stream for the surface
       
  3475      3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  3476      4.  Register for displayed x times notification (d1)
       
  3477      5.  Submit an update to the surface
       
  3478      6.  Register for displayed x times notification (d2)
       
  3479      7.  Submit an update to the surface
       
  3480      8.  The observer function should be invoked and verifies that stream and event parameters.
       
  3481      9.  The tester simulates the end of a composition by firing SymbianStreamProcessNotifications
       
  3482      10. Verify d1 status is completed with KErrOverflow and d2 status is completed with KErrNone
       
  3483      11. Destroy the native stream
       
  3484         
       
  3485 @SYMTestExpectedResults
       
  3486     No errors, d1 status completed with KErrOverflow, d2 status completed with KErrNone.
       
  3487         
       
  3488 */
       
  3489 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0119_2L()
       
  3490     {
       
  3491     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  3492     TRAPD(err, GrowCleanupStackL());
       
  3493     ASSERT_TRUE(err == KErrNone);
       
  3494     
       
  3495     iScreenNo = 0;    
       
  3496     TInt X = 5;
       
  3497     iContextUpdatedFlags = 0;
       
  3498     iStreamUpdatedSerialNumber = 1;
       
  3499     iSourceStreamUpdatedCalled = 0;
       
  3500     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  3501     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  3502     ASSERT_FALSE(surface.IsNull());
       
  3503     
       
  3504     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  3505     err = SymbianStreamAcquire(&surface, &iNs);
       
  3506     ASSERT_TRUE(err == KErrNone);
       
  3507     ASSERT_TRUE(iNs);
       
  3508     
       
  3509     iExpectedSourceStreamUpdatedEventMask = ESOWF_EventDisplayedX;
       
  3510     err = SymbianStreamAddExtendedObserver(iNs, SourceStreamUpdatedCallback, this, iScreenNo, ESOWF_EventUpdated);
       
  3511     ASSERT_TRUE(err == KErrNone);
       
  3512     
       
  3513     TRequestStatus statusDisplayedX1, statusDisplayedX2;
       
  3514 
       
  3515     CExtensionContainer* updateExtension = NULL;
       
  3516     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  3517     ASSERT_TRUE(err == KErrNone);
       
  3518     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  3519     ASSERT_NOT_NULL(updateProxy);
       
  3520     
       
  3521     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3522                                 0,                          //aBuffer
       
  3523                                 NULL,                       //aRegion
       
  3524                                 NULL,                       //aStatusConsumed
       
  3525                                 NULL,                       //aStatusDisplayed
       
  3526                                 NULL,                       //aTimeStamp
       
  3527                                 &statusDisplayedX1,         //aStatusDispXTimes
       
  3528                                 &X                          //aDisplayedXTimes
       
  3529                                 );
       
  3530     
       
  3531     ASSERT_TRUE(iSourceStreamUpdatedCalled == 2);
       
  3532     
       
  3533     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3534                                 0,                          //aBuffer
       
  3535                                 NULL,                       //aRegion
       
  3536                                 NULL,                       //aStatusConsumed
       
  3537                                 NULL,                       //aStatusDisplayed
       
  3538                                 NULL,                       //aTimeStamp
       
  3539                                 &statusDisplayedX2,         //aStatusDispXTimes
       
  3540                                 &X                          //aDisplayedXTimes
       
  3541                                 );
       
  3542     
       
  3543     ASSERT_TRUE(iSourceStreamUpdatedCalled == 4);
       
  3544     
       
  3545     User::WaitForRequest(statusDisplayedX1);
       
  3546     ASSERT_EQUALS(statusDisplayedX1.Int(), KErrOverflow);
       
  3547     
       
  3548     for (TInt i = 0; i < X; ++i)
       
  3549         {
       
  3550         ASSERT_EQUALS(statusDisplayedX2.Int(), KRequestPending);
       
  3551         
       
  3552         // Pretend that a composition has occured
       
  3553         khronos_int32_t newNotificationsMask = 0;
       
  3554         SymbianStreamProcessNotifications(iNs, 
       
  3555                                             ESOWF_EventDisplayedX, 
       
  3556                                             iScreenNo,
       
  3557                                             ++iStreamUpdatedSerialNumber,
       
  3558                                             &newNotificationsMask);        
       
  3559 
       
  3560         if (i < X -1)
       
  3561             {
       
  3562             ASSERT_TRUE(newNotificationsMask == ESOWF_EventDisplayedX);
       
  3563             }
       
  3564         else
       
  3565             {
       
  3566             ASSERT_TRUE(newNotificationsMask == 0);
       
  3567             }
       
  3568         }
       
  3569     
       
  3570     // Make sure displayed event was completed
       
  3571     User::WaitForRequest(statusDisplayedX2);
       
  3572     ASSERT_EQUALS(statusDisplayedX2.Int(), KErrNone);
       
  3573     
       
  3574     SymbianStreamRemoveReference(iNs);
       
  3575     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  3576     }
       
  3577 
       
  3578 /**
       
  3579 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0119_3
       
  3580 @SYMTestCaseDesc        Test overflow conditions on notifications for available
       
  3581 @SYMREQ                 
       
  3582 @SYMPREQ                PREQ2400
       
  3583 @SYMTestType            CT
       
  3584 @SYMTestPriority        High
       
  3585 @SYMTestPurpose         Verify that the surface stream adaptation correctly handles duplicate available 
       
  3586                         notifications registered by SUS for content updates on the same screen and buffer
       
  3587 @SYMTestActions
       
  3588 
       
  3589      1.  Create a surface
       
  3590      2.  Create a native stream for the surface
       
  3591      3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  3592      4.  Register for available notification (a1)
       
  3593      5.  Submit an update to the surface
       
  3594      6.  Register for available notification (a2)
       
  3595      7.  Submit an update to the surface
       
  3596      8.  The observer function should be invoked and verifies that stream and event parameters.
       
  3597      9.  The tester simulates the end of a composition by firing SymbianStreamProcessNotifications
       
  3598      10. Verify d1 status is completed with KErrOverflow and d2 status is completed with KErrNone
       
  3599      11. Destroy the native stream
       
  3600         
       
  3601 @SYMTestExpectedResults
       
  3602     No errors, a1 status completed with KErrOverflow, a2 status completed with KErrNone.
       
  3603         
       
  3604 */
       
  3605 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0119_3L()
       
  3606     {
       
  3607     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  3608     TRAPD(err, GrowCleanupStackL());
       
  3609     ASSERT_TRUE(err == KErrNone);
       
  3610     
       
  3611     iScreenNo = 0;    
       
  3612     iContextUpdatedFlags = 0;
       
  3613     iStreamUpdatedSerialNumber = 1;
       
  3614     iSourceStreamUpdatedCalled = 0;
       
  3615     iImmediateAvailable = EFalse;
       
  3616     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  3617     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  3618     ASSERT_FALSE(surface.IsNull());
       
  3619     
       
  3620     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  3621     err = SymbianStreamAcquire(&surface, &iNs);
       
  3622     ASSERT_TRUE(err == KErrNone);
       
  3623     ASSERT_TRUE(iNs);
       
  3624     
       
  3625     err = SymbianStreamAddExtendedObserver(iNs, SourceStreamUpdatedCallback, this, iScreenNo, ESOWF_EventUpdated);
       
  3626     ASSERT_TRUE(err == KErrNone);
       
  3627     
       
  3628     TRequestStatus statusAvailable1, statusAvailable2, statusAvailable3;
       
  3629 
       
  3630     CExtensionContainer* updateExtension = NULL;
       
  3631     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  3632     ASSERT_TRUE(err == KErrNone);
       
  3633     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  3634     ASSERT_NOT_NULL(updateProxy);
       
  3635     
       
  3636     iExpectedSourceStreamUpdatedEventMask = 0;
       
  3637     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3638                                 0,                          //aBuffer
       
  3639                                 NULL,                       //aRegion
       
  3640                                 &statusAvailable1,          //aStatusConsumed
       
  3641                                 NULL,                       //aStatusDisplayed
       
  3642                                 NULL,                       //aTimeStamp
       
  3643                                 NULL,                       //aStatusDispXTimes
       
  3644                                 NULL                        //aDisplayedXTimes
       
  3645                                 );    
       
  3646     
       
  3647     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  3648     ASSERT_TRUE(iSourceStreamUpdatedCalled == 2);
       
  3649     
       
  3650     iExpectedSourceStreamUpdatedEventMask = ESOWF_EventAvailable;
       
  3651     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3652                                 0,                          //aBuffer
       
  3653                                 NULL,                       //aRegion
       
  3654                                 &statusAvailable2,          //aStatusConsumed
       
  3655                                 NULL,                       //aStatusDisplayed
       
  3656                                 NULL,                       //aTimeStamp
       
  3657                                 NULL,                       //aStatusDispXTimes
       
  3658                                 NULL                        //aDisplayedXTimes
       
  3659                                 );   
       
  3660     
       
  3661     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  3662     ASSERT_TRUE(iSourceStreamUpdatedCalled == 4);
       
  3663     
       
  3664     iExpectedSourceStreamUpdatedEventMask = ESOWF_EventAvailable;
       
  3665     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3666                                 0,                          //aBuffer
       
  3667                                 NULL,                       //aRegion
       
  3668                                 &statusAvailable3,          //aStatusConsumed
       
  3669                                 NULL,                       //aStatusDisplayed
       
  3670                                 NULL,                       //aTimeStamp
       
  3671                                 NULL,                       //aStatusDispXTimes
       
  3672                                 NULL                        //aDisplayedXTimes
       
  3673                                 );   
       
  3674     
       
  3675     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  3676     ASSERT_TRUE(iSourceStreamUpdatedCalled == 6);
       
  3677     
       
  3678     User::WaitForRequest(statusAvailable1);
       
  3679     ASSERT_EQUALS(statusAvailable1.Int(), KErrOverflow);
       
  3680     
       
  3681     // Pretend that a composition has occured
       
  3682     khronos_int32_t newNotificationsMask = 0;
       
  3683     SymbianStreamProcessNotifications(iNs, 
       
  3684                                         ESOWF_EventAvailable, 
       
  3685                                         iScreenNo,
       
  3686                                         iStreamUpdatedSerialNumber,
       
  3687                                         &newNotificationsMask);
       
  3688     
       
  3689     ASSERT_TRUE(newNotificationsMask == 0);
       
  3690     
       
  3691     // Make sure displayed event was completed
       
  3692     User::WaitForRequest(statusAvailable2);
       
  3693     ASSERT_EQUALS(statusAvailable2.Int(), KErrNone);
       
  3694     
       
  3695     SymbianStreamRemoveReference(iNs);
       
  3696     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  3697     }
       
  3698 
       
  3699 /**
       
  3700 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0120_1
       
  3701 @SYMTestCaseDesc        Test overflow conditions on notifications for displayed
       
  3702 @SYMREQ                 
       
  3703 @SYMPREQ                PREQ2400
       
  3704 @SYMTestType            CT
       
  3705 @SYMTestPriority        High
       
  3706 @SYMTestPurpose         Verify that the surface stream adaptation correctly handles duplicate notifications
       
  3707                         registered by SUS for content updates on different buffers
       
  3708 @SYMTestActions
       
  3709 
       
  3710      1.  Create a surface
       
  3711      2.  Create a native stream for the surface
       
  3712      3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  3713      4.  Register for displayed notification (d1)
       
  3714      5.  Submit an update to the surface on buffer 0
       
  3715      6.  Register for displayed notification (d2)
       
  3716      7.  Submit an update to the surface on buffer 1
       
  3717      8.  The observer function should be invoked and verifies that stream and event parameters.
       
  3718      9.  The tester simulates the end of a composition by firing SymbianStreamProcessNotifications
       
  3719      10. Verify d1 status is completed with KErrOverflow and d2 status is completed with KErrNone
       
  3720      11. Destroy the native stream
       
  3721         
       
  3722 @SYMTestExpectedResults
       
  3723     No errors, d1 status completed with KErrOverflow, d2 status completed with KErrNone.
       
  3724         
       
  3725 */
       
  3726 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0120_1L()
       
  3727     {
       
  3728     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  3729     TRAPD(err, GrowCleanupStackL());
       
  3730     ASSERT_TRUE(err == KErrNone);
       
  3731     
       
  3732     iScreenNo = 0;    
       
  3733     iContextUpdatedFlags = 0;
       
  3734     iStreamUpdatedSerialNumber = 1;
       
  3735     iSourceStreamUpdatedCalled = 0;
       
  3736     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  3737     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  3738     ASSERT_FALSE(surface.IsNull());
       
  3739     
       
  3740     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  3741     err = SymbianStreamAcquire(&surface, &iNs);
       
  3742     ASSERT_TRUE(err == KErrNone);
       
  3743     ASSERT_TRUE(iNs);
       
  3744     
       
  3745     err = SymbianStreamAddExtendedObserver(iNs, SourceStreamUpdatedCallback, this, iScreenNo, ESOWF_EventUpdated);
       
  3746     ASSERT_TRUE(err == KErrNone);
       
  3747     iExpectedSourceStreamUpdatedEventMask = ESOWF_EventDisplayed;
       
  3748     
       
  3749     TRequestStatus statusDisplayed1, statusDisplayed2;
       
  3750     TUint32 timeStamp1 = 0;
       
  3751     TUint32 timeStamp2 = 0;
       
  3752 
       
  3753     CExtensionContainer* updateExtension = NULL;
       
  3754     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  3755     ASSERT_TRUE(err == KErrNone);
       
  3756     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  3757     ASSERT_NOT_NULL(updateProxy);
       
  3758     
       
  3759     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3760                                 0,                          //aBuffer
       
  3761                                 NULL,                       //aRegion
       
  3762                                 NULL,                       //aStatusConsumed
       
  3763                                 &statusDisplayed1,          //aStatusDisplayed
       
  3764                                 &timeStamp1,                //aTimeStamp
       
  3765                                 NULL,                       //aStatusDispXTimes
       
  3766                                 NULL                        //aDisplayedXTimes
       
  3767                                 );
       
  3768     
       
  3769     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  3770     ASSERT_TRUE(iSourceStreamUpdatedCalled == 2);
       
  3771     
       
  3772     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3773                                 1,                          //aBuffer
       
  3774                                 NULL,                       //aRegion
       
  3775                                 NULL,                       //aStatusConsumed
       
  3776                                 &statusDisplayed2,          //aStatusDisplayed
       
  3777                                 &timeStamp2,                //aTimeStamp
       
  3778                                 NULL,                       //aStatusDispXTimes
       
  3779                                 NULL                        //aDisplayedXTimes
       
  3780                                 );  
       
  3781     
       
  3782     ASSERT_TRUE(iSourceStreamUpdatedCalled == 4);
       
  3783     
       
  3784     User::WaitForRequest(statusDisplayed1);
       
  3785     ASSERT_EQUALS(statusDisplayed1.Int(), KErrOverflow);
       
  3786     
       
  3787     // Pretend that a composition has occured
       
  3788     khronos_int32_t newNotificationsMask = 0;
       
  3789     SymbianStreamProcessNotifications(iNs, 
       
  3790                                         iExpectedSourceStreamUpdatedEventMask, 
       
  3791                                         iScreenNo,
       
  3792                                         ++iStreamUpdatedSerialNumber,
       
  3793                                         &newNotificationsMask);
       
  3794     
       
  3795     ASSERT_TRUE(newNotificationsMask == 0);
       
  3796     
       
  3797     // Make sure displayed event was completed
       
  3798     User::WaitForRequest(statusDisplayed2);
       
  3799     ASSERT_EQUALS(statusDisplayed2.Int(), KErrNone);
       
  3800     
       
  3801     SymbianStreamRemoveReference(iNs);
       
  3802     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  3803     }
       
  3804 
       
  3805 
       
  3806 /**
       
  3807 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0120_2
       
  3808 @SYMTestCaseDesc        Test overflow conditions on notifications for displayed-x-times
       
  3809 @SYMREQ                 
       
  3810 @SYMPREQ                PREQ2400
       
  3811 @SYMTestType            CT
       
  3812 @SYMTestPriority        High
       
  3813 @SYMTestPurpose         Verify that the surface stream adaptation correctly handles duplicate notifications
       
  3814                         registered by SUS for content updates on different buffers
       
  3815 @SYMTestActions
       
  3816 
       
  3817      1.  Create a surface
       
  3818      2.  Create a native stream for the surface
       
  3819      3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  3820      4.  Register for displayed-x-times notification (d1)
       
  3821      5.  Submit an update to the surface on buffer 0
       
  3822      6.  Register for displayed-x-times notification (d2)
       
  3823      7.  Submit an update to the surface on buffer 1
       
  3824      8.  The observer function should be invoked and verifies that stream and event parameters.
       
  3825      9.  Verify d1 status is completed with KErrOverflow
       
  3826      10. The tester simulates the end of a composition by firing SymbianStreamProcessNotifications
       
  3827      11. Step 11. is repeated 5 times to simulate 5 compositions.
       
  3828      12. Verify that d2 status is completed with KErrNone
       
  3829      13. Destroy the native stream
       
  3830         
       
  3831 @SYMTestExpectedResults
       
  3832     No errors, d1 status completed with KErrOverflow, d2 status completed with KErrNone.
       
  3833         
       
  3834 */
       
  3835 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0120_2L()
       
  3836     {
       
  3837     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  3838     TRAPD(err, GrowCleanupStackL());
       
  3839     ASSERT_TRUE(err == KErrNone);
       
  3840     
       
  3841     iScreenNo = 0;    
       
  3842     iContextUpdatedFlags = 0;
       
  3843     iStreamUpdatedSerialNumber = 1;
       
  3844     iSourceStreamUpdatedCalled = 0;
       
  3845     TInt X = 5;
       
  3846     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  3847     ASSERT_FALSE(surface.IsNull());
       
  3848     
       
  3849     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  3850     err = SymbianStreamAcquire(&surface, &iNs);
       
  3851     ASSERT_TRUE(err == KErrNone);
       
  3852     ASSERT_TRUE(iNs);
       
  3853     
       
  3854     err = SymbianStreamAddExtendedObserver(iNs, SourceStreamUpdatedCallback, this, iScreenNo, ESOWF_EventUpdated);
       
  3855     ASSERT_TRUE(err == KErrNone);
       
  3856     iExpectedSourceStreamUpdatedEventMask = ESOWF_EventDisplayedX;
       
  3857     
       
  3858     TRequestStatus statusDisplayedX1, statusDisplayedX2;
       
  3859 
       
  3860     CExtensionContainer* updateExtension = NULL;
       
  3861     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  3862     ASSERT_TRUE(err == KErrNone);
       
  3863     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  3864     ASSERT_NOT_NULL(updateProxy);
       
  3865     
       
  3866     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3867                                 0,                          //aBuffer
       
  3868                                 NULL,                       //aRegion
       
  3869                                 NULL,                       //aStatusConsumed
       
  3870                                 NULL,                       //aStatusDisplayed
       
  3871                                 NULL,                       //aTimeStamp
       
  3872                                 &statusDisplayedX1,         //aStatusDispXTimes
       
  3873                                 &X                          //aDisplayedXTimes
       
  3874                                 );
       
  3875     
       
  3876     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  3877     ASSERT_TRUE(iSourceStreamUpdatedCalled == 2);
       
  3878     
       
  3879     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3880                                 1,                          //aBuffer
       
  3881                                 NULL,                       //aRegion
       
  3882                                 NULL,                       //aStatusConsumed
       
  3883                                 NULL,                       //aStatusDisplayed
       
  3884                                 NULL,                       //aTimeStamp
       
  3885                                 &statusDisplayedX2,         //aStatusDispXTimes
       
  3886                                 &X                          //aDisplayedXTimes
       
  3887                                 );
       
  3888     
       
  3889     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  3890     ASSERT_TRUE(iSourceStreamUpdatedCalled == 4);
       
  3891     
       
  3892     User::WaitForRequest(statusDisplayedX1);
       
  3893     ASSERT_EQUALS(statusDisplayedX1.Int(), KErrOverflow);
       
  3894     
       
  3895     for (TInt i = 0; i < X; ++i)
       
  3896         {
       
  3897         ASSERT_EQUALS(statusDisplayedX2.Int(), KRequestPending);
       
  3898         
       
  3899         // Pretend that a composition has occured
       
  3900         khronos_int32_t newNotificationsMask = 0;
       
  3901         SymbianStreamProcessNotifications(iNs, 
       
  3902                                             iExpectedSourceStreamUpdatedEventMask, 
       
  3903                                             iScreenNo,
       
  3904                                             ++iStreamUpdatedSerialNumber,
       
  3905                                             &newNotificationsMask);
       
  3906         if (i < X -1)
       
  3907             {
       
  3908             ASSERT_TRUE(newNotificationsMask == ESOWF_EventDisplayedX);
       
  3909             }
       
  3910         else
       
  3911             {
       
  3912             ASSERT_TRUE(newNotificationsMask == 0);
       
  3913             }
       
  3914         }
       
  3915     
       
  3916     // Make sure displayed event was completed
       
  3917     User::WaitForRequest(statusDisplayedX2);
       
  3918     ASSERT_EQUALS(statusDisplayedX2.Int(), KErrNone);
       
  3919     
       
  3920     SymbianStreamRemoveReference(iNs);
       
  3921     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  3922     }
       
  3923 
       
  3924 /**
       
  3925 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0120_3
       
  3926 @SYMTestCaseDesc        Test overflow conditions on notifications for available
       
  3927 @SYMREQ                 
       
  3928 @SYMPREQ                PREQ2400
       
  3929 @SYMTestType            CT
       
  3930 @SYMTestPriority        High
       
  3931 @SYMTestPurpose         Verify that the surface stream adaptation correctly handles duplicate notifications
       
  3932                         registered by SUS for content updates on different buffers
       
  3933 @SYMTestActions
       
  3934 
       
  3935      1.  Create a surface
       
  3936      2.  Create a native stream for the surface
       
  3937      3.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  3938      4.  Register for available notification (d1)
       
  3939      5.  Submit an update to the surface on buffer 0
       
  3940      6.  Register for available notification (d2)
       
  3941      7.  Submit an update to the surface on buffer 1
       
  3942      8.  The observer function should be invoked and verifies that stream and event parameters.
       
  3943      9.  The tester simulates the end of a composition by firing SymbianStreamProcessNotifications
       
  3944      10. Verify d1 status is completed with KErrOverflow and d2 status is completed with KErrNone
       
  3945      11. Destroy the native stream
       
  3946         
       
  3947 @SYMTestExpectedResults
       
  3948     No errors, d1 status completed with KErrOverflow, d2 status completed with KErrNone.
       
  3949         
       
  3950 */
       
  3951 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0120_3L()
       
  3952     {
       
  3953     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  3954     TRAPD(err, GrowCleanupStackL());
       
  3955     ASSERT_TRUE(err == KErrNone);
       
  3956     
       
  3957     iScreenNo = 0;    
       
  3958     iContextUpdatedFlags = 0;
       
  3959     iStreamUpdatedSerialNumber = 1;
       
  3960     iSourceStreamUpdatedCalled = 0;
       
  3961     //force composition, otherwise we may never be able to experience the overflow
       
  3962     iImmediateAvailable = EFalse;
       
  3963     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  3964     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  3965     ASSERT_FALSE(surface.IsNull());
       
  3966     
       
  3967     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  3968     err = SymbianStreamAcquire(&surface, &iNs);
       
  3969     ASSERT_TRUE(err == KErrNone);
       
  3970     ASSERT_TRUE(iNs);
       
  3971     
       
  3972     err = SymbianStreamAddExtendedObserver(iNs, SourceStreamUpdatedCallback, this, iScreenNo, ESOWF_EventUpdated);
       
  3973     ASSERT_TRUE(err == KErrNone);
       
  3974     
       
  3975     TRequestStatus statusAvailable1, statusAvailable2, statusAvailable3;
       
  3976 
       
  3977     CExtensionContainer* updateExtension = NULL;
       
  3978     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  3979     ASSERT_TRUE(err == KErrNone);
       
  3980     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  3981     ASSERT_NOT_NULL(updateProxy);
       
  3982     
       
  3983     iExpectedSourceStreamUpdatedEventMask = 0;
       
  3984 
       
  3985     updateProxy->ContentUpdated(surface,                    //aSurface
       
  3986                                 0,                          //aBuffer
       
  3987                                 NULL,                       //aRegion
       
  3988                                 &statusAvailable1,          //aStatusConsumed
       
  3989                                 NULL,                       //aStatusDisplayed
       
  3990                                 NULL,                       //aTimeStamp
       
  3991                                 NULL,                       //aStatusDispXTimes
       
  3992                                 NULL                        //aDisplayedXTimes
       
  3993                                 );
       
  3994     
       
  3995     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  3996     ASSERT_TRUE(iSourceStreamUpdatedCalled == 2);
       
  3997     
       
  3998     iExpectedSourceStreamUpdatedEventMask = ESOWF_EventAvailable;
       
  3999     
       
  4000     updateProxy->ContentUpdated(surface,                    //aSurface
       
  4001                                 1,                          //aBuffer
       
  4002                                 NULL,                       //aRegion
       
  4003                                 &statusAvailable2,          //aStatusConsumed
       
  4004                                 NULL,                       //aStatusDisplayed
       
  4005                                 NULL,                       //aTimeStamp
       
  4006                                 NULL,                       //aStatusDispXTimes
       
  4007                                 NULL                        //aDisplayedXTimes
       
  4008                                 );
       
  4009     
       
  4010     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  4011     ASSERT_TRUE(iSourceStreamUpdatedCalled == 4);
       
  4012    
       
  4013     iExpectedSourceStreamUpdatedEventMask = ESOWF_EventAvailable;
       
  4014     
       
  4015     updateProxy->ContentUpdated(surface,                    //aSurface
       
  4016                                 2,                          //aBuffer
       
  4017                                 NULL,                       //aRegion
       
  4018                                 &statusAvailable3,          //aStatusConsumed
       
  4019                                 NULL,                       //aStatusDisplayed
       
  4020                                 NULL,                       //aTimeStamp
       
  4021                                 NULL,                       //aStatusDispXTimes
       
  4022                                 NULL                        //aDisplayedXTimes
       
  4023                                 );
       
  4024     
       
  4025     // Verify that the context's callback is invoked when SubmitUpdate is called.
       
  4026     ASSERT_TRUE(iSourceStreamUpdatedCalled == 6);
       
  4027    
       
  4028     // Theoretically KErrNone could be returned because buffer 0 is actually available.
       
  4029     // However, this would be a change in behaviour.
       
  4030     User::WaitForRequest(statusAvailable1);
       
  4031     ASSERT_EQUALS(statusAvailable1.Int(), KErrOverflow);
       
  4032     
       
  4033     // Pretend that a composition has occured
       
  4034     khronos_int32_t newNotificationsMask = 0;
       
  4035     SymbianStreamProcessNotifications(iNs, 
       
  4036                                         iExpectedSourceStreamUpdatedEventMask, 
       
  4037                                         iScreenNo,
       
  4038                                         iStreamUpdatedSerialNumber,
       
  4039                                         &newNotificationsMask);
       
  4040     
       
  4041     ASSERT_TRUE(newNotificationsMask == 0);
       
  4042     
       
  4043     // Make sure displayed event was completed
       
  4044     User::WaitForRequest(statusAvailable2);
       
  4045     ASSERT_EQUALS(statusAvailable2.Int(), KErrNone);
       
  4046     
       
  4047     SymbianStreamRemoveReference(iNs);
       
  4048     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  4049     }
       
  4050 
       
  4051 
       
  4052 
       
  4053 /**
       
  4054 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0122
       
  4055 @SYMTestCaseDesc        
       
  4056 @SYMREQ                 
       
  4057 @SYMPREQ                PREQ2400
       
  4058 @SYMTestType            CT
       
  4059 @SYMTestPriority        High
       
  4060 @SYMTestPurpose         Tests an end to end displayed notification.
       
  4061 @SYMTestActions
       
  4062 
       
  4063      1.  Create a surface.
       
  4064      2.  Create a native stream for the surface.
       
  4065      3.  Register an observer for content-update events.
       
  4066      4.  Register notifications for displayed, available and displayed-x-times.
       
  4067      5.  Submit an update to the surface
       
  4068      6.  Remove the content-updated observer.
       
  4069      7.  Wait for the request status objects to be completed.
       
  4070         
       
  4071 @SYMTestExpectedResults
       
  4072     The notification status objects are completed with KErrCancel.
       
  4073         
       
  4074  **/
       
  4075 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0122L()
       
  4076     {
       
  4077     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  4078     TRAPD(err, GrowCleanupStackL());
       
  4079     ASSERT_TRUE(err == KErrNone);
       
  4080     
       
  4081     iScreenNo = 0;    
       
  4082     iContextUpdatedFlags = 0;
       
  4083     iStreamUpdatedSerialNumber = 1;
       
  4084     iSourceStreamUpdatedCalled = 0;
       
  4085     CTestNativeStream::iTester = this;
       
  4086     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  4087     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  4088     ASSERT_FALSE(surface.IsNull());
       
  4089     
       
  4090     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  4091     err = SymbianStreamAcquire(&surface, &iNs);
       
  4092     ASSERT_TRUE(err == KErrNone);
       
  4093     ASSERT_TRUE(iNs);
       
  4094     
       
  4095     err = SymbianStreamAddExtendedObserver(iNs, SourceStreamUpdatedCallback, this, iScreenNo, ESOWF_EventUpdated);
       
  4096     ASSERT_TRUE(err == KErrNone);
       
  4097     
       
  4098     TRequestStatus statusDisplayed, statusAvailable, statusDisplayedX;
       
  4099     TUint32 displayedTime = 0;
       
  4100     TInt X = 42;
       
  4101 
       
  4102     CExtensionContainer* updateExtension = NULL;
       
  4103     err = SymbianStreamHasRegisteredScreenNotifications(iScreenNo,reinterpret_cast<void**>(&updateExtension));
       
  4104     ASSERT_TRUE(err == KErrNone);
       
  4105     MCompositionSurfaceUpdate* updateProxy=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  4106     ASSERT_NOT_NULL(updateProxy);
       
  4107     
       
  4108     iExpectedSourceStreamUpdatedEventMask = ESOWF_EventDisplayed | ESOWF_EventDisplayedX;
       
  4109 
       
  4110     updateProxy->ContentUpdated(surface,                    //aSurface
       
  4111                                 0,                          //aBuffer
       
  4112                                 NULL,                       //aRegion
       
  4113                                 &statusAvailable,           //aStatusConsumed
       
  4114                                 &statusDisplayed,           //aStatusDisplayed
       
  4115                                 &displayedTime,             //aTimeStamp
       
  4116                                 &statusDisplayedX,          //aStatusDispXTimes
       
  4117                                 &X                          //aDisplayedXTimes
       
  4118                                 );     
       
  4119     
       
  4120     ASSERT_TRUE(iSourceStreamUpdatedCalled == 2);
       
  4121     err = SymbianStreamRemoveObserver(iNs, this, ESOWF_EventUpdated);
       
  4122     ASSERT_TRUE(err == KErrNone);
       
  4123     
       
  4124     User::WaitForRequest(statusDisplayed);
       
  4125     ASSERT_EQUALS(statusDisplayed.Int(), KErrCancel);
       
  4126     User::WaitForRequest(statusAvailable);
       
  4127     ASSERT_EQUALS(statusAvailable.Int(), KErrCancel);
       
  4128     User::WaitForRequest(statusDisplayedX);
       
  4129     ASSERT_EQUALS(statusDisplayedX.Int(), KErrCancel);
       
  4130     
       
  4131     SymbianStreamRemoveReference(iNs);
       
  4132     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  4133     
       
  4134     iUtility->DestroySurface(surface);
       
  4135     }
       
  4136 
       
  4137 /**
       
  4138 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0130
       
  4139 @SYMTestCaseDesc        Add/remove Sym observers - positive test cases
       
  4140 @SYMREQ                 
       
  4141 @SYMPREQ                PREQ2400
       
  4142 @SYMTestType            CT
       
  4143 @SYMTestPriority        
       
  4144 @SYMTestPurpose         Verify that Sym observers can be added, removed and re-added
       
  4145 @SYMTestActions 
       
  4146         Create a surface with 1 buffer
       
  4147         Add a Sym observer (displayed notification) 
       
  4148         Remove the Sym observer
       
  4149         Add the Sym observer
       
  4150 @SYMTestExpectedResults
       
  4151         KErrNone is returned when the Sym observer is added
       
  4152         KErrNone is returned when the Sym observer is removed
       
  4153         KErrNone is returned when the Sym observer is re-added
       
  4154  **/ 
       
  4155 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0130L()
       
  4156     {
       
  4157     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  4158     TRAPD(err, GrowCleanupStackL());
       
  4159     ASSERT_TRUE(err == KErrNone);
       
  4160     
       
  4161     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 1);
       
  4162     ASSERT_FALSE(surface.IsNull());
       
  4163     
       
  4164     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  4165     SymbianStreamType ns;
       
  4166     err = SymbianStreamAcquire(&surface,&ns);
       
  4167     ASSERT_TRUE(err == KErrNone);    
       
  4168     ASSERT_TRUE(ns);
       
  4169     
       
  4170     TInt32 screenNumber = 0;
       
  4171     TInt localnumber = 0;
       
  4172     err = SymbianStreamAddExtendedObserver(ns, TestUpdateCallback, &localnumber, screenNumber, ESOWF_EventDisplayed);
       
  4173     ASSERT_TRUE(err == KErrNone);
       
  4174     err = SymbianStreamRemoveObserver(ns, &localnumber, ESOWF_EventDisplayed);
       
  4175     ASSERT_TRUE(err == KErrNone);
       
  4176     err = SymbianStreamAddExtendedObserver(ns, TestUpdateCallback, &localnumber, screenNumber, ESOWF_EventDisplayed);
       
  4177     ASSERT_TRUE(err == KErrNone);
       
  4178     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  4179     }
       
  4180 
       
  4181 /**
       
  4182 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0131
       
  4183 @SYMTestCaseDesc        Add/remove Sym observers - negative test cases
       
  4184 @SYMREQ                 
       
  4185 @SYMPREQ                PREQ2400
       
  4186 @SYMTestType            CT
       
  4187 @SYMTestPriority        
       
  4188 @SYMTestPurpose         Verify that Sym observers reject invalid parameters
       
  4189 @SYMTestActions 
       
  4190         Create a surface with 1 buffer
       
  4191         Add an invalid Sym observer (invalid event flag)
       
  4192         Remove a non-existent Sym observer
       
  4193         Add a valid Sym observer
       
  4194         Add the same Sym observer
       
  4195         Remove the valid Sym observer
       
  4196         Remove the same Sym observer
       
  4197 @SYMTestExpectedResults
       
  4198         KErrArgument is returned and the observer list is un-changed
       
  4199         KErrNotFound is returned and the observer list is un-changed
       
  4200         KErrOverflow is returned when the Sym observer is added again and the observer list is un-changed
       
  4201         KErrNotFound is returned when the Sym observer is removed again the observer list is un-changed
       
  4202  **/ 
       
  4203 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0131L()
       
  4204     {
       
  4205     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  4206     TRAPD(err, GrowCleanupStackL());
       
  4207     ASSERT_TRUE(err == KErrNone);
       
  4208     
       
  4209     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 1);
       
  4210     ASSERT_FALSE(surface.IsNull());
       
  4211     
       
  4212     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  4213     SymbianStreamType ns;
       
  4214     err = SymbianStreamAcquire(&surface, &ns);
       
  4215     ASSERT_TRUE(err == KErrNone);
       
  4216     ASSERT_TRUE(ns);
       
  4217     
       
  4218     TInt32 screenNumber = 0;
       
  4219     err = SymbianStreamAddExtendedObserver(ns, NULL, NULL, screenNumber, ESOWF_NoEvent);
       
  4220     ASSERT_TRUE(err == KErrArgument);
       
  4221     err = SymbianStreamRemoveObserver(ns, &screenNumber, ESOWF_EventDisplayed);
       
  4222     ASSERT_TRUE(err == KErrNotFound);
       
  4223     
       
  4224     // add the same observer twice
       
  4225     err = SymbianStreamAddExtendedObserver(ns, NULL, NULL, screenNumber, ESOWF_EventDisplayed);
       
  4226     ASSERT_TRUE(err == KErrArgument);
       
  4227     err = SymbianStreamAddExtendedObserver(ns, NULL, NULL, screenNumber, ESOWF_EventDisplayed);
       
  4228     ASSERT_TRUE(err == KErrArgument);
       
  4229     
       
  4230     // remove the same observer
       
  4231     err = SymbianStreamRemoveObserver(ns, &screenNumber, ESOWF_EventDisplayed);
       
  4232     ASSERT_TRUE(err == KErrNotFound);
       
  4233     err = SymbianStreamRemoveObserver(ns, &screenNumber, ESOWF_EventDisplayed);
       
  4234     ASSERT_TRUE(err == KErrNotFound);
       
  4235     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  4236     }
       
  4237 
       
  4238 /**
       
  4239 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0132
       
  4240 @SYMTestCaseDesc        Destroy a native stream when a Sym observer is registered
       
  4241 @SYMREQ                 
       
  4242 @SYMPREQ                PREQ2400
       
  4243 @SYMTestType            CT
       
  4244 @SYMTestPriority        
       
  4245 @SYMTestPurpose         Verify that Sym observers are safely removed before native stream destruction
       
  4246 @SYMTestActions 
       
  4247         Create a surface with 1 buffer
       
  4248         Add a Sym observer (displayed notification) 
       
  4249         Destroy the native stream
       
  4250         Create another native stream using the surface created previously
       
  4251         Remove the same Sym observer added in step 2
       
  4252 @SYMTestExpectedResults
       
  4253         KErrNone is returned when the Sym observer is added
       
  4254         KErrNotFound is returned when the Sym observer is attempting to be removed
       
  4255  **/ 
       
  4256 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0132L()
       
  4257     {
       
  4258     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  4259     TRAPD(err, GrowCleanupStackL());
       
  4260     ASSERT_TRUE(err == KErrNone);
       
  4261 
       
  4262     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 1);
       
  4263     ASSERT_FALSE(surface.IsNull());
       
  4264     
       
  4265     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  4266     SymbianStreamType ns;
       
  4267     err = SymbianStreamAcquire(&surface, &ns);
       
  4268     ASSERT_TRUE(err == KErrNone);
       
  4269     ASSERT_TRUE(ns);
       
  4270     
       
  4271     TInt screenNumber = 0;
       
  4272     err = SymbianStreamAddExtendedObserver(ns, NULL, NULL, screenNumber, ESOWF_EventDisplayed);
       
  4273     ASSERT_TRUE(err == KErrArgument);
       
  4274    
       
  4275     SymbianStreamRemoveReference(ns);
       
  4276     
       
  4277     SymbianStreamType ns2;
       
  4278     err = SymbianStreamAcquire(&surface, &ns2);
       
  4279     ASSERT_TRUE(err == KErrNone);
       
  4280     ASSERT_TRUE(ns2);
       
  4281     
       
  4282     err = SymbianStreamRemoveObserver(ns2, &screenNumber, ESOWF_EventDisplayed);
       
  4283     ASSERT_TRUE(err == KErrNotFound);
       
  4284     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  4285 	}
       
  4286 
       
  4287 /**
       
  4288 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0133
       
  4289 @SYMTestCaseDesc        Test the construction/destruction of a CContentUpdateProxy
       
  4290 @SYMREQ                 
       
  4291 @SYMPREQ                PREQ2400
       
  4292 @SYMTestType            CT
       
  4293 @SYMTestPriority        
       
  4294 @SYMTestPurpose         Verify that additional screens can be created and destroyed
       
  4295 @SYMTestActions
       
  4296 
       
  4297      1.  Create a new CContentUpdateProxy (screen 1)
       
  4298      2.  Verify API version and Internal version are correct
       
  4299      3.  Create a surface
       
  4300      4.  Create a native stream for the surface
       
  4301      5.  Register the test class as an observer for ESOWF_EventUpdated to act as a fake composer
       
  4302      6.  Submit an update to the surface
       
  4303      7.  The observer function should be invoked and verifies that stream and event parameters.
       
  4304      8.  Verify that the source-stream updated callback is invoked.
       
  4305      9.  Destroy the native stream.
       
  4306      10. Destroy the CContentUpdateProxy (screen 1)
       
  4307 
       
  4308 @SYMTestExpectedResults
       
  4309         KErrNone is returned when screen 1 is created
       
  4310         API version and Internal version match expected results
       
  4311         KErrNone is returned when screen 1 is destroyed
       
  4312  **/ 
       
  4313 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0133L()
       
  4314     {
       
  4315     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  4316     TRAPD(err, GrowCleanupStackL());
       
  4317     ASSERT_TRUE(err == KErrNone);
       
  4318     
       
  4319     // Register a new screen
       
  4320     iScreenNo = 0;    
       
  4321     iContextUpdatedFlags = 0;
       
  4322     iStreamUpdatedSerialNumber = 1;
       
  4323     iSourceStreamUpdatedCalled = 0;
       
  4324     iImmediateVisible = SYM_CONTENT_VISIBLE;
       
  4325     
       
  4326     TSurfaceId surface=iUtility->CreateSurfaceL(TSize(100,100), EUidPixelFormatARGB_8888_PRE, 400, 4);
       
  4327     ASSERT_FALSE(surface.IsNull());
       
  4328     
       
  4329     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  4330     err = SymbianStreamRegisterScreenNotifications(1, 0, KCompositorVersion);
       
  4331     ASSERT_TRUE(err == KErrNone);   
       
  4332     
       
  4333 
       
  4334     CExtensionContainer* updateExtension = NULL;
       
  4335     err = SymbianStreamHasRegisteredScreenNotifications(1,reinterpret_cast<void**>(&updateExtension));
       
  4336     ASSERT_TRUE(err == KErrNone);
       
  4337     MCompositionSurfaceUpdate* screen1=updateExtension->GetInterface<MCompositionSurfaceUpdate>();
       
  4338     ASSERT_NOT_NULL(screen1);
       
  4339 
       
  4340     TVersion expectedVersion(KCompositorVersionMajor,KCompositorVersionMinor,KCompositorVersionRevision);
       
  4341     
       
  4342     ASSERT_EQUALS(screen1->ApiVersion(), 3);
       
  4343     ASSERT_TRUE(screen1->InternalVersion().iBuild == expectedVersion.iBuild &&
       
  4344                 screen1->InternalVersion().iMajor == expectedVersion.iMajor &&
       
  4345                 screen1->InternalVersion().iMinor == expectedVersion.iMinor);
       
  4346         
       
  4347     err = SymbianStreamAcquire(&surface, &iNs);
       
  4348     ASSERT_TRUE(err == KErrNone);
       
  4349     ASSERT_TRUE(iNs);
       
  4350     
       
  4351     iExpectedSourceStreamUpdatedEventMask = 0;
       
  4352     err = SymbianStreamAddObserver(iNs, SourceStreamUpdatedCallback, this);
       
  4353     ASSERT_TRUE(err == KErrNone);
       
  4354     
       
  4355     iSourceStreamUpdatedCalled = EFalse;    
       
  4356     screen1->ContentUpdated(surface,0,NULL,NULL,NULL,NULL,NULL,NULL);
       
  4357     
       
  4358     // Verify that the context's callback (screen 1) is invoked when SubmitUpdate is called.
       
  4359     ASSERT_TRUE(iSourceStreamUpdatedCalled == 1);
       
  4360     
       
  4361     SymbianStreamRemoveReference(iNs);
       
  4362     
       
  4363     // Destroy the context (screen 1)
       
  4364     err = SymbianStreamUnregisterScreenNotifications(1);
       
  4365     ASSERT_TRUE(err == KErrNone);
       
  4366     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  4367     }              
       
  4368 
       
  4369 /**
       
  4370 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0140
       
  4371 @SYMTestCaseDesc        Negative test - Acquire write/read buffers and retrieve the buffer ptr (single threaded test).
       
  4372 @SYMREQ                 
       
  4373 @SYMPREQ                PREQ2400
       
  4374 @SYMTestType            CT
       
  4375 @SYMTestPriority        
       
  4376 @SYMTestPurpose         Verify SymbianStreamAcquireWriteBuffer(), SymbianStreamReleaseWriteBuffer(),
       
  4377                         SymbianStreamAcquireReadBuffer() and SymbianStreamReleaseReadBuffer() methods
       
  4378                         work as expected.
       
  4379                         
       
  4380 @SYMTestActions 
       
  4381         Create a native stream 
       
  4382         For each buffer:
       
  4383         - Acquire the read buffer 
       
  4384         - Acquire the write buffer 
       
  4385         - Release the write buffer
       
  4386         - Acquire the read buffer
       
  4387 
       
  4388         Repeat for each buffer. Finally:
       
  4389         Acquire the write buffer
       
  4390         Release the write buffer    
       
  4391 @SYMTestExpectedResults
       
  4392         For each buffer of the native stream, check:
       
  4393         - The read buffer should be aquired successfully
       
  4394         If the number of buffers = 1, check:
       
  4395         - The write buffer should be aquired successfully
       
  4396         If the number of buffers > 1, check:
       
  4397         - The write buffer before the final one should be aquired successfully
       
  4398         - The final acquire write buffer call should return OWF_INVALID_HANDLE if not single buffered
       
  4399  **/
       
  4400 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0140L(TInt aNumBuffers)
       
  4401     {
       
  4402     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  4403     TRAPD(err, GrowCleanupStackL());
       
  4404     ASSERT_TRUE(err == KErrNone);
       
  4405 
       
  4406     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  4407     
       
  4408     ASSERT_TRUE(aNumBuffers > 0);
       
  4409     
       
  4410     TSize surfaceSize(TSize(100,100));
       
  4411     khronos_int32_t width = surfaceSize.iWidth;
       
  4412     khronos_int32_t height = surfaceSize.iHeight;
       
  4413     
       
  4414     OWF_IMAGE_FORMAT pixelFormat =
       
  4415         {
       
  4416         OWF_IMAGE_ARGB8888,
       
  4417         ETrue,
       
  4418         ETrue,
       
  4419         aNumBuffers
       
  4420         };  
       
  4421     
       
  4422     SymbianStreamType ns=helperCreateImageStream(width,
       
  4423                                                     height,
       
  4424                                                     &pixelFormat,
       
  4425                                                     aNumBuffers);
       
  4426     ASSERT_TRUE(ns);
       
  4427     
       
  4428     khronos_int32_t writeBuffer = 0;
       
  4429     khronos_int32_t readBuffer = 0;    
       
  4430     TInt bufferCount;
       
  4431     
       
  4432     if (aNumBuffers == 1)
       
  4433         {
       
  4434         bufferCount = aNumBuffers;
       
  4435         }
       
  4436     else
       
  4437         {
       
  4438         bufferCount = aNumBuffers - 1;
       
  4439         }
       
  4440     
       
  4441     RArray<TInt> bufferHandleArray;
       
  4442 
       
  4443     // Loop through the buffers
       
  4444     for (TInt count=0; count<bufferCount; count++)
       
  4445         {
       
  4446         err = SymbianStreamAcquireReadBuffer(ns, &readBuffer);
       
  4447         ASSERT_TRUE(err == KErrNone);
       
  4448         ASSERT_TRUE(readBuffer);
       
  4449         bufferHandleArray.Append(readBuffer);
       
  4450         
       
  4451         // Acquire the write buffer
       
  4452         err = SymbianStreamAcquireWriteBuffer(ns, &writeBuffer);
       
  4453         ASSERT_TRUE(err == KErrNone);
       
  4454         ASSERT_TRUE(writeBuffer);     
       
  4455         SymbianStreamReleaseWriteBuffer(ns,writeBuffer);        
       
  4456         }   
       
  4457 
       
  4458     // Acquire final read buffer
       
  4459     khronos_int32_t finalReadBuffer;
       
  4460     err = SymbianStreamAcquireReadBuffer(ns, &finalReadBuffer);
       
  4461     ASSERT_TRUE(err == KErrNone);
       
  4462     ASSERT_TRUE(finalReadBuffer);
       
  4463     bufferHandleArray.Append(finalReadBuffer);        
       
  4464 
       
  4465     khronos_int32_t finalWriteBuffer;
       
  4466     err = SymbianStreamAcquireWriteBuffer(ns, &finalWriteBuffer);
       
  4467     ASSERT_TRUE(err != KErrBadHandle);
       
  4468     
       
  4469     // Final checks
       
  4470     if (aNumBuffers == 1)
       
  4471         {
       
  4472         ASSERT_TRUE(finalWriteBuffer);
       
  4473         err =  SymbianStreamReleaseWriteBuffer(ns,finalWriteBuffer);
       
  4474         ASSERT_TRUE(err == KErrNone);
       
  4475         }
       
  4476     else
       
  4477         {
       
  4478         ASSERT_FALSE(finalWriteBuffer);        
       
  4479         }
       
  4480     
       
  4481     for (TInt x=0; x < bufferHandleArray.Count(); ++x)
       
  4482         {
       
  4483         err = SymbianStreamReleaseReadBuffer(ns,bufferHandleArray[x]);
       
  4484         ASSERT_TRUE(err == KErrNone);
       
  4485         }
       
  4486 
       
  4487     err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer);
       
  4488     ASSERT_TRUE(err == KErrNone);
       
  4489     ASSERT_TRUE(writeBuffer);     
       
  4490     err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer);
       
  4491     ASSERT_TRUE(err == KErrNone);
       
  4492     ASSERT_TRUE(writeBuffer);     
       
  4493 
       
  4494     bufferHandleArray.Close();
       
  4495     SymbianStreamRemoveReference(ns);
       
  4496     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  4497     }
       
  4498 
       
  4499 /**
       
  4500 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0141
       
  4501 @SYMTestCaseDesc        Negative test - Acquire multiple read buffers before releasing write buffer (single threaded test).
       
  4502 @SYMREQ                 
       
  4503 @SYMPREQ                PREQ2400
       
  4504 @SYMTestType            CT
       
  4505 @SYMTestPriority        
       
  4506 @SYMTestPurpose         Verify SymbianStreamAcquireWriteBuffer(), SymbianStreamReleaseWriteBuffer(),
       
  4507                         SymbianStreamAcquireReadBuffer() and SymbianStreamReleaseReadBuffer() methods
       
  4508                         work as expected.
       
  4509                         
       
  4510 @SYMTestActions 
       
  4511         Create a native stream 
       
  4512         For each buffer:
       
  4513         - Acquire the read buffer multiple times
       
  4514         - Acquire the write buffer 
       
  4515         - Acquire the read buffer       
       
  4516         - Release the write buffer
       
  4517         - Acquire the read buffer
       
  4518 
       
  4519 @SYMTestExpectedResults
       
  4520         For each buffer of the native stream, check:
       
  4521         - The read buffer index should remain the same before release write bufffer is called
       
  4522         If the number of buffers = 1, check:
       
  4523         - The buffer index is always the same
       
  4524         If the number of buffers > 1, check:
       
  4525         - The buffer index increments after release write buffer is called
       
  4526  **/
       
  4527 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0141L(TInt aNumBuffers)
       
  4528     {
       
  4529     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  4530     TRAPD(err, GrowCleanupStackL());
       
  4531     ASSERT_TRUE(err == KErrNone);
       
  4532 
       
  4533     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  4534     
       
  4535     ASSERT_TRUE(aNumBuffers > 0);
       
  4536     
       
  4537     TSize surfaceSize(TSize(100,100));
       
  4538     khronos_int32_t width = surfaceSize.iWidth;
       
  4539     khronos_int32_t height = surfaceSize.iHeight;
       
  4540     
       
  4541     OWF_IMAGE_FORMAT pixelFormat =
       
  4542         {
       
  4543         OWF_IMAGE_ARGB8888,
       
  4544         ETrue,
       
  4545         ETrue,
       
  4546         aNumBuffers
       
  4547         };  
       
  4548     
       
  4549     SymbianStreamType ns=helperCreateImageStream(width,
       
  4550                                                     height,
       
  4551                                                     &pixelFormat,
       
  4552                                                     aNumBuffers);
       
  4553     ASSERT_TRUE(ns);
       
  4554     
       
  4555     khronos_int32_t writeBuffer = 0;
       
  4556     khronos_int32_t readBuffer = 0; 
       
  4557     khronos_int32_t bufferIndexRead1, bufferIndexRead2, bufferIndexRead3, bufferIndexRead4;
       
  4558     khronos_int32_t bufferIndexWrite;
       
  4559     
       
  4560     err = SymbianStreamAcquireReadBuffer(ns, &readBuffer);
       
  4561     ASSERT_TRUE(err == KErrNone);
       
  4562     ASSERT_TRUE(readBuffer);
       
  4563     const TSurfaceId* getId = NULL;
       
  4564     err = SymbianStreamGetBufferId(ns,readBuffer,&bufferIndexRead1,&getId);
       
  4565     ASSERT_TRUE(err == KErrNone);
       
  4566     err = SymbianStreamReleaseReadBuffer(ns,readBuffer);
       
  4567     ASSERT_TRUE(err == KErrNone);
       
  4568     
       
  4569     err = SymbianStreamAcquireReadBuffer(ns, &readBuffer);
       
  4570     ASSERT_TRUE(err == KErrNone);
       
  4571     ASSERT_TRUE(readBuffer);
       
  4572     err = SymbianStreamGetBufferId(ns,readBuffer,&bufferIndexRead2,&getId);
       
  4573     ASSERT_TRUE(err == KErrNone);
       
  4574     SymbianStreamReleaseReadBuffer(ns,readBuffer);
       
  4575     ASSERT_EQUALS(bufferIndexRead1, bufferIndexRead2);
       
  4576 
       
  4577     err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer);
       
  4578     ASSERT_TRUE(err == KErrNone);
       
  4579     ASSERT_TRUE(writeBuffer);     
       
  4580     err = SymbianStreamGetBufferId(ns,writeBuffer,&bufferIndexWrite,&getId);
       
  4581     ASSERT_TRUE(err == KErrNone);
       
  4582     if (aNumBuffers == 1)
       
  4583         {
       
  4584         ASSERT_EQUALS(bufferIndexRead2, bufferIndexWrite);                
       
  4585         }
       
  4586     else
       
  4587         {
       
  4588         ASSERT_NOT_EQUALS((bufferIndexRead2), bufferIndexWrite);        
       
  4589         }
       
  4590 
       
  4591     err = SymbianStreamAcquireReadBuffer(ns,&readBuffer);
       
  4592     ASSERT_TRUE(err == KErrNone);
       
  4593     ASSERT_TRUE(readBuffer);
       
  4594     err = SymbianStreamGetBufferId(ns,readBuffer,&bufferIndexRead3,&getId);
       
  4595     ASSERT_TRUE(err == KErrNone);
       
  4596     err = SymbianStreamReleaseReadBuffer(ns,readBuffer);
       
  4597     ASSERT_TRUE(err == KErrNone);
       
  4598     ASSERT_EQUALS(bufferIndexRead3, bufferIndexRead2);
       
  4599     
       
  4600     err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer);
       
  4601     ASSERT_TRUE(err == KErrNone);
       
  4602     
       
  4603     err = SymbianStreamAcquireReadBuffer(ns,&readBuffer);
       
  4604     ASSERT_TRUE(err == KErrNone);
       
  4605     ASSERT_TRUE(readBuffer);
       
  4606     err = SymbianStreamGetBufferId(ns,readBuffer,&bufferIndexRead4,&getId);
       
  4607     ASSERT_TRUE(err == KErrNone);
       
  4608     err = SymbianStreamReleaseReadBuffer(ns,readBuffer);
       
  4609     ASSERT_TRUE(err == KErrNone);
       
  4610     if (aNumBuffers == 1)
       
  4611         {
       
  4612         ASSERT_EQUALS(bufferIndexRead3, bufferIndexRead4);                
       
  4613         }
       
  4614     else
       
  4615         {
       
  4616         ASSERT_NOT_EQUALS((bufferIndexRead3), bufferIndexRead4);        
       
  4617         }
       
  4618 
       
  4619     SymbianStreamRemoveReference(ns);
       
  4620     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  4621     }
       
  4622 
       
  4623 /**
       
  4624 @SYMTestCaseID          GFX_OPENWFC_NATIVESTREAM_0142
       
  4625 @SYMTestCaseDesc        Special surface ID unit tests
       
  4626 @SYMREQ                 
       
  4627 @SYMPREQ                PREQ2400
       
  4628 @SYMTestType            
       
  4629 @SYMTestPriority        
       
  4630 @SYMTestPurpose         Exercise special surface creation and flip operations
       
  4631                         
       
  4632 @SYMTestActions 
       
  4633         Generate a special surface ID with pixel formats of type 
       
  4634         EUidPixelFormatARGB_8888_PRE, EUidPixelFormatRGB_888, 
       
  4635         EUidPixelFormatRGB_565, and EUidPixelFormatRGB_332. Then
       
  4636         - Acquire the read buffer
       
  4637         - Acquire the write buffer 
       
  4638         - Check that they are the same
       
  4639         - Add a value to the read buffer
       
  4640         - Check that the write buffer has the same value       
       
  4641         - Release the write buffer
       
  4642         - Release the read buffer
       
  4643         Then reset the special surface ID, acquire a stream, and read header data.
       
  4644         Set the flip flag to true and re-acquire the stream.
       
  4645         Compare header data of pre-flip and post-flip cases.
       
  4646 
       
  4647 @SYMTestExpectedResults
       
  4648         Read/write buffer pairs are always identical.
       
  4649         Flipped stream has width and height switched and stride is different
       
  4650  **/ 
       
  4651 void CTestNativeStream::GRAPHICS_OPENWFC_NATIVESTREAM_0142L()
       
  4652     {    
       
  4653     _LIT(KDisplayChannelLdd, "display0.ldd");
       
  4654     
       
  4655     RHeap* mainHeap = COpenWfcStreamMap::InstanceL().GetMainHeap();
       
  4656     TRAPD(err, GrowCleanupStackL());
       
  4657     ASSERT_TRUE(err == KErrNone);
       
  4658     
       
  4659     CleanupStack::PushL(TCleanupItem(PopHeap, User::SwitchHeap(mainHeap)));
       
  4660 
       
  4661     err = User::LoadLogicalDevice(KDisplayChannelLdd);
       
  4662     RDisplayChannel testChannel;
       
  4663     User::LeaveIfError(testChannel.Open(0));
       
  4664     
       
  4665     TSurfaceId testId;
       
  4666     SymbianStreamType ns;
       
  4667     TUidPixelFormat testGuids[] = {EUidPixelFormatARGB_8888_PRE, EUidPixelFormatRGB_888, EUidPixelFormatRGB_565, EUidPixelFormatRGB_332};
       
  4668     TInt size = sizeof(testGuids) / sizeof(testGuids[0]);
       
  4669     TUint8 *pWriteBuffer = NULL;
       
  4670     khronos_int32_t writeBuffer;
       
  4671     TUint8 *pReadBuffer = NULL;
       
  4672     khronos_int32_t readBuffer;
       
  4673 
       
  4674     TInt halStride = 0;
       
  4675     TInt halMode = 0;
       
  4676 
       
  4677     // For header variables before flipping
       
  4678     TInt32 preFlipWidth = 0;
       
  4679     TInt32 preFlipHeight = 0;
       
  4680     TInt32 preFlipStreamStride = 0;
       
  4681     TUidPixelFormat preFlipStreamFormat = EUidPixelFormatUnknown;
       
  4682     TInt32 preFlipStreamPixelSize = 0;
       
  4683     
       
  4684     // For header variables after flipping
       
  4685     TInt32 width = 0;
       
  4686     TInt32 height = 0;
       
  4687     TInt32 streamStride = 0;
       
  4688     TUidPixelFormat streamFormat = EUidPixelFormatUnknown;
       
  4689     TInt32 streamPixelSize = 0;
       
  4690     
       
  4691     for (TInt ii = 0; ii < size; ii++)
       
  4692         {
       
  4693         HAL::Get(0, HALData::EDisplayMode, halMode);
       
  4694         
       
  4695         testId.iInternal[TSurfaceId::TScreenSurfaceUsage::EScreenField] = 0;      // Screen number
       
  4696         testId.iInternal[TSurfaceId::TScreenSurfaceUsage::EHalField] = halMode;          // Rotation and hal mode index
       
  4697         testId.iInternal[TSurfaceId::TScreenSurfaceUsage::ETypeGuidField] = testGuids[ii]; //May be zero for non-GCE modes
       
  4698         testId.iInternal[TSurfaceId::TScreenSurfaceUsage::ETypeClassField] = ((TUint32)(TSurfaceId::EScreenSurface) << TSurfaceId::TScreenSurfaceUsage::ETypeClassShift);  // Type
       
  4699                         
       
  4700         err = SymbianStreamAcquire(&testId, &ns);
       
  4701         ASSERT_TRUE(err == KErrNone);
       
  4702         ASSERT_TRUE(ns);
       
  4703         
       
  4704         err = SymbianStreamAcquireWriteBuffer(ns,&writeBuffer);
       
  4705         ASSERT_TRUE(err == KErrNone);
       
  4706         
       
  4707         err = SymbianStreamGetBufferPointer(ns,writeBuffer,reinterpret_cast<void**>(&pWriteBuffer));
       
  4708         ASSERT_TRUE(err == KErrNone);
       
  4709         ASSERT_NOT_NULL(pWriteBuffer);
       
  4710         
       
  4711         err = SymbianStreamReleaseWriteBuffer(ns,writeBuffer);
       
  4712         ASSERT_TRUE(err == KErrNone);
       
  4713 
       
  4714         err = SymbianStreamAcquireReadBuffer(ns,&readBuffer);
       
  4715         ASSERT_TRUE(err == KErrNone);
       
  4716                     
       
  4717         err = SymbianStreamGetBufferPointer(ns,readBuffer,reinterpret_cast<void**>(&pReadBuffer));
       
  4718         ASSERT_TRUE(err == KErrNone);
       
  4719         ASSERT_NOT_NULL(pReadBuffer);
       
  4720 
       
  4721         err = SymbianStreamReleaseReadBuffer(ns,readBuffer);
       
  4722         ASSERT_TRUE(err == KErrNone);
       
  4723         
       
  4724         ASSERT_SAME(pWriteBuffer, pReadBuffer);
       
  4725         
       
  4726         *pWriteBuffer = 0xFF;
       
  4727         ASSERT_TRUE(*pReadBuffer == 0xFF);
       
  4728         
       
  4729         halStride = halMode;
       
  4730         HAL::Get(0, HALData::EDisplayOffsetBetweenLines, halStride);
       
  4731 
       
  4732         SymbianStreamGetHeader(ns, &preFlipWidth, &preFlipHeight, &preFlipStreamStride, &preFlipStreamFormat, &preFlipStreamPixelSize);
       
  4733         ASSERT_TRUE(preFlipStreamStride == halStride);
       
  4734 
       
  4735         // Now the flipping test
       
  4736         halMode = halMode^TSurfaceId::TScreenSurfaceUsage::EHalFlippedFlag;
       
  4737         testId.iInternal[TSurfaceId::TScreenSurfaceUsage::EHalField] = halMode; 
       
  4738                 
       
  4739         err = SymbianStreamAcquire(&testId, &ns);
       
  4740         ASSERT_TRUE(err == KErrNone);
       
  4741         ASSERT_TRUE(ns);
       
  4742 
       
  4743         halStride = halMode;
       
  4744         HAL::Get(0, HALData::EDisplayOffsetBetweenLines, halStride);
       
  4745         SymbianStreamGetHeader(ns, &width, &height, &streamStride, &streamFormat, &streamPixelSize);
       
  4746         
       
  4747         ASSERT_EQUALS(preFlipWidth, height);
       
  4748         ASSERT_EQUALS(preFlipHeight, width);
       
  4749         ASSERT_EQUALS(preFlipStreamFormat, streamFormat);
       
  4750         ASSERT_TRUE(streamStride == halStride);
       
  4751         ASSERT_EQUALS(preFlipStreamPixelSize, streamPixelSize); 
       
  4752             
       
  4753         SymbianStreamGetHeader(ns, NULL, NULL, NULL, NULL, NULL);
       
  4754         // Clearing the flip flag
       
  4755         halMode = halMode&~TSurfaceId::TScreenSurfaceUsage::EHalFlippedFlag;
       
  4756         
       
  4757         SymbianStreamRemoveReference(ns);     
       
  4758 
       
  4759         *pWriteBuffer = NULL;
       
  4760         pWriteBuffer = NULL;
       
  4761         *pReadBuffer = NULL;
       
  4762         pReadBuffer = NULL;
       
  4763         }
       
  4764     
       
  4765     testChannel.Close();
       
  4766     CleanupStack::PopAndDestroy(); // switch the heap back to current thread's one
       
  4767     }