Further Setter/Getter public API removal from Dali::Actor
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-NativeImage.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 #include <iostream>
19 #include <algorithm>
20 #include <stdlib.h>
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>
25
26 using namespace Dali;
27
28 void utc_dali_native_image_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void utc_dali_native_image_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38 IntrusivePtr<TestNativeImage> Creator()
39 {
40   return TestNativeImage::New(10,10);
41 }
42
43 int UtcDaliIntrusivePtrTestNativeImage(void)
44 {
45   UtcCoverageIntrusivePtr<TestNativeImage> pointer;
46
47   pointer.Check(Creator);
48
49   END_TEST;
50 }
51
52 int UtcDaliNativeImageNew(void)
53 {
54   TestApplication application;
55
56   tet_infoline("UtcDaliNativeImageNew - NativeImage::New(NativeImageInterface&)");
57
58   // invoke default handle constructor
59   NativeImage image;
60   TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
61
62   DALI_TEST_CHECK( !image );
63
64   // initialise handle
65   image = NativeImage::New(*(nativeImage.Get()));
66
67   DALI_TEST_CHECK( image );
68   END_TEST;
69 }
70
71 int UtcDaliNativeImageCopyConstructor(void)
72 {
73   TestApplication application;
74
75   tet_infoline("UtcDaliNativeImageCopyConstructor - NativeImage::NativeImage( const NativeImage& )");
76
77   NativeImage image1;
78   DALI_TEST_CHECK( !image1 );
79
80   TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
81   image1 = NativeImage::New(*(nativeImage.Get()));
82   NativeImage image2( image1 );
83
84   DALI_TEST_CHECK( image2 );
85   DALI_TEST_EQUALS( image1, image2, TEST_LOCATION );
86
87   END_TEST;
88 }
89
90 int UtcDaliNativeImageDownCast(void)
91 {
92   TestApplication application;
93   tet_infoline("Testing Dali::Image::DownCast()");
94
95   TestNativeImagePointer nativeImage = TestNativeImage::New(16, 16);
96   NativeImage image = NativeImage::New(*(nativeImage.Get()));
97
98   BaseHandle object(image);
99
100   NativeImage image2 = NativeImage::DownCast(object);
101   DALI_TEST_CHECK(image2);
102
103   NativeImage image3 = DownCast< NativeImage >(object);
104   DALI_TEST_CHECK(image3);
105
106   BaseHandle unInitializedObject;
107   NativeImage image4 = NativeImage::DownCast(unInitializedObject);
108   DALI_TEST_CHECK(!image4);
109
110   NativeImage image5 = DownCast< NativeImage >(unInitializedObject);
111   DALI_TEST_CHECK(!image5);
112
113   Image image6 = NativeImage::New(*(nativeImage.Get()));
114   NativeImage image7 = NativeImage::DownCast(image6);
115   DALI_TEST_CHECK(image7);
116   END_TEST;
117 }
118
119 int UtcDaliNativeImageExtensionP(void)
120 {
121   TestApplication application;
122   tet_infoline( "Testing Dali::NativeImage::GenerateGlTexture()" );
123
124   TestNativeImagePointer testNativeImage = TestNativeImage::New( 16, 16 );
125   DALI_TEST_CHECK( testNativeImage );
126   DALI_TEST_CHECK( NULL != testNativeImage->GetExtension() );
127
128   TestNativeImageNoExtPointer testNativeImage2 = TestNativeImageNoExt::New( 16, 16 );
129   DALI_TEST_CHECK( testNativeImage2 );
130   DALI_TEST_CHECK( NULL == testNativeImage2->GetExtension() );
131
132   END_TEST;
133 }
134
135 int UtcDaliNativeImageGetCustomFragmentPreFixP(void)
136 {
137   TestApplication application;
138   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
139   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
140
141   const char* preFix = "#extension GL_OES_EGL_image_external:require\n";
142   DALI_TEST_EQUALS( nativeImage.GetCustomFragmentPreFix(), preFix, TEST_LOCATION );
143   END_TEST;
144 }
145
146 int UtcDaliNativeImageGetCustomSamplerTypenameP(void)
147 {
148   TestApplication application;
149   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
150   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
151
152   const char* samplerTypename = "samplerExternalOES";
153   DALI_TEST_EQUALS( nativeImage.GetCustomSamplerTypename(), samplerTypename, TEST_LOCATION );
154   END_TEST;
155 }
156
157
158
159 int UtcDaliNativeImageTestCreationFailure(void)
160 {
161   TestApplication application;
162   TestNativeImagePointer nativeImageInterface = TestNativeImage::New( 16, 16 );
163   NativeImage nativeImage = NativeImage::New( *(nativeImageInterface.Get()) );
164
165   tet_printf("Test what happens when GlExtensionCreate is called, and returns false to indicate an error\n");
166
167   nativeImageInterface->SetGlExtensionCreateResult( false );
168
169   Actor actor = CreateRenderableActor( nativeImage );
170   actor.SetProperty( Actor::Property::PARENT_ORIGIN, ParentOrigin::CENTER );
171   Stage::GetCurrent().Add( actor );
172
173   TestGlAbstraction& gl = application.GetGlAbstraction();
174   TraceCallStack& textureTrace = gl.GetTextureTrace();
175   textureTrace.Reset();
176   textureTrace.Enable(true);
177
178   TraceCallStack& drawTrace = gl.GetDrawTrace();
179   drawTrace.Reset();
180   drawTrace.Enable(true);
181
182   application.SendNotification();
183   application.Render();
184
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 );
191
192   textureTrace.Reset();
193   drawTrace.Reset();
194
195   nativeImageInterface->SetGlExtensionCreateResult( true );
196   actor.SetProperty( Actor::Property::POSITION, Vector3( 0, 0, 1 ));
197   application.SendNotification();
198   application.Render();
199
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 );
205
206   END_TEST;
207 }