mirror of
https://github.com/ascii-boxes/boxes.git
synced 2025-06-12 12:56:38 +02:00
Add unit tests for different input and output file situations
This commit is contained in:
parent
413b174d6c
commit
7b828461ed
@ -69,8 +69,8 @@ extern int optind; /* for getopt() */
|
|||||||
*/
|
*/
|
||||||
static void usage_short(FILE *st)
|
static void usage_short(FILE *st)
|
||||||
{
|
{
|
||||||
fprintf(st, "Usage: %s [options] [infile [outfile]]\n", PROJECT);
|
bx_fprintf(st, "Usage: %s [options] [infile [outfile]]\n", PROJECT);
|
||||||
fprintf(st, "Try `%s -h' for more information.\n", PROJECT);
|
bx_fprintf(st, "Try `%s -h' for more information.\n", PROJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -45,8 +45,8 @@ static opt_t *act(const int num_args, ...)
|
|||||||
if (num_args > 0) {
|
if (num_args > 0) {
|
||||||
va_list va;
|
va_list va;
|
||||||
va_start(va, num_args);
|
va_start(va, num_args);
|
||||||
char *arg;
|
for (int i=0; i<num_args; i++) {
|
||||||
while ((arg = va_arg(va, char *))) {
|
char *arg = va_arg(va, char *);
|
||||||
++argc;
|
++argc;
|
||||||
argv = (char **) realloc(argv, (argc + 1) * sizeof(char *));
|
argv = (char **) realloc(argv, (argc + 1) * sizeof(char *));
|
||||||
argv[argc - 1] = arg;
|
argv[argc - 1] = arg;
|
||||||
@ -367,4 +367,66 @@ void test_alignment_incomplete(void **state)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_inputfiles_illegal_third_file(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
opt_t *actual = act(3, "file1", "file2", "file3_ILLEGAL");
|
||||||
|
|
||||||
|
assert_null(actual); // invalid option, so we would need to exit with error
|
||||||
|
assert_int_equal(3, collect_err_size);
|
||||||
|
assert_string_equal("boxes: illegal parameter -- file3_ILLEGAL\n", collect_err[0]);
|
||||||
|
assert_string_equal("Usage: boxes [options] [infile [outfile]]\n", collect_err[1]);
|
||||||
|
assert_string_equal("Try `boxes -h' for more information.\n", collect_err[2]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_inputfiles_stdin_stdout(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
opt_t *actual = act(2, "-", "-");
|
||||||
|
|
||||||
|
assert_non_null(actual);
|
||||||
|
assert_ptr_equal(stdin, actual->infile);
|
||||||
|
assert_ptr_equal(stdout, actual->outfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_inputfiles_stdin(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
opt_t *actual = act(1, "-");
|
||||||
|
|
||||||
|
assert_non_null(actual);
|
||||||
|
assert_ptr_equal(stdin, actual->infile);
|
||||||
|
assert_ptr_equal(stdout, actual->outfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_inputfiles_input_nonexistent(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
opt_t *actual = act(1, "NON-EXISTENT");
|
||||||
|
|
||||||
|
assert_null(actual); // invalid option, so we would need to exit with error
|
||||||
|
assert_int_equal(1, collect_err_size);
|
||||||
|
assert_string_equal("boxes: Can\'t open input file -- NON-EXISTENT\n", collect_err[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_inputfiles_actual_success(void **state)
|
||||||
|
{
|
||||||
|
(void) state; /* unused */
|
||||||
|
|
||||||
|
opt_t *actual = act(2, "../utest/dummy_in.txt", "dummy_out.txt");
|
||||||
|
|
||||||
|
assert_non_null(actual);
|
||||||
|
assert_non_null(actual->infile);
|
||||||
|
assert_non_null(actual->outfile);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*EOF*/ /* vim: set cindent sw=4: */
|
/*EOF*/ /* vim: set cindent sw=4: */
|
||||||
|
@ -57,6 +57,12 @@ void test_alignment_invalid_jX(void **state);
|
|||||||
void test_alignment_notset(void **state);
|
void test_alignment_notset(void **state);
|
||||||
void test_alignment_incomplete(void **state);
|
void test_alignment_incomplete(void **state);
|
||||||
|
|
||||||
|
void test_inputfiles_illegal_third_file(void **state);
|
||||||
|
void test_inputfiles_stdin_stdout(void **state);
|
||||||
|
void test_inputfiles_stdin(void **state);
|
||||||
|
void test_inputfiles_input_nonexistent(void **state);
|
||||||
|
void test_inputfiles_actual_success(void **state);
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
1
utest/dummy_in.txt
Normal file
1
utest/dummy_in.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
Test fixture. Do not remove.
|
@ -73,7 +73,12 @@ int main(void)
|
|||||||
cmocka_unit_test_setup(test_alignment_invalid_vX, beforeTest),
|
cmocka_unit_test_setup(test_alignment_invalid_vX, beforeTest),
|
||||||
cmocka_unit_test_setup(test_alignment_invalid_jX, beforeTest),
|
cmocka_unit_test_setup(test_alignment_invalid_jX, beforeTest),
|
||||||
cmocka_unit_test_setup(test_alignment_notset, beforeTest),
|
cmocka_unit_test_setup(test_alignment_notset, beforeTest),
|
||||||
cmocka_unit_test_setup(test_alignment_incomplete, beforeTest)
|
cmocka_unit_test_setup(test_alignment_incomplete, beforeTest),
|
||||||
|
cmocka_unit_test_setup(test_inputfiles_illegal_third_file, beforeTest),
|
||||||
|
cmocka_unit_test_setup(test_inputfiles_stdin_stdout, beforeTest),
|
||||||
|
cmocka_unit_test_setup(test_inputfiles_stdin, beforeTest),
|
||||||
|
cmocka_unit_test_setup(test_inputfiles_input_nonexistent, beforeTest),
|
||||||
|
cmocka_unit_test_setup(test_inputfiles_actual_success, beforeTest)
|
||||||
};
|
};
|
||||||
|
|
||||||
const struct CMUnitTest regulex_tests[] = {
|
const struct CMUnitTest regulex_tests[] = {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user