FrameBuffer::Format changed to bit-mask Attachment: Core
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Matrix.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 <sstream>
20
21 #include <stdlib.h>
22 #include <dali/public-api/dali-core.h>
23 #include <dali-test-suite-utils.h>
24
25 using namespace Dali;
26
27
28 void utc_dali_matrix_startup(void)
29 {
30   test_return_value = TET_UNDEF;
31 }
32
33 void utc_dali_matrix_cleanup(void)
34 {
35   test_return_value = TET_PASS;
36 }
37
38
39 int UtcDaliMatrixConstructor01P(void)
40 {
41   Matrix m2(false);
42
43   bool initialised = true;
44   {
45     float* els = m2.AsFloat();
46     for(size_t idx=0; idx<16; ++idx, ++els)
47     {
48       if(*els != 0.0f)
49         initialised = false;
50     }
51   }
52
53   DALI_TEST_EQUALS(initialised, false, TEST_LOCATION);
54
55   END_TEST;
56 }
57
58 int UtcDaliMatrixConstructor02P(void)
59 {
60   float r[] = { 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f};
61   Matrix m(r);
62
63   float* els = m.AsFloat();
64   float* init = r;
65   bool initialised = true;
66   for(size_t idx=0; idx<16; ++idx, ++els, ++init)
67   {
68     if(*els != *init)
69       initialised = false;
70   }
71   DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
72
73   END_TEST;
74 }
75
76 int UtcDaliMatrixConstructor03P(void)
77 {
78   float r[] = { 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f};
79
80   Matrix ma(r);
81   Matrix mb(ma);
82
83   float* els = ma.AsFloat();
84   float* init = mb.AsFloat();
85   bool initialised = true;
86   for(size_t idx=0; idx<16; ++idx, ++els, ++init)
87   {
88     if(*els != *init)
89       initialised = false;
90   }
91   DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
92
93   END_TEST;
94 }
95
96 int UtcDaliMatrixConstructor04P(void)
97 {
98   Quaternion q(Quaternion::IDENTITY);
99   Matrix m(q);
100   DALI_TEST_EQUALS(Matrix(Matrix::IDENTITY), m, 0.001, TEST_LOCATION);
101   END_TEST;
102 }
103
104 int UtcDaliMatrixAssignP(void)
105 {
106   Matrix a(Matrix::IDENTITY);
107   Matrix b = a;
108   DALI_TEST_EQUALS(a, b, 0.001, TEST_LOCATION);
109   END_TEST;
110 }
111
112 int UtcDaliMatrixAssign02P(void)
113 {
114   Matrix a(Matrix::IDENTITY);
115   a = a; // self assign does the do nothing branch
116   DALI_TEST_EQUALS(Matrix(Matrix::IDENTITY), a, 0.001, TEST_LOCATION);
117   END_TEST;
118 }
119
120 int UtcDaliMatrixSetIdentityP(void)
121 {
122   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
123                   4.0f,  5.0f,  6.0f,  7.0f,
124                   8.0f,  9.0f, 10.0f, 11.0f,
125                   12.0f, 13.0f, 14.0f, 15.0f };
126   Matrix m(els);
127   m.SetIdentity();
128
129   DALI_TEST_EQUALS(m, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
130   END_TEST;
131 }
132
133 int UtcDaliMatrixSetIdentityAndScaleP(void)
134 {
135   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
136                   4.0f,  5.0f,  6.0f,  7.0f,
137                   8.0f,  9.0f, 10.0f, 11.0f,
138                   12.0f, 13.0f, 14.0f, 15.0f };
139   Matrix m(els);
140   m.SetIdentityAndScale(Vector3(4.0f, 4.0f, 4.0f));
141
142   float els2[] = { 4.0f, 0.0f, 0.0f, 0.0f,
143                    0.0f, 4.0f, 0.0f, 0.0f,
144                    0.0f, 0.0f, 4.0f, 0.0f,
145                    0.0f, 0.0f, 0.0f, 1.0f };
146   Matrix r(els2);
147
148   DALI_TEST_EQUALS(m, r, 0.001f, TEST_LOCATION);
149   END_TEST;
150 }
151
152 int UtcDaliMatrixInvertTransformP(void)
153 {
154   for (int i=0;i<1000;++i)
155   {
156     float f = i;
157     Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f));
158     axis.Normalize();
159     Vector3 center(f, cosf(f) * 100.0f, cosf(f*0.5f) * 50.0f);
160
161     Matrix m0;
162     m0.SetIdentity();
163     m0.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), center );
164
165     Matrix m1;
166     m0.InvertTransform(m1);
167
168     Matrix m2( false );
169     Matrix::Multiply( m2, m0, m1 );
170
171     DALI_TEST_EQUALS(m2, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
172   }
173   END_TEST;
174 }
175
176 int UtcDaliMatrixInvertTransformN(void)
177 {
178   std::string exceptionString( "EqualsZero( mMatrix[3] ) && EqualsZero( mMatrix[7] ) && EqualsZero( mMatrix[11] ) && Equals( mMatrix[15], 1.0f" );
179   try
180   {
181     float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
182                     4.0f,  5.0f,  6.0f,  7.0f,
183                     8.0f,  9.0f, 10.0f, 11.0f,
184                     12.0f, 13.0f, 14.0f, 15.0f };
185     Matrix m(els);
186
187     Matrix it;
188     m.InvertTransform(it);
189     tet_result(TET_FAIL);
190   }
191   catch (Dali::DaliException& e)
192   {
193     DALI_TEST_PRINT_ASSERT( e );
194     DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION );
195   }
196
197   try
198   {
199     float els[] = { 0.0f,  1.0f,  2.0f,  0.0f,
200                     4.0f,  5.0f,  6.0f,  7.0f,
201                     8.0f,  9.0f, 10.0f, 11.0f,
202                     12.0f, 13.0f, 14.0f, 15.0f };
203     Matrix m(els);
204
205     Matrix it;
206     m.InvertTransform(it);
207     tet_result(TET_FAIL);
208   }
209   catch (Dali::DaliException& e)
210   {
211     DALI_TEST_PRINT_ASSERT( e );
212     DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION );
213   }
214
215   try
216   {
217     float els[] = { 0.0f,  1.0f,  2.0f,  0.0f,
218                     4.0f,  5.0f,  6.0f,  0.0f,
219                     8.0f,  9.0f, 10.0f, 11.0f,
220                     12.0f, 13.0f, 14.0f, 15.0f };
221     Matrix m(els);
222
223     Matrix it;
224     m.InvertTransform(it);
225     tet_result(TET_FAIL);
226   }
227   catch (Dali::DaliException& e)
228   {
229     DALI_TEST_PRINT_ASSERT( e );
230     DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION );
231   }
232
233   try
234   {
235     float els[] = { 0.0f,  1.0f,  2.0f,  0.0f,
236                     4.0f,  5.0f,  6.0f,  0.0f,
237                     8.0f,  9.0f, 10.0f,  0.0f,
238                     12.0f, 13.0f, 14.0f, 15.0f };
239     Matrix m(els);
240
241     Matrix it;
242     m.InvertTransform(it);
243     tet_result(TET_FAIL);
244   }
245   catch (Dali::DaliException& e)
246   {
247     DALI_TEST_PRINT_ASSERT( e );
248     DALI_TEST_ASSERT( e, exceptionString, TEST_LOCATION );
249   }
250   END_TEST;
251 }
252
253 int UtcDaliMatrixInvert01P(void)
254 {
255   // We're going to invert a whole load of different matrices to make sure we don't
256   // fail on particular orientations.
257   for (int i=0;i<1000;++i)
258   {
259     float f = i;
260     Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f));
261     axis.Normalize();
262     Vector3 center(f, cosf(f) * 100.0f, cosf(f*0.5f) * 50.0f);
263
264     Matrix m0;
265     m0.SetIdentity();
266     m0.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), center );
267
268     Matrix m1(m0);
269     m1.Invert();
270
271     Matrix m2( false );
272     Matrix::Multiply( m2, m0, m1 );
273
274     DALI_TEST_EQUALS(m2, Matrix::IDENTITY, 0.001f, TEST_LOCATION);
275
276     m1.Invert();    // doube invert - should be back to m0
277
278     DALI_TEST_EQUALS(m0, m1, 0.001f, TEST_LOCATION);
279   }
280   END_TEST;
281 }
282
283 int UtcDaliMatrixInvert02P(void)
284 {
285   Matrix m1 = Matrix::IDENTITY;
286   m1.SetXAxis(Vector3(0.0f, 0.0f, 0.0f));
287   DALI_TEST_EQUALS(m1.Invert(), false, TEST_LOCATION);
288   END_TEST;
289 }
290
291 int UtcDaliMatrixTransposeP(void)
292 {
293   float floats[] =
294   {   0.0f,  1.0f,  2.0f,  3.0f,
295       4.0f,  5.0f,  6.0f,  7.0f,
296       8.0f,  9.0f, 10.0f,  11.0f,
297      12.0f, 13.0f, 14.0f,  15.0f
298   };
299
300   Matrix m(floats);
301   m.Transpose();
302
303   bool success = true;
304
305   for (int x=0;x<4;++x)
306   {
307     for (int y=0;y<4;++y)
308     {
309       success &= (m.AsFloat()[x+y*4] == floats[x*4+y]);
310     }
311   }
312
313   DALI_TEST_CHECK(success);
314   END_TEST;
315 }
316
317 int UtcDaliMatrixGetXAxisP(void)
318 {
319   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
320                   4.0f,  5.0f,  6.0f,  7.0f,
321                   8.0f,  9.0f, 10.0f, 11.0f,
322                   12.0f, 13.0f, 14.0f, 15.0f };
323   Matrix m(els);
324
325   DALI_TEST_CHECK(m.GetXAxis() == Vector3(0.0f,  1.0f,  2.0f));
326   END_TEST;
327 }
328
329 int UtcDaliMatrixGetYAxisP(void)
330 {
331   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
332                   4.0f,  5.0f,  6.0f,  7.0f,
333                   8.0f,  9.0f, 10.0f, 11.0f,
334                   12.0f, 13.0f, 14.0f, 15.0f };
335   Matrix m(els);
336
337   DALI_TEST_CHECK(m.GetYAxis() == Vector3(4.0f,  5.0f,  6.0f));
338   END_TEST;
339 }
340
341 int UtcDaliMatrixGetZAxisP(void)
342 {
343   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
344                   4.0f,  5.0f,  6.0f,  7.0f,
345                   8.0f,  9.0f, 10.0f, 11.0f,
346                   12.0f, 13.0f, 14.0f, 15.0f };
347   Matrix m(els);
348
349   DALI_TEST_CHECK(m.GetZAxis() == Vector3(8.0f,  9.0f, 10.0f));
350   END_TEST;
351 }
352
353 int UtcDaliMatrixSetXAxisP(void)
354 {
355   Matrix m;
356   Vector3 v(2.0f, 3.0f, 4.0f);
357   m.SetXAxis(v);
358
359   DALI_TEST_CHECK(m.GetXAxis() == v);
360   END_TEST;
361 }
362
363 int UtcDaliMatrixSetYAxisP(void)
364 {
365   Matrix m;
366   Vector3 v(2.0f, 3.0f, 4.0f);
367   m.SetYAxis(v);
368
369   DALI_TEST_CHECK(m.GetYAxis() == v);
370   END_TEST;
371 }
372
373 int UtcDaliMatrixSetZAxisP(void)
374 {
375   Matrix m;
376   Vector3 v(2.0f, 3.0f, 4.0f);
377   m.SetZAxis(v);
378
379   DALI_TEST_CHECK(m.GetZAxis() == v);
380   END_TEST;
381 }
382
383 int UtcDaliMatrixGetTranslationP(void)
384 {
385   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
386                   4.0f,  5.0f,  6.0f,  7.0f,
387                   8.0f,  9.0f, 10.0f, 11.0f,
388                   12.0f, 13.0f, 14.0f, 15.0f };
389   Matrix m(els);
390
391   DALI_TEST_EQUALS(m.GetTranslation(), Vector4(12.0f, 13.0f, 14.0f, 15.0f), TEST_LOCATION);
392   END_TEST;
393 }
394
395 int UtcDaliMatrixGetTranslation3P(void)
396 {
397   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
398                   4.0f,  5.0f,  6.0f,  7.0f,
399                   8.0f,  9.0f, 10.0f, 11.0f,
400                   12.0f, 13.0f, 14.0f, 15.0f };
401   Matrix m(els);
402
403   DALI_TEST_EQUALS(m.GetTranslation3(), Vector3(12.0f, 13.0f, 14.0f), TEST_LOCATION);
404   END_TEST;
405 }
406
407 int UtcDaliMatrixSetTranslationP(void)
408 {
409   Matrix m;
410   Vector4 v(2.0f, 3.0f, 4.0f, 5.0f);
411   m.SetTranslation(v);
412
413   DALI_TEST_CHECK(m.GetTranslation() == v);
414   END_TEST;
415 }
416
417 int UtcDaliMatrixSetTranslation3P(void)
418 {
419   Matrix m;
420   Vector3 v(2.0f, 3.0f, 4.0f);
421   m.SetTranslation(v);
422
423   DALI_TEST_CHECK(m.GetTranslation3() == v);
424   END_TEST;
425 }
426
427 int UtcDaliMatrixOrthoNormalize0P(void)
428 {
429   // OrthoNormalise fixes floating point errors from matrix rotations
430   Matrix m;
431   m.SetIdentity();
432
433   for (int i=0;i<1000;++i)
434   {
435     float f = i;
436     Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f));
437     axis.Normalize();
438
439     m.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), Vector3::ZERO );
440     m.OrthoNormalize();
441   }
442
443   bool success = true;
444   success &= fabsf(m.GetXAxis().Dot(m.GetYAxis())) < 0.001f;
445   success &= fabsf(m.GetYAxis().Dot(m.GetXAxis())) < 0.001f;
446   success &= fabsf(m.GetZAxis().Dot(m.GetYAxis())) < 0.001f;
447
448   success &= fabsf(m.GetXAxis().Length() - 1.0f) < 0.001f;
449   success &= fabsf(m.GetYAxis().Length() - 1.0f) < 0.001f;
450   success &= fabsf(m.GetZAxis().Length() - 1.0f) < 0.001f;
451
452   DALI_TEST_CHECK(success);
453   END_TEST;
454 }
455
456 int UtcDaliMatrixOrthoNormalize1P(void)
457 {
458   // OrthoNormalize is not flipping the axes and is maintaining the translation
459   for (int i=0;i<1000;++i)
460   {
461     float f = i;
462     Vector3 axis(cosf(f*0.001f), cosf(f*0.02f), cosf(f*0.03f));
463     axis.Normalize();
464     Vector3 center(10.0f, 15.0f, 5.0f);
465
466     Matrix m0;
467     m0.SetIdentity();
468     m0.SetTransformComponents( Vector3::ONE, Quaternion(Radian(1.0f), axis), center );
469
470     Matrix m1(m0);
471     m1.OrthoNormalize();
472
473     DALI_TEST_EQUALS(m0.GetXAxis(), m1.GetXAxis(), 0.001f, TEST_LOCATION);
474     DALI_TEST_EQUALS(m0.GetYAxis(), m1.GetYAxis(), 0.001f, TEST_LOCATION);
475     DALI_TEST_EQUALS(m0.GetZAxis(), m1.GetZAxis(), 0.001f, TEST_LOCATION);
476     DALI_TEST_EQUALS(m0.GetTranslation(), m1.GetTranslation(), 0.001f, TEST_LOCATION);
477   }
478   END_TEST;
479 }
480
481 int UtcDaliMatrixConstAsFloatP(void)
482 {
483   float r[] = { 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f};
484   const Matrix m(r);
485
486   const float* els = m.AsFloat();
487   const float* init = r;
488   bool initialised = true;
489   for(size_t idx=0; idx<16; ++idx, ++els, ++init)
490   {
491     if(*els != *init)
492       initialised = false;
493   }
494   DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
495
496
497   END_TEST;
498 }
499
500 int UtcDaliMatrixAsFloatP(void)
501 {
502   float r[] = { 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f, 1.0f, 2.0f, 3.0f, 4.0f};
503   Matrix m(r);
504
505   float* els = m.AsFloat();
506   float* init = r;
507   bool initialised = true;
508   for(size_t idx=0; idx<16; ++idx, ++els, ++init)
509   {
510     if(*els != *init)
511       initialised = false;
512   }
513   DALI_TEST_EQUALS(initialised, true, TEST_LOCATION);
514
515
516   END_TEST;
517 }
518
519 int UtcDaliMatrixMultiplyP(void)
520 {
521   Matrix m1 = Matrix::IDENTITY;
522
523   float els[] = { 1.0f, 0.0f,    0.0f,   0.0f,
524                   0.0f, 0.707f, 0.707f, 0.0f,
525                   0.0f, -0.707f,  0.707f, 0.0f,
526                   0.0f, 0.0f,    0.0f,   1.0f };
527   Matrix result(els);
528
529   Quaternion q(Radian(Degree(45.0f)), Vector3::XAXIS);
530   Matrix m2(false);
531   Matrix::Multiply(m2, m1, q);
532
533   DALI_TEST_EQUALS(m2, result, 0.01f, TEST_LOCATION);
534   END_TEST;
535 }
536
537 int UtcDaliMatrixOperatorMultiply01P(void)
538 {
539   Vector4 v1(2.0f, 5.0f, 4.0f, 0.0f);
540
541   float els[] = {2.0f, 0.0f, 0.0f, 0.0f,
542                  0.0f, 3.0f, 0.0f, 0.0f,
543                  0.0f, 0.0f, 4.0f, 0.0f,
544                  0.0f, 0.0f, 0.0f, 1.0f };
545   Matrix m1(els);
546
547   Vector4 v2 = m1 * v1;
548   Vector4 r1(4.0f, 15.0f, 16.0f, 0.0f);
549   DALI_TEST_EQUALS(v2, r1, 0.01f, TEST_LOCATION);
550   END_TEST;
551 }
552
553 int UtcDaliMatrixOperatorMultiply02P(void)
554 {
555   TestApplication application;
556
557   Vector3 position ( 30.f, 40.f, 50.f);
558
559   Matrix m1(false);
560   m1.SetIdentity();
561   m1.SetTranslation(-position);
562
563   Vector4 positionV4(position);
564   positionV4.w=1.0f;
565   Vector4 output = m1 * positionV4;
566
567   output.w = 0.0f;
568   DALI_TEST_EQUALS(output, Vector4::ZERO, 0.01f, TEST_LOCATION);
569   END_TEST;
570 }
571
572 int UtcDaliMatrixOperatorEqualsP(void)
573 {
574   Matrix m1 = Matrix::IDENTITY;
575
576   float els[] = { 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
577   Matrix r2(els);
578   DALI_TEST_EQUALS(m1 == r2, true, TEST_LOCATION);
579
580   float *f = m1.AsFloat();
581   for(size_t i=0; i<16; i++)
582   {
583     f[15-i] = 1.2f;
584     DALI_TEST_EQUALS(m1 == r2, false, TEST_LOCATION);
585   }
586   END_TEST;
587 }
588
589 int UtcDaliMatrixOperatorNotEqualsP(void)
590 {
591   Matrix m1 = Matrix::IDENTITY;
592   float els[] = {2.0f, 0.0f, 0.0f, 0.0f,
593                  0.0f, 3.0f, 0.0f, 0.0f,
594                  0.0f, 0.0f, 4.0f, 0.0f,
595                  0.0f, 0.0f, 0.0f, 1.0f };
596   Matrix r1(els);
597
598   DALI_TEST_CHECK(m1 != r1);
599   DALI_TEST_CHECK(!(m1 != m1));
600   END_TEST;
601 }
602
603 int UtcDaliMatrixSetTransformComponents01P(void)
604 {
605   // Create an arbitrary vector
606   for( float x=-1.0f; x<=1.0f; x+=0.1f )
607   {
608     for( float y=-1.0f; y<1.0f; y+=0.1f )
609     {
610       for( float z=-1.0f; z<1.0f; z+=0.1f )
611       {
612         Vector3 vForward(x, y, z);
613         vForward.Normalize();
614
615         for( float angle = 5.0f; angle <= 360.0f; angle += 15.0f)
616         {
617           Quaternion rotation1(Radian(Degree(angle)), vForward);
618
619           Matrix m1(rotation1);
620           Matrix result1(false);
621           Vector3 vForward3(vForward.x, vForward.y, vForward.z);
622           result1.SetTransformComponents( Vector3::ONE, Quaternion(Radian(Degree(angle)), vForward3), Vector3::ZERO );
623
624           DALI_TEST_EQUALS(m1, result1, 0.001, TEST_LOCATION);
625
626           Matrix m2(false);
627           m2.SetTransformComponents(vForward, Quaternion::IDENTITY, Vector3::ZERO);
628
629           Matrix result2a(Matrix::IDENTITY);
630           result2a.SetXAxis(result2a.GetXAxis() * vForward[0]);
631           result2a.SetYAxis(result2a.GetYAxis() * vForward[1]);
632           result2a.SetZAxis(result2a.GetZAxis() * vForward[2]);
633
634           DALI_TEST_EQUALS(m2, result2a, 0.001, TEST_LOCATION);
635
636           Matrix m3(false);
637           m3.SetTransformComponents(vForward, rotation1, Vector3::ZERO);
638
639           Matrix result3(Matrix::IDENTITY);
640           result3.SetXAxis(result3.GetXAxis() * vForward[0]);
641           result3.SetYAxis(result3.GetYAxis() * vForward[1]);
642           result3.SetZAxis(result3.GetZAxis() * vForward[2]);
643
644           Matrix::Multiply(result3, result3, m1);
645           DALI_TEST_EQUALS(m3, result3, 0.001, TEST_LOCATION);
646         }
647       }
648     }
649   }
650   END_TEST;
651 }
652
653 int UtcDaliMatrixSetInverseTransformComponent01P(void)
654 {
655   // Create an arbitrary vector
656   for( float x=-1.0f; x<=1.0f; x+=0.1f )
657   {
658     for( float y=-1.0f; y<1.0f; y+=0.1f )
659     {
660       for( float z=-1.0f; z<1.0f; z+=0.1f )
661       {
662         Vector3 vForward(x, y, z);
663         vForward.Normalize();
664
665         {
666           Quaternion rotation1(Quaternion::IDENTITY); // test no rotation branch
667           Vector3 scale1(2.0f, 3.0f, 4.0f);
668           Vector3 position1(1.0f, 2.0f, 3.0f);
669
670           Matrix m1(false);
671           m1.SetTransformComponents(scale1, rotation1, position1);
672
673           Matrix m2(false);
674           m2.SetInverseTransformComponents(scale1, rotation1, position1);
675
676           Matrix result;
677           Matrix::Multiply(result, m1, m2);
678
679           DALI_TEST_EQUALS(result, Matrix::IDENTITY, 0.001, TEST_LOCATION);
680         }
681       }
682     }
683   }
684   END_TEST;
685 }
686
687 int UtcDaliMatrixSetInverseTransformComponent02P(void)
688 {
689   // Create an arbitrary vector
690   for( float x=-1.0f; x<=1.0f; x+=0.1f )
691   {
692     for( float y=-1.0f; y<1.0f; y+=0.1f )
693     {
694       for( float z=-1.0f; z<1.0f; z+=0.1f )
695       {
696         Vector3 vForward(x, y, z);
697         vForward.Normalize();
698
699         for( float angle = 5.0f; angle <= 360.0f; angle += 15.0f)
700         {
701           Quaternion rotation1(Radian(Degree(angle)), vForward);
702           Matrix rotationMatrix(rotation1);   // TEST RELIES ON THIS METHOD WORKING!!!
703
704           Vector3 position1(5.0f, -6.0f, 7.0f);
705
706           Matrix m1(false);
707           m1.SetTransformComponents( Vector3::ONE, rotation1, position1 );
708
709           Matrix m2(false);
710           m2.SetInverseTransformComponents( rotationMatrix.GetXAxis(),
711                                             rotationMatrix.GetYAxis(),
712                                             rotationMatrix.GetZAxis(),
713                                             position1 );
714
715           Matrix result;
716           Matrix::Multiply(result, m1, m2);
717
718           DALI_TEST_EQUALS(result, Matrix::IDENTITY, 0.001, TEST_LOCATION);
719         }
720       }
721     }
722   }
723   END_TEST;
724 }
725
726 int UtcDaliMatrixGetTransformComponents01P(void)
727 {
728   Matrix m2(Matrix::IDENTITY.AsFloat());
729   Vector3 pos2;
730   Vector3 scale2;
731   Quaternion q2;
732   m2.GetTransformComponents(pos2, q2, scale2);
733   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), pos2, 0.001, TEST_LOCATION);
734   DALI_TEST_EQUALS(Vector3(1.0f, 1.0f, 1.0f), scale2, 0.001, TEST_LOCATION);
735   DALI_TEST_EQUALS(Quaternion(), q2, 0.001, TEST_LOCATION);
736   END_TEST;
737 }
738
739
740 int UtcDaliMatrixGetTransformComponents02P(void)
741 {
742   // Create an arbitrary vector
743   for( float x=-1.0f; x<=1.0f; x+=0.1f )
744   {
745     for( float y=-1.0f; y<1.0f; y+=0.1f )
746     {
747       for( float z=-1.0f; z<1.0f; z+=0.1f )
748       {
749         Vector3 vForward(x, y, z);
750         vForward.Normalize();
751
752         for( float angle = 5.0f; angle <= 360.0f; angle += 15.0f)
753         {
754           Quaternion rotation1(Radian(Degree(angle)), vForward);
755           Vector3 scale1(2.0f, 3.0f, 4.0f);
756           Vector3 position1(1.0f, 2.0f, 3.0f);
757
758           Matrix m1(false);
759           m1.SetTransformComponents(scale1, rotation1, position1);
760
761           Vector3 position2;
762           Quaternion rotation2;
763           Vector3 scale2;
764           m1.GetTransformComponents(position2, rotation2, scale2);
765
766           DALI_TEST_EQUALS(position1, position2, 0.001, TEST_LOCATION);
767           DALI_TEST_EQUALS(scale1, scale2, 0.001, TEST_LOCATION);
768           DALI_TEST_EQUALS(rotation1, rotation2, 0.001, TEST_LOCATION);
769         }
770       }
771     }
772   }
773   END_TEST;
774 }
775
776 int UtcDaliMatrixGetTransformComponents03P(void)
777 {
778   Matrix m2; // zero branch
779   Vector3 pos2;
780   Vector3 scale2;
781   Quaternion q2;
782   m2.GetTransformComponents(pos2, q2, scale2);
783   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), pos2, 0.001, TEST_LOCATION);
784   DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), scale2, 0.001, TEST_LOCATION);
785   // DALI_TEST_EQUALS(Quaternion(), q2, 0.001, TEST_LOCATION);
786   END_TEST;
787 }
788
789 int UtcDaliMatrixOStreamOperator(void)
790 {
791   std::ostringstream oss;
792
793   Matrix matrix;
794   matrix.SetIdentity();
795
796   oss << matrix;
797
798   std::string expectedOutput = "[ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ]";
799
800   DALI_TEST_EQUALS( oss.str(), expectedOutput, TEST_LOCATION);
801   END_TEST;
802 }