ncplane: unit tests for rgb

This commit is contained in:
nick black 2019-11-21 07:46:19 -05:00 committed by Nick Black
parent c8d11459ec
commit 1fb1be6a4d

View File

@ -11,6 +11,8 @@ class NcplaneTest : public :: testing::Test {
nopts.outfd = STDIN_FILENO;
nc_ = notcurses_init(&nopts);
ASSERT_NE(nullptr, nc_);
n_ = notcurses_stdplane(nc_);
ASSERT_NE(nullptr, n_);
}
void TearDown() override {
@ -18,38 +20,57 @@ class NcplaneTest : public :: testing::Test {
}
struct notcurses* nc_;
struct ncplane* n_;
};
TEST_F(NcplaneTest, RetrieveStdPlane) {
EXPECT_NE(nullptr, notcurses_stdplane(nc_));
// Dimensions of the standard plane ought be the same as those of the context
TEST_F(NcplaneTest, StdPlaneDimensions) {
int cols, rows;
notcurses_term_dimensions(nc_, &rows, &cols);
int ncols, nrows;
ncplane_dimensions(n_, &nrows, &ncols);
EXPECT_EQ(rows, nrows);
EXPECT_EQ(cols, ncols);
}
// Verify that we can move to all four coordinates of the standard plane
TEST_F(NcplaneTest, MoveStdPlaneDimensions) {
auto n = notcurses_stdplane(nc_);
ASSERT_NE(nullptr, n);
int cols, rows;
notcurses_term_dimensions(nc_, &rows, &cols);
EXPECT_EQ(0, ncplane_move(n, 0, 0));
EXPECT_EQ(0, ncplane_move(n, cols - 1, 0));
EXPECT_EQ(0, ncplane_move(n, cols - 1, rows - 1));
EXPECT_EQ(0, ncplane_move(n, 0, rows - 1));
EXPECT_EQ(0, ncplane_move(n_, 0, 0));
EXPECT_EQ(0, ncplane_move(n_, cols - 1, 0));
EXPECT_EQ(0, ncplane_move(n_, cols - 1, rows - 1));
EXPECT_EQ(0, ncplane_move(n_, 0, rows - 1));
}
// Verify that we can move to all four coordinates of the standard plane
TEST_F(NcplaneTest, MoveBeyondPlaneFails) {
auto n = notcurses_stdplane(nc_);
ASSERT_NE(nullptr, n);
int cols, rows;
notcurses_term_dimensions(nc_, &rows, &cols);
EXPECT_NE(0, ncplane_move(n, -1, 0));
EXPECT_NE(0, ncplane_move(n, -1, -1));
EXPECT_NE(0, ncplane_move(n, 0, -1));
EXPECT_NE(0, ncplane_move(n, cols - 1, -1));
EXPECT_NE(0, ncplane_move(n, cols, 0));
EXPECT_NE(0, ncplane_move(n, cols + 1, 0));
EXPECT_NE(0, ncplane_move(n, cols, rows));
EXPECT_NE(0, ncplane_move(n, -1, rows - 1));
EXPECT_NE(0, ncplane_move(n, 0, rows));
EXPECT_NE(0, ncplane_move(n, 0, rows + 1));
EXPECT_NE(0, ncplane_move(n_, -1, 0));
EXPECT_NE(0, ncplane_move(n_, -1, -1));
EXPECT_NE(0, ncplane_move(n_, 0, -1));
EXPECT_NE(0, ncplane_move(n_, cols - 1, -1));
EXPECT_NE(0, ncplane_move(n_, cols, 0));
EXPECT_NE(0, ncplane_move(n_, cols + 1, 0));
EXPECT_NE(0, ncplane_move(n_, cols, rows));
EXPECT_NE(0, ncplane_move(n_, -1, rows - 1));
EXPECT_NE(0, ncplane_move(n_, 0, rows));
EXPECT_NE(0, ncplane_move(n_, 0, rows + 1));
}
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));
}