1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
|
#include "../src/input.c"
#include "queues.h"
#include "greatest.h"
#include "helpers.h"
#include "../src/utils.h"
TEST test_get_notification_clickable_height_first(void)
{
bool orginal_gap_size = settings.gap_size;
settings.gap_size = 0;
struct notification *n = test_notification("test", 10);
n->displayed_height = 12;
int expected_size = n->displayed_height + settings.frame_width;
expected_size += (settings.separator_height / 2.0);
int result = get_notification_clickable_height(n, true, false);
ASSERT(result == expected_size);
settings.gap_size = orginal_gap_size;
notification_unref(n);
PASS();
}
TEST test_get_notification_clickable_height_middle(void)
{
bool orginal_gap_size = settings.gap_size;
settings.gap_size = 0;
struct notification *n = test_notification("test", 10);
n->displayed_height = 12;
int expected_size = n->displayed_height + settings.separator_height;
int result = get_notification_clickable_height(n, false, false);
ASSERT(result == expected_size);
settings.gap_size = orginal_gap_size;
notification_unref(n);
PASS();
}
TEST test_get_notification_clickable_height_last(void)
{
bool orginal_gap_size = settings.gap_size;
settings.gap_size = 0;
struct notification *n = test_notification("test", 10);
n->displayed_height = 12;
int expected_size = n->displayed_height + settings.frame_width;
expected_size += (settings.separator_height / 2.0);
int result = get_notification_clickable_height(n, false, true);
ASSERT(result == expected_size);
settings.gap_size = orginal_gap_size;
notification_unref(n);
PASS();
}
TEST test_get_notification_clickable_height_gaps(void)
{
bool orginal_gap_size = settings.gap_size;
settings.gap_size = 7;
struct notification *n = test_notification("test", 10);
n->displayed_height = 12;
int expected_size = n->displayed_height + (settings.frame_width * 2);
int result_first = get_notification_clickable_height(n, true, false);
ASSERT(result_first == expected_size);
int result_middle = get_notification_clickable_height(n, false, false);
ASSERT(result_middle == expected_size);
int result_last = get_notification_clickable_height(n, false, true);
ASSERT(result_last == expected_size);
settings.gap_size = orginal_gap_size;
notification_unref(n);
PASS();
}
TEST test_notification_at(void)
{
int total_notifications = 3;
GSList *notifications = get_dummy_notifications(total_notifications);
queues_init();
int display_height = 12;
struct notification *n;
for (GSList *iter = notifications; iter; iter = iter->next) {
n = iter->data;
n->displayed_height = display_height;
queues_notification_insert(n);
}
queues_update(STATUS_NORMAL, time_monotonic_now());
struct notification *top_notification = g_slist_nth_data(notifications, 0);
int top_notification_height = get_notification_clickable_height(top_notification, true, false);
struct notification *middle_notification = g_slist_nth_data(notifications, 1);
int middle_notification_height = get_notification_clickable_height(middle_notification, false, false);
struct notification *bottom_notification = g_slist_nth_data(notifications, 2);
int bottom_notification_height = get_notification_clickable_height(bottom_notification, false, true);
struct notification *result;
int top_y_coord;
top_y_coord = 0;
result = get_notification_at(top_y_coord);
ASSERT(result != NULL);
ASSERT(result == top_notification);
top_y_coord = top_notification_height - 1;
result = get_notification_at(top_y_coord);
ASSERT(result != NULL);
ASSERT(result == top_notification);
int middle_y_coord;
middle_y_coord = top_notification_height;
result = get_notification_at(middle_y_coord);
ASSERT(result != NULL);
ASSERT(result == middle_notification);
middle_y_coord = top_notification_height;
result = get_notification_at(middle_y_coord);
ASSERT(result != NULL);
ASSERT(result == middle_notification);
int bottom_y_coord;
bottom_y_coord = top_notification_height + middle_notification_height;
result = get_notification_at(bottom_y_coord);
ASSERT(result != NULL);
ASSERT(result == bottom_notification);
bottom_y_coord = top_notification_height + middle_notification_height + bottom_notification_height - 1;
result = get_notification_at(bottom_y_coord);
ASSERT(result != NULL);
ASSERT(result == bottom_notification);
queues_teardown();
g_slist_free(notifications);
PASS();
}
SUITE(suite_input)
{
SHUFFLE_TESTS(time(NULL), {
RUN_TEST(test_get_notification_clickable_height_first);
RUN_TEST(test_get_notification_clickable_height_middle);
RUN_TEST(test_get_notification_clickable_height_last);
RUN_TEST(test_get_notification_clickable_height_gaps);
RUN_TEST(test_notification_at);
});
}
|