mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 09:09:03 -04:00
[visual] extrinsic geometry unit tests
This commit is contained in:
parent
4028d3f56a
commit
b19847a06a
2
NEWS.md
2
NEWS.md
@ -18,6 +18,8 @@ rearrangements of Notcurses.
|
||||
deprecated, and will be removed in ABI3. It furthermore exposes some of
|
||||
the information previously available only from `ncplane_pixelgeom()`,
|
||||
though that function continues to be supported.
|
||||
* `ncvgeom`'s `rcelly` and `rcellx` fields are now (finally) filled in
|
||||
by `ncvisual_geom()` (and thus `ncdirectf_geom()`), and suitable for use.
|
||||
* On transition between `ncplane`s (on terminals implementing complex wide
|
||||
glyphs), Notcurses now always issues an `hpa` sequence to force horizontal
|
||||
positioning. This fixes a number of longstanding bugs in e.g. the
|
||||
|
@ -2910,7 +2910,9 @@ typedef struct ncvgeom {
|
||||
// all-purpose ncvisual geometry solver. one or both of 'nc' and 'n' must be
|
||||
// non-NULL. if 'nc' is NULL, only pixy/pixx will be filled in, with the true
|
||||
// pixel geometry of 'n'. if 'n' is NULL, only cdimy/cdimx, blitter,
|
||||
// scaley/scalex, and (if applicable) maxpixely/maxpixelx are filled in.
|
||||
// scaley/scalex, and maxpixely/maxpixelx are filled in; this is the same as
|
||||
// calling with a NULL 'n' and a default 'vopts'. cdimy/cdimx and
|
||||
// maxpixely/maxpixelx are only ever filled in if we know them.
|
||||
API int ncvisual_geom(const struct notcurses* nc, const struct ncvisual* n,
|
||||
const struct ncvisual_options* vopts, ncvgeom* geom)
|
||||
__attribute__ ((nonnull (4)));
|
||||
|
@ -313,9 +313,12 @@ int ncvisual_geom_inner(const tinfo* ti, const ncvisual* n,
|
||||
if((geom->blitter = bset->geom) == NCBLIT_PIXEL){
|
||||
geom->maxpixely = ti->sixel_maxy_pristine;
|
||||
geom->maxpixelx = ti->sixel_maxx;
|
||||
geom->scaley = ti->cellpixy;
|
||||
geom->scalex = ti->cellpixx;
|
||||
}else{
|
||||
geom->scaley = bset->height;
|
||||
geom->scalex = bset->width;
|
||||
}
|
||||
geom->scaley = bset->height;
|
||||
geom->scaley = bset->width;
|
||||
return 0;
|
||||
}
|
||||
// FIXME now work with full variant
|
||||
|
@ -3,6 +3,28 @@
|
||||
#include <vector>
|
||||
#include <cmath>
|
||||
|
||||
// verify results for extrinsic geometries with NULL or default vopts
|
||||
void default_visual_extrinsics(const notcurses* nc, const ncvgeom& g) {
|
||||
CHECK(0 == g.pixy);
|
||||
CHECK(0 == g.pixx);
|
||||
if(notcurses_canpixel(nc)){
|
||||
CHECK(1 <= g.cdimy);
|
||||
CHECK(1 <= g.cdimx);
|
||||
}else{
|
||||
CHECK(0 == g.cdimy);
|
||||
CHECK(0 == g.cdimx);
|
||||
}
|
||||
CHECK(1 <= g.scaley);
|
||||
CHECK(1 <= g.scalex);
|
||||
CHECK(0 == g.rpixy);
|
||||
CHECK(0 == g.rpixx);
|
||||
CHECK(0 <= g.maxpixely);
|
||||
CHECK(0 <= g.maxpixelx);
|
||||
// we never use pixel by default, and must not revolve to default
|
||||
CHECK(NCBLIT_PIXEL != g.blitter);
|
||||
CHECK(NCBLIT_DEFAULT != g.blitter);
|
||||
}
|
||||
|
||||
TEST_CASE("Visual") {
|
||||
auto nc_ = testing_notcurses();
|
||||
REQUIRE(nullptr != nc_);
|
||||
@ -36,6 +58,7 @@ TEST_CASE("Visual") {
|
||||
REQUIRE(nullptr != ncv);
|
||||
ncvgeom g{};
|
||||
CHECK(0 == ncvisual_geom(nullptr, ncv, nullptr, &g));
|
||||
ncvisual_destroy(ncv);
|
||||
CHECK(2 == g.pixy);
|
||||
CHECK(10 == g.pixx);
|
||||
CHECK(0 == g.cdimy);
|
||||
@ -49,6 +72,47 @@ TEST_CASE("Visual") {
|
||||
CHECK(NCBLIT_DEFAULT == g.blitter);
|
||||
}
|
||||
|
||||
// ncvisual_geom() with a NULL ncvisual and NULL visual_options
|
||||
SUBCASE("VisualExtrinsicGeometryNULL") {
|
||||
ncvgeom g{};
|
||||
CHECK(0 == ncvisual_geom(nc_, nullptr, nullptr, &g));
|
||||
default_visual_extrinsics(nc_, g);
|
||||
}
|
||||
|
||||
// ncvisual_geom() with a NULL ncvisual and default visual_options
|
||||
SUBCASE("VisualExtrinsicGeometryDefault") {
|
||||
ncvgeom g{};
|
||||
struct ncvisual_options vopts{};
|
||||
CHECK(0 == ncvisual_geom(nc_, nullptr, &vopts, &g));
|
||||
default_visual_extrinsics(nc_, g);
|
||||
}
|
||||
|
||||
// ncvisual_geom() with a NULL ncvisual and NCBLIT_PIXEL requested
|
||||
SUBCASE("VisualExtrinsicGeometryPixel") {
|
||||
ncvgeom g{};
|
||||
struct ncvisual_options vopts{};
|
||||
vopts.blitter = NCBLIT_PIXEL;
|
||||
CHECK(0 == ncvisual_geom(nc_, nullptr, &vopts, &g));
|
||||
CHECK(0 == g.pixy);
|
||||
CHECK(0 == g.pixx);
|
||||
if(notcurses_canpixel(nc_)){
|
||||
CHECK(1 <= g.cdimy);
|
||||
CHECK(1 <= g.cdimx);
|
||||
CHECK(g.cdimy == g.scaley);
|
||||
CHECK(g.cdimx == g.scalex);
|
||||
}else{
|
||||
CHECK(0 == g.cdimy);
|
||||
CHECK(0 == g.cdimx);
|
||||
CHECK(1 <= g.scaley);
|
||||
CHECK(1 <= g.scalex);
|
||||
}
|
||||
CHECK(0 == g.rpixy);
|
||||
CHECK(0 == g.rpixx);
|
||||
CHECK(0 <= g.maxpixely);
|
||||
CHECK(0 <= g.maxpixelx);
|
||||
CHECK(NCBLIT_DEFAULT != g.blitter); // we must not revolve to default
|
||||
}
|
||||
|
||||
// check that we properly populate RGB + A -> RGBA from 35x4 (see #1806)
|
||||
SUBCASE("VisualFromRGBPacked35x4") {
|
||||
unsigned char rgb[4 * 35 * 3] = "";
|
||||
|
Loading…
x
Reference in New Issue
Block a user