Add cc only response
For a PLDM operation resulting in an error,
unless otherwise specified, the responder shall not
return any additional parametric data.
It is useful to implement a cc-only response
Signed-off-by: John Wang <wangzqbj@inspur.com>
Change-Id: Iec5299f4c4043491aa62e0b94de7f9c12d0bee2e
diff --git a/test/libpldm_base_test.cpp b/test/libpldm_base_test.cpp
index 7aaf7e4..af3a2af 100644
--- a/test/libpldm_base_test.cpp
+++ b/test/libpldm_base_test.cpp
@@ -1,11 +1,16 @@
#include <string.h>
#include <array>
+#include <cstring>
+#include <vector>
#include "libpldm/base.h"
+#include <gmock/gmock.h>
#include <gtest/gtest.h>
+using testing::ElementsAreArray;
+
constexpr auto hdrSize = sizeof(pldm_msg_hdr);
TEST(PackPLDMMessage, BadPathTest)
@@ -466,3 +471,23 @@
ASSERT_EQ(completion_code, PLDM_SUCCESS);
ASSERT_EQ(tid, 1);
}
+
+TEST(CcOnlyResponse, testEncode)
+{
+ struct pldm_msg responseMsg;
+
+ auto rc =
+ encode_cc_only_resp(0 /*instance id*/, 1 /*pldm type*/, 2 /*command*/,
+ 3 /*complection code*/, &responseMsg);
+ EXPECT_EQ(rc, PLDM_SUCCESS);
+
+ auto p = reinterpret_cast<uint8_t*>(&responseMsg);
+ EXPECT_THAT(std::vector<uint8_t>(p, p + sizeof(responseMsg)),
+ ElementsAreArray({0, 1, 2, 3}));
+
+ rc = encode_cc_only_resp(PLDM_INSTANCE_MAX + 1, 1, 2, 3, &responseMsg);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+
+ rc = encode_cc_only_resp(0, 1, 2, 3, nullptr);
+ EXPECT_EQ(rc, PLDM_ERROR_INVALID_DATA);
+}