Purge underscored header file barriers
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-NativeImage.cpp
index 3dc7568..089ab4e 100644 (file)
@@ -116,90 +116,6 @@ int UtcDaliNativeImageDownCast(void)
   END_TEST;
 }
 
-int UtcDaliNativeImageCreateGlTextureN(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 );
-  }
-  END_TEST;
-}
-
-int UtcDaliNativeImageCreateGlTextureP(void)
-{
-  TestApplication application;
-  tet_infoline( "Testing Dali::NativeImage::GenerateGlTexture()" );
-
-  TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
-  NativeImage image = NativeImage::New( *(imageInterface.Get()) );
-  DALI_TEST_CHECK( image );
-
-  image.CreateGlTexture();
-
-  application.SendNotification();
-  application.Render(16);
-
-  DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
-  DALI_TEST_EQUALS( imageInterface->mTargetTextureCalls, 1, TEST_LOCATION );
-
-  END_TEST;
-}
-
-int UtcDaliNativeImageContextLoss(void)
-{
-  TestApplication application;
-  tet_infoline( "Testing Dali::NativeImage behaviour through a context lost/regained cycle." );
-
-  // 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 );
-
-  // Build a regular lazy-allocated image for comparison:
-  TestNativeImagePointer lazyImageInterface = TestNativeImage::New( 16, 16 );
-  NativeImage lazyImage = NativeImage::New( *(lazyImageInterface.Get()) );
-  DALI_TEST_CHECK( lazyImage );
-
-  eagerImage.CreateGlTexture();
-
-  application.SendNotification();
-  application.Render(16);
-
-  // 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:
-
-  // Call render thread context destroyed / created functions:
-  application.ResetContext();
-
-  // Call event thread function:
-  application.GetCore().RecoverFromContextLoss();
-
-  // Run update/render loop
-  application.SendNotification();
-  application.Render(16);
-
-  DALI_TEST_EQUALS( eagerImageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
-  DALI_TEST_EQUALS( eagerImageInterface->mTargetTextureCalls, 1, TEST_LOCATION );
-
-  DALI_TEST_EQUALS( lazyImageInterface->mExtensionCreateCalls, 0, TEST_LOCATION );
-  DALI_TEST_EQUALS( lazyImageInterface->mTargetTextureCalls, 0, TEST_LOCATION );
-
-  END_TEST;
-}
-
 int UtcDaliNativeImageExtensionP(void)
 {
   TestApplication application;
@@ -207,9 +123,12 @@ int UtcDaliNativeImageExtensionP(void)
 
   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;
 }
 
@@ -234,3 +153,55 @@ int UtcDaliNativeImageGetCustomSamplerTypenameP(void)
   DALI_TEST_EQUALS( nativeImage.GetCustomSamplerTypename(), samplerTypename, TEST_LOCATION );
   END_TEST;
 }
+
+
+
+int UtcDaliNativeImageTestCreationFailure(void)
+{
+  TestApplication application;
+  TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
+  NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
+
+  tet_printf("Test what happens when GlExtensionCreate is called, and returns false to indicate an error\n");
+
+  nativeImageInterface->SetGlExtensionCreateResult( false );
+
+  Actor actor = CreateRenderableActor( nativeImage );
+  actor.SetParentOrigin( ParentOrigin::CENTER );
+  Stage::GetCurrent().Add( actor );
+
+  TestGlAbstraction& gl = application.GetGlAbstraction();
+  TraceCallStack& textureTrace = gl.GetTextureTrace();
+  textureTrace.Reset();
+  textureTrace.Enable(true);
+
+  TraceCallStack& drawTrace = gl.GetDrawTrace();
+  drawTrace.Reset();
+  drawTrace.Enable(true);
+
+  application.SendNotification();
+  application.Render();
+
+  // 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 );
+
+  textureTrace.Reset();
+  drawTrace.Reset();
+
+  nativeImageInterface->SetGlExtensionCreateResult( true );
+  actor.SetPosition( 0, 0, 1 );
+  application.SendNotification();
+  application.Render();
+
+  // 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;
+}