Skip to content

Commit

Permalink
Fix uninitialized use of PangoContext in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bynect committed Apr 19, 2024
1 parent f38a60a commit b0620ce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ test: test/test clean-coverage-run
test-valgrind: test/test
${VALGRIND} \
--suppressions=.valgrind.suppressions \
--track-origins=yes \
--leak-check=full \
--show-leak-kinds=definite \
--errors-for-leak-kinds=definite \
Expand Down
5 changes: 1 addition & 4 deletions src/icon.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,10 +168,7 @@ static GdkPixbuf *icon_pixbuf_scale_to_size(GdkPixbuf *pixbuf, int min_size, int
int h = gdk_pixbuf_get_height(pixbuf);

// TODO immediately rescale icon upon scale changes
if(icon_size_clamp(&w, &h, min_size, max_size)) {
//w = round(w * dpi_scale);
//h = round(h * dpi_scale);
}
icon_size_clamp(&w, &h, min_size, max_size);
GdkPixbuf *scaled = gdk_pixbuf_scale_simple(
pixbuf,
w,
Expand Down
31 changes: 25 additions & 6 deletions test/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ cairo_t *c;
double get_dummy_scale(void) { return 1; }

const struct screen_info* noop_screen(void) {
static struct screen_info i;
static struct screen_info i = {0};
return &i;
}

Expand Down Expand Up @@ -267,15 +267,18 @@ TEST test_layout_render_no_gaps(void)
dim = calculate_dimensions(layouts);
image_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);

enum corner_pos corners = C_TOP | _C_FIRST;
enum corner_pos corners = (settings.corners & C_TOP) | _C_FIRST;
for (GSList *iter = layouts; iter; iter = iter->next) {

struct colored_layout *cl_this = iter->data;
struct colored_layout *cl_next = iter->next ? iter->next->data : NULL;

if (!cl_next)
corners |= C_BOT | _C_LAST;
dim = layout_render(image_surface, cl_this, cl_next, dim, corners);
if (settings.gap_size)
corners = settings.corners;
else if (!cl_next)
corners |= (settings.corners & C_BOT) | _C_LAST;

dim = layout_render(image_surface, cl_this, cl_next, dim, corners);
corners &= ~(C_TOP | _C_FIRST);
}

Expand Down Expand Up @@ -311,11 +314,19 @@ TEST test_layout_render_gaps(void)
dim = calculate_dimensions(layouts);
image_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);

enum corner_pos corners = (settings.corners & C_TOP) | _C_FIRST;
for (GSList *iter = layouts; iter; iter = iter->next) {

struct colored_layout *cl_this = iter->data;
struct colored_layout *cl_next = iter->next ? iter->next->data : NULL;

dim = layout_render(image_surface, cl_this, cl_next, dim, C_ALL);
if (settings.gap_size)
corners = settings.corners;
else if (!cl_next)
corners |= (settings.corners & C_BOT) | _C_LAST;

dim = layout_render(image_surface, cl_this, cl_next, dim, corners);
corners &= ~(C_TOP | _C_FIRST);
}

expected_y = get_expected_dimension_y_offset(layout_count);
Expand All @@ -336,6 +347,10 @@ SUITE(suite_draw)
cairo_surface_t *s = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 1, 1);
c = cairo_create(s);

// XXX: This variable should not be accessed like this
extern PangoContext *pango_ctx;
pango_ctx = pango_cairo_create_context(c);

SHUFFLE_TESTS(time(NULL), {
RUN_TEST(test_layout_from_notification);
RUN_TEST(test_layout_from_notification_icon_off);
Expand All @@ -345,4 +360,8 @@ SUITE(suite_draw)
RUN_TEST(test_layout_render_no_gaps);
RUN_TEST(test_layout_render_gaps);
});

g_object_unref(pango_ctx);
cairo_destroy(c);
cairo_surface_destroy(s);
}

0 comments on commit b0620ce

Please sign in to comment.