[Tizen] Scene, Scene Loader, and glTF Loader
[platform/core/uifw/dali-toolkit.git] / automated-tests / src / dali-toolkit / utc-Dali-Scene.cpp
1 /*
2  * Copyright (c) 2014 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/scene/scene.h>
23
24 using namespace Dali;
25 using namespace Dali::Toolkit;
26
27 void dali_scene_startup(void)
28 {
29   test_return_value = TET_UNDEF;
30 }
31
32 void dali_scene_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 /**
47  * For the diffuse and specular cube map texture.
48  * These textures are based off version of Wave engine sample
49  * Take from https://github.com/WaveEngine/Samples
50  *
51  * Copyright (c) 2016 Wave Coorporation
52  *
53  * Permission is hereby granted, free of charge, to any person obtaining a copy
54  * of this software and associated documentation files (the "Software"), to
55  * deal in the Software without restriction, including without limitation the
56  * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
57  * sell copies of the Software, and to permit persons to whom the Software is
58  * furnished to do so, subject to the following conditions:
59  *
60  * The above copyright notice and this permission notice shall be included in
61  * all copies or substantial portions of the Software.
62  *
63  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
64  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
65  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
66  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
67  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
68  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
69  * THE SOFTWARE.
70  */
71 const char* TEST_DIFFUSE_TEXTURE = TEST_RESOURCE_DIR "/forest_diffuse_cubemap.png";
72 const char* TEST_SPECULAR_TEXTURE = TEST_RESOURCE_DIR "/forest_specular_cubemap.png";
73 }
74
75 int UtcDaliSceneConstructorP(void)
76 {
77   TestApplication application;
78
79   Scene scene;
80
81   DALI_TEST_CHECK( !scene );
82   END_TEST;
83 }
84
85 int UtcDaliSceneCopyConstructorP(void)
86 {
87   TestApplication application;
88
89   // Initialize an object, ref count == 1
90   Scene scene = Scene::New( TEST_GLTF_FILE_NAME );
91
92   Scene copy( scene );
93   DALI_TEST_CHECK( copy );
94   END_TEST;
95 }
96
97 int UtcDaliSceneCopyConstructor2P(void)
98 {
99   TestApplication application;
100
101   // Initialize an object, ref count == 1
102   Toolkit::Scene scene = Toolkit::Scene::New( TEST_GLTF_FILE_NAME, TEST_DIFFUSE_TEXTURE, TEST_SPECULAR_TEXTURE );
103
104   Scene copy( scene );
105   DALI_TEST_CHECK( copy );
106   END_TEST;
107 }
108
109 int UtcDaliSceneAssignmentOperatorP(void)
110 {
111   TestApplication application;
112
113   Scene scene = Scene::New( TEST_GLTF_FILE_NAME );
114
115   Scene copy( scene );
116   DALI_TEST_CHECK( copy );
117
118   DALI_TEST_CHECK( scene == copy );
119   END_TEST;
120 }
121
122 int UtcDaliSceneNewP(void)
123 {
124   ToolkitTestApplication application;
125   tet_infoline(" UtcDaliSceneNewP");
126
127   // Create the Slider actor
128   Scene scene;
129   DALI_TEST_CHECK( !scene );
130
131   scene = Scene::New( TEST_GLTF_FILE_NAME );
132   DALI_TEST_CHECK( scene );
133
134   END_TEST;
135 }
136
137 int UtcDaliSceneDestructorP(void)
138 {
139   ToolkitTestApplication application;
140
141   Scene* scene = new Scene();
142   delete scene;
143
144   DALI_TEST_CHECK( true );
145   END_TEST;
146 }
147
148 int UtcDaliSceneDownCast(void)
149 {
150   ToolkitTestApplication application;
151   tet_infoline(" UtcDaliSceneDownCast");
152
153   Toolkit::Scene view = Toolkit::Scene::New( TEST_GLTF_FILE_NAME );
154   BaseHandle handle(view);
155
156   Toolkit::Scene scene = Toolkit::Scene::DownCast( handle );
157   DALI_TEST_CHECK( view );
158   DALI_TEST_CHECK( scene );
159   DALI_TEST_CHECK( scene == view );
160   END_TEST;
161 }
162
163 int UtcDaliSceneSetLight(void)
164 {
165   ToolkitTestApplication application;
166   tet_infoline(" UtcDaliSceneSetLight");
167
168   Toolkit::Scene view = Toolkit::Scene::New( TEST_GLTF_FILE_NAME );
169
170   bool lightSet = view.SetLight( Scene::LightType::DIRECTIONAL_LIGHT, Vector3( 1.0, 1.0, -1.0 ), Vector3( 0.3, 0.3, 0.3 ) );
171   DALI_TEST_CHECK( lightSet );
172   bool lightSet2 = view.SetLight( Scene::LightType::POINT_LIGHT, Vector3( 1.0, 1.0, -1.0 ), Vector3( 0.3, 0.3, 0.3 ) );
173   DALI_TEST_CHECK( lightSet2 );
174
175   END_TEST;
176 }
177
178 int UtcDaliSceneGetCamera(void)
179 {
180   ToolkitTestApplication application;
181   tet_infoline(" UtcDaliSceneGetCamera");
182
183   Toolkit::Scene view = Toolkit::Scene::New( TEST_GLTF_FILE_NAME );
184
185   CameraActor camera = view.GetDefaultCamera();
186   DALI_TEST_CHECK( camera );
187
188   CameraActor camera2 = view.GetCamera( -1 );
189   DALI_TEST_CHECK( camera2 );
190
191   CameraActor camera3 = view.GetCamera( 0 );
192   DALI_TEST_CHECK( camera3 );
193
194   END_TEST;
195 }
196
197 int UtcDaliSceneAnimation(void)
198 {
199   ToolkitTestApplication application;
200   tet_infoline(" UtcDaliSceneAnimation");
201
202   Toolkit::Scene view = Toolkit::Scene::New( TEST_GLTF_FILE_NAME );
203
204   bool playAnimation = view.PlayAnimations();
205   DALI_TEST_CHECK( playAnimation );
206
207   END_TEST;
208 }