Merge branch 'devel/master' into tizen
[platform/core/uifw/dali-core.git] / automated-tests / src / dali / utc-Dali-MathUtils.cpp
index b383e56..d8a5b4e 100644 (file)
@@ -1,23 +1,24 @@
-//
-// Copyright (c) 2014 Samsung Electronics Co., Ltd.
-//
-// Licensed under the Flora License, Version 1.0 (the License);
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://floralicense.org/license/
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an AS IS BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-//
+/*
+ * Copyright (c) 2014 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
 
 #include <iostream>
 
 #include <stdlib.h>
-#include <dali/dali.h>
+#include <dali/public-api/dali-core.h>
 #include <dali-test-suite-utils.h>
 
 using namespace Dali;
@@ -32,9 +33,34 @@ void utc_dali_math_utils_cleanup(void)
   test_return_value = TET_PASS;
 }
 
+int UtcDaliMathUtilsIsPowerOfTwo(void)
+{
+  Dali::TestApplication testApp;
+  DALI_TEST_EQUALS(IsPowerOfTwo(0), false, TEST_LOCATION);
 
-// Positive test case for a method
-int UtcDaliMathUtilsNextPowerOfTwo(void)
+  DALI_TEST_EQUALS(IsPowerOfTwo(1), true, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(2), true, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(3), false, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(4), true, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(5), false, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(6), false, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(7), false, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(8), true, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(255), false, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(256), true, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(257), false, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(511), false, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(512), true, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(513), false, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(768), false, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(1023), false, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(1024), true, TEST_LOCATION);
+  DALI_TEST_EQUALS(IsPowerOfTwo(1025), false, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliMathUtilsNextPowerOfTwoP(void)
 {
   Dali::TestApplication testApp;
 
@@ -60,39 +86,91 @@ int UtcDaliMathUtilsNextPowerOfTwo(void)
   END_TEST;
 }
 
+int UtcDaliMathUtilsNextPowerOfTwoN(void)
+{
+  Dali::TestApplication testApp;
 
-// Positive test case for a method
-int UtcDaliMathUtilsIsPowerOfTwo(void)
+  try
+  {
+    NextPowerOfTwo( (1u << (sizeof(unsigned) * 8 - 1)) + 1);
+    tet_result(TET_FAIL);
+  }
+  catch( Dali::DaliException& e )
+  {
+    DALI_TEST_PRINT_ASSERT( e );
+    DALI_TEST_ASSERT( e, "Return type cannot represent the next power of two greater than the argument.", TEST_LOCATION );
+  }
+  catch( ... )
+  {
+    tet_printf("Assertion test failed - wrong Exception\n" );
+    tet_result(TET_FAIL);
+  }
+
+  END_TEST;
+}
+
+int UtcDaliMathUtilsClampP(void)
 {
   Dali::TestApplication testApp;
 
-  DALI_TEST_EQUALS(IsPowerOfTwo(0), false, TEST_LOCATION);
+  //floats
+  DALI_TEST_EQUALS(Clamp(-1.0f, 0.0f, 1.0f), 0.0f, TEST_LOCATION);
+  DALI_TEST_EQUALS(Clamp(0.0f, -1.0f, 1.0f), 0.0f, TEST_LOCATION);
+  DALI_TEST_EQUALS(Clamp(1.0f, 0.0f, 1.0f), 1.0f, TEST_LOCATION);
+  DALI_TEST_EQUALS(Clamp(2.0f, 0.0f, 1.0f), 1.0f, TEST_LOCATION);
 
-  DALI_TEST_EQUALS(IsPowerOfTwo(1), true, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(2), true, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(3), false, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(4), true, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(5), false, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(6), false, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(7), false, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(8), true, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(255), false, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(256), true, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(257), false, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(511), false, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(512), true, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(513), false, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(768), false, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(1023), false, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(1024), true, TEST_LOCATION);
-  DALI_TEST_EQUALS(IsPowerOfTwo(1025), false, TEST_LOCATION);
+  // integers
+  DALI_TEST_EQUALS(Clamp(-10, 0, 10), 0, TEST_LOCATION);
+  DALI_TEST_EQUALS(Clamp(0, -10, 10), 0, TEST_LOCATION);
+  DALI_TEST_EQUALS(Clamp(20, 0, 10), 10, TEST_LOCATION);
+
+  float value=-10.0f, min=-2.0f, max=4.0f;
+  ClampInPlace(value, min, max);
+  DALI_TEST_EQUALS(value, min, 0.001, TEST_LOCATION);
+
+  value = 10.0f;
+  ClampInPlace(value, min, max);
+  DALI_TEST_EQUALS(value, max, 0.001, TEST_LOCATION);
+
+  value = 3.0f;
+  ClampInPlace(value, min, max);
+  DALI_TEST_EQUALS(value, 3.0f, 0.001, TEST_LOCATION);
   END_TEST;
 }
 
+int UtcDaliMathUtilsClampInPlaceP(void)
+{
+  Dali::TestApplication testApp;
 
+  float value=-10.0f, min=-2.0f, max=4.0f;
+  ClampInPlace(value, min, max);
+  DALI_TEST_EQUALS(value, min, 0.001, TEST_LOCATION);
+
+  value = 10.0f;
+  ClampInPlace(value, min, max);
+  DALI_TEST_EQUALS(value, max, 0.001, TEST_LOCATION);
 
-// Positive test case for a method
-int UtcDaliMathUtilsGetRangedEpsilon(void)
+  value = 3.0f;
+  ClampInPlace(value, min, max);
+  DALI_TEST_EQUALS(value, 3.0f, 0.001, TEST_LOCATION);
+  END_TEST;
+}
+
+int UtcDaliMathUtilsLerpP(void)
+{
+  Dali::TestApplication testApp;
+
+  float offset=0.0f, low=-2.0f, high=4.0f;
+  DALI_TEST_EQUALS(Lerp(offset, low, high), low, 0.001, TEST_LOCATION);
+  offset = 1.0f;
+  DALI_TEST_EQUALS(Lerp(offset, low, high), high, 0.001, TEST_LOCATION);
+  offset = 0.5f;
+  DALI_TEST_EQUALS(Lerp(offset, low, high), 1.0f, 0.001, TEST_LOCATION);
+
+  END_TEST;
+}
+
+int UtcDaliMathUtilsGetRangedEpsilonP(void)
 {
   Dali::TestApplication testApp;
 
@@ -167,50 +245,7 @@ int UtcDaliMathUtilsGetRangedEpsilon(void)
   END_TEST;
 }
 
-// Positive test case for a method
-int UtcDaliMathUtilsRound(void)
-{
-  Dali::TestApplication testApp;
-
-  DALI_TEST_EQUALS(Round(1.00001, 4), 1.0f, TEST_LOCATION);
-  DALI_TEST_EQUALS(Round(0.99999f, 4), 1.0f, TEST_LOCATION);
-  DALI_TEST_EQUALS(Round(-1.00001, 4), -1.0f, TEST_LOCATION);
-  DALI_TEST_EQUALS(Round(-0.99999f, 4), -1.0f, TEST_LOCATION);
-  END_TEST;
-}
-
-// Positive test case for a method
-int UtcDaliMathUtilsClamp(void)
-{
-  Dali::TestApplication testApp;
-
-  //floats
-  DALI_TEST_EQUALS(Clamp(-1.0f, 0.0f, 1.0f), 0.0f, TEST_LOCATION);
-  DALI_TEST_EQUALS(Clamp(0.0f, -1.0f, 1.0f), 0.0f, TEST_LOCATION);
-  DALI_TEST_EQUALS(Clamp(1.0f, 0.0f, 1.0f), 1.0f, TEST_LOCATION);
-  DALI_TEST_EQUALS(Clamp(2.0f, 0.0f, 1.0f), 1.0f, TEST_LOCATION);
-
-  // integers
-  DALI_TEST_EQUALS(Clamp(-10, 0, 10), 0, TEST_LOCATION);
-  DALI_TEST_EQUALS(Clamp(0, -10, 10), 0, TEST_LOCATION);
-  DALI_TEST_EQUALS(Clamp(20, 0, 10), 10, TEST_LOCATION);
-
-  float value=-10.0f, min=-2.0f, max=4.0f;
-  ClampInPlace(value, min, max);
-  DALI_TEST_EQUALS(value, min, 0.001, TEST_LOCATION);
-
-  value = 10.0f;
-  ClampInPlace(value, min, max);
-  DALI_TEST_EQUALS(value, max, 0.001, TEST_LOCATION);
-
-  value = 3.0f;
-  ClampInPlace(value, min, max);
-  DALI_TEST_EQUALS(value, 3.0f, 0.001, TEST_LOCATION);
-  END_TEST;
-}
-
-// Positive test case for a method
-int UtcDaliMathUtilsWrapInDomain(void)
+int UtcDaliMathUtilsWrapInDomainP(void)
 {
   Dali::TestApplication testApp;
 
@@ -229,8 +264,7 @@ int UtcDaliMathUtilsWrapInDomain(void)
   END_TEST;
 }
 
-// Positive test case for a method
-int UtcDaliMathUtilsShortestDistanceInDomain(void)
+int UtcDaliMathUtilsShortestDistanceInDomainP(void)
 {
   Dali::TestApplication testApp;
 
@@ -244,7 +278,7 @@ int UtcDaliMathUtilsShortestDistanceInDomain(void)
   END_TEST;
 }
 
-int UtcDaliMathUtilsEquals(void)
+int UtcDaliMathUtilsEqualsZeroP(void)
 {
   float v=0.0f;
 
@@ -254,8 +288,32 @@ int UtcDaliMathUtilsEquals(void)
   v -= (Math::PI_2 * 2.0f);
   DALI_TEST_CHECK(EqualsZero(v));
 
+  END_TEST;
+}
+
+int UtcDaliMathUtilsEquals01P(void)
+{
   float w=100.0f;
   float x=w+1e-8f;
   DALI_TEST_CHECK( Equals(w, x, GetRangedEpsilon( w, x )) );
   END_TEST;
 }
+
+int UtcDaliMathUtilsEquals02P(void)
+{
+  float w=100.0f;
+  float x=w+1e-8f;
+  DALI_TEST_CHECK( Equals(w, x) );
+  END_TEST;
+}
+
+int UtcDaliMathUtilsRoundP(void)
+{
+  Dali::TestApplication testApp;
+
+  DALI_TEST_EQUALS(Round(1.00001, 4), 1.0f, TEST_LOCATION);
+  DALI_TEST_EQUALS(Round(0.99999f, 4), 1.0f, TEST_LOCATION);
+  DALI_TEST_EQUALS(Round(-1.00001, 4), -1.0f, TEST_LOCATION);
+  DALI_TEST_EQUALS(Round(-0.99999f, 4), -1.0f, TEST_LOCATION);
+  END_TEST;
+}