51 #define CONFIG_FILE "test_config.conf"
52 #define CONFIG_INCLUDE_FILE "test_config_include.conf"
68 const char cat1[] =
"Capitals";
69 const char cat1varname1[] =
"Germany";
70 const char cat1varvalue1[] =
"Berlin";
71 const char cat1varname2[] =
"China";
72 const char cat1varvalue2[] =
"Beijing";
73 const char cat1varname3[] =
"Canada";
74 const char cat1varvalue3[] =
"Ottawa";
76 const char cat2[] =
"Protagonists";
77 const char cat2varname1[] =
"1984";
78 const char cat2varvalue1[] =
"Winston Smith";
79 const char cat2varname2[] =
"Green Eggs And Ham";
80 const char cat2varvalue2[] =
"Sam I Am";
81 const char cat2varname3[] =
"The Kalevala";
82 const char cat2varvalue3[] =
"Vainamoinen";
95 { cat1varname1, cat1varvalue1 },
96 { cat1varname2, cat1varvalue2 },
97 { cat1varname3, cat1varvalue3 },
102 { cat2varname1, cat2varvalue1 },
103 { cat2varname2, cat2varvalue2 },
104 { cat2varname3, cat2varvalue3 },
119 struct pair *var_iter;
128 for (i = 0; i < ARRAY_LEN(categories); ++i) {
130 cat_iter = &categories[i];
138 for (j = 0; j < ARRAY_LEN(cat_iter->vars); ++j) {
140 var_iter = &cat_iter->vars[j];
142 var = ast_variable_new(var_iter->name, var_iter->val,
"");
146 ast_variable_append(cat, var);
167 const char *cat_iter = NULL;
169 for (i = 0; i < ARRAY_LEN(categories); ++i) {
173 if (strcmp(cat_iter, categories[i].category)) {
174 ast_log(LOG_ERROR,
"Category name mismatch, %s does not match %s\n", cat_iter, categories[i].category);
177 for (j = 0; j < ARRAY_LEN(categories[i].vars); ++j) {
178 var = var ? var->
next : ast_variable_browse(cfg, cat_iter);
179 if (strcmp(var->
name, categories[i].vars[j].name)) {
180 ast_log(LOG_ERROR,
"Variable name mismatch, %s does not match %s\n", var->
name, categories[i].vars[j].name);
183 if (strcmp(var->
value, categories[i].vars[j].val)) {
184 ast_log(LOG_ERROR,
"Variable value mismatch, %s does not match %s\n", var->
value, categories[i].vars[j].val);
194 enum ast_test_result_state res = AST_TEST_FAIL;
200 info->name =
"copy_config";
201 info->category =
"/main/config/";
202 info->summary =
"Test copying configuration";
204 "Ensure that variables and categories are copied correctly";
205 return AST_TEST_NOT_RUN;
234 enum ast_test_result_state res = AST_TEST_FAIL;
240 const char *cat_name;
241 const char *var_value;
246 info->name =
"config_basic_ops";
247 info->category =
"/main/config/";
248 info->summary =
"Test basic config ops";
249 info->description =
"Test basic config ops";
250 return AST_TEST_NOT_RUN;
261 for(i = 0; i < 5; i++) {
262 snprintf(temp,
sizeof(temp),
"test%d", i);
271 snprintf(temp,
sizeof(temp),
"test%d", i);
279 ast_test_status_update(
test,
"There were %d matches instead of 5.\n", i);
304 ast_test_status_update(
test,
"Should not have found test2\n");
313 snprintf(temp,
sizeof(temp),
"test%d", i);
324 ast_test_status_update(
test,
"There were %d matches instead of 5.\n", i);
336 snprintf(temp,
sizeof(temp),
"test%d", i);
344 ast_test_status_update(
test,
"There were %d matches instead of 5.\n", i);
353 snprintf(temp,
sizeof(temp),
"test%d", i);
354 if (strcmp(cat_name, temp)) {
355 ast_test_status_update(
test,
"%s != %s\n", cat_name, temp);
361 ast_test_status_update(
test,
"There were %d matches instead of 5.\n", i);
380 ast_test_status_update(
test,
"Should have found 2 test2's %d\n", i);
388 for(i = 0; i < 5; i++) {
389 snprintf(temp,
sizeof(temp),
"test%d", i);
392 if (strcmp(cat_name, temp)) {
393 ast_test_status_update(
test,
"Should have returned %s instead of %s: %d\n", temp, cat_name, i);
405 if (strcmp(cat_name,
"test0")) {
406 ast_test_status_update(
test,
"Should have returned test0 instead of %s\n", cat_name);
415 if (strcmp(cat_name,
"test1")) {
416 ast_test_status_update(
test,
"Should have returned test3 instead of %s\n", cat_name);
423 if (strcmp(cat_name,
"test2")) {
424 ast_test_status_update(
test,
"Should have returned test2 instead of %s\n", cat_name);
434 if (strcmp(cat_name,
"test1")) {
435 ast_test_status_update(
test,
"Should have returned test1 instead of %s\n", cat_name);
441 if (strcmp(cat_name,
"test3")) {
442 ast_test_status_update(
test,
"Should have returned test3 instead of %s\n", cat_name);
448 if (strcmp(cat_name,
"test4")) {
449 ast_test_status_update(
test,
"Should have returned test4 instead of %s\n", cat_name);
456 ast_test_status_update(
test,
"Should not have returned anything\n");
466 var = ast_variable_new(
"aaa",
"bbb0",
"dummy");
468 ast_test_status_update(
test,
"Couldn't allocate variable.\n");
471 ast_variable_append(cat, var);
474 var_value = ast_variable_retrieve(cfg, cat_name,
"aaa");
475 if (!var_value || strcmp(var_value,
"bbb0")) {
476 ast_test_status_update(
test,
"Variable not found or wrong value.\n");
481 var_value = ast_variable_retrieve(cfg, NULL,
"aaa");
482 if (!var_value || strcmp(var_value,
"bbb0")) {
483 ast_test_status_update(
test,
"Variable not found or wrong value.\n");
492 ast_test_status_update(
test,
"Couldn't allocate category.\n");
495 var = ast_variable_new(
"aaa",
"bbb1",
"dummy");
497 ast_test_status_update(
test,
"Couldn't allocate variable.\n");
500 ast_variable_append(cat, var);
505 ast_test_status_update(
test,
"Couldn't allocate category.\n");
508 var = ast_variable_new(
"aaa",
"bbb2",
"dummy");
510 ast_test_status_update(
test,
"Couldn't allocate variable.\n");
513 ast_variable_append(cat, var);
519 if (!strcmp(cat_name,
"test3")) {
520 snprintf(temp,
sizeof(temp),
"bbb%d", i);
522 var_value = ast_variable_retrieve(cfg, cat_name,
"aaa");
523 if (!var_value || strcmp(var_value, temp)) {
524 ast_test_status_update(
test,
"Variable not found or wrong value %s.\n", var_value);
528 var = ast_variable_browse(cfg, cat_name);
529 if (!var->
value || strcmp(var->
value, temp)) {
530 ast_test_status_update(
test,
"Variable not found or wrong value %s.\n", var->
value);
538 ast_test_status_update(
test,
"There should have been 3 matches instead of %d.\n", i);
542 varlist = ast_variable_new(
"name1",
"value1",
"");
547 if (strcmp(var_value,
"value1") != 0) {
548 ast_test_status_update(
test,
"Wrong variable retrieved %s.\n", var_value);
553 if (strcmp(var_value,
"value3") != 0) {
554 ast_test_status_update(
test,
"Wrong variable retrieved %s.\n", var_value);
567 enum ast_test_result_state res = AST_TEST_FAIL;
576 info->name =
"config_filtered_ops";
577 info->category =
"/main/config/";
578 info->summary =
"Test filtered config ops";
579 info->description =
"Test filtered config ops";
580 return AST_TEST_NOT_RUN;
591 for(i = 0; i < 5; i++) {
592 snprintf(temp,
sizeof(temp),
"test%d", i);
594 ast_variable_insert(cat, ast_variable_new(
"type",
"a",
"dummy"),
"0");
598 for(i = 0; i < 5; i++) {
599 snprintf(temp,
sizeof(temp),
"test%d", i);
601 ast_variable_insert(cat, ast_variable_new(
"type",
"b",
"dummy"),
"0");
609 snprintf(temp,
sizeof(temp),
"test%d", i);
615 if (!value || strcmp(value,
"a")) {
616 ast_test_status_update(
test,
"Type %s != %s\n",
"a", value);
622 ast_test_status_update(
test,
"There were %d matches instead of 5.\n", i);
629 snprintf(temp,
sizeof(temp),
"test%d", i);
635 if (!value || strcmp(value,
"b")) {
636 ast_test_status_update(
test,
"Type %s != %s\n",
"b", value);
642 ast_test_status_update(
test,
"There were %d matches instead of 5.\n", i);
651 if (strcmp(value,
"b")) {
652 ast_test_status_update(
test,
"Type %s != %s\n",
"b", value);
659 ast_test_status_update(
test,
"Category b was not deleted.\n");
665 ast_test_status_update(
test,
"Category a was deleted.\n");
670 if (strcmp(value,
"a")) {
671 ast_test_status_update(
test,
"Type %s != %s\n", value,
"a");
679 ast_variable_insert(cat, ast_variable_new(
"type",
"bx",
"dummy"),
"0");
680 ast_variable_insert(cat, ast_variable_new(
"e",
"z",
"dummy"),
"0");
684 ast_test_status_update(
test,
"Category not found.\n");
690 ast_test_status_update(
test,
"Category found.\n");
696 ast_test_status_update(
test,
"Category found.\n");
709 enum ast_test_result_state res = AST_TEST_FAIL;
718 info->name =
"config_template_ops";
719 info->category =
"/main/config/";
720 info->summary =
"Test template config ops";
721 info->description =
"Test template config ops";
722 return AST_TEST_NOT_RUN;
733 for(i = 0; i < 5; i++) {
734 snprintf(temp,
sizeof(temp),
"test%d", i);
736 ast_variable_insert(cat, ast_variable_new(
"type",
"a",
"dummy"),
"0");
740 for(i = 0; i < 5; i++) {
741 snprintf(temp,
sizeof(temp),
"test%d", i);
743 ast_variable_insert(cat, ast_variable_new(
"type",
"b",
"dummy"),
"0");
751 snprintf(temp,
sizeof(temp),
"test%d", i);
757 if (!value || strcmp(value,
"a")) {
758 ast_test_status_update(
test,
"Type %s != %s\n", value,
"a");
764 ast_test_status_update(
test,
"There were %d matches instead of 5.\n", i);
772 snprintf(temp,
sizeof(temp),
"test%d", i);
778 if (!value || strcmp(value,
"a")) {
779 ast_test_status_update(
test,
"Type %s != %s\n", value,
"a");
785 ast_test_status_update(
test,
"There were %d matches instead of 5.\n", i);
796 ast_test_status_update(
test,
"There were %d matches instead of 10.\n", i);
807 ast_test_status_update(
test,
"There were %d matches instead of 0.\n", i);
829 char filename[PATH_MAX];
831 snprintf(filename,
sizeof(filename),
"%s/%s",
832 ast_config_AST_CONFIG_DIR, CONFIG_FILE);
833 config_file = fopen(filename,
"w");
839 for (i = 0; i < ARRAY_LEN(categories); ++i) {
841 fprintf(config_file,
"[%s]\n", categories[i].category);
842 for (j = 0; j < ARRAY_LEN(categories[i].vars); ++j) {
843 fprintf(config_file,
"%s = %s\n",
844 categories[i].vars[j].name,
845 categories[i].vars[j].
val);
858 char filename[PATH_MAX];
859 snprintf(filename,
sizeof(filename),
"%s/%s",
860 ast_config_AST_CONFIG_DIR, CONFIG_FILE);
873 static int hook_config_sane;
879 hook_config_sane = 1;
887 enum ast_test_result_state res = AST_TEST_FAIL;
890 char config_filename[PATH_MAX];
891 char include_filename[PATH_MAX];
892 struct stat config_stat;
897 info->name =
"config_save";
898 info->category =
"/main/config/";
899 info->summary =
"Test config save";
901 "Test configuration save.";
902 return AST_TEST_NOT_RUN;
908 ast_test_status_update(
test,
"Could not write initial config files\n");
912 snprintf(config_filename, PATH_MAX,
"%s/%s", ast_config_AST_CONFIG_DIR, CONFIG_FILE);
913 snprintf(include_filename, PATH_MAX,
"%s/%s", ast_config_AST_CONFIG_DIR, CONFIG_INCLUDE_FILE);
917 ast_test_status_update(
test,
"Could not load config\n");
923 ast_test_status_update(
test,
"Unable to write files\n");
927 stat(config_filename, &config_stat);
928 before_save = config_stat.st_size;
930 if (!ast_include_new(cfg, CONFIG_FILE, CONFIG_INCLUDE_FILE, 0, NULL, 4, include_filename, PATH_MAX)) {
931 ast_test_status_update(
test,
"Could not create include\n");
936 ast_test_status_update(
test,
"Unable to write files\n");
940 stat(config_filename, &config_stat);
941 if (config_stat.st_size <= before_save) {
942 ast_test_status_update(
test,
"Did not save config file with #include\n");
950 unlink(config_filename);
951 unlink(include_filename);
958 enum ast_test_result_state res = AST_TEST_FAIL;
966 info->name =
"config_hook";
967 info->category =
"/main/config/";
968 info->summary =
"Test config hooks";
970 "Ensure that config hooks are called at approriate times,"
971 "not called at inappropriate times, and that all information"
972 "that should be present is present.";
973 return AST_TEST_NOT_RUN;
995 if (!hook_run || !hook_config_sane) {
996 ast_test_status_update(
test,
"Config hook either did not run or was given bad data!\n");
1008 ast_test_status_update(
test,
"Config hook ran even though an incorrect file was specified.\n");
1020 ast_test_status_update(
test,
"Config hook ran even though an incorrect module was specified.\n");
1031 if (cfg != CONFIG_STATUS_FILEUNCHANGED) {
1035 ast_test_status_update(
test,
"Config hook ran even though file contents had not changed\n");
1039 res = AST_TEST_PASS;
1052 #define TOOBIG_I32 "2147483649"
1053 #define TOOSMALL_I32 "-2147483649"
1054 #define TOOBIG_U32 "4294967297"
1055 #define TOOSMALL_U32 "-4294967297"
1056 #define DEFAULTVAL 42
1057 #define EPSILON 0.001
1059 #define TEST_PARSE(input, should_succeed, expected_result, flags, result, ...) do {\
1060 int __res = ast_parse_arg(input, (flags), result, ##__VA_ARGS__); \
1061 if (!__res == !should_succeed) { \
1062 ast_test_status_update(test, "ast_parse_arg failed on '%s'. %d/%d\n", input, __res, should_succeed); \
1063 ret = AST_TEST_FAIL; \
1065 if (((flags) & PARSE_TYPE) == PARSE_INT32) { \
1066 int32_t *r = (int32_t *) (void *) result; \
1067 int32_t e = (int32_t) expected_result; \
1069 ast_test_status_update(test, "ast_parse_arg int32_t failed with %d != %d\n", *r, e); \
1070 ret = AST_TEST_FAIL; \
1072 } else if (((flags) & PARSE_TYPE) == PARSE_UINT32) { \
1073 uint32_t *r = (uint32_t *) (void *) result; \
1074 uint32_t e = (uint32_t) expected_result; \
1076 ast_test_status_update(test, "ast_parse_arg uint32_t failed with %u != %u\n", *r, e); \
1077 ret = AST_TEST_FAIL; \
1079 } else if (((flags) & PARSE_TYPE) == PARSE_DOUBLE) { \
1080 double *r = (double *) (void *) result; \
1081 double e = (double) expected_result; \
1082 if (fabs(*r - e) > EPSILON) { \
1083 ast_test_status_update(test, "ast_parse_arg double failed with %f != %f\n", *r, e); \
1084 ret = AST_TEST_FAIL; \
1086 } else if (((flags) & PARSE_TYPE) == PARSE_TIMELEN) { \
1087 int *r = (int *) (void *) result; \
1088 int e = (int) expected_result; \
1090 ast_test_status_update(test, "ast_parse_arg timelen failed with %d != %d\n", *r, e); \
1091 ret = AST_TEST_FAIL; \
1095 *(result) = DEFAULTVAL; \
1100 int ret = AST_TEST_PASS;
1101 int32_t int32_t_val = DEFAULTVAL;
1102 uint32_t uint32_t_val = DEFAULTVAL;
1103 int timelen_val = DEFAULTVAL;
1104 double double_val = DEFAULTVAL;
1108 info->name =
"ast_parse_arg";
1109 info->category =
"/config/";
1110 info->summary =
"Test the output of ast_parse_arg";
1112 "Ensures that ast_parse_arg behaves as expected";
1113 return AST_TEST_NOT_RUN;
1119 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_INT32, &int32_t_val);
1120 TEST_PARSE(
"-123", EXPECT_SUCCEED, -123, PARSE_INT32, &int32_t_val);
1121 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_INT32, &int32_t_val);
1122 TEST_PARSE(TOOBIG_I32, EXPECT_FAIL, DEFAULTVAL, PARSE_INT32, &int32_t_val);
1123 TEST_PARSE(TOOSMALL_I32, EXPECT_FAIL, DEFAULTVAL, PARSE_INT32, &int32_t_val);
1124 TEST_PARSE(
"not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_INT32, &int32_t_val);
1125 TEST_PARSE(
"7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_INT32, &int32_t_val);
1126 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_INT32 | PARSE_DEFAULT, &int32_t_val, 7);
1127 TEST_PARSE(
"-123", EXPECT_SUCCEED, -123, PARSE_INT32 | PARSE_DEFAULT, &int32_t_val, 7);
1128 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_INT32 | PARSE_DEFAULT, &int32_t_val, 7);
1129 TEST_PARSE(TOOBIG_I32, EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT, &int32_t_val, 7);
1130 TEST_PARSE(TOOSMALL_I32, EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT, &int32_t_val, 7);
1131 TEST_PARSE(
"not a number", EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT, &int32_t_val, 7);
1132 TEST_PARSE(
"7not a number", EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT, &int32_t_val, 7);
1134 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_INT32 | PARSE_IN_RANGE, &int32_t_val, 0, 200);
1135 TEST_PARSE(
"-123", EXPECT_SUCCEED, -123, PARSE_INT32 | PARSE_IN_RANGE, &int32_t_val, -200, 100);
1136 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_INT32 | PARSE_IN_RANGE, &int32_t_val, -1, 0);
1137 TEST_PARSE(
"123", EXPECT_FAIL, DEFAULTVAL, PARSE_INT32 | PARSE_IN_RANGE, &int32_t_val, 0, 122);
1138 TEST_PARSE(
"-123", EXPECT_FAIL, DEFAULTVAL, PARSE_INT32 | PARSE_IN_RANGE, &int32_t_val, -122, 100);
1139 TEST_PARSE(
"0", EXPECT_FAIL, DEFAULTVAL, PARSE_INT32 | PARSE_IN_RANGE, &int32_t_val, 1, 100);
1140 TEST_PARSE(TOOBIG_I32, EXPECT_FAIL, DEFAULTVAL, PARSE_INT32 | PARSE_IN_RANGE, &int32_t_val, INT_MIN, INT_MAX);
1141 TEST_PARSE(TOOSMALL_I32, EXPECT_FAIL, DEFAULTVAL, PARSE_INT32 | PARSE_IN_RANGE, &int32_t_val, INT_MIN, INT_MAX);
1142 TEST_PARSE(
"not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_INT32 | PARSE_IN_RANGE, &int32_t_val, INT_MIN, INT_MAX);
1143 TEST_PARSE(
"7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_INT32 | PARSE_IN_RANGE, &int32_t_val, INT_MIN, INT_MAX);
1144 TEST_PARSE(
"123", EXPECT_FAIL, DEFAULTVAL, PARSE_INT32 | PARSE_OUT_RANGE, &int32_t_val, 0, 200);
1145 TEST_PARSE(
"-123", EXPECT_FAIL, DEFAULTVAL, PARSE_INT32 | PARSE_OUT_RANGE, &int32_t_val, -200, 100);
1146 TEST_PARSE(
"0", EXPECT_FAIL, DEFAULTVAL, PARSE_INT32 | PARSE_OUT_RANGE, &int32_t_val, -1, 0);
1147 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_INT32 | PARSE_OUT_RANGE, &int32_t_val, 0, 122);
1148 TEST_PARSE(
"-123", EXPECT_SUCCEED, -123, PARSE_INT32 | PARSE_OUT_RANGE, &int32_t_val, -122, 100);
1149 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_INT32 | PARSE_OUT_RANGE, &int32_t_val, 1, 100);
1150 TEST_PARSE(TOOBIG_I32, EXPECT_FAIL, DEFAULTVAL, PARSE_INT32 | PARSE_OUT_RANGE, &int32_t_val, INT_MIN, INT_MAX);
1151 TEST_PARSE(TOOSMALL_I32, EXPECT_FAIL, DEFAULTVAL, PARSE_INT32 | PARSE_OUT_RANGE, &int32_t_val, INT_MIN, INT_MAX);
1152 TEST_PARSE(
"not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_INT32 | PARSE_OUT_RANGE, &int32_t_val, INT_MIN, INT_MAX);
1153 TEST_PARSE(
"7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_INT32 | PARSE_OUT_RANGE, &int32_t_val, INT_MIN, INT_MAX);
1155 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_INT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &int32_t_val, 7, 0, 200);
1156 TEST_PARSE(
"-123", EXPECT_SUCCEED, -123, PARSE_INT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &int32_t_val, 7, -200, 100);
1157 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_INT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &int32_t_val, 7, -1, 0);
1158 TEST_PARSE(
"123", EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &int32_t_val, 7, 0, 122);
1159 TEST_PARSE(
"-123", EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &int32_t_val, 7, -122, 100);
1160 TEST_PARSE(
"0", EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &int32_t_val, 7, 1, 100);
1161 TEST_PARSE(TOOBIG_I32, EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &int32_t_val, 7, INT_MIN, INT_MAX);
1162 TEST_PARSE(TOOSMALL_I32, EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &int32_t_val, 7, INT_MIN, INT_MAX);
1163 TEST_PARSE(
"not a number", EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &int32_t_val, 7, INT_MIN, INT_MAX);
1164 TEST_PARSE(
"7not a number", EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &int32_t_val, 7, INT_MIN, INT_MAX);
1165 TEST_PARSE(
"123", EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &int32_t_val, 7, 0, 200);
1166 TEST_PARSE(
"-123", EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &int32_t_val, 7, -200, 100);
1167 TEST_PARSE(
"0", EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &int32_t_val, 7, -1, 0);
1168 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_INT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &int32_t_val, 7, 0, 122);
1169 TEST_PARSE(
"-123", EXPECT_SUCCEED, -123, PARSE_INT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &int32_t_val, 7, -122, 100);
1170 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_INT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &int32_t_val, 7, 1, 100);
1171 TEST_PARSE(TOOBIG_I32, EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &int32_t_val, 7, INT_MIN, INT_MAX);
1172 TEST_PARSE(TOOSMALL_I32, EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &int32_t_val, 7, INT_MIN, INT_MAX);
1173 TEST_PARSE(
"not a number", EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &int32_t_val, 7, INT_MIN, INT_MAX);
1174 TEST_PARSE(
"7not a number", EXPECT_FAIL, 7, PARSE_INT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &int32_t_val, 7, INT_MIN, INT_MAX);
1177 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_UINT32, &uint32_t_val);
1178 TEST_PARSE(
"-123", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32, &uint32_t_val);
1179 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_UINT32, &uint32_t_val);
1180 TEST_PARSE(TOOBIG_U32, EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32, &uint32_t_val);
1181 TEST_PARSE(TOOSMALL_U32, EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32, &uint32_t_val);
1182 TEST_PARSE(
"not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32, &uint32_t_val);
1183 TEST_PARSE(
"7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32, &uint32_t_val);
1185 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_UINT32 | PARSE_DEFAULT, &uint32_t_val, 7);
1186 TEST_PARSE(
"-123", EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT, &uint32_t_val, 7);
1187 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_UINT32 | PARSE_DEFAULT, &uint32_t_val, 7);
1188 TEST_PARSE(TOOBIG_U32, EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT, &uint32_t_val, 7);
1189 TEST_PARSE(TOOSMALL_U32, EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT, &uint32_t_val, 7);
1190 TEST_PARSE(
"not a number", EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT, &uint32_t_val, 7);
1191 TEST_PARSE(
"7not a number", EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT, &uint32_t_val, 7);
1193 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_UINT32 | PARSE_IN_RANGE, &uint32_t_val, 0, 200);
1194 TEST_PARSE(
"-123", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32 | PARSE_IN_RANGE, &uint32_t_val, 0, 200);
1195 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_UINT32 | PARSE_IN_RANGE, &uint32_t_val, 0, 1);
1197 TEST_PARSE(
"123", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32 | PARSE_IN_RANGE, &uint32_t_val, 0, 122);
1198 TEST_PARSE(
"0", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32 | PARSE_IN_RANGE, &uint32_t_val, 1, 100);
1199 TEST_PARSE(TOOBIG_U32, EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32 | PARSE_IN_RANGE, &uint32_t_val, INT_MIN, INT_MAX);
1200 TEST_PARSE(TOOSMALL_U32, EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32 | PARSE_IN_RANGE, &uint32_t_val, INT_MIN, INT_MAX);
1201 TEST_PARSE(
"not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32 | PARSE_IN_RANGE, &uint32_t_val, INT_MIN, INT_MAX);
1202 TEST_PARSE(
"7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32 | PARSE_IN_RANGE, &uint32_t_val, INT_MIN, INT_MAX);
1204 TEST_PARSE(
"123", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32 | PARSE_OUT_RANGE, &uint32_t_val, 0, 200);
1205 TEST_PARSE(
"-123", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32 | PARSE_OUT_RANGE, &uint32_t_val, 0, 200);
1206 TEST_PARSE(
"0", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32 | PARSE_OUT_RANGE, &uint32_t_val, 0, 1);
1208 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_UINT32 | PARSE_OUT_RANGE, &uint32_t_val, 0, 122);
1209 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_UINT32 | PARSE_OUT_RANGE, &uint32_t_val, 1, 100);
1210 TEST_PARSE(TOOBIG_U32, EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32 | PARSE_OUT_RANGE, &uint32_t_val, INT_MIN, INT_MAX);
1211 TEST_PARSE(TOOSMALL_U32, EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32 | PARSE_OUT_RANGE, &uint32_t_val, INT_MIN, INT_MAX);
1212 TEST_PARSE(
"not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32 | PARSE_OUT_RANGE, &uint32_t_val, INT_MIN, INT_MAX);
1213 TEST_PARSE(
"7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32 | PARSE_OUT_RANGE, &uint32_t_val, INT_MIN, INT_MAX);
1215 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_UINT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &uint32_t_val, 7, 0, 200);
1216 TEST_PARSE(
"-123", EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &uint32_t_val, 7, 0, 200);
1217 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_UINT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &uint32_t_val, 7, 0, 1);
1218 TEST_PARSE(
"123", EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &uint32_t_val, 7, 0, 122);
1219 TEST_PARSE(
"0", EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &uint32_t_val, 7, 1, 100);
1220 TEST_PARSE(TOOBIG_U32, EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &uint32_t_val, 7, INT_MIN, INT_MAX);
1221 TEST_PARSE(TOOSMALL_U32, EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &uint32_t_val, 7, INT_MIN, INT_MAX);
1222 TEST_PARSE(
"not a number", EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &uint32_t_val, 7, INT_MIN, INT_MAX);
1223 TEST_PARSE(
"7not a number", EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT | PARSE_IN_RANGE, &uint32_t_val, 7, INT_MIN, INT_MAX);
1224 TEST_PARSE(
"123", EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &uint32_t_val, 7, 0, 200);
1225 TEST_PARSE(
"-123", EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &uint32_t_val, 7, 0, 100);
1226 TEST_PARSE(
"0", EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &uint32_t_val, 7, 0, 1);
1227 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_UINT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &uint32_t_val, 7, 0, 122);
1228 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_UINT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &uint32_t_val, 7, 1, 100);
1229 TEST_PARSE(TOOBIG_U32, EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &uint32_t_val, 7, INT_MIN, INT_MAX);
1230 TEST_PARSE(TOOSMALL_U32, EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &uint32_t_val, 7, INT_MIN, INT_MAX);
1231 TEST_PARSE(
"not a number", EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &uint32_t_val, 7, INT_MIN, INT_MAX);
1232 TEST_PARSE(
"7not a number", EXPECT_FAIL, 7, PARSE_UINT32 | PARSE_DEFAULT | PARSE_OUT_RANGE, &uint32_t_val, 7, INT_MIN, INT_MAX);
1234 TEST_PARSE(
" -123", EXPECT_FAIL, DEFAULTVAL, PARSE_UINT32, &uint32_t_val);
1237 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
1238 TEST_PARSE(
"-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
1239 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
1240 TEST_PARSE(
"not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
1241 TEST_PARSE(
"7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
1243 TEST_PARSE(
"123s", EXPECT_SUCCEED, 123000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
1244 TEST_PARSE(
"-123s", EXPECT_SUCCEED, -123000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
1245 TEST_PARSE(
"1m", EXPECT_SUCCEED, 60000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
1246 TEST_PARSE(
"1", EXPECT_SUCCEED, 60000, PARSE_TIMELEN, &timelen_val, TIMELEN_MINUTES);
1247 TEST_PARSE(
"1h", EXPECT_SUCCEED, 3600000, PARSE_TIMELEN, &timelen_val, TIMELEN_MILLISECONDS);
1248 TEST_PARSE(
"1", EXPECT_SUCCEED, 3600000, PARSE_TIMELEN, &timelen_val, TIMELEN_HOURS);
1250 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);
1251 TEST_PARSE(
"-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);
1252 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);
1253 TEST_PARSE(
"not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);
1254 TEST_PARSE(
"7not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT, &timelen_val, TIMELEN_MILLISECONDS, 7);
1256 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 200);
1257 TEST_PARSE(
"-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -200, 100);
1258 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -1, 0);
1259 TEST_PARSE(
"123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 122);
1260 TEST_PARSE(
"-123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -122, 100);
1261 TEST_PARSE(
"0", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 1, 100);
1262 TEST_PARSE(
"not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX);
1263 TEST_PARSE(
"7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX);
1264 TEST_PARSE(
"123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 200);
1265 TEST_PARSE(
"-123", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -200, 100);
1266 TEST_PARSE(
"0", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -1, 0);
1267 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 0, 122);
1268 TEST_PARSE(
"-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, -122, 100);
1269 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 1, 100);
1270 TEST_PARSE(
"not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX);
1271 TEST_PARSE(
"7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_TIMELEN | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, INT_MIN, INT_MAX);
1273 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 200);
1274 TEST_PARSE(
"-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -200, 100);
1275 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -1, 0);
1276 TEST_PARSE(
"123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 122);
1277 TEST_PARSE(
"-123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -122, 100);
1278 TEST_PARSE(
"0", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 1, 100);
1279 TEST_PARSE(
"not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX);
1280 TEST_PARSE(
"7not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_IN_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX);
1281 TEST_PARSE(
"123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 200);
1282 TEST_PARSE(
"-123", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -200, 100);
1283 TEST_PARSE(
"0", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -1, 0);
1284 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 0, 122);
1285 TEST_PARSE(
"-123", EXPECT_SUCCEED, -123, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, -122, 100);
1286 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, 1, 100);
1287 TEST_PARSE(
"not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX);
1288 TEST_PARSE(
"7not a number", EXPECT_FAIL, 7, PARSE_TIMELEN | PARSE_DEFAULT | PARSE_OUT_RANGE, &timelen_val, TIMELEN_MILLISECONDS, 7, INT_MIN, INT_MAX);
1291 TEST_PARSE(
"123", EXPECT_SUCCEED, 123, PARSE_DOUBLE, &double_val);
1292 TEST_PARSE(
"123.123", EXPECT_SUCCEED, 123.123, PARSE_DOUBLE, &double_val);
1293 TEST_PARSE(
"-123", EXPECT_SUCCEED, -123, PARSE_DOUBLE, &double_val);
1294 TEST_PARSE(
"-123.123", EXPECT_SUCCEED, -123.123, PARSE_DOUBLE, &double_val);
1295 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_DOUBLE, &double_val);
1296 TEST_PARSE(
"not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_DOUBLE, &double_val);
1297 TEST_PARSE(
"7.0not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_DOUBLE, &double_val);
1298 TEST_PARSE(
"123.123", EXPECT_SUCCEED, 123.123, PARSE_DOUBLE | PARSE_DEFAULT, &double_val, 7.0);
1299 TEST_PARSE(
"-123.123", EXPECT_SUCCEED, -123.123, PARSE_DOUBLE | PARSE_DEFAULT, &double_val, 7.0);
1300 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_DOUBLE | PARSE_DEFAULT, &double_val, 7.0);
1301 TEST_PARSE(
"not a number", EXPECT_FAIL, 7.0, PARSE_DOUBLE | PARSE_DEFAULT, &double_val, 7.0);
1302 TEST_PARSE(
"7.0not a number", EXPECT_FAIL, 7.0, PARSE_DOUBLE | PARSE_DEFAULT, &double_val, 7.0);
1304 TEST_PARSE(
"123.123", EXPECT_SUCCEED, 123.123, PARSE_DOUBLE | PARSE_IN_RANGE, &double_val, 0.0, 200.0);
1305 TEST_PARSE(
"-123.123", EXPECT_SUCCEED, -123.123, PARSE_DOUBLE | PARSE_IN_RANGE, &double_val, -200.0, 100.0);
1306 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_DOUBLE | PARSE_IN_RANGE, &double_val, -1.0, 0.0);
1307 TEST_PARSE(
"123.123", EXPECT_FAIL, DEFAULTVAL, PARSE_DOUBLE | PARSE_IN_RANGE, &double_val, 0.0, 122.0);
1308 TEST_PARSE(
"-123.123", EXPECT_FAIL, DEFAULTVAL, PARSE_DOUBLE | PARSE_IN_RANGE, &double_val, -122.0, 100.0);
1309 TEST_PARSE(
"0", EXPECT_FAIL, DEFAULTVAL, PARSE_DOUBLE | PARSE_IN_RANGE, &double_val, 1.0, 100.0);
1310 TEST_PARSE(
"not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_DOUBLE | PARSE_IN_RANGE, &double_val, -HUGE_VAL, HUGE_VAL);
1311 TEST_PARSE(
"7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_DOUBLE | PARSE_IN_RANGE, &double_val, -HUGE_VAL, HUGE_VAL);
1312 TEST_PARSE(
"123.123", EXPECT_FAIL, DEFAULTVAL, PARSE_DOUBLE | PARSE_OUT_RANGE, &double_val, 0.0, 200.0);
1313 TEST_PARSE(
"-123.123", EXPECT_FAIL, DEFAULTVAL, PARSE_DOUBLE | PARSE_OUT_RANGE, &double_val, -200.0, 100.0);
1314 TEST_PARSE(
"0", EXPECT_FAIL, DEFAULTVAL, PARSE_DOUBLE | PARSE_OUT_RANGE, &double_val, -1.0, 0.0);
1315 TEST_PARSE(
"123.123", EXPECT_SUCCEED, 123.123, PARSE_DOUBLE | PARSE_OUT_RANGE, &double_val, 0.0, 122.0);
1316 TEST_PARSE(
"-123.123", EXPECT_SUCCEED, -123.123, PARSE_DOUBLE | PARSE_OUT_RANGE, &double_val, -122.0, 100.0);
1317 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_DOUBLE | PARSE_OUT_RANGE, &double_val, 1.0, 100.0);
1318 TEST_PARSE(
"not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_DOUBLE | PARSE_OUT_RANGE, &double_val, -HUGE_VAL, HUGE_VAL);
1319 TEST_PARSE(
"7not a number", EXPECT_FAIL, DEFAULTVAL, PARSE_DOUBLE | PARSE_OUT_RANGE, &double_val, -HUGE_VAL, HUGE_VAL);
1321 TEST_PARSE(
"123.123", EXPECT_SUCCEED, 123.123, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_IN_RANGE, &double_val, 7.0, 0.0, 200.0);
1322 TEST_PARSE(
"-123.123", EXPECT_SUCCEED, -123.123, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_IN_RANGE, &double_val, 7.0, -200.0, 100.0);
1323 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_IN_RANGE, &double_val, 7.0, -1.0, 0.0);
1324 TEST_PARSE(
"123.123", EXPECT_FAIL, 7.0, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_IN_RANGE, &double_val, 7.0, 0.0, 122.0);
1325 TEST_PARSE(
"-123.123", EXPECT_FAIL, 7.0, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_IN_RANGE, &double_val, 7.0, -122.0, 100.0);
1326 TEST_PARSE(
"0", EXPECT_FAIL, 7.0, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_IN_RANGE, &double_val, 7.0, 1.0, 100.0);
1327 TEST_PARSE(
"not a number", EXPECT_FAIL, 7.0, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_IN_RANGE, &double_val, 7.0, -HUGE_VAL, HUGE_VAL);
1328 TEST_PARSE(
"7not a number", EXPECT_FAIL, 7.0, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_IN_RANGE, &double_val, 7.0, -HUGE_VAL, HUGE_VAL);
1329 TEST_PARSE(
"123.123", EXPECT_FAIL, 7.0, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_OUT_RANGE, &double_val, 7.0, 0.0, 200.0);
1330 TEST_PARSE(
"-123.123", EXPECT_FAIL, 7.0, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_OUT_RANGE, &double_val, 7.0, -200.0, 100.0);
1331 TEST_PARSE(
"0", EXPECT_FAIL, 7.0, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_OUT_RANGE, &double_val, 7.0, -1.0, 0.0);
1332 TEST_PARSE(
"123.123", EXPECT_SUCCEED, 123.123, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_OUT_RANGE, &double_val, 7.0, 0.0, 122.0);
1333 TEST_PARSE(
"-123.123", EXPECT_SUCCEED, -123.123, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_OUT_RANGE, &double_val, 7.0, -122.0, 100.0);
1334 TEST_PARSE(
"0", EXPECT_SUCCEED, 0, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_OUT_RANGE, &double_val, 7.0, 1.0, 100.0);
1335 TEST_PARSE(
"not a number", EXPECT_FAIL, 7.0, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_OUT_RANGE, &double_val, 7.0, -HUGE_VAL, HUGE_VAL);
1336 TEST_PARSE(
"7not a number", EXPECT_FAIL, 7.0, PARSE_DOUBLE | PARSE_DEFAULT | PARSE_OUT_RANGE, &double_val, 7.0, -HUGE_VAL, HUGE_VAL);
1359 unsigned int customopt:1;
1367 static int test_item_cmp(
void *obj,
void *arg,
int flags)
1369 struct test_item *one = obj, *two = arg;
1370 const char *match = (flags &
OBJ_KEY) ? arg : two->name;
1373 static void test_item_destructor(
void *obj)
1377 ao2_cleanup(item->codeccapopt);
1383 static void *test_item_alloc(
const char *cat)
1386 if (!(item = ao2_alloc(
sizeof(*item), test_item_destructor))) {
1400 static void test_config_destructor(
void *obj)
1403 ao2_cleanup(cfg->global);
1404 ao2_cleanup(cfg->global_defaults);
1405 ao2_cleanup(cfg->items);
1407 static void *test_config_alloc(
void)
1410 if (!(cfg = ao2_alloc(
sizeof(*cfg), test_config_destructor))) {
1413 if (!(cfg->global = test_item_alloc(
"global"))) {
1416 if (!(cfg->global_defaults = test_item_alloc(
"global_defaults"))) {
1430 return ao2_find(container, cat,
OBJ_KEY);
1436 if (!strcasecmp(var->
name,
"customopt")) {
1447 .item_offset = offsetof(
struct test_config, global),
1449 .category =
"^global$",
1451 static struct aco_type global_defaults = {
1453 .item_offset = offsetof(
struct test_config, global_defaults),
1455 .category =
"global_defaults",
1457 static const char *item_blacklist[] = {
1466 .category = (
const char *)item_blacklist,
1472 struct aco_file config_test_conf = {
1474 .types =
ACO_TYPES(&global, &global_defaults, &item),
1478 CONFIG_INFO_TEST(cfg_info, global_obj, test_config_alloc,
1479 .files = ACO_FILES(&config_test_conf),
1484 int res = AST_TEST_PASS, x, error;
1487 struct ast_sockaddr acl_allow = {{ 0, }}, acl_fail = {{ 0, }};
1494 info->name =
"config_options_test";
1495 info->category =
"/config/";
1496 info->summary =
"Config options unit test";
1498 "Tests the Config Options API";
1499 return AST_TEST_NOT_RUN;
1504 #define INT_DEFAULT "-2"
1505 #define INT_CONFIG "-1"
1506 #define UINT_DEFAULT "2"
1507 #define UINT_CONFIG "1"
1508 #define TIMELEN_DEFAULT "2"
1509 #define TIMELEN_CONFIG "1"
1510 #define DOUBLE_DEFAULT "1.1"
1511 #define DOUBLE_CONFIG "0.1"
1512 #define SOCKADDR_DEFAULT "4.3.2.1:4321"
1513 #define SOCKADDR_CONFIG "1.2.3.4:1234"
1514 #define BOOL_DEFAULT "false"
1515 #define BOOL_CONFIG "true"
1516 #define BOOLFLAG1_DEFAULT "false"
1517 #define BOOLFLAG1_CONFIG "true"
1518 #define BOOLFLAG2_DEFAULT "false"
1519 #define BOOLFLAG2_CONFIG "false"
1520 #define BOOLFLAG3_DEFAULT "false"
1521 #define BOOLFLAG3_CONFIG "true"
1522 #define ACL_DEFAULT NULL
1523 #define ACL_CONFIG_PERMIT "1.2.3.4/32"
1524 #define ACL_CONFIG_DENY "0.0.0.0/0"
1525 #define CODEC_DEFAULT "!all,alaw"
1526 #define CODEC_CONFIG "!all,ulaw,g729"
1527 #define STR_DEFAULT "default"
1528 #define STR_CONFIG "test"
1529 #define CUSTOM_DEFAULT "no"
1530 #define CUSTOM_CONFIG "yes"
1532 #define BOOLFLAG1 1 << 0
1533 #define BOOLFLAG2 1 << 1
1534 #define BOOLFLAG3 1 << 2
1537 ast_test_status_update(
test,
"Could not init cfg info\n");
1538 return AST_TEST_FAIL;
1563 ast_test_status_update(
test,
"Could not parse config\n");
1564 return AST_TEST_FAIL;
1569 ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt1, TIMELEN_MILLISECONDS);
1571 ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt2, TIMELEN_SECONDS);
1573 ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt3, TIMELEN_MINUTES);
1575 ast_parse_arg(TIMELEN_DEFAULT, PARSE_TIMELEN, &defaults.timelenopt4, TIMELEN_HOURS);
1577 ast_parse_arg(UINT_DEFAULT, PARSE_UINT32, &defaults.uintopt);
1579 ast_parse_arg(DOUBLE_DEFAULT, PARSE_DOUBLE, &defaults.doubleopt);
1581 ast_parse_arg(SOCKADDR_DEFAULT, PARSE_ADDR, &defaults.sockaddropt);
1583 defaults.boolopt =
ast_true(BOOL_DEFAULT);
1585 ast_set2_flag(&defaults,
ast_true(BOOLFLAG1_DEFAULT), BOOLFLAG1);
1586 ast_set2_flag(&defaults,
ast_true(BOOLFLAG2_DEFAULT), BOOLFLAG2);
1587 ast_set2_flag(&defaults,
ast_true(BOOLFLAG3_DEFAULT), BOOLFLAG3);
1592 defaults.aclopt = NULL;
1609 defaults.customopt =
ast_true(CUSTOM_DEFAULT);
1614 if (!(item = ao2_find(cfg->items,
"item",
OBJ_KEY))) {
1615 ast_test_status_update(
test,
"could not look up 'item'\n");
1616 return AST_TEST_FAIL;
1618 if (!(item_defaults = ao2_find(cfg->items,
"item_defaults",
OBJ_KEY))) {
1619 ast_test_status_update(
test,
"could not look up 'item_defaults'\n");
1620 return AST_TEST_FAIL;
1622 arr[0] = cfg->global;
1624 arr[2] = cfg->global_defaults;
1625 arr[3] = item_defaults;
1628 #define NOT_EQUAL_FAIL(field, format) \
1629 if (arr[x]->field != control->field) { \
1630 ast_test_status_update(test, "%s did not match: " format " != " format " with x = %d\n", #field, arr[x]->field, control->field, x); \
1631 res = AST_TEST_FAIL; \
1633 for (x = 0; x < 4; x++) {
1636 NOT_EQUAL_FAIL(intopt,
"%d");
1637 NOT_EQUAL_FAIL(uintopt,
"%u");
1638 NOT_EQUAL_FAIL(timelenopt1,
"%d");
1639 NOT_EQUAL_FAIL(timelenopt2,
"%d");
1640 NOT_EQUAL_FAIL(timelenopt3,
"%d");
1641 NOT_EQUAL_FAIL(timelenopt4,
"%d");
1642 NOT_EQUAL_FAIL(boolopt,
"%d");
1643 NOT_EQUAL_FAIL(flags,
"%u");
1644 NOT_EQUAL_FAIL(customopt,
"%d");
1645 if (fabs(arr[x]->doubleopt - control->doubleopt) > 0.001) {
1646 ast_test_status_update(
test,
"doubleopt did not match: %f vs %f on loop %d\n", arr[x]->doubleopt, control->doubleopt, x);
1647 res = AST_TEST_FAIL;
1650 ast_test_status_update(
test,
"sockaddr did not match on loop %d\n", x);
1651 res = AST_TEST_FAIL;
1657 ast_test_status_update(
test,
"format did not match: '%s' vs '%s' on loop %d\n",
1661 res = AST_TEST_FAIL;
1663 if (strcasecmp(arr[x]->stropt, control->stropt)) {
1664 ast_test_status_update(
test,
"stropt did not match: '%s' vs '%s' on loop %d\n", arr[x]->stropt, control->stropt, x);
1665 res = AST_TEST_FAIL;
1667 if (arr[x]->aclopt != control->aclopt && (
ast_apply_ha(arr[x]->aclopt, &acl_allow) !=
ast_apply_ha(control->aclopt, &acl_allow) ||
1669 ast_test_status_update(
test,
"acl not match: on loop %d\n", x);
1670 res = AST_TEST_FAIL;
1675 ao2_cleanup(defaults.codeccapopt);
1676 defaults.codeccapopt = NULL;
1677 ao2_cleanup(
configs.codeccapopt);
1688 enum ast_test_result_state res = AST_TEST_PASS;
1690 char filename[PATH_MAX];
1695 info->name =
"config_dialplan_function";
1696 info->category =
"/main/config/";
1697 info->summary =
"Test AST_CONFIG dialplan function";
1698 info->description =
"Test AST_CONFIG dialplan function";
1699 return AST_TEST_NOT_RUN;
1704 snprintf(filename,
sizeof(filename),
"%s/%s",
1705 ast_config_AST_CONFIG_DIR, CONFIG_FILE);
1706 config_file = fopen(filename,
"w");
1709 return AST_TEST_FAIL;
1723 fclose(config_file);
1726 ast_test_status_update(
test,
"Failed to allocate return buffer\n");
1727 res = AST_TEST_FAIL;
1731 if (
ast_func_read2(NULL,
"AST_CONFIG("CONFIG_FILE
",c1,var1)", &buf, 32)) {
1732 ast_test_status_update(
test,
"Failed to retrieve field 'var1'\n");
1733 res = AST_TEST_FAIL;
1737 ast_test_status_update(
test,
"Got '%s', should be '%s'\n",
1739 res = AST_TEST_FAIL;
1744 if (
ast_func_read2(NULL,
"AST_CONFIG("CONFIG_FILE
",c1,var1,0)", &buf, 32)) {
1745 ast_test_status_update(
test,
"Failed to retrieve field 'var1'\n");
1746 res = AST_TEST_FAIL;
1750 ast_test_status_update(
test,
"Got '%s', should be '%s'\n",
1752 res = AST_TEST_FAIL;
1757 if (
ast_func_read2(NULL,
"AST_CONFIG("CONFIG_FILE
",c1,var1,1)", &buf, 32)) {
1758 ast_test_status_update(
test,
"Failed to retrieve field 'var1'\n");
1759 res = AST_TEST_FAIL;
1763 ast_test_status_update(
test,
"Got '%s', should be '%s'\n",
1765 res = AST_TEST_FAIL;
1770 if (
ast_func_read2(NULL,
"AST_CONFIG("CONFIG_FILE
",c1,var1,2)", &buf, 32)) {
1771 ast_test_status_update(
test,
"Failed to retrieve field 'var1'\n");
1772 res = AST_TEST_FAIL;
1776 ast_test_status_update(
test,
"Got '%s', should be '%s'\n",
1778 res = AST_TEST_FAIL;
1783 if (
ast_func_read2(NULL,
"AST_CONFIG("CONFIG_FILE
",c1,var1,3)", &buf, 32)) {
1784 ast_test_status_update(
test,
"Failed to retrieve field 'var1'\n");
1785 res = AST_TEST_FAIL;
1789 ast_test_status_update(
test,
"Got '%s', should be '%s'\n",
1791 res = AST_TEST_FAIL;
1796 if (
ast_func_read2(NULL,
"AST_CONFIG("CONFIG_FILE
",c1,var1,-1)", &buf, 32)) {
1797 ast_test_status_update(
test,
"Failed to retrieve field 'var1'\n");
1798 res = AST_TEST_FAIL;
1802 ast_test_status_update(
test,
"Got '%s', should be '%s'\n",
1804 res = AST_TEST_FAIL;
1809 if (
ast_func_read2(NULL,
"AST_CONFIG("CONFIG_FILE
",c1,var2,-1)", &buf, 32)) {
1810 ast_test_status_update(
test,
"Failed to retrieve field 'var2'\n");
1811 res = AST_TEST_FAIL;
1815 ast_test_status_update(
test,
"Got '%s', should be '%s'\n",
1817 res = AST_TEST_FAIL;
1822 if (!
ast_func_read2(NULL,
"AST_CONFIG("CONFIG_FILE
",c1,var1,5)", &buf, 32)) {
1823 ast_test_status_update(
test,
"Should not have retrieved a value\n");
1824 res = AST_TEST_FAIL;
1844 info->name =
"variable_lists_match";
1845 info->category =
"/main/config/";
1846 info->summary =
"Test ast_variable_lists_match";
1847 info->description =
"Test ast_variable_lists_match";
1848 return AST_TEST_NOT_RUN;
1853 var = ast_variable_new(
"aaa",
"111",
"");
1854 ast_test_validate(
test, var);
1856 var = ast_variable_new(
"bbb",
"222",
"");
1857 ast_test_validate(
test, var);
1858 ast_variable_list_append(&left, var);
1860 var = ast_variable_new(
"aaa",
"111",
"");
1861 ast_test_validate(
test, var);
1867 var = ast_variable_new(
"bbb",
"222",
"");
1868 ast_test_validate(
test, var);
1869 ast_variable_list_append(&right, var);
1874 var = ast_variable_new(
"ccc >",
"333",
"");
1875 ast_test_validate(
test, var);
1876 ast_variable_list_append(&right, var);
1881 var = ast_variable_new(
"ccc",
"444",
"");
1882 ast_test_validate(
test, var);
1883 ast_variable_list_append(&left, var);
1893 return AST_TEST_PASS;
1905 info->name =
"variable_list_join_replace";
1906 info->category =
"/main/config/";
1907 info->summary =
"Test joining a variable list";
1908 info->description = info->summary;
1909 return AST_TEST_NOT_RUN;
1914 list = ast_variable_new(
"aaa",
"111",
"");
1915 bbb = ast_variable_new(
"bbb",
"222",
"");
1916 ast_variable_list_append(&list, bbb);
1917 ast_variable_list_append(&list, ast_variable_new(
"ccc",
"33 33",
""));
1920 ast_test_validate(
test, strcmp(
ast_str_buffer(str),
"aaa = \"111\", bbb = \"222\", ccc = \"33 33\"") == 0);
1925 ast_test_validate(
test, strcmp(
ast_str_buffer(str),
"aaa = \"111\", bbb = \"222\", ccc = \"33 33\"") == 0);
1929 ast_test_validate(
test, strcmp(
ast_str_buffer(str),
"aaa = \"111\", bbb = \"222\", ccc = \"33 33\"") == 0);
1934 ast_test_validate(
test, rc == 0);
1936 ast_test_validate(
test, strcmp(
ast_str_buffer(str),
"ddd = \"444\", bbb = \"222\", ccc = \"33 33\"") == 0);
1940 ast_test_validate(
test, rc == 0);
1942 ast_test_validate(
test, strcmp(
ast_str_buffer(str),
"ddd = \"444\", eee = \"555\", ccc = \"33 33\"") == 0);
1944 return AST_TEST_PASS;
1955 info->name =
"variable_list_from_quoted_string";
1956 info->category =
"/main/config/";
1957 info->summary =
"Test parsing a string into a variable list";
1958 info->description = info->summary;
1959 return AST_TEST_NOT_RUN;
1964 parse_string =
"000= '', 111=, 222 = , 333 = ' ', abc = 'def', ghi = 'j,kl', mno='pq=r', stu = 'vwx=\"yz\", ABC = \"DEF\"'";
1966 ast_test_validate(
test, list != NULL);
1969 ast_test_validate(
test,
1970 strcmp(
ast_str_buffer(str),
"000^@@|111^@@|222^@@|333^@ @|abc^@def@|ghi^@j,kl@|mno^@pq=r@|stu^@vwx=\"yz\", ABC = \"DEF\"@") == 0);
1972 return AST_TEST_PASS;
1975 static int unload_module(
void)
1977 AST_TEST_UNREGISTER(config_save);
1978 AST_TEST_UNREGISTER(config_basic_ops);
1979 AST_TEST_UNREGISTER(config_filtered_ops);
1980 AST_TEST_UNREGISTER(config_template_ops);
1981 AST_TEST_UNREGISTER(copy_config);
1982 AST_TEST_UNREGISTER(config_hook);
1983 AST_TEST_UNREGISTER(ast_parse_arg_test);
1984 AST_TEST_UNREGISTER(config_options_test);
1985 AST_TEST_UNREGISTER(config_dialplan_function);
1986 AST_TEST_UNREGISTER(variable_lists_match);
1987 AST_TEST_UNREGISTER(variable_list_join_replace);
1988 AST_TEST_UNREGISTER(variable_list_from_string);
1992 static int load_module(
void)
1994 AST_TEST_REGISTER(config_save);
1995 AST_TEST_REGISTER(config_basic_ops);
1996 AST_TEST_REGISTER(config_filtered_ops);
1997 AST_TEST_REGISTER(config_template_ops);
1998 AST_TEST_REGISTER(copy_config);
1999 AST_TEST_REGISTER(config_hook);
2000 AST_TEST_REGISTER(ast_parse_arg_test);
2001 AST_TEST_REGISTER(config_options_test);
2002 AST_TEST_REGISTER(config_dialplan_function);
2003 AST_TEST_REGISTER(variable_lists_match);
2004 AST_TEST_REGISTER(variable_list_join_replace);
2005 AST_TEST_REGISTER(variable_list_from_string);
Type for default handler for ast_sockaddrs.
struct ast_category * ast_category_new(const char *name, const char *in_file, int lineno)
Create a category.
struct ast_variable * next
Type for default option handler for format capabilities.
aco_type_item_find item_find
int ast_config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator)
Save a config text file preserving the pre 13.2 behavior.
Asterisk main include file. File version handling, generic pbx functions.
int ast_parse_arg(const char *arg, enum ast_parse_flags flags, void *p_result,...)
The argument parsing routine.
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
#define aco_option_register_custom(info, name, matchtype, types, default_val, handler, flags)
Register a config option.
int ast_sockaddr_parse(struct ast_sockaddr *addr, const char *str, int flags)
Parse an IPv4 or IPv6 address string.
int ast_func_read2(struct ast_channel *chan, const char *function, struct ast_str **str, ssize_t maxlen)
executes a read operation on a function
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
#define aco_option_register(info, name, matchtype, types, default_val, opt_type, flags,...)
Register a config option.
#define ao2_container_alloc_list(ao2_options, container_options, sort_fn, cmp_fn)
Allocate and initialize a list container.
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Structure for variables, used for configurations and for channel variables.
struct ast_category * ast_category_delete(struct ast_config *cfg, struct ast_category *cat)
Delete a category.
enum ast_acl_sense ast_apply_ha(const struct ast_ha *ha, const struct ast_sockaddr *addr)
Apply a set of rules to a given IP address.
enum aco_process_status aco_process_config(struct aco_info *info, int reload)
Process a config info via the options registered with an aco_info.
#define ao2_global_obj_ref(holder)
Get a reference to the object stored in the global holder.
static int copy(char *infile, char *outfile)
Utility function to copy a file.
#define AST_DECLARE_STRING_FIELDS(field_list)
Declare the fields needed in a structure.
Type for default option handler for bools (ast_true/ast_false) that are stored in a flag...
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
The representation of a single configuration file to be processed.
const char * ast_variable_find_last_in_list(const struct ast_variable *list, const char *variable)
Gets the value of the LAST occurrence of a variable from a variable list.
Socket address structure.
#define ACO_TYPES(...)
A helper macro to ensure that aco_info types always have a sentinel.
struct ast_category * ast_category_browse_filtered(struct ast_config *config, const char *category_name, struct ast_category *prev, const char *filter)
Browse categories with filters.
void ast_category_append(struct ast_config *config, struct ast_category *category)
Appends a category to a config.
internal representation of ACL entries In principle user applications would have no need for this...
Configuration File Parser.
void ast_config_hook_unregister(const char *name)
Unregister a config hook.
static const char config_file[]
#define ast_config_load(filename, flags)
Load a config file.
#define FLDSET(type,...)
Convert a struct and list of fields to an argument list of field offsets.
int aco_info_init(struct aco_info *info)
Initialize an aco_info structure.
Asterisk file paths, configured in asterisk.conf.
Type for default option handler for unsigned integers.
int ast_config_hook_register(const char *name, const char *filename, const char *module, enum config_hook_flags flags, config_hook_cb hook)
Register a config hook for a particular file and module.
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Access Control of various sorts.
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
#define AST_STRING_FIELD(name)
Declare a string field.
Asterisk internal frame definitions.
static int write_config_file(void)
Write the config file to disk.
const char * ast_variable_find_in_list(const struct ast_variable *list, const char *variable)
Gets the value of a variable from a variable list by name.
aco_type_item_alloc item_alloc
struct ao2_container * container
int aco_option_register_deprecated(struct aco_info *info, const char *name, struct aco_type **types, const char *aliased_to)
Register a deprecated (and aliased) config option.
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
struct ast_variable * ast_variable_list_append_hint(struct ast_variable **head, struct ast_variable *search_hint, struct ast_variable *new_var)
Appends a variable list to the end of another list.
Core PBX routines and definitions.
int ast_variable_list_replace_variable(struct ast_variable **head, struct ast_variable *oldvar, struct ast_variable *newvar)
Replace a variable in the given list with a new variable.
Their was an error and no changes were applied.
Configuration option-handling.
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Support for dynamic strings.
void aco_info_destroy(struct aco_info *info)
Destroy an initialized aco_info struct.
#define ao2_global_obj_release(holder)
Release the ao2 object held in the global holder.
Type for default option handler for bools (ast_true/ast_false)
int ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match)
Inserts new category.
struct ast_config * ast_config_copy(const struct ast_config *orig)
Copies the contents of one ast_config into another.
Type for default option handler for ACLs.
Type for default option handler for doubles.
#define STRFLDSET(type,...)
Convert a struct and a list of stringfield fields to an argument list of field offsets.
Support for logging to various files, console and syslog Configuration in file logger.conf.
const char * ast_variable_find(const struct ast_category *category, const char *variable)
Gets a variable value from a specific category structure by name.
Structure used to handle boolean flags.
config_hook_flags
Flags that affect the behaviour of config hooks.
struct ast_category * ast_category_new_template(const char *name, const char *in_file, int lineno)
Create a category making it a template.
void ast_free_ha(struct ast_ha *ha)
Free a list of HAs.
void ast_str_reset(struct ast_str *buf)
Reset the content of a dynamic string. Useful before a series of ast_str_append.
static void delete_config_file(void)
Delete config file created by write_config_file.
int ast_category_empty(struct ast_category *category)
Removes and destroys all variables in a category.
int ast_variable_lists_match(const struct ast_variable *left, const struct ast_variable *right, int exact_match)
Tests 2 variable lists to see if they match.
Type for default option handler for time length signed integers.
struct ast_str * ast_variable_list_join(const struct ast_variable *head, const char *item_separator, const char *name_value_separator, const char *quote_char, struct ast_str **str)
Join an ast_variable list with specified separators and quoted values.
Type information about a category-level configurable object.
#define AST_TEST_DEFINE(hdr)
Type for default option handler for stringfields.
struct ast_ha * ast_append_ha(const char *sense, const char *stuff, struct ast_ha *path, int *error)
Add a new rule to a list of HAs.
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name, const char *filter)
Retrieve a category if it exists.
static struct ast_config * build_cfg(void)
Build ast_config struct from above definitions.
void ast_config_destroy(struct ast_config *cfg)
Destroys a config.
struct aco_type * types[]
Type for default option handler for signed integers.
#define AO2_GLOBAL_OBJ_STATIC(name)
Define a global object holder to be used to hold an ao2 object, statically initialized.
#define ASTERISK_GPL_KEY
The text the key() function should return.
Asterisk module definitions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
#define ast_string_field_free_memory(x)
free all memory - to be called before destroying the object
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
static int test_config_validity(struct ast_config *cfg)
Tests that the contents of an ast_config is what is expected.
const char * ast_category_get_name(const struct ast_category *category)
Return the name of the category.
struct ast_variable * ast_variable_list_from_quoted_string(const char *input, const char *item_separator, const char *name_value_separator, const char *quote_str)
Parse a string into an ast_variable list. The reverse of ast_variable_list_join.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
#define AST_MAX_USER_FIELD