controller: Heap-allocate LEDs

Do this in preparation for migrating to a single instance of the daemon
whose LED inventory is updated via DBus where the update is triggered by
udev.

Splitting out this work reduces the review complexity of the patch that
rewrites the internals of the daemon.

Signed-off-by: Jayashree Dhanapal <jayashree-d@hcl.com>
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I50e58126413514f7a64153f425629142fa5af6d4
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/test/physical.cpp b/test/physical.cpp
index 271143c..90ced2d 100644
--- a/test/physical.cpp
+++ b/test/physical.cpp
@@ -76,9 +76,9 @@
 {
     sdbusplus::bus_t bus = sdbusplus::bus::new_default();
     /* NiceMock ignores calls to methods with no expectations defined */
-    NiceMock<MockLed> led;
-    ON_CALL(led, getTrigger()).WillByDefault(Return("none"));
-    phosphor::led::Physical phy(bus, ledObj, led);
+    auto led = std::make_unique<NiceMock<MockLed>>();
+    ON_CALL(*led, getTrigger()).WillByDefault(Return("none"));
+    phosphor::led::Physical phy(bus, ledObj, std::move(led));
     EXPECT_EQ(phy.state(), Action::Off);
 }
 
@@ -86,11 +86,11 @@
 {
     sdbusplus::bus_t bus = sdbusplus::bus::new_default();
     /* NiceMock ignores calls to methods with no expectations defined */
-    NiceMock<MockLed> led;
-    EXPECT_CALL(led, getTrigger()).WillRepeatedly(Return("none"));
-    EXPECT_CALL(led, getBrightness()).WillOnce(Return(127));
-    EXPECT_CALL(led, getMaxBrightness()).WillOnce(Return(127));
-    phosphor::led::Physical phy(bus, ledObj, led);
+    auto led = std::make_unique<NiceMock<MockLed>>();
+    EXPECT_CALL(*led, getTrigger()).WillRepeatedly(Return("none"));
+    EXPECT_CALL(*led, getBrightness()).WillOnce(Return(127));
+    EXPECT_CALL(*led, getMaxBrightness()).WillOnce(Return(127));
+    phosphor::led::Physical phy(bus, ledObj, std::move(led));
     EXPECT_EQ(phy.state(), Action::On);
 }
 
@@ -98,11 +98,11 @@
 {
     sdbusplus::bus_t bus = sdbusplus::bus::new_default();
     /* NiceMock ignores calls to methods with no expectations defined */
-    NiceMock<MockLed> led;
-    EXPECT_CALL(led, getTrigger()).WillRepeatedly(Return("none"));
-    EXPECT_CALL(led, getBrightness()).WillOnce(Return(0));
-    EXPECT_CALL(led, getMaxBrightness()).WillOnce(Return(0));
-    phosphor::led::Physical phy(bus, ledObj, led);
+    auto led = std::make_unique<NiceMock<MockLed>>();
+    EXPECT_CALL(*led, getTrigger()).WillRepeatedly(Return("none"));
+    EXPECT_CALL(*led, getBrightness()).WillOnce(Return(0));
+    EXPECT_CALL(*led, getMaxBrightness()).WillOnce(Return(0));
+    phosphor::led::Physical phy(bus, ledObj, std::move(led));
     EXPECT_EQ(phy.state(), Action::Off);
 }
 
@@ -110,11 +110,11 @@
 {
     sdbusplus::bus_t bus = sdbusplus::bus::new_default();
     /* NiceMock ignores calls to methods with no expectations defined */
-    NiceMock<MockLed> led;
-    EXPECT_CALL(led, getTrigger()).WillRepeatedly(Return("none"));
-    EXPECT_CALL(led, getBrightness()).WillOnce(Return(0));
-    EXPECT_CALL(led, getMaxBrightness()).WillOnce(Return(127));
-    phosphor::led::Physical phy(bus, ledObj, led);
+    auto led = std::make_unique<NiceMock<MockLed>>();
+    EXPECT_CALL(*led, getTrigger()).WillRepeatedly(Return("none"));
+    EXPECT_CALL(*led, getBrightness()).WillOnce(Return(0));
+    EXPECT_CALL(*led, getMaxBrightness()).WillOnce(Return(127));
+    phosphor::led::Physical phy(bus, ledObj, std::move(led));
     EXPECT_EQ(phy.state(), Action::Off);
 }
 
