implement ncplane_box() and unit test #9

pull/30/head
nick black 5 years ago committed by Nick Black
parent 2b467c99af
commit d400c79870

@ -808,8 +808,51 @@ fprintf(stderr, "RETURN %d of %d\n", ret, len);
int ncplane_box(ncplane* n, const cell* ul, const cell* ur,
const cell* ll, const cell* lr, const cell* hline,
const cell* vline, int ylen, int xlen){
const cell* ll, const cell* lr, const cell* hl,
const cell* vl, int ylen, int xlen){
int yoff, xoff;
ncplane_cursor_yx(n, &yoff, &xoff);
if(xlen < 2 || ylen < 2){
return -1;
}
if(ncplane_putc(n, ul) < 0){
return -1;
}
if(xlen > 2){
if(ncplane_hline(n, hl, xlen - 2) < 0){
return -1;
}
}
if(ncplane_putc(n, ur) < 0){
return -1;
}
++yoff;
while(yoff < ylen - 1){
if(ncplane_cursor_move_yx(n, yoff, xoff)){
return -1;
}
if(ncplane_putc(n, vl) < 0){
return -1;
}
if(ncplane_cursor_move_yx(n, yoff, xoff + xlen - 1)){
return -1;
}
if(ncplane_putc(n, vl) < 0){
return -1;
}
++yoff;
}
if(ncplane_putc(n, ll) < 0){
return -1;
}
if(xlen > 2){
if(ncplane_hline(n, hl, xlen - 2) < 0){
return -1;
}
}
if(ncplane_putc(n, lr) < 0){
return -1;
}
return 0;
}

@ -138,6 +138,7 @@ TEST_F(NcplaneTest, HorizontalLines) {
EXPECT_EQ(yidx, posy);
EXPECT_EQ(x - 1, posx);
}
cell_release(n_, &c);
}
TEST_F(NcplaneTest, VerticalLines) {
@ -155,6 +156,28 @@ TEST_F(NcplaneTest, VerticalLines) {
EXPECT_EQ(y - 2, posy);
EXPECT_EQ(xidx, posx - 1);
}
cell_release(n_, &c);
}
TEST_F(NcplaneTest, ConcentricBoxen) {
int x, y;
ncplane_dimyx(n_, &y, &x);
ASSERT_LT(0, y);
ASSERT_LT(0, x);
cell ul{}, ll{}, lr{}, ur{}, hl{}, vl{};
cell_load(n_, &ul, "");
cell_load(n_, &ur, "");
cell_load(n_, &ll, "");
cell_load(n_, &lr, "");
cell_load(n_, &hl, "");
cell_load(n_, &vl, "");
EXPECT_EQ(0, ncplane_box(n_, &ul, &ur, &ll, &lr, &hl, &vl, y, x));
cell_release(n_, &vl);
cell_release(n_, &hl);
cell_release(n_, &ul);
cell_release(n_, &ll);
cell_release(n_, &ur);
cell_release(n_, &lr);
}
TEST_F(NcplaneTest, EraseScreen) {

Loading…
Cancel
Save