From 5b6868abee7bc9815ec1e73fb5e5ed4ace755391 Mon Sep 17 00:00:00 2001 From: nick black Date: Fri, 28 Aug 2020 12:10:14 -0400 Subject: [PATCH] finish out ReelGaps unit test --- tests/main.h | 1 + tests/reel.cpp | 149 +++++--------------------------------------- tests/reelgaps.cpp | 151 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 133 deletions(-) create mode 100644 tests/reelgaps.cpp diff --git a/tests/main.h b/tests/main.h index 769083f30..fb3fc62d2 100644 --- a/tests/main.h +++ b/tests/main.h @@ -12,5 +12,6 @@ auto find_data(const char* datum) -> char*; auto enforce_utf8() -> bool; auto testing_notcurses() -> struct notcurses*; +auto ncreel_validate(const ncreel* n) -> bool; #endif diff --git a/tests/reel.cpp b/tests/reel.cpp index fad883693..71ef83571 100644 --- a/tests/reel.cpp +++ b/tests/reel.cpp @@ -1,23 +1,7 @@ #include "main.h" #include -auto panelcb(struct nctablet* t, bool toptobottom) -> int { - CHECK(nctablet_ncplane(t)); - CHECK(!nctablet_userptr(t)); - CHECK(toptobottom); - // FIXME verify geometry is as expected - return 0; -} - -auto cbfxn(struct nctablet* t, bool toptobottom) -> int { - (void)toptobottom; - int* userptr = static_cast(nctablet_userptr(t)); - ++*userptr; - return 4; -} - -// debugging -bool ncreel_validate(const ncreel* n){ +auto ncreel_validate(const ncreel* n) -> bool { if(n->tablets == NULL){ return true; } @@ -66,6 +50,21 @@ bool ncreel_validate(const ncreel* n){ return true; } +auto panelcb(struct nctablet* t, bool toptobottom) -> int { + CHECK(nctablet_ncplane(t)); + CHECK(!nctablet_userptr(t)); + CHECK(toptobottom); + // FIXME verify geometry is as expected + return 0; +} + +auto cbfxn(struct nctablet* t, bool toptobottom) -> int { + (void)toptobottom; + int* userptr = static_cast(nctablet_userptr(t)); + ++*userptr; + return 4; +} + TEST_CASE("Reels") { auto nc_ = testing_notcurses(); if(!nc_){ @@ -423,119 +422,3 @@ TEST_CASE("Reels") { } 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_)); -} diff --git a/tests/reelgaps.cpp b/tests/reelgaps.cpp new file mode 100644 index 000000000..95b46c423 --- /dev/null +++ b/tests/reelgaps.cpp @@ -0,0 +1,151 @@ +#include "main.h" + +// ahci-1 +int t1_tablet_cb(struct nctablet* t, bool drawfromtop){ + REQUIRE(nullptr != t); + (void)drawfromtop; + return 6; +} + +// mpt3sas-0 +int t2_tablet_cb(struct nctablet* t, bool drawfromtop){ + REQUIRE(nullptr != t); + (void)drawfromtop; + return 24; +} + +// ahci-0 +int t3_tablet_cb(struct nctablet* t, bool drawfromtop){ + REQUIRE(nullptr != t); + (void)drawfromtop; + return 6; +} + +// virtual +int t4_tablet_cb(struct nctablet* t, bool drawfromtop){ + REQUIRE(nullptr != t); + (void)drawfromtop; + return 17; +} + +// nvme-0 +int t5_tablet_cb(struct nctablet* t, bool drawfromtop){ + REQUIRE(nullptr != t); + (void)drawfromtop; + return 3; +} + +// nvme-1 +int t6_tablet_cb(struct nctablet* t, bool drawfromtop){ + REQUIRE(nullptr != t); + (void)drawfromtop; + return 3; +} + +// nvme-2 +int t7_tablet_cb(struct nctablet* t, bool drawfromtop){ + REQUIRE(nullptr != t); + (void)drawfromtop; + return 3; +} + +// xhci_pci-0 +int t8_tablet_cb(struct nctablet* t, bool drawfromtop){ + REQUIRE(nullptr != t); + (void)drawfromtop; + return 5; +} + +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); // move to t2 + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + ncreel_next(nr); // move to t3 + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + ncreel_next(nr); // move to t4 + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + ncreel_next(nr); // move to t5 + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + ncreel_next(nr); // move to t6 + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + ncreel_next(nr); // move to t7 + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + ncreel_next(nr); // move to t8 + ncreel_redraw(nr); + CHECK(ncreel_validate(nr)); + CHECK_EQ(0, notcurses_render(nc_)); +sleep(1); + } + + CHECK(0 == notcurses_stop(nc_)); +}