aboutsummaryrefslogtreecommitdiffstats
path: root/rtgrpblib_create_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_create_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_create_raster.c')
-rw-r--r--rtgrpblib_create_raster.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/rtgrpblib_create_raster.c b/rtgrpblib_create_raster.c
index 89ebad6..cbc69f2 100644
--- a/rtgrpblib_create_raster.c
+++ b/rtgrpblib_create_raster.c
@@ -7,6 +7,7 @@ RASTER *
rtgrpblib_create_raster(size_t width, size_t height)
{
RASTER *raster;
+ size_t size;
if (!width || !height) {
errno = EINVAL;
@@ -15,7 +16,8 @@ rtgrpblib_create_raster(size_t width, size_t height)
if (width > (SIZE_MAX - offsetof(RASTER, cells)) / sizeof(*raster->cells) / height)
goto enomem;
- raster = calloc(1, offsetof(RASTER, cells) + height * width * sizeof(*raster->cells));
+ size = width * height;
+ raster = calloc(1, offsetof(RASTER, cells) + size * sizeof(*raster->cells));
if (!raster) {
enomem:
errno = ENOMEM;
@@ -24,7 +26,8 @@ rtgrpblib_create_raster(size_t width, size_t height)
raster->width = width;
raster->height = height;
- raster->draftness = 0.5;
+ raster->size = size;
+ raster->draftness = DEFAULT_DRAFTNESS;
return raster;
}
@@ -34,7 +37,43 @@ rtgrpblib_create_raster(size_t width, size_t height)
int
main(void)
{
- return 0; /* TODO add test */
+ RASTER *raster;
+ size_t i, n;
+
+ errno = 0;
+ ASSERT(!rtgrpblib_create_raster(0, 1));
+ ASSERT(errno == EINVAL);
+
+ errno = 0;
+ ASSERT(!rtgrpblib_create_raster(1, 0));
+ ASSERT(errno == EINVAL);
+
+ errno = 0;
+ ASSERT(!rtgrpblib_create_raster(0, 0));
+ ASSERT(errno == EINVAL);
+
+ errno = 0;
+ ASSERT(!rtgrpblib_create_raster(SIZE_MAX - offsetof(RASTER, cells) + 1, 1));
+ ASSERT(errno == ENOMEM);
+
+ errno = 0;
+ ASSERT(!rtgrpblib_create_raster(1, SIZE_MAX - offsetof(RASTER, cells) + 1));
+ ASSERT(errno == ENOMEM);
+
+ raster = rtgrpblib_create_raster(10, 20);
+ ASSERT(raster);
+ ASSERT(raster->width == 10);
+ ASSERT(raster->height == 20);
+ ASSERT(raster->size == raster->width * raster->height);
+ ASSERT(raster->draftness == DEFAULT_DRAFTNESS);
+ 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