Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : :
3 : : /**
4 : : * @brief Capture negative cases for descriptors with non-zero length and NULL data
5 : : *
6 : : * @return Return describing success or failure
7 : : */
8 : 1 : static Return capture_libmem_inconsistent_string_descriptor(void)
9 : : {
10 : 1 : INITTEST;
11 : :
12 : 1 : size_t measured_length = SIZE_MAX;
13 : 1 : memory invalid_data_descriptor = m_init(char,MEMORY_DATA);
14 : 1 : memory invalid_string_descriptor = m_init(char,MEMORY_STRING);
15 : :
16 : 1 : invalid_data_descriptor.length = 3;
17 : 1 : invalid_string_descriptor.length = 3;
18 : 1 : invalid_string_descriptor.string_length = 2;
19 : :
20 : 1 : ASSERT(FAILURE == m_string_length(&invalid_data_descriptor,&measured_length));
21 : 1 : ASSERT(measured_length == SIZE_MAX);
22 : 1 : ASSERT(FAILURE == m_to_string(&invalid_data_descriptor));
23 : 1 : ASSERT(FAILURE == m_to_data(&invalid_string_descriptor));
24 : :
25 : 1 : const unsigned char *safe_string_view = (const unsigned char *)m_string(&invalid_string_descriptor);
26 : 1 : ASSERT(safe_string_view != NULL);
27 : :
28 : 1 : IF(safe_string_view != NULL)
29 : : {
30 : 1 : ASSERT(safe_string_view[0] == 0U);
31 : : }
32 : :
33 : 1 : ASSERT(invalid_data_descriptor.length == 3);
34 : 1 : ASSERT(invalid_data_descriptor.data == NULL);
35 : 1 : ASSERT(invalid_data_descriptor.is_string == false);
36 : 1 : ASSERT(invalid_string_descriptor.length == 3);
37 : 1 : ASSERT(invalid_string_descriptor.data == NULL);
38 : 1 : ASSERT(invalid_string_descriptor.is_string == true);
39 : :
40 : 1 : deliver(status);
41 : : }
42 : :
43 : : /**
44 : : * @brief Check string-facing helpers reject inconsistent descriptors
45 : : *
46 : : * @return Return describing success or failure
47 : : */
48 : 1 : Return test_libmem_0029(void)
49 : : {
50 : 1 : INITTEST;
51 : :
52 : : static const char expected_stderr_pattern_libmem_0029[] =
53 : : "\\A.*Descriptor has non-zero length with NULL data pointer.*\\Z";
54 : :
55 : 1 : ASSERT(SUCCESS == match_function_output(NULL,expected_stderr_pattern_libmem_0029,capture_libmem_inconsistent_string_descriptor));
56 : :
57 : 1 : RETURN_STATUS;
58 : : }
|