1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
/* See LICENSE file for copyright and license details. */
#include "common.h"
#ifndef TEST
int
rtgrpblib_reset_raster(RASTER *raster, size_t width, size_t height)
{
if (!width || !height || width > raster->size / height) {
errno = EINVAL;
return -1;
}
raster->width = width;
raster->height = height;
memset(raster->cells, 0, width * height * sizeof(*raster->cells));
return 0;
}
#else
int
main(void)
{
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
|