summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorVernon Mauery <vernon.mauery@linux.intel.com>2019-04-03 12:11:08 -0700
committerTom Joseph <tomjoseph@in.ibm.com>2019-04-05 09:31:35 +0000
commitbae91350cc4bad07b841037f078c0df282beffbf (patch)
tree6081ff01e54acf11cf20118880e3ef8a49b8b11d /test
parentf299807f1bcca4e2582427d4dcd2a4473871d125 (diff)
downloadphosphor-host-ipmid-bae91350cc4bad07b841037f078c0df282beffbf.tar.gz
phosphor-host-ipmid-bae91350cc4bad07b841037f078c0df282beffbf.zip
Add support for returning optional values
Some commands have optional return values. This allows the handlers to be defined as returning an optional<T> value and then in the body of the handler set the value in the optional or not. Tested-by: unit test runs successfully Change-Id: Ib38a4589609fb1eb192106e511c9ee3a507ac42f Signed-off-by: Vernon Mauery <vernon.mauery@linux.intel.com>
Diffstat (limited to 'test')
-rw-r--r--test/message/pack.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/message/pack.cpp b/test/message/pack.cpp
index b3957cc..03846c5 100644
--- a/test/message/pack.cpp
+++ b/test/message/pack.cpp
@@ -222,6 +222,32 @@ TEST(PackBasics, VectorUint8)
ASSERT_EQ(p.raw, k);
}
+TEST(PackBasics, OptionalEmpty)
+{
+ // an optional will only pack if the value is present
+ ipmi::message::Payload p;
+ std::optional<uint32_t> v;
+ p.pack(v);
+ // check that the number of bytes matches
+ ASSERT_EQ(p.size(), 0);
+ // check that the bytes were correctly packed (in byte order)
+ std::vector<uint8_t> k = {};
+ ASSERT_EQ(p.raw, k);
+}
+
+TEST(PackBasics, OptionalContainsValue)
+{
+ // an optional will only pack if the value is present
+ ipmi::message::Payload p;
+ std::optional<uint32_t> v(0x04860002);
+ p.pack(v);
+ // check that the number of bytes matches
+ ASSERT_EQ(p.size(), sizeof(uint32_t));
+ // check that the bytes were correctly packed (in byte order)
+ std::vector<uint8_t> k = {0x02, 0x00, 0x86, 0x04};
+ ASSERT_EQ(p.raw, k);
+}
+
TEST(PackAdvanced, Uints)
{
// all elements will be processed in order, with each multi-byte
OpenPOWER on IntegriCloud