| Flutter Linux Embedder |

Classes | Functions
fl_message_codec_test.cc File Reference
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_message_codec.h"`
`#include "gtest/gtest.h"`

Go to the source code of this file.

## Classes
struct | _FlTestCodec

## Functions
static GBytes * | fl_test_codec_encode_message (FlMessageCodec *codec, FlValue *value, GError **error)
static FlValue * | fl_test_codec_decode_message (FlMessageCodec *codec, GBytes *message, GError **error)
static void | fl_test_codec_class_init (FlTestCodecClass *klass)
static void | fl_test_codec_init (FlTestCodec *self)
static FlTestCodec * | fl_test_codec_new ()
| TEST (FlMessageCodecTest, EncodeMessage)
| TEST (FlMessageCodecTest, EncodeMessageError)
| TEST (FlMessageCodecTest, DecodeMessageEmpty)
| TEST (FlMessageCodecTest, DecodeMessage)
| TEST (FlMessageCodecTest, DecodeMessageExtraData)

## Function Documentation

## ◆ fl_test_codec_class_init()

static void fl_test_codec_class_init | ( | FlTestCodecClass * | klass | ) |
| static

Definition at line 58 of file fl_message_codec_test.cc.

58 {
59 FL_MESSAGE_CODEC_CLASS(klass)->encode_message = fl_test_codec_encode_message;
60 FL_MESSAGE_CODEC_CLASS(klass)->decode_message = fl_test_codec_decode_message;
61 }
fl_test_codec_encode_message
static GBytes * fl_test_codec_encode_message(FlMessageCodec *codec, FlValue *value, GError **error)
Definition: fl_message_codec_test.cc:19
fl_test_codec_decode_message
static FlValue * fl_test_codec_decode_message(FlMessageCodec *codec, GBytes *message, GError **error)
Definition: fl_message_codec_test.cc:35

References fl_test_codec_decode_message(), and fl_test_codec_encode_message().

## ◆ fl_test_codec_decode_message()

static FlValue* fl_test_codec_decode_message | ( | FlMessageCodec * | codec,
|  | GBytes * | message,
|  | GError ** | error
| ) |  |
| static

Definition at line 35 of file fl_message_codec_test.cc.

37 {
38 EXPECT_TRUE(FL_IS_TEST_CODEC(codec));
39
40 size_t data_length;
41 const uint8_t* data =
42 static_cast<const uint8_t*>(g_bytes_get_data(message, &data_length));
43 if (data_length < 1) {
44 g_set_error(error, FL_MESSAGE_CODEC_ERROR,
45 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA, "No data");
46 return FALSE;
47 }
48 if (data_length > 1) {
49 g_set_error(error, FL_MESSAGE_CODEC_ERROR,
50 FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA,
51 "FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA");
52 return FALSE;
53 }
54
55 return fl_value_new_int(data[0] - '0');
56 }
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
@ FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
Definition: fl_message_codec.h:34
FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA
@ FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA
Definition: fl_message_codec.h:35
FL_MESSAGE_CODEC_ERROR
#define FL_MESSAGE_CODEC_ERROR
Definition: fl_message_codec.h:30
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_value_new_int
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:262

References error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA, FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA, and fl_value_new_int().

Referenced by fl_test_codec_class_init().

## ◆ fl_test_codec_encode_message()

static GBytes* fl_test_codec_encode_message | ( | FlMessageCodec * | codec,
|  | FlValue * | value,
|  | GError ** | error
| ) |  |
| static

Definition at line 19 of file fl_message_codec_test.cc.

21 {
22 EXPECT_TRUE(FL_IS_TEST_CODEC(codec));
23
24 if (fl_value_get_type(value) == FL_VALUE_TYPE_INT) {
25 char c = '0' + fl_value_get_int(value);
26 return g_bytes_new(&c, 1);
27 } else {
28 g_set_error(error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED,
29 "ERROR");
30 return nullptr;
31 }
32 }
FL_MESSAGE_CODEC_ERROR_FAILED
@ FL_MESSAGE_CODEC_ERROR_FAILED
Definition: fl_message_codec.h:33
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
fl_value_get_int
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition: fl_value.cc:668
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
FL_VALUE_TYPE_INT
@ FL_VALUE_TYPE_INT
Definition: fl_value.h:66

References error, FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED, fl_value_get_int(), fl_value_get_type(), FL_VALUE_TYPE_INT, and value.

Referenced by fl_test_codec_class_init().

## ◆ fl_test_codec_init()

static void fl_test_codec_init | ( | FlTestCodec * | self | ) |
| static

Definition at line 63 of file fl_message_codec_test.cc.

63 {}

## ◆ fl_test_codec_new()

static FlTestCodec* fl_test_codec_new | ( |  | ) |
| static

Definition at line 65 of file fl_message_codec_test.cc.

65 {
66 return FL_TEST_CODEC(g_object_new(fl_test_codec_get_type(), nullptr));
67 }

Referenced by TEST().

## ◆ TEST() [1/5]

TEST | ( | FlMessageCodecTest | ,
|  | DecodeMessage |
| ) |  |

