|
|
@ -23,6 +23,12 @@ TEST_CASE("SelectorTest") {
|
|
|
|
REQUIRE(nullptr != ncs);
|
|
|
|
REQUIRE(nullptr != ncs);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
CHECK(nullptr == ncselector_selected(ncs));
|
|
|
|
CHECK(nullptr == ncselector_selected(ncs));
|
|
|
|
|
|
|
|
struct ncplane* ncsp = ncselector_plane(ncs);
|
|
|
|
|
|
|
|
REQUIRE(nullptr != ncsp);
|
|
|
|
|
|
|
|
int dimy, dimx;
|
|
|
|
|
|
|
|
ncplane_dim_yx(ncsp, &dimy, &dimx);
|
|
|
|
|
|
|
|
CHECK(4 == dimy);
|
|
|
|
|
|
|
|
CHECK(5 == dimx);
|
|
|
|
ncselector_destroy(ncs, nullptr);
|
|
|
|
ncselector_destroy(ncs, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -32,6 +38,12 @@ TEST_CASE("SelectorTest") {
|
|
|
|
struct ncselector* ncs = ncselector_create(notcurses_stdplane(nc_), 0, 0, &opts);
|
|
|
|
struct ncselector* ncs = ncselector_create(notcurses_stdplane(nc_), 0, 0, &opts);
|
|
|
|
REQUIRE(nullptr != ncs);
|
|
|
|
REQUIRE(nullptr != ncs);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
|
|
|
struct ncplane* ncsp = ncselector_plane(ncs);
|
|
|
|
|
|
|
|
REQUIRE(nullptr != ncsp);
|
|
|
|
|
|
|
|
int dimy, dimx;
|
|
|
|
|
|
|
|
ncplane_dim_yx(ncsp, &dimy, &dimx);
|
|
|
|
|
|
|
|
CHECK(6 == dimy);
|
|
|
|
|
|
|
|
CHECK(strlen(opts.title) + 4 == dimx);
|
|
|
|
ncselector_destroy(ncs, nullptr);
|
|
|
|
ncselector_destroy(ncs, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -41,15 +53,27 @@ TEST_CASE("SelectorTest") {
|
|
|
|
struct ncselector* ncs = ncselector_create(notcurses_stdplane(nc_), 0, 0, &opts);
|
|
|
|
struct ncselector* ncs = ncselector_create(notcurses_stdplane(nc_), 0, 0, &opts);
|
|
|
|
REQUIRE(nullptr != ncs);
|
|
|
|
REQUIRE(nullptr != ncs);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
|
|
|
struct ncplane* ncsp = ncselector_plane(ncs);
|
|
|
|
|
|
|
|
REQUIRE(nullptr != ncsp);
|
|
|
|
|
|
|
|
int dimy, dimx;
|
|
|
|
|
|
|
|
ncplane_dim_yx(ncsp, &dimy, &dimx);
|
|
|
|
|
|
|
|
CHECK(4 == dimy);
|
|
|
|
|
|
|
|
CHECK(strlen(opts.secondary) + 2 == dimx);
|
|
|
|
ncselector_destroy(ncs, nullptr);
|
|
|
|
ncselector_destroy(ncs, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SUBCASE("FooterSelector") {
|
|
|
|
SUBCASE("FooterSelector") {
|
|
|
|
struct selector_options opts{};
|
|
|
|
struct selector_options opts{};
|
|
|
|
opts.secondary = strdup("i am a lone footer, little old footer");
|
|
|
|
opts.footer = strdup("i am a lone footer, little old footer");
|
|
|
|
struct ncselector* ncs = ncselector_create(notcurses_stdplane(nc_), 0, 0, &opts);
|
|
|
|
struct ncselector* ncs = ncselector_create(notcurses_stdplane(nc_), 0, 0, &opts);
|
|
|
|
REQUIRE(nullptr != ncs);
|
|
|
|
REQUIRE(nullptr != ncs);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
|
|
|
struct ncplane* ncsp = ncselector_plane(ncs);
|
|
|
|
|
|
|
|
REQUIRE(nullptr != ncsp);
|
|
|
|
|
|
|
|
int dimy, dimx;
|
|
|
|
|
|
|
|
ncplane_dim_yx(ncsp, &dimy, &dimx);
|
|
|
|
|
|
|
|
CHECK(4 == dimy);
|
|
|
|
|
|
|
|
CHECK(strlen(opts.footer) + 2 == dimx);
|
|
|
|
ncselector_destroy(ncs, nullptr);
|
|
|
|
ncselector_destroy(ncs, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -65,6 +89,12 @@ TEST_CASE("SelectorTest") {
|
|
|
|
struct ncselector* ncs = ncselector_create(notcurses_stdplane(nc_), 0, 0, &opts);
|
|
|
|
struct ncselector* ncs = ncselector_create(notcurses_stdplane(nc_), 0, 0, &opts);
|
|
|
|
REQUIRE(nullptr != ncs);
|
|
|
|
REQUIRE(nullptr != ncs);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
|
|
|
struct ncplane* ncsp = ncselector_plane(ncs);
|
|
|
|
|
|
|
|
REQUIRE(nullptr != ncsp);
|
|
|
|
|
|
|
|
int dimy, dimx;
|
|
|
|
|
|
|
|
ncplane_dim_yx(ncsp, &dimy, &dimx);
|
|
|
|
|
|
|
|
CHECK(7 == dimy);
|
|
|
|
|
|
|
|
CHECK(15 < dimx);
|
|
|
|
ncselector_destroy(ncs, nullptr);
|
|
|
|
ncselector_destroy(ncs, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -95,29 +125,79 @@ TEST_CASE("SelectorTest") {
|
|
|
|
opts.itemcount = sizeof(items) / sizeof(*items);
|
|
|
|
opts.itemcount = sizeof(items) / sizeof(*items);
|
|
|
|
struct ncselector* ncs = ncselector_create(notcurses_stdplane(nc_), 0, 0, &opts);
|
|
|
|
struct ncselector* ncs = ncselector_create(notcurses_stdplane(nc_), 0, 0, &opts);
|
|
|
|
REQUIRE(nullptr != ncs);
|
|
|
|
REQUIRE(nullptr != ncs);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
|
|
|
auto sel = ncselector_selected(ncs);
|
|
|
|
auto sel = ncselector_selected(ncs);
|
|
|
|
REQUIRE(nullptr != sel);
|
|
|
|
REQUIRE(nullptr != sel);
|
|
|
|
CHECK(0 == strcmp(sel, items[0].option));
|
|
|
|
CHECK(0 == strcmp(sel, items[0].option));
|
|
|
|
free(sel);
|
|
|
|
free(sel);
|
|
|
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
ncselector_nextitem(ncs, &sel);
|
|
|
|
ncselector_nextitem(ncs, &sel);
|
|
|
|
REQUIRE(nullptr != sel);
|
|
|
|
REQUIRE(nullptr != sel);
|
|
|
|
CHECK(0 == strcmp(sel, items[1].option));
|
|
|
|
CHECK(0 == strcmp(sel, items[1].option));
|
|
|
|
free(sel);
|
|
|
|
free(sel);
|
|
|
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
ncselector_previtem(ncs, &sel);
|
|
|
|
ncselector_previtem(ncs, &sel);
|
|
|
|
REQUIRE(nullptr != sel);
|
|
|
|
REQUIRE(nullptr != sel);
|
|
|
|
CHECK(0 == strcmp(sel, items[0].option));
|
|
|
|
CHECK(0 == strcmp(sel, items[0].option));
|
|
|
|
free(sel);
|
|
|
|
free(sel);
|
|
|
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
// wrap around from the top to bottom...
|
|
|
|
// wrap around from the top to bottom...
|
|
|
|
ncselector_previtem(ncs, &sel);
|
|
|
|
ncselector_previtem(ncs, &sel);
|
|
|
|
REQUIRE(nullptr != sel);
|
|
|
|
REQUIRE(nullptr != sel);
|
|
|
|
CHECK(0 == strcmp(sel, items[2].option));
|
|
|
|
CHECK(0 == strcmp(sel, items[2].option));
|
|
|
|
free(sel);
|
|
|
|
free(sel);
|
|
|
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
// ...and back to the top
|
|
|
|
// ...and back to the top
|
|
|
|
ncselector_nextitem(ncs, &sel);
|
|
|
|
ncselector_nextitem(ncs, &sel);
|
|
|
|
REQUIRE(nullptr != sel);
|
|
|
|
REQUIRE(nullptr != sel);
|
|
|
|
CHECK(0 == strcmp(sel, items[0].option));
|
|
|
|
CHECK(0 == strcmp(sel, items[0].option));
|
|
|
|
free(sel);
|
|
|
|
free(sel);
|
|
|
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
|
|
|
ncselector_destroy(ncs, nullptr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Provide three items, limited to 1 shown at a time
|
|
|
|
|
|
|
|
SUBCASE("ScrollingSelectorOne") {
|
|
|
|
|
|
|
|
selector_item items[] = {
|
|
|
|
|
|
|
|
{ strdup("op1"), strdup("this is option 1"), },
|
|
|
|
|
|
|
|
{ strdup("2ndop"), strdup("this is option #2"), },
|
|
|
|
|
|
|
|
{ strdup("tres"), strdup("option the third"), },
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct selector_options opts{};
|
|
|
|
|
|
|
|
opts.maxdisplay = 1;
|
|
|
|
|
|
|
|
opts.items = items;
|
|
|
|
|
|
|
|
opts.itemcount = sizeof(items) / sizeof(*items);
|
|
|
|
|
|
|
|
struct ncselector* ncs = ncselector_create(notcurses_stdplane(nc_), 0, 0, &opts);
|
|
|
|
|
|
|
|
REQUIRE(nullptr != ncs);
|
|
|
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
|
|
|
auto sel = ncselector_selected(ncs);
|
|
|
|
|
|
|
|
REQUIRE(nullptr != sel);
|
|
|
|
|
|
|
|
struct ncplane* ncsp = ncselector_plane(ncs);
|
|
|
|
|
|
|
|
REQUIRE(nullptr != ncsp);
|
|
|
|
|
|
|
|
int dimy, dimx;
|
|
|
|
|
|
|
|
ncplane_dim_yx(ncsp, &dimy, &dimx);
|
|
|
|
|
|
|
|
CHECK(5 == dimy);
|
|
|
|
|
|
|
|
ncselector_destroy(ncs, nullptr);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Provide three items, limited to 2 shown at a time
|
|
|
|
|
|
|
|
SUBCASE("ScrollingSelectorTwo") {
|
|
|
|
|
|
|
|
selector_item items[] = {
|
|
|
|
|
|
|
|
{ strdup("op1"), strdup("this is option 1"), },
|
|
|
|
|
|
|
|
{ strdup("2ndop"), strdup("this is option #2"), },
|
|
|
|
|
|
|
|
{ strdup("tres"), strdup("option the third"), },
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct selector_options opts{};
|
|
|
|
|
|
|
|
opts.maxdisplay = 2;
|
|
|
|
|
|
|
|
opts.items = items;
|
|
|
|
|
|
|
|
opts.itemcount = sizeof(items) / sizeof(*items);
|
|
|
|
|
|
|
|
struct ncselector* ncs = ncselector_create(notcurses_stdplane(nc_), 0, 0, &opts);
|
|
|
|
|
|
|
|
REQUIRE(nullptr != ncs);
|
|
|
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
|
|
|
struct ncplane* ncsp = ncselector_plane(ncs);
|
|
|
|
|
|
|
|
REQUIRE(nullptr != ncsp);
|
|
|
|
|
|
|
|
int dimy, dimx;
|
|
|
|
|
|
|
|
ncplane_dim_yx(ncsp, &dimy, &dimx);
|
|
|
|
|
|
|
|
CHECK(6 == dimy);
|
|
|
|
ncselector_destroy(ncs, nullptr);
|
|
|
|
ncselector_destroy(ncs, nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|