2019-12-16 22:56:21 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <iostream>
|
|
|
|
|
2020-05-07 19:06:07 +00:00
|
|
|
TEST_CASE("ZAxis") {
|
2020-06-16 03:58:43 +00:00
|
|
|
auto nc_ = testing_notcurses();
|
2020-10-11 00:33:23 +00:00
|
|
|
REQUIRE(nullptr != nc_);
|
2019-12-27 22:20:20 +00:00
|
|
|
struct ncplane* n_ = notcurses_stdplane(nc_);
|
|
|
|
REQUIRE(n_);
|
2019-12-16 22:56:21 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("StdPlaneOnly") {
|
|
|
|
struct ncplane* top = notcurses_top(nc_);
|
|
|
|
CHECK(n_ == top);
|
|
|
|
CHECK(!ncplane_below(top));
|
2019-12-16 22:56:21 +00:00
|
|
|
}
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
// if you want to move the plane which is already top+bottom to either, go ahead
|
|
|
|
SUBCASE("StdPlaneOnanism") {
|
2020-05-20 19:32:27 +00:00
|
|
|
ncplane_move_top(n_);
|
2019-12-27 22:20:20 +00:00
|
|
|
struct ncplane* top = notcurses_top(nc_);
|
|
|
|
CHECK(n_ == top);
|
|
|
|
CHECK(!ncplane_below(top));
|
2020-05-20 19:32:27 +00:00
|
|
|
ncplane_move_bottom(n_);
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(!ncplane_below(n_));
|
|
|
|
}
|
2019-12-16 22:56:21 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
// you can't place a plane above or below itself, stdplane or otherwise
|
|
|
|
SUBCASE("NoMoveSelf") {
|
2020-11-14 22:23:22 +00:00
|
|
|
struct ncplane_options nopts = {
|
|
|
|
.y = 0,
|
2020-11-15 02:42:37 +00:00
|
|
|
.x = 0,
|
2020-11-14 22:23:22 +00:00
|
|
|
.rows = 2,
|
|
|
|
.cols = 2,
|
2020-11-24 01:31:39 +00:00
|
|
|
nullptr, nullptr, nullptr, 0,
|
2020-11-14 22:23:22 +00:00
|
|
|
};
|
|
|
|
struct ncplane* np = ncplane_create(n_, &nopts);
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(np);
|
|
|
|
CHECK(ncplane_move_below(n_, n_));
|
|
|
|
CHECK(ncplane_move_above(n_, n_));
|
|
|
|
CHECK(ncplane_move_below(np, np));
|
|
|
|
CHECK(ncplane_move_above(np, np));
|
|
|
|
}
|
2019-12-16 23:13:18 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
// new planes ought be on the top
|
|
|
|
SUBCASE("NewPlaneOnTop") {
|
2020-11-14 22:23:22 +00:00
|
|
|
struct ncplane_options nopts = {
|
|
|
|
.y = 0,
|
2020-11-15 02:42:37 +00:00
|
|
|
.x = 0,
|
2020-11-14 22:23:22 +00:00
|
|
|
.rows = 2,
|
|
|
|
.cols = 2,
|
2020-11-24 01:31:39 +00:00
|
|
|
nullptr, nullptr, nullptr, 0,
|
2020-11-14 22:23:22 +00:00
|
|
|
};
|
|
|
|
struct ncplane* np = ncplane_create(n_, &nopts);
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(np);
|
|
|
|
struct ncplane* top = notcurses_top(nc_);
|
|
|
|
CHECK(np == top);
|
|
|
|
CHECK(n_ == ncplane_below(top));
|
|
|
|
CHECK(!ncplane_below(n_));
|
|
|
|
}
|
2019-12-16 23:13:18 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
// "move" top plane to top. everything ought remain the same.
|
|
|
|
SUBCASE("TopToTop") {
|
2020-11-14 22:23:22 +00:00
|
|
|
struct ncplane_options nopts = {
|
|
|
|
.y = 0,
|
2020-11-15 02:42:37 +00:00
|
|
|
.x = 0,
|
2020-11-14 22:23:22 +00:00
|
|
|
.rows = 2,
|
|
|
|
.cols = 2,
|
2020-11-24 01:31:39 +00:00
|
|
|
nullptr, nullptr, nullptr, 0,
|
2020-11-14 22:23:22 +00:00
|
|
|
};
|
|
|
|
struct ncplane* np = ncplane_create(n_, &nopts);
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(np);
|
|
|
|
struct ncplane* top = notcurses_top(nc_);
|
|
|
|
CHECK(np == top);
|
|
|
|
CHECK(n_ == ncplane_below(top));
|
|
|
|
CHECK(!ncplane_below(n_));
|
2020-05-20 19:32:27 +00:00
|
|
|
ncplane_move_top(np);
|
2019-12-27 22:20:20 +00:00
|
|
|
// verify it
|
|
|
|
top = notcurses_top(nc_);
|
|
|
|
CHECK(np == top);
|
|
|
|
CHECK(n_ == ncplane_below(top));
|
|
|
|
CHECK(!ncplane_below(n_));
|
|
|
|
}
|
2019-12-16 23:13:18 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
// move top plane to bottom, and verify enumeration
|
|
|
|
SUBCASE("TopToBottom") {
|
2020-11-14 22:23:22 +00:00
|
|
|
struct ncplane_options nopts = {
|
|
|
|
.y = 0,
|
2020-11-15 02:42:37 +00:00
|
|
|
.x = 0,
|
2020-11-14 22:23:22 +00:00
|
|
|
.rows = 2,
|
|
|
|
.cols = 2,
|
2020-11-24 01:31:39 +00:00
|
|
|
nullptr, nullptr, nullptr, 0,
|
2020-11-14 22:23:22 +00:00
|
|
|
};
|
|
|
|
struct ncplane* np = ncplane_create(n_, &nopts);
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(np);
|
|
|
|
struct ncplane* top = notcurses_top(nc_);
|
|
|
|
CHECK(np == top);
|
|
|
|
CHECK(n_ == ncplane_below(top));
|
|
|
|
CHECK(!ncplane_below(n_));
|
2020-05-20 19:32:27 +00:00
|
|
|
ncplane_move_bottom(np);
|
2019-12-27 22:20:20 +00:00
|
|
|
top = notcurses_top(nc_);
|
|
|
|
CHECK(n_ == top);
|
|
|
|
CHECK(np == ncplane_below(top));
|
|
|
|
CHECK(!ncplane_below(np));
|
|
|
|
}
|
2019-12-16 23:13:18 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
// verify that moving one above another, with no other changes, is reflected at
|
|
|
|
// render time (requires explicit damage maintenance from move functionality).
|
|
|
|
SUBCASE("ZAxisDamage") {
|
2020-12-13 05:19:24 +00:00
|
|
|
nccell cat = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
nccell c = CELL_CHAR_INITIALIZER('x');
|
2020-09-17 19:34:28 +00:00
|
|
|
REQUIRE(!cell_set_fg_rgb8(&c, 0xff, 0, 0));
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(1 == ncplane_putc(n_, &c));
|
|
|
|
CHECK(!notcurses_render(nc_));
|
|
|
|
REQUIRE(!ncplane_cursor_move_yx(n_, 0, 0));
|
2020-04-18 04:09:14 +00:00
|
|
|
REQUIRE(1 == ncplane_at_cursor_cell(n_, &cat));
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(cell_simple_p(&cat));
|
2020-08-27 12:09:06 +00:00
|
|
|
REQUIRE(0 == strcmp("x", cell_extended_gcluster(n_, &c)));
|
2020-11-14 22:23:22 +00:00
|
|
|
struct ncplane_options nopts = {
|
|
|
|
.y = 0,
|
2020-11-15 02:42:37 +00:00
|
|
|
.x = 0,
|
2020-11-14 22:23:22 +00:00
|
|
|
.rows = 2,
|
|
|
|
.cols = 2,
|
2020-11-24 01:31:39 +00:00
|
|
|
nullptr, nullptr, nullptr, 0,
|
2020-11-14 22:23:22 +00:00
|
|
|
};
|
|
|
|
struct ncplane* n2 = ncplane_create(n_, &nopts);
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(1 == cell_load(n2, &c, "y"));
|
2020-09-17 19:34:28 +00:00
|
|
|
REQUIRE(!cell_set_fg_rgb8(&c, 0, 0xff, 0));
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(1 == ncplane_putc(n2, &c));
|
|
|
|
CHECK_EQ(0, notcurses_render(nc_));
|
|
|
|
REQUIRE(!ncplane_cursor_move_yx(n2, 0, 0));
|
2020-04-18 04:09:14 +00:00
|
|
|
REQUIRE(1 == ncplane_at_cursor_cell(n2, &cat));
|
2020-08-27 15:31:31 +00:00
|
|
|
REQUIRE(0 == strcmp("y", cell_extended_gcluster(n_, &c)));
|
2020-11-14 22:23:22 +00:00
|
|
|
struct ncplane* n3 = ncplane_create(n_, &nopts);
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(1 == cell_load(n3, &c, "z"));
|
2020-09-17 19:34:28 +00:00
|
|
|
REQUIRE(!cell_set_fg_rgb8(&c, 0, 0, 0xff));
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(1 == ncplane_putc(n3, &c));
|
|
|
|
CHECK(!notcurses_render(nc_));
|
|
|
|
REQUIRE(!ncplane_cursor_move_yx(n3, 0, 0));
|
2020-04-18 04:09:14 +00:00
|
|
|
REQUIRE(1 == ncplane_at_cursor_cell(n3, &cat));
|
2020-08-27 15:31:31 +00:00
|
|
|
REQUIRE(0 == strcmp("z", cell_extended_gcluster(n_, &c)));
|
2019-12-27 22:20:20 +00:00
|
|
|
// FIXME testing damage requires notcurses keeping a copy of the screen....
|
|
|
|
// FIXME move y atop z
|
|
|
|
// FIXME inspect
|
|
|
|
// FIXME move z atop y
|
|
|
|
// FIXME inspect
|
|
|
|
}
|
2019-12-17 04:07:55 +00:00
|
|
|
|
2020-07-13 05:21:41 +00:00
|
|
|
SUBCASE("DropPlanes") {
|
2020-11-14 22:23:22 +00:00
|
|
|
struct ncplane_options nopts = {
|
|
|
|
.y = 1,
|
2020-11-15 02:42:37 +00:00
|
|
|
.x = 1,
|
2020-11-14 22:23:22 +00:00
|
|
|
.rows = 1,
|
|
|
|
.cols = 1,
|
2020-11-24 01:31:39 +00:00
|
|
|
nullptr, nullptr, nullptr, 0,
|
2020-11-14 22:23:22 +00:00
|
|
|
};
|
|
|
|
auto p = ncplane_create(n_, &nopts);
|
2020-07-13 05:21:41 +00:00
|
|
|
REQUIRE(nullptr != p);
|
|
|
|
CHECK(notcurses_top(nc_) == p);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
notcurses_drop_planes(nc_);
|
|
|
|
CHECK(notcurses_top(nc_) != p);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
}
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(0 == notcurses_stop(nc_));
|
2019-12-17 04:07:55 +00:00
|
|
|
}
|