summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorWilliam A. Kennington III <wak@google.com>2019-04-24 14:44:26 -0700
committerWilliam A. Kennington III <wak@google.com>2019-04-29 12:06:35 -0700
commite2aec26caacdc65711a96ce3b6dbaa5ea526fc1f (patch)
treeb858890a099c0b52f48eb222c5b7c80367cfa9dd /test
parent906e0f802b56d26e7e0c65eba797fa8a596dee91 (diff)
downloadphosphor-host-ipmid-e2aec26caacdc65711a96ce3b6dbaa5ea526fc1f.tar.gz
phosphor-host-ipmid-e2aec26caacdc65711a96ce3b6dbaa5ea526fc1f.zip
message/pack: Support packing string_views
Now we don't need to make an intermediate copy of our data into an array before packing it into a payload. Change-Id: Iac79a79e0ae95835cb67d617a966a92ce8dcd5f8 Signed-off-by: William A. Kennington III <wak@google.com>
Diffstat (limited to 'test')
-rw-r--r--test/message/pack.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/message/pack.cpp b/test/message/pack.cpp
index 7e6cf31..939b356 100644
--- a/test/message/pack.cpp
+++ b/test/message/pack.cpp
@@ -242,6 +242,20 @@ TEST(PackBasics, VectorUnaligned)
EXPECT_EQ(p.raw, std::vector<uint8_t>{0b1});
}
+TEST(PackBasics, StringView)
+{
+ ipmi::message::Payload p;
+ EXPECT_EQ(p.pack(std::string_view{"\x24\x30\x11"}), 0);
+ EXPECT_EQ(p.raw, std::vector<uint8_t>({0x24, 0x30, 0x11}));
+}
+
+TEST(PackBasics, StringViewUnaligned)
+{
+ ipmi::message::Payload p;
+ EXPECT_EQ(p.pack(true, std::string_view{"abc"}), 1);
+ EXPECT_EQ(p.raw, std::vector<uint8_t>({0b1}));
+}
+
TEST(PackBasics, OptionalEmpty)
{
// an optional will only pack if the value is present
OpenPOWER on IntegriCloud