Skip to content

Commit

Permalink
Add Sale Test
Browse files Browse the repository at this point in the history
  • Loading branch information
afiebig committed May 9, 2019
1 parent 68bad96 commit da46f39
Showing 1 changed file with 90 additions and 1 deletion.
91 changes: 90 additions & 1 deletion test/test_transbank.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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),
Expand All @@ -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)
{
Expand Down

0 comments on commit da46f39

Please sign in to comment.