* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*! \file
*
* \brief String fields test
*
* \author\verbatim Mark Michelson <mmichelson@digium.com> \endverbatim
*
* Test module for string fields API
* \ingroup tests
* \todo need to test ast_calloc_with_stringfields
*/
/*** MODULEINFO
<depend>TEST_FRAMEWORK</depend>
***/
#include"asterisk.h"
#include"asterisk/module.h"
#include"asterisk/stringfields.h"
#include"asterisk/cli.h"
#include"asterisk/utils.h"
#include"asterisk/test.h"
AST_TEST_DEFINE(string_field_test)
{
constchar*address_holder;
structast_string_field_pool*field_pool1;
structast_string_field_pool*field_pool2;
structast_string_field_pool*field_pool3;
staticconstcharLONG_STRING[]="A professional panoramic photograph of the majestic elephant bathing itself and its young by the shores of the raging Mississippi River";
struct{
AST_DECLARE_STRING_FIELDS(
AST_STRING_FIELD(string1);
AST_STRING_FIELD(string2);
);
}test_struct;
struct{
AST_DECLARE_STRING_FIELDS(
AST_STRING_FIELD(string1);
AST_STRING_FIELD(string2);
AST_STRING_FIELD(string3);
);
}test_struct2;
switch(cmd){
caseTEST_INIT:
info->name="string_field_test";
info->category="main/utils/";
info->summary="Test stringfield operations";
info->description=
"This tests the stringfield API";
returnAST_TEST_NOT_RUN;
caseTEST_EXECUTE:
break;
}
ast_test_status_update(test,"First things first. Let's see if we can actually allocate string fields\n");
if(ast_string_field_init(&test_struct,32)){
ast_test_status_update(test,"Failure to initialize string fields. They are totally messed up\n");
returnAST_TEST_FAIL;
}else{
ast_test_status_update(test,"All right! Successfully allocated! Now let's get down to business\n");
}
ast_test_status_update(test,"We're going to set some string fields and perform some checks\n");
ast_test_status_update(test,"The allocation amount changed when we re-expanded the string...\n");
gotoerror;
}else{
ast_test_status_update(test,"The allocation amount for string1 is still holding steady\n");
}
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");
/* This string is 208 characters long, which will surely exceed the initial pool size */
ast_string_field_set(&test_struct2,string1,"Expanded first string to create new pool-----------------------------------------------------------------------------------------------------------------------------------------------------------------------");
/* Pool size at this point is 976, so 1000 chars should do it */
ast_string_field_set(&test_struct2,string2,"Expanded second string to create new pool----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");