2009-06-03 06:12:09 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
|
|
|
#include "test-conform-common.h"
|
|
|
|
|
2009-10-16 10:25:37 -04:00
|
|
|
void
|
2012-02-27 07:54:23 -05:00
|
|
|
units_cache (TestConformSimpleFixture *fixture,
|
|
|
|
gconstpointer data)
|
2009-10-16 10:25:37 -04:00
|
|
|
{
|
|
|
|
ClutterUnits units;
|
2010-06-22 06:59:07 -04:00
|
|
|
ClutterSettings *settings;
|
2009-10-16 10:25:37 -04:00
|
|
|
gfloat pixels;
|
2010-09-24 11:21:06 -04:00
|
|
|
gint old_dpi;
|
2009-10-16 10:25:37 -04:00
|
|
|
|
2010-06-22 06:59:07 -04:00
|
|
|
settings = clutter_settings_get_default ();
|
2010-09-24 11:21:06 -04:00
|
|
|
g_object_get (settings, "font-dpi", &old_dpi, NULL);
|
2009-10-16 10:25:37 -04:00
|
|
|
|
2010-09-24 11:21:06 -04:00
|
|
|
g_object_set (settings, "font-dpi", 96 * 1024, NULL);
|
2009-10-16 10:25:37 -04:00
|
|
|
clutter_units_from_em (&units, 1.0);
|
|
|
|
pixels = clutter_units_to_pixels (&units);
|
|
|
|
|
2010-09-24 11:21:06 -04:00
|
|
|
g_object_set (settings, "font-dpi", ((96 * 2) * 1024), NULL);
|
2009-10-16 10:25:37 -04:00
|
|
|
g_assert_cmpfloat (clutter_units_to_pixels (&units), !=, pixels);
|
|
|
|
|
2010-09-24 11:21:06 -04:00
|
|
|
g_object_set (settings, "font-dpi", (96 * 1024), NULL);
|
2009-10-16 10:25:37 -04:00
|
|
|
g_assert_cmpfloat (clutter_units_to_pixels (&units), ==, pixels);
|
2010-09-24 11:21:06 -04:00
|
|
|
|
|
|
|
g_object_set (settings, "font-dpi", old_dpi, NULL);
|
2009-10-16 10:25:37 -04:00
|
|
|
}
|
|
|
|
|
2009-06-03 06:12:09 -04:00
|
|
|
void
|
2012-02-27 07:54:23 -05:00
|
|
|
units_constructors (TestConformSimpleFixture *fixture,
|
|
|
|
gconstpointer data)
|
2009-06-03 06:12:09 -04:00
|
|
|
{
|
2009-10-06 12:47:34 -04:00
|
|
|
ClutterUnits units, units_cm;
|
2009-06-03 06:12:09 -04:00
|
|
|
|
2009-07-28 08:43:52 -04:00
|
|
|
clutter_units_from_pixels (&units, 100);
|
2009-06-03 06:12:09 -04:00
|
|
|
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL);
|
|
|
|
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 100.0);
|
|
|
|
g_assert_cmpfloat (clutter_units_to_pixels (&units), ==, 100.0);
|
|
|
|
|
2009-07-28 08:43:52 -04:00
|
|
|
clutter_units_from_em (&units, 5.0);
|
2009-06-03 06:12:09 -04:00
|
|
|
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_EM);
|
|
|
|
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 5.0);
|
|
|
|
g_assert_cmpfloat (clutter_units_to_pixels (&units), !=, 5.0);
|
2009-10-06 12:47:34 -04:00
|
|
|
|
|
|
|
clutter_units_from_cm (&units_cm, 5.0);
|
|
|
|
g_assert (clutter_units_get_unit_type (&units_cm) == CLUTTER_UNIT_CM);
|
|
|
|
g_assert_cmpfloat (clutter_units_get_unit_value (&units_cm), ==, 5.0);
|
|
|
|
g_assert_cmpfloat (clutter_units_to_pixels (&units_cm), !=, 5.0);
|
|
|
|
|
|
|
|
clutter_units_from_mm (&units, 50.0);
|
|
|
|
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_MM);
|
|
|
|
g_assert_cmpfloat (clutter_units_to_pixels (&units),
|
|
|
|
==,
|
|
|
|
clutter_units_to_pixels (&units_cm));
|
2009-06-03 06:12:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-02-27 07:54:23 -05:00
|
|
|
units_string (TestConformSimpleFixture *fixture,
|
|
|
|
gconstpointer data)
|
2009-06-03 06:12:09 -04:00
|
|
|
{
|
|
|
|
ClutterUnits units;
|
|
|
|
gchar *string;
|
|
|
|
|
2010-01-13 12:31:13 -05:00
|
|
|
g_assert (clutter_units_from_string (&units, "") == FALSE);
|
|
|
|
|
2009-10-03 09:08:33 -04:00
|
|
|
g_assert (clutter_units_from_string (&units, "10") == TRUE);
|
|
|
|
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL);
|
|
|
|
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 10);
|
|
|
|
|
2010-01-13 12:31:13 -05:00
|
|
|
g_assert (clutter_units_from_string (&units, "10 px") == TRUE);
|
|
|
|
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL);
|
|
|
|
|
|
|
|
g_assert (clutter_units_from_string (&units, "10 mm") == TRUE);
|
|
|
|
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_MM);
|
|
|
|
|
|
|
|
g_assert (clutter_units_from_string (&units, "10 cm") == TRUE);
|
|
|
|
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_CM);
|
|
|
|
|
2009-10-06 07:02:15 -04:00
|
|
|
g_assert (clutter_units_from_string (&units, "10 ") == TRUE);
|
|
|
|
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_PIXEL);
|
|
|
|
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 10);
|
|
|
|
|
2009-06-03 06:12:09 -04:00
|
|
|
g_assert (clutter_units_from_string (&units, "5 em") == TRUE);
|
|
|
|
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_EM);
|
|
|
|
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 5);
|
|
|
|
|
2009-10-06 07:02:15 -04:00
|
|
|
g_assert (clutter_units_from_string (&units, "5 emeralds") == FALSE);
|
|
|
|
|
2009-06-03 06:12:09 -04:00
|
|
|
g_assert (clutter_units_from_string (&units, " 16 mm") == TRUE);
|
|
|
|
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_MM);
|
|
|
|
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 16);
|
|
|
|
|
2009-10-06 07:02:15 -04:00
|
|
|
g_assert (clutter_units_from_string (&units, " 24 pt ") == TRUE);
|
|
|
|
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_POINT);
|
|
|
|
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 24);
|
|
|
|
|
|
|
|
g_assert (clutter_units_from_string (&units, " 32 em garbage") == FALSE);
|
|
|
|
|
2009-10-06 12:47:34 -04:00
|
|
|
g_assert (clutter_units_from_string (&units, "5.1cm") == TRUE);
|
|
|
|
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_CM);
|
2009-10-06 07:02:15 -04:00
|
|
|
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 5.1f);
|
|
|
|
|
|
|
|
g_assert (clutter_units_from_string (&units, "5,mm") == FALSE);
|
|
|
|
|
|
|
|
g_assert (clutter_units_from_string (&units, ".5pt") == TRUE);
|
|
|
|
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_POINT);
|
|
|
|
g_assert_cmpfloat (clutter_units_get_unit_value (&units), ==, 0.5f);
|
|
|
|
|
2009-10-07 12:09:41 -04:00
|
|
|
g_assert (clutter_units_from_string (&units, "1 omg!!pony") == FALSE);
|
2009-06-03 06:12:09 -04:00
|
|
|
|
2009-07-28 08:43:52 -04:00
|
|
|
clutter_units_from_pt (&units, 24.0);
|
2009-06-03 06:12:09 -04:00
|
|
|
string = clutter_units_to_string (&units);
|
|
|
|
g_assert_cmpstr (string, ==, "24.0 pt");
|
|
|
|
g_free (string);
|
|
|
|
|
2009-07-28 08:43:52 -04:00
|
|
|
clutter_units_from_em (&units, 3.0);
|
2009-06-03 06:12:09 -04:00
|
|
|
string = clutter_units_to_string (&units);
|
|
|
|
g_assert_cmpstr (string, ==, "3.00 em");
|
|
|
|
|
|
|
|
units.unit_type = CLUTTER_UNIT_PIXEL;
|
|
|
|
units.value = 0;
|
|
|
|
|
|
|
|
g_assert (clutter_units_from_string (&units, string) == TRUE);
|
|
|
|
g_assert (clutter_units_get_unit_type (&units) != CLUTTER_UNIT_PIXEL);
|
|
|
|
g_assert (clutter_units_get_unit_type (&units) == CLUTTER_UNIT_EM);
|
|
|
|
g_assert_cmpint ((int) clutter_units_get_unit_value (&units), ==, 3);
|
|
|
|
|
|
|
|
g_free (string);
|
|
|
|
}
|