2019-11-17 15:25:40 +00:00
|
|
|
#include <string>
|
|
|
|
#include <cstdlib>
|
2019-11-17 14:53:59 +00:00
|
|
|
#include <notcurses.h>
|
2019-12-05 04:43:19 +00:00
|
|
|
#include "internal.h"
|
2019-11-17 14:53:59 +00:00
|
|
|
#include "main.h"
|
|
|
|
|
2019-11-19 01:57:33 +00:00
|
|
|
class NotcursesTest : public :: testing::Test {
|
2019-11-19 10:33:38 +00:00
|
|
|
protected:
|
2019-11-19 01:57:33 +00:00
|
|
|
void SetUp() override {
|
2019-12-12 13:59:16 +00:00
|
|
|
setlocale(LC_ALL, "");
|
2019-11-19 01:57:33 +00:00
|
|
|
if(getenv("TERM") == nullptr){
|
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
2019-11-19 14:54:14 +00:00
|
|
|
notcurses_options nopts{};
|
2019-11-29 08:25:55 +00:00
|
|
|
nopts.inhibit_alternate_screen = true;
|
2019-12-21 01:38:13 +00:00
|
|
|
nopts.suppress_bannner = true;
|
2019-12-12 12:59:48 +00:00
|
|
|
outfp_ = fopen("/dev/tty", "wb");
|
|
|
|
ASSERT_NE(nullptr, outfp_);
|
|
|
|
nc_ = notcurses_init(&nopts, outfp_);
|
2019-11-19 11:44:28 +00:00
|
|
|
ASSERT_NE(nullptr, nc_);
|
2019-11-19 01:57:33 +00:00
|
|
|
}
|
2019-11-19 10:33:38 +00:00
|
|
|
|
2019-11-23 17:28:42 +00:00
|
|
|
void TearDown() override {
|
|
|
|
if(nc_){
|
|
|
|
EXPECT_EQ(0, notcurses_stop(nc_));
|
|
|
|
}
|
2019-12-12 14:08:06 +00:00
|
|
|
if(outfp_){
|
|
|
|
fclose(outfp_);
|
|
|
|
}
|
2019-11-23 17:28:42 +00:00
|
|
|
}
|
|
|
|
|
2019-11-27 01:46:46 +00:00
|
|
|
struct notcurses* nc_{};
|
2019-12-12 12:59:48 +00:00
|
|
|
FILE* outfp_{};
|
2019-11-19 01:57:33 +00:00
|
|
|
};
|
|
|
|
|
2019-11-27 01:46:46 +00:00
|
|
|
TEST_F(NotcursesTest, NotcursesVersionString) {
|
|
|
|
const char* ver = notcurses_version();
|
|
|
|
ASSERT_NE(nullptr, ver);
|
|
|
|
ASSERT_LT(0, strlen(ver));
|
|
|
|
std::cout << "notcurses version " << ver << std::endl;
|
|
|
|
}
|
|
|
|
|
2019-11-19 01:57:33 +00:00
|
|
|
TEST_F(NotcursesTest, BasicLifetime) {
|
2019-11-17 15:25:40 +00:00
|
|
|
}
|
|
|
|
|
2019-11-19 01:57:33 +00:00
|
|
|
TEST_F(NotcursesTest, TermDimensions) {
|
2019-11-17 15:25:40 +00:00
|
|
|
int x, y;
|
2019-11-29 03:08:26 +00:00
|
|
|
notcurses_term_dim_yx(nc_, &y, &x);
|
2019-11-17 15:25:40 +00:00
|
|
|
auto stry = getenv("LINES");
|
|
|
|
if(stry){
|
|
|
|
auto envy = std::stoi(stry, nullptr);
|
|
|
|
EXPECT_EQ(envy, y);
|
|
|
|
}
|
|
|
|
auto strx = getenv("COLUMNS");
|
|
|
|
if(stry){
|
|
|
|
auto envx = std::stoi(strx, nullptr);
|
|
|
|
EXPECT_EQ(envx, x);
|
|
|
|
}
|
2019-11-17 14:53:59 +00:00
|
|
|
}
|
2019-11-21 11:38:21 +00:00
|
|
|
|
|
|
|
TEST_F(NotcursesTest, ResizeSameSize) {
|
|
|
|
int x, y;
|
2019-11-29 03:08:26 +00:00
|
|
|
notcurses_term_dim_yx(nc_, &y, &x);
|
2019-11-21 11:38:21 +00:00
|
|
|
int newx, newy;
|
2019-11-29 08:56:53 +00:00
|
|
|
EXPECT_EQ(0, notcurses_resize(nc_, &newy, &newx));
|
2019-11-21 11:38:21 +00:00
|
|
|
EXPECT_EQ(newx, x);
|
|
|
|
EXPECT_EQ(newy, y);
|
|
|
|
}
|
2019-11-23 15:42:46 +00:00
|
|
|
|
2019-11-28 20:19:54 +00:00
|
|
|
// we should at least have CELL_STYLE_BOLD everywhere, i should think?
|
2019-11-23 15:42:46 +00:00
|
|
|
TEST_F(NotcursesTest, CursesStyles) {
|
|
|
|
unsigned attrs = notcurses_supported_styles(nc_);
|
2019-11-28 20:19:54 +00:00
|
|
|
EXPECT_EQ(1, !!(CELL_STYLE_BOLD & attrs));
|
2019-11-23 15:42:46 +00:00
|
|
|
}
|
2019-11-27 22:22:13 +00:00
|
|
|
|
|
|
|
// it is an error to attempt to destroy the standard plane
|
|
|
|
TEST_F(NotcursesTest, RejectDestroyStdPlane) {
|
|
|
|
ncplane* ncp = notcurses_stdplane(nc_);
|
|
|
|
ASSERT_NE(nullptr, ncp);
|
2019-11-29 03:08:26 +00:00
|
|
|
ASSERT_NE(0, ncplane_destroy(ncp));
|
2019-11-27 22:22:13 +00:00
|
|
|
}
|
2019-11-28 20:19:54 +00:00
|
|
|
|
2019-12-10 11:02:49 +00:00
|
|
|
// it is an error to attempt to move the standard plane
|
|
|
|
TEST_F(NotcursesTest, RejectMoveStdPlane) {
|
|
|
|
ncplane* ncp = notcurses_stdplane(nc_);
|
|
|
|
ASSERT_NE(nullptr, ncp);
|
|
|
|
ASSERT_NE(0, ncplane_move_yx(ncp, 1, 1));
|
|
|
|
}
|
|
|
|
|
2019-11-28 20:19:54 +00:00
|
|
|
// create planes partitioning the entirety of the screen, one at each coordinate
|
|
|
|
TEST_F(NotcursesTest, TileScreenWithPlanes) {
|
|
|
|
int maxx, maxy;
|
2019-11-29 03:08:26 +00:00
|
|
|
notcurses_term_dim_yx(nc_, &maxy, &maxx);
|
2019-11-28 20:19:54 +00:00
|
|
|
auto total = maxx * maxy;
|
|
|
|
struct ncplane** planes = new struct ncplane*[total];
|
|
|
|
int* planesecrets = new int[total];
|
|
|
|
for(int y = 0 ; y < maxy ; ++y){
|
|
|
|
for(int x = 0 ; x < maxx ; ++x){
|
|
|
|
const auto idx = y * maxx + x;
|
|
|
|
planes[idx] = notcurses_newplane(nc_, 1, 1, y, x, &planesecrets[idx]);
|
|
|
|
ASSERT_NE(nullptr, planes[idx]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ASSERT_EQ(0, notcurses_render(nc_));
|
|
|
|
for(int y = 0 ; y < maxy ; ++y){
|
|
|
|
for(int x = 0 ; x < maxx ; ++x){
|
|
|
|
const auto idx = y * maxx + x;
|
|
|
|
auto userptr = ncplane_userptr(planes[idx]);
|
|
|
|
ASSERT_NE(nullptr, userptr);
|
|
|
|
EXPECT_EQ(userptr, &planesecrets[idx]);
|
2019-11-29 03:08:26 +00:00
|
|
|
ASSERT_EQ(0, ncplane_destroy(planes[idx]));
|
2019-11-28 20:19:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
delete[] planesecrets;
|
|
|
|
delete[] planes;
|
|
|
|
ASSERT_EQ(0, notcurses_render(nc_));
|
|
|
|
}
|
2019-12-08 18:00:19 +00:00
|
|
|
|
|
|
|
TEST_F(NotcursesTest, ChannelSetFGAlpha){
|
|
|
|
uint64_t channel = 0;
|
2019-12-14 10:33:34 +00:00
|
|
|
EXPECT_GT(0, channels_set_fg_alpha(&channel, -1));
|
|
|
|
EXPECT_GT(0, channels_set_fg_alpha(&channel, 4));
|
2019-12-21 21:08:24 +00:00
|
|
|
EXPECT_EQ(0, channels_set_fg_alpha(&channel, CELL_ALPHA_OPAQUE));
|
|
|
|
EXPECT_EQ(CELL_ALPHA_OPAQUE, channels_get_fg_alpha(channel));
|
|
|
|
EXPECT_EQ(0, channels_set_fg_alpha(&channel, CELL_ALPHA_HIGHCONTRAST));
|
|
|
|
EXPECT_EQ(CELL_ALPHA_HIGHCONTRAST, channels_get_fg_alpha(channel));
|
2019-12-14 10:33:34 +00:00
|
|
|
EXPECT_TRUE(channels_fg_default_p(channel));
|
|
|
|
EXPECT_TRUE(channels_bg_default_p(channel));
|
2019-12-08 18:00:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(NotcursesTest, ChannelSetBGAlpha){
|
|
|
|
uint64_t channel = 0;
|
2019-12-14 10:33:34 +00:00
|
|
|
EXPECT_GT(0, channels_set_bg_alpha(&channel, -1));
|
|
|
|
EXPECT_GT(0, channels_set_bg_alpha(&channel, 4));
|
2019-12-21 21:08:24 +00:00
|
|
|
EXPECT_EQ(0, channels_set_bg_alpha(&channel, CELL_ALPHA_OPAQUE));
|
2019-12-14 10:33:34 +00:00
|
|
|
EXPECT_EQ(0, channels_get_bg_alpha(channel));
|
2019-12-21 21:08:24 +00:00
|
|
|
EXPECT_EQ(0, channels_set_bg_alpha(&channel, CELL_ALPHA_TRANSPARENT));
|
|
|
|
EXPECT_NE(0, channels_set_bg_alpha(&channel, CELL_ALPHA_HIGHCONTRAST));
|
|
|
|
EXPECT_EQ(CELL_ALPHA_TRANSPARENT, channels_get_bg_alpha(channel));
|
2019-12-14 10:33:34 +00:00
|
|
|
EXPECT_TRUE(channels_fg_default_p(channel));
|
|
|
|
EXPECT_TRUE(channels_bg_default_p(channel));
|
2019-12-08 18:00:19 +00:00
|
|
|
}
|
2019-12-20 05:05:03 +00:00
|
|
|
|
|
|
|
TEST_F(NotcursesTest, Stats){
|
|
|
|
struct ncstats stats;
|
|
|
|
notcurses_stats(nc_, &stats);
|
|
|
|
EXPECT_EQ(0, stats.renders);
|
|
|
|
EXPECT_EQ(0, notcurses_render(nc_));
|
|
|
|
notcurses_stats(nc_, &stats);
|
|
|
|
EXPECT_EQ(1, stats.renders);
|
|
|
|
notcurses_reset_stats(nc_);
|
|
|
|
notcurses_stats(nc_, &stats);
|
|
|
|
EXPECT_EQ(0, stats.renders);
|
|
|
|
}
|