eina: add test for all float/double util function.
authorCedric BAIL <cedric@osg.samsung.com>
Fri, 6 Jan 2017 23:19:41 +0000 (15:19 -0800)
committerCedric BAIL <cedric@osg.samsung.com>
Fri, 6 Jan 2017 23:58:46 +0000 (15:58 -0800)
src/Makefile_Eina.am
src/tests/eina/eina_suite.c
src/tests/eina/eina_suite.x
src/tests/eina/eina_test_util.c [new file with mode: 0644]

index 967d023..56b1959 100644 (file)
@@ -387,4 +387,5 @@ tests/eina/sample.gpx \
 tests/eina/eina_suite.x \
 lib/eina/eina_config.h.in \
 tests/eina/eina_test_stringshare.c \
+tests/eina/eina_test_util.c \
 $(bin_SCRIPTS)
index 24719fe..5cb67f9 100644 (file)
@@ -85,6 +85,7 @@ static const Efl_Test_Case etc[] = {
    { "SafePointer", eina_test_safepointer },
    { "Slice", eina_test_slice },
    { "Free Queue", eina_test_freeq },
+   { "Util", eina_test_util },
    { NULL, NULL }
 };
 
index 4c9274e..52d80c3 100644 (file)
@@ -18,6 +18,7 @@
 #define EINA_TEST_CODE
 
 #include "eina_test_stringshare.c"
+#include "eina_test_util.c"
 
 #undef EINA_TEST_START
 #undef EINA_TEST_END
@@ -37,4 +38,10 @@ eina_test_stringshare(TCase *tc)
 #include "eina_test_stringshare.c"
 }
 
+static void
+eina_test_util(TCase *tc)
+{
+#include "eina_test_util.c"
+}
+
 #endif
diff --git a/src/tests/eina/eina_test_util.c b/src/tests/eina/eina_test_util.c
new file mode 100644 (file)
index 0000000..71680ba
--- /dev/null
@@ -0,0 +1,61 @@
+/* EINA - EFL data type library
+ * Copyright (C) 2017 Cedric Bail
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library;
+ * if not, see <http://www.gnu.org/licenses/>.
+ */
+
+EINA_TEST_START(eina_util_fpx)
+{
+   double a = 42.42, b = 42.41;
+   float c = 7.654, d = 8.765;
+
+   ck_assert_int_eq(eina_dbl_exact(a, b), EINA_FALSE);
+   ck_assert_int_eq(eina_dbl_exact(a, a), EINA_TRUE);
+   ck_assert_int_eq(eina_flt_exact(c, d), EINA_FALSE);
+   ck_assert_int_eq(eina_flt_exact(c, c), EINA_TRUE);
+   ck_assert_int_eq(eina_dbl_exact(a, c), EINA_FALSE);
+}
+EINA_TEST_END
+
+EINA_TEST_START(eina_util_fpeq)
+{
+   double a, b, c;
+   double d, e, f;
+
+   a = 6.0 * 7.0 + 7.0;
+   b = 7.0 * 7.0;
+   c = a - 0.1;
+
+   d = 6.0 * 7.0 + 7.0;
+   e = 7.0 * 7.0;
+   f = a - 0.1;
+
+   ck_assert_int_ne(EINA_DBL_EQ(a, b), 0);
+   ck_assert_int_eq(EINA_DBL_EQ(a, c), 0);
+   ck_assert_int_ne(EINA_DBL_EQ(d, e), 0);
+   ck_assert_int_eq(EINA_DBL_EQ(d, f), 0);
+}
+EINA_TEST_END
+
+EINA_TEST_START(eina_util_fpz)
+{
+   ck_assert_int_eq(EINA_FLT_NONZERO(7.0 - 7.0), 0);
+   ck_assert_int_ne(EINA_FLT_NONZERO(7.1 - 7.0), 0);
+   ck_assert_int_eq(EINA_FLT_NONZERO(0.0), 0);
+   ck_assert_int_eq(EINA_DBL_NONZERO(7.0 - 7.0), 0);
+   ck_assert_int_ne(EINA_DBL_NONZERO(7.1 - 7.0), 0);
+   ck_assert_int_eq(EINA_DBL_NONZERO(0.0), 0);
+}
+EINA_TEST_END