From da46f3919bd871e4f0f0442ce2c10f9f15915af1 Mon Sep 17 00:00:00 2001 From: afiebig Date: Thu, 9 May 2019 12:10:49 -0400 Subject: [PATCH] Add Sale Test --- test/test_transbank.c | 91 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 1 deletion(-) diff --git a/test/test_transbank.c b/test/test_transbank.c index deb4467..c347a82 100644 --- a/test/test_transbank.c +++ b/test/test_transbank.c @@ -37,6 +37,19 @@ int __wrap_read_bytes(struct sp_port *port, char *buf, Message message) 0x37, 0x35, 0x30, 0x30, 0x31, 0x30, 0x38, 0x37, 0x03, 0x30, '\0'}; strcpy(buf, response); } + else if (strcmp(command, "0200") == 0) //Sale + { + char response[] = {0x02, + 0x30, 0x32, 0x31, 0x30, 0x7C, + 0x30, 0x30, 0x7C, + 0x35, 0x39, 0x37, 0x30, 0x32, 0x39, 0x34, 0x31, 0x34, 0x33, 0x30, 0x30, 0x7C, + 0x37, 0x35, 0x30, 0x30, 0x31, 0x30, 0x38, 0x37, 0x7C, + 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x30, 0x7C, + 0x32, 0x35, 0x30, 0x30, 0x7C, + 0x30, 0x7c, 0x7c, + 0x03, 0x30, '\0'}; + strcpy(buf, response); + } return mock(); } @@ -261,6 +274,77 @@ void test_close_reply_ack_nok(void **state) assert_int_equal(NULL, response.initilized); } +void test_sale_ok(void **state) +{ + (void)state; + will_return(__wrap_write_message, TBK_OK); + will_return(__wrap_read_ack, TBK_OK); + will_return(__wrap_sp_input_waiting, 70); + will_return(__wrap_read_bytes, 70); + will_return(__wrap_reply_ack, 0); + + char *response = sale(2500, 1, false); + + char command[5]; + memset(command, '\0', sizeof(command)); + strncpy(command, response + 1, 4); + assert_int_equal(0, strcmp(command, "0210")); + + char code[3]; + memset(code, '\0', sizeof(code)); + strncpy(code, response + 6, 2); + assert_int_equal(0, strcmp(code, "00")); + + char ammount[5]; + memset(ammount, '\0', sizeof(ammount)); + strncpy(ammount, response + 41, 4); + assert_int_equal(0, strcmp(ammount, "2500")); +} + +void test_sale_nok(void **state) +{ + (void)state; + will_return_count(__wrap_write_message, TBK_NOK, 3); + + char *response = sale(2500, 1, false); + assert_int_equal(0, strcmp("Unable to request sale\n", response)); +} + +void test_sale_ack_nok(void **state) +{ + (void)state; + will_return_count(__wrap_write_message, TBK_OK, 3); + will_return_count(__wrap_read_ack, TBK_NOK, 3); + + char *response = sale(2500, 1, false); + assert_int_equal(0, strcmp("Unable to request sale\n", response)); +} + +void test_sale_read_bytes_nok(void **state) +{ + (void)state; + will_return(__wrap_write_message, TBK_OK); + will_return(__wrap_read_ack, TBK_OK); + will_return_count(__wrap_read_bytes, -1, 3); + will_return_count(__wrap_sp_input_waiting, 70, 4); + + char *response = sale(2500, 1, false); + assert_int_equal(0, strcmp("Unable to request sale\n", response)); +} + +void test_sale_reply_ack_nok(void **state) +{ + (void)state; + will_return(__wrap_write_message, TBK_OK); + will_return(__wrap_read_ack, TBK_OK); + will_return_count(__wrap_read_bytes, 70, 3); + will_return_count(__wrap_sp_input_waiting, 70, 4); + will_return_count(__wrap_reply_ack, -1, 3); + + char *response = sale(2500, 1, false); + assert_int_equal(0, strcmp("Unable to request sale\n", response)); +} + const struct CMUnitTest transbank_tests[] = { cmocka_unit_test(test_poll_ok), cmocka_unit_test(test_poll_write_nok), @@ -281,7 +365,12 @@ const struct CMUnitTest transbank_tests[] = { cmocka_unit_test(test_close_nok), cmocka_unit_test(test_close_ack_nok), cmocka_unit_test(test_close_read_bytes_nok), - cmocka_unit_test(test_close_reply_ack_nok)}; + cmocka_unit_test(test_close_reply_ack_nok), + cmocka_unit_test(test_sale_ok), + cmocka_unit_test(test_sale_nok), + cmocka_unit_test(test_sale_ack_nok), + cmocka_unit_test(test_sale_read_bytes_nok), + cmocka_unit_test(test_sale_reply_ack_nok)}; int main(void) {