Merge "Change setting background color for Scene." into devel/master
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-Matrix.cpp
index 17649ed..4d3535c 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -38,19 +38,24 @@ void utc_dali_matrix_cleanup(void)
 
 int UtcDaliMatrixConstructor01P(void)
 {
-  Matrix m2(false);
+  // State of memory cannot be guaranteed, so use
+  // a buffer in a known state to check for changes
+  char buffer[sizeof(Matrix)];
 
-  bool initialised = true;
+  memset(buffer, 1, sizeof(Matrix));
+
+  Matrix* m2 = new(&buffer) Matrix(false);
+  bool initialisation_occured = false;
   {
-    float* els = m2.AsFloat();
+    float* els = m2->AsFloat();
     for(size_t idx=0; idx<16; ++idx, ++els)
     {
-      if(*els != 0.0f)
-        initialised = false;
+      if(*els == 0.0f)
+        initialisation_occured = true;
     }
   }
 
-  DALI_TEST_EQUALS(initialised, false, TEST_LOCATION);
+  DALI_TEST_EQUALS(initialisation_occured, false, TEST_LOCATION);
 
   END_TEST;
 }
@@ -109,6 +114,14 @@ int UtcDaliMatrixAssignP(void)
   END_TEST;
 }
 
+int UtcDaliMatrixAssign02P(void)
+{
+  Matrix a(Matrix::IDENTITY);
+  a = a; // self assign does the do nothing branch
+  DALI_TEST_EQUALS(Matrix(Matrix::IDENTITY), a, 0.001, TEST_LOCATION);
+  END_TEST;
+}
+
 int UtcDaliMatrixSetIdentityP(void)
 {
   float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
@@ -141,7 +154,7 @@ int UtcDaliMatrixSetIdentityAndScaleP(void)
   END_TEST;
 }
 
-int UtcDaliMatrixInvertTransform01P(void)
+int UtcDaliMatrixInvertTransformP(void)
 {
   for (int i=0;i<1000;++i)
   {
@@ -165,7 +178,7 @@ int UtcDaliMatrixInvertTransform01P(void)
   END_TEST;
 }
 
-int UtcDaliMatrixInvertTransform02P(void)
+int UtcDaliMatrixInvertTransformN(void)
 {
   std::string exceptionString( "EqualsZero( mMatrix[3] ) && EqualsZero( mMatrix[7] ) && EqualsZero( mMatrix[11] ) && Equals( mMatrix[15], 1.0f" );
   try
@@ -188,7 +201,7 @@ int UtcDaliMatrixInvertTransform02P(void)
 
   try
   {
-    float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
+    float els[] = { 0.0f,  1.0f,  2.0f,  0.0f,
                     4.0f,  5.0f,  6.0f,  7.0f,
                     8.0f,  9.0f, 10.0f, 11.0f,
                     12.0f, 13.0f, 14.0f, 15.0f };
@@ -206,8 +219,8 @@ int UtcDaliMatrixInvertTransform02P(void)
 
   try
   {
-    float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
-                    4.0f,  5.0f,  6.0f,  7.0f,
+    float els[] = { 0.0f,  1.0f,  2.0f,  0.0f,
+                    4.0f,  5.0f,  6.0f,  0.0f,
                     8.0f,  9.0f, 10.0f, 11.0f,
                     12.0f, 13.0f, 14.0f, 15.0f };
     Matrix m(els);
@@ -224,9 +237,9 @@ int UtcDaliMatrixInvertTransform02P(void)
 
   try
   {
-    float els[] = { 0.0f,  1.0f,  2.0f,  3.0f,
-                    4.0f,  5.0f,  6.0f,  7.0f,
-                    8.0f,  9.0f, 10.0f, 11.0f,
+    float els[] = { 0.0f,  1.0f,  2.0f,  0.0f,
+                    4.0f,  5.0f,  6.0f,  0.0f,
+                    8.0f,  9.0f, 10.0f,  0.0f,
                     12.0f, 13.0f, 14.0f, 15.0f };
     Matrix m(els);
 
@@ -642,7 +655,6 @@ int UtcDaliMatrixSetTransformComponents01P(void)
   END_TEST;
 }
 
-
 int UtcDaliMatrixSetInverseTransformComponent01P(void)
 {
   // Create an arbitrary vector
@@ -655,9 +667,8 @@ int UtcDaliMatrixSetInverseTransformComponent01P(void)
         Vector3 vForward(x, y, z);
         vForward.Normalize();
 
-        for( float angle = 5.0f; angle <= 360.0f; angle += 15.0f)
         {
-          Quaternion rotation1(Radian(Degree(angle)), vForward);
+          Quaternion rotation1(Quaternion::IDENTITY); // test no rotation branch
           Vector3 scale1(2.0f, 3.0f, 4.0f);
           Vector3 position1(1.0f, 2.0f, 3.0f);
 
@@ -767,6 +778,18 @@ int UtcDaliMatrixGetTransformComponents02P(void)
   END_TEST;
 }
 
+int UtcDaliMatrixGetTransformComponents03P(void)
+{
+  Matrix m2; // zero branch
+  Vector3 pos2;
+  Vector3 scale2;
+  Quaternion q2;
+  m2.GetTransformComponents(pos2, q2, scale2);
+  DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), pos2, 0.001, TEST_LOCATION);
+  DALI_TEST_EQUALS(Vector3(0.0f, 0.0f, 0.0f), scale2, 0.001, TEST_LOCATION);
+  // DALI_TEST_EQUALS(Quaternion(), q2, 0.001, TEST_LOCATION);
+  END_TEST;
+}
 
 int UtcDaliMatrixOStreamOperator(void)
 {
@@ -777,7 +800,7 @@ int UtcDaliMatrixOStreamOperator(void)
 
   oss << matrix;
 
-  std::string expectedOutput = "[ [1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1] ]";
+  std::string expectedOutput = "[ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]";
 
   DALI_TEST_EQUALS( oss.str(), expectedOutput, TEST_LOCATION);
   END_TEST;