1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
#undef G_DISABLE_ASSERT
#include <gtk/gtk.h>
#include <shumate/shumate.h>
#include "shumate/vector/shumate-vector-value-private.h"
static void
test_vector_value_literal (void)
{
g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
double number;
gboolean boolean;
const char *string;
shumate_vector_value_unset (&value);
shumate_vector_value_set_number (&value, 3.1415);
g_assert_true (shumate_vector_value_get_number (&value, &number));
g_assert_cmpfloat (3.1415, ==, number);
shumate_vector_value_set_boolean (&value, TRUE);
g_assert_true (shumate_vector_value_get_boolean (&value, &boolean));
g_assert_true (boolean);
shumate_vector_value_set_boolean (&value, FALSE);
g_assert_true (shumate_vector_value_get_boolean (&value, &boolean));
g_assert_false (boolean);
shumate_vector_value_set_string (&value, "Hello, world!");
g_assert_true (shumate_vector_value_get_string (&value, &string));
g_assert_cmpstr ("Hello, world!", ==, string);
}
static void
test_vector_value_from_gvalue (void)
{
g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
g_auto(GValue) gvalue = G_VALUE_INIT;
double number;
gboolean boolean;
const char *string;
shumate_vector_value_unset (&value);
g_value_init (&gvalue, G_TYPE_DOUBLE);
g_value_set_double (&gvalue, 3.1415);
g_assert_true (shumate_vector_value_set_from_g_value (&value, &gvalue));
g_assert_true (shumate_vector_value_get_number (&value, &number));
g_assert_cmpfloat (3.1415, ==, number);
g_value_unset (&gvalue);
g_value_init (&gvalue, G_TYPE_BOOLEAN);
g_value_set_boolean (&gvalue, TRUE);
g_assert_true (shumate_vector_value_set_from_g_value (&value, &gvalue));
g_assert_true (shumate_vector_value_get_boolean (&value, &boolean));
g_assert_true (boolean);
g_value_set_boolean (&gvalue, FALSE);
shumate_vector_value_set_from_g_value (&value, &gvalue);
g_assert_true (shumate_vector_value_get_boolean (&value, &boolean));
g_assert_false (boolean);
g_value_unset (&gvalue);
g_value_init (&gvalue, G_TYPE_STRING);
g_value_set_string (&gvalue, "Hello, world!");
g_assert_true (shumate_vector_value_set_from_g_value (&value, &gvalue));
g_assert_true (shumate_vector_value_get_string (&value, &string));
g_assert_cmpstr ("Hello, world!", ==, string);
g_value_unset (&gvalue);
}
static void
test_vector_value_get_color (void)
{
g_auto(ShumateVectorValue) value = SHUMATE_VECTOR_VALUE_INIT;
GdkRGBA color, correct_color;
gdk_rgba_parse (&correct_color, "goldenrod");
shumate_vector_value_set_string (&value, "goldenrod");
g_assert_true (shumate_vector_value_get_color (&value, &color));
g_assert_true (gdk_rgba_equal (&color, &correct_color));
/* Try again to make sure caching works */
g_assert_true (shumate_vector_value_get_color (&value, &color));
g_assert_true (gdk_rgba_equal (&color, &correct_color));
shumate_vector_value_set_string (&value, "not a real color");
g_assert_false (shumate_vector_value_get_color (&value, &color));
/* Try again to make sure caching works */
g_assert_false (shumate_vector_value_get_color (&value, &color));
}
static void
test_vector_value_equal (void)
{
g_auto(ShumateVectorValue) value1 = SHUMATE_VECTOR_VALUE_INIT;
g_auto(ShumateVectorValue) value2 = SHUMATE_VECTOR_VALUE_INIT;
GdkRGBA color;
/* Both are initialized to NULL so they should be equal */
g_assert_true (shumate_vector_value_equal (&value1, &value2));
shumate_vector_value_set_number (&value1, 1.0);
shumate_vector_value_set_number (&value2, 1.0);
g_assert_true (shumate_vector_value_equal (&value1, &value2));
shumate_vector_value_set_number (&value1, 1.0);
shumate_vector_value_set_number (&value2, 2.0);
g_assert_false (shumate_vector_value_equal (&value1, &value2));
shumate_vector_value_set_boolean (&value1, TRUE);
shumate_vector_value_set_boolean (&value2, TRUE);
g_assert_true (shumate_vector_value_equal (&value1, &value2));
shumate_vector_value_set_number (&value1, FALSE);
shumate_vector_value_set_number (&value2, TRUE);
g_assert_false (shumate_vector_value_equal (&value1, &value2));
shumate_vector_value_set_string (&value1, "Hello, world!");
shumate_vector_value_set_string (&value2, "Hello, world!");
g_assert_true (shumate_vector_value_equal (&value1, &value2));
shumate_vector_value_set_string (&value1, "Hello, world!");
shumate_vector_value_set_string (&value2, "Goodbye, world!");
g_assert_false (shumate_vector_value_equal (&value1, &value2));
gdk_rgba_parse (&color, "magenta");
shumate_vector_value_set_color (&value1, &color);
shumate_vector_value_set_color (&value2, &color);
g_assert_true (shumate_vector_value_equal (&value1, &value2));
shumate_vector_value_set_color (&value1, &color);
gdk_rgba_parse (&color, "purple");
shumate_vector_value_set_color (&value2, &color);
g_assert_false (shumate_vector_value_equal (&value1, &value2));
shumate_vector_value_set_string (&value1, "Hello, world!");
shumate_vector_value_set_number (&value2, 1.0);
g_assert_false (shumate_vector_value_equal (&value1, &value2));
shumate_vector_value_set_number (&value1, TRUE);
shumate_vector_value_set_boolean (&value2, 1.0);
g_assert_false (shumate_vector_value_equal (&value1, &value2));
shumate_vector_value_unset (&value1);
shumate_vector_value_set_number (&value2, 0.0);
g_assert_false (shumate_vector_value_equal (&value1, &value2));
}
static void
test_vector_value_copy (void)
{
g_auto(ShumateVectorValue) value1 = SHUMATE_VECTOR_VALUE_INIT;
g_auto(ShumateVectorValue) value2 = SHUMATE_VECTOR_VALUE_INIT;
GdkRGBA color;
shumate_vector_value_copy (&value1, &value2);
g_assert_true (shumate_vector_value_equal (&value1, &value2));
gdk_rgba_parse (&color, "red");
shumate_vector_value_set_color (&value1, &color);
shumate_vector_value_copy (&value1, &value2);
g_assert_true (shumate_vector_value_equal (&value1, &value2));
shumate_vector_value_set_string (&value1, "Hello, world!");
shumate_vector_value_copy (&value1, &value2);
g_assert_true (shumate_vector_value_equal (&value1, &value2));
}
int
main (int argc, char *argv[])
{
g_test_init (&argc, &argv, NULL);
g_test_add_func ("/vector/value/literal", test_vector_value_literal);
g_test_add_func ("/vector/value/from-gvalue", test_vector_value_from_gvalue);
g_test_add_func ("/vector/value/get-color", test_vector_value_get_color);
g_test_add_func ("/vector/value/equal", test_vector_value_equal);
g_test_add_func ("/vector/value/copy", test_vector_value_copy);
return g_test_run ();
}
|