Skip to content

Commit 54685f7

Browse files
committed
Update tests for icon sizes being a rule
1 parent 9210854 commit 54685f7

File tree

4 files changed

+22
-33
lines changed

4 files changed

+22
-33
lines changed

src/icon.c

+2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ cairo_surface_t *gdk_pixbuf_to_cairo_surface(GdkPixbuf *pixbuf)
122122
*
123123
* @param w a pointer to the image width, to be modified in-place
124124
* @param h a pointer to the image height, to be modified in-place
125+
* @param min_size the minimum icon size setting for this notification
126+
* @param max_size the maximum icon size setting for this notification
125127
* @return TRUE if the dimensions were updated, FALSE if they were left unchanged
126128
*/
127129
static bool icon_size_clamp(int *w, int *h, int min_size, int max_size) {

src/icon.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ char *get_path_from_icon_name(const char *iconname, int size);
5656
* like described in the notification spec.
5757
* @param id (necessary) A unique identifier of the returned pixbuf.
5858
* Only filled, if the return value is non-NULL.
59-
* @param scale An integer representing the output dpi scaling.
59+
* @param dpi_scale An integer representing the output dpi scaling.
6060
* @param min_size An integer representing the desired minimum unscaled icon size.
6161
* @param max_size An integer representing the desired maximum unscaled icon size.
6262
* @return an instance of `GdkPixbuf` derived from the GVariant

test/icon.c

+17-28
Original file line numberDiff line numberDiff line change
@@ -38,43 +38,43 @@ TEST test_get_path_from_icon_name_full(void)
3838
PASS();
3939
}
4040

41-
TEST test_icon_size_clamp_too_small(void)
41+
TEST test_icon_size_clamp_too_small(int min_icon_size, int max_icon_size)
4242
{
4343
int w = 12, h = 24;
44-
bool resized = icon_size_clamp(&w, &h);
44+
bool resized = icon_size_clamp(&w, &h, min_icon_size, max_icon_size);
4545
ASSERT(resized);
4646
ASSERT_EQ(w, 16);
4747
ASSERT_EQ(h, 32);
4848

4949
PASS();
5050
}
5151

52-
TEST test_icon_size_clamp_not_necessary(void)
52+
TEST test_icon_size_clamp_not_necessary(int min_icon_size, int max_icon_size)
5353
{
5454
int w = 20, h = 30;
55-
bool resized = icon_size_clamp(&w, &h);
55+
bool resized = icon_size_clamp(&w, &h, min_icon_size, max_icon_size);
5656
ASSERT(!resized);
5757
ASSERT_EQ(w, 20);
5858
ASSERT_EQ(h, 30);
5959

6060
PASS();
6161
}
6262

63-
TEST test_icon_size_clamp_too_big(void)
63+
TEST test_icon_size_clamp_too_big(int min_icon_size, int max_icon_size)
6464
{
6565
int w = 75, h = 150;
66-
bool resized = icon_size_clamp(&w, &h);
66+
bool resized = icon_size_clamp(&w, &h, min_icon_size, max_icon_size);
6767
ASSERT(resized);
6868
ASSERT_EQ(w, 50);
6969
ASSERT_EQ(h, 100);
7070

7171
PASS();
7272
}
7373

74-
TEST test_icon_size_clamp_too_small_then_too_big(void)
74+
TEST test_icon_size_clamp_too_small_then_too_big(int min_icon_size, int max_icon_size)
7575
{
7676
int w = 8, h = 80;
77-
bool resized = icon_size_clamp(&w, &h);
77+
bool resized = icon_size_clamp(&w, &h, min_icon_size, max_icon_size);
7878
ASSERT(resized);
7979
ASSERT_EQ(w, 10);
8080
ASSERT_EQ(h, 100);
@@ -90,30 +90,19 @@ SUITE(suite_icon)
9090
printf("Icon path: %s\n", icon_path);
9191
RUN_TEST(test_get_path_from_icon_null);
9292
RUN_TEST(test_get_path_from_icon_name_full);
93-
RUN_TEST(test_icon_size_clamp_not_necessary);
93+
RUN_TESTp(test_icon_size_clamp_not_necessary, 0, 100);
9494

95-
settings.min_icon_size = 16;
96-
settings.max_icon_size = 100;
95+
RUN_TESTp(test_icon_size_clamp_too_small, 16, 100);
96+
RUN_TESTp(test_icon_size_clamp_not_necessary, 16, 100);
97+
RUN_TESTp(test_icon_size_clamp_too_big, 16, 100);
98+
RUN_TESTp(test_icon_size_clamp_too_small_then_too_big, 16, 100);
9799

98-
RUN_TEST(test_icon_size_clamp_too_small);
99-
RUN_TEST(test_icon_size_clamp_not_necessary);
100-
RUN_TEST(test_icon_size_clamp_too_big);
101-
RUN_TEST(test_icon_size_clamp_too_small_then_too_big);
100+
RUN_TESTp(test_icon_size_clamp_too_small, 16, 0);
101+
RUN_TESTp(test_icon_size_clamp_not_necessary, 16, 0);
102102

103-
settings.min_icon_size = 16;
104-
settings.max_icon_size = 0;
103+
RUN_TESTp(test_icon_size_clamp_not_necessary, 0, 100);
104+
RUN_TESTp(test_icon_size_clamp_too_big, 0, 100);
105105

106-
RUN_TEST(test_icon_size_clamp_too_small);
107-
RUN_TEST(test_icon_size_clamp_not_necessary);
108-
109-
settings.min_icon_size = 0;
110-
settings.max_icon_size = 100;
111-
112-
RUN_TEST(test_icon_size_clamp_not_necessary);
113-
RUN_TEST(test_icon_size_clamp_too_big);
114-
115-
settings.min_icon_size = 0;
116-
settings.max_icon_size = 0;
117106
g_clear_pointer(&icon_path, g_free);
118107
}
119108
/* vim: set tabstop=8 shiftwidth=8 expandtab textwidth=0: */

test/notification.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,9 @@ static struct notification *notification_load_icon_with_scaling(int min_icon_siz
137137

138138
GVariant *rawIcon = notification_setup_raw_image(path);
139139

140-
settings.min_icon_size = min_icon_size;
141-
settings.max_icon_size = max_icon_size;
140+
n->min_icon_size = min_icon_size;
141+
n->max_icon_size = max_icon_size;
142142
notification_icon_replace_data(n, rawIcon);
143-
settings.min_icon_size = 0;
144-
settings.max_icon_size = 0;
145143

146144
g_variant_unref(rawIcon);
147145
g_free(path);

0 commit comments

Comments
 (0)