examples: Fix warnings of calculator_test.
authorAndreas Schneider <asn@cryptomilk.org>
Mon, 25 Jun 2012 13:55:15 +0000 (15:55 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Mon, 25 Jun 2012 13:55:15 +0000 (15:55 +0200)
src/example/calculator_test.c

index 58db5ea..a568025 100644 (file)
@@ -54,8 +54,8 @@ extern int perform_operation(
         int ** const intermediate_values, int * const error_occurred);
 extern int example_main(int argc, char *argv[]);
 
-int example_test_fprintf(FILE* const file, const char *format, ...);
-int example_test_printf(const char *format, ...);
+int example_test_fprintf(FILE* const file, const char *format, ...) PRINTF_ATTRIBUTE(2, 3);
+int example_test_printf(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
 
 char temporary_buffer[256];
 
@@ -96,36 +96,48 @@ static int binary_operator(int a, int b) {
 
 // Ensure add() adds two integers correctly.
 static void test_add(void **state) {
+        (void) state; /* unused */
+
        assert_int_equal(add(3, 3), 6);
        assert_int_equal(add(3, -3), 0);
 }
 
 // Ensure subtract() subtracts two integers correctly.
 static void test_subtract(void **state) {
+        (void) state; /* unused */
+
        assert_int_equal(subtract(3, 3), 0);
        assert_int_equal(subtract(3, -3), 6);
 }
 
 // Ensure multiple() mulitplies two integers correctly.
 static void test_multiply(void **state) {
+        (void) state; /* unused */
+
        assert_int_equal(multiply(3, 3), 9);
        assert_int_equal(multiply(3, 0), 0);
 }
 
 // Ensure divide() divides one integer by another correctly.
 static void test_divide(void **state) {
+        (void) state; /* unused */
+
        assert_int_equal(divide(10, 2), 5);
        assert_int_equal(divide(2, 10), 0);
 }
 
 // Ensure divide() asserts when trying to divide by zero.
 static void test_divide_by_zero(void **state) {
+        (void) state; /* unused */
+
        expect_assert_failure(divide(100, 0));
 }
 
 /* Ensure find_operator_function_by_string() asserts when a NULL pointer is
  * specified as the table to search. */
 static void test_find_operator_function_by_string_null_functions(void **state) {
+        (void) state; /* unused */
+
        expect_assert_failure(find_operator_function_by_string(1, NULL, "test"));
 }
 
@@ -135,6 +147,9 @@ static void test_find_operator_function_by_string_null_string(void **state) {
        const OperatorFunction operator_functions[] = {
                {"+", binary_operator},
        };
+
+        (void) state; /* unused */
+
        expect_assert_failure(find_operator_function_by_string(
            array_length(operator_functions), operator_functions, NULL));
 }
@@ -142,6 +157,8 @@ static void test_find_operator_function_by_string_null_string(void **state) {
 /* Ensure find_operator_function_by_string() returns NULL when a NULL pointer
  * is specified as the table to search when the table size is 0. */
 static void test_find_operator_function_by_string_valid_null_functions(void **state) {
+        (void) state; /* unused */
+
   assert_int_equal(find_operator_function_by_string(0, NULL, "test"), NULL);
 }
 
@@ -153,6 +170,9 @@ static void test_find_operator_function_by_string_not_found(void **state) {
                {"-", binary_operator},
                {"/", binary_operator},
        };
+
+        (void) state; /* unused */
+
        assert_int_equal(find_operator_function_by_string(
                array_length(operator_functions), operator_functions, "test"),
                NULL);
@@ -166,6 +186,9 @@ static void test_find_operator_function_by_string_found(void **state) {
                {"-", (BinaryOperator)0xDEADBEEF},
                {"/", (BinaryOperator)0xABADCAFE},
        };
+
+        (void) state; /* unused */
+
        assert_int_equal(find_operator_function_by_string(
                array_length(operator_functions), operator_functions, "-"),
            0xDEADBEEF);
@@ -179,6 +202,9 @@ static void test_perform_operation_null_args(void **state) {
        int number_of_intermediate_values;
        int *intermediate_values;
        int error_occurred;
+
+        (void) state; /* unused */
+
        expect_assert_failure(perform_operation(
            1, NULL, array_length(operator_functions), operator_functions,
            &number_of_intermediate_values, &intermediate_values,
@@ -188,14 +214,17 @@ static void test_perform_operation_null_args(void **state) {
 /* Ensure perform_operation() asserts when a NULL operator_functions array is
  * specified. */
 static void test_perform_operation_null_operator_functions(void **state) {
-       char *args[] = {
+       const char *args[] = {
                "1", "+", "2", "*", "4"
        };
        int number_of_intermediate_values;
        int *intermediate_values;
        int error_occurred;
+
+        (void) state; /* unused */
+
        expect_assert_failure(perform_operation(
-           array_length(args), args, 1, NULL, &number_of_intermediate_values,
+           array_length(args), (char **) args, 1, NULL, &number_of_intermediate_values,
            &intermediate_values, &error_occurred));
 }
 
@@ -205,13 +234,16 @@ static void test_perform_operation_null_number_of_intermediate_values(void **sta
        const OperatorFunction operator_functions[] = {
                {"+", binary_operator},
        };
-       char *args[] = {
+       const char *args[] = {
                "1", "+", "2", "*", "4"
        };
        int *intermediate_values;
        int error_occurred;
+
+        (void) state; /* unused */
+
        expect_assert_failure(perform_operation(
-           array_length(args), args, 1, operator_functions, NULL,
+           array_length(args), (char **) args, 1, operator_functions, NULL,
            &intermediate_values, &error_occurred));
 }
 
@@ -221,22 +253,28 @@ static void test_perform_operation_null_intermediate_values(void **state) {
        const OperatorFunction operator_functions[] = {
                {"+", binary_operator},
        };
-       char *args[] = {
+       const char *args[] = {
                "1", "+", "2", "*", "4"
        };
        int number_of_intermediate_values;
        int error_occurred;
+
+        (void) state; /* unused */
+
        expect_assert_failure(perform_operation(
-           array_length(args), args, array_length(operator_functions),
+           array_length(args), (char **) args, array_length(operator_functions),
            operator_functions, &number_of_intermediate_values, NULL,
            &error_occurred));
 }
 
 // Ensure perform_operation() returns 0 when no arguments are specified.
-void test_perform_operation_no_arguments(void **state) {
+static void test_perform_operation_no_arguments(void **state) {
        int number_of_intermediate_values;
        int *intermediate_values;
        int error_occurred;
+
+        (void) state; /* unused */
+
        assert_int_equal(perform_operation(
            0, NULL, 0, NULL, &number_of_intermediate_values, &intermediate_values,
            &error_occurred), 0);
@@ -249,18 +287,20 @@ static void test_perform_operation_first_arg_not_integer(void **state) {
        const OperatorFunction operator_functions[] = {
                {"+", binary_operator},
        };
-       char *args[] = {
+       const char *args[] = {
                "test", "+", "2", "*", "4"
        };
        int number_of_intermediate_values;
        int *intermediate_values;
        int error_occurred;
 
+        (void) state; /* unused */
+
        expect_string(example_test_fprintf, temporary_buffer,
                      "Unable to parse integer from argument test\n");
 
        assert_int_equal(perform_operation(
-           array_length(args), args, array_length(operator_functions),
+           array_length(args), (char **) args, array_length(operator_functions),
            operator_functions, &number_of_intermediate_values,
            &intermediate_values, &error_occurred), 0);
        assert_int_equal(error_occurred, 1);
@@ -272,18 +312,20 @@ static void test_perform_operation_unknown_operator(void **state) {
        const OperatorFunction operator_functions[] = {
                {"+", binary_operator},
        };
-       char *args[] = {
+       const char *args[] = {
                "1", "*", "2", "*", "4"
        };
        int number_of_intermediate_values;
        int *intermediate_values;
        int error_occurred;
 
+        (void) state; /* unused */
+
        expect_string(example_test_fprintf, temporary_buffer,
                      "Unknown operator *, argument 1\n");
 
        assert_int_equal(perform_operation(
-           array_length(args), args, array_length(operator_functions),
+           array_length(args), (char **) args, array_length(operator_functions),
            operator_functions, &number_of_intermediate_values,
            &intermediate_values, &error_occurred), 0);
        assert_int_equal(error_occurred, 1);
@@ -295,18 +337,20 @@ static void test_perform_operation_missing_argument(void **state) {
        const OperatorFunction operator_functions[] = {
                {"+", binary_operator},
        };
-       char *args[] = {
+       const char *args[] = {
                "1", "+",
        };
        int number_of_intermediate_values;
        int *intermediate_values;
        int error_occurred;
 
+        (void) state; /* unused */
+
        expect_string(example_test_fprintf, temporary_buffer,
                      "Binary operator + missing argument\n");
 
        assert_int_equal(perform_operation(
-           array_length(args), args, array_length(operator_functions),
+           array_length(args), (char **) args, array_length(operator_functions),
            operator_functions, &number_of_intermediate_values,
            &intermediate_values, &error_occurred), 0);
        assert_int_equal(error_occurred, 1);
@@ -318,18 +362,20 @@ static void test_perform_operation_no_integer_after_operator(void **state) {
        const OperatorFunction operator_functions[] = {
                {"+", binary_operator},
        };
-       char *args[] = {
+       const char *args[] = {
                "1", "+", "test",
        };
        int number_of_intermediate_values;
        int *intermediate_values;
        int error_occurred;
 
+        (void) state; /* unused */
+
        expect_string(example_test_fprintf, temporary_buffer,
                      "Unable to parse integer test of argument 2\n");
 
        assert_int_equal(perform_operation(
-           array_length(args), args, array_length(operator_functions),
+           array_length(args), (char **) args, array_length(operator_functions),
            operator_functions, &number_of_intermediate_values,
            &intermediate_values, &error_occurred), 0);
        assert_int_equal(error_occurred, 1);
@@ -342,13 +388,15 @@ static void test_perform_operation(void **state) {
                {"+", binary_operator},
                {"*", binary_operator},
        };
-       char *args[] = {
+       const char *args[] = {
                "1", "+", "3", "*", "10",
        };
        int number_of_intermediate_values;
        int *intermediate_values;
        int error_occurred;
 
+        (void) state; /* unused */
+
        // Setup return values of mock operator functions.
        // Addition.
        expect_value(binary_operator, a, 1);
@@ -361,7 +409,7 @@ static void test_perform_operation(void **state) {
        will_return(binary_operator, 40);
 
        assert_int_equal(perform_operation(
-           array_length(args), args, array_length(operator_functions),
+           array_length(args), (char **) args, array_length(operator_functions),
            operator_functions, &number_of_intermediate_values,
            &intermediate_values, &error_occurred), 40);
        assert_int_equal(error_occurred, 0);
@@ -375,30 +423,35 @@ static void test_perform_operation(void **state) {
 
 // Ensure main() in example.c succeeds given no arguments.
 static void test_example_main_no_args(void **state) {
-       char *args[] = {
+       const char *args[] = {
                "example",
        };
-       assert_int_equal(example_main(array_length(args), args), 0);
+
+        (void) state; /* unused */
+
+       assert_int_equal(example_main(array_length(args), (char **) args), 0);
 }
 
 
 
 // Ensure main() in example.c succeeds given valid input arguments.
 static void test_example_main(void **state) {
-       char *args[] = {
+       const char *args[] = {
                "example", "1", "+", "3", "*", "10",
        };
 
+        (void) state; /* unused */
+
        expect_string(example_test_printf, temporary_buffer, "1\n");
        expect_string(example_test_printf, temporary_buffer, "  + 3 = 4\n");
        expect_string(example_test_printf, temporary_buffer, "  * 10 = 40\n");
        expect_string(example_test_printf, temporary_buffer, "= 40\n");
 
-       assert_int_equal(example_main(array_length(args), args), 0);
+       assert_int_equal(example_main(array_length(args), (char **) args), 0);
 }
 
 
-int main(int argc, char* argv[]) {
+int main(void) {
        UnitTest tests[] = {
                unit_test(test_add),
                unit_test(test_subtract),