Skip to content

Commit

Permalink
gaps: tests inner, outer and smart gaps
Browse files Browse the repository at this point in the history
  • Loading branch information
kyechou committed Apr 19, 2024
1 parent 89302cd commit 2108e48
Show file tree
Hide file tree
Showing 4 changed files with 401 additions and 6 deletions.
48 changes: 45 additions & 3 deletions tst/tst-args_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void args_parse_cli__valid(void **state) {
"--ratio-master", "0.2",
"--count-wide-left", "8",
"--ratio-wide", "0.8",
"--smart-gaps", "off",
"--smart-gaps", "on",
"--inner-gaps", "6",
"--outer-gaps", "6",
"--border-width", "5",
Expand All @@ -61,7 +61,7 @@ void args_parse_cli__valid(void **state) {
assert_float_equal(cfg->ratio_master, 0.2, 0.001);
assert_int_equal(cfg->count_wide_left, 8);
assert_float_equal(cfg->ratio_wide, 0.8, 0.001);
assert_false(cfg->smart_gaps);
assert_true(cfg->smart_gaps);
assert_int_equal(cfg->inner_gaps, 6);
assert_int_equal(cfg->outer_gaps, 6);
assert_int_equal(cfg->border_width, 5);
Expand All @@ -78,7 +78,7 @@ void args_parse_cli__valid(void **state) {
"--ratio-master 0.2\n"
"--count-wide-left 8\n"
"--ratio-wide 0.8\n"
"--smart-gaps off\n"
"--smart-gaps on\n"
"--inner-gaps 6\n"
"--outer-gaps 6\n"
"--border-width 5\n"
Expand Down Expand Up @@ -181,6 +181,45 @@ void args_parse_cli__bad_ratio_wide(void **state) {
assert_log(ERROR, "invalid --ratio-wide '-1'\n\n");
}

void args_parse_cli__bad_smart_gaps(void **state) {
int argc = 3;
char *argv[] = { "dummy",
"--smart-gaps", "enabled",
};

expect_value(__wrap_usage, status, EXIT_FAILURE);

args_cli(argc, argv);

assert_log(ERROR, "invalid --smart-gaps 'enabled'\n\n");
}

void args_parse_cli__bad_inner_gaps(void **state) {
int argc = 3;
char *argv[] = { "dummy",
"--inner-gaps", "-1",
};

expect_value(__wrap_usage, status, EXIT_FAILURE);

args_cli(argc, argv);

assert_log(ERROR, "invalid --inner-gaps '-1'\n\n");
}

void args_parse_cli__bad_outer_gaps(void **state) {
int argc = 3;
char *argv[] = { "dummy",
"--outer-gaps", "-1",
};

expect_value(__wrap_usage, status, EXIT_FAILURE);

args_cli(argc, argv);

assert_log(ERROR, "invalid --outer-gaps '-1'\n\n");
}

void args_parse_cli__bad_border_width(void **state) {
int argc = 3;
char *argv[] = { "dummy",
Expand Down Expand Up @@ -269,6 +308,9 @@ int main(void) {
TEST(args_parse_cli__bad_ratio_master),
TEST(args_parse_cli__bad_count_wide_left),
TEST(args_parse_cli__bad_ratio_wide),
TEST(args_parse_cli__bad_smart_gaps),
TEST(args_parse_cli__bad_inner_gaps),
TEST(args_parse_cli__bad_outer_gaps),
TEST(args_parse_cli__bad_border_width),
TEST(args_parse_cli__bad_border_width_monocle),
TEST(args_parse_cli__bad_border_color_focused),
Expand Down
93 changes: 93 additions & 0 deletions tst/tst-arrange_master_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "asserts.h"

#include <cmocka.h>
#include <stdbool.h>

#include "enum.h"
#include "layout.h"
Expand Down Expand Up @@ -64,6 +65,42 @@ void arrange_master_stack__zero_stack(void **state) {
assert_box_equal(&stack, 0, 0, 0, 0);
}

void arrange_master_stack__zero_master_with_gaps(void **state) {
struct Box master, stack;

struct Demand demand = { .view_count = 1, .usable_width = 9, .usable_height = 5, };
struct Tag tag = { .layout_cur = LEFT, .ratio_master = 0.5,
.smart_gaps = false, .inner_gaps = 1, .outer_gaps = 1, };
struct Tag smart_tag = { .layout_cur = LEFT, .ratio_master = 0.5,
.smart_gaps = true, .inner_gaps = 1, .outer_gaps = 1, };

arrange_master_stack(&demand, &tag, 0, 1, &master, &stack);
assert_box_equal(&master, 0, 0, 0, 0);
assert_box_equal(&stack, 1, 1, 7, 3);

arrange_master_stack(&demand, &smart_tag, 0, 1, &master, &stack);
assert_box_equal(&master, 0, 0, 0, 0);
assert_box_equal(&stack, 0, 0, 9, 5);
}

void arrange_master_stack__zero_stack_with_gaps(void **state) {
struct Box master, stack;

struct Demand demand = { .view_count = 1, .usable_width = 9, .usable_height = 5, };
struct Tag tag = { .layout_cur = LEFT, .ratio_master = 0.5,
.smart_gaps = false, .inner_gaps = 1, .outer_gaps = 1, };
struct Tag smart_tag = { .layout_cur = LEFT, .ratio_master = 0.5,
.smart_gaps = true, .inner_gaps = 1, .outer_gaps = 1, };

arrange_master_stack(&demand, &tag, 1, 0, &master, &stack);
assert_box_equal(&master, 1, 1, 7, 3);
assert_box_equal(&stack, 0, 0, 0, 0);

arrange_master_stack(&demand, &smart_tag, 1, 0, &master, &stack);
assert_box_equal(&master, 0, 0, 9, 5);
assert_box_equal(&stack, 0, 0, 0, 0);
}

void arrange_master_stack__left(void **state) {
struct Box master, stack;

Expand All @@ -77,6 +114,18 @@ void arrange_master_stack__left(void **state) {
assert_box_equal(&stack, 4, 0, 5, 5);
}

void arrange_master_stack__left_with_gaps(void **state) {
struct Box master, stack;

struct Demand demand = { .usable_width = 9, .usable_height = 5, };
struct Tag tag = { .layout_cur = LEFT, .ratio_master = 0.4,
.inner_gaps = 1, .outer_gaps = 1, };

arrange_master_stack(&demand, &tag, 1, 1, &master, &stack);
assert_box_equal(&master, 1, 1, 2, 3);
assert_box_equal(&stack, 4, 1, 4, 3);
}

void arrange_master_stack__right(void **state) {
struct Box master, stack;

Expand All @@ -90,6 +139,18 @@ void arrange_master_stack__right(void **state) {
assert_box_equal(&stack, 0, 0, 5, 5);
}

void arrange_master_stack__right_with_gaps(void **state) {
struct Box master, stack;

struct Demand demand = { .usable_width = 9, .usable_height = 5, };
struct Tag tag = { .layout_cur = RIGHT, .ratio_master = 0.4,
.inner_gaps = 1, .outer_gaps = 1, };

arrange_master_stack(&demand, &tag, 1, 1, &master, &stack);
assert_box_equal(&master, 6, 1, 2, 3);
assert_box_equal(&stack, 1, 1, 4, 3);
}

void arrange_master_stack__top(void **state) {
struct Box master, stack;

Expand All @@ -103,6 +164,18 @@ void arrange_master_stack__top(void **state) {
assert_box_equal(&stack, 0, 2, 9, 3);
}

void arrange_master_stack__top_with_gaps(void **state) {
struct Box master, stack;

struct Demand demand = { .usable_width = 9, .usable_height = 5, };
struct Tag tag = { .layout_cur = TOP, .ratio_master = 0.3,
.inner_gaps = 1, .outer_gaps = 1, };

arrange_master_stack(&demand, &tag, 1, 1, &master, &stack);
assert_box_equal(&master, 1, 1, 7, 1);
assert_box_equal(&stack, 1, 3, 7, 1);
}

void arrange_master_stack__bottom(void **state) {
struct Box master, stack;

Expand All @@ -116,6 +189,18 @@ void arrange_master_stack__bottom(void **state) {
assert_box_equal(&stack, 0, 0, 9, 3);
}

void arrange_master_stack__bottom_with_gaps(void **state) {
struct Box master, stack;

struct Demand demand = { .usable_width = 9, .usable_height = 5, };
struct Tag tag = { .layout_cur = BOTTOM, .ratio_master = 0.3,
.inner_gaps = 1, .outer_gaps = 1, };

arrange_master_stack(&demand, &tag, 1, 1, &master, &stack);
assert_box_equal(&master, 1, 3, 7, 1);
assert_box_equal(&stack, 1, 1, 7, 1);
}

int main(void) {
const struct CMUnitTest tests[] = {
TEST(arrange_master_stack__zero),
Expand All @@ -126,6 +211,14 @@ int main(void) {
TEST(arrange_master_stack__right),
TEST(arrange_master_stack__top),
TEST(arrange_master_stack__bottom),

TEST(arrange_master_stack__zero_master_with_gaps),
TEST(arrange_master_stack__zero_stack_with_gaps),

TEST(arrange_master_stack__left_with_gaps),
TEST(arrange_master_stack__right_with_gaps),
TEST(arrange_master_stack__top_with_gaps),
TEST(arrange_master_stack__bottom_with_gaps),
};

return RUN(tests);
Expand Down
Loading

0 comments on commit 2108e48

Please sign in to comment.