Skip to content

Commit e1479a8

Browse files
committed
improve test_kinput.c
1 parent 31e89a6 commit e1479a8

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

tests/unit/test_kinput.c

+16-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
char *str = "";
77

88
void test(buffer_t *buf, mark_t *cur) {
9-
kinput_t garbage[NUM_KINPUTS];
9+
kinput_t weird_input[NUM_KINPUTS];
1010
kinput_t input;
1111
int result;
1212
size_t i, j;
@@ -16,28 +16,32 @@ void test(buffer_t *buf, mark_t *cur) {
1616
offsetof_ch = OFFSETOF(kinput_t, ch);
1717
offsetof_key = OFFSETOF(kinput_t, key);
1818

19-
// Fill garbage inputs
19+
// Fill weird_input values
2020
for (i = 0; i < sizeof(kinput_t) * NUM_KINPUTS; i++) {
21-
*(((uint8_t*)garbage) + i) = (uint8_t)i;
21+
*(((uint8_t*)weird_input) + i) = (uint8_t)i;
2222
}
2323

24-
// Ensure MLE_KINPUT_COPY preserves padding bytes
24+
// Ensure MLE_KINPUT_COPY *preserves* padding bytes
2525
result = 0;
2626
for (i = 0; i < NUM_KINPUTS; i++) {
27-
MLE_KINPUT_COPY(input, garbage[i]);
28-
result |= memcmp(&input, &garbage[i], sizeof(kinput_t));
27+
MLE_KINPUT_COPY(input, weird_input[i]);
28+
result |= memcmp(&input, &weird_input[i], sizeof(kinput_t));
2929
}
3030
ASSERT("cmp_kinput_assign", 0, result);
3131

32-
// Ensure MLE_KINPUT_SET zeroes padding bytes
32+
// Ensure MLE_KINPUT_SET *zeroes* padding bytes
3333
result = 0;
3434
for (i = 0; i < NUM_KINPUTS; i++) {
35-
MLE_KINPUT_SET(input, garbage[i].mod, garbage[i].ch, garbage[i].key);
35+
// Fill input with non-sense; 42 is a good choice
36+
memset(&input, 42, sizeof(input));
3637

37-
// Ensure fields are equal
38-
result |= memcmp(&input.mod, &garbage[i].mod, sizeof(input.mod));
39-
result |= memcmp(&input.ch, &garbage[i].ch, sizeof(input.ch));
40-
result |= memcmp(&input.key, &garbage[i].key, sizeof(input.key));
38+
// Set input to weird_input[i]
39+
MLE_KINPUT_SET(input, weird_input[i].mod, weird_input[i].ch, weird_input[i].key);
40+
41+
// Ensure all fields are equal
42+
result |= memcmp(&input.mod, &weird_input[i].mod, sizeof(input.mod));
43+
result |= memcmp(&input.ch, &weird_input[i].ch, sizeof(input.ch));
44+
result |= memcmp(&input.key, &weird_input[i].key, sizeof(input.key));
4145

4246
// Ensure bytes between mod and ch are zero
4347
for (j = offsetof_mod + sizeof(input.mod); j < offsetof_ch; j++) {

0 commit comments

Comments
 (0)