@@ -122,35 +122,35 @@
 {
     sdbusplus::bus_t bus = sdbusplus::bus::new_default();
     /* NiceMock ignores calls to methods with no expectations defined */
-    NiceMock<MockLed> led;
-    EXPECT_CALL(led, getTrigger()).WillRepeatedly(Return("none"));
-    EXPECT_CALL(led, getBrightness()).WillOnce(Return(127));
-    EXPECT_CALL(led, getMaxBrightness()).WillOnce(Return(0));
-    phosphor::led::Physical phy(bus, ledObj, led);
+    auto led = std::make_unique<NiceMock<MockLed>>();
+    EXPECT_CALL(*led, getTrigger()).WillRepeatedly(Return("none"));
+    EXPECT_CALL(*led, getBrightness()).WillOnce(Return(127));
+    EXPECT_CALL(*led, getMaxBrightness()).WillOnce(Return(0));
+    phosphor::led::Physical phy(bus, ledObj, std::move(led));
     EXPECT_EQ(phy.state(), Action::Off);
 }
 
 TEST(Physical, ctor_timer_trigger)
 {
     sdbusplus::bus_t bus = sdbusplus::bus::new_default();
-    NiceMock<MockLed> led;
-    EXPECT_CALL(led, getTrigger()).WillOnce(Return("timer"));
-    EXPECT_CALL(led, getDelayOn()).WillOnce(Return(500));
-    EXPECT_CALL(led, getDelayOff()).WillOnce(Return(500));
-    phosphor::led::Physical phy(bus, ledObj, led);
+    auto led = std::make_unique<NiceMock<MockLed>>();
+    EXPECT_CALL(*led, getTrigger()).WillOnce(Return("timer"));
+    EXPECT_CALL(*led, getDelayOn()).WillOnce(Return(500));
+    EXPECT_CALL(*led, getDelayOff()).WillOnce(Return(500));
+    phosphor::led::Physical phy(bus, ledObj, std::move(led));
     EXPECT_EQ(phy.state(), Action::Blink);
 }
 
 TEST(Physical, off)
 {
     sdbusplus::bus_t bus = sdbusplus::bus::new_default();
-    NiceMock<MockLed> led;
-    ON_CALL(led, getMaxBrightness()).WillByDefault(Return(127));
-    EXPECT_CALL(led, getTrigger()).WillOnce(Return("none"));
-    EXPECT_CALL(led, getBrightness())
+    auto led = std::make_unique<NiceMock<MockLed>>();
+    ON_CALL(*led, getMaxBrightness()).WillByDefault(Return(127));
+    EXPECT_CALL(*led, getTrigger()).WillOnce(Return("none"));
+    EXPECT_CALL(*led, getBrightness())
         .WillOnce(Return(phosphor::led::deasserted));
-    EXPECT_CALL(led, setBrightness(phosphor::led::deasserted)).Times(0);
-    phosphor::led::Physical phy(bus, ledObj, led);
+    EXPECT_CALL(*led, setBrightness(phosphor::led::deasserted)).Times(0);
+    phosphor::led::Physical phy(bus, ledObj, std::move(led));
     phy.state(Action::Off);
     EXPECT_EQ(phy.state(), Action::Off);
 }
@@ -160,12 +160,12 @@
     constexpr unsigned long asserted = 127;
 
     sdbusplus::bus_t bus = sdbusplus::bus::new_default();
