Data Buffer API Unit Tests.
More...
Go to the source code of this file.
|
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Data buffer API test module" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } |
|
static const struct ast_module_info * | ast_module_info = &__mod_info |
|
Data Buffer API Unit Tests.
- Author
- Ben Ford bford.nosp@m.@dig.nosp@m.ium.c.nosp@m.om
Definition in file test_data_buffer.c.
◆ BUFFER_MAX_NOMINAL
#define BUFFER_MAX_NOMINAL 10 |
◆ __reg_module()
static void __reg_module |
( |
void |
| ) |
|
|
static |
◆ __unreg_module()
static void __unreg_module |
( |
void |
| ) |
|
|
static |
◆ ast_data_buffer_free_wrapper()
static void ast_data_buffer_free_wrapper |
( |
struct ast_data_buffer * |
buffer | ) |
|
|
static |
◆ AST_MODULE_SELF_SYM()
◆ AST_TEST_DEFINE() [1/4]
AST_TEST_DEFINE |
( |
buffer_create |
| ) |
|
Definition at line 55 of file test_data_buffer.c.
References ast_data_buffer_alloc(), ast_data_buffer_count(), ast_data_buffer_free_wrapper(), ast_data_buffer_max(), ast_free_ptr(), AST_TEST_NOT_RUN, AST_TEST_PASS, BUFFER_MAX_NOMINAL, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_EXECUTE, and TEST_INIT.
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");
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_free_ptr(void *ptr)
free() wrapper
#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.
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.
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() [2/4]
AST_TEST_DEFINE |
( |
buffer_put |
| ) |
|
Definition at line 83 of file test_data_buffer.c.
References ast_calloc, ast_data_buffer_alloc(), ast_data_buffer_count(), ast_data_buffer_free_wrapper(), ast_data_buffer_get(), ast_data_buffer_put(), ast_free_ptr(), AST_TEST_NOT_RUN, AST_TEST_PASS, mock_payload::id, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_EXECUTE, and TEST_INIT.
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");
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_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 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_calloc(num, len)
A wrapper for calloc()
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.
◆ AST_TEST_DEFINE() [3/4]
AST_TEST_DEFINE |
( |
buffer_resize |
| ) |
|
Definition at line 178 of file test_data_buffer.c.
References ast_data_buffer_alloc(), ast_data_buffer_free_wrapper(), ast_data_buffer_max(), ast_data_buffer_resize(), ast_free_ptr(), AST_TEST_NOT_RUN, AST_TEST_PASS, BUFFER_MAX_NOMINAL, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_EXECUTE, and TEST_INIT.
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");
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_free_ptr(void *ptr)
free() wrapper
#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.
static void ast_data_buffer_free_wrapper(struct ast_data_buffer *buffer)
void ast_data_buffer_resize(struct ast_data_buffer *buffer, size_t size)
Resize a data buffer.
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() [4/4]
AST_TEST_DEFINE |
( |
buffer_nominal |
| ) |
|
Definition at line 217 of file test_data_buffer.c.
References ast_calloc, ast_data_buffer_alloc(), ast_data_buffer_count(), ast_data_buffer_free_wrapper(), ast_data_buffer_get(), ast_data_buffer_put(), ast_data_buffer_remove(), ast_data_buffer_remove_head(), ast_free, ast_free_ptr(), AST_TEST_NOT_RUN, AST_TEST_PASS, BUFFER_MAX_NOMINAL, mock_payload::id, sip_to_pjsip::info(), NULL, RAII_VAR, TEST_EXECUTE, and TEST_INIT.
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");
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.
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_calloc(num, len)
A wrapper for calloc()
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_remove_head(struct ast_data_buffer *buffer)
Remove the first payload from the data buffer.
◆ load_module()
static int load_module |
( |
void |
| ) |
|
|
static |
◆ unload_module()
static int unload_module |
( |
void |
| ) |
|
|
static |
◆ __mod_info
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Data buffer API test module" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, } |
|
static |
◆ ast_module_info