From 0cee9bdb5cd504d52c390196bf7f4dd3a9c654bd Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 27 Aug 2020 12:22:35 -0400 Subject: [PATCH] ReelsGap unit test #901 --- include/notcurses/notcurses.h | 4 +- tests/reel.cpp | 115 ++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+), 1 deletion(-) diff --git a/include/notcurses/notcurses.h b/include/notcurses/notcurses.h index 536197dde..d065754cf 100644 --- a/include/notcurses/notcurses.h +++ b/include/notcurses/notcurses.h @@ -2495,7 +2495,9 @@ API int ncreel_tabletcount(const struct ncreel* pr); // -1 if the tablet cannot be found. API int ncreel_del(struct ncreel* pr, struct nctablet* t); -// Redraw the ncreel in its entirety. +// Redraw the ncreel in its entirety. The reel will be cleared, and tablets +// will be lain out, using the focused tablet as a fulcrum. Tablet drawing +// callbacks will be invoked for each visible tablet. API int ncreel_redraw(struct ncreel* pr); // Offer the input to the ncreel. If it's relevant, this function returns diff --git a/tests/reel.cpp b/tests/reel.cpp index 15ab02366..fad883693 100644 --- a/tests/reel.cpp +++ b/tests/reel.cpp @@ -421,6 +421,121 @@ TEST_CASE("Reels") { } CHECK(0 == ncreel_destroy(nr)); } + CHECK(0 == notcurses_stop(nc_)); +} + +int t1_tablet_cb(struct nctablet* t, bool drawfromtop){ + REQUIRE(nullptr != t); + CHECK(drawfromtop); + return 6; +} + +int t2_tablet_cb(struct nctablet* t, bool drawfromtop){ + REQUIRE(nullptr != t); + CHECK(drawfromtop); + return 24; +} + +int t3_tablet_cb(struct nctablet* t, bool drawfromtop){ + REQUIRE(nullptr != t); + CHECK(drawfromtop); + return 6; +} + +int t4_tablet_cb(struct nctablet* t, bool drawfromtop){ + REQUIRE(nullptr != t); + CHECK(drawfromtop); + return 17; +} + +int t5_tablet_cb(struct nctablet* t, bool drawfromtop){ + REQUIRE(nullptr != t); + CHECK(drawfromtop); + return 3; +} + +int t6_tablet_cb(struct nctablet* t, bool drawfromtop){ + REQUIRE(nullptr != t); + CHECK(drawfromtop); + return 3; +} + +TEST_CASE("ReelGaps") { + auto nc_ = testing_notcurses(); + if(!nc_){ + return; + } + struct ncplane* n_ = notcurses_stdplane(nc_); + REQUIRE(n_); + + // https://github.com/dankamongmen/notcurses/issues/901 + SUBCASE("ReelsGapping") { + ncreel_options r{}; + r.bordermask = 0xf; + channels_set_bg_alpha(&r.bgchannel, 3); + struct ncreel* nr = ncreel_create(n_, &r); + REQUIRE(nr); + CHECK_EQ(0, ncreel_redraw(nr)); + CHECK_EQ(0, notcurses_render(nc_)); + CHECK(ncreel_validate(nr)); + auto t1 = ncreel_add(nr, NULL, NULL, t1_tablet_cb, NULL); + CHECK(nullptr != t1); + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + auto t2 = ncreel_add(nr, NULL, NULL, t2_tablet_cb, NULL); + CHECK(nullptr != t2); + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + auto t3 = ncreel_add(nr, NULL, NULL, t3_tablet_cb, NULL); + CHECK(nullptr != t3); + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + auto t4 = ncreel_add(nr, NULL, NULL, t4_tablet_cb, NULL); + CHECK(nullptr != t4); + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + auto t5 = ncreel_add(nr, NULL, NULL, t5_tablet_cb, NULL); + CHECK(nullptr != t5); + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + auto t6 = ncreel_add(nr, NULL, NULL, t6_tablet_cb, NULL); + CHECK(nullptr != t6); + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + ncreel_next(nr); + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + ncreel_next(nr); + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + ncreel_next(nr); + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + ncreel_next(nr); + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + ncreel_next(nr); + } CHECK(0 == notcurses_stop(nc_)); }