diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-11-17 20:56:25 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-11-18 13:58:15 -0500 |
commit | 4d60ee85616d500c3384301330b8bfae619c7963 (patch) | |
tree | b0e200841afd8da783c8cd6965ee1f5867dd9cfd /tests/testserialize.c | |
parent | 2aead7a8e8828de6afef96611661997a52ca6739 (diff) | |
download | pango-4d60ee85616d500c3384301330b8bfae619c7963.tar.gz |
Make test-layout use layout serialization
Now that we have this api, lets use it for
our tests.
Diffstat (limited to 'tests/testserialize.c')
-rw-r--r-- | tests/testserialize.c | 87 |
1 files changed, 55 insertions, 32 deletions
diff --git a/tests/testserialize.c b/tests/testserialize.c index 2c1d2f53..5fb7543a 100644 --- a/tests/testserialize.c +++ b/tests/testserialize.c @@ -245,43 +245,66 @@ test_serialize_layout_valid (void) static void test_serialize_layout_invalid (void) { - const char *test1 = - "{\n" - " \"attributes\" : [\n" - " {\n" - " \"type\" : \"caramba\"\n" - " }\n" - " ]\n" - "}"; - - const char *test2 = - "{\n" - " \"attributes\" : [\n" - " {\n" - " \"type\" : \"weight\"\n" - " }\n" - " ]\n" - "}"; + struct { + const char *json; + int expected_error; + } test[] = { + { + "{\n" + " \"attributes\" : [\n" + " {\n" + " \"type\" : \"caramba\"\n" + " }\n" + " ]\n" + "}", + PANGO_LAYOUT_SERIALIZE_INVALID_VALUE + }, + { + "{\n" + " \"attributes\" : [\n" + " {\n" + " \"type\" : \"weight\"\n" + " }\n" + " ]\n" + "}", + PANGO_LAYOUT_SERIALIZE_MISSING_VALUE + }, + { + "{\n" + " \"attributes\" : [\n" + " {\n" + " \"type\" : \"alignment\",\n" + " \"value\" : \"nonsense\"\n" + " }\n" + " ]\n" + "}", + PANGO_LAYOUT_SERIALIZE_INVALID_VALUE + }, + { + "{\n" + " \"alignment\" : \"nonsense\"\n" + "}", + PANGO_LAYOUT_SERIALIZE_INVALID_VALUE + } + }; PangoContext *context; - GBytes *bytes; - PangoLayout *layout; - GError *error = NULL; context = pango_font_map_create_context (pango_cairo_font_map_get_default ()); - bytes = g_bytes_new_static (test1, -1); - layout = pango_layout_deserialize (context, bytes, &error); - g_assert_null (layout); - g_assert_error (error, PANGO_LAYOUT_SERIALIZE_ERROR, PANGO_LAYOUT_SERIALIZE_INVALID_VALUE); - g_bytes_unref (bytes); - g_clear_error (&error); - - bytes = g_bytes_new_static (test2, -1); - layout = pango_layout_deserialize (context, bytes, &error); - g_assert_null (layout); - g_assert_error (error, PANGO_LAYOUT_SERIALIZE_ERROR, PANGO_LAYOUT_SERIALIZE_MISSING_VALUE); - g_bytes_unref (bytes); + for (int i = 0; i < G_N_ELEMENTS (test); i++) + { + GBytes *bytes; + PangoLayout *layout; + GError *error = NULL; + + bytes = g_bytes_new_static (test[i].json, -1); + layout = pango_layout_deserialize (context, bytes, &error); + g_assert_null (layout); + g_assert_error (error, PANGO_LAYOUT_SERIALIZE_ERROR, test[i].expected_error); + g_bytes_unref (bytes); + g_clear_error (&error); + } g_object_unref (context); } |