Add unique constraint to enumeration parameters
Enum parameters can now be declared unique. This prevents multiple values for enumerations which only accept one value.
This commit is contained in:
parent
73a1388468
commit
a1293fbd79
@ -98,7 +98,8 @@ enum mxs_module_param_options
|
||||
MXS_MODULE_OPT_PATH_X_OK = (1 << 1), /**< PATH: Execute permission to path required */
|
||||
MXS_MODULE_OPT_PATH_R_OK = (1 << 2), /**< PATH: Read permission to path required */
|
||||
MXS_MODULE_OPT_PATH_W_OK = (1 << 3), /**< PATH: Write permission to path required */
|
||||
MXS_MODULE_OPT_PATH_F_OK = (1 << 4) /**< PATH: Path must exist */
|
||||
MXS_MODULE_OPT_PATH_F_OK = (1 << 4), /**< PATH: Path must exist */
|
||||
MXS_MODULE_OPT_ENUM_UNIQUE = (1 << 5) /**< ENUM: Only one value can be defined */
|
||||
};
|
||||
|
||||
/** String to enum value mappings */
|
||||
|
@ -3262,7 +3262,16 @@ bool config_param_is_valid(const MXS_MODULE_PARAM *params, const char *key,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
tok = strtok_r(NULL, delim, &endptr);
|
||||
|
||||
if ((params[i].options & MXS_MODULE_OPT_ENUM_UNIQUE) && (tok || !valid))
|
||||
{
|
||||
/** Either the only defined enum value is not valid
|
||||
* or multiple values were defined */
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -39,6 +39,7 @@ int test_validity()
|
||||
{"p5", MXS_MODULE_PARAM_ENUM, "a", MXS_MODULE_OPT_NONE, enum_values},
|
||||
{"p6", MXS_MODULE_PARAM_PATH, "/tmp", MXS_MODULE_OPT_PATH_F_OK},
|
||||
{"p7", MXS_MODULE_PARAM_SERVICE, "my-service"},
|
||||
{"p8", MXS_MODULE_PARAM_ENUM, "a", MXS_MODULE_OPT_ENUM_UNIQUE, enum_values},
|
||||
{MXS_END_MODULE_PARAMS}
|
||||
};
|
||||
|
||||
@ -76,7 +77,13 @@ int test_validity()
|
||||
TEST(config_param_is_valid(params, "p5", "a", &ctx));
|
||||
TEST(config_param_is_valid(params, "p5", "b", &ctx));
|
||||
TEST(config_param_is_valid(params, "p5", "c", &ctx));
|
||||
TEST(config_param_is_valid(params, "p5", "a,b", &ctx));
|
||||
TEST(config_param_is_valid(params, "p5", "b,a", &ctx));
|
||||
TEST(config_param_is_valid(params, "p5", "a, b, c", &ctx));
|
||||
TEST(config_param_is_valid(params, "p5", "c,a,b", &ctx));
|
||||
TEST(!config_param_is_valid(params, "p5", "d", &ctx));
|
||||
TEST(!config_param_is_valid(params, "p5", "a,d", &ctx));
|
||||
TEST(!config_param_is_valid(params, "p5", "a,b,c,d", &ctx));
|
||||
|
||||
/** Path parameter */
|
||||
TEST(config_param_is_valid(params, "p6", "/tmp", &ctx));
|
||||
@ -90,6 +97,18 @@ int test_validity()
|
||||
TEST(!config_param_is_valid(params, "p7", "test-service", NULL));
|
||||
TEST(!config_param_is_valid(params, "p7", "no-such-service", &ctx));
|
||||
|
||||
/** Unique enum parameter */
|
||||
TEST(config_param_is_valid(params, "p8", "a", &ctx));
|
||||
TEST(config_param_is_valid(params, "p8", "b", &ctx));
|
||||
TEST(config_param_is_valid(params, "p8", "c", &ctx));
|
||||
TEST(!config_param_is_valid(params, "p8", "a,b", &ctx));
|
||||
TEST(!config_param_is_valid(params, "p8", "b,a", &ctx));
|
||||
TEST(!config_param_is_valid(params, "p8", "a, b, c", &ctx));
|
||||
TEST(!config_param_is_valid(params, "p8", "c,a,b", &ctx));
|
||||
TEST(!config_param_is_valid(params, "p8", "d", &ctx));
|
||||
TEST(!config_param_is_valid(params, "p8", "a,d", &ctx));
|
||||
TEST(!config_param_is_valid(params, "p8", "a,b,c,d", &ctx));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user