1 #include "main.h" 2 3 TEST_CASE("Geometry") { 4 auto nc_ = testing_notcurses(); 5 if(!nc_){ 6 return; 7 } 8 ncplane* n_ = notcurses_stdplane(nc_); 9 REQUIRE(n_); 10 11 SUBCASE("Center") { 12 const struct test { 13 unsigned leny, lenx; // geometries 14 int centy, centx; // pre-calculated centers 15 } tests[] = { 16 { 1, 1, 0, 0, }, 17 { 1, 2, 0, 0, }, 18 { 3, 1, 1, 0, }, { 1, 3, 0, 1, }, { 2, 3, 0, 1, }, { 3, 2, 1, 0, }, { 3, 3, 1, 1, }, 19 { 4, 1, 1, 0, }, { 1, 4, 0, 1, }, { 2, 4, 0, 1, }, { 4, 2, 0, 1, }, { 3, 4, 1, 1, }, 20 { 4, 3, 1, 1, }, { 4, 4, 1, 1, }, { 4, 4, 1, 1, }, 21 { 5, 1, 2, 0, }, { 1, 5, 0, 2, }, { 2, 5, 0, 2, }, { 5, 2, 2, 1, }, { 3, 5, 1, 2, }, 22 { 5, 3, 2, 1, }, { 4, 5, 1, 2, }, { 5, 4, 2, 1, }, { 5, 5, 2, 2, }, 23 { 0, 0, 0, 0, } 24 }, *t; 25 for(t = tests ; !t->leny ; ++t){ 26 struct ncplane_options nopts = { 27 .y = 0, 28 .x = 0, 29 .rows = t->leny, 30 .cols = t->lenx, 31 .userptr = nullptr, 32 .name = nullptr, 33 .resizecb = nullptr, 34 .flags = 0, 35 .margin_b = 0, .margin_r = 0, 36 }; 37 auto n = ncplane_create(n_, &nopts); 38 REQUIRE(n); 39 nccell tl = NCCELL_TRIVIAL_INITIALIZER, tr = NCCELL_TRIVIAL_INITIALIZER; 40 nccell bl = NCCELL_TRIVIAL_INITIALIZER, br = NCCELL_TRIVIAL_INITIALIZER; 41 nccell hl = NCCELL_TRIVIAL_INITIALIZER, vl = NCCELL_TRIVIAL_INITIALIZER; 42 CHECK(0 == nccells_double_box(n, 0, 0, &tl, &tr, &bl, &br, &hl, &vl)); 43 CHECK(0 <= ncplane_perimeter(n, &tl, &tr, &bl, &br, &hl, &vl, 0)); 44 CHECK(0 == notcurses_render(nc_)); 45 int y, x; 46 ncplane_center(n, &y, &x); 47 CHECK(y == t->centy); 48 CHECK(x == t->centx); 49 CHECK(0 == ncplane_destroy(n)); 50 } 51 } 52 53 SUBCASE("CenterAbs") { 54 const struct test { 55 unsigned leny, lenx; // geometries 56 int absy, absx; // location of the origin 57 int centy, centx; // pre-calculated centers 58 } tests[] = { 59 { 1, 1, 10, 20, 0, 0, }, 60 { 1, 2, 10, 20, 0, 0, }, 61 { 3, 1, 10, 20, 1, 0, }, { 1, 3, 10, 20, 0, 1, }, { 2, 3, 10, 20, 0, 1, }, 62 { 3, 2, 10, 20, 1, 0, }, { 3, 3, 10, 20, 1, 1, }, 63 { 4, 1, 10, 20, 1, 0, }, { 1, 4, 10, 20, 0, 1, }, { 2, 4, 10, 20, 0, 1, }, 64 { 4, 2, 10, 20, 0, 1, }, { 3, 4, 10, 20, 1, 1, }, 65 { 4, 3, 10, 20, 1, 1, }, { 4, 4, 10, 20, 1, 1, }, { 4, 4, 10, 20, 1, 1, }, 66 { 5, 1, 10, 20, 2, 0, }, { 1, 5, 10, 20, 0, 2, }, { 2, 5, 10, 20, 0, 2, }, 67 { 5, 2, 10, 20, 2, 1, }, { 3, 5, 10, 20, 1, 2, }, 68 { 5, 3, 10, 20, 2, 1, }, { 4, 5, 10, 20, 1, 2, }, { 5, 4, 10, 20, 2, 1, }, 69 { 5, 5, 10, 20, 2, 2, }, 70 { 0, 0, 10, 20, 0, 0, } 71 }, *t; 72 for(t = tests ; !t->leny ; ++t){ 73 struct ncplane_options nopts = { 74 .y = t->absy, 75 .x = t->absx, 76 .rows = t->leny, 77 .cols = t->lenx, 78 .userptr = nullptr, 79 .name = nullptr, 80 .resizecb = nullptr, 81 .flags = 0, 82 .margin_b = 0, .margin_r = 0, 83 }; 84 auto n = ncplane_create(n_, &nopts); 85 REQUIRE(n); 86 nccell tl = NCCELL_TRIVIAL_INITIALIZER, tr = NCCELL_TRIVIAL_INITIALIZER; 87 nccell bl = NCCELL_TRIVIAL_INITIALIZER, br = NCCELL_TRIVIAL_INITIALIZER; 88 nccell hl = NCCELL_TRIVIAL_INITIALIZER, vl = NCCELL_TRIVIAL_INITIALIZER; 89 CHECK(0 == nccells_double_box(n, 0, 0, &tl, &tr, &bl, &br, &hl, &vl)); 90 CHECK(0 <= ncplane_perimeter(n, &tl, &tr, &bl, &br, &hl, &vl, 0)); 91 CHECK(0 == notcurses_render(nc_)); 92 int y, x; 93 ncplane_center_abs(n, &y, &x); 94 CHECK(y == t->centy + t->absy); 95 CHECK(x == t->centx + t->absx); 96 ncplane_center(n, &y, &x); 97 CHECK(y == t->centy); 98 CHECK(x == t->centx); 99 CHECK(0 == ncplane_destroy(n)); 100 } 101 } 102 103 CHECK(0 == notcurses_stop(nc_)); 104 105 } 106