Verify reading parameters on update
Adds verification of ReadingParameter's metric count when property is
being updated. This brings consistency with behavior upon adding a new
report, where that same check is being made. Also adds a unit test for
that check.
Tested:
On platform, by updating report's ReadingParameter with object
containing metric count exceeding one specified by
`max-reading-parameters` project option. With this change applied, that
operation failed, as expected.
Change-Id: I06c8e21178d6bd554b62886e0e4f8cd0589f0d09
Signed-off-by: Michal Orzel <michalx.orzel@intel.com>
diff --git a/src/report_manager.cpp b/src/report_manager.cpp
index 3af033a..e9ccbb8 100644
--- a/src/report_manager.cpp
+++ b/src/report_manager.cpp
@@ -119,19 +119,7 @@
throw errors::InvalidArgument("Interval");
}
- size_t metricCount = 0;
- for (auto metricParam : readingParams)
- {
- auto metricParamsVec =
- metricParam.at_label<utils::tstring::SensorPath>();
- metricCount += metricParamsVec.size();
- }
-
- if (readingParams.size() > maxNumberMetrics ||
- metricCount > maxNumberMetrics)
- {
- throw errors::InvalidArgument("MetricParams", "Too many.");
- }
+ verifyMetricParams(readingParams);
for (const LabeledMetricParameters& item : readingParams)
{
@@ -237,3 +225,21 @@
}
}
}
+
+void ReportManager::verifyMetricParams(
+ const std::vector<LabeledMetricParameters>& metricParams)
+{
+ size_t metricCount = 0;
+ for (const auto& metricParam : metricParams)
+ {
+ auto metricParamsVec =
+ metricParam.at_label<utils::tstring::SensorPath>();
+ metricCount += metricParamsVec.size();
+ }
+
+ if (metricParams.size() > ReportManager::maxNumberMetrics ||
+ metricCount > ReportManager::maxNumberMetrics)
+ {
+ throw errors::InvalidArgument("ReadingParameters", "Too many");
+ }
+}