Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : :
3 : : /**
4 : : * @brief Capture negative already-string cases for data-to-string conversion
5 : : *
6 : : * @return Return describing success or failure
7 : : */
8 : 1 : static Return capture_libmem_inconsistent_data_to_string_string_mode(void)
9 : : {
10 : 1 : INITTEST;
11 : :
12 : 1 : memory zero_sized_string = m_init(unsigned char,MEMORY_STRING);
13 : 1 : memory zero_length_cached_string = m_init(char,MEMORY_STRING);
14 : 1 : unsigned char materialized_string[] = {'a','b','\0'};
15 : 1 : memory invalid_string_descriptor = m_init(unsigned char,MEMORY_STRING);
16 : :
17 : 1 : zero_sized_string.single_element_size = 0;
18 : 1 : zero_length_cached_string.string_length = 1;
19 : :
20 : 1 : invalid_string_descriptor.data = materialized_string;
21 : 1 : invalid_string_descriptor.length = sizeof(materialized_string);
22 : 1 : invalid_string_descriptor.actually_allocated_bytes = sizeof(materialized_string);
23 : 1 : invalid_string_descriptor.string_length = sizeof(materialized_string);
24 : 1 : invalid_string_descriptor.is_string = true;
25 : :
26 : 1 : ASSERT(FAILURE == m_to_string(&zero_sized_string));
27 : 1 : ASSERT(zero_sized_string.length == 0);
28 : 1 : ASSERT(zero_sized_string.string_length == 0);
29 : 1 : ASSERT(zero_sized_string.is_string == true);
30 : :
31 : 1 : ASSERT(FAILURE == m_to_string(&zero_length_cached_string));
32 : 1 : ASSERT(zero_length_cached_string.length == 0);
33 : 1 : ASSERT(zero_length_cached_string.string_length == 1);
34 : 1 : ASSERT(zero_length_cached_string.is_string == true);
35 : :
36 : 1 : ASSERT(FAILURE == m_to_string(&invalid_string_descriptor));
37 : 1 : ASSERT(invalid_string_descriptor.data == materialized_string);
38 : 1 : ASSERT(invalid_string_descriptor.length == sizeof(materialized_string));
39 : 1 : ASSERT(invalid_string_descriptor.actually_allocated_bytes == sizeof(materialized_string));
40 : 1 : ASSERT(invalid_string_descriptor.string_length == sizeof(materialized_string));
41 : 1 : ASSERT(invalid_string_descriptor.is_string == true);
42 : :
43 : 1 : deliver(status);
44 : : }
45 : :
46 : : /**
47 : : * @brief Check data-to-string conversion rejection for inconsistent already-string metadata
48 : : *
49 : : * @return Return describing success or failure
50 : : */
51 : 1 : Return test_libmem_0040(void)
52 : : {
53 : 1 : INITTEST;
54 : :
55 : : static const char expected_stderr_pattern_libmem_0040[] =
56 : : "\\A.*Descriptor element size is zero during string conversion"
57 : : ".*String descriptor has non-zero string_length with zero length during string conversion"
58 : : ".*String descriptor cache is inconsistent during string conversion.*\\Z";
59 : :
60 : 1 : ASSERT(SUCCESS == match_function_output(NULL,expected_stderr_pattern_libmem_0040,capture_libmem_inconsistent_data_to_string_string_mode));
61 : :
62 : 1 : RETURN_STATUS;
63 : : }
|