~vcs-imports/pango/master

« back to all changes in this revision

Viewing changes to tests/testserialize.c

  • Committer: Matthias Clasen
  • Date: 2021-12-03 01:34:40 UTC
  • mfrom: (4611.1.10)
  • Revision ID: git-v1:fdef4305de8cd7e411a3da61bf1dcbd3a628b035
Merge branch 'serializer-rewrite' into 'main'

Port the serializer to use our own json parser and printer

See merge request GNOME/pango!531

Show diffs side-by-side

added added

removed removed

Lines of Context:
135
135
  PangoContext *context;
136
136
  PangoFontDescription *desc;
137
137
  PangoFont *font;
 
138
  PangoFont *font2;
138
139
  GBytes *bytes;
 
140
  GBytes *bytes2;
 
141
  GError *error = NULL;
139
142
  const char *expected =
140
143
    "{\n"
141
144
    "  \"description\" : \"Cantarell 20 @wght=600\",\n"
144
147
    "    \"wght\" : 5583\n"
145
148
    "  },\n"
146
149
    "  \"matrix\" : [\n"
147
 
    "    1.0,\n"
148
 
    "    -0.0,\n"
149
 
    "    -0.0,\n"
150
 
    "    1.0,\n"
151
 
    "    0.0,\n"
152
 
    "    0.0\n"
 
150
    "    1,\n"
 
151
    "    -0,\n"
 
152
    "    -0,\n"
 
153
    "    1,\n"
 
154
    "    0,\n"
 
155
    "    0\n"
153
156
    "  ]\n"
154
157
    "}";
155
158
 
159
162
 
160
163
  bytes = pango_font_serialize (font);
161
164
  g_assert_cmpstr (g_bytes_get_data (bytes, NULL), ==, expected);
162
 
  g_bytes_unref (bytes);
 
165
 
 
166
  font2 = pango_font_deserialize (context, bytes, &error);
 
167
  g_assert_no_error (error);
 
168
  g_assert_nonnull (font2);
 
169
 
 
170
  bytes2 = pango_font_serialize (font2);
 
171
  g_assert_true (g_bytes_equal (bytes2, bytes));
163
172
 
164
173
  g_object_unref (font);
 
174
  g_object_unref (font2);
165
175
  pango_font_description_free (desc);
 
176
 
 
177
  g_bytes_unref (bytes);
 
178
  g_bytes_unref (bytes2);
166
179
  g_object_unref (context);
167
180
}
168
181
 
183
196
 
184
197
  context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
185
198
 
186
 
  bytes = g_bytes_new_static (test, -1);
 
199
  bytes = g_bytes_new_static (test, strlen (test) + 1);
187
200
 
188
201
  layout = pango_layout_deserialize (context, bytes, PANGO_LAYOUT_DESERIALIZE_DEFAULT, &error);
189
202
  g_assert_no_error (error);
267
280
 
268
281
  context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
269
282
 
270
 
  bytes = g_bytes_new_static (test, -1);
 
283
  bytes = g_bytes_new_static (test, strlen (test) + 1);
271
284
 
272
285
  layout = pango_layout_deserialize (context, bytes, PANGO_LAYOUT_DESERIALIZE_DEFAULT, &error);
273
286
  g_assert_no_error (error);
286
299
 
287
300
  out_bytes = pango_layout_serialize (layout, PANGO_LAYOUT_SERIALIZE_DEFAULT);
288
301
 
 
302
  if (strcmp (g_bytes_get_data (out_bytes, NULL), g_bytes_get_data (bytes, NULL)) != 0)
 
303
    {
 
304
      g_print ("expected:\n%s\ngot:\n%s\n",
 
305
               (char *)g_bytes_get_data (bytes, NULL),
 
306
               (char *)g_bytes_get_data (out_bytes, NULL));
 
307
    }
 
308
 
289
309
  g_assert_cmpstr (g_bytes_get_data (out_bytes, NULL), ==, g_bytes_get_data (bytes, NULL));
290
310
 
291
311
  g_bytes_unref (out_bytes);
303
323
    "  \"context\" : {\n"
304
324
    "    \"base-gravity\" : \"east\",\n"
305
325
    "    \"language\" : \"de-de\",\n"
306
 
    "    \"round-glyph-positions\" : \"false\"\n"
 
326
    "    \"round-glyph-positions\" : false\n"
307
327
    "  },\n"
308
328
    "  \"text\" : \"Some fun with layouts!\"\n"
309
329
    "}\n";
315
335
 
316
336
  context = pango_font_map_create_context (pango_cairo_font_map_get_default ());
317
337
 
318
 
  bytes = g_bytes_new_static (test, -1);
 
338
  bytes = g_bytes_new_static (test, strlen (test) + 1);
319
339
 
320
340
  layout = pango_layout_deserialize (context, bytes, PANGO_LAYOUT_DESERIALIZE_CONTEXT, &error);
321
341
  g_assert_no_error (error);
381
401
      "    \"name\" : \"This is wrong\"\n"
382
402
      "  }\n"
383
403
      "}\n",
384
 
      PANGO_LAYOUT_DESERIALIZE_INVALID_SYNTAX
 
404
      0,
385
405
    }
386
406
  };
387
407
 
395
415
      PangoLayout *layout;
396
416
      GError *error = NULL;
397
417
 
398
 
       bytes = g_bytes_new_static (test[i].json, -1);
 
418
       bytes = g_bytes_new_static (test[i].json, strlen (test[i].json) + 1);
399
419
       layout = pango_layout_deserialize (context, bytes, PANGO_LAYOUT_DESERIALIZE_DEFAULT, &error);
400
420
       g_assert_null (layout);
401
 
       g_assert_error (error, PANGO_LAYOUT_DESERIALIZE_ERROR, test[i].expected_error);
 
421
       if (test[i].expected_error)
 
422
         g_assert_error (error, PANGO_LAYOUT_DESERIALIZE_ERROR, test[i].expected_error);
 
423
       else
 
424
         g_assert_nonnull (error);
402
425
       g_bytes_unref (bytes);
403
426
       g_clear_error (&error);
404
427
    }