diff options
author | Mattias Andrée <maandree@kth.se> | 2023-02-05 12:11:30 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2023-02-05 12:16:17 +0100 |
commit | 4df563948b0c4086c7be5cb0ef453570d2ec40a0 (patch) | |
tree | 4e41e547491d6de7d4be530d45347267358d3d2e /rtgrpblib_reset_raster.c | |
parent | Add draw_linear_bezier_reference (diff) | |
download | librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket-4df563948b0c4086c7be5cb0ef453570d2ec40a0.tar.gz librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket-4df563948b0c4086c7be5cb0ef453570d2ec40a0.tar.bz2 librifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket-4df563948b0c4086c7be5cb0ef453570d2ec40a0.tar.xz |
Add tests and documentation
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'rtgrpblib_reset_raster.c')
-rw-r--r-- | rtgrpblib_reset_raster.c | 93 |
1 files changed, 91 insertions, 2 deletions
diff --git a/rtgrpblib_reset_raster.c b/rtgrpblib_reset_raster.c index 2cfef42..a3b81df 100644 --- a/rtgrpblib_reset_raster.c +++ b/rtgrpblib_reset_raster.c @@ -6,7 +6,7 @@ int rtgrpblib_reset_raster(RASTER *raster, size_t width, size_t height) { - if (!width || !height || width > raster->width * raster->height / height) { + if (!width || !height || width > raster->size / height) { errno = EINVAL; return -1; } @@ -23,7 +23,96 @@ rtgrpblib_reset_raster(RASTER *raster, size_t width, size_t height) int main(void) { - return 0; /* TODO add test */ + + RASTER *raster; + size_t i, n, size; + + raster = rtgrpblib_create_raster(10, 20); + ASSERT(raster); + ASSERT(raster->width == 10); + ASSERT(raster->height == 20); + raster->draftness = 10; + size = raster->width * raster->height; + ASSERT(raster->size == size); + + errno = 0; + ASSERT(rtgrpblib_reset_raster(raster, 10, 21) == -1); + ASSERT(errno == EINVAL); + ASSERT(raster->width == 10); + ASSERT(raster->height == 20); + ASSERT(raster->size == size); + ASSERT(raster->draftness == 10); + + errno = 0; + ASSERT(rtgrpblib_reset_raster(raster, 11, 20) == -1); + ASSERT(errno == EINVAL); + ASSERT(raster->width == 10); + ASSERT(raster->height == 20); + ASSERT(raster->size == size); + ASSERT(raster->draftness == 10); + + errno = 0; + ASSERT(rtgrpblib_reset_raster(raster, 1, 0) == -1); + ASSERT(errno == EINVAL); + ASSERT(raster->width == 10); + ASSERT(raster->height == 20); + ASSERT(raster->size == size); + ASSERT(raster->draftness == 10); + + errno = 0; + ASSERT(rtgrpblib_reset_raster(raster, 0, 1) == -1); + ASSERT(errno == EINVAL); + ASSERT(raster->width == 10); + ASSERT(raster->height == 20); + ASSERT(raster->size == size); + ASSERT(raster->draftness == 10); + + errno = 0; + ASSERT(rtgrpblib_reset_raster(raster, 0, 0) == -1); + ASSERT(errno == EINVAL); + ASSERT(raster->width == 10); + ASSERT(raster->height == 20); + ASSERT(raster->size == size); + ASSERT(raster->draftness == 10); + + memset(raster->cells, 100, raster->size * sizeof(*raster->cells)); + ASSERT(!rtgrpblib_reset_raster(raster, 5, 10)); + ASSERT(raster->width == 5); + ASSERT(raster->height == 10); + ASSERT(raster->size == size); + ASSERT(raster->draftness == 10); + n = raster->width * raster->height; + for (i = 0; i < n; i++) { + ASSERT(!raster->cells[i].cell_coverage); + ASSERT(!raster->cells[i].opposite_coverage); + } + + memset(raster->cells, 100, raster->size * sizeof(*raster->cells)); + ASSERT(!rtgrpblib_reset_raster(raster, 5, 30)); + ASSERT(raster->width == 5); + ASSERT(raster->height == 30); + ASSERT(raster->size == size); + ASSERT(raster->draftness == 10); + n = raster->width * raster->height; + for (i = 0; i < n; i++) { + ASSERT(!raster->cells[i].cell_coverage); + ASSERT(!raster->cells[i].opposite_coverage); + } + + memset(raster->cells, 100, raster->size * sizeof(*raster->cells)); + ASSERT(!rtgrpblib_reset_raster(raster, 15, 10)); + ASSERT(raster->width == 15); + ASSERT(raster->height == 10); + ASSERT(raster->size == size); + ASSERT(raster->draftness == 10); + n = raster->width * raster->height; + for (i = 0; i < n; i++) { + ASSERT(!raster->cells[i].cell_coverage); + ASSERT(!raster->cells[i].opposite_coverage); + } + + free(raster); + return 0; } #endif |