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"
|
|
|
|
|
2020-02-01 00:00:51 +00:00
|
|
|
TEST_CASE("MultibyteWidth") {
|
2020-02-07 02:52:41 +00:00
|
|
|
if(!enforce_utf8()){
|
|
|
|
return;
|
|
|
|
}
|
2020-02-01 00:00:51 +00:00
|
|
|
CHECK(0 == mbswidth("")); // zero bytes, zero columns
|
|
|
|
CHECK(-1 == mbswidth("\x7")); // single byte, non-printable
|
|
|
|
CHECK(1 == mbswidth(" ")); // single byte, one column
|
|
|
|
CHECK(5 == mbswidth("abcde")); // single byte, one column
|
|
|
|
CHECK(1 == mbswidth("µ")); // two bytes, one column
|
2020-02-09 02:38:44 +00:00
|
|
|
CHECK(2 == mbswidth("\xf0\x9f\xa6\xb2")); // four bytes, two columns
|
2020-02-01 00:00:51 +00:00
|
|
|
CHECK(6 == mbswidth("平仮名")); // nine bytes, six columns
|
|
|
|
CHECK(1 == mbswidth("\ufdfd")); // three bytes, ? columns, wcwidth() returns 1
|
|
|
|
}
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
TEST_CASE("Cell") {
|
2020-02-07 02:52:41 +00:00
|
|
|
|
|
|
|
if(!enforce_utf8()){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
// common initialization
|
|
|
|
if(getenv("TERM") == nullptr){
|
|
|
|
return;
|
2019-11-24 17:36:46 +00:00
|
|
|
}
|
2019-12-12 12:59:48 +00:00
|
|
|
FILE* outfp_{};
|
2019-12-27 22:20:20 +00:00
|
|
|
outfp_ = fopen("/dev/tty", "wb");
|
|
|
|
REQUIRE(nullptr != outfp_);
|
|
|
|
notcurses_options nopts{};
|
|
|
|
nopts.inhibit_alternate_screen = true;
|
2019-12-28 23:37:44 +00:00
|
|
|
nopts.suppress_banner = true;
|
2019-12-27 22:20:20 +00:00
|
|
|
struct notcurses* nc_ = notcurses_init(&nopts, outfp_);
|
|
|
|
REQUIRE(nullptr != nc_);
|
|
|
|
struct ncplane* n_ = notcurses_stdplane(nc_);
|
|
|
|
REQUIRE(nullptr != n_);
|
2019-11-24 17:36:46 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("LoadSimple") {
|
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
REQUIRE(1 == cell_load(n_, &c, " "));
|
|
|
|
CHECK(cell_simple_p(&c));
|
|
|
|
cell_release(n_, &c);
|
|
|
|
}
|
2019-12-14 23:02:58 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("SetItalic") {
|
2019-12-14 23:02:58 +00:00
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
2019-12-27 22:20:20 +00:00
|
|
|
int dimy, dimx;
|
|
|
|
notcurses_term_dim_yx(nc_, &dimy, &dimx);
|
2020-02-02 08:14:45 +00:00
|
|
|
cell_styles_set(&c, NCSTYLE_ITALIC);
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(1 == cell_load(n_, &c, "i"));
|
|
|
|
cell_set_fg_rgb(&c, 255, 255, 255);
|
2020-01-30 13:55:01 +00:00
|
|
|
ncplane_set_base_cell(n_, &c);
|
2019-12-27 22:20:20 +00:00
|
|
|
cell_release(n_, &c);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-02-02 08:14:45 +00:00
|
|
|
cell_styles_off(&c, NCSTYLE_ITALIC);
|
2019-12-27 22:20:20 +00:00
|
|
|
}
|
2019-12-10 13:50:32 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("SetBold") {
|
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
int dimy, dimx;
|
|
|
|
notcurses_term_dim_yx(nc_, &dimy, &dimx);
|
2020-02-02 08:14:45 +00:00
|
|
|
cell_styles_set(&c, NCSTYLE_BOLD);
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(1 == cell_load(n_, &c, "b"));
|
|
|
|
cell_set_fg_rgb(&c, 255, 255, 255);
|
2020-01-30 13:55:01 +00:00
|
|
|
ncplane_set_base_cell(n_, &c);
|
2019-12-27 22:20:20 +00:00
|
|
|
cell_release(n_, &c);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-02-02 08:14:45 +00:00
|
|
|
cell_styles_off(&c, NCSTYLE_BOLD);
|
2019-12-27 22:20:20 +00:00
|
|
|
}
|
2019-12-10 13:50:32 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("SetUnderline") {
|
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
int dimy, dimx;
|
|
|
|
notcurses_term_dim_yx(nc_, &dimy, &dimx);
|
2020-02-02 08:14:45 +00:00
|
|
|
cell_styles_set(&c, NCSTYLE_UNDERLINE);
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(1 == cell_load(n_, &c, "u"));
|
|
|
|
cell_set_fg_rgb(&c, 255, 255, 255);
|
2020-01-30 13:55:01 +00:00
|
|
|
ncplane_set_base_cell(n_, &c);
|
2019-12-27 22:20:20 +00:00
|
|
|
cell_release(n_, &c);
|
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-02-02 08:14:45 +00:00
|
|
|
cell_styles_off(&c, NCSTYLE_UNDERLINE);
|
2019-12-27 22:20:20 +00:00
|
|
|
}
|
2019-11-27 15:43:03 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
/* SUBCASE("CellLoadTamil") {
|
2019-11-27 15:43:03 +00:00
|
|
|
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
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(6 == ulen);
|
2019-11-27 15:43:03 +00:00
|
|
|
ulen = cell_load(n_, &c, zerodeg + ulen);
|
|
|
|
// U+0BB0 TAMIL LETTER RA U+0BCB TAMIL VOWEL SIGN OO
|
|
|
|
// e0 ae b0 e0 af 8b
|
2019-12-27 22:20:20 +00:00
|
|
|
REQUIRE(6 == ulen);
|
2019-11-27 15:43:03 +00:00
|
|
|
// FIXME
|
2019-12-27 22:20:20 +00:00
|
|
|
}*/
|
2019-12-08 18:00:19 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("CellSetFGAlpha"){
|
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
CHECK(0 > cell_set_fg_alpha(&c, -1));
|
|
|
|
CHECK(0 > cell_set_fg_alpha(&c, 4));
|
|
|
|
CHECK(0 == cell_set_fg_alpha(&c, CELL_ALPHA_OPAQUE));
|
2020-02-07 13:12:18 +00:00
|
|
|
CHECK(cell_fg_default_p(&c));
|
|
|
|
CHECK(cell_bg_default_p(&c));
|
2019-12-30 04:47:42 +00:00
|
|
|
CHECK(CELL_ALPHA_OPAQUE == cell_fg_alpha(&c));
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(0 == cell_set_fg_alpha(&c, CELL_ALPHA_HIGHCONTRAST));
|
2019-12-30 04:47:42 +00:00
|
|
|
CHECK(CELL_ALPHA_HIGHCONTRAST == cell_fg_alpha(&c));
|
2020-02-07 13:12:18 +00:00
|
|
|
CHECK(!cell_fg_default_p(&c));
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(cell_bg_default_p(&c));
|
|
|
|
}
|
2019-12-08 18:00:19 +00:00
|
|
|
|
2019-12-27 22:20:20 +00:00
|
|
|
SUBCASE("CellSetBGAlpha"){
|
|
|
|
cell c = CELL_TRIVIAL_INITIALIZER;
|
|
|
|
CHECK(0 > cell_set_bg_alpha(&c, -1));
|
|
|
|
CHECK(0 > cell_set_bg_alpha(&c, 4));
|
|
|
|
CHECK(0 == cell_set_bg_alpha(&c, CELL_ALPHA_OPAQUE));
|
2019-12-30 04:47:42 +00:00
|
|
|
CHECK(CELL_ALPHA_OPAQUE == cell_bg_alpha(&c));
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(0 != cell_set_bg_alpha(&c, CELL_ALPHA_HIGHCONTRAST));
|
|
|
|
CHECK(0 == cell_set_bg_alpha(&c, CELL_ALPHA_TRANSPARENT));
|
2019-12-30 04:47:42 +00:00
|
|
|
CHECK(CELL_ALPHA_TRANSPARENT == cell_bg_alpha(&c));
|
2019-12-27 22:20:20 +00:00
|
|
|
CHECK(cell_fg_default_p(&c));
|
|
|
|
CHECK(cell_bg_default_p(&c));
|
|
|
|
}
|
|
|
|
|
|
|
|
// common teardown
|
|
|
|
CHECK(0 == notcurses_stop(nc_));
|
|
|
|
CHECK(0 == fclose(outfp_));
|
2019-12-08 18:00:19 +00:00
|
|
|
}
|
2019-12-27 22:20:20 +00:00
|
|
|
|