test: physical: Cover trigger:timer branch in setInitialState()
The test causes execution to take the following path in
setInitialState(), previously outlined in 264d909d3dc9 ("test: Add tests
for Physical class") as being missed:
auto trigger = led.getTrigger();
if (trigger == "timer")
{
// LED is blinking. Get the delay_on and delay_off and compute
// DutyCycle. sfsfs values are in strings. Need to convert 'em over to
// integer.
auto delayOn = led.getDelayOn();
auto delayOff = led.getDelayOff();
// Calculate frequency and then percentage ON
frequency = delayOn + delayOff;
auto factor = frequency / 100;
auto dutyOn = delayOn / factor;
// Update.
this->dutyOn(dutyOn);
}
This brings the line coverage to 96.6% (function coverage remains
unchanged by this patch).
Change-Id: Ie311186f6275d3fdd31de5698c7c14bb335128e1
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/test/physical.cpp b/test/physical.cpp
index 1b546ed..897a43f 100644
--- a/test/physical.cpp
+++ b/test/physical.cpp
@@ -70,7 +70,7 @@
using ::testing::Return;
using ::testing::Throw;
-TEST(Physical, ctor)
+TEST(Physical, ctor_none_trigger)
{
sdbusplus::bus::bus bus = sdbusplus::bus::new_default();
/* NiceMock ignores calls to methods with no expectations defined */
@@ -79,6 +79,16 @@
phosphor::led::Physical phy(bus, LED_OBJ, led);
}
+TEST(Physical, ctor_timer_trigger)
+{
+ sdbusplus::bus::bus 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, LED_OBJ, led);
+}
+
TEST(Physical, off)
{
sdbusplus::bus::bus bus = sdbusplus::bus::new_default();