38 #define BUFFER_MAX_NOMINAL 10 61 info->name =
"buffer_create";
62 info->category =
"/main/data_buffer/";
63 info->summary =
"buffer create unit test";
65 "Test that creating a data buffer results in a buffer with the expected values";
73 ast_test_validate(
test, buffer !=
NULL,
74 "Failed to create buffer with valid arguments");
76 "Newly created buffer does not have the expected payload count");
78 "Newly created buffer does not have the expected max size");
92 info->name =
"buffer_put";
93 info->category =
"/main/data_buffer/";
94 info->summary =
"buffer put unit test";
96 "Test that putting payloads in the buffer yields the expected results";
104 ast_test_validate(
test, buffer !=
NULL,
105 "Failed to create buffer with valid arguments");
107 "Newly created buffer is not empty");
111 ast_test_validate(
test, payload !=
NULL,
112 "Failed to allocate memory for first payload");
117 ast_test_validate(
test, ret == 0,
118 "Adding a payload to an empty buffer did not return the expected value");
120 "Adding a payload to an empty buffer did not update count to the expected value");
124 ast_test_validate(
test, fetched_payload !=
NULL,
125 "Failed to get only payload from buffer given valid arguments");
130 "Adding a payload that is already in the buffer should not do anything");
134 ast_test_validate(
test, payload !=
NULL,
135 "Failed to allocate memory for second payload");
141 ast_test_validate(
test, fetched_payload !=
NULL,
142 "Failed to get a payload from buffer given valid arguments");
144 "Buffer does not have the expected count after removing a payload");
145 ast_test_validate(
test, fetched_payload->
id == 1,
146 "Did not get the expected payload from the buffer");
150 ast_test_validate(
test, payload !=
NULL,
151 "Failed to allocate memory for third payload");
156 ast_test_validate(
test, ret == 0,
157 "Failed to replace a payload in the buffer");
159 "Buffer count exceeded the max");
163 ast_test_validate(
test, fetched_payload !=
NULL,
164 "Failed to get a payload from buffer at position 3 given valid arguments");
165 ast_test_validate(
test, fetched_payload->
id == 3,
166 "Did not get the expected payload at position 3 from the buffer");
170 ast_test_validate(
test, fetched_payload !=
NULL,
171 "Failed to get a payload from buffer at position 2 given valid arguments");
172 ast_test_validate(
test, fetched_payload->
id == 2,
173 "Did not get the expected payload at position 2 from the buffer");
184 info->name =
"buffer_resize";
185 info->category =
"/main/data_buffer/";
186 info->summary =
"buffer resize unit test";
188 "Tests resizing a data buffer to make sure it has the expected outcome";
196 ast_test_validate(
test, buffer !=
NULL,
197 "Failed to create buffer with valid arguments");
202 "Trying to resize buffer to same size should not change its max size");
207 "Increasing buffer size did not return the expected max");
212 "Decreasing buffer size did not return the expected max");
228 info->name =
"buffer_nominal";
229 info->category =
"/main/data_buffer/";
230 info->summary =
"buffer nominal unit test";
232 "Tests the normal usage of a data buffer to ensure the expected payloads " 233 "are present after multiple insertions";
241 ast_test_validate(
test, buffer !=
NULL,
242 "Failed to create buffer with valid arguments");
247 ast_test_validate(
test, payload !=
NULL,
248 "Failed to allocate memory for payload %d", i);
255 ast_test_validate(
test, ret == 0,
256 "Failed to add payload %d to buffer", i);
260 "Buffer does not have the expected count after adding payloads");
265 ast_test_validate(
test, fetched_payload !=
NULL,
266 "Failed to get payload at position %d during first loop", i);
272 ast_test_validate(
test, payload !=
NULL,
281 ast_test_validate(
test, ret == 0,
286 "Buffer does not have the expected count after replacing payloads");
291 ast_test_validate(
test, fetched_payload ==
NULL,
292 "Got an unexpected payload at position %d", i);
296 ast_test_validate(
test, fetched_payload !=
NULL,
302 ast_test_validate(
test, removed_payload !=
NULL,
303 "Failed to get the payload at the HEAD of the buffer");
306 "Removing payload from HEAD of buffer did not decrease buffer size");
308 ast_test_validate(
test, removed_payload->id == 1,
309 "Removing payload from HEAD of buffer did not return expected payload");
315 ast_test_validate(
test, removed_payload !=
NULL,
319 "Removing payload from buffer did not decrease buffer size");
322 "Removing payload from buffer did not return expected payload");
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Asterisk main include file. File version handling, generic pbx functions.
Data buffer containing fixed number of data payloads.
struct ast_data_buffer * ast_data_buffer_alloc(ast_data_buffer_free_callback free_fn, size_t size)
Allocate a data buffer.
void * ast_data_buffer_remove(struct ast_data_buffer *buffer, size_t pos)
Remove a data payload from the data buffer.
#define AST_TEST_REGISTER(cb)
static int unload_module(void)
void ast_free_ptr(void *ptr)
free() wrapper
int ast_data_buffer_put(struct ast_data_buffer *buffer, size_t pos, void *payload)
Place a data payload at a position in the data buffer.
#define BUFFER_MAX_NOMINAL
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
void * ast_data_buffer_get(const struct ast_data_buffer *buffer, size_t pos)
Retrieve a data payload from the data buffer.
#define AST_TEST_UNREGISTER(cb)
#define ast_calloc(num, len)
A wrapper for calloc()
static int load_module(void)
static void ast_data_buffer_free_wrapper(struct ast_data_buffer *buffer)
size_t ast_data_buffer_count(const struct ast_data_buffer *buffer)
Return the number of payloads in a data buffer.
void ast_data_buffer_resize(struct ast_data_buffer *buffer, size_t size)
Resize a data buffer.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
size_t ast_data_buffer_max(const struct ast_data_buffer *buffer)
Return the maximum number of payloads a data buffer can hold.
AST_TEST_DEFINE(buffer_create)
void ast_data_buffer_free(struct ast_data_buffer *buffer)
Free a data buffer (and all held data payloads)
void * ast_data_buffer_remove_head(struct ast_data_buffer *buffer)
Remove the first payload from the data buffer.