Add unit test for PayloadListner

PiperOrigin-RevId: 481773299
This commit is contained in:
Hai Shang
2022-10-17 16:53:52 -07:00
committed by Copybara-Service
parent a620d8eeb6
commit 4157b1f70b
+20
View File
@@ -15,11 +15,13 @@
#include "connections/listeners.h"
#include <memory>
#include <string>
#include <utility>
#include "gmock/gmock.h"
#include "protobuf-matchers/protocol-buffer-matchers.h"
#include "gtest/gtest.h"
#include "internal/platform/byte_array.h"
namespace location {
namespace nearby {
@@ -54,6 +56,24 @@ TEST(ListenersTest, EnsurePartiallyInitializedIsCallable) {
EXPECT_TRUE(initiated_cb_called);
}
TEST(ListenersTest, PayloadListener_PayloadCb_Works) {
bool payload_content_match = false;
const std::string input_bytes = "input";
Payload payload = Payload(ByteArray(input_bytes));
PayloadListener listener{
.payload_cb =
[&](const std::string& endpoint_id, Payload payload) {
if (payload.AsBytes().data() == input_bytes) {
payload_content_match = true;
}
},
};
listener.payload_cb("endpoint_id", std::move(payload));
EXPECT_TRUE(payload_content_match);
}
} // namespace
} // namespace connections
} // namespace nearby