2020-01-15 11:14:08 +00:00
|
|
|
#include "main.h"
|
|
|
|
|
|
|
|
TEST_CASE("Palette256") {
|
|
|
|
// common initialization
|
|
|
|
if(getenv("TERM") == nullptr){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FILE* outfp_{};
|
|
|
|
outfp_ = fopen("/dev/tty", "wb");
|
|
|
|
REQUIRE(nullptr != outfp_);
|
|
|
|
notcurses_options nopts{};
|
|
|
|
nopts.inhibit_alternate_screen = true;
|
|
|
|
nopts.suppress_banner = true;
|
|
|
|
struct notcurses* nc_ = notcurses_init(&nopts, outfp_);
|
2020-02-09 03:58:46 +00:00
|
|
|
REQUIRE(nc_);
|
2020-01-15 11:14:08 +00:00
|
|
|
struct ncplane* n_ = notcurses_stdplane(nc_);
|
2020-02-09 03:58:46 +00:00
|
|
|
REQUIRE(n_);
|
2020-01-15 11:14:08 +00:00
|
|
|
|
|
|
|
SUBCASE("AllocAndFree") {
|
2020-01-19 01:42:29 +00:00
|
|
|
palette256* p = palette256_new(nc_);
|
2020-01-15 11:14:08 +00:00
|
|
|
REQUIRE(nullptr != p);
|
|
|
|
palette256_free(p);
|
|
|
|
}
|
|
|
|
|
2020-01-15 11:25:13 +00:00
|
|
|
SUBCASE("SetIndexZero") {
|
2020-01-19 01:42:29 +00:00
|
|
|
palette256* p = palette256_new(nc_);
|
2020-01-15 11:25:13 +00:00
|
|
|
REQUIRE(nullptr != p);
|
|
|
|
palette256_set_rgb(p, 0, 0x80, 0x90, 0xa0);
|
|
|
|
unsigned r, g, b;
|
2020-01-19 01:42:29 +00:00
|
|
|
palette256_get_rgb(p, 0, &r, &g, &b);
|
2020-01-15 11:25:13 +00:00
|
|
|
CHECK(r == 0x80);
|
|
|
|
CHECK(g == 0x90);
|
|
|
|
CHECK(b == 0xa0);
|
|
|
|
palette256_free(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
SUBCASE("SetIndex255") {
|
2020-01-19 01:42:29 +00:00
|
|
|
palette256* p = palette256_new(nc_);
|
2020-01-15 11:25:13 +00:00
|
|
|
REQUIRE(nullptr != p);
|
|
|
|
palette256_set_rgb(p, 255, 0xa0, 0x70, 0x50);
|
|
|
|
unsigned r, g, b;
|
2020-01-19 01:42:29 +00:00
|
|
|
palette256_get_rgb(p, 255, &r, &g, &b);
|
2020-01-15 11:25:13 +00:00
|
|
|
CHECK(r == 0xa0);
|
|
|
|
CHECK(g == 0x70);
|
|
|
|
CHECK(b == 0x50);
|
|
|
|
palette256_free(p);
|
|
|
|
}
|
|
|
|
|
2020-01-15 12:15:45 +00:00
|
|
|
// when we set a palette index, it ought change us from using default
|
2020-01-19 01:42:29 +00:00
|
|
|
SUBCASE("FAttributes") {
|
2020-01-15 12:15:45 +00:00
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
CHECK(cell_fg_default_p(&c));
|
2020-01-19 01:42:29 +00:00
|
|
|
cell_set_fg_alpha(&c, CELL_ALPHA_TRANSPARENT);
|
2020-01-15 12:15:45 +00:00
|
|
|
CHECK(0 == cell_set_fg_palindex(&c, 0x20));
|
|
|
|
CHECK(!cell_fg_default_p(&c));
|
2020-01-19 01:42:29 +00:00
|
|
|
CHECK(cell_fg_palindex_p(&c));
|
2020-01-17 16:49:21 +00:00
|
|
|
CHECK(CELL_ALPHA_OPAQUE == cell_fg_alpha(&c));
|
2020-01-15 12:15:45 +00:00
|
|
|
CHECK(0x20 == cell_fg_palindex(&c));
|
|
|
|
}
|
|
|
|
|
2020-01-19 01:42:29 +00:00
|
|
|
SUBCASE("BAttributes") {
|
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
CHECK(cell_bg_default_p(&c));
|
|
|
|
cell_set_bg_alpha(&c, CELL_ALPHA_TRANSPARENT);
|
|
|
|
CHECK(0 == cell_set_bg_palindex(&c, 0x20));
|
|
|
|
CHECK(!cell_bg_default_p(&c));
|
|
|
|
CHECK(cell_bg_palindex_p(&c));
|
|
|
|
CHECK(CELL_ALPHA_OPAQUE == cell_bg_alpha(&c));
|
|
|
|
CHECK(0x20 == cell_bg_palindex(&c));
|
|
|
|
}
|
|
|
|
|
|
|
|
// write it to an ncplane, and verify attributes via reflection
|
|
|
|
SUBCASE("PutCAttrs") {
|
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
2020-01-19 09:04:13 +00:00
|
|
|
cell_load_simple(n_, &c, 'X');
|
2020-01-19 01:42:29 +00:00
|
|
|
CHECK(0 == cell_set_fg_palindex(&c, 0x20));
|
|
|
|
CHECK(0 == cell_set_bg_palindex(&c, 0x40));
|
|
|
|
CHECK(0 < ncplane_putc_yx(n_, 0, 0, &c));
|
|
|
|
cell_release(n_, &c);
|
|
|
|
cell r = CELL_TRIVIAL_INITIALIZER;
|
2020-04-18 04:09:14 +00:00
|
|
|
CHECK(0 < ncplane_at_yx_cell(n_, 0, 0, &r));
|
2020-01-19 01:42:29 +00:00
|
|
|
CHECK(cell_fg_palindex_p(&r));
|
|
|
|
CHECK(cell_bg_palindex_p(&r));
|
|
|
|
CHECK(CELL_ALPHA_OPAQUE == cell_fg_alpha(&r));
|
|
|
|
CHECK(CELL_ALPHA_OPAQUE == cell_bg_alpha(&r));
|
|
|
|
CHECK(0x20 == cell_fg_palindex(&r));
|
|
|
|
CHECK(0x40 == cell_bg_palindex(&r));
|
|
|
|
cell_release(n_, &r);
|
|
|
|
}
|
|
|
|
|
|
|
|
SUBCASE("RenderCAttrs") {
|
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
2020-01-19 09:04:13 +00:00
|
|
|
cell_load_simple(n_, &c, 'X');
|
2020-01-19 01:42:29 +00:00
|
|
|
CHECK(0 == cell_set_fg_palindex(&c, 0x20));
|
|
|
|
CHECK(0 == cell_set_bg_palindex(&c, 0x40));
|
2020-01-19 09:04:13 +00:00
|
|
|
CHECK(0 == ncplane_set_fg_palindex(n_, 0x20));
|
|
|
|
CHECK(0 == ncplane_set_bg_palindex(n_, 0x40));
|
2020-01-19 01:42:29 +00:00
|
|
|
CHECK(0 < ncplane_putc_yx(n_, 0, 0, &c));
|
|
|
|
cell_release(n_, &c);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
cell r = CELL_TRIVIAL_INITIALIZER;
|
2020-03-27 07:49:13 +00:00
|
|
|
CHECK(nullptr != notcurses_at_yx(nc_, 0, 0, &r.attrword, &r.channels));
|
2020-01-19 01:42:29 +00:00
|
|
|
CHECK(cell_fg_palindex_p(&r));
|
|
|
|
CHECK(cell_bg_palindex_p(&r));
|
|
|
|
CHECK(CELL_ALPHA_OPAQUE == cell_fg_alpha(&r));
|
|
|
|
CHECK(CELL_ALPHA_OPAQUE == cell_bg_alpha(&r));
|
|
|
|
CHECK(0x20 == cell_fg_palindex(&r));
|
|
|
|
CHECK(0x40 == cell_bg_palindex(&r));
|
|
|
|
cell_release(n_, &r);
|
|
|
|
}
|
|
|
|
|
2020-01-15 11:14:08 +00:00
|
|
|
// common teardown
|
|
|
|
CHECK(0 == notcurses_stop(nc_));
|
|
|
|
CHECK(0 == fclose(outfp_));
|
|
|
|
}
|
|
|
|
|