GCC Code Coverage Report


Directory: ./
Coverage: low: ≥ 0% medium: ≥ 75.0% high: ≥ 90.0%
Coverage Exec / Excl / Total
Lines: 78.0% 188 / 0 / 241
Functions: 72.1% 44 / 0 / 61
Branches: 81.8% 166 / 0 / 203

src/utilities/filetypes/WorkflowStep.cpp
Line Branch Exec Source
1 /***********************************************************************************************************************
2 * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC.
3 * See also https://openstudio.net/license
4 ***********************************************************************************************************************/
5
6 #include "WorkflowStep.hpp"
7 #include "WorkflowStep_Impl.hpp"
8
9 #include "../core/Assert.hpp"
10
11 namespace openstudio {
12 namespace detail {
13
14 315 WorkflowStep_Impl::WorkflowStep_Impl() = default;
15
16 486 boost::optional<WorkflowStepResult> WorkflowStep_Impl::result() const {
17 486 return m_result;
18 }
19
20 4 std::string WorkflowStep_Impl::string() const {
21
1/1
✓ Branch 1 taken 4 times.
4 Json::StreamWriterBuilder wbuilder;
22 // mimic the old StyledWriter behavior:
23
3/3
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
✓ Branch 7 taken 4 times.
12 wbuilder["indentation"] = " ";
24
2/2
✓ Branch 1 taken 4 times.
✓ Branch 4 taken 4 times.
4 std::string resultString = Json::writeString(wbuilder, toJSON());
25
26 8 return resultString;
27 4 }
28
29 83 void WorkflowStep_Impl::setResult(const WorkflowStepResult& result) {
30 83 m_result = result;
31 83 onUpdate();
32 83 }
33
34 56 void WorkflowStep_Impl::resetResult() {
35 56 m_result.reset();
36 56 onUpdate();
37 56 }
38
39 355 void WorkflowStep_Impl::onUpdate() {
40 355 this->onChange.nano_emit();
41 355 }
42
43
1/1
✓ Branch 2 taken 315 times.
315 MeasureStep_Impl::MeasureStep_Impl(const std::string& measureDirName) : m_measureDirName(measureDirName) {}
44
45 441 Json::Value MeasureStep_Impl::toJSON() const {
46
1/1
✓ Branch 1 taken 441 times.
441 Json::Value root;
47
2/2
✓ Branch 1 taken 441 times.
✓ Branch 4 taken 441 times.
441 root["measure_dir_name"] = m_measureDirName;
48
49
2/2
✓ Branch 1 taken 9 times.
✓ Branch 2 taken 432 times.
882 if (m_name) {
50
3/3
✓ Branch 1 taken 9 times.
✓ Branch 4 taken 9 times.
✓ Branch 7 taken 9 times.
9 root["name"] = m_name.get();
51 }
52
53
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 441 times.
882 if (m_description) {
54 ✗ root["description"] = m_description.get();
55 }
56
57
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 441 times.
882 if (m_modelerDescription) {
58 ✗ root["modeler_description"] = m_modelerDescription.get();
59 }
60
61
1/1
✓ Branch 1 taken 441 times.
441 Json::Value arguments(Json::objectValue);
62
2/2
✓ Branch 7 taken 424 times.
✓ Branch 8 taken 441 times.
865 for (const auto& [name, value] : m_arguments) {
63
4/4
✓ Branch 1 taken 424 times.
✓ Branch 4 taken 424 times.
✓ Branch 7 taken 43 times.
✓ Branch 8 taken 381 times.
424 if (value.variantType() == VariantType::String) {
64
3/3
✓ Branch 1 taken 43 times.
✓ Branch 4 taken 43 times.
✓ Branch 7 taken 43 times.
43 arguments[name] = value.valueAsString();
65
4/4
✓ Branch 1 taken 381 times.
✓ Branch 4 taken 381 times.
✓ Branch 7 taken 114 times.
✓ Branch 8 taken 267 times.
381 } else if (value.variantType() == VariantType::Double) {
66
3/3
✓ Branch 1 taken 114 times.
✓ Branch 4 taken 114 times.
✓ Branch 7 taken 114 times.
114 arguments[name] = value.valueAsDouble();
67
4/4
✓ Branch 1 taken 267 times.
✓ Branch 4 taken 267 times.
✓ Branch 7 taken 232 times.
✓ Branch 8 taken 35 times.
267 } else if (value.variantType() == VariantType::Integer) {
68
3/3
✓ Branch 1 taken 232 times.
✓ Branch 4 taken 232 times.
✓ Branch 7 taken 232 times.
232 arguments[name] = value.valueAsInteger();
69
3/4
✓ Branch 1 taken 35 times.
✓ Branch 4 taken 35 times.
✓ Branch 7 taken 35 times.
✗ Branch 8 not taken.
35 } else if (value.variantType() == VariantType::Boolean) {
70
3/3
✓ Branch 1 taken 35 times.
✓ Branch 4 taken 35 times.
✓ Branch 7 taken 35 times.
35 arguments[name] = value.valueAsBoolean();
71 }
72 }
73
2/2
✓ Branch 1 taken 441 times.
✓ Branch 4 taken 441 times.
441 root["arguments"] = arguments;
74
75
3/3
✓ Branch 1 taken 441 times.
✓ Branch 3 taken 225 times.
✓ Branch 4 taken 216 times.
882 if (boost::optional<WorkflowStepResult> workflowStepResult_ = this->result()) {
76
3/3
✓ Branch 1 taken 225 times.
✓ Branch 4 taken 225 times.
✓ Branch 7 taken 225 times.
225 root["result"] = workflowStepResult_->toJSON();
77 441 }
78
79 882 return root;
80 441 }
81
82 594 std::string MeasureStep_Impl::measureDirName() const {
83 594 return m_measureDirName;
84 }
85
86 ✗ bool MeasureStep_Impl::setMeasureDirName(const std::string& measureDirName) {
87 ✗ m_measureDirName = measureDirName;
88 ✗ return true;
89 }
90
91 65 boost::optional<std::string> MeasureStep_Impl::name() const {
92 65 return m_name;
93 }
94
95 5 bool MeasureStep_Impl::setName(const std::string& name) {
96 5 m_name = name;
97 5 onUpdate();
98 5 return true;
99 }
100
101 ✗ void MeasureStep_Impl::resetName() {
102 ✗ m_name.reset();
103 ✗ onUpdate();
104 ✗ }
105
106 ✗ boost::optional<std::string> MeasureStep_Impl::description() const {
107 ✗ return m_description;
108 }
109
110 1 bool MeasureStep_Impl::setDescription(const std::string& description) {
111 1 m_description = description;
112 1 onUpdate();
113 1 return true;
114 }
115
116 ✗ void MeasureStep_Impl::resetDescription() {
117 ✗ m_description.reset();
118 ✗ onUpdate();
119 ✗ }
120
121 ✗ boost::optional<std::string> MeasureStep_Impl::modelerDescription() const {
122 ✗ return m_modelerDescription;
123 }
124
125 1 bool MeasureStep_Impl::setModelerDescription(const std::string& modelerDescription) {
126 1 m_modelerDescription = modelerDescription;
127 1 onUpdate();
128 1 return true;
129 }
130
131 ✗ void MeasureStep_Impl::resetModelerDescription() {
132 ✗ m_modelerDescription.reset();
133 ✗ onUpdate();
134 ✗ }
135
136 130 std::map<std::string, Variant> MeasureStep_Impl::arguments() const {
137 130 return m_arguments;
138 }
139
140 176 boost::optional<Variant> MeasureStep_Impl::getArgument(const std::string& name) const {
141
1/1
✓ Branch 1 taken 176 times.
176 auto it = m_arguments.find(name);
142
2/2
✓ Branch 2 taken 174 times.
✓ Branch 3 taken 2 times.
176 if (it != m_arguments.end()) {
143
1/1
✓ Branch 2 taken 174 times.
174 return it->second;
144 }
145 2 return boost::none;
146 }
147
148 208 void MeasureStep_Impl::setArgument(const std::string& name, const Variant& value) {
149 208 m_arguments[name] = value;
150 208 onUpdate();
151 208 }
152
153 16 void MeasureStep_Impl::setArgument(const std::string& name, bool value) {
154
2/2
✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
16 setArgument(name, Variant(value));
155 16 }
156
157 63 void MeasureStep_Impl::setArgument(const std::string& name, double value) {
158
2/2
✓ Branch 1 taken 63 times.
✓ Branch 4 taken 63 times.
63 setArgument(name, Variant(value));
159 63 }
160
161 106 void MeasureStep_Impl::setArgument(const std::string& name, int value) {
162
2/2
✓ Branch 1 taken 106 times.
✓ Branch 4 taken 106 times.
106 setArgument(name, Variant(value));
163 106 }
164
165 23 void MeasureStep_Impl::setArgument(const std::string& name, const std::string& value) {
166
2/2
✓ Branch 1 taken 23 times.
✓ Branch 4 taken 23 times.
23 setArgument(name, Variant(value));
167 23 }
168
169 1 void MeasureStep_Impl::removeArgument(const std::string& name) {
170 1 m_arguments.erase(name);
171 1 onUpdate();
172 1 }
173
174 ✗ void MeasureStep_Impl::clearArguments() {
175 ✗ m_arguments.clear();
176 ✗ onUpdate();
177 ✗ }
178
179 } // namespace detail
180
181 1470 WorkflowStep::WorkflowStep(std::shared_ptr<detail::WorkflowStep_Impl> impl) : m_impl(impl) {
182
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 1470 times.
✗ Branch 5 not taken.
1470 OS_ASSERT(getImpl<detail::WorkflowStep_Impl>());
183 1470 }
184
185 219 boost::optional<WorkflowStep> WorkflowStep::fromString(const std::string& s) {
186 219 boost::optional<WorkflowStep> result;
187
188 // We let it fail with a warning message
189
1/1
✓ Branch 1 taken 219 times.
219 Json::CharReaderBuilder rbuilder;
190
1/1
✓ Branch 1 taken 219 times.
219 std::istringstream ss(s);
191 219 std::string formattedErrors;
192
1/1
✓ Branch 1 taken 219 times.
219 Json::Value value;
193
1/1
✓ Branch 1 taken 219 times.
219 bool parsingSuccessful = Json::parseFromStream(rbuilder, ss, &value, &formattedErrors);
194
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 219 times.
219 if (!parsingSuccessful) {
195 ✗ LOG(Warn, "Couldn't parse WorkflowStep from string s='" << s << "'. Error: '" << formattedErrors << "'.");
196 ✗ return result;
197 }
198
199
2/3
✓ Branch 1 taken 219 times.
✓ Branch 3 taken 219 times.
✗ Branch 4 not taken.
219 if (value.isMember("measure_dir_name")) {
200
2/2
✓ Branch 1 taken 219 times.
✓ Branch 4 taken 219 times.
219 Json::Value measureDirName = value["measure_dir_name"];
201
202
2/2
✓ Branch 1 taken 219 times.
✓ Branch 4 taken 219 times.
219 MeasureStep measureStep(measureDirName.asString());
203
1/1
✓ Branch 1 taken 219 times.
219 result = measureStep;
204
205
3/3
✓ Branch 1 taken 219 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 217 times.
219 if (value.isMember("name")) {
206
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 Json::Value name = value["name"];
207
2/2
✓ Branch 1 taken 2 times.
✓ Branch 4 taken 2 times.
2 measureStep.setName(name.asString());
208 2 }
209
210
3/3
✓ Branch 1 taken 219 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 218 times.
219 if (value.isMember("description")) {
211
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Json::Value description = value["description"];
212
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 measureStep.setDescription(description.asString());
213 1 }
214
215
3/3
✓ Branch 1 taken 219 times.
✓ Branch 3 taken 1 time.
✓ Branch 4 taken 218 times.
219 if (value.isMember("modeler_description")) {
216
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 Json::Value modelerDescription = value["modeler_description"];
217
2/2
✓ Branch 1 taken 1 time.
✓ Branch 4 taken 1 time.
1 measureStep.setModelerDescription(modelerDescription.asString());
218 1 }
219
220
2/2
✓ Branch 1 taken 219 times.
✓ Branch 4 taken 219 times.
219 Json::Value arguments = value["arguments"];
221
3/3
✓ Branch 1 taken 219 times.
✓ Branch 8 taken 194 times.
✓ Branch 9 taken 219 times.
413 for (const auto& name : arguments.getMemberNames()) {
222
2/2
✓ Branch 1 taken 194 times.
✓ Branch 4 taken 194 times.
194 Json::Value arg_val = arguments[name];
223
224
3/3
✓ Branch 1 taken 194 times.
✓ Branch 3 taken 16 times.
✓ Branch 4 taken 178 times.
194 if (arg_val.isBool()) {
225
2/2
✓ Branch 1 taken 16 times.
✓ Branch 4 taken 16 times.
16 measureStep.setArgument(name, arg_val.asBool());
226
3/3
✓ Branch 1 taken 178 times.
✓ Branch 3 taken 97 times.
✓ Branch 4 taken 81 times.
178 } else if (arg_val.isIntegral()) {
227
2/2
✓ Branch 1 taken 97 times.
✓ Branch 4 taken 97 times.
97 measureStep.setArgument(name, arg_val.asInt());
228
3/3
✓ Branch 1 taken 81 times.
✓ Branch 3 taken 61 times.
✓ Branch 4 taken 20 times.
81 } else if (arg_val.isDouble()) {
229
2/2
✓ Branch 1 taken 61 times.
✓ Branch 4 taken 61 times.
61 measureStep.setArgument(name, arg_val.asDouble());
230 } else {
231
2/2
✓ Branch 1 taken 20 times.
✓ Branch 4 taken 20 times.
20 measureStep.setArgument(name, arg_val.asString());
232 }
233 413 }
234 219 }
235
236
3/3
✓ Branch 1 taken 219 times.
✓ Branch 3 taken 15 times.
✓ Branch 4 taken 204 times.
219 if (value.isMember("result")) {
237
238
2/2
✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
15 Json::Value v = value["result"];
239
240
1/1
✓ Branch 1 taken 15 times.
15 Json::StreamWriterBuilder wbuilder;
241 // mimic the old StyledWriter behavior:
242
3/3
✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
✓ Branch 7 taken 15 times.
45 wbuilder["indentation"] = " ";
243
1/1
✓ Branch 1 taken 15 times.
15 std::string result_str = Json::writeString(wbuilder, v);
244
245
1/1
✓ Branch 1 taken 15 times.
15 boost::optional<WorkflowStepResult> workflowStepResult = WorkflowStepResult::fromString(result_str);
246
1/2
✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
15 if (workflowStepResult) {
247
3/3
✓ Branch 1 taken 15 times.
✓ Branch 4 taken 15 times.
✓ Branch 7 taken 15 times.
15 result->setResult(*workflowStepResult);
248 }
249 15 }
250
251 219 return result;
252 219 }
253
254 4 std::string WorkflowStep::string() const {
255
1/1
✓ Branch 3 taken 4 times.
4 return getImpl<detail::WorkflowStep_Impl>()->string();
256 }
257
258 437 Json::Value WorkflowStep::toJSON() const {
259
1/1
✓ Branch 3 taken 437 times.
437 return getImpl<detail::WorkflowStep_Impl>()->toJSON();
260 }
261
262 45 boost::optional<WorkflowStepResult> WorkflowStep::result() const {
263
1/1
✓ Branch 3 taken 45 times.
45 return getImpl<detail::WorkflowStep_Impl>()->result();
264 }
265
266 83 void WorkflowStep::setResult(const WorkflowStepResult& result) {
267
1/1
✓ Branch 3 taken 83 times.
83 getImpl<detail::WorkflowStep_Impl>()->setResult(result);
268 83 }
269
270 56 void WorkflowStep::resetResult() {
271
1/1
✓ Branch 3 taken 56 times.
56 getImpl<detail::WorkflowStep_Impl>()->resetResult();
272 56 }
273
274 ✗ bool WorkflowStep::operator==(const WorkflowStep& other) const {
275 ✗ return m_impl == other.m_impl;
276 }
277
278
2/2
✓ Branch 1 taken 80 times.
✓ Branch 5 taken 80 times.
80 MeasureStep::MeasureStep() : WorkflowStep(std::make_shared<detail::MeasureStep_Impl>("")) {}
279
280
2/2
✓ Branch 1 taken 235 times.
✓ Branch 5 taken 235 times.
235 MeasureStep::MeasureStep(const std::string& measureDirName) : WorkflowStep(std::make_shared<detail::MeasureStep_Impl>(measureDirName)) {
281
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 235 times.
✗ Branch 5 not taken.
235 OS_ASSERT(getImpl<detail::MeasureStep_Impl>());
282 235 }
283
284
1/1
✓ Branch 3 taken 1155 times.
1155 MeasureStep::MeasureStep(std::shared_ptr<detail::MeasureStep_Impl> impl) : WorkflowStep(std::move(impl)) {
285
1/3
✗ Branch 2 not taken.
✓ Branch 3 taken 1155 times.
✗ Branch 5 not taken.
1155 OS_ASSERT(getImpl<detail::MeasureStep_Impl>());
286 1155 }
287
288 594 std::string MeasureStep::measureDirName() const {
289
1/1
✓ Branch 3 taken 594 times.
594 return getImpl<detail::MeasureStep_Impl>()->measureDirName();
290 }
291
292 ✗ bool MeasureStep::setMeasureDirName(const std::string& measureDirName) {
293 ✗ return getImpl<detail::MeasureStep_Impl>()->setMeasureDirName(measureDirName);
294 }
295
296 65 boost::optional<std::string> MeasureStep::name() const {
297
1/1
✓ Branch 3 taken 65 times.
65 return getImpl<detail::MeasureStep_Impl>()->name();
298 }
299
300 5 bool MeasureStep::setName(const std::string& name) {
301
1/1
✓ Branch 3 taken 5 times.
5 return getImpl<detail::MeasureStep_Impl>()->setName(name);
302 }
303
304 ✗ void MeasureStep::resetName() {
305 ✗ getImpl<detail::MeasureStep_Impl>()->resetName();
306 ✗ }
307
308 ✗ boost::optional<std::string> MeasureStep::description() const {
309 ✗ return getImpl<detail::MeasureStep_Impl>()->description();
310 }
311
312 1 bool MeasureStep::setDescription(const std::string& description) {
313
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::MeasureStep_Impl>()->setDescription(description);
314 }
315
316 ✗ void MeasureStep::resetDescription() {
317 ✗ getImpl<detail::MeasureStep_Impl>()->resetDescription();
318 ✗ }
319
320 ✗ boost::optional<std::string> MeasureStep::modelerDescription() const {
321 ✗ return getImpl<detail::MeasureStep_Impl>()->modelerDescription();
322 }
323
324 1 bool MeasureStep::setModelerDescription(const std::string& modelerDescription) {
325
1/1
✓ Branch 3 taken 1 time.
1 return getImpl<detail::MeasureStep_Impl>()->setModelerDescription(modelerDescription);
326 }
327
328 ✗ void MeasureStep::resetModelerDescription() {
329 ✗ getImpl<detail::MeasureStep_Impl>()->resetModelerDescription();
330 ✗ }
331
332 130 std::map<std::string, Variant> MeasureStep::arguments() const {
333
1/1
✓ Branch 3 taken 130 times.
130 return getImpl<detail::MeasureStep_Impl>()->arguments();
334 }
335
336 176 boost::optional<Variant> MeasureStep::getArgument(const std::string& name) const {
337
1/1
✓ Branch 3 taken 176 times.
176 return getImpl<detail::MeasureStep_Impl>()->getArgument(name);
338 }
339
340 ✗ void MeasureStep::setArgument(const std::string& name, const Variant& value) {
341 ✗ getImpl<detail::MeasureStep_Impl>()->setArgument(name, value);
342 ✗ }
343
344 16 void MeasureStep::setArgument(const std::string& name, bool value) {
345
1/1
✓ Branch 3 taken 16 times.
16 getImpl<detail::MeasureStep_Impl>()->setArgument(name, value);
346 16 }
347
348 63 void MeasureStep::setArgument(const std::string& name, double value) {
349
1/1
✓ Branch 3 taken 63 times.
63 getImpl<detail::MeasureStep_Impl>()->setArgument(name, value);
350 63 }
351
352 106 void MeasureStep::setArgument(const std::string& name, int value) {
353
1/1
✓ Branch 3 taken 106 times.
106 getImpl<detail::MeasureStep_Impl>()->setArgument(name, value);
354 106 }
355
356 1 void MeasureStep::setArgument(const std::string& name, const char* value) {
357
2/2
✓ Branch 3 taken 1 time.
✓ Branch 6 taken 1 time.
3 getImpl<detail::MeasureStep_Impl>()->setArgument(name, std::string(value));
358 1 }
359
360 22 void MeasureStep::setArgument(const std::string& name, const std::string& value) {
361
1/1
✓ Branch 3 taken 22 times.
22 getImpl<detail::MeasureStep_Impl>()->setArgument(name, value);
362 22 }
363
364 1 void MeasureStep::removeArgument(const std::string& name) {
365
1/1
✓ Branch 3 taken 1 time.
1 getImpl<detail::MeasureStep_Impl>()->removeArgument(name);
366 1 }
367
368 ✗ void MeasureStep::clearArguments() {
369 ✗ getImpl<detail::MeasureStep_Impl>()->clearArguments();
370 ✗ }
371
372 ✗ std::ostream& operator<<(std::ostream& os, const WorkflowStep& workflowStep) {
373 ✗ os << workflowStep.string();
374 ✗ return os;
375 }
376
377 } // namespace openstudio
378