2020-05-07 19:06:07 +00:00
|
|
|
#include "main.h"
|
|
|
|
#include <cstring>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
TEST_CASE("Readers") {
|
|
|
|
if(getenv("TERM") == nullptr){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
notcurses_options nopts{};
|
|
|
|
nopts.suppress_banner = true;
|
|
|
|
FILE* outfp_ = fopen("/dev/tty", "wb");
|
|
|
|
REQUIRE(outfp_);
|
|
|
|
struct notcurses* nc_ = notcurses_init(&nopts, outfp_);
|
|
|
|
REQUIRE(nc_);
|
|
|
|
int dimx, dimy;
|
|
|
|
struct ncplane* n_ = notcurses_stddim_yx(nc_, &dimy, &dimx);
|
|
|
|
REQUIRE(n_);
|
|
|
|
REQUIRE(0 == ncplane_cursor_move_yx(n_, 0, 0));
|
|
|
|
|
2020-05-07 19:33:36 +00:00
|
|
|
SUBCASE("ReaderBadOptions") {
|
|
|
|
ncreader_options opts{};
|
2020-05-09 12:41:19 +00:00
|
|
|
auto nr = ncreader_create(n_, 0, 0, &opts);
|
2020-05-07 19:33:36 +00:00
|
|
|
CHECK(!nr);
|
|
|
|
opts.physrows = 1;
|
2020-05-09 12:41:19 +00:00
|
|
|
nr = ncreader_create(n_, 0, 0, &opts);
|
2020-05-07 19:33:36 +00:00
|
|
|
CHECK(!nr);
|
|
|
|
opts.physcols = 1;
|
|
|
|
opts.physrows = 0;
|
2020-05-09 12:41:19 +00:00
|
|
|
nr = ncreader_create(n_, 0, 0, &opts);
|
2020-05-07 19:33:36 +00:00
|
|
|
CHECK(!nr);
|
|
|
|
}
|
|
|
|
|
2020-05-08 17:30:29 +00:00
|
|
|
SUBCASE("ReaderRender") {
|
2020-05-07 19:33:36 +00:00
|
|
|
ncreader_options opts{};
|
2020-05-08 20:16:24 +00:00
|
|
|
opts.physrows = dimy / 2;
|
2020-05-07 19:33:36 +00:00
|
|
|
opts.physcols = dimx / 2;
|
2020-05-11 08:57:20 +00:00
|
|
|
if(enforce_utf8()){
|
|
|
|
opts.egc = strdup("▒");
|
|
|
|
}else{
|
|
|
|
opts.egc = strdup("x");
|
|
|
|
}
|
2020-05-09 12:41:19 +00:00
|
|
|
auto nr = ncreader_create(n_, 0, 0, &opts);
|
2020-05-07 19:06:07 +00:00
|
|
|
REQUIRE(nullptr != nr);
|
2020-05-08 20:16:24 +00:00
|
|
|
channels_set_fg(&opts.echannels, 0xff44ff);
|
|
|
|
ncplane_set_base(n_, opts.egc, opts.eattrword, opts.echannels);
|
2020-05-08 17:30:29 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
2020-05-09 01:30:45 +00:00
|
|
|
char* contents = nullptr;
|
2020-05-08 20:16:24 +00:00
|
|
|
ncreader_destroy(nr, &contents);
|
|
|
|
REQUIRE(contents);
|
2020-05-07 19:06:07 +00:00
|
|
|
CHECK(0 == notcurses_render(nc_));
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(0 == notcurses_stop(nc_));
|
|
|
|
CHECK(0 == fclose(outfp_));
|
|
|
|
}
|