[dali_1.9.27] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Scene3dView.cpp
1 /*
2  * Copyright (c) 2018 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 <stdlib.h>
20 #include <dali-toolkit-test-suite-utils.h>
21 #include <dali-toolkit/dali-toolkit.h>
22 #include <dali-toolkit/devel-api/controls/scene3d-view/scene3d-view.h>
23
24 using namespace Dali;
25 using namespace Dali::Toolkit;
26
27 void dali_scene_view_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void dali_scene_view_cleanup(void)
33 {
34   test_return_value = TET_PASS;
35 }
36
37 namespace
38 {
39
40 /**
41  * For the AnimatedCube.gltf and its Assets
42  * Donated by Norbert Nopper for glTF testing.
43  * Take from https://github.com/KhronosGroup/glTF-Sample-Models/tree/master/2.0/AnimatedCube
44  */
45 const char* TEST_GLTF_FILE_NAME[] = {TEST_RESOURCE_DIR "/AnimatedCube.gltf",
46                                      TEST_RESOURCE_DIR "/InterpolationTest.gltf"};
47 /**
48  * For the diffuse and specular cube map texture.
49  * These textures are based off version of Wave engine sample
50  * Take from https://github.com/WaveEngine/Samples
51  *
52  * Copyright (c) 2016 Wave Coorporation
53  *
54  * Permission is hereby granted, free of charge, to any person obtaining a copy
55  * of this software and associated documentation files (the "Software"), to
56  * deal in the Software without restriction, including without limitation the
57  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
58  * sell copies of the Software, and to permit persons to whom the Software is
59  * furnished to do so, subject to the following conditions:
60  *
61  * The above copyright notice and this permission notice shall be included in
62  * all copies or substantial portions of the Software.
63  *
64  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
65  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
66  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
67  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
68  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
69  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
70  * THE SOFTWARE.
71  */
72 const char* TEST_DIFFUSE_TEXTURE = TEST_RESOURCE_DIR "/forest_diffuse_cubemap.png";
73 const char* TEST_SPECULAR_TEXTURE = TEST_RESOURCE_DIR "/forest_specular_cubemap.png";
74 }
75
76 int UtcDaliScene3dViewConstructorP(void)
77 {
78   TestApplication application;
79
80   Scene3dView scene3dView;
81
82   DALI_TEST_CHECK( !scene3dView );
83   END_TEST;
84 }
85
86 int UtcDaliScene3dViewCopyConstructorP(void)
87 {
88   TestApplication application;
89
90   // Initialize an object, ref count == 1
91   Scene3dView scene3dView = Scene3dView::New( TEST_GLTF_FILE_NAME[0] );
92
93   Scene3dView copy( scene3dView );
94   DALI_TEST_CHECK( copy );
95   END_TEST;
96 }
97
98 int UtcDaliScene3dViewCopyConstructor2P(void)
99 {
100   TestApplication application;
101
102   // Initialize an object, ref count == 1
103   Toolkit::Scene3dView scene3dView = Toolkit::Scene3dView::New( TEST_GLTF_FILE_NAME[0], TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE, Vector4::ONE );
104
105   Scene3dView copy( scene3dView );
106   DALI_TEST_CHECK( copy );
107   END_TEST;
108 }
109
110 int UtcDaliScene3dViewAssignmentOperatorP(void)
111 {
112   TestApplication application;
113
114   Scene3dView scene3dView = Scene3dView::New( TEST_GLTF_FILE_NAME[0] );
115
116   Scene3dView copy( scene3dView );
117   DALI_TEST_CHECK( copy );
118
119   DALI_TEST_CHECK( scene3dView == copy );
120   END_TEST;
121 }
122
123 int UtcDaliScene3dViewNewP(void)
124 {
125   ToolkitTestApplication application;
126   tet_infoline(" UtcDaliScene3dViewNewP");
127
128   // Create the Slider actor
129   Scene3dView scene3dView;
130   DALI_TEST_CHECK( !scene3dView );
131
132   scene3dView = Scene3dView::New( TEST_GLTF_FILE_NAME[0] );
133   DALI_TEST_CHECK( scene3dView );
134
135   END_TEST;
136 }
137
138 int UtcDaliScene3dViewDestructorP(void)
139 {
140   ToolkitTestApplication application;
141
142   Scene3dView* scene3dView = new Scene3dView();
143   delete scene3dView;
144
145   DALI_TEST_CHECK( true );
146   END_TEST;
147 }
148
149 int UtcDaliScene3dViewDownCast(void)
150 {
151   ToolkitTestApplication application;
152   tet_infoline(" UtcDaliScene3dViewDownCast");
153
154   Toolkit::Scene3dView view = Toolkit::Scene3dView::New( TEST_GLTF_FILE_NAME[0] );
155   BaseHandle handle(view);
156
157   Toolkit::Scene3dView scene3dView = Toolkit::Scene3dView::DownCast( handle );
158   DALI_TEST_CHECK( view );
159   DALI_TEST_CHECK( scene3dView );
160   DALI_TEST_CHECK( scene3dView == view );
161   END_TEST;
162 }
163
164 int UtcDaliScene3dViewSetLight(void)
165 {
166   ToolkitTestApplication application;
167   tet_infoline(" UtcDaliScene3dViewSetLight");
168
169   Toolkit::Scene3dView view = Toolkit::Scene3dView::New( TEST_GLTF_FILE_NAME[0] );
170
171   bool lightSet = view.SetLight( Scene3dView::LightType::DIRECTIONAL_LIGHT, Vector3( 1.0, 1.0, -1.0 ), Vector3( 0.3, 0.3, 0.3 ) );
172   DALI_TEST_CHECK( lightSet );
173   bool lightSet2 = view.SetLight( Scene3dView::LightType::POINT_LIGHT, Vector3( 1.0, 1.0, -1.0 ), Vector3( 0.3, 0.3, 0.3 ) );
174   DALI_TEST_CHECK( lightSet2 );
175
176   END_TEST;
177 }
178
179 int UtcDaliScene3dViewGetCamera(void)
180 {
181   ToolkitTestApplication application;
182   tet_infoline(" UtcDaliScene3dViewGetCamera");
183
184   Toolkit::Scene3dView view = Toolkit::Scene3dView::New( TEST_GLTF_FILE_NAME[0] );
185
186   CameraActor camera = view.GetDefaultCamera();
187   DALI_TEST_CHECK( camera );
188
189   CameraActor camera2 = view.GetCamera( -1 );
190   DALI_TEST_CHECK( !camera2 );
191
192   CameraActor camera3 = view.GetCamera( 0 );
193   DALI_TEST_CHECK( camera3 );
194
195   CameraActor camera4 = view.GetCamera( view.GetCameraCount() - 1 );
196   DALI_TEST_CHECK( camera4 );
197
198   END_TEST;
199 }
200
201 int UtcDaliScene3dViewAnimations(void)
202 {
203   ToolkitTestApplication application;
204   tet_infoline(" UtcDaliScene3dViewAnimations");
205
206   for( auto filename : TEST_GLTF_FILE_NAME )
207   {
208     Toolkit::Scene3dView view = Toolkit::Scene3dView::New( filename );
209
210     bool playAnimation = view.PlayAnimations();
211     DALI_TEST_CHECK( playAnimation );
212   }
213
214   END_TEST;
215 }
216
217 int UtcDaliScene3dViewAnimations2(void)
218 {
219   ToolkitTestApplication application;
220   tet_infoline(" UtcDaliScene3dViewAnimations2");
221
222   Toolkit::Scene3dView view = Toolkit::Scene3dView::New( TEST_GLTF_FILE_NAME[0] );
223
224   bool animated = true;
225   unsigned int animationCount = view.GetAnimationCount();
226   for( unsigned int i = 0; i < animationCount; ++i )
227   {
228     animated = ( animated && view.PlayAnimation( i ) );
229   }
230   DALI_TEST_CHECK( animated );
231
232   END_TEST;
233 }