Skip to content

Commit

Permalink
#164 print_head tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-courtis committed Nov 10, 2024
1 parent 709094a commit f7a5920
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,15 @@ void print_head_current(enum LogThreshold t, struct Head *head) {
}

print_mode(t, head->current.mode);
log_(t, " VRR: %s", head->current.adaptive_sync == ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED ? "on" : "off");

if (!head->current.enabled) {
log_(t, " (disabled)");
if (head->current.enabled) {
log_(t, " VRR: %s", head->current.adaptive_sync == ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED ? "on" : "off");
} else {
log_(t, " (disabled)");
}

if (lid_is_closed(head->name)) {
log_(t, " (lid closed)");
log_(t, " (lid closed)");
}
}

Expand Down Expand Up @@ -373,10 +374,10 @@ void print_head_desired(enum LogThreshold t, struct Head *head) {
}
}
if (!head->current.enabled) {
log_(t, " (enabled)");
log_(t, " (enabled)");
}
} else {
log_(t, " (disabled)");
log_(t, " (disabled)");
}
}

Expand All @@ -389,7 +390,7 @@ void print_head(enum LogThreshold t, enum InfoEvent event, struct Head *head) {
switch (event) {
case ARRIVED:
case NONE:
log_(t, "\n%s%s:", head->name, event == ARRIVED ? " Arrived" : "");
log_(t, "\n%s%s:", head->name ? head->name : "???", event == ARRIVED ? " Arrived" : "");
log_(t, " info:");
if (head->name)
log_(t, " name: '%s'", head->name);
Expand Down
2 changes: 1 addition & 1 deletion tst/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ OBJS = tst/util.o \
WRAPS_COMMON = -Wl,$\
--wrap=log_set_threshold,$\
--wrap=log_,--wrap=log_error,--wrap=log_warn,--wrap=log_info,--wrap=log_debug,--wrap=log_error_errno,$\
--wrap=print_head,--wrap=print_mode,$\
--wrap=spawn_sh_cmd,--wrap=wd_exit,--wrap=wd_exit_message

tst-head: WRAPS=,$\
Expand All @@ -24,6 +23,7 @@ tst-head: WRAPS=,$\
tst-layout: WRAPS=,$\
--wrap=lid_is_closed,$\
--wrap=head_find_mode,$\
--wrap=print_head,--wrap=print_mode,$\
--wrap=head_auto_scale

tst-cfg-file: WRAPS=,$\
Expand Down
23 changes: 23 additions & 0 deletions tst/info/print-head-arrived-all.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

name Arrived:
info:
name: 'name'
make: 'make'
model: 'model'
serial: 'serial_number'
desc: 'description'
width: 1mm
height: 2mm
dpi: 2540.00 @ 100x200
mode: 700 x 800 @ 90 Hz 90,000 mHz
mode: 400 x 500 @ 60 Hz 60,000 mHz
mode: 100 x 200 @ 30 Hz 30,000 mHz (preferred)
failed:
mode: 700x800@90Hz (90,000mHz)
current:
scale: 2.000 (26.458)
position: 700,800
transform: 180
mode: 100x200@30Hz (30,000mHz) (preferred)
VRR: off

9 changes: 9 additions & 0 deletions tst/info/print-head-arrived-min.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

??? Arrived:
info:
width: (not specified)
height: (not specified)
current:
(no mode)
(disabled)

5 changes: 5 additions & 0 deletions tst/info/print-head-departed.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

name Departed:
name: 'name'
desc: 'description'

72 changes: 72 additions & 0 deletions tst/tst-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "info.h"

struct Head *head = NULL;

int before_all(void **state) {
return 0;
}
Expand All @@ -23,10 +25,49 @@ int after_all(void **state) {
}

int before_each(void **state) {
head = calloc(1, sizeof(struct Head));

struct Mode *mode_cur = mode_init(head, NULL, 100, 200, 30000, true);
struct Mode *mode_des = mode_init(head, NULL, 400, 500, 60000, false);
struct Mode *mode_failed = mode_init(head, NULL, 700, 800, 90000, false);

slist_append(&head->modes, mode_cur);
slist_append(&head->modes, mode_des);
slist_append(&head->modes, mode_failed);
slist_append(&head->modes_failed, mode_failed);

head->name = strdup("name");
head->description = strdup("description");
head->width_mm = 1;
head->height_mm = 2;
head->make = strdup("make");
head->model = strdup("model");
head->serial_number = strdup("serial_number");

head->current.mode = mode_cur;
head->current.scale = 512;
head->current.enabled = true;
head->current.x = 700;
head->current.y = 800;
head->current.transform = WL_OUTPUT_TRANSFORM_180;
head->current.adaptive_sync = ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_DISABLED;

head->desired.mode = mode_des;
head->desired.scale = 1024;
head->desired.enabled = false;
head->desired.x = 900;
head->desired.y = 1000;
head->desired.transform = WL_OUTPUT_TRANSFORM_90;
head->desired.adaptive_sync = ZWLR_OUTPUT_HEAD_V1_ADAPTIVE_SYNC_STATE_ENABLED;

return 0;
}

int after_each(void **state) {
head_free(head);

head = NULL;

assert_logs_empty();

return 0;
Expand Down Expand Up @@ -78,10 +119,41 @@ void print_cfg_commands__ok(void **state) {
free(expected_log);
}

void print_head_arrived__all(void **state) {
print_head(INFO, ARRIVED, head);

char *expected_log = read_file("tst/info/print-head-arrived-all.log");
assert_log(INFO, expected_log);
free(expected_log);
}

void print_head_arrived__min(void **state) {
head_free(head);
head = calloc(1, sizeof(struct Head));

print_head(INFO, ARRIVED, head);

char *expected_log = read_file("tst/info/print-head-arrived-min.log");
assert_log(INFO, expected_log);
free(expected_log);
}

void print_head_departed(void **state) {
print_head(INFO, DEPARTED, head);

char *expected_log = read_file("tst/info/print-head-departed.log");
assert_log(INFO, expected_log);
free(expected_log);
}

int main(void) {
const struct CMUnitTest tests[] = {
TEST(print_cfg_commands__empty),
TEST(print_cfg_commands__ok),

TEST(print_head_arrived__all),
TEST(print_head_arrived__min),
TEST(print_head_departed),
};

return RUN(tests);
Expand Down

0 comments on commit f7a5920

Please sign in to comment.