diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/markups/valid-19.expected | 2 | ||||
-rw-r--r-- | tests/markups/valid-4.expected | 4 | ||||
-rw-r--r-- | tests/test-itemize.c | 2 | ||||
-rw-r--r-- | tests/test-shape.c | 4 | ||||
-rw-r--r-- | tests/testattributes.c | 180 | ||||
-rw-r--r-- | tests/testserialize.c | 8 |
6 files changed, 122 insertions, 78 deletions
diff --git a/tests/markups/valid-19.expected b/tests/markups/valid-19.expected index 5b84133f..9de3df07 100644 --- a/tests/markups/valid-19.expected +++ b/tests/markups/valid-19.expected @@ -4,7 +4,7 @@ test --- range 0 4 -0 4 family Times +0 4 family "Times" 0 4 weight bold 0 4 foreground #ffff00000000 0 4 letter-spacing 1024 diff --git a/tests/markups/valid-4.expected b/tests/markups/valid-4.expected index 345e8699..11ecfab1 100644 --- a/tests/markups/valid-4.expected +++ b/tests/markups/valid-4.expected @@ -31,9 +31,9 @@ range 38 41 38 41 baseline-shift superscript range 41 42 range 42 45 -42 54 family Monospace +42 54 family "Monospace" range 45 54 -42 54 family Monospace +42 54 family "Monospace" 45 54 underline single range 54 2147483647 diff --git a/tests/test-itemize.c b/tests/test-itemize.c index 267c1b62..fc87a959 100644 --- a/tests/test-itemize.c +++ b/tests/test-itemize.c @@ -57,7 +57,7 @@ static gboolean affects_itemization (PangoAttribute *attr, gpointer data) { - switch ((int)attr->klass->type) + switch ((int)attr->type) { /* These affect font selection */ case PANGO_ATTR_LANGUAGE: diff --git a/tests/test-shape.c b/tests/test-shape.c index bbfd91db..a3d4e8b7 100644 --- a/tests/test-shape.c +++ b/tests/test-shape.c @@ -63,7 +63,7 @@ static gboolean affects_itemization (PangoAttribute *attr, gpointer data) { - switch ((int)attr->klass->type) + switch ((int)attr->type) { /* These affect font selection */ case PANGO_ATTR_LANGUAGE: @@ -94,7 +94,7 @@ static gboolean affects_break_or_shape (PangoAttribute *attr, gpointer data) { - switch ((int)attr->klass->type) + switch ((int)attr->type) { /* Affects breaks */ case PANGO_ATTR_ALLOW_BREAKS: diff --git a/tests/testattributes.c b/tests/testattributes.c index 772578de..be98cdd0 100644 --- a/tests/testattributes.c +++ b/tests/testattributes.c @@ -36,7 +36,6 @@ static void test_attributes_basic (void) { PangoFontDescription *desc; - PangoRectangle rect = { 0, 0, 10, 10 }; test_copy (pango_attr_language_new (pango_language_from_string ("ja-JP"))); test_copy (pango_attr_family_new ("Times")); @@ -97,64 +96,110 @@ test_attributes_equal (void) pango_attribute_destroy (attr3); } +static gpointer +copy_my_attribute_data (gconstpointer data) +{ + return (gpointer)data; +} + +static void +destroy_my_attribute_data (gpointer data) +{ +} + +static gboolean +my_attribute_data_equal (gconstpointer data1, + gconstpointer data2) +{ + return data1 == data2; +} + +static char * +my_attribute_data_serialize (gconstpointer data) +{ + return g_strdup_printf ("%p", data); +} + static void test_attributes_register (void) { PangoAttrType type; - GEnumClass *class; + PangoAttribute *attr; + PangoAttribute *attr2; + gpointer value = NULL; + gboolean ret; + PangoAttrList *list; + char *str; + + type = pango_attr_type_register (copy_my_attribute_data, + destroy_my_attribute_data, + my_attribute_data_equal, + "my-attribute", + my_attribute_data_serialize); - type = pango_attr_type_register ("my-attribute"); g_assert_cmpstr (pango_attr_type_get_name (type), ==, "my-attribute"); - class = g_type_class_ref (PANGO_TYPE_ATTR_TYPE); - for (int i = 0; i < class->n_values; i++) - { - g_assert_cmpint (type, !=, class->values[i].value); - g_assert_null (pango_attr_type_get_name (class->values[i].value)); - } + attr = pango_attr_custom_new (type, (gpointer)0x42); + + ret = pango_attribute_get_custom (attr, &value); + g_assert_true (ret); + g_assert_true (value == (gpointer)0x42); + + attr2 = pango_attr_custom_new (type, (gpointer)0x43); - g_type_class_unref (class); + ret = pango_attribute_equal (attr, attr2); + g_assert_false (ret); + + list = pango_attr_list_new (); + pango_attr_list_insert (list, attr2); + + str = pango_attr_list_to_string (list); + g_assert_cmpstr (str, ==, "0 4294967295 my-attribute 0x43"); + g_free (str); + + pango_attr_list_unref (list); + + pango_attribute_destroy (attr); } static void test_binding (PangoAttribute *attr) { - enum { - INVALID, INT, LANGUAGE, STRING, SIZE, FONT_DESC, COLOR, SHAPE, FLOAT, FONT_FEATURES, - } attr_base[] = { - INVALID, LANGUAGE, STRING, INT, INT, INT, INT, SIZE, FONT_DESC, COLOR, - COLOR, INT, INT, INT, SHAPE, FLOAT, INT, INT, COLOR, COLOR, SIZE, - INT, INT, FONT_FEATURES, INT, INT, INT, INT, INT, INT, COLOR, FLOAT, - INT, INT, INT, INT, INT, INT - }; - - switch (attr_base[attr->klass->type]) + int int_value; + gboolean boolean_value; + PangoLanguage *lang_value; + const char *string; + PangoFontDescription *font_desc; + PangoColor color; + double double_value; + gpointer pointer_value; + + switch (PANGO_ATTR_VALUE_TYPE (attr)) { - case INT: - g_assert_nonnull (pango_attribute_as_int (attr)); + case PANGO_ATTR_VALUE_INT: + g_assert_true (pango_attribute_get_int (attr, &int_value)); break; - case LANGUAGE: - g_assert_nonnull (pango_attribute_as_language (attr)); + case PANGO_ATTR_VALUE_BOOLEAN: + g_assert_true (pango_attribute_get_boolean (attr, &boolean_value)); break; - case STRING: - g_assert_nonnull (pango_attribute_as_string (attr)); + case PANGO_ATTR_VALUE_LANGUAGE: + g_assert_true (pango_attribute_get_language (attr, &lang_value)); break; - case SIZE: - g_assert_nonnull (pango_attribute_as_size (attr)); + case PANGO_ATTR_VALUE_STRING: + g_assert_true (pango_attribute_get_string (attr, &string)); break; - case FONT_DESC: - g_assert_nonnull (pango_attribute_as_font_desc (attr)); + case PANGO_ATTR_VALUE_FONT_DESC: + g_assert_true (pango_attribute_get_font_desc (attr, &font_desc)); break; - case COLOR: - g_assert_nonnull (pango_attribute_as_color (attr)); + case PANGO_ATTR_VALUE_COLOR: + g_assert_true (pango_attribute_get_color (attr, &color)); break; - case FLOAT: - g_assert_nonnull (pango_attribute_as_float (attr)); + case PANGO_ATTR_VALUE_FLOAT: + g_assert_true (pango_attribute_get_float (attr, &double_value)); break; - case FONT_FEATURES: - g_assert_nonnull (pango_attribute_as_font_features (attr)); + case PANGO_ATTR_VALUE_POINTER: + g_assert_true (pango_attribute_get_custom (attr, &pointer_value)); break; - case INVALID: default: g_assert_not_reached (); } @@ -166,7 +211,6 @@ static void test_binding_helpers (void) { PangoFontDescription *desc; - PangoRectangle rect = { 0, 0, 10, 10 }; test_binding (pango_attr_language_new (pango_language_from_string ("ja-JP"))); test_binding (pango_attr_family_new ("Times")); @@ -451,7 +495,7 @@ test_list_change5 (void) attr = attribute_from_string ("5 15 style italic"); g_assert (attr->start_index == 5); g_assert (attr->end_index == 15); - g_assert (((PangoAttrInt *)attr)->value == PANGO_STYLE_ITALIC); + g_assert (attr->int_value == PANGO_STYLE_ITALIC); pango_attr_list_change (list, attr); assert_attr_list (list, "0 3 weight ultrabold\n" @@ -740,7 +784,7 @@ never_true (PangoAttribute *attribute, gpointer user_data) static gboolean just_weight (PangoAttribute *attribute, gpointer user_data) { - if (attribute->klass->type == PANGO_ATTR_WEIGHT) + if (attribute->type == PANGO_ATTR_WEIGHT) return TRUE; else return FALSE; @@ -877,7 +921,7 @@ test_iter_get_font (void) list = pango_attr_list_new (); attr = pango_attr_size_new (10 * PANGO_SCALE); pango_attr_list_insert (list, attr); - attr = attribute_from_string ("0 -1 family Times"); + attr = attribute_from_string ("0 -1 family \"Times\""); pango_attr_list_insert (list, attr); attr = attribute_from_string ("10 30 stretch condensed"); pango_attr_list_insert (list, attr); @@ -938,7 +982,7 @@ test_iter_get_attrs (void) list = pango_attr_list_new (); attr = pango_attr_size_new (10 * PANGO_SCALE); pango_attr_list_insert (list, attr); - attr = attribute_from_string ("0 -1 family Times"); + attr = attribute_from_string ("0 -1 family \"Times\""); pango_attr_list_insert (list, attr); attr = attribute_from_string ("10 30 stretch condensed"); pango_attr_list_insert (list, attr); @@ -951,24 +995,24 @@ test_iter_get_attrs (void) iter = pango_attr_list_get_iterator (list); assert_attr_iterator (iter, "0 -1 size 10240\n" - "0 -1 family Times\n"); + "0 -1 family \"Times\"\n"); pango_attr_iterator_next (iter); assert_attr_iterator (iter, "0 -1 size 10240\n" - "0 -1 family Times\n" + "0 -1 family \"Times\"\n" "10 30 stretch 2\n" "10 20 language ja-jp\n"); pango_attr_iterator_next (iter); assert_attr_iterator (iter, "0 -1 size 10240\n" - "0 -1 family Times\n" + "0 -1 family \"Times\"\n" "10 30 stretch 2\n" "20 -1 rise 100\n" "20 -1 fallback 0\n"); pango_attr_iterator_next (iter); assert_attr_iterator (iter, "0 -1 size 10240\n" - "0 -1 family Times\n" + "0 -1 family \"Times\"\n" "20 -1 rise 100\n" "20 -1 fallback 0\n"); @@ -985,7 +1029,7 @@ test_list_update (void) PangoAttrList *list; list = pango_attr_list_from_string ("0 200 rise 100\n" - "5 15 family Times\n" + "5 15 family \"Times\"\n" "10 11 size 10240\n" "11 100 fallback 0\n" "30 60 stretch 2\n"); @@ -993,7 +1037,7 @@ test_list_update (void) pango_attr_list_update (list, 8, 10, 20); assert_attr_list (list, "0 210 rise 100\n" - "5 8 family Times\n" + "5 8 family \"Times\"\n" "28 110 fallback false\n" "40 70 stretch condensed\n"); @@ -1020,11 +1064,11 @@ test_list_update3 (void) { PangoAttrList *list; - list = pango_attr_list_from_string ("5 4294967285 family Times\n"); + list = pango_attr_list_from_string ("5 4294967285 family \"Times\"\n"); pango_attr_list_update (list, 8, 10, 30); - assert_attr_list (list, "5 -1 family Times\n"); + assert_attr_list (list, "5 -1 family \"Times\"\n"); pango_attr_list_unref (list); } @@ -1105,28 +1149,28 @@ test_insert (void) PangoAttribute *attr; list = pango_attr_list_from_string ("0 200 rise 100\n" - "5 15 family Times\n" + "5 15 family \"Times\"\n" "10 11 size 10240\n" "11 100 fallback 0\n" "30 60 stretch 2\n"); - attr = attribute_from_string ("10 25 family Times"); + attr = attribute_from_string ("10 25 family \"Times\""); pango_attr_list_change (list, attr); assert_attr_list (list, "0 200 rise 100\n" - "5 25 family Times\n" + "5 25 family \"Times\"\n" "10 11 size 10240\n" "11 100 fallback false\n" "30 60 stretch condensed\n"); - attr = attribute_from_string ("11 25 family Futura"); + attr = attribute_from_string ("11 25 family \"Futura\""); pango_attr_list_insert (list, attr); assert_attr_list (list, "0 200 rise 100\n" - "5 25 family Times\n" + "5 25 family \"Times\"\n" "10 11 size 10240\n" "11 100 fallback false\n" - "11 25 family Futura\n" + "11 25 family \"Futura\"\n" "30 60 stretch condensed\n"); pango_attr_list_unref (list); @@ -1139,21 +1183,21 @@ test_insert2 (void) PangoAttribute *attr; list = pango_attr_list_from_string ("0 200 rise 100\n" - "5 15 family Times\n" + "5 15 family \"Times\"\n" "10 11 size 10240\n" "11 100 fallback 0\n" - "20 30 family Times\n" - "30 40 family Futura\n" + "20 30 family \"Times\"\n" + "30 40 family \"Futura\"\n" "30 60 stretch 2\n"); - attr = attribute_from_string ("10 35 family Times"); + attr = attribute_from_string ("10 35 family \"Times\""); pango_attr_list_change (list, attr); assert_attr_list (list, "0 200 rise 100\n" - "5 35 family Times\n" + "5 35 family \"Times\"\n" "10 11 size 10240\n" "11 100 fallback false\n" - "35 40 family Futura\n" + "35 40 family \"Futura\"\n" "30 60 stretch condensed\n"); pango_attr_list_unref (list); @@ -1175,7 +1219,7 @@ test_merge (void) PangoAttrList *list2; list = pango_attr_list_from_string ("0 200 rise 100\n" - "5 15 family Times\n" + "5 15 family \"Times\"\n" "10 11 size 10240\n" "11 100 fallback 0\n" "30 60 stretch 2\n"); @@ -1187,7 +1231,7 @@ test_merge (void) pango_attr_list_filter (list2, attr_list_merge_filter, list); assert_attr_list (list, "0 200 rise 100\n" - "5 15 family Times\n" + "5 15 family \"Times\"\n" "10 13 size 10240\n" "11 100 fallback false\n" "13 15 size 11264\n" @@ -1253,25 +1297,25 @@ print_tags_for_attributes (PangoAttrIterator *iter, if (attr) g_string_append_printf (s, "%d %d rise %d\n", attr->start_index, attr->end_index, - ((PangoAttrInt*)attr)->value); + attr->int_value); attr = pango_attr_iterator_get (iter, PANGO_ATTR_SIZE); if (attr) g_string_append_printf (s, "%d %d size %d\n", attr->start_index, attr->end_index, - ((PangoAttrInt*)attr)->value); + attr->int_value); attr = pango_attr_iterator_get (iter, PANGO_ATTR_SCALE); if (attr) g_string_append_printf (s, "%d %d scale %f\n", attr->start_index, attr->end_index, - ((PangoAttrFloat*)attr)->value); + attr->double_value); attr = pango_attr_iterator_get (iter, PANGO_ATTR_ALLOW_BREAKS); if (attr) g_string_append_printf (s, "%d %d allow_breaks %d\n", attr->start_index, attr->end_index, - ((PangoAttrInt*)attr)->value); + attr->int_value); } static void diff --git a/tests/testserialize.c b/tests/testserialize.c index e480da31..f8a7bca3 100644 --- a/tests/testserialize.c +++ b/tests/testserialize.c @@ -36,7 +36,7 @@ test_serialize_attr_list (void) "0 100 font-desc \"Cantarell, Sans, Italic Ultra-Light 64\", 10 11 weight 100", "0 -1 size 10", "0 1 weight 700, 2 4 weight book", - "0 200 rise 100\n5 15 family Times\n10 11 size 10240\n11 100 fallback 0\n30 60 stretch 2\n", + "0 200 rise 100\n5 15 family \"Times\"\n10 11 size 10240\n11 100 fallback 0\n30 60 stretch 2\n", "" }; const char *roundtripped[] = { @@ -47,7 +47,7 @@ test_serialize_attr_list (void) "0 100 font-desc \"Cantarell,Sans Ultra-Light Italic 64\"\n10 11 weight thin", "0 4294967295 size 10", "0 1 weight bold\n2 4 weight book", - "0 200 rise 100\n5 15 family Times\n10 11 size 10240\n11 100 fallback false\n30 60 stretch condensed", + "0 200 rise 100\n5 15 family \"Times\"\n10 11 size 10240\n11 100 fallback false\n30 60 stretch condensed", "" }; const char *invalid[] = { @@ -366,7 +366,7 @@ test_serialize_layout_invalid (void) " }\n" " ]\n" "}\n", - PANGO_LAYOUT_DESERIALIZE_INVALID_VALUE + PANGO_LAYOUT_DESERIALIZE_MISSING_VALUE }, { "{\n" @@ -382,7 +382,7 @@ test_serialize_layout_invalid (void) "{\n" " \"attributes\" : [\n" " {\n" - " \"type\" : \"alignment\",\n" + " \"type\" : \"background\",\n" " \"value\" : \"nonsense\"\n" " }\n" " ]\n" |