Library: handle validation expression '-1000-0'. Ticket #5847
This commit is contained in:
parent
4d5b463613
commit
4c7b0806aa
|
@ -181,6 +181,8 @@ Library::Error Library::load(const tinyxml2::XMLDocument &doc)
|
|||
else if (strcmp(argnode->Name(), "valid") == 0) {
|
||||
// Validate the validation expression
|
||||
const char *p = argnode->GetText();
|
||||
if (*p == '-')
|
||||
++p;
|
||||
if (!std::isdigit(*p))
|
||||
return Error(BAD_ATTRIBUTE_VALUE, argnode->GetText());
|
||||
for (; *p; p++) {
|
||||
|
@ -321,6 +323,10 @@ bool Library::isargvalid(const std::string &functionName, int argnr, const MathL
|
|||
TokenList tokenList(0);
|
||||
std::istringstream istr(ac->valid + ',');
|
||||
tokenList.createTokens(istr,"");
|
||||
if (Token::Match(tokenList.front(), "- %num% -")) {
|
||||
tokenList.front()->str("-" + tokenList.front()->strAt(1));
|
||||
tokenList.front()->deleteNext();
|
||||
}
|
||||
for (const Token *tok = tokenList.front(); tok; tok = tok->next()) {
|
||||
if (tok->isNumber() && argvalue == MathLib::toLongNumber(tok->str()))
|
||||
return true;
|
||||
|
|
|
@ -33,6 +33,7 @@ private:
|
|||
TEST_CASE(function);
|
||||
TEST_CASE(function_arg);
|
||||
TEST_CASE(function_arg_any);
|
||||
TEST_CASE(function_arg_valid);
|
||||
TEST_CASE(memory);
|
||||
TEST_CASE(memory2); // define extra "free" allocation functions
|
||||
TEST_CASE(resource);
|
||||
|
@ -76,8 +77,7 @@ private:
|
|||
" <arg nr=\"2\"><not-null/></arg>\n"
|
||||
" <arg nr=\"3\"><formatstr/></arg>\n"
|
||||
" <arg nr=\"4\"><strz/></arg>\n"
|
||||
" <arg nr=\"5\"><valid>1-</valid></arg>\n"
|
||||
" <arg nr=\"6\"><not-bool/></arg>\n"
|
||||
" <arg nr=\"5\"><not-bool/></arg>\n"
|
||||
" </function>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
|
@ -89,8 +89,7 @@ private:
|
|||
ASSERT_EQUALS(true, library.argumentChecks["foo"][2].notnull);
|
||||
ASSERT_EQUALS(true, library.argumentChecks["foo"][3].formatstr);
|
||||
ASSERT_EQUALS(true, library.argumentChecks["foo"][4].strz);
|
||||
ASSERT_EQUALS("1-", library.argumentChecks["foo"][5].valid);
|
||||
ASSERT_EQUALS(true, library.argumentChecks["foo"][6].notbool);
|
||||
ASSERT_EQUALS(true, library.argumentChecks["foo"][5].notbool);
|
||||
}
|
||||
|
||||
void function_arg_any() const {
|
||||
|
@ -108,6 +107,45 @@ private:
|
|||
ASSERT_EQUALS(true, library.argumentChecks["foo"][-1].notuninit);
|
||||
}
|
||||
|
||||
void function_arg_valid() const {
|
||||
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
||||
"<def>\n"
|
||||
" <function name=\"foo\">\n"
|
||||
" <arg nr=\"1\"><valid>1-</valid></arg>\n"
|
||||
" <arg nr=\"2\"><valid>-7-0</valid></arg>\n"
|
||||
" <arg nr=\"3\"><valid>1-5,8</valid></arg>\n"
|
||||
" </function>\n"
|
||||
"</def>";
|
||||
tinyxml2::XMLDocument doc;
|
||||
doc.Parse(xmldata, sizeof(xmldata));
|
||||
|
||||
Library library;
|
||||
library.load(doc);
|
||||
|
||||
// 1-
|
||||
ASSERT_EQUALS(false, library.isargvalid("foo", 1, -10));
|
||||
ASSERT_EQUALS(false, library.isargvalid("foo", 1, 0));
|
||||
ASSERT_EQUALS(true, library.isargvalid("foo", 1, 1));
|
||||
ASSERT_EQUALS(true, library.isargvalid("foo", 1, 10));
|
||||
|
||||
// -7-0
|
||||
ASSERT_EQUALS(false, library.isargvalid("foo", 2, -10));
|
||||
ASSERT_EQUALS(true, library.isargvalid("foo", 2, -7));
|
||||
ASSERT_EQUALS(true, library.isargvalid("foo", 2, -3));
|
||||
ASSERT_EQUALS(true, library.isargvalid("foo", 2, 0));
|
||||
ASSERT_EQUALS(false, library.isargvalid("foo", 2, 1));
|
||||
|
||||
// 1-5,8
|
||||
ASSERT_EQUALS(false, library.isargvalid("foo", 3, 0));
|
||||
ASSERT_EQUALS(true, library.isargvalid("foo", 3, 1));
|
||||
ASSERT_EQUALS(true, library.isargvalid("foo", 3, 3));
|
||||
ASSERT_EQUALS(true, library.isargvalid("foo", 3, 5));
|
||||
ASSERT_EQUALS(false, library.isargvalid("foo", 3, 6));
|
||||
ASSERT_EQUALS(false, library.isargvalid("foo", 3, 7));
|
||||
ASSERT_EQUALS(true, library.isargvalid("foo", 3, 8));
|
||||
ASSERT_EQUALS(false, library.isargvalid("foo", 3, 9));
|
||||
}
|
||||
|
||||
void memory() const {
|
||||
const char xmldata[] = "<?xml version=\"1.0\"?>\n"
|
||||
"<def>\n"
|
||||
|
|
Loading…
Reference in New Issue