Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : :
3 : : /**
4 : : * @brief Capture the negative resize case for a string descriptor whose reserve is too small
5 : : *
6 : : * @return Return describing success or failure
7 : : */
8 : 1 : static Return capture_libmem_inconsistent_resize_string_reserve(void)
9 : : {
10 : 1 : INITTEST;
11 : :
12 : 1 : char materialized_string[] = "alpha";
13 : 1 : memory invalid_string = m_init(char,MEMORY_STRING);
14 : :
15 : 1 : invalid_string.data = materialized_string;
16 : 1 : invalid_string.length = sizeof(materialized_string);
17 : 1 : invalid_string.actually_allocated_bytes = sizeof(materialized_string) - 1u;
18 : 1 : invalid_string.string_length = sizeof(materialized_string) - 1u;
19 : 1 : invalid_string.is_string = true;
20 : :
21 : 1 : ASSERT(FAILURE == m_resize(&invalid_string,sizeof(materialized_string)));
22 : 1 : ASSERT(invalid_string.data == materialized_string);
23 : 1 : ASSERT(invalid_string.length == sizeof(materialized_string));
24 : 1 : ASSERT(invalid_string.actually_allocated_bytes == sizeof(materialized_string) - 1u);
25 : 1 : ASSERT(invalid_string.string_length == sizeof(materialized_string) - 1u);
26 : 1 : ASSERT(invalid_string.is_string == true);
27 : :
28 : 1 : deliver(status);
29 : : }
30 : :
31 : : /**
32 : : * @brief Check resize rejection for string descriptors whose reserve does not cover the payload
33 : : *
34 : : * @return Return describing success or failure
35 : : */
36 : 1 : Return test_libmem_0041(void)
37 : : {
38 : 1 : INITTEST;
39 : :
40 : : static const char expected_stderr_pattern_libmem_0041[] =
41 : : "\\A.*Descriptor reserve is smaller than logical payload during resize.*\\Z";
42 : :
43 : 1 : ASSERT(SUCCESS == match_function_output(NULL,expected_stderr_pattern_libmem_0041,capture_libmem_inconsistent_resize_string_reserve));
44 : :
45 : 1 : RETURN_STATUS;
46 : : }
|