Skip to content

Commit

Permalink
unit tests: accomodate sixel runoff
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Oct 17, 2021
1 parent 53b024e commit 1369a36
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/lib/sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ int sprixel_load(sprixel* spx, fbuf* f, int pixy, int pixx,
int parse_start, sprixel_e state){
assert(spx->n);
if(spx->cellpxy > 0){ // don't explode on ncdirect case
if((pixy + spx->cellpxy - 1) / spx->cellpxy != spx->dimy){
if((pixy + spx->cellpxy - 1) / spx->cellpxy > spx->dimy){
logerror("bad pixy %d (cellpxy %d dimy %d)\n", pixy, spx->cellpxy, spx->dimy);
return -1;
}
if((pixx + spx->cellpxx - 1) / spx->cellpxx != spx->dimx){
if((pixx + spx->cellpxx - 1) / spx->cellpxx > spx->dimx){
logerror("bad pixx %d (cellpxx %d dimx %d)\n", pixx, spx->cellpxx, spx->dimx);
return -1;
}
Expand Down
34 changes: 23 additions & 11 deletions src/tests/bitmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ TEST_CASE("Bitmaps") {
}

// create an image of exactly 1 cell, inflate it, scale it, and compare the
// resulting geometries for equality
// resulting geometries for (rough) equality
SUBCASE("InflateVsScale") {
// first, assemble a visual equivalent to 1 cell
auto y = nc_->tcache.cellpixy;
Expand All @@ -287,32 +287,44 @@ TEST_CASE("Bitmaps") {
struct ncplane_options nopts = {
.y = 2,
.x = 0,
.rows = 4,
.rows = 5,
.cols = 4,
.userptr = nullptr, .name = "scale", .resizecb = nullptr,
.flags = 0, .margin_b = 0, .margin_r = 0,
};
auto nres = ncplane_create(n_, &nopts);
REQUIRE(nullptr != nres);
vopts.n = nres;
auto scal = ncplane_create(n_, &nopts);
REQUIRE(nullptr != scal);
vopts.n = scal;
vopts.scaling = NCSCALE_SCALE;
ncvisual_blit(nc_, ncv, &vopts);
auto bmap = ncvisual_blit(nc_, ncv, &vopts);
REQUIRE(nullptr != bmap);
CHECK(4 == ncplane_dim_x(vopts.n));
CHECK(0 == ncvisual_resize_noninterpolative(ncv, ncv->pixy * 4, ncv->pixx * 4));
vopts.n = nres;
CHECK(0 == ncvisual_resize_noninterpolative(ncv, ncv->pixy * 5, ncv->pixx * 4));
vopts.n = scal;
vopts.y = 2;
vopts.x = 5;
vopts.scaling = NCSCALE_NONE;
auto ninf = ncvisual_blit(nc_, ncv, &vopts);
ncplane_set_name(ninf, "ninf");
notcurses_debug(nc_, stderr);
REQUIRE(nullptr != ninf);
CHECK(ncplane_dim_y(nres) == ncplane_dim_y(ninf));
CHECK(ncplane_dim_x(nres) == ncplane_dim_x(ninf));
// y of scaled might not be exactly equal to y of inflated since one
// is based around what can be fit into a specific space, whereas the
// other is based on a multiple of the original image size, which might
// not be a multiple of the sixel quantum.
CHECK(5 == ncplane_dim_y(scal));
if(5 >= ncplane_dim_y(ninf)){
CHECK(5 == ncplane_dim_y(ninf));
}else{
CHECK(6 == ncplane_dim_y(ninf));
}
CHECK(ncplane_dim_x(scal) == ncplane_dim_x(ninf));
CHECK(0 == notcurses_render(nc_));
ncvisual_destroy(ncv);
CHECK(0 == ncplane_destroy(n));
CHECK(0 == ncplane_destroy(ninf));
CHECK(0 == ncplane_destroy(nres));
CHECK(0 == ncplane_destroy(scal));
CHECK(0 == ncplane_destroy(bmap));
}

// test NCVISUAL_OPTIONS_CHILDPLANE + stretch + (null) alignment
Expand Down

0 comments on commit 1369a36

Please sign in to comment.