summaryrefslogtreecommitdiff
path: root/testsuite/caps
diff options
context:
space:
mode:
authorWim Taymans <wim.taymans@gmail.com>2004-07-27 16:45:30 +0000
committerWim Taymans <wim.taymans@gmail.com>2004-07-27 16:45:30 +0000
commit36b41f4666ffad371cabdebec8011412bd40a747 (patch)
tree7d54ef3de779445d11792a6a4bf759b537d7310f /testsuite/caps
parentf8d6750a3627ed746d81ba9a2cb026a8e61b6a82 (diff)
Added transform functions between double and fraction.
Original commit message from CVS: * gst/gstvalue.c: (gst_value_transform_double_fraction), (gst_value_transform_fraction_double), (_gst_value_initialize): * testsuite/caps/Makefile.am: * testsuite/caps/fraction-convert.c: (check_from_double_convert), (check_from_fraction_convert), (transform_test), (main): Added transform functions between double and fraction. Added testcase to verify transforms
Diffstat (limited to 'testsuite/caps')
-rw-r--r--testsuite/caps/Makefile.am1
-rw-r--r--testsuite/caps/fraction-convert.c115
2 files changed, 116 insertions, 0 deletions
diff --git a/testsuite/caps/Makefile.am b/testsuite/caps/Makefile.am
index 42efbd4b2..8d961d626 100644
--- a/testsuite/caps/Makefile.am
+++ b/testsuite/caps/Makefile.am
@@ -10,6 +10,7 @@ tests_pass = \
union \
string-conversions \
fixed \
+ fraction-convert \
fraction-multiply-and-zero \
intersect2 \
caps \
diff --git a/testsuite/caps/fraction-convert.c b/testsuite/caps/fraction-convert.c
new file mode 100644
index 000000000..41aae4047
--- /dev/null
+++ b/testsuite/caps/fraction-convert.c
@@ -0,0 +1,115 @@
+/* GStreamer
+ *
+ * fraction-convert.c: test for GstFraction transform
+ *
+ * Copyright (C) <2004> Thomas Vander Stichele <thomas at apestaart dot org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include <math.h>
+#include <gst/gst.h>
+#include <glib.h>
+
+static void
+check_from_double_convert (gdouble value, gint nom, gint denom, gdouble prec)
+{
+ GValue value1 = { 0 };
+ GValue value2 = { 0 };
+ gdouble check;
+
+ g_value_init (&value1, G_TYPE_DOUBLE);
+ g_value_init (&value2, GST_TYPE_FRACTION);
+
+ g_value_set_double (&value1, value);
+ g_value_transform (&value1, &value2);
+ g_print ("%s = %s\n",
+ gst_value_serialize (&value1), gst_value_serialize (&value2));
+ g_assert (gst_value_get_fraction_numerator (&value2) == nom);
+ g_assert (gst_value_get_fraction_denominator (&value2) == denom);
+ g_value_transform (&value2, &value1);
+ g_print ("%s = %s\n",
+ gst_value_serialize (&value2), gst_value_serialize (&value1));
+ check = g_value_get_double (&value1);
+ g_assert (fabs (value - check) <= prec);
+}
+
+static void
+check_from_fraction_convert (gint nom, gint denom, gdouble prec)
+{
+ GValue value1 = { 0 };
+ GValue value2 = { 0 };
+ gdouble value;
+
+ g_value_init (&value1, GST_TYPE_FRACTION);
+ g_value_init (&value2, G_TYPE_DOUBLE);
+
+ gst_value_set_fraction (&value1, nom, denom);
+ g_value_transform (&value1, &value2);
+
+ value = g_value_get_double (&value2);
+ g_assert (fabs (value - ((gdouble) nom) / denom) < prec);
+
+ g_print ("%s = %s, %2.50lf as double\n",
+ gst_value_serialize (&value1), gst_value_serialize (&value2), value);
+
+ g_value_transform (&value2, &value1);
+ g_print ("%s = %s\n",
+ gst_value_serialize (&value2), gst_value_serialize (&value1));
+ value = g_value_get_double (&value2);
+ g_assert (gst_value_get_fraction_numerator (&value1) == nom);
+ g_assert (gst_value_get_fraction_denominator (&value1) == denom);
+
+ g_value_unset (&value2);
+ g_value_unset (&value1);
+}
+
+static void
+transform_test (void)
+{
+ check_from_fraction_convert (30000, 1001, 1.0e-12);
+ check_from_fraction_convert (1, G_MAXINT, 1.0e-12);
+ check_from_fraction_convert (G_MAXINT, 1, 1.0e-12);
+
+ check_from_double_convert (0.0, 0, 1, 1.0e-12);
+ check_from_double_convert (1.0, 1, 1, 1.0e-12);
+ check_from_double_convert (-1.0, -1, 1, 1.0e-12);
+ check_from_double_convert (M_PI, 1881244168, 598818617, 1.0e-12);
+ check_from_double_convert (-M_PI, -1881244168, 598818617, 1.0e-12);
+
+ check_from_double_convert (G_MAXDOUBLE, G_MAXINT, 1, G_MAXDOUBLE);
+ check_from_double_convert (G_MINDOUBLE, 0, 1, G_MAXDOUBLE);
+ check_from_double_convert (-G_MAXDOUBLE, -G_MAXINT, 1, G_MAXDOUBLE);
+ check_from_double_convert (-G_MINDOUBLE, 0, 1, G_MAXDOUBLE);
+
+ check_from_double_convert (((gdouble) G_MAXINT) + 1, G_MAXINT, 1,
+ G_MAXDOUBLE);
+ check_from_double_convert (((gdouble) G_MININT) - 1, G_MININT + 1, 1,
+ G_MAXDOUBLE);
+
+ check_from_double_convert (G_MAXINT - 1, G_MAXINT - 1, 1, 0);
+ check_from_double_convert (G_MININT + 1, G_MININT + 1, 1, 0);
+}
+
+int
+main (int argc, char *argv[])
+{
+ gst_init (&argc, &argv);
+
+ transform_test ();
+
+ return 0;
+}