sdbus++: support special double values
Enable properties to have default values of special IEEE floating
points: 'NaN', 'infinity' and 'epsilon'.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I7c2daa3c36cde69c2ee06afd75a8d2e77992c6e7
diff --git a/test/server/Test.interface.yaml b/test/server/Test.interface.yaml
index 30df1f9..ed98eb3 100644
--- a/test/server/Test.interface.yaml
+++ b/test/server/Test.interface.yaml
@@ -22,3 +22,15 @@
type: uint64
- name: ObjectPath
type: object_path
+ - name: DoubleAsNAN
+ type: double
+ default: NaN
+ - name: DoubleAsInf
+ type: double
+ default: Infinity
+ - name: DoubleAsNegInf
+ type: double
+ default: -Infinity
+ - name: DoubleAsEpsilon
+ type: double
+ default: Epsilon
diff --git a/test/server/object.cpp b/test/server/object.cpp
index 8faa668..76e077d 100644
--- a/test/server/object.cpp
+++ b/test/server/object.cpp
@@ -103,3 +103,24 @@
sd_bus_emit_interfaces_removed_strv(_, StrEq(objPath), _))
.Times(0);
}
+
+TEST_F(Object, DoubleHasDefaultValues)
+{
+ // Simulate the typical usage of a service
+ sdbusplus::server::manager::manager objManager(bus, objPath);
+ bus.request_name(busName);
+
+ EXPECT_CALL(sdbusMock, sd_bus_emit_object_added(_, StrEq(objPath)))
+ .Times(1);
+ EXPECT_CALL(sdbusMock,
+ sd_bus_emit_interfaces_added_strv(_, StrEq(objPath), _))
+ .Times(0);
+
+ auto test = std::make_unique<TestInherit>(bus, objPath);
+ EXPECT_TRUE(std::isnan(test->doubleAsNAN()));
+ EXPECT_TRUE(std::isinf(test->doubleAsInf()) &&
+ !std::signbit(test->doubleAsInf()));
+ EXPECT_TRUE(std::isinf(test->doubleAsNegInf()) &&
+ std::signbit(test->doubleAsNegInf()));
+ EXPECT_EQ(std::numeric_limits<double>::epsilon(), test->doubleAsEpsilon());
+}