aboutsummaryrefslogtreecommitdiffstats
path: root/rtgrpblib_reset_raster.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2023-02-05 12:11:30 +0100
committerMattias Andrée <maandree@kth.se>2023-02-05 12:16:17 +0100
commit4df563948b0c4086c7be5cb0ef453570d2ec40a0 (patch)
tree4e41e547491d6de7d4be530d45347267358d3d2e /rtgrpblib_reset_raster.c
parentAdd draw_linear_bezier_reference (diff)
downloadlibrifunktionsteckensnittsglyfrasteriseringsprogrambiblioteket-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.c93
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