firmware  v0.1.2
Chromation Spectrometer Dev-Kit
test_runner.c
1 #include <unity.h>
2 #include <stdbool.h>
3 #include <Mock.h>
4 #include "test_Mock.h"
5 #include "test_ReturnValues.h"
6 #include "test_RecordedArg.h"
7 
8 void (*setUp)(void);
9 void (*tearDown)(void);
10 Mock_s *mock;
11 
12 bool Yep=true, Nope=false;
13 
14 void DevelopingMock(bool run_test)
15 {
16  if (run_test)
17  {
18  /* =====[ New functionality I added 2019 October ]===== */
19  setUp = SetUp_AssertCall;
20  tearDown = TearDown_AssertCall;
21  printf("\n# Test AssertCall\n");
22  RUN_TEST(AssertCall_returns_false_if_call_number_exceeds_call_list);
23  RUN_TEST(AssertCall_returns_false_if_call_n_does_not_match_name);
24  RUN_TEST(AssertCall_returns_true_if_call_n_matches_name);
25  // use same setUp/tearDown for AssertArg tests
26  printf("\n# Test AssertArg\n");
27  RUN_TEST(AssertArg_returns_false_if_call_number_exceeds_call_list);
28  RUN_TEST(AssertArg_returns_false_if_arg_number_exceeds_arg_list);
29  RUN_TEST(AssertArg_returns_true_if_arg_1_in_call_1_matches_uint8_arg_value);
30  RUN_TEST(AssertArg_returns_true_if_arg_2_in_call_1_matches_uint8_arg_value);
31  RUN_TEST(AssertArg_returns_true_if_arg_1_in_call_2_matches_uint8_arg_value);
32  RUN_TEST(AssertArg_returns_true_if_arg_2_in_call_2_matches_uint8_arg_value);
33  /* // use same setUp/tearDown for NumberOfActualCalls tests */
34  printf("\n# Test NumberOfActualCalls\n");
35  RUN_TEST(NumberOfActualCalls_returns_number_of_actual_calls_recorded_in_mock);
36 
37  setUp = SetUp_libMock;
38  tearDown = TearDown_libMock;
39 
40  printf("\n# Test RanAsHoped\n");
41  RUN_TEST(RanAsHoped_returns_true_if_call_lists_match);
42  RUN_TEST(RanAsHoped_returns_false_if_more_expected_calls_than_actual_calls);
43  RUN_TEST(RanAsHoped_returns_false_if_more_actual_calls_than_expected_calls);
44  RUN_TEST(RanAsHoped_returns_false_if_call_names_do_not_match);
45  RUN_TEST(RanAsHoped_returns_false_if_a_call_expected_more_inputs);
46  RUN_TEST(RanAsHoped_returns_false_if_a_call_expected_less_inputs);
47  RUN_TEST(RanAsHoped_returns_false_if_a_call_has_the_wrong_input_value);
48 
49  printf("\n# Test WhyDidItFail\n");
50  // TODO(sustainablelab): I think Mock.WhyDidItFail is
51  // replaced with Mock.ListAllCalls. Delete these tests if
52  // WhyDidItFail is not used. And add tests for
53  // ListAllCalls.
54  RUN_TEST(WhyDidItFail_reports_unexpected_calls);
55  RUN_TEST(WhyDidItFail_reports_when_calls_are_out_of_order);
56  RUN_TEST(WhyDidItFail_reports_first_unexpected_call_after_last_expected_call);
57  RUN_TEST(WhyDidItFail_reports_first_missed_call_after_last_actual_call);
58  }
59 }
60 
61 void DevelopingRecordedCall(bool run_test)
62 {
63  if (run_test)
64  {
65  }
66 }
67 
68 void DevelopingRecordedArg (bool run_test)
69 {
70  if (run_test)
71  {
72 
73  setUp = SetUp_RecordedArg; tearDown = TearDown_RecordedArg;
74  printf("\n# Test Methods in struct SetupRecord_uint8_t\n");
75  RUN_TEST(SetupRecord_uint8_t_points_pArg_at_a_uint8_t);
76  RUN_TEST(Destroy_for_SetupRecord_uint8_t_frees_a_uint8_t);
77  RUN_TEST(Print_for_SetupRecord_uint8_t_prints_a_uint8_t_to_a_string);
78  RUN_TEST(Match_for_SetupRecord_uint8_t_checks_if_uint8_t_values_match);
79  printf("\n# Test Methods in struct SetupRecord_uint16_t\n");
80  RUN_TEST(SetupRecord_uint16_t_points_pArg_at_a_uint16_t);
81  RUN_TEST(Destroy_for_SetupRecord_uint16_t_frees_a_uint16_t);
82  RUN_TEST(Print_for_SetupRecord_uint16_t_prints_a_uint16_t_to_a_string);
83  RUN_TEST(Match_for_SetupRecord_uint16_t_checks_if_uint16_t_values_match);
84  printf("\n# Test Methods in struct SetupRecord_GString\n");
85  RUN_TEST(SetupRecord_GString_points_pArg_at_a_GString);
86  RUN_TEST(Destroy_for_SetupRecord_GString_frees_a_GString);
87  RUN_TEST(Print_for_SetupRecord_GString_prints_a_GString_to_a_string);
88  RUN_TEST(Match_for_SetupRecord_GString_checks_if_GString_values_match);
89  printf("\n# Test Methods in struct SetupRecord_p_uint8_t\n");
90  RUN_TEST(SetupRecord_p_uint8_t_points_pArg_at_a_pointer_to_an_uint8_t);
91  RUN_TEST(Destroy_for_SetupRecord_p_uint8_t_frees_a_pointer_to_an_uint8_t);
92  RUN_TEST(Print_for_SetupRecord_p_uint8_t_derefs_and_prints_value_to_a_string);
93  RUN_TEST(Match_for_SetupRecord_p_uint8_t_derefs_and_checks_if_values_match);
94  printf("\n# Test Methods in struct SetupRecord_p_GString\n");
95  RUN_TEST(SetupRecord_p_GString_points_pArg_at_a_pointer_to_a_GString);
96  RUN_TEST(Destroy_for_SetupRecord_p_GString_frees_a_pointer_to_a_GString);
97  RUN_TEST(Print_for_SetupRecord_p_GString_derefs_and_prints_value_to_a_string);
98  RUN_TEST(Match_for_SetupRecord_p_GString_derefs_and_checks_if_values_match);
99  }
100 }
101 
102 void DevelopingReturnValues(bool run_test)
103 {
104  if (run_test)
105  {
106  setUp = SetUp_ReturnValues; tearDown = TearDown_ReturnValues;
107  printf("\n# Test ReturnValues\n");
108  RUN_TEST(StubReturnsFalse_returns_false);
109  RUN_TEST(StubReturnsTrue_returns_true);
110  RUN_TEST(StubReturns_uint8_t_returns_the_input_uint8_t);
111  }
112 }
113 
114 int main(void)
115 {
116  /* TODO(sustainablelab): Write more tests */
117  UNITY_BEGIN();
118  DevelopingMock (Yep); // <---- WRITE TESTS FOR ListAllCalls
119  DevelopingRecordedArg (Yep);
120  DevelopingRecordedCall (Yep); // <--- WRITE THESE TESTS
121  DevelopingReturnValues (Yep); // <---- WRITE TESTS FOR OTHER RETURN TYPES
122  return UNITY_END();
123 }
Definition: Mock.c:5