Definition at line 107 of file fl_message_codec_test.cc.

107 {
108 g_autoptr(FlTestCodec) codec = fl_test_codec_new();
109 uint8_t data[] = {'1'};
110 g_autoptr(GBytes) message = g_bytes_new(data, 1);
111
112 g_autoptr(GError) error = nullptr;
113 g_autoptr(FlValue) value =
114 fl_message_codec_decode_message(FL_MESSAGE_CODEC(codec), message, &error);
115 EXPECT_NE(value, nullptr);
116 EXPECT_EQ(error, nullptr);
117
118 ASSERT_TRUE(fl_value_get_type(value) == FL_VALUE_TYPE_INT);
119 EXPECT_EQ(fl_value_get_int(value), 1);
120 }
g_autoptr
g_autoptr(GMutexLocker) locker
fl_message_codec_decode_message
G_MODULE_EXPORT FlValue * fl_message_codec_decode_message(FlMessageCodec *self, GBytes *message, GError **error)
Definition: fl_message_codec.cc:33
fl_test_codec_new
static FlTestCodec * fl_test_codec_new()
Definition: fl_message_codec_test.cc:65
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42

References error, fl_message_codec_decode_message(), fl_test_codec_new(), fl_value_get_int(), fl_value_get_type(), FL_VALUE_TYPE_INT, g_autoptr(), and value.

## ◆ TEST() [2/5]

TEST | ( | FlMessageCodecTest | ,
|  | DecodeMessageEmpty |
| ) |  |

Definition at line 95 of file fl_message_codec_test.cc.

95 {
96 g_autoptr(FlTestCodec) codec = fl_test_codec_new();
97 g_autoptr(GBytes) message = g_bytes_new(nullptr, 0);
98
99 g_autoptr(GError) error = nullptr;
100 g_autoptr(FlValue) value =
101 fl_message_codec_decode_message(FL_MESSAGE_CODEC(codec), message, &error);
102 EXPECT_EQ(value, nullptr);
103 EXPECT_TRUE(g_error_matches(error, FL_MESSAGE_CODEC_ERROR,
104 FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA));
105 }

References error, fl_message_codec_decode_message(), FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA, fl_test_codec_new(), g_autoptr(), and value.

## ◆ TEST() [3/5]

TEST | ( | FlMessageCodecTest | ,
|  | DecodeMessageExtraData |
| ) |  |

Definition at line 122 of file fl_message_codec_test.cc.

122 {
123 g_autoptr(FlTestCodec) codec = fl_test_codec_new();
124 uint8_t data[] = {'1', '2'};
125 g_autoptr(GBytes) message = g_bytes_new(data, 2);
126
127 g_autoptr(GError) error = nullptr;
128 g_autoptr(FlValue) value =
129 fl_message_codec_decode_message(FL_MESSAGE_CODEC(codec), message, &error);
130 EXPECT_EQ(value, nullptr);
131 EXPECT_TRUE(g_error_matches(error, FL_MESSAGE_CODEC_ERROR,
132 FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA));
133 }

References error, fl_message_codec_decode_message(), FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_ADDITIONAL_DATA, fl_test_codec_new(), g_autoptr(), and value.

## ◆ TEST() [4/5]

TEST | ( | FlMessageCodecTest | ,
|  | EncodeMessage |
| ) |  |

Definition at line 69 of file fl_message_codec_test.cc.

69 {
70 g_autoptr(FlTestCodec) codec = fl_test_codec_new();
71
72 g_autoptr(FlValue) value = fl_value_new_int(1);
73 g_autoptr(GError) error = nullptr;
74 g_autoptr(GBytes) message =
75 fl_message_codec_encode_message(FL_MESSAGE_CODEC(codec), value, &error);
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],
80 '1');
81 }
fl_message_codec_encode_message
G_MODULE_EXPORT GBytes * fl_message_codec_encode_message(FlMessageCodec *self, FlValue *message, GError **error)
Definition: fl_message_codec.cc:17

References error, fl_message_codec_encode_message(), fl_test_codec_new(), fl_value_new_int(), g_autoptr(), and value.

## ◆ TEST() [5/5]

TEST | ( | FlMessageCodecTest | ,
|  | EncodeMessageError |
| ) |  |

Definition at line 83 of file fl_message_codec_test.cc.

83 {
84 g_autoptr(FlTestCodec) codec = fl_test_codec_new();
85
86 g_autoptr(FlValue) value = fl_value_new_null();
87 g_autoptr(GError) error = nullptr;
88 g_autoptr(GBytes) message =
89 fl_message_codec_encode_message(FL_MESSAGE_CODEC(codec), value, &error);
90 EXPECT_EQ(message, nullptr);
91 EXPECT_TRUE(g_error_matches(error, FL_MESSAGE_CODEC_ERROR,
92 FL_MESSAGE_CODEC_ERROR_FAILED));
93 }
fl_value_new_null
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:251

References error, fl_message_codec_encode_message(), FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_FAILED, fl_test_codec_new(), fl_value_new_null(), g_autoptr(), and value.