2020-04-06 01:10:48 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include <array>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include "internal.h"
|
|
|
|
|
|
|
|
TEST_CASE("Scrolling") {
|
2020-06-16 03:58:43 +00:00
|
|
|
auto nc_ = testing_notcurses();
|
2020-05-17 11:57:21 +00:00
|
|
|
if(!nc_){
|
|
|
|
return;
|
|
|
|
}
|
2020-04-06 01:10:48 +00:00
|
|
|
struct ncplane* n_ = notcurses_stdplane(nc_);
|
|
|
|
REQUIRE(n_);
|
|
|
|
|
|
|
|
// verify that the standard plane has scrolling disabled initially, and that
|
|
|
|
// we can enable it at runtime.
|
2020-04-14 18:57:47 +00:00
|
|
|
SUBCASE("ScollingDisabledStdplane") {
|
2020-04-06 01:10:48 +00:00
|
|
|
CHECK(!ncplane_set_scrolling(n_, true));
|
|
|
|
CHECK(ncplane_set_scrolling(n_, false));
|
|
|
|
}
|
|
|
|
|
2020-04-14 18:57:47 +00:00
|
|
|
SUBCASE("ScrollingStr") {
|
2020-04-06 01:10:48 +00:00
|
|
|
struct ncplane* n = ncplane_new(nc_, 2, 20, 1, 1, nullptr);
|
|
|
|
REQUIRE(n);
|
|
|
|
// verify that the new plane was started without scrolling
|
|
|
|
CHECK(!ncplane_set_scrolling(n, false));
|
2020-04-15 00:17:52 +00:00
|
|
|
// try to write 40 EGCs; it ought fail after 20
|
2020-04-06 03:06:21 +00:00
|
|
|
CHECK(-20 == ncplane_putstr(n, "0123456789012345678901234567890123456789"));
|
|
|
|
int y, x;
|
|
|
|
ncplane_cursor_yx(n, &y, &x);
|
|
|
|
CHECK(0 == y);
|
|
|
|
CHECK(20 == x);
|
2020-04-06 01:10:48 +00:00
|
|
|
CHECK(!ncplane_set_scrolling(n, true)); // enable scrolling
|
2020-04-15 00:17:52 +00:00
|
|
|
// try to write 40 EGCs from origin; it ought succeed
|
|
|
|
CHECK(40 == ncplane_putstr_yx(n, 0, 0, "0123456789012345678901234567890123456789"));
|
2020-04-06 01:18:35 +00:00
|
|
|
ncplane_cursor_yx(n, &y, &x);
|
|
|
|
CHECK(1 == y);
|
|
|
|
CHECK(20 == x);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
}
|
|
|
|
|
2020-04-06 03:06:21 +00:00
|
|
|
// even when scrolling is enabled, you aren't allowed to move the cursor
|
|
|
|
// off-plane, or initiate output there
|
2020-04-14 18:57:47 +00:00
|
|
|
SUBCASE("NoScrollingManually") {
|
2020-04-06 03:06:21 +00:00
|
|
|
struct ncplane* n = ncplane_new(nc_, 2, 20, 1, 1, nullptr);
|
|
|
|
REQUIRE(n);
|
|
|
|
CHECK(!ncplane_set_scrolling(n, true)); // enable scrolling
|
|
|
|
CHECK(0 > ncplane_cursor_move_yx(n, 0, 20));
|
|
|
|
CHECK(0 > ncplane_cursor_move_yx(n, 1, 20));
|
|
|
|
CHECK(0 > ncplane_cursor_move_yx(n, 2, 2));
|
|
|
|
CHECK(0 > ncplane_putsimple_yx(n, 0, 20, 'c'));
|
|
|
|
CHECK(0 > ncplane_putsimple_yx(n, 1, 20, 'c'));
|
|
|
|
CHECK(0 > ncplane_putsimple_yx(n, 2, 0, 'c'));
|
|
|
|
}
|
|
|
|
|
|
|
|
// verify that two strings, each the length of the plane, can be output when
|
|
|
|
// scrolling is enabled (the second ought get an error without scrolling)
|
2020-04-14 18:57:47 +00:00
|
|
|
SUBCASE("ScrollingSplitStr") {
|
2020-04-06 01:18:35 +00:00
|
|
|
struct ncplane* n = ncplane_new(nc_, 2, 20, 1, 1, nullptr);
|
|
|
|
REQUIRE(n);
|
|
|
|
CHECK(20 == ncplane_putstr(n, "01234567890123456789"));
|
|
|
|
int y, x;
|
|
|
|
ncplane_cursor_yx(n, &y, &x);
|
|
|
|
CHECK(0 == y);
|
|
|
|
CHECK(20 == x);
|
2020-04-06 03:06:21 +00:00
|
|
|
CHECK(0 == ncplane_putstr(n, "01234567890123456789"));
|
2020-04-06 01:18:35 +00:00
|
|
|
CHECK(!ncplane_set_scrolling(n, true)); // enable scrolling
|
2020-04-06 03:06:21 +00:00
|
|
|
CHECK(20 == ncplane_putstr(n, "01234567890123456789"));
|
2020-04-06 01:18:35 +00:00
|
|
|
ncplane_cursor_yx(n, &y, &x);
|
|
|
|
CHECK(1 == y);
|
|
|
|
CHECK(20 == x);
|
2020-04-06 01:10:48 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
}
|
|
|
|
|
2020-04-06 03:06:21 +00:00
|
|
|
// verify that a single string the size of the plane can be output when
|
|
|
|
// scrolling is enabled (it ought be an error without scrolling)
|
2020-04-14 18:57:47 +00:00
|
|
|
SUBCASE("ScrollingEGC") {
|
2020-04-06 03:06:21 +00:00
|
|
|
const char* out = "0123456789012345678901234567890123456789";
|
2020-04-06 01:10:48 +00:00
|
|
|
struct ncplane* n = ncplane_new(nc_, 2, 20, 1, 1, nullptr);
|
|
|
|
REQUIRE(n);
|
|
|
|
// verify that the new plane was started without scrolling
|
|
|
|
CHECK(!ncplane_set_scrolling(n, false));
|
|
|
|
// try to write 40 EGCs; the last 20 ought fail
|
|
|
|
for(const char* c = out ; *c ; ++c){
|
|
|
|
int ret = ncplane_putsimple(n, *c);
|
|
|
|
if(c - out < 20){
|
|
|
|
CHECK(1 == ret);
|
|
|
|
}else{
|
|
|
|
CHECK(0 > ret);
|
|
|
|
}
|
|
|
|
}
|
2020-04-06 01:18:35 +00:00
|
|
|
int y, x;
|
|
|
|
ncplane_cursor_yx(n, &y, &x);
|
|
|
|
CHECK(0 == y);
|
|
|
|
CHECK(20 == x);
|
2020-04-06 01:10:48 +00:00
|
|
|
CHECK(0 == ncplane_cursor_move_yx(n, 0, 0));
|
|
|
|
CHECK(!ncplane_set_scrolling(n, true)); // enable scrolling
|
|
|
|
// try to write 40 EGCs; all ought succeed
|
|
|
|
for(const char* c = out ; *c ; ++c){
|
|
|
|
CHECK(1 == ncplane_putsimple(n, *c));
|
|
|
|
}
|
2020-04-06 01:18:35 +00:00
|
|
|
ncplane_cursor_yx(n, &y, &x);
|
|
|
|
CHECK(1 == y);
|
|
|
|
CHECK(20 == x);
|
2020-04-06 01:10:48 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
}
|
|
|
|
|
2020-04-14 18:57:47 +00:00
|
|
|
// ensure that if we draw a box on a scrolling plane, it stops at the right
|
|
|
|
// side, as opposed to scrolling and making a horrible mess
|
|
|
|
SUBCASE("ScrollingBoxen") {
|
|
|
|
struct ncplane* n = ncplane_new(nc_, 4, 20, 1, 1, nullptr);
|
|
|
|
REQUIRE(n);
|
|
|
|
// verify that the new plane was started without scrolling
|
|
|
|
CHECK(!ncplane_set_scrolling(n, true));
|
|
|
|
cell ul = CELL_TRIVIAL_INITIALIZER, ur = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
cell dl = CELL_TRIVIAL_INITIALIZER, dr = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
cell hl = CELL_TRIVIAL_INITIALIZER, vl = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
CHECK(0 == cells_double_box(n, 0, 0, &ul, &ur, &dl, &dr, &hl, &vl));
|
|
|
|
CHECK(0 > ncplane_box_sized(n, &ul, &ur, &dl, &dr, &hl, &vl, 2, 25, 0));
|
|
|
|
CHECK(0 > ncplane_box_sized(n, &ul, &ur, &dl, &dr, &hl, &vl, 2, 21, 0));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
}
|
|
|
|
|
2020-04-14 19:04:10 +00:00
|
|
|
SUBCASE("ScrollingOffBottom") {
|
|
|
|
const char* out = "0123456789012345678901234567890123456789";
|
2020-04-14 19:43:42 +00:00
|
|
|
const char* onext = "ABCDEFGHIJKLMNOPQRST";
|
|
|
|
const char* next2 = "UVWXYZabcd";
|
2020-04-14 19:04:10 +00:00
|
|
|
struct ncplane* n = ncplane_new(nc_, 2, 20, 1, 1, nullptr);
|
|
|
|
REQUIRE(n);
|
|
|
|
// verify that the new plane was started without scrolling
|
|
|
|
CHECK(!ncplane_set_scrolling(n, true));
|
2020-04-14 19:43:42 +00:00
|
|
|
CHECK(40 == ncplane_putstr(n, out)); // fill up the plane w/ numbers
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
int y, x;
|
|
|
|
ncplane_cursor_yx(n, &y, &x);
|
2020-04-15 00:17:52 +00:00
|
|
|
CHECK(1 == y);
|
|
|
|
CHECK(20 == x);
|
|
|
|
CHECK(20 == ncplane_putstr(n, onext)); // scroll off one line, fill new one
|
|
|
|
ncplane_cursor_yx(n, &y, &x);
|
|
|
|
CHECK(1 == y);
|
|
|
|
CHECK(20 == x);
|
2020-04-14 19:43:42 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
for(int i = 1 ; i < 21 ; ++i){
|
|
|
|
uint32_t attr;
|
|
|
|
uint64_t channels;
|
|
|
|
char* egc = notcurses_at_yx(nc_, 2, i, &attr, &channels);
|
|
|
|
REQUIRE(egc);
|
|
|
|
CHECK(onext[i - 1] == *egc);
|
|
|
|
free(egc);
|
|
|
|
}
|
2020-04-15 00:17:52 +00:00
|
|
|
ncplane_cursor_yx(n, &y, &x);
|
|
|
|
CHECK(1 == y);
|
|
|
|
CHECK(20 == x);
|
2020-04-14 19:43:42 +00:00
|
|
|
CHECK(10 == ncplane_putstr(n, next2));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
for(int i = 1 ; i < 21 ; ++i){
|
|
|
|
uint32_t attr;
|
|
|
|
uint64_t channels;
|
|
|
|
char* egc = notcurses_at_yx(nc_, 2, i, &attr, &channels);
|
|
|
|
REQUIRE(egc);
|
|
|
|
if(i < 11){
|
|
|
|
CHECK(next2[i - 1] == *egc);
|
|
|
|
}else{
|
|
|
|
CHECK(' ' == *egc);
|
|
|
|
}
|
|
|
|
free(egc);
|
|
|
|
}
|
2020-04-15 00:17:52 +00:00
|
|
|
ncplane_cursor_yx(n, &y, &x);
|
|
|
|
CHECK(1 == y);
|
|
|
|
CHECK(10 == x);
|
2020-04-14 19:43:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// make sure that, after scrolling a line up, our y specifications are
|
|
|
|
// correctly adjusted for scrolling.
|
|
|
|
SUBCASE("XYPostScroll") {
|
|
|
|
const char* out = "0123456789012345678901234567890123456789";
|
|
|
|
const char* onext = "ABCDEFGHIJ";
|
2020-04-15 20:36:17 +00:00
|
|
|
//const char* next2 = "KLMNOPQRST";
|
|
|
|
//const char* next3 = "UVWXYZ";
|
2020-04-14 19:43:42 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
struct ncplane* n = ncplane_new(nc_, 2, 20, 1, 1, nullptr);
|
|
|
|
REQUIRE(n);
|
|
|
|
// verify that the new plane was started without scrolling
|
|
|
|
CHECK(!ncplane_set_scrolling(n, true));
|
2020-04-14 19:04:10 +00:00
|
|
|
CHECK(40 == ncplane_putstr(n, out));
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-04-14 19:43:42 +00:00
|
|
|
CHECK(10 == ncplane_putstr(n, onext));
|
2020-04-14 19:04:10 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-04-14 19:41:13 +00:00
|
|
|
for(int i = 1 ; i < 21 ; ++i){
|
|
|
|
uint32_t attr;
|
|
|
|
uint64_t channels;
|
|
|
|
char* egc = notcurses_at_yx(nc_, 2, i, &attr, &channels);
|
|
|
|
REQUIRE(egc);
|
2020-04-14 19:43:42 +00:00
|
|
|
if(i < 11){
|
|
|
|
CHECK(onext[i - 1] == *egc);
|
2020-04-14 19:41:13 +00:00
|
|
|
}else{
|
|
|
|
CHECK(' ' == *egc);
|
|
|
|
}
|
|
|
|
free(egc);
|
|
|
|
}
|
2020-04-14 19:43:42 +00:00
|
|
|
// FIXME
|
2020-04-14 19:04:10 +00:00
|
|
|
}
|
2020-04-06 01:10:48 +00:00
|
|
|
|
|
|
|
CHECK(0 == notcurses_stop(nc_));
|
|
|
|
|
|
|
|
}
|