[nctree] refuse the standard plane

pull/2463/head
nick black 3 years ago committed by nick black
parent c2c61172f2
commit 49e9406576

@ -196,6 +196,10 @@ nctree* nctree_create(ncplane* n, const nctree_options* opts){
if(opts->flags){
logwarn("Passed invalid flags 0x%016" PRIx64 "\n", opts->flags);
}
if(n == notcurses_stdplane(ncplane_notcurses(n))){
logerror("can't use the standard plane\n");
goto error;
}
if(opts->nctreecb == NULL){
logerror("Can't use NULL callback\n");
goto error;

@ -16,16 +16,24 @@ TEST_CASE("Tree") {
REQUIRE(n_);
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
SUBCASE("RefuseStandardPlane") {
struct nctree_options opts{};
opts.nctreecb = treecb;
auto treen = nctree_create(n_, &opts);
REQUIRE(nullptr == treen);
CHECK(0 == notcurses_render(nc_));
}
// trivial tree with null items
SUBCASE("TreeNoItems") {
struct nctree_options opts = {
.items = nullptr,
.count = 0,
.nctreecb = treecb,
.indentcols = 0,
.flags = 0,
};
auto treen = nctree_create(n_, &opts);
struct ncplane_options nopts{};
nopts.rows = 7;
nopts.cols = 20;
auto p = ncplane_create(n_, &nopts);
REQUIRE(p);
struct nctree_options opts{};
opts.nctreecb = treecb;
auto treen = nctree_create(p, &opts);
REQUIRE(treen);
CHECK(0 == notcurses_render(nc_));
nctree_destroy(treen);
@ -520,6 +528,11 @@ TEST_CASE("Tree") {
};
SUBCASE("TraverseLongList") {
struct ncplane_options nopts{};
nopts.rows = 7;
nopts.cols = 20;
auto p = ncplane_create(n_, &nopts);
REQUIRE(p);
struct nctree_options topts = {
.items = &rads,
.count = 1,
@ -527,7 +540,7 @@ TEST_CASE("Tree") {
.indentcols = 2,
.flags = 0,
};
struct nctree* tree = nctree_create(notcurses_stdplane(nc_), &topts);
struct nctree* tree = nctree_create(p, &topts);
REQUIRE(nullptr != tree);
CHECK(0 == notcurses_render(nc_));
void* curry = nctree_focused(tree);

Loading…
Cancel
Save