Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : :
3 : : /**
4 : : * @brief Capture the zero-sized string-to-data negative case
5 : : *
6 : : * @return Return describing success or failure
7 : : */
8 : 1 : static Return capture_libmem_zero_sized_element_string_to_data(void)
9 : : {
10 : 1 : INITTEST;
11 : :
12 : 1 : unsigned char payload[] = {0U};
13 : 1 : memory invalid_string = m_init(unsigned char,MEMORY_STRING);
14 : :
15 : : /* Keep the backing storage valid so this test reaches only the
16 : : deliberately invalid zero-sized element condition */
17 : 1 : invalid_string.data = payload;
18 : 1 : invalid_string.actually_allocated_bytes = sizeof(payload);
19 : 1 : invalid_string.length = 1;
20 : 1 : invalid_string.single_element_size = 0;
21 : :
22 : 1 : ASSERT(FAILURE == m_to_data(&invalid_string));
23 : 1 : ASSERT(invalid_string.length == 1);
24 : 1 : ASSERT(invalid_string.string_length == 0);
25 : 1 : ASSERT(invalid_string.is_string == true);
26 : :
27 : 1 : deliver(status);
28 : : }
29 : :
30 : : /**
31 : : * @brief Check string-to-data conversion rejects zero-sized elements
32 : : *
33 : : * @return Return describing success or failure
34 : : */
35 : 1 : Return test_libmem_0022(void)
36 : : {
37 : 1 : INITTEST;
38 : :
39 : : static const char expected_stderr_pattern_libmem_0022[] =
40 : : "\\A.*Descriptor element size is zero \\(uninitialized\\).*\\Z";
41 : :
42 : 1 : ASSERT(SUCCESS == match_function_output(NULL,expected_stderr_pattern_libmem_0022,capture_libmem_zero_sized_element_string_to_data));
43 : :
44 : 1 : RETURN_STATUS;
45 : : }
|