Skip to content

Commit

Permalink
Improved sanitation and coverage a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
aiobofh committed Dec 3, 2017
1 parent 68580c4 commit 02a329e
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/arg_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ test(allocate_arg_node_shall_output_an_error_if_allocation_failed)

test(allocate_arg_node_shall_return_pointer_to_new_node_if_all_is_ok)
{
m.malloc.retval = 0x1234;
assert_eq(0x1234, allocate_arg_node());
arg_node_t node;
m.malloc.retval = &node;
assert_eq(&node, allocate_arg_node());
}

test(allocate_arg_node_shall_return_null_if_something_wrong)
Expand Down Expand Up @@ -65,14 +66,14 @@ test(new_arg_shall_grab_the_string_length_of_the_input_arg)
test(new_arg_shall_allocate_correct_amount_of_memory_for_name)
{
m.strlen.retval = 10;
new_arg(NULL);
new_arg(0x1234);
assert_eq(1, m.malloc.call_count);
assert_eq(10 + 1, m.malloc.args.arg0); // plus \0
}

test(new_arg_shall_output_an_error_if_allocation_failed)
{
new_arg(NULL);
new_arg(0x1234);
#ifdef CUTEST_GCC
assert_eq(1, m.fwrite.call_count);
assert_eq(stderr, m.fwrite.args.arg3);
Expand All @@ -95,13 +96,14 @@ test(new_arg_shall_new_the_full_string)

test(new_arg_shall_return_pointer_to_the_new_string_if_all_is_ok)
{
m.malloc.retval = 0x1234;
assert_eq(0x1234, new_arg(NULL));
arg_node_t node;
m.malloc.retval = &node;
assert_eq(&node, new_arg(0x1234));
}

test(new_arg_shall_return_null_if_something_went_wrong)
{
assert_eq(NULL, new_arg(NULL));
assert_eq(NULL, new_arg(0x1234));
}

/*****************************************************************************
Expand Down
107 changes: 107 additions & 0 deletions src/cutest_run_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,113 @@ test(print_test_case_executions_shall_read_next_test_not_print_it_if_no_test)
assert_eq(0, m.print_test_case_executor.call_count);
}

/*****************************************************************************
* print_test_names_printer()
*/
test(print_test_names_printer_shall_open_the_correct_file_for_reading)
{
m.feof.retval = 1;
print_test_names_printer("some_file");
assert_eq("some_file", m.fopen.args.arg0);
assert_eq("r", m.fopen.args.arg1);
}

test(print_test_names_printer_shall_call_feof_correctly)
{
m.fopen.retval = 0x1234;
m.feof.retval = 1;
print_test_names_printer("some_file");
assert_eq(1, m.feof.call_count);
assert_eq(0x1234, m.feof.args.arg0);
}

test(print_test_names_printer_shall_close_the_correct_file)
{
m.fopen.retval = 0x1234;
m.feof.retval = 1;
print_test_names_printer("some_file");
assert_eq(1, m.fclose.call_count);
assert_eq(0x1234, m.fclose.args.arg0);
}

test(print_test_names_printer_shall_call_fgets_correctly)
{
m.fopen.retval = 0x1234;
m.feof.retval = 0;
print_test_names_printer("some_file");
assert_eq(1, m.fgets.call_count);
assert_eq(0x1234, m.fgets.args.arg2);
}

test(print_test_names_printer_shall_read_file_rows_until_eof)
{
m.feof.func = feof_stub;
m.fgets.retval = 0x1234;
feof_cnt = 0;
print_test_names_printer("some_file");
feof_cnt = 0;
assert_eq(10, m.feof.call_count);
assert_eq(9, m.fgets.call_count);
}

test(print_test_names_printer_shall_quit_reading_file_if_fgets_fails)
{
m.feof.func = feof_stub;
m.fgets.retval = 0;
feof_cnt = 0;
print_test_names_printer("some_file");
feof_cnt = 0;
assert_eq(1, m.feof.call_count);
assert_eq(1, m.fgets.call_count);
}

test(print_test_names_printer_shall_call_skip_comments_correctly)
{
m.feof.func = feof_stub;
m.fgets.retval = 0x1234;
feof_cnt = 0;
print_test_names_printer("some_file");
feof_cnt = 0;
assert_eq(9, m.skip_comments.call_count);
}

test(print_test_names_printer_shall_not_read_next_test_or_print_if_comment)
{
m.feof.func = feof_stub;
m.fgets.retval = 0x1234;
m.skip_comments.retval = 1;
feof_cnt = 0;
print_test_names_printer("some_file");
feof_cnt = 0;
assert_eq(9, m.skip_comments.call_count);
assert_eq(0, m.next_test.call_count);
assert_eq(0, m.printf.call_count);
}

test(print_test_names_printer_shall_read_next_test_and_print_it)
{
struct test_s t = {"foo", 0};
m.feof.func = feof_stub;
m.fgets.retval = 0x1234;
m.next_test.retval = t;
feof_cnt = 0;
print_test_names_printer("some_file");
feof_cnt = 0;
assert_eq(9, m.printf.call_count);
}

test(print_test_names_printer_shall_read_next_test_not_print_it_if_no_test)
{
struct test_s t = {NULL, 0};
m.feof.func = feof_stub;
m.fgets.retval = 0x1234;
m.next_test.retval = t;
feof_cnt = 0;
print_test_names_printer("some_file");
feof_cnt = 0;
assert_eq(0, m.printf.call_count);
}

/*****************************************************************************
* main()
*/
Expand Down

0 comments on commit 02a329e

Please sign in to comment.