Tests/font-variations: Cleanup resources in all cases

Otherwise the test runner detects leaks
This commit is contained in:
Luca Bacci 2025-02-06 18:58:12 +01:00
parent 98e5d5ad16
commit 47d8ff0e2a

View file

@ -47,19 +47,21 @@ test_variation (cairo_test_context_t *ctx,
int def,
float expected_value)
{
cairo_font_face_t *font_face;
cairo_scaled_font_t *scaled_font;
#if CAIRO_HAS_FC_FONT
cairo_test_status_t result = CAIRO_TEST_FAILURE;
cairo_font_face_t *font_face = NULL;
cairo_scaled_font_t *scaled_font = NULL;
cairo_matrix_t matrix;
cairo_font_options_t *options;
cairo_font_options_t *options = NULL;
cairo_status_t status;
FT_Face ft_face;
FT_Face ft_face = NULL;
FT_MM_Var *ft_mm_var;
FT_Error ret;
FT_Fixed coords[20];
unsigned int i;
#if CAIRO_HAS_FC_FONT
FcPattern *pattern;
/* we need a font that has variations */
@ -72,25 +74,25 @@ test_variation (cairo_test_context_t *ctx,
if (status != CAIRO_STATUS_SUCCESS) {
cairo_test_log (ctx, "Failed to create font face");
return CAIRO_TEST_FAILURE;
goto cleanup;
}
cairo_matrix_init_identity (&matrix);
options = cairo_font_options_create ();
if (cairo_font_options_status (options) != CAIRO_STATUS_SUCCESS) {
cairo_test_log (ctx, "Failed to create font options");
return CAIRO_TEST_FAILURE;
goto cleanup;
}
cairo_font_options_set_variations (options, input);
if (cairo_font_options_status (options) != CAIRO_STATUS_SUCCESS) {
cairo_test_log (ctx, "Failed to set variations");
return CAIRO_TEST_FAILURE;
goto cleanup;
}
if (strcmp (cairo_font_options_get_variations (options), input) != 0) {
cairo_test_log (ctx, "Failed to verify variations");
return CAIRO_TEST_FAILURE;
goto cleanup;
}
scaled_font = cairo_scaled_font_create (font_face, &matrix, &matrix, options);
@ -98,29 +100,30 @@ test_variation (cairo_test_context_t *ctx,
if (status != CAIRO_STATUS_SUCCESS) {
cairo_test_log (ctx, "Failed to create scaled font");
return CAIRO_TEST_FAILURE;
goto cleanup;
}
ft_face = cairo_ft_scaled_font_lock_face (scaled_font);
if (cairo_scaled_font_status (scaled_font) != CAIRO_STATUS_SUCCESS) {
cairo_test_log (ctx, "Failed to get FT_Face");
return CAIRO_TEST_FAILURE;
goto cleanup;
}
if (strcmp (ft_face->family_name, "Adobe Variable Font Prototype") != 0) {
cairo_test_log (ctx, "This test requires the font \"Adobe Variable Font Prototype\" (https://github.com/adobe-fonts/adobe-variable-font-prototype/releases)");
return CAIRO_TEST_UNTESTED;
result = CAIRO_TEST_UNTESTED;
goto cleanup;
}
ret = FT_Get_MM_Var (ft_face, &ft_mm_var);
if (ret != 0) {
cairo_test_log (ctx, "Failed to get MM");
return CAIRO_TEST_FAILURE;
goto cleanup;
}
ret = FT_Get_Var_Design_Coordinates (ft_face, 20, coords);
if (ret != 0) {
cairo_test_log (ctx, "Failed to get coords");
return CAIRO_TEST_FAILURE;
goto cleanup;
}
for (i = 0; i < ft_mm_var->num_axis; i++) {
@ -134,14 +137,14 @@ test_variation (cairo_test_context_t *ctx,
if (coords[i] != axis->def) {
cairo_test_log (ctx, "Axis %s: not default value (%g != %g)",
axis->name, coords[i] / 65536., axis->def / 65536.);
return CAIRO_TEST_FAILURE;
goto cleanup;
}
}
else {
if (coords[i] != FloatToFixed(expected_value)) {
cairo_test_log (ctx, "Axis %s: not expected value (%g != %g)",
axis->name, coords[i] / 65536., expected_value);
return CAIRO_TEST_FAILURE;
goto cleanup;
}
}
}
@ -149,13 +152,19 @@ test_variation (cairo_test_context_t *ctx,
}
}
cairo_ft_scaled_font_unlock_face (scaled_font);
result = CAIRO_TEST_SUCCESS;
cairo_scaled_font_destroy (scaled_font);
cairo_font_options_destroy (options);
cairo_font_face_destroy (font_face);
cleanup:
if (ft_face)
cairo_ft_scaled_font_unlock_face (scaled_font);
if (scaled_font)
cairo_scaled_font_destroy (scaled_font);
if (options)
cairo_font_options_destroy (options);
if (font_face)
cairo_font_face_destroy (font_face);
return CAIRO_TEST_SUCCESS;
return result;
#else
return CAIRO_TEST_UNTESTED;
#endif