String fields test.
- Author
Mark Michelson <mmichelson@digium.com>
Test module for string fields API
Definition in file test_stringfields.c.
AST_TEST_DEFINE |
( |
string_field_test |
| ) |
|
Definition at line 41 of file test_stringfields.c.
References __ast_string_field_empty, AST_DECLARE_STRING_FIELDS, AST_STRING_FIELD, AST_STRING_FIELD_ALLOCATION, AST_STRING_FIELD_EXTENDED, ast_string_field_free_memory, ast_string_field_init, ast_string_field_init_extended, ast_string_field_set, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, error(), sip_to_pjsip::info(), NULL, ast_string_field_pool::prev, test_struct::string1, TEST_EXECUTE, and TEST_INIT.
43 const char *address_holder;
47 static const char LONG_STRING[] =
"A professional panoramic photograph of the majestic elephant bathing itself and its young by the shores of the raging Mississippi River";
66 info->name =
"string_field_test";
67 info->category =
"/main/utils/";
68 info->summary =
"Test stringfield operations";
70 "This tests the stringfield API";
205 ast_test_status_update(
test,
"All right, now we're going to expand string 2. It should stay in place since it was the last string allocated in this pool\n");
210 if (strcmp(
test_struct.string2,
"hippopotamus face")) {
232 ast_test_status_update(
test,
"Now we're going to set string1 to a very long string so that a new string field pool must be allocated\n");
252 ast_test_status_update(
test,
"The string field allocation for string1 indicates a length of %hu instead of the expected %lu\n",
260 ast_test_status_update(
test,
"Now using a totally separate area of memory we're going to test a basic pool freeing scenario\n");
269 ast_string_field_set(&test_struct2, string1,
"Expanded first string to create new pool-----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
271 ast_string_field_set(&test_struct2, string2,
"Expanded second string to create new pool----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
273 field_pool3 = test_struct2.__field_mgr_pool;
274 field_pool2 = test_struct2.__field_mgr_pool->
prev;
275 field_pool1 = test_struct2.__field_mgr_pool->
prev->
prev;
277 if(field_pool3->
prev != field_pool2 || field_pool2->
prev != field_pool1) {
#define ast_string_field_init_extended(x, field)
Initialize an extended string field.
const char * __ast_string_field_empty
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD_ALLOCATION(x)
Macro to provide access to the allocation field that lives immediately in front of a string field...
#define AST_STRING_FIELD_EXTENDED(name)
Declare an extended string field.
#define ast_test_status_update(a, b, c...)
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define AST_STRING_FIELD(name)
Declare a string field.
struct ast_string_field_pool * prev
const ast_string_field string1
int error(const char *format,...)
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
AST_TEST_DEFINE |
( |
string_field_aggregate_test |
| ) |
|
Definition at line 311 of file test_stringfields.c.
References test_struct::__field_mgr, test_struct::__field_mgr_pool, ast_calloc_with_stringfields, ast_free, ast_string_field_free_memory, ast_string_field_init, ast_string_field_init_extended, ast_string_field_ptr_set_by_fields, ast_string_field_set, ast_string_fields_cmp, ast_string_fields_copy, AST_STRINGFIELD_RESET, AST_TEST_FAIL, AST_TEST_NOT_RUN, AST_TEST_PASS, ast_test_status_update, ast_string_field_mgr::embedded_pool, error(), test_struct::foo, sip_to_pjsip::info(), NULL, ast_string_field_pool::prev, test_struct::string1, TEST_EXECUTE, and TEST_INIT.
321 info->name =
"string_field_aggregate_test";
322 info->category =
"/main/utils/";
323 info->summary =
"Test stringfield aggregate operations";
325 "This tests the structure comparison and copy macros of the stringfield API";
395 ast_string_field_set(inst3, string2,
"baz 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890");
414 ast_string_field_set(inst4, string2,
"baz 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890");
#define ast_string_field_init_extended(x, field)
Initialize an extended string field.
struct ast_string_field_pool * embedded_pool
#define ast_calloc_with_stringfields(n, type, size)
Allocate a structure with embedded stringfields in a single allocation.
#define ast_test_status_update(a, b, c...)
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_fields_cmp(instance1, instance2)
Compare the string fields in two instances of the same structure.
#define ast_string_fields_copy(copy, orig)
Copy all string fields from one instance to another of the same structure.
struct ast_string_field_mgr __field_mgr
#define ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data)
struct ast_string_field_pool * __field_mgr_pool
struct ast_string_field_pool * prev
const ast_string_field string1
int error(const char *format,...)
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.