Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some errors in FilterNode functionality #67

Merged
merged 4 commits into from
Dec 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Release 3.6.0

* fix too specific params of *build.bat* #16, by @flipback
* fix OpenSSL-1.1 compatibility in test compilation #46, by @flipback
* fix type conversion of refernces on the same value #67, by @flipback
* fix comparison in *OpcUaStackCore::ComparisonFilterNode* #67, by @flipback

**Documentation**:

Expand Down
14 changes: 5 additions & 9 deletions src/OpcUaStackCore/BuildInTypes/OpcUaTypeConversion.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2017 Kai Huebl ([email protected])
Copyright 2017-2018 Kai Huebl ([email protected])

Lizenziert gemäß Apache Licence Version 2.0 (die „Lizenz“); Nutzung dieser
Datei nur in Übereinstimmung mit der Lizenz erlaubt.
Expand All @@ -20,13 +20,6 @@
namespace OpcUaStackCore
{

//operator bool(const std::string& value) const
//{
// return true;
//}



OpcUaTypeConversion::OpcUaTypeConversion(void)
{
}
Expand Down Expand Up @@ -92,7 +85,10 @@ namespace OpcUaStackCore
{
case '-':
{
targetVariant.copyFrom(sourceVariant);
if (&sourceVariant != &targetVariant) {
targetVariant.copyFrom(sourceVariant);
}

return true;
}
case 'I':
Expand Down
33 changes: 18 additions & 15 deletions src/OpcUaStackCore/Filter/ComparisonFilterNode.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2017 Kai Huebl ([email protected])
Copyright 2017-2018 Kai Huebl ([email protected])

Lizenziert gemäß Apache Licence Version 2.0 (die „Lizenz“); Nutzung dieser
Datei nur in Übereinstimmung mit der Lizenz erlaubt.
Expand Down Expand Up @@ -82,21 +82,24 @@ namespace OpcUaStackCore
return false;
}

OpcUaTypeConversion converter;
// Convert variable with greater precedence rank
if (converter.precedenceRank(value1.variantType()) < converter.precedenceRank(value2.variantType())) {
std::swap(value1, value2);
}
char conveType = converter.conversionType(value1.variantType(), value2.variantType());

if (converter.conversion(value1, value2.variantType(), value1)) {
return compare(value1, value2, value);
} else {
value.set<OpcUaBoolean>(false); // see the description in table 115 of part 4
}
bool converted = true;

return true;
}
OpcUaTypeConversion converter;
// Convert variable with greater precedence rank
if (converter.precedenceRank(value1.variantType()) > converter.precedenceRank(value2.variantType())) {
converted = converter.conversion(value1, value2.variantType(), value1);
} else if (converter.precedenceRank(value1.variantType()) < converter.precedenceRank(value2.variantType())) {
converted = converter.conversion(value2, value1.variantType(), value2);
}

if (converted) {
return compare(value1, value2, value);
} else {
value.set<OpcUaBoolean>(false); // see the description in table 115 of part 4
}

return true;
}

return false;
}
Expand Down
9 changes: 9 additions & 0 deletions tst/OpcUaStackCore/BuildInTypes/OpcUaTypeConversion_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,5 +1060,14 @@ BOOST_AUTO_TEST_CASE(OpcUaTypeConversion_XmlElement)
// SHOULD_BE_SAME_PTR (OpcUaXmlElement, xmlElement);
}

BOOST_AUTO_TEST_CASE(OpcUaTypeConversion_ConvertTheSameData)
{
OpcUaTypeConversion converter;
OpcUaVariant value1;
value1.set<OpcUaDouble>(0);

BOOST_REQUIRE(converter.conversion(value1, OpcUaBuildInType_OpcUaDouble, value1));
}

BOOST_AUTO_TEST_SUITE_END()

24 changes: 24 additions & 0 deletions tst/OpcUaStackCore/Filter/ComparisonFilterNode_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,30 @@ BOOST_AUTO_TEST_CASE(ComparisonFilterNode_120_less_than_or_eaual_100)
BOOST_REQUIRE(operatorResult.get<OpcUaBoolean>() == false);
}

BOOST_AUTO_TEST_CASE(ComparisonFilterNode_120I_less_than_or_eaual_100F)
{
std::vector<FilterNode::SPtr> args;
MAKE_TWO_LITERAL_ARGS(args, OpcUaInt32(120), OpcUaDouble(100));

ComparisonFilterNode lessThanOrEqualOperator(OpcUaOperator::LessThanOrEqual, args);

OpcUaVariant operatorResult;
BOOST_REQUIRE(lessThanOrEqualOperator.evaluate(operatorResult));
BOOST_REQUIRE(operatorResult.get<OpcUaBoolean>() == false);
}

BOOST_AUTO_TEST_CASE(ComparisonFilterNode_120F_less_than_or_eaual_100I)
{
std::vector<FilterNode::SPtr> args;
MAKE_TWO_LITERAL_ARGS(args, OpcUaDouble(120), OpcUaInt32(100));

ComparisonFilterNode lessThanOrEqualOperator(OpcUaOperator::LessThanOrEqual, args);

OpcUaVariant operatorResult;
BOOST_REQUIRE(lessThanOrEqualOperator.evaluate(operatorResult));
BOOST_REQUIRE(operatorResult.get<OpcUaBoolean>() == false);
}

//------------------------------------------------
// Handle errors
//------------------------------------------------
Expand Down