-    NiceMock<MockLed> led;
-    ON_CALL(led, getMaxBrightness()).WillByDefault(Return(asserted));
-    EXPECT_CALL(led, getTrigger()).WillOnce(Return("none"));
-    EXPECT_CALL(led, setTrigger("none"));
-    EXPECT_CALL(led, setBrightness(asserted));
-    phosphor::led::Physical phy(bus, ledObj, led);
+    auto led = std::make_unique<NiceMock<MockLed>>();
+    ON_CALL(*led, getMaxBrightness()).WillByDefault(Return(asserted));
+    EXPECT_CALL(*led, getTrigger()).WillOnce(Return("none"));
+    EXPECT_CALL(*led, setTrigger("none"));
+    EXPECT_CALL(*led, setBrightness(asserted));
+    phosphor::led::Physical phy(bus, ledObj, std::move(led));
     phy.state(Action::On);
     EXPECT_EQ(phy.state(), Action::On);
 }
@@ -173,12 +173,12 @@
 TEST(Physical, blink)
 {
     sdbusplus::bus_t bus = sdbusplus::bus::new_default();
-    NiceMock<MockLed> led;
-    EXPECT_CALL(led, getTrigger()).WillOnce(Return("none"));
-    EXPECT_CALL(led, setTrigger("timer"));
-    EXPECT_CALL(led, setDelayOn(500));
-    EXPECT_CALL(led, setDelayOff(500));
-    phosphor::led::Physical phy(bus, ledObj, led);
+    auto led = std::make_unique<NiceMock<MockLed>>();
+    EXPECT_CALL(*led, getTrigger()).WillOnce(Return("none"));
+    EXPECT_CALL(*led, setTrigger("timer"));
+    EXPECT_CALL(*led, setDelayOn(500));
+    EXPECT_CALL(*led, setDelayOff(500));
+    phosphor::led::Physical phy(bus, ledObj, std::move(led));
     phy.state(Action::Blink);
     EXPECT_EQ(phy.state(), Action::Blink);
 }
@@ -186,10 +186,10 @@
 TEST(Physical, ctor_none_trigger_asserted_brightness)
 {
     sdbusplus::bus_t bus = sdbusplus::bus::new_default();
-    NiceMock<MockLed> led;
-    EXPECT_CALL(led, getTrigger()).WillRepeatedly(Return("none"));
-    EXPECT_CALL(led, getBrightness()).WillRepeatedly(Return(127));
-    phosphor::led::Physical phy(bus, ledObj, led);
+    auto led = std::make_unique<NiceMock<MockLed>>();
+    EXPECT_CALL(*led, getTrigger()).WillRepeatedly(Return("none"));
+    EXPECT_CALL(*led, getBrightness()).WillRepeatedly(Return(127));
+    phosphor::led::Physical phy(bus, ledObj, std::move(led));
     EXPECT_EQ(phy.state(), Action::Off);
 }
 
@@ -199,14 +199,14 @@
     constexpr unsigned long asserted = 127;
 
     auto bus = sdbusplus::bus::new_default();
-    NiceMock<MockLed> led;
-    ON_CALL(led, getMaxBrightness()).WillByDefault(Return(asserted));
-    EXPECT_CALL(led, getTrigger()).Times(1).WillOnce(Return("none"));
-    constexpr auto deasserted = phosphor::led::deasserted;
-    EXPECT_CALL(led, getBrightness()).WillOnce(Return(deasserted));
-    EXPECT_CALL(led, setBrightness(asserted));
-    EXPECT_CALL(led, setBrightness(deasserted));
-    phosphor::led::Physical phy(bus, ledObj, led);
+    auto led = std::make_unique<NiceMock<MockLed>>();
+    ON_CALL(*led, getMaxBrightness()).WillByDefault(Return(asserted));
+    EXPECT_CALL(*led, getTrigger()).Times(1).WillOnce(Return("none"));
+    EXPECT_CALL(*led, getBrightness())
+        .WillOnce(Return(phosphor::led::deasserted));
+    EXPECT_CALL(*led, setBrightness(asserted));
+    EXPECT_CALL(*led, setBrightness(phosphor::led::deasserted));
+    phosphor::led::Physical phy(bus, ledObj, std::move(led));
     phy.state(Action::On);
     EXPECT_EQ(phy.state(), Action::On);
     phy.state(Action::Off);