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/test_utils.hpp b/phosphor-regulators/test/test_utils.hpp
index cbb322a..313d9f7 100644
--- a/phosphor-regulators/test/test_utils.hpp
+++ b/phosphor-regulators/test/test_utils.hpp
@@ -13,9 +13,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+#include "action.hpp"
+#include "chassis.hpp"
+#include "configuration.hpp"
+#include "device.hpp"
 #include "i2c_interface.hpp"
+#include "mock_action.hpp"
+#include "presence_detection.hpp"
+#include "rail.hpp"
+#include "rule.hpp"
 
 #include <memory>
+#include <string>
+#include <utility>
+#include <vector>
 
 namespace phosphor::power::regulators::test_utils
 {
@@ -30,4 +41,52 @@
     return i2c::create(1, 0x70, i2c::I2CInterface::InitialState::CLOSED);
 }
 
+/**
+ * Creates a Device object with the specified ID.
+ *
+ * Creates Rail objects within the Device if railIDs is specified.
+ *
+ * @param id device ID
+ * @param railIDs rail IDs (optional)
+ * @return Device object
+ */
+inline std::unique_ptr<Device>
+    createDevice(const std::string& id,
+                 const std::vector<std::string>& railIDs = {})
+{
+    // Create Rails (if any)
+    std::vector<std::unique_ptr<Rail>> rails{};
+    for (const std::string& railID : railIDs)
+    {
+        rails.emplace_back(std::make_unique<Rail>(railID));
+    }
+
+    // Create Device
+    bool isRegulator = true;
+    std::string fru = "/system/chassis/motherboard/reg1";
+    std::unique_ptr<i2c::I2CInterface> i2cInterface = createI2CInterface();
+    std::unique_ptr<PresenceDetection> presenceDetection{};
+    std::unique_ptr<Configuration> configuration{};
+    return std::make_unique<Device>(id, isRegulator, fru,
+                                    std::move(i2cInterface),
+                                    std::move(presenceDetection),
+                                    std::move(configuration), std::move(rails));
+}
+
+/**
+ * Creates a Rule object with the specified ID.
+ *
+ * @param id rule ID
+ * @return Rule object
+ */
+inline std::unique_ptr<Rule> createRule(const std::string& id)
+{
+    // Create actions
+    std::vector<std::unique_ptr<Action>> actions{};
+    actions.emplace_back(std::make_unique<MockAction>());
+
+    // Create Rule
+    return std::make_unique<Rule>(id, std::move(actions));
+}
+
 } // namespace phosphor::power::regulators::test_utils