Add length limit for user-defined values

Previously, the only limit for most user-defined values like id or name
was the one enforced by dbus, which was fairly big. In order to save
space used by persistent data, new meson options were added, with length
limit for those fields.

This directly impacts following dbus interfaces:
- TriggerManager.AddTrigger:
  - Id
  - Name
  - Reports
  - Thresholds (only name of discrete threshold)
- Trigger.Name
- Trigger.Reports
- Trigger.Thresholds (only name of discrete threshold)
- ReportManager.AddReport(FutureVersion):
  - Id
  - Name
  - MetricParameters (metricId)
- Report.Name
- Report.ReadingParameters (metricId)

For Id fields we support 'prefixes', which also are limited, but those
limit are separate. So if limit for prefix is set to 5 and limit for
id/name is set to 5, following Ids are fine:
- 12345/12345
- 12345
and following are not:
- 123456/1234
- 1/123456

Testing done:
- UTs are passing.
- new limits are reflected when calling mentioned dbus interfaces.

Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: I29291a1cc56a344d92fb65491c9186fdb90a8529
diff --git a/tests/src/test_report_manager.cpp b/tests/src/test_report_manager.cpp
index 5d0d4a5..6ce0f1f 100644
--- a/tests/src/test_report_manager.cpp
+++ b/tests/src/test_report_manager.cpp
@@ -8,7 +8,10 @@
 #include "report.hpp"
 #include "report_manager.hpp"
 #include "utils/conversion.hpp"
+#include "utils/dbus_path_utils.hpp"
+#include "utils/string_utils.hpp"
 #include "utils/transform.hpp"
+#include "utils/tstring.hpp"
 
 using namespace testing;
 using namespace std::string_literals;
@@ -162,7 +165,7 @@
 
 TEST_F(TestReportManager, addReportWithMaxLengthId)
 {
-    std::string reportId(ReportManager::maxReportIdLength, 'z');
+    std::string reportId = utils::string_utils::getMaxId();
     reportParams.reportId(reportId);
     reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock));
 
@@ -172,13 +175,142 @@
     EXPECT_THAT(path, Eq("/"s + reportId));
 }
 
-TEST_F(TestReportManager, DISABLED_failToAddReportWithTooLongName)
+TEST_F(TestReportManager, addReportWithMaxLengthPrefix)
+{
+    std::string reportId = utils::string_utils::getMaxPrefix() + "/MyId";
+    reportParams.reportId(reportId);
+    reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock));
+
+    auto [ec, path] = addReport(reportParams);
+
+    EXPECT_THAT(ec.value(), Eq(boost::system::errc::success));
+    EXPECT_THAT(path, Eq("/"s + reportId));
+}
+
+TEST_F(TestReportManager, addReportWithMaxLengthName)
+{
+    reportParams.reportName(utils::string_utils::getMaxName());
+    reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock));
+
+    auto [ec, path] = addReport(reportParams);
+
+    EXPECT_THAT(ec.value(), Eq(boost::system::errc::success));
+    EXPECT_THAT(path, Eq("/"s + reportParams.reportId()));
+}
+
+TEST_F(TestReportManager, addReportWithMaxLengthMetricId)
+{
+    namespace ts = utils::tstring;
+    std::vector<LabeledMetricParameters> newMetricParams{
+        {LabeledMetricParameters{
+            {LabeledSensorInfo{"Service",
+                               "/xyz/openbmc_project/sensors/power/p1",
+                               "metadata1"}},
+            OperationType::avg,
+            utils::string_utils::getMaxId(),
+            CollectionTimeScope::point,
+            CollectionDuration(Milliseconds(0u))}}};
+
+    reportParams.metricParameters(newMetricParams);
+    reportFactoryMock.expectMake(reportParams, Ref(*sut), Ref(storageMock));
+
+    auto [ec, path] = addReport(reportParams);
+
+    EXPECT_THAT(ec.value(), Eq(boost::system::errc::success));
+    EXPECT_THAT(path, Eq("/"s + reportParams.reportId()));
+}
+
+TEST_F(TestReportManager, DISABLED_failToAddReportWithTooLongFullId)
 {
     reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock))
         .Times(0);
 
     reportParams.reportId(
-        std::string(ReportManager::maxReportIdLength + 1, 'z'));
+        std::string(utils::constants::maxReportFullIdLength + 1, 'z'));
+
+    auto [ec, path] = addReport(reportParams);
+
+    EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument));
+    EXPECT_THAT(path, Eq(std::string()));
+}
+
+TEST_F(TestReportManager, DISABLED_failToAddReportWithTooLongId)
+{
+    reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock))
+        .Times(0);
+
+    reportParams.reportId(utils::string_utils::getTooLongId());
+
+    auto [ec, path] = addReport(reportParams);
+
+    EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument));
+    EXPECT_THAT(path, Eq(std::string()));
+}
+
+TEST_F(TestReportManager, DISABLED_failToAddReportWithTooLongPrefix)
+{
+    reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock))
+        .Times(0);
+
+    reportParams.reportId(utils::string_utils::getTooLongPrefix() + "/MyId");
+
+    auto [ec, path] = addReport(reportParams);
+
+    EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument));
+    EXPECT_THAT(path, Eq(std::string()));
+}
+
+TEST_F(TestReportManager, DISABLED_failToAddReportWithTooManyPrefixes)
+{
+    reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock))
+        .Times(0);
+
+    std::string reportId;
+    for (size_t i = 0; i < utils::constants::maxPrefixesInId + 1; i++)
+    {
+        reportId += "prefix/";
+    }
+    reportId += "MyId";
+
+    reportParams.reportId(reportId);
+
+    auto [ec, path] = addReport(reportParams);
+
+    EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument));
+    EXPECT_THAT(path, Eq(std::string()));
+}
+
+TEST_F(TestReportManager, DISABLED_failToAddReportWithTooLongName)
+{
+    reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock))
+        .Times(0);
+
+    reportParams.reportName(utils::string_utils::getTooLongName());
+
+    auto [ec, path] = addReport(reportParams);
+
+    EXPECT_THAT(ec.value(), Eq(boost::system::errc::invalid_argument));
+    EXPECT_THAT(path, Eq(std::string()));
+}
+
+TEST_F(TestReportManager, DISABLED_failToAddReportWithTooLongMetricId)
+{
+    namespace ts = utils::tstring;
+
+    std::vector<LabeledMetricParameters> newMetricParams{
+        {LabeledMetricParameters{
+            {LabeledSensorInfo{"Service",
+                               "/xyz/openbmc_project/sensors/power/p1",
+                               "metadata1"}},
+            OperationType::avg,
+            utils::string_utils::getTooLongId(),
+            CollectionTimeScope::point,
+            CollectionDuration(Milliseconds(0u))}}};
+
+    reportFactoryMock.expectMake(std::nullopt, Ref(*sut), Ref(storageMock))
+        .Times(0);
+
+    reportParams.metricParameters(newMetricParams);
 
     auto [ec, path] = addReport(reportParams);