/* Type used to map small test values (i.e. simple types that fit in an int)
* to expected status codes if we try to output them for a given type */ struct int_test_value
{ int value; enum libipm_status expected_status;
};
/***************************************************************************//**
* Compares the data in a stream against an expected data block
*
* @param s Stream to check
* @param expdata Expected data
* @aram explen Expected data len
*/ staticvoid
check_stream_data_eq(conststruct stream *s, constunsignedchar *expected_data, unsignedint expected_len)
{
check_binary_data_eq((unsignedchar *)s->data,
(unsignedint)(s->end - s->data),
expected_data,
expected_len);
}
/***************************************************************************//**
* Value checks for small types (i.e. those that fit in an 'int' */ staticvoid
test_small_type_values(char typechar, conststruct int_test_value v[], unsignedint count)
{ unsignedint i; enum libipm_status status; char format[] = { typechar, '\0'};
for (i = 0 ; i < count; ++i)
{
status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO,
format, v[i].value); if (status != v[i].expected_status)
{
ck_abort_msg("Test value %d. Expected status %d, got %d",
v[i].value, v[i].expected_status, status);
}
}
}
/***************************************************************************//**
* Checks we can add a simple type right at the end of a buffer, but that
* a buffer overflow is also detected if there's not enough space.
*/ staticvoid
test_append_at_end_of_message(char typechar, unsignedint wire_size)
{ char padding[LIBIPM_MAX_PAYLOAD_SIZE] = {0}; struct libipm_fsb desc; enum libipm_status status; constchar format[] = {'B', typechar, '\0'};
/* Construct a descriptor for a binary object that fills most of *theoutputbuffer,leavingjustenoughspaceforourtypeattheend.
* Three bytes are needed for the binary descriptor overhead */
desc.data = padding;
desc.datalen = LIBIPM_MAX_PAYLOAD_SIZE - 3 - wire_size;
/* Check we're OK at the end of the buffer... */
status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, format, &desc, 0);
ck_assert_int_eq(status, E_LI_SUCCESS);
/* ..but if the value would overflow the end of the packet it's an error */
++desc.datalen;
status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, format, &desc, 0);
ck_assert_int_eq(status, E_LI_BUFFER_OVERFLOW);
}
/***************************************************************************//**
* Appends all data types to a transport, and checks the binary data in
* the output stream is as expected */
START_TEST(test_libipm_append_all_test)
{
ck_assert_ptr_ne(g_t_out, NULL);
/* A write should overflow... */
status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, "s", str);
ck_assert_int_eq(status, E_LI_BUFFER_OVERFLOW);
/* .. but a string one character shorter should be OK */
str[sizeof(str) - 2] = '\0';
status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, "s", str);
ck_assert_int_eq(status, E_LI_SUCCESS);
/* Check passing a NULL string doesn't crash the program */
status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, "s", NULL);
ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);
}
END_TEST
/* The maximum binary block length would be LIBIPM_MAX_PAYLOAD_SIZE - 3, *asweneedonecharforthe'B'typemarker,andtwoforthelength * *Constructadescriptorforabinaryobjectthatcompletelyfills
* the output buffer */
desc.data = bin;
desc.datalen = LIBIPM_MAX_PAYLOAD_SIZE - 3;
/* Check it fits in the buffer... */
status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, "B", &desc);
ck_assert_int_eq(status, E_LI_SUCCESS);
/* ..but one byte bigger, and it won't fit */
++desc.datalen;
status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, "B", &desc);
ck_assert_int_eq(status, E_LI_BUFFER_OVERFLOW);
--desc.datalen;
/* Check NULL pointers don't crash the library */
desc.data = NULL;
status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, "B", &desc);
ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);
status = libipm_msg_out_init(g_t_out, TEST_MESSAGE_NO, "B", NULL);
ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);
}
END_TEST
/***************************************************************************//**
* Exercises codepaths that shouldn't be called (programming errors)
*/
START_TEST(test_libipm_send_programming_errors)
{ enum libipm_status status;
status = libipm_msg_out_init(g_t_vanilla, TEST_MESSAGE_NO, NULL);
ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);
status = libipm_msg_out_append(g_t_vanilla, "i", 0);
ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);
libipm_msg_out_mark_end(g_t_vanilla); /* No status to check */
status = libipm_msg_out_simple_send(g_t_vanilla, TEST_MESSAGE_NO, "i", 0);
ck_assert_int_eq(status, E_LI_PROGRAM_ERROR);
}
END_TEST
/******************************************************************************/
Suite *
make_suite_test_libipm_send_calls(void)
{
Suite *s;
TCase *tc;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.