2019-11-24 17:36:46 +00:00
|
|
|
#include <notcurses.h>
|
2019-11-27 15:43:03 +00:00
|
|
|
#include "egcpool.h"
|
2019-11-24 17:36:46 +00:00
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
class CellTest : public :: testing::Test {
|
|
|
|
protected:
|
|
|
|
void SetUp() override {
|
2019-12-12 13:59:16 +00:00
|
|
|
setlocale(LC_ALL, "");
|
2019-11-24 17:36:46 +00:00
|
|
|
if(getenv("TERM") == nullptr){
|
|
|
|
GTEST_SKIP();
|
|
|
|
}
|
|
|
|
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-24 17:36:46 +00:00
|
|
|
ASSERT_NE(nullptr, nc_);
|
|
|
|
n_ = notcurses_stdplane(nc_);
|
|
|
|
ASSERT_NE(nullptr, n_);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-24 17:36:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct notcurses* nc_{};
|
|
|
|
struct ncplane* n_{};
|
2019-12-12 12:59:48 +00:00
|
|
|
FILE* outfp_{};
|
2019-11-24 17:36:46 +00:00
|
|
|
};
|
|
|
|
|
2019-12-14 23:02:58 +00:00
|
|
|
TEST_F(CellTest, LoadSimple) {
|
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
ASSERT_EQ(1, cell_load(n_, &c, " "));
|
|
|
|
EXPECT_TRUE(cell_simple_p(&c));
|
|
|
|
cell_release(n_, &c);
|
|
|
|
}
|
|
|
|
|
2019-12-10 13:50:32 +00:00
|
|
|
TEST_F(CellTest, SetItalic) {
|
2019-12-14 23:02:58 +00:00
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
2019-11-29 09:57:09 +00:00
|
|
|
int dimy, dimx;
|
|
|
|
notcurses_term_dim_yx(nc_, &dimy, &dimx);
|
2019-11-28 18:04:46 +00:00
|
|
|
cell_styles_set(&c, CELL_STYLE_ITALIC);
|
2019-12-10 13:50:32 +00:00
|
|
|
ASSERT_EQ(1, cell_load(n_, &c, "i"));
|
2019-12-14 10:33:34 +00:00
|
|
|
cell_set_fg_rgb(&c, 255, 255, 255);
|
2019-12-14 22:34:10 +00:00
|
|
|
ncplane_set_default(n_, &c);
|
2019-12-10 13:50:32 +00:00
|
|
|
cell_release(n_, &c);
|
2019-11-24 20:32:38 +00:00
|
|
|
EXPECT_EQ(0, notcurses_render(nc_));
|
2019-11-29 10:37:41 +00:00
|
|
|
cell_styles_off(&c, CELL_STYLE_ITALIC);
|
2019-12-10 13:50:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CellTest, SetBold) {
|
2019-12-14 23:02:58 +00:00
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
2019-12-10 13:50:32 +00:00
|
|
|
int dimy, dimx;
|
|
|
|
notcurses_term_dim_yx(nc_, &dimy, &dimx);
|
|
|
|
cell_styles_set(&c, CELL_STYLE_BOLD);
|
|
|
|
ASSERT_EQ(1, cell_load(n_, &c, "b"));
|
2019-12-14 10:33:34 +00:00
|
|
|
cell_set_fg_rgb(&c, 255, 255, 255);
|
2019-12-14 22:34:10 +00:00
|
|
|
ncplane_set_default(n_, &c);
|
2019-12-10 13:50:32 +00:00
|
|
|
cell_release(n_, &c);
|
|
|
|
EXPECT_EQ(0, notcurses_render(nc_));
|
|
|
|
cell_styles_off(&c, CELL_STYLE_BOLD);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CellTest, SetUnderline) {
|
2019-12-14 23:02:58 +00:00
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
2019-12-10 13:50:32 +00:00
|
|
|
int dimy, dimx;
|
|
|
|
notcurses_term_dim_yx(nc_, &dimy, &dimx);
|
|
|
|
cell_styles_set(&c, CELL_STYLE_UNDERLINE);
|
|
|
|
ASSERT_EQ(1, cell_load(n_, &c, "u"));
|
2019-12-14 10:33:34 +00:00
|
|
|
cell_set_fg_rgb(&c, 255, 255, 255);
|
2019-12-14 22:34:10 +00:00
|
|
|
ncplane_set_default(n_, &c);
|
2019-12-10 13:50:32 +00:00
|
|
|
cell_release(n_, &c);
|
2019-11-29 10:37:41 +00:00
|
|
|
EXPECT_EQ(0, notcurses_render(nc_));
|
2019-12-10 13:50:32 +00:00
|
|
|
cell_styles_off(&c, CELL_STYLE_UNDERLINE);
|
2019-11-24 17:36:46 +00:00
|
|
|
}
|
2019-11-27 15:43:03 +00:00
|
|
|
|
|
|
|
/*TEST_F(CellTest, CellLoadTamil) {
|
|
|
|
const char zerodeg[] = "\u0bb8\u0bc0\u0bb0\u0bc7\u0bb3\u0b95\u0bbf\u0b95\u0bbf\u0bb0\u0bbf";
|
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
size_t ulen = cell_load(n_, &c, zerodeg);
|
|
|
|
// First have U+0BB8 TAMIL LETTER SA U+0BC0 TAMIL VOWEL SIGN II
|
|
|
|
// // e0 ae b8 e0 af 80
|
|
|
|
ASSERT_EQ(6, ulen);
|
|
|
|
ulen = cell_load(n_, &c, zerodeg + ulen);
|
|
|
|
// U+0BB0 TAMIL LETTER RA U+0BCB TAMIL VOWEL SIGN OO
|
|
|
|
// e0 ae b0 e0 af 8b
|
|
|
|
ASSERT_EQ(6, ulen);
|
|
|
|
// FIXME
|
|
|
|
}*/
|
2019-12-08 18:00:19 +00:00
|
|
|
|
|
|
|
TEST_F(CellTest, CellSetFGAlpha){
|
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
2019-12-14 10:33:34 +00:00
|
|
|
EXPECT_GT(0, cell_set_fg_alpha(&c, -1));
|
|
|
|
EXPECT_GT(0, cell_set_fg_alpha(&c, 4));
|
2019-12-21 21:08:24 +00:00
|
|
|
EXPECT_EQ(0, cell_set_fg_alpha(&c, CELL_ALPHA_OPAQUE));
|
|
|
|
EXPECT_EQ(CELL_ALPHA_OPAQUE, cell_get_fg_alpha(&c));
|
|
|
|
EXPECT_EQ(0, cell_set_fg_alpha(&c, CELL_ALPHA_HIGHCONTRAST));
|
|
|
|
EXPECT_EQ(CELL_ALPHA_HIGHCONTRAST, cell_get_fg_alpha(&c));
|
2019-12-08 18:00:19 +00:00
|
|
|
EXPECT_TRUE(cell_fg_default_p(&c));
|
|
|
|
EXPECT_TRUE(cell_bg_default_p(&c));
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CellTest, CellSetBGAlpha){
|
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
2019-12-14 10:33:34 +00:00
|
|
|
EXPECT_GT(0, cell_set_bg_alpha(&c, -1));
|
|
|
|
EXPECT_GT(0, cell_set_bg_alpha(&c, 4));
|
2019-12-21 21:08:24 +00:00
|
|
|
EXPECT_EQ(0, cell_set_bg_alpha(&c, CELL_ALPHA_OPAQUE));
|
|
|
|
EXPECT_EQ(CELL_ALPHA_OPAQUE, cell_get_bg_alpha(&c));
|
|
|
|
EXPECT_NE(0, cell_set_bg_alpha(&c, CELL_ALPHA_HIGHCONTRAST));
|
|
|
|
EXPECT_EQ(0, cell_set_bg_alpha(&c, CELL_ALPHA_TRANSPARENT));
|
|
|
|
EXPECT_EQ(CELL_ALPHA_TRANSPARENT, cell_get_bg_alpha(&c));
|
2019-12-08 18:00:19 +00:00
|
|
|
EXPECT_TRUE(cell_fg_default_p(&c));
|
|
|
|
EXPECT_TRUE(cell_bg_default_p(&c));
|
|
|
|
}
|