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>
24 #include <test-intrusive-ptr.h>
28 void utc_dali_native_image_startup(void)
30 test_return_value = TET_UNDEF;
33 void utc_dali_native_image_cleanup(void)
35 test_return_value = TET_PASS;
38 IntrusivePtr<TestNativeImage> Creator()
40 return TestNativeImage::New(10,10);
43 int UtcDaliIntrusivePtrTestNativeImage(void)
45 UtcCoverageIntrusivePtr<TestNativeImage> pointer;
47 pointer.Check(Creator);
52 int UtcDaliNativeImageNew(void)
54 TestApplication application;
56 tet_infoline("UtcDaliNativeImageNew - NativeImage::New(NativeImageInterface&)");
58 // invoke default handle constructor
60 TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
62 DALI_TEST_CHECK( !image );
65 image = NativeImage::New(*(nativeImage.Get()));
67 DALI_TEST_CHECK( image );
71 int UtcDaliNativeImageCopyConstructor(void)
73 TestApplication application;
75 tet_infoline("UtcDaliNativeImageCopyConstructor - NativeImage::NativeImage( const NativeImage& )");
78 DALI_TEST_CHECK( !image1 );
80 TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
81 image1 = NativeImage::New(*(nativeImage.Get()));
82 NativeImage image2( image1 );
84 DALI_TEST_CHECK( image2 );
85 DALI_TEST_EQUALS( image1, image2, TEST_LOCATION );
90 int UtcDaliNativeImageDownCast(void)
92 TestApplication application;
93 tet_infoline("Testing Dali::Image::DownCast()");
95 TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
96 NativeImage image = NativeImage::New(*(nativeImage.Get()));
98 BaseHandle object(image);
100 NativeImage image2 = NativeImage::DownCast(object);
101 DALI_TEST_CHECK(image2);
103 NativeImage image3 = DownCast< NativeImage >(object);
104 DALI_TEST_CHECK(image3);
106 BaseHandle unInitializedObject;
107 NativeImage image4 = NativeImage::DownCast(unInitializedObject);
108 DALI_TEST_CHECK(!image4);
110 NativeImage image5 = DownCast< NativeImage >(unInitializedObject);
111 DALI_TEST_CHECK(!image5);
113 Image image6 = NativeImage::New(*(nativeImage.Get()));
114 NativeImage image7 = NativeImage::DownCast(image6);
115 DALI_TEST_CHECK(image7);
119 int UtcDaliNativeImageExtensionP(void)
121 TestApplication application;
122 tet_infoline( "Testing Dali::NativeImage::GenerateGlTexture()" );
124 TestNativeImagePointer testNativeImage = TestNativeImage::New( 16, 16 );
125 DALI_TEST_CHECK( testNativeImage );
126 DALI_TEST_CHECK( NULL != testNativeImage->GetExtension() );
128 TestNativeImageNoExtPointer testNativeImage2 = TestNativeImageNoExt::New( 16, 16 );
129 DALI_TEST_CHECK( testNativeImage2 );
130 DALI_TEST_CHECK( NULL == testNativeImage2->GetExtension() );
135 int UtcDaliNativeImageGetCustomFragmentPreFixP(void)
137 TestApplication application;
138 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
139 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
141 const char* preFix = "#extension GL_OES_EGL_image_external:require\n";
142 DALI_TEST_EQUALS( nativeImage.GetCustomFragmentPreFix(), preFix, TEST_LOCATION );
146 int UtcDaliNativeImageGetCustomSamplerTypenameP(void)
148 TestApplication application;
149 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
150 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
152 const char* samplerTypename = "samplerExternalOES";
153 DALI_TEST_EQUALS( nativeImage.GetCustomSamplerTypename(), samplerTypename, TEST_LOCATION );
159 int UtcDaliNativeImageTestCreationFailure(void)
161 TestApplication application;
162 TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
163 NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
165 tet_printf("Test what happens when GlExtensionCreate is called, and returns false to indicate an error\n");
167 nativeImageInterface->SetGlExtensionCreateResult( false );
169 Actor actor = CreateRenderableActor( nativeImage );
170 actor.SetParentOrigin( ParentOrigin::CENTER );
171 Stage::GetCurrent().Add( actor );
173 TestGlAbstraction& gl = application.GetGlAbstraction();
174 TraceCallStack& textureTrace = gl.GetTextureTrace();
175 textureTrace.Reset();
176 textureTrace.Enable(true);
178 TraceCallStack& drawTrace = gl.GetDrawTrace();
180 drawTrace.Enable(true);
182 application.SendNotification();
183 application.Render();
185 // Test that nothing was rendered
186 //GlExtensionCreate() called twice, once at initialization and once when trying to bind the texture
187 DALI_TEST_EQUALS( nativeImageInterface->mExtensionCreateCalls, 2, TEST_LOCATION );
188 DALI_TEST_EQUALS( nativeImageInterface->mTargetTextureCalls, 0, TEST_LOCATION );
189 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), false, TEST_LOCATION );
190 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawElements") || drawTrace.FindMethod("DrawArrays"), false, TEST_LOCATION );
192 textureTrace.Reset();
195 nativeImageInterface->SetGlExtensionCreateResult( true );
196 actor.SetPosition( 0, 0, 1 );
197 application.SendNotification();
198 application.Render();
200 // This time around, the bind and draw should occur following the call to nativeImage->GlExtensionCreate.
201 DALI_TEST_EQUALS( nativeImageInterface->mExtensionCreateCalls, 3, TEST_LOCATION );
202 DALI_TEST_EQUALS( nativeImageInterface->mTargetTextureCalls, 1, TEST_LOCATION );
203 DALI_TEST_EQUALS( textureTrace.FindMethod("BindTexture"), true, TEST_LOCATION );
204 DALI_TEST_EQUALS( drawTrace.FindMethod("DrawElements") || drawTrace.FindMethod("DrawArrays"), true, TEST_LOCATION );