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