core: Add PARSE_TIMELEN support to ast_parse_arg and ACO.
This adds support for parsing timelen values from config files. This includes support for all flags which apply to PARSE_INT32. Support for this parser is added to ACO via the OPT_TIMELEN_T option type. Fixes an issue where extra characters provided to ast_app_parse_timelen were ignored, they now cause an error. Testing is included. ASTERISK-27117 #close Change-Id: I6b333feca7e3f83b4ef5bf2636fc0fd613742554
This commit is contained in:
parent
b0e184f0a7
commit
78a50b0343
|
@ -32,6 +32,12 @@ Core:
|
|||
ARI. As a result, the 'DataGet' AMI action as well as the 'data get'
|
||||
CLI command have been removed.
|
||||
|
||||
From 14.6.0 to 14.7.0:
|
||||
|
||||
Core:
|
||||
- ast_app_parse_timelen now returns an error if it encounters extra characters
|
||||
at the end of the string to be parsed.
|
||||
|
||||
From 14.4.0 to 14.5.0:
|
||||
|
||||
Core:
|
||||
|
|
|
@ -6,6 +6,10 @@
|
|||
[global]
|
||||
intopt=-1
|
||||
uintopt=1
|
||||
timelenopt1=1ms
|
||||
timelenopt2=1s
|
||||
timelenopt3=1m
|
||||
timelenopt4=1h
|
||||
doubleopt=0.1
|
||||
sockaddropt=1.2.3.4:1234
|
||||
boolopt=true
|
||||
|
@ -23,6 +27,10 @@ customopt=yes
|
|||
[item]
|
||||
intopt=-1
|
||||
uintopt=1
|
||||
timelenopt1=1
|
||||
timelenopt2=1
|
||||
timelenopt3=1
|
||||
timelenopt4=1
|
||||
doubleopt=0.1
|
||||
sockaddropt=1.2.3.4:1234
|
||||
boolopt=true
|
||||
|
|
|
@ -1086,6 +1086,11 @@ enum ast_parse_flags {
|
|||
PARSE_UINT16 = 0x0005,
|
||||
#endif
|
||||
|
||||
/* Returns an int processed by ast_app_parse_timelen.
|
||||
* The first argument is an enum ast_timelen value (required).
|
||||
*/
|
||||
PARSE_TIMELEN = 0x0006,
|
||||
|
||||
/* Returns a struct ast_sockaddr, with optional default value
|
||||
* (passed by reference) and port handling (accept, ignore,
|
||||
* require, forbid). The format is 'ipaddress[:port]'. IPv6 address
|
||||
|
@ -1152,6 +1157,12 @@ enum ast_parse_flags {
|
|||
* returns 1, b unchanged
|
||||
* ast_parse_arg("12", PARSE_UINT32|PARSE_IN_RANGE|PARSE_RANGE_DEFAULTS, &a, 1, 10);
|
||||
* returns 1, a = 10
|
||||
* ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE, &a, TIMELEN_SECONDS, -1000, 1000);
|
||||
* returns 0, a = 1000
|
||||
* ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE, &a, TIMELEN_SECONDS, -1000, 250000);
|
||||
* returns 0, a = 223000
|
||||
* ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE|PARSE_DEFAULT, &a, TIMELEN_SECONDS, 9999, -1000, 250000);
|
||||
* returns 0, a = 9999
|
||||
* ast_parse_arg("www.foo.biz:44", PARSE_INADDR, &sa);
|
||||
* returns 0, sa contains address and port
|
||||
* ast_parse_arg("www.foo.biz", PARSE_INADDR|PARSE_PORT_REQUIRE, &sa);
|
||||
|
|
|
@ -468,6 +468,30 @@ enum aco_option_type {
|
|||
*/
|
||||
OPT_YESNO_T,
|
||||
|
||||
/*! \brief Type for default option handler for time length signed integers
|
||||
*
|
||||
* \note aco_option_register flags:
|
||||
* See flags available for use with the PARSE_TIMELEN type for the ast_parse_arg function
|
||||
* aco_option_register varargs:
|
||||
* FLDSET macro with the field of type int
|
||||
* The remaining varargs for should be arguments compatible with the varargs for the
|
||||
* ast_parse_arg function with the PARSE_TIMELEN type and the flags passed in the
|
||||
* aco_option_register flags parameter.
|
||||
*
|
||||
* \note In most situations, it is preferable to not pass the PARSE_DEFAULT flag. If a config
|
||||
* contains an invalid value, it is better to let the config loading fail with warnings so that
|
||||
* the problem is fixed by the administrator.
|
||||
*
|
||||
* Example:
|
||||
* struct test_item {
|
||||
* int timelen;
|
||||
* };
|
||||
* {code}
|
||||
* aco_option_register(&cfg_info, "timelen", ACO_EXACT, my_types, "3", OPT_TIMELEN_T, PARSE_IN_RANGE, FLDSET(struct test_item, intopt), TIMELEN_MILLISECONDS, -10, 10);
|
||||
* {endcode}
|
||||
*/
|
||||
OPT_TIMELEN_T,
|
||||
|
||||
};
|
||||
|
||||
/*! \brief A callback function for handling a particular option
|
||||
|
|
13
main/app.c
13
main/app.c
|
@ -3060,19 +3060,32 @@ int ast_app_parse_timelen(const char *timestr, int *result, enum ast_timelen uni
|
|||
case 'h':
|
||||
case 'H':
|
||||
unit = TIMELEN_HOURS;
|
||||
if (u[1] != '\0') {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case 's':
|
||||
case 'S':
|
||||
unit = TIMELEN_SECONDS;
|
||||
if (u[1] != '\0') {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
if (toupper(u[1]) == 'S') {
|
||||
unit = TIMELEN_MILLISECONDS;
|
||||
if (u[2] != '\0') {
|
||||
return -1;
|
||||
}
|
||||
} else if (u[1] == '\0') {
|
||||
unit = TIMELEN_MINUTES;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3741,6 +3741,55 @@ uint32_done:
|
|||
break;
|
||||
}
|
||||
|
||||
case PARSE_TIMELEN:
|
||||
{
|
||||
int x = 0;
|
||||
int *result = p_result;
|
||||
int def = result ? *result : 0;
|
||||
int high = INT_MAX;
|
||||
int low = INT_MIN;
|
||||
enum ast_timelen defunit;
|
||||
|
||||
defunit = va_arg(ap, enum ast_timelen);
|
||||
/* optional arguments: default value and/or (low, high) */
|
||||
if (flags & PARSE_DEFAULT) {
|
||||
def = va_arg(ap, int);
|
||||
}
|
||||
if (flags & (PARSE_IN_RANGE | PARSE_OUT_RANGE)) {
|
||||
low = va_arg(ap, int);
|
||||
high = va_arg(ap, int);
|
||||
}
|
||||
if (ast_strlen_zero(arg)) {
|
||||
error = 1;
|
||||
goto timelen_done;
|
||||
}
|
||||
error = ast_app_parse_timelen(arg, &x, defunit);
|
||||
if (error || x < INT_MIN || x > INT_MAX) {
|
||||
/* Parse error, or type out of int bounds */
|
||||
error = 1;
|
||||
goto timelen_done;
|
||||
}
|
||||
error = (x < low) || (x > high);
|
||||
if (flags & PARSE_RANGE_DEFAULTS) {
|
||||
if (x < low) {
|
||||
def = low;
|
||||
} else if (x > high) {
|
||||
def = high;
|
||||
}
|
||||
}
|
||||
if (flags & PARSE_OUT_RANGE) {
|
||||
error = !error;
|
||||
}
|
||||
timelen_done:
|
||||
if (result) {
|
||||
*result = error ? def : x;
|
||||
}
|
||||
|
||||
ast_debug(3, "extract timelen from [%s] in [%d, %d] gives [%d](%d)\n",
|
||||
arg, low, high, result ? *result : x, error);
|
||||
break;
|
||||
}
|
||||
|
||||
case PARSE_DOUBLE:
|
||||
{
|
||||
double *result = p_result;
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "asterisk/config_options.h"
|
||||
#include "asterisk/stringfields.h"
|
||||
#include "asterisk/acl.h"
|
||||
#include "asterisk/app.h"
|
||||
#include "asterisk/frame.h"
|
||||
#include "asterisk/xmldoc.h"
|
||||
#include "asterisk/cli.h"
|
||||
|
@ -118,6 +119,7 @@ static void config_option_destroy(void *obj)
|
|||
|
||||
static int int_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
|
||||
static int uint_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
|
||||
static int timelen_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
|
||||
static int double_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
|
||||
static int sockaddr_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
|
||||
static int stringfield_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
|
||||
|
@ -151,6 +153,7 @@ static aco_option_handler ast_config_option_default_handler(enum aco_option_type
|
|||
case OPT_SOCKADDR_T: return sockaddr_handler_fn;
|
||||
case OPT_STRINGFIELD_T: return stringfield_handler_fn;
|
||||
case OPT_UINT_T: return uint_handler_fn;
|
||||
case OPT_TIMELEN_T: return timelen_handler_fn;
|
||||
|
||||
case OPT_CUSTOM_T: return NULL;
|
||||
}
|
||||
|
@ -1378,6 +1381,39 @@ static int uint_handler_fn(const struct aco_option *opt, struct ast_variable *va
|
|||
return res;
|
||||
}
|
||||
|
||||
/*! \brief Default option handler for timelen signed integers
|
||||
* \note For a description of the opt->flags and opt->args values, see the documentation for
|
||||
* enum aco_option_type in config_options.h
|
||||
*/
|
||||
static int timelen_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj)
|
||||
{
|
||||
int *field = (int *)(obj + opt->args[0]);
|
||||
unsigned int flags = PARSE_TIMELEN | opt->flags;
|
||||
int res = 0;
|
||||
if (opt->flags & PARSE_IN_RANGE) {
|
||||
if (opt->flags & PARSE_DEFAULT) {
|
||||
res = ast_parse_arg(var->value, flags, field, (enum ast_timelen) opt->args[1], (int) opt->args[2], (int) opt->args[3], opt->args[4]);
|
||||
} else {
|
||||
res = ast_parse_arg(var->value, flags, field, (enum ast_timelen) opt->args[1], (int) opt->args[2], (int) opt->args[3]);
|
||||
}
|
||||
if (res) {
|
||||
if (opt->flags & PARSE_RANGE_DEFAULTS) {
|
||||
ast_log(LOG_WARNING, "Failed to set %s=%s. Set to %d instead due to range limit (%d, %d)\n", var->name, var->value, *field, (int) opt->args[2], (int) opt->args[3]);
|
||||
res = 0;
|
||||
} else if (opt->flags & PARSE_DEFAULT) {
|
||||
ast_log(LOG_WARNING, "Failed to set %s=%s, Set to default value %d instead.\n", var->name, var->value, *field);
|
||||
res = 0;
|
||||
}
|
||||
}
|
||||
} else if ((opt->flags & PARSE_DEFAULT) && ast_parse_arg(var->value, flags, field, (enum ast_timelen) opt->args[1], (int) opt->args[2])) {
|
||||
ast_log(LOG_WARNING, "Attempted to set %s=%s, but set it to %d instead due to default)\n", var->name, var->value, *field);
|
||||
} else {
|
||||
res = ast_parse_arg(var->value, flags, field, (enum ast_timelen) opt->args[1]);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/*! \brief Default option handler for doubles
|
||||
* \note For a description of the opt->flags and opt->args values, see the documentation for
|
||||
* enum aco_option_type in config_options.h
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
#include "asterisk/config_options.h"
|
||||
#include "asterisk/netsock2.h"
|
||||
#include "asterisk/acl.h"
|
||||
#include "asterisk/app.h"
|
||||
#include "asterisk/pbx.h"
|
||||
#include "asterisk/frame.h"
|
||||
#include "asterisk/utils.h"
|
||||
|
@ -1080,6 +1081,13 @@ enum {
|
|||
ast_test_status_update(test, "ast_parse_arg double failed with %f != %f\n", *r, e); \
|
||||
ret = AST_TEST_FAIL; \
|
||||
} \
|
||||
} else if (((flags) & PARSE_TYPE) == PARSE_TIMELEN) { \
|
||||
int *r = (int *) (void *) result; \
|
||||
int e = (int) expected_result; \
|
||||
if (*r != e) { \
|
||||
ast_test_status_update(test, "ast_parse_arg timelen failed with %d != %d\n", *r, e); \
|
||||
ret = AST_TEST_FAIL; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
*(result) = DEFAULTVAL; \
|
||||
|
@ -1090,6 +1098,7 @@ AST_TEST_DEFINE(ast_parse_arg_test)
|
|||
int ret = AST_TEST_PASS;
|
||||
int32_t int32_t_val = DEFAULTVAL;
|
||||
uint32_t uint32_t_val = DEFAULTVAL;
|
||||
int timelen_val = DEFAULTVAL;
|
||||
double double_val = DEFAULTVAL;
|
||||
|
||||
switch (cmd) {
|
||||
|
@ -1222,6 +1231,60 @@ AST_TEST_DEFINE(ast_parse_arg_test)
|
|||
|
||||
TEST_PARSE(" -123", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32, &uint32_t_val);
|
||||
|
||||
/* timelen testing */
|
||||
TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
|
||||
TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
|
||||
TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
|
||||
TEST_PARSE("not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
|
||||
TEST_PARSE("7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
|
||||
|
||||
TEST_PARSE("123s", EXPECT_SUCCEED, 123000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
|
||||
TEST_PARSE("-123s", EXPECT_SUCCEED, -123000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
|
||||
TEST_PARSE("1m", EXPECT_SUCCEED, 60000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
|
||||
TEST_PARSE("1", EXPECT_SUCCEED, 60000, PARSE_TIMELEN, &timelen_val, TIMELEN_MINUTES);
|
||||
TEST_PARSE("1h", EXPECT_SUCCEED, 3600000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
|
||||
TEST_PARSE("1", EXPECT_SUCCEED, 3600000, PARSE_TIMELEN, &timelen_val, TIMELEN_HOURS);
|
||||
|
||||
TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);
|
||||
TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);
|
||||
TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);
|
||||
TEST_PARSE("not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);
|
||||
TEST_PARSE("7not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);
|
||||
|
||||
TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 200);
|
||||
TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -200, 100);
|
||||
TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -1, 0);
|
||||
TEST_PARSE("123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 122);
|
||||
TEST_PARSE("-123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -122, 100);
|
||||
TEST_PARSE("0", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 1, 100);
|
||||
TEST_PARSE("not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX);
|
||||
TEST_PARSE("7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX);
|
||||
TEST_PARSE("123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 200);
|
||||
TEST_PARSE("-123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -200, 100);
|
||||
TEST_PARSE("0", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -1, 0);
|
||||
TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 122);
|
||||
TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -122, 100);
|
||||
TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 1, 100);
|
||||
TEST_PARSE("not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX);
|
||||
TEST_PARSE("7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX);
|
||||
|
||||
TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 200);
|
||||
TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -200, 100);
|
||||
TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -1, 0);
|
||||
TEST_PARSE("123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 122);
|
||||
TEST_PARSE("-123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -122, 100);
|
||||
TEST_PARSE("0", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 1, 100);
|
||||
TEST_PARSE("not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX);
|
||||
TEST_PARSE("7not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX);
|
||||
TEST_PARSE("123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 200);
|
||||
TEST_PARSE("-123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -200, 100);
|
||||
TEST_PARSE("0", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -1, 0);
|
||||
TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 122);
|
||||
TEST_PARSE("-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -122, 100);
|
||||
TEST_PARSE("0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 1, 100);
|
||||
TEST_PARSE("not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX);
|
||||
TEST_PARSE("7not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX);
|
||||
|
||||
/* double testing */
|
||||
TEST_PARSE("123", EXPECT_SUCCEED, 123, PARSE_DOUBLE, &double_val);
|
||||
TEST_PARSE("123.123", EXPECT_SUCCEED, 123.123, PARSE_DOUBLE, &double_val);
|
||||
|
@ -1281,6 +1344,10 @@ struct test_item {
|
|||
);
|
||||
int32_t intopt;
|
||||
uint32_t uintopt;
|
||||
int timelenopt1;
|
||||
int timelenopt2;
|
||||
int timelenopt3;
|
||||
int timelenopt4;
|
||||
unsigned int flags;
|
||||
double doubleopt;
|
||||
struct ast_sockaddr sockaddropt;
|
||||
|
@ -1435,6 +1502,8 @@ AST_TEST_DEFINE(config_options_test)
|
|||
#define INT_CONFIG "-1"
|
||||
#define UINT_DEFAULT "2"
|
||||
#define UINT_CONFIG "1"
|
||||
#define TIMELEN_DEFAULT "2"
|
||||
#define TIMELEN_CONFIG "1"
|
||||
#define DOUBLE_DEFAULT "1.1"
|
||||
#define DOUBLE_CONFIG "0.1"
|
||||
#define SOCKADDR_DEFAULT "4.3.2.1:4321"
|
||||
|
@ -1469,6 +1538,10 @@ AST_TEST_DEFINE(config_options_test)
|
|||
/* Register all options */
|
||||
aco_option_register(&cfg_info, "intopt", ACO_EXACT, config_test_conf.types, INT_DEFAULT, OPT_INT_T, 0, FLDSET(struct test_item, intopt));
|
||||
aco_option_register(&cfg_info, "uintopt", ACO_EXACT, config_test_conf.types, UINT_DEFAULT, OPT_UINT_T, 0, FLDSET(struct test_item, uintopt));
|
||||
aco_option_register(&cfg_info, "timelenopt1", ACO_EXACT, config_test_conf.types, TIMELEN_DEFAULT, OPT_TIMELEN_T, 0, FLDSET(struct test_item, timelenopt1), TIMELEN_MILLISECONDS);
|
||||
aco_option_register(&cfg_info, "timelenopt2", ACO_EXACT, config_test_conf.types, TIMELEN_DEFAULT, OPT_TIMELEN_T, 0, FLDSET(struct test_item, timelenopt2), TIMELEN_SECONDS);
|
||||
aco_option_register(&cfg_info, "timelenopt3", ACO_EXACT, config_test_conf.types, TIMELEN_DEFAULT, OPT_TIMELEN_T, 0, FLDSET(struct test_item, timelenopt3), TIMELEN_MINUTES);
|
||||
aco_option_register(&cfg_info, "timelenopt4", ACO_EXACT, config_test_conf.types, TIMELEN_DEFAULT, OPT_TIMELEN_T, 0, FLDSET(struct test_item, timelenopt4), TIMELEN_HOURS);
|
||||
aco_option_register(&cfg_info, "doubleopt", ACO_EXACT, config_test_conf.types, DOUBLE_DEFAULT, OPT_DOUBLE_T, 0, FLDSET(struct test_item, doubleopt));
|
||||
aco_option_register(&cfg_info, "sockaddropt", ACO_EXACT, config_test_conf.types, SOCKADDR_DEFAULT, OPT_SOCKADDR_T, 0, FLDSET(struct test_item, sockaddropt));
|
||||
aco_option_register(&cfg_info, "boolopt", ACO_EXACT, config_test_conf.types, BOOL_DEFAULT, OPT_BOOL_T, 1, FLDSET(struct test_item, boolopt));
|
||||
|
@ -1490,6 +1563,14 @@ AST_TEST_DEFINE(config_options_test)
|
|||
|
||||
ast_parse_arg(INT_DEFAULT, PARSE_INT32, &defaults.intopt);
|
||||
ast_parse_arg(INT_CONFIG, PARSE_INT32, &configs.intopt);
|
||||
ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt1, TIMELEN_MILLISECONDS);
|
||||
ast_parse_arg(TIMELEN_CONFIG, PARSE_TIMELEN, &configs.timelenopt1, TIMELEN_MILLISECONDS);
|
||||
ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt2, TIMELEN_SECONDS);
|
||||
ast_parse_arg(TIMELEN_CONFIG, PARSE_TIMELEN, &configs.timelenopt2, TIMELEN_SECONDS);
|
||||
ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt3, TIMELEN_MINUTES);
|
||||
ast_parse_arg(TIMELEN_CONFIG, PARSE_TIMELEN, &configs.timelenopt3, TIMELEN_MINUTES);
|
||||
ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt4, TIMELEN_HOURS);
|
||||
ast_parse_arg(TIMELEN_CONFIG, PARSE_TIMELEN, &configs.timelenopt4, TIMELEN_HOURS);
|
||||
ast_parse_arg(UINT_DEFAULT, PARSE_UINT32, &defaults.uintopt);
|
||||
ast_parse_arg(UINT_CONFIG, PARSE_UINT32, &configs.uintopt);
|
||||
ast_parse_arg(DOUBLE_DEFAULT, PARSE_DOUBLE, &defaults.doubleopt);
|
||||
|
@ -1551,6 +1632,10 @@ AST_TEST_DEFINE(config_options_test)
|
|||
|
||||
NOT_EQUAL_FAIL(intopt, "%d");
|
||||
NOT_EQUAL_FAIL(uintopt, "%u");
|
||||
NOT_EQUAL_FAIL(timelenopt1, "%d");
|
||||
NOT_EQUAL_FAIL(timelenopt2, "%d");
|
||||
NOT_EQUAL_FAIL(timelenopt3, "%d");
|
||||
NOT_EQUAL_FAIL(timelenopt4, "%d");
|
||||
NOT_EQUAL_FAIL(boolopt, "%d");
|
||||
NOT_EQUAL_FAIL(flags, "%u");
|
||||
NOT_EQUAL_FAIL(customopt, "%d");
|
||||
|
|
Loading…
Reference in New Issue