Skip to content

Commit 65dc35b

Browse files
committed
Add more include tests
1 parent 8a60ce4 commit 65dc35b

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

Diff for: src/zone.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ nonnull_all
255255
void zone_close_file(
256256
parser_t *parser, zone_file_t *file)
257257
{
258-
assert((file->name == not_a_file) == !file->handle);
259-
assert((file->path == not_a_file) == !file->handle);
258+
assert(file->name != not_a_file || !file->handle);
259+
assert(file->path != not_a_file || !file->handle);
260260

261261
if (!file->handle)
262262
return;

Diff for: tests/syntax.c

+50
Original file line numberDiff line numberDiff line change
@@ -615,3 +615,53 @@ void no_famous_last_words(void **state)
615615
assert_int_equal(code, ZONE_SUCCESS);
616616
assert_true(count == 0);
617617
}
618+
619+
/*!cmocka */
620+
void the_include_that_wasnt(void **state)
621+
{
622+
(void)state;
623+
624+
int32_t code;
625+
size_t count = 0;
626+
627+
char *path = generate_include(" ");
628+
assert_non_null(path);
629+
char dummy[16];
630+
int length = snprintf(dummy, sizeof(dummy), "$INCLUDE \"%s\"\n", path);
631+
assert_true(length > 0 && length < INT_MAX - ZONE_PADDING_SIZE);
632+
char *include = malloc((size_t)length + 1 + ZONE_PADDING_SIZE);
633+
assert_non_null(include);
634+
(void)snprintf(include, (size_t)length + 1, "$INCLUDE \"%s\"\n", path);
635+
remove_include(path);
636+
free(path);
637+
code = parse(include, &count);
638+
free(include);
639+
assert_int_equal(code, ZONE_READ_ERROR);
640+
}
641+
642+
/*!cmocka */
643+
void been_there_done_that(void **state)
644+
{
645+
(void)state;
646+
647+
int32_t code;
648+
size_t count = 0;
649+
650+
char *path = generate_include(" ");
651+
assert_non_null(path);
652+
FILE* handle = fopen(path, "wb");
653+
assert_non_null(handle);
654+
char dummy[16];
655+
int length = snprintf(dummy, sizeof(dummy), "$INCLUDE \"%s\"\n", path);
656+
assert_true(length > 0 && length < INT_MAX - ZONE_PADDING_SIZE);
657+
char *include = malloc((size_t)length + 1 + ZONE_PADDING_SIZE);
658+
assert_non_null(include);
659+
(void)snprintf(include, (size_t)length + 1, "$INCLUDE \"%s\"\n", path);
660+
int result = fputs(include, handle);
661+
assert_true(result >= 0);
662+
(void)fclose(handle);
663+
free(path);
664+
code = parse(include, &count);
665+
free(include);
666+
assert_int_equal(code, ZONE_SYNTAX_ERROR);
667+
}

0 commit comments

Comments
 (0)