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