2019-11-21 06:55:05 -05:00
|
|
|
#include <notcurses.h>
|
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
class NcplaneTest : public :: testing::Test {
|
|
|
|
protected:
|
|
|
|
void SetUp() override {
|
2019-11-25 13:36:16 -05:00
|
|
|
setlocale(LC_ALL, nullptr);
|
2019-11-21 06:55:05 -05:00
|
|
|
if(getenv("TERM") == nullptr){
|
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
notcurses_options nopts{};
|
|
|
|
nopts.outfd = STDIN_FILENO;
|
|
|
|
nc_ = notcurses_init(&nopts);
|
|
|
|
ASSERT_NE(nullptr, nc_);
|
2019-11-21 07:46:19 -05:00
|
|
|
n_ = notcurses_stdplane(nc_);
|
|
|
|
ASSERT_NE(nullptr, n_);
|
2019-11-25 13:36:16 -05:00
|
|
|
ASSERT_EQ(0, ncplane_cursor_move_yx(n_, 0, 0));
|
2019-11-21 06:55:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
2019-11-21 08:24:09 -05:00
|
|
|
if(nc_){
|
2019-11-23 10:42:46 -05:00
|
|
|
EXPECT_EQ(0, ncplane_fg_rgb8(n_, 255, 255, 255));
|
2019-11-21 08:24:09 -05:00
|
|
|
EXPECT_EQ(0, notcurses_render(nc_));
|
|
|
|
EXPECT_EQ(0, notcurses_stop(nc_));
|
|
|
|
}
|
2019-11-21 06:55:05 -05:00
|
|
|
}
|
|
|
|
|
2019-11-21 08:24:09 -05:00
|
|
|
struct notcurses* nc_{};
|
|
|
|
struct ncplane* n_{};
|
2019-11-21 06:55:05 -05:00
|
|
|
};
|
|
|
|
|
2019-11-21 08:19:14 -05:00
|
|
|
// Starting position ought be 0, 0 (the origin)
|
|
|
|
TEST_F(NcplaneTest, StdPlanePosition) {
|
|
|
|
int x, y;
|
2019-11-22 22:47:12 -05:00
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
2019-11-21 08:19:14 -05:00
|
|
|
EXPECT_EQ(0, x);
|
|
|
|
EXPECT_EQ(0, y);
|
|
|
|
}
|
|
|
|
|
2019-11-21 07:46:19 -05:00
|
|
|
// Dimensions of the standard plane ought be the same as those of the context
|
|
|
|
TEST_F(NcplaneTest, StdPlaneDimensions) {
|
|
|
|
int cols, rows;
|
2019-11-21 08:19:14 -05:00
|
|
|
notcurses_term_dimyx(nc_, &rows, &cols);
|
2019-11-21 07:46:19 -05:00
|
|
|
int ncols, nrows;
|
2019-11-21 08:19:14 -05:00
|
|
|
ncplane_dimyx(n_, &nrows, &ncols);
|
2019-11-21 07:46:19 -05:00
|
|
|
EXPECT_EQ(rows, nrows);
|
|
|
|
EXPECT_EQ(cols, ncols);
|
2019-11-21 06:55:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that we can move to all four coordinates of the standard plane
|
|
|
|
TEST_F(NcplaneTest, MoveStdPlaneDimensions) {
|
|
|
|
int cols, rows;
|
2019-11-21 08:19:14 -05:00
|
|
|
notcurses_term_dimyx(nc_, &rows, &cols);
|
2019-11-22 22:47:12 -05:00
|
|
|
EXPECT_EQ(0, ncplane_cursor_move_yx(n_, 0, 0));
|
2019-11-21 08:19:14 -05:00
|
|
|
int x, y;
|
2019-11-22 22:47:12 -05:00
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
2019-11-21 08:19:14 -05:00
|
|
|
EXPECT_EQ(y, 0);
|
|
|
|
EXPECT_EQ(x, 0);
|
2019-11-22 22:47:12 -05:00
|
|
|
EXPECT_EQ(0, ncplane_cursor_move_yx(n_, rows - 1, 0));
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
2019-11-21 08:19:14 -05:00
|
|
|
EXPECT_EQ(y, rows - 1);
|
|
|
|
EXPECT_EQ(x, 0);
|
2019-11-22 22:47:12 -05:00
|
|
|
EXPECT_EQ(0, ncplane_cursor_move_yx(n_, rows - 1, cols - 1));
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
2019-11-21 08:19:14 -05:00
|
|
|
EXPECT_EQ(y, rows - 1);
|
|
|
|
EXPECT_EQ(x, cols - 1);
|
2019-11-22 22:47:12 -05:00
|
|
|
EXPECT_EQ(0, ncplane_cursor_move_yx(n_, 0, cols - 1));
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
2019-11-21 08:19:14 -05:00
|
|
|
EXPECT_EQ(y, 0);
|
|
|
|
EXPECT_EQ(x, cols - 1);
|
2019-11-21 06:55:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Verify that we can move to all four coordinates of the standard plane
|
|
|
|
TEST_F(NcplaneTest, MoveBeyondPlaneFails) {
|
|
|
|
int cols, rows;
|
2019-11-21 08:19:14 -05:00
|
|
|
notcurses_term_dimyx(nc_, &rows, &cols);
|
2019-11-22 22:47:12 -05:00
|
|
|
EXPECT_NE(0, ncplane_cursor_move_yx(n_, -1, 0));
|
|
|
|
EXPECT_NE(0, ncplane_cursor_move_yx(n_, -1, -1));
|
|
|
|
EXPECT_NE(0, ncplane_cursor_move_yx(n_, 0, -1));
|
|
|
|
EXPECT_NE(0, ncplane_cursor_move_yx(n_, rows - 1, -1));
|
|
|
|
EXPECT_NE(0, ncplane_cursor_move_yx(n_, rows, 0));
|
|
|
|
EXPECT_NE(0, ncplane_cursor_move_yx(n_, rows + 1, 0));
|
|
|
|
EXPECT_NE(0, ncplane_cursor_move_yx(n_, rows, cols));
|
|
|
|
EXPECT_NE(0, ncplane_cursor_move_yx(n_, -1, cols - 1));
|
|
|
|
EXPECT_NE(0, ncplane_cursor_move_yx(n_, 0, cols));
|
|
|
|
EXPECT_NE(0, ncplane_cursor_move_yx(n_, 0, cols + 1));
|
2019-11-21 07:46:19 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(NcplaneTest, SetPlaneRGB) {
|
|
|
|
EXPECT_EQ(0, ncplane_fg_rgb8(n_, 0, 0, 0));
|
|
|
|
EXPECT_EQ(0, ncplane_fg_rgb8(n_, 255, 255, 255));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(NcplaneTest, RejectBadRGB) {
|
|
|
|
EXPECT_NE(0, ncplane_fg_rgb8(n_, -1, 0, 0));
|
|
|
|
EXPECT_NE(0, ncplane_fg_rgb8(n_, 0, -1, 0));
|
|
|
|
EXPECT_NE(0, ncplane_fg_rgb8(n_, 0, 0, -1));
|
|
|
|
EXPECT_NE(0, ncplane_fg_rgb8(n_, -1, -1, -1));
|
|
|
|
EXPECT_NE(0, ncplane_fg_rgb8(n_, 256, 255, 255));
|
|
|
|
EXPECT_NE(0, ncplane_fg_rgb8(n_, 255, 256, 255));
|
|
|
|
EXPECT_NE(0, ncplane_fg_rgb8(n_, 255, 255, 256));
|
|
|
|
EXPECT_NE(0, ncplane_fg_rgb8(n_, 256, 256, 256));
|
2019-11-21 06:55:05 -05:00
|
|
|
}
|
2019-11-21 08:19:14 -05:00
|
|
|
|
|
|
|
// Verify we can emit a wide character, and it advances the cursor
|
|
|
|
TEST_F(NcplaneTest, EmitWchar) {
|
2019-11-23 18:34:06 -05:00
|
|
|
const char cchar[] = "✔";
|
2019-11-24 15:32:38 -05:00
|
|
|
cell c{};
|
2019-11-25 13:36:16 -05:00
|
|
|
EXPECT_EQ(strlen(cchar), cell_load(n_, &c, cchar));
|
2019-11-24 15:32:38 -05:00
|
|
|
EXPECT_EQ(strlen(cchar), ncplane_putc(n_, &c));
|
2019-11-21 08:19:14 -05:00
|
|
|
int x, y;
|
2019-11-22 22:47:12 -05:00
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
2019-11-23 19:24:29 -05:00
|
|
|
EXPECT_EQ(0, y);
|
|
|
|
EXPECT_EQ(1, x);
|
2019-11-21 08:19:14 -05:00
|
|
|
}
|
2019-11-23 12:52:09 -05:00
|
|
|
|
|
|
|
// Verify we can emit a wide string, and it advances the cursor
|
2019-11-23 18:34:06 -05:00
|
|
|
TEST_F(NcplaneTest, EmitStr) {
|
|
|
|
const char s[] = "Σιβυλλα τι θελεις; respondebat illa: αποθανειν θελω.";
|
2019-11-23 19:24:29 -05:00
|
|
|
int wrote = ncplane_putstr(n_, s);
|
|
|
|
EXPECT_EQ(strlen(s), wrote);
|
2019-11-23 12:52:09 -05:00
|
|
|
int x, y;
|
|
|
|
ncplane_cursor_yx(n_, &y, &x);
|
2019-11-23 19:24:29 -05:00
|
|
|
EXPECT_EQ(0, y);
|
|
|
|
EXPECT_NE(1, x); // FIXME tighten in on this
|
2019-11-23 12:52:09 -05:00
|
|
|
}
|
2019-11-24 16:41:43 -05:00
|
|
|
|
2019-11-24 16:46:58 -05:00
|
|
|
TEST_F(NcplaneTest, HorizontalLines) {
|
|
|
|
int x, y;
|
|
|
|
ncplane_dimyx(n_, &y, &x);
|
|
|
|
ASSERT_LT(0, y);
|
|
|
|
ASSERT_LT(0, x);
|
|
|
|
cell c{};
|
|
|
|
cell_load(n_, &c, "-");
|
|
|
|
for(int yidx = 0 ; yidx < y ; ++yidx){
|
|
|
|
EXPECT_EQ(0, ncplane_cursor_move_yx(n_, yidx, 1));
|
|
|
|
EXPECT_EQ(x - 2, ncplane_hline(n_, &c, x - 2));
|
2019-11-24 16:57:53 -05:00
|
|
|
int posx, posy;
|
|
|
|
ncplane_cursor_yx(n_, &posy, &posx);
|
|
|
|
EXPECT_EQ(yidx, posy);
|
|
|
|
EXPECT_EQ(x - 1, posx);
|
|
|
|
}
|
2019-11-24 17:06:57 -05:00
|
|
|
cell_release(n_, &c);
|
2019-11-24 16:57:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(NcplaneTest, VerticalLines) {
|
|
|
|
int x, y;
|
|
|
|
ncplane_dimyx(n_, &y, &x);
|
|
|
|
ASSERT_LT(0, y);
|
|
|
|
ASSERT_LT(0, x);
|
|
|
|
cell c{};
|
|
|
|
cell_load(n_, &c, "-");
|
|
|
|
for(int xidx = 0 ; xidx < x - 1 ; ++xidx){
|
|
|
|
EXPECT_EQ(0, ncplane_cursor_move_yx(n_, 1, xidx));
|
|
|
|
EXPECT_EQ(y - 2, ncplane_vline(n_, &c, y - 2));
|
|
|
|
int posx, posy;
|
|
|
|
ncplane_cursor_yx(n_, &posy, &posx);
|
|
|
|
EXPECT_EQ(y - 2, posy);
|
|
|
|
EXPECT_EQ(xidx, posx - 1);
|
2019-11-24 16:46:58 -05:00
|
|
|
}
|
2019-11-24 17:06:57 -05:00
|
|
|
cell_release(n_, &c);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(NcplaneTest, ConcentricBoxen) {
|
|
|
|
int x, y;
|
|
|
|
ncplane_dimyx(n_, &y, &x);
|
|
|
|
ASSERT_LT(0, y);
|
|
|
|
ASSERT_LT(0, x);
|
|
|
|
cell ul{}, ll{}, lr{}, ur{}, hl{}, vl{};
|
|
|
|
cell_load(n_, &ul, "╭");
|
|
|
|
cell_load(n_, &ur, "╮");
|
|
|
|
cell_load(n_, &ll, "╰");
|
|
|
|
cell_load(n_, &lr, "╯");
|
2019-11-24 18:31:26 -05:00
|
|
|
cell_load(n_, &vl, "│");
|
|
|
|
cell_load(n_, &hl, "─");
|
2019-11-24 17:06:57 -05:00
|
|
|
EXPECT_EQ(0, ncplane_box(n_, &ul, &ur, &ll, &lr, &hl, &vl, y, x));
|
|
|
|
cell_release(n_, &vl);
|
|
|
|
cell_release(n_, &hl);
|
|
|
|
cell_release(n_, &ul);
|
|
|
|
cell_release(n_, &ll);
|
|
|
|
cell_release(n_, &ur);
|
|
|
|
cell_release(n_, &lr);
|
2019-11-24 16:46:58 -05:00
|
|
|
}
|
|
|
|
|
2019-11-24 16:41:43 -05:00
|
|
|
TEST_F(NcplaneTest, EraseScreen) {
|
|
|
|
ncplane_erase(n_);
|
|
|
|
}
|