Skip to content
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
4 changes: 4 additions & 0 deletions src/measure/OSRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,10 @@ namespace measure {
bool result = true;
std::vector<WorkflowStepValue> stepValues;
for (const OSArgument& script_argument : script_arguments) {
if (script_argument.type().value() == OSArgumentType::Separator) {
// skip separators
continue;
}
Comment on lines +412 to +415

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No point validating it.

auto it = user_arguments.find(script_argument.name());
if (it == user_arguments.end()) {
// script_argument is not in user_arguments
Expand Down
88 changes: 88 additions & 0 deletions src/measure/test/OSMeasure_GTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <utilities/idd/IddEnums.hxx>

#include "../../utilities/core/Finder.hpp"
#include "../../utilities/core/StringStreamLogSink.hpp"
#include "../../utilities/filetypes/WorkflowJSON.hpp"
#include "../../utilities/filetypes/WorkflowStep.hpp"

Expand Down Expand Up @@ -457,3 +458,90 @@ TEST_F(MeasureFixture, UserScript_TestModelUserScriptDomain) {
EXPECT_EQ("Integer User argument 'int_arg' has a value '-3' that is not in the domain [0, 2147483647].", result.stepErrors()[0]);
EXPECT_EQ(0u, result.stepWarnings().size());
}

// Test for #5464 - Shouldn't throw an error when a separator is used in the arguments
class ModelMeasureWithSeparator : public ModelMeasure
{
public:
virtual std::string name() const override {
return "ModelMeasureWithSeparator";
}

virtual std::vector<OSArgument> arguments(const Model& /*model*/) const override {
std::vector<OSArgument> result;

OSArgument arg = OSArgument::makeDoubleArgument("double_arg", true);
arg.setMaxValue(10.0);
result.push_back(arg);

arg = OSArgument::makeSeparatorArgument("separator");
result.push_back(arg);
Comment on lines +477 to +478

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New Test, failing before


arg = OSArgument::makeIntegerArgument("int_arg", true);
arg.setMinValue(0);
result.push_back(arg);

return result;
}

// remove all spaces and add a new one
virtual bool run(Model& model, OSRunner& runner, const std::map<std::string, OSArgument>& user_arguments) const override {
ModelMeasure::run(model, runner, user_arguments); // initializes runner

return runner.validateUserArguments(arguments(model), user_arguments);
}
};

TEST_F(MeasureFixture, ModelMeasureWithSeparator) {
ModelMeasureWithSeparator measure;
EXPECT_EQ("ModelMeasureWithSeparator", measure.name());

Model model;

std::vector<WorkflowStep> steps;
steps.push_back(MeasureStep("dummy"));

WorkflowJSON workflow;
workflow.setWorkflowSteps(steps);

TestOSRunner runner(workflow);
OSArgumentVector arguments = measure.arguments(model);
std::map<std::string, OSArgument> argumentMap = convertOSArgumentVectorToMap(arguments);
ASSERT_EQ(3, argumentMap.size());

OSArgument& double_arg = argumentMap["double_arg"];
OSArgument& int_arg = argumentMap["int_arg"];

StringStreamLogSink sink;
sink.setLogLevel(Fatal);

// call with a good value
double_arg.setValue(-1.0);
int_arg.setValue(1.0);
EXPECT_TRUE(measure.run(model, runner, argumentMap));

EXPECT_EQ(0, sink.logMessages().size()) << sink.string();
sink.resetStringStream();
Comment on lines +515 to +524

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fails before

[ RUN      ] MeasureFixture.ModelMeasureWithSeparator
/media/DataExt4/Software/Others/OpenStudio3/src/measure/test/OSMeasure_GTest.cpp:523: Failure
Expected equality of these values:
  0
  sink.logMessages().size()
    Which is: 1
[BOOST_ASSERT] <2> Assertion false failed on line 585 of bool openstudio::measure::OSRunner::validateUserArguments(const std::vector<openstudio::measure::OSArgument>&, const std::map<std::__cxx11::basic_string<char>, openstudio::measure::OSArgument>&) in file /media/DataExt4/Software/Others/OpenStudio3/src/measure/OSRunner.cpp.


WorkflowStepResult result = runner.result();
ASSERT_TRUE(result.stepResult());
EXPECT_EQ(StepResult::Success, result.stepResult()->value());
EXPECT_EQ(0u, result.stepErrors().size());
EXPECT_EQ(0u, result.stepWarnings().size());

// Out of bound value for int_arg
runner.reset();
double_arg.setValue(1.0);
int_arg.setValue(-3);
EXPECT_FALSE(measure.run(model, runner, argumentMap));

EXPECT_EQ(0, sink.logMessages().size()) << sink.string();
sink.resetStringStream();

result = runner.result();
ASSERT_TRUE(result.stepResult());
EXPECT_EQ(StepResult::Fail, result.stepResult()->value());
ASSERT_EQ(1u, result.stepErrors().size());
EXPECT_EQ("Integer User argument 'int_arg' has a value '-3' that is not in the domain [0, 2147483647].", result.stepErrors()[0]);
EXPECT_EQ(0u, result.stepWarnings().size());
}
1 change: 1 addition & 0 deletions src/utilities/xml/resources/bcl/measure_v3.1.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
<xs:enumeration value="String"/>
<xs:enumeration value="Choice"/>
<xs:enumeration value="Path"/>
<xs:enumeration value="Separator"/>

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was missing cf #5464 (comment)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, I see there was a second error before:

[openstudio.XMLValidator] <1> xsdValidate.parseFileError: XML error 17.1840: Element 'type': [facet 'enumeration'] The value 'Separator' is not an element of the set {'Boolean', 'Double', 'Integer', 'String', 'Choice', 'Path'}.

</xs:restriction>
</xs:simpleType>
</xs:element>
Expand Down
Loading