Purge underscored header file barriers
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-NativeImage.cpp
index 6368762..089ab4e 100644 (file)
@@ -116,86 +116,92 @@ int UtcDaliNativeImageDownCast(void)
   END_TEST;
 }
 
-int UtcDaliNativeImageCreateGlTextureN(void)
+int UtcDaliNativeImageExtensionP(void)
 {
   TestApplication application;
   tet_infoline( "Testing Dali::NativeImage::GenerateGlTexture()" );
 
-  NativeImage image;
-  try
-  {
-    image.CreateGlTexture();
-    tet_printf( "Assertion test failed - no Exception\n" );
-    tet_result( TET_FAIL );
-  }
-  catch( Dali::DaliException& e )
-  {
-    DALI_TEST_PRINT_ASSERT( e );
-    DALI_TEST_ASSERT( e, "image &&", TEST_LOCATION );
-  }
+  TestNativeImagePointer testNativeImage = TestNativeImage::New( 16, 16 );
+  DALI_TEST_CHECK( testNativeImage );
+  DALI_TEST_CHECK( NULL != testNativeImage->GetExtension() );
+
+  TestNativeImageNoExtPointer testNativeImage2 = TestNativeImageNoExt::New( 16, 16 );
+  DALI_TEST_CHECK( testNativeImage2 );
+  DALI_TEST_CHECK( NULL == testNativeImage2->GetExtension() );
+
   END_TEST;
 }
 
-int UtcDaliNativeImageCreateGlTextureP(void)
+int UtcDaliNativeImageGetCustomFragmentPreFixP(void)
 {
   TestApplication application;
-  tet_infoline( "Testing Dali::NativeImage::GenerateGlTexture()" );
+  TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
+  NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
 
-  TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
-  NativeImage image = NativeImage::New( *(imageInterface.Get()) );
-  DALI_TEST_CHECK( image );
-
-  image.CreateGlTexture();
-
-  application.SendNotification();
-  application.Render(16);
+  const char* preFix = "#extension GL_OES_EGL_image_external:require\n";
+  DALI_TEST_EQUALS( nativeImage.GetCustomFragmentPreFix(), preFix, TEST_LOCATION );
+  END_TEST;
+}
 
-  DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
-  DALI_TEST_EQUALS( imageInterface->mTargetTextureCalls, 1, TEST_LOCATION );
+int UtcDaliNativeImageGetCustomSamplerTypenameP(void)
+{
+  TestApplication application;
+  TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
+  NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
 
+  const char* samplerTypename = "samplerExternalOES";
+  DALI_TEST_EQUALS( nativeImage.GetCustomSamplerTypename(), samplerTypename, TEST_LOCATION );
   END_TEST;
 }
 
-int UtcDaliNativeImageContextLoss(void)
+
+
+int UtcDaliNativeImageTestCreationFailure(void)
 {
   TestApplication application;
-  tet_infoline( "Testing Dali::NativeImage behaviour through a context lost/regained cycle." );
+  TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
+  NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
 
-  // Build an image that is expected to have a GL texture created for it and
-  // recreated in a GL context recovery:
-  TestNativeImagePointer eagerImageInterface = TestNativeImage::New( 16, 16 );
-  NativeImage eagerImage = NativeImage::New( *(eagerImageInterface.Get()) );
-  DALI_TEST_CHECK( eagerImage );
+  tet_printf("Test what happens when GlExtensionCreate is called, and returns false to indicate an error\n");
 
-  // Build a regular lazy-allocated image for comparison:
-  TestNativeImagePointer lazyImageInterface = TestNativeImage::New( 16, 16 );
-  NativeImage lazyImage = NativeImage::New( *(lazyImageInterface.Get()) );
-  DALI_TEST_CHECK( lazyImage );
+  nativeImageInterface->SetGlExtensionCreateResult( false );
 
-  eagerImage.CreateGlTexture();
+  Actor actor = CreateRenderableActor( nativeImage );
+  actor.SetParentOrigin( ParentOrigin::CENTER );
+  Stage::GetCurrent().Add( actor );
 
-  application.SendNotification();
-  application.Render(16);
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+  TraceCallStack& textureTrace = gl.GetTextureTrace();
+  textureTrace.Reset();
+  textureTrace.Enable(true);
+
+  TraceCallStack& drawTrace = gl.GetDrawTrace();
+  drawTrace.Reset();
+  drawTrace.Enable(true);
 
-  // Cycle through a context loss and regain, asserting that the texture is
-  // not reallocated if it already existed before the cycle and is never allocated
-  // throughout the cycle if of the regular lazy kind:
+  application.SendNotification();
+  application.Render();
 
-  // Call render thread context destroyed / created functions:
-  application.ResetContext();
+  // Test that nothing was rendered
+  //GlExtensionCreate() called twice, once at initialization and once when trying to bind the texture
+  DALI_TEST_EQUALS( nativeImageInterface->mExtensionCreateCalls, 2, TEST_LOCATION );
+  DALI_TEST_EQUALS( nativeImageInterface->mTargetTextureCalls, 0, TEST_LOCATION );
+  DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
+  DALI_TEST_EQUALS( drawTrace.FindMethod("DrawElements") || drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
 
-  // Call event thread function:
-  application.GetCore().RecoverFromContextLoss();
+  textureTrace.Reset();
+  drawTrace.Reset();
 
-  // Run update/render loop
+  nativeImageInterface->SetGlExtensionCreateResult( true );
+  actor.SetPosition( 0, 0, 1 );
   application.SendNotification();
-  application.Render(16);
-
-  DALI_TEST_EQUALS( eagerImageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
-  DALI_TEST_EQUALS( eagerImageInterface->mTargetTextureCalls, 1, TEST_LOCATION );
+  application.Render();
 
-  DALI_TEST_EQUALS( lazyImageInterface->mExtensionCreateCalls, 0, TEST_LOCATION );
-  DALI_TEST_EQUALS( lazyImageInterface->mTargetTextureCalls, 0, TEST_LOCATION );
+  // This time around, the bind and draw should occur following the call to nativeImage->GlExtensionCreate.
+  DALI_TEST_EQUALS( nativeImageInterface->mExtensionCreateCalls, 3, TEST_LOCATION );
+  DALI_TEST_EQUALS( nativeImageInterface->mTargetTextureCalls, 1, TEST_LOCATION );
+  DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
+  DALI_TEST_EQUALS( drawTrace.FindMethod("DrawElements") || drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );
 
   END_TEST;
 }