2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
21 #include <dali/public-api/dali-core.h>
22 #include <dali-test-suite-utils.h>
23 #include <test-native-image.h>
27 void utc_dali_native_image_startup(void)
29 test_return_value = TET_UNDEF;
32 void utc_dali_native_image_cleanup(void)
34 test_return_value = TET_PASS;
37 int UtcDaliNativeImageNew(void)
39 TestApplication application;
41 tet_infoline("UtcDaliNativeImageNew - NativeImage::New(NativeImageInterface&)");
43 // invoke default handle constructor
45 TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
47 DALI_TEST_CHECK( !image );
50 image = NativeImage::New(*(nativeImage.Get()));
52 DALI_TEST_CHECK( image );
56 int UtcDaliNativeImageDownCast(void)
58 TestApplication application;
59 tet_infoline("Testing Dali::Image::DownCast()");
61 TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
62 NativeImage image = NativeImage::New(*(nativeImage.Get()));
64 BaseHandle object(image);
66 NativeImage image2 = NativeImage::DownCast(object);
67 DALI_TEST_CHECK(image2);
69 NativeImage image3 = DownCast< NativeImage >(object);
70 DALI_TEST_CHECK(image3);
72 BaseHandle unInitializedObject;
73 NativeImage image4 = NativeImage::DownCast(unInitializedObject);
74 DALI_TEST_CHECK(!image4);
76 NativeImage image5 = DownCast< NativeImage >(unInitializedObject);
77 DALI_TEST_CHECK(!image5);
79 Image image6 = NativeImage::New(*(nativeImage.Get()));
80 NativeImage image7 = NativeImage::DownCast(image6);
81 DALI_TEST_CHECK(image7);
85 int UtcDaliNativeImageCreateGlTextureN(void)
87 TestApplication application;
88 tet_infoline( "Testing Dali::NativeImage::GenerateGlTexture()" );
93 image.CreateGlTexture();
94 tet_printf( "Assertion test failed - no Exception\n" );
95 tet_result( TET_FAIL );
97 catch( Dali::DaliException& e )
99 DALI_TEST_PRINT_ASSERT( e );
100 DALI_TEST_ASSERT( e, "image &&", TEST_LOCATION );
105 int UtcDaliNativeImageCreateGlTextureP(void)
107 TestApplication application;
108 tet_infoline( "Testing Dali::NativeImage::GenerateGlTexture()" );
110 TestNativeImagePointer imageInterface = TestNativeImage::New( 16, 16 );
111 NativeImage image = NativeImage::New( *(imageInterface.Get()) );
112 DALI_TEST_CHECK( image );
114 image.CreateGlTexture();
116 application.SendNotification();
117 application.Render(16);
119 DALI_TEST_EQUALS( imageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
120 DALI_TEST_EQUALS( imageInterface->mTargetTextureCalls, 1, TEST_LOCATION );
125 int UtcDaliNativeImageContextLoss(void)
127 TestApplication application;
128 tet_infoline( "Testing Dali::NativeImage behaviour through a context lost/regained cycle." );
130 // Build an image that is expected to have a GL texture created for it and
131 // recreated in a GL context recovery:
132 TestNativeImagePointer eagerImageInterface = TestNativeImage::New( 16, 16 );
133 NativeImage eagerImage = NativeImage::New( *(eagerImageInterface.Get()) );
134 DALI_TEST_CHECK( eagerImage );
136 // Build a regular lazy-allocated image for comparison:
137 TestNativeImagePointer lazyImageInterface = TestNativeImage::New( 16, 16 );
138 NativeImage lazyImage = NativeImage::New( *(lazyImageInterface.Get()) );
139 DALI_TEST_CHECK( lazyImage );
141 eagerImage.CreateGlTexture();
143 application.SendNotification();
144 application.Render(16);
146 // Cycle through a context loss and regain, asserting that the texture is
147 // not reallocated if it already existed before the cycle and is never allocated
148 // throughout the cycle if of the regular lazy kind:
150 // Call render thread context destroyed / created functions:
151 application.ResetContext();
153 // Call event thread function:
154 application.GetCore().RecoverFromContextLoss();
156 // Run update/render loop
157 application.SendNotification();
158 application.Render(16);
160 DALI_TEST_EQUALS( eagerImageInterface->mExtensionCreateCalls, 1, TEST_LOCATION );
161 DALI_TEST_EQUALS( eagerImageInterface->mTargetTextureCalls, 1, TEST_LOCATION );
163 DALI_TEST_EQUALS( lazyImageInterface->mExtensionCreateCalls, 0, TEST_LOCATION );
164 DALI_TEST_EQUALS( lazyImageInterface->mTargetTextureCalls, 0, TEST_LOCATION );