Branch data Line data Source code
1 : : #include "test_libmem_all.h"
2 : :
3 : : /**
4 : : * @brief Capture noisy mode mismatch negative cases
5 : : *
6 : : * The checked functions are expected to call report() and return FAILURE.
7 : : * match_function_output() keeps those expected diagnostics out of the common test output
8 : : *
9 : : * @return Return describing success or failure
10 : : */
11 : 1 : static Return capture_libmem_mode_mismatch_negative_cases(void)
12 : : {
13 : 1 : INITTEST;
14 : :
15 : : static const char text_literal[] = "text";
16 : :
17 : 1 : m_create(char,destination);
18 : 1 : ASSERT(SUCCESS == m_to_string(destination));
19 : 1 : m_create(char,source);
20 : 1 : m_create(char,invalid_destination);
21 : 1 : m_create(char,invalid_source);
22 : 1 : m_create(char,invalid_size_destination);
23 : 1 : m_create(char,invalid_size_source);
24 : 1 : m_create(char,string_destination,MEMORY_STRING);
25 : 1 : m_create(char,stale_string_destination,MEMORY_STRING);
26 : 1 : m_create(char,stale_string_source,MEMORY_STRING);
27 : 1 : m_create(unsigned short,wide_string_source,MEMORY_STRING);
28 : :
29 : 1 : const char raw_bytes[] = {'a','b','\0'};
30 : 1 : const char bounded_string[] = {'x','y','\0','z'};
31 : :
32 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(destination,sizeof(text_literal),text_literal));
33 : 1 : ASSERT(SUCCESS == m_copy_buffer(source,sizeof(raw_bytes),raw_bytes));
34 : :
35 : : /* Reject raw descriptor concatenation when destination is a string */
36 : 1 : ASSERT(FAILURE == m_concat_data(destination,source));
37 : :
38 : 1 : ASSERT(SUCCESS == m_copy_string(destination,sizeof(raw_bytes),raw_bytes));
39 : 1 : ASSERT(SUCCESS == m_to_string(source));
40 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(source,sizeof(text_literal),text_literal));
41 : :
42 : : /* Reject raw descriptor concatenation when both operands are strings */
43 : 1 : ASSERT(FAILURE == m_concat_data(destination,source));
44 : :
45 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(destination,sizeof(text_literal),text_literal));
46 : :
47 : : /* Reject bounded raw-buffer concatenation when destination is a string */
48 : 1 : ASSERT(FAILURE == m_concat_buffer(destination,sizeof(raw_bytes),raw_bytes));
49 : :
50 : 1 : ASSERT(SUCCESS == m_to_data(destination));
51 : :
52 : : /* Reject bounded string concatenation when destination is data */
53 : 1 : ASSERT(FAILURE == m_concat_string(destination,sizeof(bounded_string),bounded_string));
54 : :
55 : : /* Reject descriptor copy when destination is data and source is a string */
56 : 1 : ASSERT(FAILURE == m_copy(destination,source));
57 : :
58 : : /* Reject descriptor concat when destination is data and source is a string */
59 : 1 : ASSERT(FAILURE == m_concat_strings(destination,source));
60 : :
61 : 1 : ASSERT(SUCCESS == m_to_data(source));
62 : 1 : ASSERT(SUCCESS == m_to_string(destination));
63 : 1 : ASSERT(SUCCESS == m_copy_fixed_string(destination,sizeof(text_literal),text_literal));
64 : :
65 : : /* Reject descriptor copy when destination is a string and source is data */
66 : 1 : ASSERT(FAILURE == m_copy(destination,source));
67 : :
68 : : /* Reject descriptor concat when destination is a string and source is data */
69 : 1 : ASSERT(FAILURE == m_concat_strings(destination,source));
70 : :
71 : 1 : invalid_destination->length = 1;
72 : :
73 : : /* Reject descriptor copy when destination has a logical payload but NULL data */
74 : 1 : ASSERT(FAILURE == m_copy(invalid_destination,invalid_source));
75 : :
76 : 1 : invalid_destination->length = 0;
77 : 1 : invalid_source->length = 1;
78 : :
79 : : /* Reject descriptor copy when source has a logical payload but NULL data */
80 : 1 : ASSERT(FAILURE == m_copy(invalid_destination,invalid_source));
81 : :
82 : 1 : invalid_size_destination->single_element_size = 0;
83 : :
84 : : /* Reject descriptor copy when destination element size is zero */
85 : 1 : ASSERT(FAILURE == m_copy(invalid_size_destination,invalid_size_source));
86 : :
87 : 1 : invalid_size_destination->single_element_size = sizeof(char);
88 : 1 : invalid_size_source->single_element_size = 0;
89 : :
90 : : /* Reject descriptor copy when source element size is zero */
91 : 1 : ASSERT(FAILURE == m_copy(invalid_size_destination,invalid_size_source));
92 : :
93 : : /* Reject string-route descriptor copy when element sizes differ */
94 : 1 : ASSERT(FAILURE == m_copy(string_destination,wide_string_source));
95 : :
96 : : /* Reject string-route descriptor concat when element sizes differ */
97 : 1 : ASSERT(FAILURE == m_concat_strings(string_destination,wide_string_source));
98 : :
99 : 1 : stale_string_destination->string_length = 1;
100 : :
101 : : /* Reject descriptor concat when destination string metadata is stale */
102 : 1 : ASSERT(FAILURE == m_concat_strings(stale_string_destination,string_destination));
103 : :
104 : 1 : stale_string_destination->string_length = 0;
105 : :
106 : 1 : stale_string_source->string_length = 1;
107 : :
108 : : /* Reject string-route descriptor copy when source string metadata is stale */
109 : 1 : ASSERT(FAILURE == m_copy(stale_string_destination,stale_string_source));
110 : :
111 : : /* Reject descriptor concat when source string metadata is stale */
112 : 1 : ASSERT(FAILURE == m_concat_strings(stale_string_destination,stale_string_source));
113 : :
114 : 1 : invalid_destination->length = 0;
115 : 1 : invalid_source->length = 0;
116 : 1 : invalid_size_destination->single_element_size = sizeof(char);
117 : 1 : invalid_size_source->single_element_size = sizeof(char);
118 : :
119 : 1 : call(m_del(destination));
120 : 1 : call(m_del(source));
121 : 1 : call(m_del(invalid_destination));
122 : 1 : call(m_del(invalid_source));
123 : 1 : call(m_del(invalid_size_destination));
124 : 1 : call(m_del(invalid_size_source));
125 : 1 : call(m_del(string_destination));
126 : 1 : call(m_del(stale_string_destination));
127 : 1 : call(m_del(stale_string_source));
128 : 1 : call(m_del(wide_string_source));
129 : :
130 : 1 : deliver(status);
131 : : }
132 : :
133 : : /**
134 : : * @brief Check mode mismatch and malformed-descriptor failures are diagnosed
135 : : *
136 : : * @return Return describing success or failure
137 : : */
138 : 1 : Return test_libmem_0065(void)
139 : : {
140 : 1 : INITTEST;
141 : :
142 : : static const char expected_stderr_pattern[] =
143 : : "\\A"
144 : : "ERROR: src/mem_core_data\\.c:mem_core_data:\\d+ Memory management; Destination must be in data mode, but it is a string Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
145 : : "ERROR: src/mem_core_data\\.c:mem_core_data:\\d+ Memory management; Destination must be in data mode, but it is a string Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
146 : : "ERROR: src/mem_core_buffer\\.c:mem_core_buffer:\\d+ Memory management; Destination must be in data mode, but it is a string Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
147 : : "ERROR: src/mem_core_string\\.c:mem_core_string:\\d+ Memory management; Destination must be a string descriptor Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
148 : : "ERROR: src/mem_copy\\.c:mem_copy:\\d+ Memory management; Source and destination must both be strings or both be data Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
149 : : "ERROR: src/mem_concat_strings\\.c:mem_concat_strings:\\d+ Memory management; Source and destination must both be strings Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
150 : : "ERROR: src/mem_copy\\.c:mem_copy:\\d+ Memory management; Source and destination must both be strings or both be data Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
151 : : "ERROR: src/mem_concat_strings\\.c:mem_concat_strings:\\d+ Memory management; Source and destination must both be strings Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
152 : : "ERROR: src/mem_copy\\.c:mem_copy:\\d+ Memory management; Descriptor has non-zero length with NULL data pointer Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
153 : : "ERROR: src/mem_copy\\.c:mem_copy:\\d+ Memory management; Descriptor has non-zero length with NULL data pointer Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
154 : : "ERROR: src/mem_copy\\.c:mem_copy:\\d+ Memory management; Destination element size is zero \\(uninitialized\\) Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
155 : : "ERROR: src/mem_copy\\.c:mem_copy:\\d+ Memory management; Source element size is zero \\(uninitialized\\) Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
156 : : "ERROR: src/mem_copy\\.c:mem_copy:\\d+ Memory management; Element size mismatch \\([0-9]+ vs [0-9]+\\) Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
157 : : "ERROR: src/mem_concat_strings\\.c:mem_concat_strings:\\d+ Memory management; Element size mismatch \\([0-9]+ vs [0-9]+\\) Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
158 : : "ERROR: src/mem_concat_strings\\.c:mem_concat_strings:\\d+ Memory management; Destination string descriptor is inconsistent Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
159 : : "ERROR: src/mem_copy\\.c:mem_copy:\\d+ Memory management; Source string descriptor is inconsistent Errno: [^\\n]+ \\(errno: [0-9]+\\)\n"
160 : : "ERROR: src/mem_concat_strings\\.c:mem_concat_strings:\\d+ Memory management; Source string descriptor is inconsistent Errno: [^\\n]+ \\(errno: [0-9]+\\)\\Z";
161 : :
162 : 1 : ASSERT(SUCCESS == match_function_output(NULL,expected_stderr_pattern,capture_libmem_mode_mismatch_negative_cases));
163 : :
164 : 1 : RETURN_STATUS;
165 : : }
|