summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-15 16:49:22 -0500
committerChristopher Peplin <chris.peplin@rhubarbtech.com>2014-01-15 16:49:22 -0500
commit1b5a2116bc558ebef5d59c2c37c02c7375bf8712 (patch)
tree3fff0cefe2fd0ecee12d00b65c28fda947a9d09e /tests
parent6e08c6f35254273aa9750600be0effe6e7cf276e (diff)
Accept functional broadcast responses to a range of arb IDs.
Diffstat (limited to 'tests')
-rw-r--r--tests/test_core.c89
1 files changed, 45 insertions, 44 deletions
diff --git a/tests/test_core.c b/tests/test_core.c
index be4d1412..182f268b 100644
--- a/tests/test_core.c
+++ b/tests/test_core.c
@@ -20,7 +20,7 @@ void response_received_handler(const DiagnosticResponse* response) {
START_TEST (test_receive_wrong_arb_id)
{
DiagnosticRequest request = {
- arbitration_id: OBD2_FUNCTIONAL_BROADCAST_ID,
+ arbitration_id: 0x100,
mode: OBD2_MODE_POWERTRAIN_DIAGNOSTIC_REQUEST
};
DiagnosticRequestHandle handle = diagnostic_request(&SHIMS, &request,
@@ -37,7 +37,7 @@ END_TEST
START_TEST (test_send_diag_request_with_payload)
{
DiagnosticRequest request = {
- arbitration_id: OBD2_FUNCTIONAL_BROADCAST_ID,
+ arbitration_id: 0x100,
mode: OBD2_MODE_POWERTRAIN_DIAGNOSTIC_REQUEST,
payload: {0x12, 0x34},
payload_length: 2
@@ -56,7 +56,7 @@ START_TEST (test_send_diag_request_with_payload)
}
END_TEST
-START_TEST (test_send_diag_request)
+START_TEST (test_send_functional_request)
{
DiagnosticRequest request = {
arbitration_id: OBD2_FUNCTIONAL_BROADCAST_ID,
@@ -72,6 +72,41 @@ START_TEST (test_send_diag_request)
fail_if(last_response_was_received);
const uint8_t can_data[] = {0x2, request.mode + 0x40, 0x23};
+ for(uint16_t filter = OBD2_FUNCTIONAL_RESPONSE_START; filter <
+ OBD2_FUNCTIONAL_RESPONSE_START + OBD2_FUNCTIONAL_RESPONSE_COUNT;
+ filter++) {
+ DiagnosticResponse response = diagnostic_receive_can_frame(&SHIMS, &handle,
+ filter, can_data, sizeof(can_data));
+ fail_unless(response.success);
+ fail_unless(response.completed);
+ fail_unless(handle.completed);
+ ck_assert(last_response_received.success);
+ ck_assert_int_eq(last_response_received.arbitration_id,
+ filter);
+ ck_assert_int_eq(last_response_received.mode, request.mode);
+ ck_assert_int_eq(last_response_received.pid, 0);
+ ck_assert_int_eq(last_response_received.payload_length, 1);
+ ck_assert_int_eq(last_response_received.payload[0], can_data[2]);
+ }
+}
+END_TEST
+
+START_TEST (test_send_diag_request)
+{
+ DiagnosticRequest request = {
+ arbitration_id: 0x100,
+ mode: OBD2_MODE_EMISSIONS_DTC_REQUEST
+ };
+ DiagnosticRequestHandle handle = diagnostic_request(&SHIMS, &request,
+ response_received_handler);
+
+ fail_if(handle.completed);
+ ck_assert_int_eq(last_can_frame_sent_arb_id, request.arbitration_id);
+ ck_assert_int_eq(last_can_payload_sent[1], request.mode);
+ ck_assert_int_eq(last_can_payload_size, 2);
+
+ fail_if(last_response_was_received);
+ const uint8_t can_data[] = {0x2, request.mode + 0x40, 0x23};
DiagnosticResponse response = diagnostic_receive_can_frame(&SHIMS, &handle,
request.arbitration_id + 0x8, can_data, sizeof(can_data));
fail_unless(response.success);
@@ -110,7 +145,7 @@ END_TEST
START_TEST (test_request_pid_enhanced)
{
- uint16_t arb_id = OBD2_FUNCTIONAL_BROADCAST_ID;
+ uint16_t arb_id = 0x100;
DiagnosticRequestHandle handle = diagnostic_request_pid(&SHIMS,
DIAGNOSTIC_ENHANCED_PID, arb_id, 0x2, response_received_handler);
@@ -131,7 +166,7 @@ END_TEST
START_TEST (test_wrong_mode_response)
{
- uint16_t arb_id = OBD2_FUNCTIONAL_BROADCAST_ID;
+ uint16_t arb_id = 0x100;
DiagnosticRequestHandle handle = diagnostic_request_pid(&SHIMS,
DIAGNOSTIC_ENHANCED_PID, arb_id, 0x2, response_received_handler);
@@ -146,7 +181,7 @@ END_TEST
START_TEST (test_missing_pid)
{
- uint16_t arb_id = OBD2_FUNCTIONAL_BROADCAST_ID;
+ uint16_t arb_id = 0x100;
DiagnosticRequestHandle handle = diagnostic_request_pid(&SHIMS,
DIAGNOSTIC_ENHANCED_PID, arb_id, 0x2, response_received_handler);
@@ -161,7 +196,7 @@ END_TEST
START_TEST (test_wrong_pid_response)
{
- uint16_t arb_id = OBD2_FUNCTIONAL_BROADCAST_ID;
+ uint16_t arb_id = 0x100;
DiagnosticRequestHandle handle = diagnostic_request_pid(&SHIMS,
DIAGNOSTIC_ENHANCED_PID, arb_id, 0x2, response_received_handler);
@@ -176,7 +211,7 @@ END_TEST
START_TEST (test_wrong_pid_then_right_completes)
{
- uint16_t arb_id = OBD2_FUNCTIONAL_BROADCAST_ID;
+ uint16_t arb_id = 0x100;
DiagnosticRequestHandle handle = diagnostic_request_pid(&SHIMS,
DIAGNOSTIC_ENHANCED_PID, arb_id, 0x2, response_received_handler);
@@ -198,44 +233,10 @@ START_TEST (test_wrong_pid_then_right_completes)
}
END_TEST
-START_TEST (test_handle_completed)
-{
- DiagnosticRequest request = {
- arbitration_id: OBD2_FUNCTIONAL_BROADCAST_ID,
- mode: OBD2_MODE_POWERTRAIN_DIAGNOSTIC_REQUEST
- };
- DiagnosticRequestHandle handle = diagnostic_request(&SHIMS, &request,
- response_received_handler);
-
- fail_if(handle.completed);
-
- const uint8_t can_data[] = {0x2, request.mode + 0x40, 0x23};
- DiagnosticResponse response = diagnostic_receive_can_frame(&SHIMS, &handle,
- request.arbitration_id + 0x8, can_data, sizeof(can_data));
- fail_unless(response.success);
- fail_unless(response.completed);
- fail_unless(handle.completed);
-
- response = diagnostic_receive_can_frame(&SHIMS, &handle,
- request.arbitration_id + 0x8, can_data, sizeof(can_data));
- fail_if(response.success);
- fail_if(response.completed);
- fail_unless(handle.completed);
-
- ck_assert(last_response_received.success);
- ck_assert_int_eq(last_response_received.arbitration_id,
- request.arbitration_id + 0x8);
- ck_assert_int_eq(last_response_received.mode, request.mode);
- ck_assert_int_eq(last_response_received.pid, 0);
- ck_assert_int_eq(last_response_received.payload_length, 1);
- ck_assert_int_eq(last_response_received.payload[0], can_data[2]);
-}
-END_TEST
-
START_TEST (test_negative_response)
{
DiagnosticRequest request = {
- arbitration_id: OBD2_FUNCTIONAL_BROADCAST_ID,
+ arbitration_id: 0x100,
mode: OBD2_MODE_POWERTRAIN_DIAGNOSTIC_REQUEST
};
DiagnosticRequestHandle handle = diagnostic_request(&SHIMS, &request,
@@ -262,6 +263,7 @@ Suite* testSuite(void) {
TCase *tc_core = tcase_create("core");
tcase_add_checked_fixture(tc_core, setup, NULL);
tcase_add_test(tc_core, test_send_diag_request);
+ tcase_add_test(tc_core, test_send_functional_request);
tcase_add_test(tc_core, test_send_diag_request_with_payload);
tcase_add_test(tc_core, test_receive_wrong_arb_id);
tcase_add_test(tc_core, test_request_pid_standard);
@@ -270,7 +272,6 @@ Suite* testSuite(void) {
tcase_add_test(tc_core, test_wrong_pid_response);
tcase_add_test(tc_core, test_missing_pid);
tcase_add_test(tc_core, test_wrong_pid_then_right_completes);
- tcase_add_test(tc_core, test_handle_completed);
tcase_add_test(tc_core, test_negative_response);
// TODO these are future work: