aboutsummaryrefslogtreecommitdiffstats
path: root/rtgrpblib_reset_raster.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-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