regulators: Build IDMap for system

The IDMap class is used to map string IDs to the corresponding C++
Device, Rail, and Rule objects.

The IDMap class is complete and tested, but it was not previously being
populated except in testcases.

Add new methods to the System, Chassis, and Device classes to populate
the IDMap with all the ID -> object mappings in the system.

Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
Change-Id: I80f39b663b011ca643c91f7281ff50c956631331
diff --git a/phosphor-regulators/test/device_tests.cpp b/phosphor-regulators/test/device_tests.cpp
index 2ae4d6f..c4875bf 100644
--- a/phosphor-regulators/test/device_tests.cpp
+++ b/phosphor-regulators/test/device_tests.cpp
@@ -17,6 +17,7 @@
 #include "configuration.hpp"
 #include "device.hpp"
 #include "i2c_interface.hpp"
+#include "id_map.hpp"
 #include "mock_action.hpp"
 #include "presence_detection.hpp"
 #include "rail.hpp"
@@ -95,6 +96,39 @@
     }
 }
 
+TEST(DeviceTests, AddToIDMap)
+{
+    std::unique_ptr<PresenceDetection> presenceDetection{};
+    std::unique_ptr<Configuration> configuration{};
+
+    // Create vector of Rail objects
+    std::vector<std::unique_ptr<Rail>> rails{};
+    rails.push_back(std::make_unique<Rail>("vdd0"));
+    rails.push_back(std::make_unique<Rail>("vdd1"));
+
+    // Create Device
+    Device device{"vdd_reg",
+                  false,
+                  "/system/chassis/motherboard/reg2",
+                  std::move(createI2CInterface()),
+                  std::move(presenceDetection),
+                  std::move(configuration),
+                  std::move(rails)};
+
+    // Add Device and Rail objects to an IDMap
+    IDMap idMap{};
+    device.addToIDMap(idMap);
+
+    // Verify Device is in the IDMap
+    EXPECT_NO_THROW(idMap.getDevice("vdd_reg"));
+    EXPECT_THROW(idMap.getDevice("vio_reg"), std::invalid_argument);
+
+    // Verify all Rails are in the IDMap
+    EXPECT_NO_THROW(idMap.getRail("vdd0"));
+    EXPECT_NO_THROW(idMap.getRail("vdd1"));
+    EXPECT_THROW(idMap.getRail("vdd2"), std::invalid_argument);
+}
+
 TEST(DeviceTests, GetConfiguration)
 {
     // Test where Configuration was not specified in constructor