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