6 #include "gtest/gtest.h"
16 G_DEFINE_TYPE(FlTestCodec, fl_test_codec, fl_message_codec_get_type())
22 EXPECT_TRUE(FL_IS_TEST_CODEC(codec));
26 return g_bytes_new(&c, 1);
38 EXPECT_TRUE(FL_IS_TEST_CODEC(codec));
42 static_cast<const uint8_t*
>(g_bytes_get_data(message, &data_length));
43 if (data_length < 1) {
48 if (data_length > 1) {
51 "FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA");
66 return FL_TEST_CODEC(g_object_new(fl_test_codec_get_type(),
nullptr));
69 TEST(FlMessageCodecTest, EncodeMessage) {
73 g_autoptr(GError)
error =
nullptr;
74 g_autoptr(GBytes) message =
76 EXPECT_NE(message,
nullptr);
77 EXPECT_EQ(
error,
nullptr);
78 EXPECT_EQ(g_bytes_get_size(message),
static_cast<gsize
>(1));
79 EXPECT_EQ(
static_cast<const uint8_t*
>(g_bytes_get_data(message,
nullptr))[0],
83 TEST(FlMessageCodecTest, EncodeMessageError) {
87 g_autoptr(GError)
error =
nullptr;
88 g_autoptr(GBytes) message =
90 EXPECT_EQ(message,
nullptr);
95 TEST(FlMessageCodecTest, DecodeMessageEmpty) {
97 g_autoptr(GBytes) message = g_bytes_new(
nullptr, 0);
99 g_autoptr(GError)
error =
nullptr;
102 EXPECT_EQ(
value,
nullptr);
107 TEST(FlMessageCodecTest, DecodeMessage) {
109 uint8_t data[] = {
'1'};
110 g_autoptr(GBytes) message = g_bytes_new(data, 1);
112 g_autoptr(GError)
error =
nullptr;
115 EXPECT_NE(
value,
nullptr);
116 EXPECT_EQ(
error,
nullptr);
122 TEST(FlMessageCodecTest, DecodeMessageExtraData) {
124 uint8_t data[] = {
'1',
'2'};
125 g_autoptr(GBytes) message = g_bytes_new(data, 2);
127 g_autoptr(GError)
error =
nullptr;
130 EXPECT_EQ(
value,
nullptr);