2019-12-01 03:53:24 +00:00
|
|
|
|
#include <cstdlib>
|
2019-11-21 11:55:05 +00:00
|
|
|
|
#include "main.h"
|
2020-02-18 17:36:16 +00:00
|
|
|
|
#include "internal.h"
|
2019-11-21 11:55:05 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
void BoxPermutationsRounded(struct notcurses* nc, struct ncplane* n, unsigned edges) {
|
|
|
|
|
int dimx, dimy;
|
|
|
|
|
ncplane_dim_yx(n, &dimy, &dimx);
|
|
|
|
|
REQUIRE(2 < dimy);
|
|
|
|
|
REQUIRE(47 < dimx);
|
|
|
|
|
// we'll try all 16 boxmasks in 3x3 configurations in a 1x16 map
|
|
|
|
|
unsigned boxmask = edges << NCBOXCORNER_SHIFT;
|
|
|
|
|
for(auto x0 = 0 ; x0 < 16 ; ++x0){
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n, 0, x0 * 3));
|
|
|
|
|
CHECK(0 == ncplane_rounded_box_sized(n, 0, 0, 3, 3, boxmask));
|
|
|
|
|
++boxmask;
|
2019-12-14 00:40:22 +00:00
|
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK(0 == notcurses_render(nc));
|
2019-11-21 13:19:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
TEST_CASE("NCPlane") {
|
2020-05-11 08:57:20 +00:00
|
|
|
|
if(!enforce_utf8()){
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-06-16 03:58:43 +00:00
|
|
|
|
auto nc_ = testing_notcurses();
|
2020-05-17 11:57:21 +00:00
|
|
|
|
if(!nc_){
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
|
struct ncplane* n_ = notcurses_stdplane(nc_);
|
|
|
|
|
REQUIRE(n_);
|
|
|
|
|
|
|
|
|
|
// Starting position ought be 0, 0 (the origin)
|
|
|
|
|
SUBCASE("StdPlanePosition") {
|
|
|
|
|
int x, y;
|
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
|
|
|
|
CHECK(0 == x);
|
|
|
|
|
CHECK(0 == y);
|
|
|
|
|
}
|
2019-11-21 12:46:19 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
// Dimensions of the standard plane ought be the same as those of the context
|
|
|
|
|
SUBCASE("StdPlaneDimensions") {
|
|
|
|
|
int cols, rows;
|
|
|
|
|
notcurses_term_dim_yx(nc_, &rows, &cols);
|
|
|
|
|
int ncols, nrows;
|
|
|
|
|
ncplane_dim_yx(n_, &nrows, &ncols);
|
|
|
|
|
CHECK(rows == nrows);
|
|
|
|
|
CHECK(cols == ncols);
|
|
|
|
|
}
|
2019-11-21 13:19:14 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
// Verify that we can move to all four coordinates of the standard plane
|
|
|
|
|
SUBCASE("MoveStdPlaneDimensions") {
|
|
|
|
|
int cols, rows;
|
|
|
|
|
notcurses_term_dim_yx(nc_, &rows, &cols);
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
|
|
|
|
int x, y;
|
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
|
|
|
|
CHECK(y == 0);
|
|
|
|
|
CHECK(x == 0);
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, rows - 1, 0));
|
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
|
|
|
|
CHECK(y == rows - 1);
|
|
|
|
|
CHECK(x == 0);
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, rows - 1, cols - 1));
|
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
|
|
|
|
CHECK(y == rows - 1);
|
|
|
|
|
CHECK(x == cols - 1);
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, 0, cols - 1));
|
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
|
|
|
|
CHECK(y == 0);
|
|
|
|
|
CHECK(x == cols - 1);
|
|
|
|
|
}
|
2019-11-23 17:52:09 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
// Verify that we can move to all four coordinates of the standard plane
|
|
|
|
|
SUBCASE("MoveBeyondPlaneFails") {
|
|
|
|
|
int cols, rows;
|
|
|
|
|
notcurses_term_dim_yx(nc_, &rows, &cols);
|
|
|
|
|
CHECK(0 > ncplane_cursor_move_yx(n_, -2, 0));
|
|
|
|
|
CHECK(0 > ncplane_cursor_move_yx(n_, -2, -2));
|
|
|
|
|
CHECK(0 > ncplane_cursor_move_yx(n_, 0, -2));
|
|
|
|
|
CHECK(0 > ncplane_cursor_move_yx(n_, rows - 1, -2));
|
|
|
|
|
CHECK(0 > ncplane_cursor_move_yx(n_, rows, 0));
|
|
|
|
|
CHECK(0 > ncplane_cursor_move_yx(n_, rows + 1, 0));
|
|
|
|
|
CHECK(0 > ncplane_cursor_move_yx(n_, rows, cols));
|
|
|
|
|
CHECK(0 > ncplane_cursor_move_yx(n_, -2, cols - 1));
|
|
|
|
|
CHECK(0 > ncplane_cursor_move_yx(n_, 0, cols));
|
|
|
|
|
CHECK(0 > ncplane_cursor_move_yx(n_, 0, cols + 1));
|
|
|
|
|
}
|
2019-12-08 04:00:12 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("SetPlaneRGB") {
|
|
|
|
|
CHECK(0 == ncplane_set_fg_rgb(n_, 0, 0, 0));
|
|
|
|
|
CHECK(0 == ncplane_set_fg_rgb(n_, 255, 255, 255));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-12-08 01:37:25 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("RejectBadRGB") {
|
|
|
|
|
CHECK(0 > ncplane_set_fg_rgb(n_, -1, 0, 0));
|
|
|
|
|
CHECK(0 > ncplane_set_fg_rgb(n_, 0, -1, 0));
|
|
|
|
|
CHECK(0 > ncplane_set_fg_rgb(n_, 0, 0, -1));
|
|
|
|
|
CHECK(0 > ncplane_set_fg_rgb(n_, -1, -1, -1));
|
|
|
|
|
CHECK(0 > ncplane_set_fg_rgb(n_, 256, 255, 255));
|
|
|
|
|
CHECK(0 > ncplane_set_fg_rgb(n_, 255, 256, 255));
|
|
|
|
|
CHECK(0 > ncplane_set_fg_rgb(n_, 255, 255, 256));
|
|
|
|
|
CHECK(0 > ncplane_set_fg_rgb(n_, 256, 256, 256));
|
|
|
|
|
}
|
2019-11-24 21:41:43 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
// Verify we can emit a multibyte character, and it advances the cursor
|
|
|
|
|
SUBCASE("EmitCell") {
|
|
|
|
|
const char cchar[] = "✔";
|
|
|
|
|
cell c{};
|
|
|
|
|
CHECK(strlen(cchar) == cell_load(n_, &c, cchar));
|
|
|
|
|
CHECK(0 < ncplane_putc(n_, &c));
|
|
|
|
|
int x, y;
|
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
|
|
|
|
CHECK(0 == y);
|
|
|
|
|
CHECK(1 == x);
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-12-12 21:14:01 +00:00
|
|
|
|
|
2020-01-01 11:33:45 +00:00
|
|
|
|
// Verify we can emit a wchar_t, and it advances the cursor
|
|
|
|
|
SUBCASE("EmitWcharT") {
|
2019-12-27 22:20:20 +00:00
|
|
|
|
const wchar_t* w = L"✔";
|
|
|
|
|
int sbytes = 0;
|
2020-01-04 07:37:55 +00:00
|
|
|
|
CHECK(0 < ncplane_putwegc(n_, w, &sbytes));
|
2019-12-27 22:20:20 +00:00
|
|
|
|
int x, y;
|
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
|
|
|
|
CHECK(0 == y);
|
|
|
|
|
CHECK(1 == x);
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-11-24 21:57:53 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
// Verify we can emit a multibyte string, and it advances the cursor
|
|
|
|
|
SUBCASE("EmitStr") {
|
|
|
|
|
const char s[] = "Σιβυλλα τι θελεις; respondebat illa: αποθανειν θελω.";
|
|
|
|
|
int wrote = ncplane_putstr(n_, s);
|
|
|
|
|
CHECK(strlen(s) == wrote);
|
|
|
|
|
int x, y;
|
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
|
|
|
|
CHECK(0 == y);
|
|
|
|
|
CHECK(1 <= x); // FIXME tighten in on this
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-11-24 22:06:57 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
// Verify we can emit a wide string, and it advances the cursor
|
|
|
|
|
SUBCASE("EmitWideStr") {
|
|
|
|
|
const wchar_t s[] = L"Σιβυλλα τι θελεις; respondebat illa: αποθανειν θελω.";
|
|
|
|
|
int wrote = ncplane_putwstr(n_, s);
|
|
|
|
|
CHECK(0 < wrote);
|
|
|
|
|
int x, y;
|
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
|
|
|
|
CHECK(0 == y);
|
|
|
|
|
CHECK(1 <= x); // FIXME tighten in on this
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-11-26 00:51:11 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("EmitEmojiStr") {
|
|
|
|
|
const wchar_t e[] =
|
|
|
|
|
L"🍺🚬🌿💉💊🔫💣🤜🤛🐌🐎🐑🐒🐔🐗🐘🐙🐚"
|
|
|
|
|
"🐛🐜🐝🐞🐟🐠🐡🐢🐣🐤🐥🐦🐧🐨🐩🐫🐬🐭🐮"
|
|
|
|
|
"🐯🐰🐱🐲🐳🐴🐵🐶🐷🐹🐺🐻🐼🦉🐊🦕🦖🐬🐙🦠🦀";
|
2020-04-06 03:06:21 +00:00
|
|
|
|
CHECK(!ncplane_set_scrolling(n_, true));
|
2019-12-27 22:20:20 +00:00
|
|
|
|
int wrote = ncplane_putwstr(n_, e);
|
|
|
|
|
CHECK(0 < wrote);
|
|
|
|
|
int x, y;
|
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
|
|
|
|
CHECK_LE(0, y);
|
|
|
|
|
CHECK(1 <= x); // FIXME tighten in on this
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-12-14 00:40:22 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("HorizontalLines") {
|
|
|
|
|
int x, y;
|
|
|
|
|
ncplane_dim_yx(n_, &y, &x);
|
|
|
|
|
REQUIRE(0 < y);
|
|
|
|
|
REQUIRE(0 < x);
|
|
|
|
|
cell c{};
|
|
|
|
|
cell_load(n_, &c, "-");
|
|
|
|
|
for(int yidx = 0 ; yidx < y ; ++yidx){
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, yidx, 1));
|
|
|
|
|
CHECK(x - 2 == ncplane_hline(n_, &c, x - 2));
|
|
|
|
|
int posx, posy;
|
|
|
|
|
ncplane_cursor_yx(n_, &posy, &posx);
|
|
|
|
|
CHECK(yidx == posy);
|
|
|
|
|
CHECK(x - 1 == posx);
|
|
|
|
|
}
|
|
|
|
|
cell_release(n_, &c);
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-12-14 00:40:22 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("VerticalLines") {
|
|
|
|
|
int x, y;
|
|
|
|
|
ncplane_dim_yx(n_, &y, &x);
|
|
|
|
|
REQUIRE(0 < y);
|
|
|
|
|
REQUIRE(0 < x);
|
|
|
|
|
cell c{};
|
|
|
|
|
cell_load(n_, &c, "|");
|
|
|
|
|
for(int xidx = 1 ; xidx < x - 1 ; ++xidx){
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, 1, xidx));
|
|
|
|
|
CHECK(y - 2 == ncplane_vline(n_, &c, y - 2));
|
|
|
|
|
int posx, posy;
|
|
|
|
|
ncplane_cursor_yx(n_, &posy, &posx);
|
|
|
|
|
CHECK(y - 2 == posy);
|
|
|
|
|
CHECK(xidx == posx - 1);
|
|
|
|
|
}
|
|
|
|
|
cell_release(n_, &c);
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-12-14 00:40:22 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
// reject attempts to draw boxes beyond the boundaries of the ncplane
|
|
|
|
|
SUBCASE("BadlyPlacedBoxen") {
|
|
|
|
|
int x, y;
|
|
|
|
|
ncplane_dim_yx(n_, &y, &x);
|
|
|
|
|
REQUIRE(2 < y);
|
|
|
|
|
REQUIRE(2 < x);
|
|
|
|
|
cell ul{}, ll{}, lr{}, ur{}, hl{}, vl{};
|
|
|
|
|
REQUIRE(0 == cells_rounded_box(n_, 0, 0, &ul, &ur, &ll, &lr, &hl, &vl));
|
|
|
|
|
CHECK_GT(0, ncplane_box(n_, &ul, &ur, &ll, &lr, &hl, &vl, y + 1, x + 1, 0));
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, 1, 0));
|
|
|
|
|
CHECK_GT(0, ncplane_box(n_, &ul, &ur, &ll, &lr, &hl, &vl, y, x, 0));
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, 0, 1));
|
|
|
|
|
CHECK_GT(0, ncplane_box(n_, &ul, &ur, &ll, &lr, &hl, &vl, y, x, 0));
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, y - 1, x - 1));
|
|
|
|
|
CHECK_GT(0, ncplane_box(n_, &ul, &ur, &ll, &lr, &hl, &vl, 2, 2, 0));
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, y - 2, x - 1));
|
|
|
|
|
CHECK_GT(0, ncplane_box(n_, &ul, &ur, &ll, &lr, &hl, &vl, 2, 2, 0));
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, y - 1, x - 2));
|
|
|
|
|
CHECK_GT(0, ncplane_box(n_, &ul, &ur, &ll, &lr, &hl, &vl, 2, 2, 0));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-12-10 11:02:49 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("BoxPermutationsRoundedZeroEdges") {
|
|
|
|
|
BoxPermutationsRounded(nc_, n_, 0);
|
2019-12-04 08:42:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("BoxPermutationsRoundedOneEdges") {
|
|
|
|
|
BoxPermutationsRounded(nc_, n_, 1);
|
|
|
|
|
}
|
2019-11-24 21:46:58 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("BoxPermutationsRoundedTwoEdges") {
|
|
|
|
|
BoxPermutationsRounded(nc_, n_, 2);
|
|
|
|
|
}
|
2019-12-03 23:40:41 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("BoxPermutationsRoundedThreeEdges") {
|
|
|
|
|
BoxPermutationsRounded(nc_, n_, 3);
|
|
|
|
|
}
|
2019-12-03 23:40:41 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("BoxPermutationsDouble") {
|
|
|
|
|
int dimx, dimy;
|
|
|
|
|
ncplane_dim_yx(n_, &dimy, &dimx);
|
|
|
|
|
REQUIRE(2 < dimx);
|
|
|
|
|
REQUIRE(47 < dimx);
|
|
|
|
|
// we'll try all 16 boxmasks in 3x3 configurations in a 1x16 map
|
|
|
|
|
unsigned boxmask = 0;
|
|
|
|
|
for(auto x0 = 0 ; x0 < 16 ; ++x0){
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, 0, x0 * 3));
|
|
|
|
|
CHECK(0 == ncplane_double_box_sized(n_, 0, 0, 3, 3, boxmask));
|
|
|
|
|
++boxmask;
|
|
|
|
|
}
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-11-27 15:43:03 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("PerimeterRoundedBox") {
|
|
|
|
|
int x, y;
|
|
|
|
|
ncplane_dim_yx(n_, &y, &x);
|
|
|
|
|
REQUIRE(2 < y);
|
|
|
|
|
REQUIRE(2 < x);
|
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
|
|
|
|
CHECK(0 == ncplane_rounded_box(n_, 0, 0, y - 1, x - 1, 0));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-11-26 02:11:27 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("PerimeterRoundedBoxSized") {
|
|
|
|
|
int x, y;
|
|
|
|
|
ncplane_dim_yx(n_, &y, &x);
|
|
|
|
|
REQUIRE(2 < y);
|
|
|
|
|
REQUIRE(2 < x);
|
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
|
|
|
|
CHECK(0 == ncplane_rounded_box_sized(n_, 0, 0, y, x, 0));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-11-26 02:11:27 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("PerimeterDoubleBox") {
|
|
|
|
|
int x, y;
|
|
|
|
|
ncplane_dim_yx(n_, &y, &x);
|
|
|
|
|
REQUIRE(2 < y);
|
|
|
|
|
REQUIRE(2 < x);
|
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
|
|
|
|
CHECK(0 == ncplane_double_box(n_, 0, 0, y - 1, x - 1, 0));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-11-26 12:14:38 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("PerimeterDoubleBoxSized") {
|
|
|
|
|
int x, y;
|
|
|
|
|
ncplane_dim_yx(n_, &y, &x);
|
|
|
|
|
REQUIRE(2 < y);
|
|
|
|
|
REQUIRE(2 < x);
|
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
|
|
|
|
CHECK(0 == ncplane_double_box_sized(n_, 0, 0, y, x, 0));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-11-28 15:05:44 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("EraseScreen") {
|
|
|
|
|
ncplane_erase(n_);
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-11-28 15:05:44 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
// we're gonna run both a composed latin a with grave, and then a latin a with
|
|
|
|
|
// a combining nonspacing grave
|
|
|
|
|
SUBCASE("CellLoadCombining") {
|
|
|
|
|
const char* w1 = "à"; // U+00E0, U+0000 (c3 a0)
|
|
|
|
|
const char* w2 = "à"; // U+0061, U+0300, U+0000 (61 cc 80)
|
|
|
|
|
const char* w3 = "a"; // U+0061, U+0000 (61)
|
|
|
|
|
cell cell1 = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
|
cell cell2 = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
|
cell cell3 = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
|
auto u1 = cell_load(n_, &cell1, w1);
|
|
|
|
|
auto u2 = cell_load(n_, &cell2, w2);
|
|
|
|
|
auto u3 = cell_load(n_, &cell3, w3);
|
|
|
|
|
REQUIRE(2 == u1);
|
|
|
|
|
REQUIRE(3 == u2);
|
|
|
|
|
REQUIRE(1 == u3);
|
|
|
|
|
cell_release(n_, &cell1);
|
|
|
|
|
cell_release(n_, &cell2);
|
|
|
|
|
cell_release(n_, &cell3);
|
|
|
|
|
}
|
2019-11-29 03:08:26 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("CellDuplicateCombining") {
|
|
|
|
|
const char* w1 = "à"; // U+00E0, U+0000 (c3 a0)
|
|
|
|
|
const char* w2 = "à"; // U+0061, U+0300, U+0000 (61 cc 80)
|
|
|
|
|
const char* w3 = "a"; // U+0061, U+0000 (61)
|
|
|
|
|
cell cell1 = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
|
cell cell2 = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
|
cell cell3 = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
|
auto u1 = cell_load(n_, &cell1, w1);
|
|
|
|
|
auto u2 = cell_load(n_, &cell2, w2);
|
|
|
|
|
auto u3 = cell_load(n_, &cell3, w3);
|
|
|
|
|
REQUIRE(2 == u1);
|
|
|
|
|
REQUIRE(3 == u2);
|
|
|
|
|
REQUIRE(1 == u3);
|
|
|
|
|
cell cell4 = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
|
cell cell5 = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
|
cell cell6 = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
|
CHECK(2 == cell_duplicate(n_, &cell4, &cell1));
|
|
|
|
|
CHECK(3 == cell_duplicate(n_, &cell5, &cell2));
|
|
|
|
|
CHECK(1 == cell_duplicate(n_, &cell6, &cell3));
|
|
|
|
|
cell_release(n_, &cell1);
|
|
|
|
|
cell_release(n_, &cell2);
|
|
|
|
|
cell_release(n_, &cell3);
|
|
|
|
|
cell_release(n_, &cell4);
|
|
|
|
|
cell_release(n_, &cell5);
|
|
|
|
|
cell_release(n_, &cell6);
|
2019-11-29 03:08:26 +00:00
|
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
|
|
|
|
|
|
SUBCASE("CellMultiColumn") {
|
|
|
|
|
const char* w1 = "\xf0\x9f\x91\xa9"; // U+1F469 WOMAN
|
|
|
|
|
const char* w2 = "N";
|
|
|
|
|
cell c1 = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
|
cell c2 = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
|
auto u1 = cell_load(n_, &c1, w1);
|
|
|
|
|
auto u2 = cell_load(n_, &c2, w2);
|
|
|
|
|
REQUIRE(0 < u1);
|
|
|
|
|
REQUIRE(0 < u2);
|
|
|
|
|
REQUIRE(strlen(w1) == u1);
|
|
|
|
|
REQUIRE(strlen(w2) == u2);
|
2020-06-28 10:43:29 +00:00
|
|
|
|
CHECK(mbswidth(w1) == 1 + cell_double_wide_p(&c1));
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK_FALSE(cell_double_wide_p(&c2));
|
|
|
|
|
cell_release(n_, &c1);
|
|
|
|
|
cell_release(n_, &c2);
|
2019-11-29 03:08:26 +00:00
|
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
|
|
|
|
|
|
// verifies that the initial userptr is what we provided, that it is a nullptr
|
|
|
|
|
// for the standard plane, and that we can change it.
|
|
|
|
|
SUBCASE("UserPtr") {
|
|
|
|
|
CHECK(nullptr == ncplane_userptr(n_));
|
|
|
|
|
int x, y;
|
|
|
|
|
void* sentinel = &x;
|
|
|
|
|
notcurses_term_dim_yx(nc_, &y, &x);
|
2019-12-30 07:28:40 +00:00
|
|
|
|
struct ncplane* ncp = ncplane_new(nc_, y, x, 0, 0, sentinel);
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(ncp);
|
|
|
|
|
CHECK(&x == ncplane_userptr(ncp));
|
|
|
|
|
CHECK(sentinel == ncplane_set_userptr(ncp, nullptr));
|
|
|
|
|
CHECK(nullptr == ncplane_userptr(ncp));
|
|
|
|
|
sentinel = &y;
|
|
|
|
|
CHECK(nullptr == ncplane_set_userptr(ncp, sentinel));
|
|
|
|
|
CHECK(&y == ncplane_userptr(ncp));
|
|
|
|
|
CHECK(0 == ncplane_destroy(ncp));
|
2019-11-29 03:08:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
// create a new plane, the same size as the terminal, and verify that it
|
|
|
|
|
// occupies the same dimensions as the standard plane.
|
|
|
|
|
SUBCASE("NewPlaneSameSize") {
|
|
|
|
|
int x, y;
|
|
|
|
|
notcurses_term_dim_yx(nc_, &y, &x);
|
2019-12-30 07:28:40 +00:00
|
|
|
|
struct ncplane* ncp = ncplane_new(nc_, y, x, 0, 0, nullptr);
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(ncp);
|
|
|
|
|
int px, py;
|
|
|
|
|
ncplane_dim_yx(ncp, &py, &px);
|
|
|
|
|
CHECK(y == py);
|
|
|
|
|
CHECK(x == px);
|
|
|
|
|
int sx, sy;
|
|
|
|
|
ncplane_dim_yx(n_, &sy, &sx);
|
|
|
|
|
CHECK(sy == py);
|
|
|
|
|
CHECK(sx == px);
|
|
|
|
|
CHECK(0 == ncplane_destroy(ncp));
|
2019-11-29 03:08:26 +00:00
|
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
|
|
|
|
|
|
SUBCASE("ShrinkPlane") {
|
|
|
|
|
int maxx, maxy;
|
|
|
|
|
int x = 0, y = 0;
|
|
|
|
|
notcurses_term_dim_yx(nc_, &maxy, &maxx);
|
2019-12-30 07:28:40 +00:00
|
|
|
|
struct ncplane* newp = ncplane_new(nc_, maxy, maxx, y, x, nullptr);
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(newp);
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
while(y > 4 && x > 4){
|
|
|
|
|
maxx -= 2;
|
|
|
|
|
maxy -= 2;
|
|
|
|
|
++x;
|
2019-11-29 03:08:26 +00:00
|
|
|
|
++y;
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(0 == ncplane_resize(newp, 1, 1, maxy, maxx, 1, 1, maxy, maxx));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
// FIXME check dims, pos
|
2019-11-29 03:08:26 +00:00
|
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
|
while(y > 4){
|
|
|
|
|
maxy -= 2;
|
|
|
|
|
++y;
|
|
|
|
|
REQUIRE(0 == ncplane_resize(newp, 1, 0, maxy, maxx, 1, 0, maxy, maxx));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
// FIXME check dims, pos
|
|
|
|
|
}
|
|
|
|
|
while(x > 4){
|
|
|
|
|
maxx -= 2;
|
2019-11-29 03:08:26 +00:00
|
|
|
|
++x;
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(0 == ncplane_resize(newp, 0, 1, maxy, maxx, 0, 1, maxy, maxx));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
// FIXME check dims, pos
|
2019-11-29 03:08:26 +00:00
|
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(0 == ncplane_resize(newp, 0, 0, 0, 0, 0, 0, 2, 2));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2019-11-29 03:08:26 +00:00
|
|
|
|
// FIXME check dims, pos
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(0 == ncplane_destroy(newp));
|
2019-11-29 03:08:26 +00:00
|
|
|
|
}
|
2019-12-01 03:53:24 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("GrowPlane") {
|
|
|
|
|
int maxx = 2, maxy = 2;
|
|
|
|
|
int x = 0, y = 0;
|
|
|
|
|
int dimy, dimx;
|
|
|
|
|
notcurses_term_dim_yx(nc_, &dimy, &dimx);
|
|
|
|
|
x = dimx / 2 - 1;
|
|
|
|
|
y = dimy / 2 - 1;
|
2019-12-30 07:28:40 +00:00
|
|
|
|
struct ncplane* newp = ncplane_new(nc_, maxy, maxx, y, x, nullptr);
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(newp);
|
|
|
|
|
while(dimx - maxx > 4 && dimy - maxy > 4){
|
|
|
|
|
maxx += 2;
|
|
|
|
|
maxy += 2;
|
|
|
|
|
--x;
|
|
|
|
|
--y;
|
|
|
|
|
// REQUIRE(0 == ncplane_resize(newp, 1, 1, maxy, maxx, 1, 1, maxy, maxx));
|
|
|
|
|
// FIXME check dims, pos
|
|
|
|
|
}
|
|
|
|
|
while(y < dimy){
|
|
|
|
|
++maxy;
|
|
|
|
|
if(y){
|
|
|
|
|
++y;
|
|
|
|
|
}
|
|
|
|
|
// REQUIRE(0 == ncplane_resize(newp, 1, 0, maxy, maxx, 1, 0, maxy, maxx));
|
|
|
|
|
// FIXME check dims, pos
|
|
|
|
|
}
|
|
|
|
|
while(x < dimx){
|
|
|
|
|
++maxx;
|
|
|
|
|
if(x){
|
|
|
|
|
++x;
|
|
|
|
|
}
|
|
|
|
|
// REQUIRE(0 == ncplane_resize(newp, 0, 1, maxy, maxx, 0, 1, maxy, maxx));
|
|
|
|
|
// FIXME check dims, pos
|
|
|
|
|
}
|
|
|
|
|
REQUIRE(0 == ncplane_resize(newp, 0, 0, 0, 0, 0, 0, dimy, dimx));
|
|
|
|
|
// FIXME check dims, pos
|
|
|
|
|
REQUIRE(0 == ncplane_destroy(newp));
|
|
|
|
|
}
|
2019-12-01 03:53:24 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
// we ought be able to see what we're about to render, or have just rendered, or
|
|
|
|
|
// in any case whatever's in the virtual framebuffer for a plane
|
|
|
|
|
SUBCASE("PlaneAtCursorSimples"){
|
|
|
|
|
const char STR1[] = "Jackdaws love my big sphinx of quartz";
|
|
|
|
|
const char STR2[] = "Cwm fjord bank glyphs vext quiz";
|
|
|
|
|
const char STR3[] = "Pack my box with five dozen liquor jugs";
|
|
|
|
|
ncplane_styles_set(n_, 0);
|
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
|
|
|
|
REQUIRE(0 < ncplane_putstr(n_, STR1));
|
2020-04-06 03:06:21 +00:00
|
|
|
|
cell testcell = CELL_TRIVIAL_INITIALIZER;
|
2020-04-18 04:09:14 +00:00
|
|
|
|
REQUIRE(0 == ncplane_at_cursor_cell(n_, &testcell)); // want nothing at the cursor
|
2020-04-06 03:06:21 +00:00
|
|
|
|
CHECK(0 == testcell.gcluster);
|
|
|
|
|
CHECK(0 == testcell.attrword);
|
|
|
|
|
CHECK(0 == testcell.channels);
|
2019-12-27 22:20:20 +00:00
|
|
|
|
int dimy, dimx;
|
|
|
|
|
ncplane_dim_yx(n_, &dimy, &dimx);
|
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 1, dimx - strlen(STR2)));
|
|
|
|
|
REQUIRE(0 < ncplane_putstr(n_, STR2));
|
|
|
|
|
int y, x;
|
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
2020-04-06 03:06:21 +00:00
|
|
|
|
REQUIRE(1 == y);
|
|
|
|
|
REQUIRE(dimx == x);
|
|
|
|
|
REQUIRE(0 == ncplane_putstr(n_, STR3));
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
2020-04-18 04:09:14 +00:00
|
|
|
|
REQUIRE(0 < ncplane_at_cursor_cell(n_, &testcell)); // want first char of STR1
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK(STR1[0] == testcell.gcluster);
|
|
|
|
|
CHECK(0 == testcell.attrword);
|
|
|
|
|
CHECK(0 == testcell.channels);
|
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 1, dimx - 1));
|
2020-04-18 04:09:14 +00:00
|
|
|
|
REQUIRE(0 < ncplane_at_cursor_cell(n_, &testcell)); // want last char of STR2
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK(STR2[strlen(STR2) - 1] == testcell.gcluster);
|
|
|
|
|
CHECK(0 == testcell.attrword);
|
|
|
|
|
CHECK(0 == testcell.channels);
|
|
|
|
|
// FIXME maybe check all cells?
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-12-01 03:53:24 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
// ensure we read back what's expected for latinesque complex characters
|
|
|
|
|
SUBCASE("PlaneAtCursorComplex"){
|
|
|
|
|
const char STR1[] = "Σιβυλλα τι θελεις; respondebat illa:";
|
|
|
|
|
const char STR2[] = "αποθανειν θελω";
|
|
|
|
|
const char STR3[] = "Война и мир"; // just thrown in to complicate things
|
|
|
|
|
ncplane_styles_set(n_, 0);
|
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
|
|
|
|
REQUIRE(0 < ncplane_putstr(n_, STR1));
|
2020-04-06 03:06:21 +00:00
|
|
|
|
cell testcell = CELL_TRIVIAL_INITIALIZER;
|
2020-04-18 04:09:14 +00:00
|
|
|
|
ncplane_at_cursor_cell(n_, &testcell); // should be nothing at the cursor
|
2020-04-06 03:06:21 +00:00
|
|
|
|
CHECK(0 == testcell.gcluster);
|
|
|
|
|
CHECK(0 == testcell.attrword);
|
|
|
|
|
CHECK(0 == testcell.channels);
|
2019-12-27 22:20:20 +00:00
|
|
|
|
int dimy, dimx;
|
|
|
|
|
ncplane_dim_yx(n_, &dimy, &dimx);
|
2020-05-07 04:52:40 +00:00
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 1, dimx - mbstowcs(nullptr, STR2, 0)));
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(0 < ncplane_putstr(n_, STR2));
|
|
|
|
|
int y, x;
|
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
2020-04-06 03:06:21 +00:00
|
|
|
|
REQUIRE(1 == y);
|
|
|
|
|
REQUIRE(dimx == x);
|
|
|
|
|
REQUIRE(0 == ncplane_putstr(n_, STR3));
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
2020-04-18 04:09:14 +00:00
|
|
|
|
REQUIRE(0 < ncplane_at_cursor_cell(n_, &testcell)); // want first char of STR1
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK(!strcmp("Σ", cell_extended_gcluster(n_, &testcell)));
|
|
|
|
|
CHECK(0 == testcell.attrword);
|
|
|
|
|
CHECK(0 == testcell.channels);
|
2020-05-07 04:52:40 +00:00
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 1, dimx - mbstowcs(nullptr, STR2, 0)));
|
2020-04-18 04:09:14 +00:00
|
|
|
|
REQUIRE(0 < ncplane_at_cursor_cell(n_, &testcell)); // want first char of STR2
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK(!strcmp("α", cell_extended_gcluster(n_, &testcell)));
|
|
|
|
|
CHECK(0 == testcell.attrword);
|
|
|
|
|
CHECK(0 == testcell.channels);
|
|
|
|
|
// FIXME maybe check all cells?
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// test that we read back correct attrs/colors despite changing defaults
|
|
|
|
|
SUBCASE("PlaneAtCursorAttrs"){
|
|
|
|
|
const char STR1[] = "this has been a world destroyer production";
|
|
|
|
|
const char STR2[] = "not to mention dank";
|
|
|
|
|
const char STR3[] = "da chronic lives";
|
2020-02-02 08:14:45 +00:00
|
|
|
|
ncplane_styles_set(n_, NCSTYLE_BOLD);
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(0 < ncplane_putstr(n_, STR1));
|
|
|
|
|
int y, x;
|
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, y + 1, x - strlen(STR2)));
|
2020-02-02 08:14:45 +00:00
|
|
|
|
ncplane_styles_on(n_, NCSTYLE_ITALIC);
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(0 < ncplane_putstr(n_, STR2));
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, y + 2, x - strlen(STR3)));
|
2020-02-02 08:14:45 +00:00
|
|
|
|
ncplane_styles_off(n_, NCSTYLE_BOLD);
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(0 < ncplane_putstr(n_, STR3));
|
2020-02-02 08:14:45 +00:00
|
|
|
|
ncplane_styles_off(n_, NCSTYLE_ITALIC);
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
int newx;
|
|
|
|
|
ncplane_cursor_yx(n_, &y, &newx);
|
|
|
|
|
CHECK(newx == x);
|
|
|
|
|
cell testcell = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, y - 2, x - 1));
|
2020-04-18 04:09:14 +00:00
|
|
|
|
REQUIRE(1 == ncplane_at_cursor_cell(n_, &testcell));
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK(testcell.gcluster == STR1[strlen(STR1) - 1]);
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, y - 1, x - 1));
|
2020-04-18 04:09:14 +00:00
|
|
|
|
REQUIRE(1 == ncplane_at_cursor_cell(n_, &testcell));
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK(testcell.gcluster == STR2[strlen(STR2) - 1]);
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, y, x - 1));
|
2020-04-18 04:09:14 +00:00
|
|
|
|
REQUIRE(1 == ncplane_at_cursor_cell(n_, &testcell));
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK(testcell.gcluster == STR3[strlen(STR3) - 1]);
|
|
|
|
|
}
|
2019-12-04 08:54:52 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("BoxGradients") {
|
|
|
|
|
const auto sidesz = 5;
|
|
|
|
|
int dimx, dimy;
|
|
|
|
|
ncplane_dim_yx(n_, &dimy, &dimx);
|
|
|
|
|
REQUIRE(20 < dimy);
|
|
|
|
|
REQUIRE(40 < dimx);
|
|
|
|
|
cell ul{}, ll{}, lr{}, ur{}, hl{}, vl{};
|
|
|
|
|
REQUIRE(0 == cells_double_box(n_, 0, 0, &ul, &ur, &ll, &lr, &hl, &vl));
|
|
|
|
|
CHECK(0 == channels_set_fg_rgb(&ul.channels, 255, 0, 0));
|
|
|
|
|
CHECK(0 == channels_set_fg_rgb(&ur.channels, 0, 255, 0));
|
|
|
|
|
CHECK(0 == channels_set_fg_rgb(&ll.channels, 0, 0, 255));
|
|
|
|
|
CHECK(0 == channels_set_fg_rgb(&lr.channels, 255, 255, 255));
|
|
|
|
|
CHECK(0 == channels_set_bg_rgb(&ul.channels, 0, 255, 255));
|
|
|
|
|
CHECK(0 == channels_set_bg_rgb(&ur.channels, 255, 0, 255));
|
|
|
|
|
CHECK(0 == channels_set_bg_rgb(&ll.channels, 255, 255, 0));
|
|
|
|
|
CHECK(0 == channels_set_bg_rgb(&lr.channels, 0, 0, 0));
|
|
|
|
|
// we'll try all 16 gradmasks in sideszXsidesz configs in a 4x4 map
|
|
|
|
|
unsigned gradmask = 0;
|
|
|
|
|
for(auto y0 = 0 ; y0 < 4 ; ++y0){
|
|
|
|
|
for(auto x0 = 0 ; x0 < 4 ; ++x0){
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, y0 * sidesz, x0 * (sidesz + 1)));
|
|
|
|
|
CHECK(0 == ncplane_box_sized(n_, &ul, &ur, &ll, &lr, &hl, &vl,
|
|
|
|
|
sidesz, sidesz, gradmask << 4u));
|
|
|
|
|
++gradmask;
|
|
|
|
|
}
|
2019-12-04 08:54:52 +00:00
|
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
|
gradmask = 0;
|
|
|
|
|
for(auto y0 = 0 ; y0 < 4 ; ++y0){
|
|
|
|
|
for(auto x0 = 0 ; x0 < 4 ; ++x0){
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, y0 * sidesz, x0 * (sidesz + 1) + (4 * (sidesz + 1))));
|
|
|
|
|
CHECK(0 == ncplane_box_sized(n_, &ul, &ur, &ll, &lr, &hl, &vl,
|
|
|
|
|
sidesz, sidesz, gradmask << 4u));
|
|
|
|
|
++gradmask;
|
|
|
|
|
}
|
2019-12-04 08:54:52 +00:00
|
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2019-12-04 08:54:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("BoxSideColors") {
|
|
|
|
|
const auto sidesz = 5;
|
|
|
|
|
int dimx, dimy;
|
|
|
|
|
ncplane_dim_yx(n_, &dimy, &dimx);
|
|
|
|
|
REQUIRE(20 < dimy);
|
|
|
|
|
REQUIRE(40 < dimx);
|
|
|
|
|
cell ul{}, ll{}, lr{}, ur{}, hl{}, vl{};
|
|
|
|
|
REQUIRE(0 == cells_rounded_box(n_, 0, 0, &ul, &ur, &ll, &lr, &hl, &vl));
|
|
|
|
|
// we'll try all 16 boxmasks in sideszXsidesz configurations in a 4x4 map
|
|
|
|
|
CHECK(0 == channels_set_fg_rgb(&ul.channels, 255, 0, 0));
|
|
|
|
|
CHECK(0 == channels_set_fg_rgb(&ur.channels, 0, 255, 0));
|
|
|
|
|
CHECK(0 == channels_set_fg_rgb(&ll.channels, 0, 0, 255));
|
|
|
|
|
CHECK(0 == channels_set_fg_rgb(&lr.channels, 0, 0, 0));
|
|
|
|
|
CHECK(0 == channels_set_bg_rgb(&ul.channels, 0, 255, 255));
|
|
|
|
|
CHECK(0 == channels_set_bg_rgb(&ur.channels, 255, 0, 255));
|
|
|
|
|
CHECK(0 == channels_set_bg_rgb(&ll.channels, 255, 255, 0));
|
|
|
|
|
CHECK(0 == channels_set_bg_rgb(&lr.channels, 0, 0, 0));
|
|
|
|
|
CHECK(0 == channels_set_fg_rgb(&hl.channels, 255, 0, 255));
|
|
|
|
|
CHECK(0 == channels_set_fg_rgb(&vl.channels, 255, 255, 255));
|
|
|
|
|
CHECK(0 == channels_set_bg_rgb(&hl.channels, 0, 255, 0));
|
|
|
|
|
CHECK(0 == channels_set_bg_rgb(&vl.channels, 0, 0, 0));
|
|
|
|
|
for(auto y0 = 0 ; y0 < 4 ; ++y0){
|
|
|
|
|
for(auto x0 = 0 ; x0 < 4 ; ++x0){
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, y0 * sidesz, x0 * (sidesz + 1)));
|
|
|
|
|
CHECK(0 == ncplane_box_sized(n_, &ul, &ur, &ll, &lr, &hl, &vl,
|
|
|
|
|
sidesz, sidesz, 0));
|
|
|
|
|
}
|
2019-12-04 08:54:52 +00:00
|
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
|
for(auto y0 = 0 ; y0 < 4 ; ++y0){
|
|
|
|
|
for(auto x0 = 0 ; x0 < 4 ; ++x0){
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, y0 * sidesz, x0 * (sidesz + 1) + (4 * (sidesz + 1))));
|
|
|
|
|
CHECK(0 == ncplane_box_sized(n_, &ul, &ur, &ll, &lr, &hl, &vl,
|
|
|
|
|
sidesz, sidesz, 0));
|
|
|
|
|
}
|
2019-12-04 08:54:52 +00:00
|
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2019-12-04 08:54:52 +00:00
|
|
|
|
}
|
2019-12-04 15:00:23 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("RightToLeft") {
|
|
|
|
|
// give us some room on both sides
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, 1, 10));
|
|
|
|
|
int sbytes = -1;
|
2020-01-04 07:37:55 +00:00
|
|
|
|
CHECK(0 < ncplane_putegc(n_, "־", &sbytes));
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, 3, 10));
|
|
|
|
|
CHECK(0 < ncplane_putstr(n_, "I can write English with מילים בעברית in the same sentence."));
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, 5, 10));
|
|
|
|
|
CHECK(0 < ncplane_putstr(n_, "|🔥|I have not yet ־ begun to hack|🔥|"));
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, 7, 10));
|
|
|
|
|
CHECK(0 < ncplane_putstr(n_, "㉀㉁㉂㉃㉄㉅㉆㉇㉈㉉㉊㉋㉌㉍㉎㉏㉐㉑㉒㉓㉔㉕㉖㉗㉘㉙㉚㉛㉜㉝㉞㉟"));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
2019-12-10 11:02:49 +00:00
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
SUBCASE("NewPlaneOnRight") {
|
|
|
|
|
int ncols, nrows;
|
|
|
|
|
ncplane_dim_yx(n_, &nrows, &ncols);
|
|
|
|
|
cell ul{}, ll{}, lr{}, ur{}, hl{}, vl{};
|
|
|
|
|
int y, x;
|
|
|
|
|
ncplane_yx(n_, &y, &x);
|
2019-12-30 07:28:40 +00:00
|
|
|
|
struct ncplane* ncp = ncplane_new(nc_, 2, 2, y, ncols - 3, nullptr);
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(ncp);
|
|
|
|
|
REQUIRE(0 == cells_rounded_box(ncp, 0, 0, &ul, &ur, &ll, &lr, &hl, &vl));
|
|
|
|
|
CHECK(0 == ncplane_box(ncp, &ul, &ur, &ll, &lr, &hl, &vl, y + 1, x + 1, 0));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-04-18 04:09:14 +00:00
|
|
|
|
// FIXME verify with ncplane_at_cursor_cell()
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK(0 == ncplane_destroy(ncp));
|
|
|
|
|
}
|
|
|
|
|
SUBCASE("MoveToLowerRight") {
|
|
|
|
|
int ncols, nrows;
|
|
|
|
|
ncplane_dim_yx(n_, &nrows, &ncols);
|
|
|
|
|
cell ul{}, ll{}, lr{}, ur{}, hl{}, vl{};
|
|
|
|
|
int y, x;
|
|
|
|
|
ncplane_yx(n_, &y, &x);
|
2019-12-30 07:28:40 +00:00
|
|
|
|
struct ncplane* ncp = ncplane_new(nc_, 2, 2, y, x, nullptr);
|
2019-12-27 22:20:20 +00:00
|
|
|
|
REQUIRE(ncp);
|
|
|
|
|
REQUIRE(0 == cells_rounded_box(ncp, 0, 0, &ul, &ur, &ll, &lr, &hl, &vl));
|
|
|
|
|
CHECK(0 == ncplane_box(ncp, &ul, &ur, &ll, &lr, &hl, &vl, y + 1, x + 1, 0));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
CHECK(0 == ncplane_move_yx(ncp, nrows - 3, ncols - 3));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
CHECK(0 == ncplane_destroy(ncp));
|
2020-04-18 04:09:14 +00:00
|
|
|
|
// FIXME verify with ncplane_at_cursor_cell()
|
2019-12-27 22:20:20 +00:00
|
|
|
|
}
|
2019-12-18 09:38:43 +00:00
|
|
|
|
|
2020-02-12 17:29:28 +00:00
|
|
|
|
SUBCASE("Perimeter") {
|
|
|
|
|
cell c = CELL_SIMPLE_INITIALIZER('X');
|
|
|
|
|
CHECK(0 == ncplane_perimeter(n_, &c, &c, &c, &c, &c, &c, 0));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-20 09:41:56 +00:00
|
|
|
|
SUBCASE("EGCStainable") {
|
|
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
|
int sbytes;
|
|
|
|
|
CHECK(0 == ncplane_set_fg(n_, 0x444444));
|
|
|
|
|
CHECK(1 == ncplane_putegc(n_, "A", &sbytes));
|
|
|
|
|
CHECK(0 == ncplane_set_fg(n_, 0x888888));
|
|
|
|
|
CHECK(1 == ncplane_putegc(n_, "B", &sbytes));
|
|
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
// EGC should change, but not the color
|
|
|
|
|
CHECK(0 == ncplane_set_fg(n_, 0x222222));
|
|
|
|
|
CHECK(1 == ncplane_putegc_stainable(n_, "C", &sbytes));
|
|
|
|
|
CHECK(1 == ncplane_putegc_stainable(n_, "D", &sbytes));
|
|
|
|
|
uint64_t channels = 0;
|
2020-04-18 04:09:14 +00:00
|
|
|
|
CHECK(1 == ncplane_at_yx_cell(n_, 0, 0, &c));
|
2020-02-20 09:41:56 +00:00
|
|
|
|
CHECK(cell_simple_p(&c));
|
|
|
|
|
CHECK('C' == c.gcluster);
|
|
|
|
|
CHECK(0 == channels_set_fg(&channels, 0x444444));
|
|
|
|
|
CHECK(channels == c.channels);
|
2020-04-18 04:09:14 +00:00
|
|
|
|
CHECK(1 == ncplane_at_yx_cell(n_, 0, 1, &c));
|
2020-02-20 09:41:56 +00:00
|
|
|
|
CHECK(cell_simple_p(&c));
|
|
|
|
|
CHECK('D' == c.gcluster);
|
|
|
|
|
CHECK(0 == channels_set_fg(&channels, 0x888888));
|
|
|
|
|
CHECK(channels == c.channels);
|
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-23 08:50:17 +00:00
|
|
|
|
SUBCASE("MouseEvent") {
|
|
|
|
|
int dimy, dimx;
|
|
|
|
|
notcurses_stddim_yx(nc_, &dimy, &dimx);
|
|
|
|
|
struct ncplane* n = ncplane_new(nc_, 2, 2, 1, 1, nullptr);
|
2020-03-27 06:06:58 +00:00
|
|
|
|
REQUIRE(n);
|
2020-02-23 08:50:17 +00:00
|
|
|
|
ncinput ni{};
|
|
|
|
|
ni.id = NCKEY_RELEASE;
|
|
|
|
|
int total = 0;
|
|
|
|
|
for(ni.y = 0 ; ni.y < 5 ; ++ni.y){
|
|
|
|
|
for(ni.x = 0 ; ni.x < 5 ; ++ni.x){
|
2020-03-03 05:59:35 +00:00
|
|
|
|
int y = ni.y, x = ni.x;
|
|
|
|
|
bool p = ncplane_translate_abs(n, &y, &x);
|
2020-02-23 08:50:17 +00:00
|
|
|
|
if(ni.y >= 1 && ni.y <= 2 && ni.x >= 1 && ni.x <= 2){
|
|
|
|
|
CHECK(p);
|
|
|
|
|
}else{
|
|
|
|
|
CHECK(!p);
|
|
|
|
|
}
|
|
|
|
|
++total;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
CHECK(25 == total); // make sure x/y never got changed
|
|
|
|
|
CHECK(0 == ncplane_destroy(n));
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-27 06:06:58 +00:00
|
|
|
|
SUBCASE("BoundPlaneMoves") {
|
|
|
|
|
struct ncplane* ndom = ncplane_new(nc_, 2, 2, 1, 1, nullptr);
|
|
|
|
|
REQUIRE(ndom);
|
|
|
|
|
struct ncplane* nsub = ncplane_bound(ndom, 2, 2, 1, 1, nullptr);
|
|
|
|
|
REQUIRE(nsub);
|
|
|
|
|
int absy, absx;
|
|
|
|
|
ncplane_yx(nsub, &absy, &absx);
|
2020-06-03 16:17:51 +00:00
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
CHECK(1 == absy); // actually at 2, 2
|
|
|
|
|
CHECK(1 == absx);
|
|
|
|
|
CHECK(0 == ncplane_move_yx(nsub, -1, -1));
|
2020-03-27 06:06:58 +00:00
|
|
|
|
ncplane_yx(nsub, &absy, &absx);
|
2020-06-03 16:17:51 +00:00
|
|
|
|
CHECK(-1 == absy); // actually at 0, 0
|
|
|
|
|
CHECK(-1 == absx);
|
2020-03-27 06:06:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SUBCASE("BoundToPlaneMoves") { // bound plane ought move along with plane
|
|
|
|
|
struct ncplane* ndom = ncplane_new(nc_, 2, 2, 1, 1, nullptr);
|
|
|
|
|
REQUIRE(ndom);
|
|
|
|
|
struct ncplane* nsub = ncplane_bound(ndom, 2, 2, 1, 1, nullptr);
|
|
|
|
|
REQUIRE(nsub);
|
|
|
|
|
int absy, absx;
|
|
|
|
|
ncplane_yx(nsub, &absy, &absx);
|
2020-06-03 16:17:51 +00:00
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
|
CHECK(1 == absy); // actually at 2, 2
|
|
|
|
|
CHECK(1 == absx);
|
|
|
|
|
CHECK(0 == ncplane_move_yx(ndom, 0, 0));
|
2020-03-27 06:06:58 +00:00
|
|
|
|
ncplane_yx(nsub, &absy, &absx);
|
|
|
|
|
CHECK(1 == absy);
|
|
|
|
|
CHECK(1 == absx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SUBCASE("UnboundPlaneMoves") { // unbound plane no longer gets pulled along
|
|
|
|
|
struct ncplane* ndom = ncplane_new(nc_, 2, 2, 1, 1, nullptr);
|
|
|
|
|
REQUIRE(ndom);
|
|
|
|
|
struct ncplane* nsub = ncplane_bound(ndom, 2, 2, 1, 1, nullptr);
|
|
|
|
|
REQUIRE(nsub);
|
|
|
|
|
int absy, absx;
|
2020-06-03 16:17:51 +00:00
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-03-27 06:06:58 +00:00
|
|
|
|
ncplane_yx(nsub, &absy, &absx);
|
2020-06-03 16:17:51 +00:00
|
|
|
|
CHECK(1 == absy); // actually at 2, 2
|
|
|
|
|
CHECK(1 == absx);
|
2020-03-27 06:06:58 +00:00
|
|
|
|
ncplane_reparent(nsub, nullptr);
|
|
|
|
|
ncplane_yx(nsub, &absy, &absx);
|
2020-06-03 16:17:51 +00:00
|
|
|
|
CHECK(2 == absy); // now we recognize 2, 2
|
|
|
|
|
CHECK(2 == absx);
|
|
|
|
|
CHECK(0 == ncplane_move_yx(ndom, 0, 0));
|
|
|
|
|
ncplane_yx(nsub, &absy, &absx);
|
|
|
|
|
CHECK(2 == absy); // still at 2, 2
|
2020-03-27 06:06:58 +00:00
|
|
|
|
CHECK(2 == absx);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SUBCASE("NoReparentStdPlane") {
|
|
|
|
|
struct ncplane* ndom = ncplane_new(nc_, 2, 2, 1, 1, nullptr);
|
|
|
|
|
REQUIRE(ndom);
|
|
|
|
|
CHECK(!ncplane_reparent(n_, ndom)); // can't reparent standard plane
|
|
|
|
|
CHECK(ncplane_reparent(ndom, n_)); // *can* reparent *to* standard plane
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
|
CHECK(0 == notcurses_stop(nc_));
|
2019-12-18 09:38:43 +00:00
|
|
|
|
|
|
|
|
|
}
|