|
static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "String Fields Test" , .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 |
|
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_aggregate_test |
| ) |
|
Definition at line 311 of file test_stringfields.c.
312{
318
319 switch (cmd) {
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";
328 break;
329 }
330
332 if (!inst1) {
336 }
338
340 if (!inst2) {
344 }
346
348 if (!inst3) {
352 }
354
356 if (!inst4) {
360 }
362
363
367
371
376 }
377
379
384 }
385
390 }
391
393
394
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");
397
402 }
403
408 }
409
411
413
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");
416
421 } else {
423 }
424
429 } else {
431 }
432
437 } else {
439 }
440
445 } else {
447 }
448
453 } else {
455 }
456
457
462 } else {
464 }
465
469 } else {
471 }
472
474
479
483 } else {
485 }
486
491 } else {
493 }
494
499 } else {
501 }
502
512
513 return res;
514}
#define ast_string_fields_cmp(instance1, instance2)
Compare the string fields in two instances of the same structure.
#define ast_calloc_with_stringfields(n, type, size)
Allocate a structure with embedded stringfields in a single allocation.
#define ast_string_fields_copy(copy, orig)
Copy all string fields from one instance to another of the same structure.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
#define ast_string_field_init_extended(x, field)
Initialize an extended string field.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
#define ast_string_field_ptr_set_by_fields(field_mgr_pool, field_mgr, ptr, data)
struct ast_string_field_pool * embedded_pool
struct ast_string_field_pool * prev
struct ast_string_field_mgr __field_mgr
struct ast_string_field_pool * __field_mgr_pool
const ast_string_field string1
#define ast_test_status_update(a, b, c...)
int error(const char *format,...)
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.
AST_TEST_DEFINE |
( |
string_field_test |
| ) |
|
Definition at line 41 of file test_stringfields.c.
42{
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";
48
49 struct {
52 );
55
56 struct {
60 );
62 } test_struct2;
63
64 switch (cmd) {
66 info->name =
"string_field_test";
67 info->category =
"/main/utils/";
68 info->summary =
"Test stringfield operations";
70 "This tests the stringfield API";
73 break;
74 }
75
78
80
84 } else {
86 }
88
90
93
95
99 } else {
101 }
102
106 } else {
108 }
109
111
116 } else {
118 }
119
124 } else {
126 }
127
129
132
136 } else {
138 }
139
143 } else {
145 }
146
150 } else {
152 }
153
155
158
162 } else {
164 }
165
169 } else {
171 }
172
176 } else {
178 }
179
181
183
187 } else {
189 }
190
194 } else {
196 }
197
201 } else {
203 }
204
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");
206
209
210 if (strcmp(
test_struct.string2,
"hippopotamus face")) {
213 } else {
215 }
216
221 } else {
223 }
224
228 } else {
230 }
231
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");
233
236
240 } else {
242 }
243
247 } else {
249 }
250
252 ast_test_status_update(
test,
"The string field allocation for string1 indicates a length of %hu instead of the expected %lu\n",
255 } else {
257 }
258
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");
262
263
267
268
269 ast_string_field_set(&test_struct2, string1,
"Expanded first string to create new pool-----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
270
271 ast_string_field_set(&test_struct2, string2,
"Expanded second string to create new pool----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
272
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;
276
277 if(field_pool3->
prev != field_pool2 || field_pool2->
prev != field_pool1) {
280 } else {
282 }
283
288 } else {
290 }
291
295
300}
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
#define AST_STRING_FIELD(name)
Declare a string field.
const char * __ast_string_field_empty
#define AST_STRING_FIELD_EXTENDED(name)
Declare an extended string field.
#define AST_STRING_FIELD_ALLOCATION(x)
Macro to provide access to the allocation field that lives immediately in front of a string field.
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.