X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=tests%2Ftest_core.c;h=2730cd7389c652d06959beb41837ee8eb0c222b1;hb=54713fc5deab5de318d79035a0927d828ae239f5;hp=340a32682350ca876ad2c605733b00751b1ca05d;hpb=0bd237bae324740d6b6b22e3c63ac426267d5bf1;p=apps%2Fagl-service-can-low-level.git diff --git a/tests/test_core.c b/tests/test_core.c index 340a3268..2730cd73 100644 --- a/tests/test_core.c +++ b/tests/test_core.c @@ -8,7 +8,12 @@ extern void setup(); extern bool last_response_was_received; extern DiagnosticResponse last_response_received; extern DiagnosticShims SHIMS; -extern DiagnosticResponseReceived response_received_handler; + +void response_received_handler(const DiagnosticResponse* response) { + last_response_was_received = true; + // TODO not sure if we can copy the struct like this + last_response_received = *response; +} START_TEST (test_receive_wrong_arb_id) { @@ -21,8 +26,8 @@ START_TEST (test_receive_wrong_arb_id) fail_if(last_response_was_received); const uint8_t can_data[] = {0x2, request.mode + 0x40, 0x23}; - diagnostic_receive_can_frame(&handle, request.arbitration_id, can_data, - sizeof(can_data)); + diagnostic_receive_can_frame(&SHIMS, &handle, request.arbitration_id, + can_data, sizeof(can_data)); fail_if(last_response_was_received); } END_TEST @@ -36,15 +41,18 @@ START_TEST (test_send_diag_request) DiagnosticRequestHandle handle = diagnostic_request(&SHIMS, &request, response_received_handler); + fail_if(handle.completed); + fail_if(last_response_was_received); const uint8_t can_data[] = {0x2, request.mode + 0x40, 0x23}; - diagnostic_receive_can_frame(&handle, request.arbitration_id + 0x8, - can_data, sizeof(can_data)); - fail_unless(last_response_was_received); + 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); ck_assert(last_response_received.success); ck_assert_int_eq(last_response_received.arbitration_id, request.arbitration_id + 0x8); - // TODO should we set it back to the original mode, or leave as mode + 0x40? 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); @@ -60,13 +68,12 @@ START_TEST (test_request_pid_standard) fail_if(last_response_was_received); const uint8_t can_data[] = {0x3, 0x1 + 0x40, 0x2, 0x45}; // TODO need a constant for the 7df broadcast functional request - diagnostic_receive_can_frame(&handle, 0x7df + 0x8, + diagnostic_receive_can_frame(&SHIMS, &handle, 0x7df + 0x8, can_data, sizeof(can_data)); fail_unless(last_response_was_received); ck_assert(last_response_received.success); ck_assert_int_eq(last_response_received.arbitration_id, 0x7df + 0x8); - // TODO should we set it back to the original mode, or leave as mode + 0x40? ck_assert_int_eq(last_response_received.mode, 0x1); ck_assert_int_eq(last_response_received.pid, 0x2); ck_assert_int_eq(last_response_received.payload_length, 1); @@ -82,7 +89,7 @@ START_TEST (test_request_pid_enhanced) fail_if(last_response_was_received); const uint8_t can_data[] = {0x4, 0x1 + 0x40, 0x0, 0x2, 0x45}; // TODO need a constant for the 7df broadcast functional request - diagnostic_receive_can_frame(&handle, 0x7df + 0x8, can_data, + diagnostic_receive_can_frame(&SHIMS, &handle, 0x7df + 0x8, can_data, sizeof(can_data)); fail_unless(last_response_was_received); ck_assert(last_response_received.success);