| Flutter Linux Embedder |

Functions
fl_binary_codec_test.cc File Reference
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_binary_codec.h"`
`#include "flutter/shell/platform/linux/testing/fl_test.h"`
`#include "gtest/gtest.h"`

Go to the source code of this file.

## Functions
static gchar * | encode_message (FlValue *value)
static void | encode_message_error (FlValue *value, GQuark domain, int code)
static FlValue * | decode_message (const char *hex_string)
| TEST (FlBinaryCodecTest, EncodeData)
| TEST (FlBinaryCodecTest, EncodeEmpty)
| TEST (FlBinaryCodecTest, EncodeNullptr)
| TEST (FlBinaryCodecTest, EncodeUnknownType)
| TEST (FlBinaryCodecTest, DecodeData)
| TEST (FlBinaryCodecTest, DecodeEmpty)
| TEST (FlBinaryCodecTest, EncodeDecode)

## Function Documentation

## ◆ decode_message()

static FlValue* decode_message | ( | const char * | hex_string | ) |
| static

Definition at line 34 of file fl_binary_codec_test.cc.

34 {
35 g_autoptr(FlBinaryCodec) codec = fl_binary_codec_new();
36 g_autoptr(GBytes) data = hex_string_to_bytes(hex_string);
37 g_autoptr(GError) error = nullptr;
38 g_autoptr(FlValue) value =
39 fl_message_codec_decode_message(FL_MESSAGE_CODEC(codec), data, &error);
40 EXPECT_EQ(error, nullptr);
41 EXPECT_NE(value, nullptr);
42 return fl_value_ref(value);
43 }
g_autoptr
g_autoptr(FlEngine) engine
fl_binary_codec_new
G_MODULE_EXPORT FlBinaryCodec * fl_binary_codec_new()
Definition: fl_binary_codec.cc:51
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
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
fl_value_ref
G_MODULE_EXPORT FlValue * fl_value_ref(FlValue *self)
Definition: fl_value.cc:394
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42

References error, fl_binary_codec_new(), fl_message_codec_decode_message(), fl_value_ref(), g_autoptr(), and value.

Referenced by TEST().

## ◆ encode_message()

static gchar* encode_message | ( | FlValue * | value | ) |
| static

Definition at line 11 of file fl_binary_codec_test.cc.

11 {
12 g_autoptr(FlBinaryCodec) codec = fl_binary_codec_new();
13 g_autoptr(GError) error = nullptr;
14 g_autoptr(GBytes) message =
15 fl_message_codec_encode_message(FL_MESSAGE_CODEC(codec), value, &error);
16 EXPECT_NE(message, nullptr);
17 EXPECT_EQ(error, nullptr);
18
19 return bytes_to_hex_string(message);
20 }
message
const char * message
Definition: fl_accessibility_handler.cc:21
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_binary_codec_new(), fl_message_codec_encode_message(), g_autoptr(), message, and value.

Referenced by TEST().

## ◆ encode_message_error()

static void encode_message_error | ( | FlValue * | value,
|  | GQuark | domain,
|  | int | code
| ) |  |
| static

Definition at line 23 of file fl_binary_codec_test.cc.

23 {
24 g_autoptr(FlBinaryCodec) codec = fl_binary_codec_new();
25 g_autoptr(GError) error = nullptr;
26 g_autoptr(GBytes) message =
27 fl_message_codec_encode_message(FL_MESSAGE_CODEC(codec), value, &error);
28 EXPECT_EQ(message, nullptr);
29 EXPECT_TRUE(g_error_matches(error, domain, code));
30 }

References error, fl_binary_codec_new(), fl_message_codec_encode_message(), g_autoptr(), message, and value.

Referenced by TEST().

## ◆ TEST() [1/7]

TEST | ( | FlBinaryCodecTest | ,
|  | DecodeData |
| ) |  |

Definition at line 69 of file fl_binary_codec_test.cc.

69 {
70 g_autoptr(FlValue) value = decode_message("000102fdfeff");
71 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_UINT8_LIST);
72 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(6));
73 EXPECT_EQ(fl_value_get_uint8_list(value)[0], 0x00);
74 EXPECT_EQ(fl_value_get_uint8_list(value)[1], 0x01);
75 EXPECT_EQ(fl_value_get_uint8_list(value)[2], 0x02);
76 EXPECT_EQ(fl_value_get_uint8_list(value)[3], 0xFD);
77 EXPECT_EQ(fl_value_get_uint8_list(value)[4], 0xFE);
78 EXPECT_EQ(fl_value_get_uint8_list(value)[5], 0xFF);
79 }
decode_message
static FlValue * decode_message(const char *hex_string)
Definition: fl_binary_codec_test.cc:34
fl_value_get_uint8_list
G_MODULE_EXPORT const uint8_t * fl_value_get_uint8_list(FlValue *self)
Definition: fl_value.cc:689
fl_value_get_type
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:466
fl_value_get_length
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition: fl_value.cc:724
FL_VALUE_TYPE_UINT8_LIST
@ FL_VALUE_TYPE_UINT8_LIST
Definition: fl_value.h:69

References decode_message(), fl_value_get_length(), fl_value_get_type(), fl_value_get_uint8_list(), FL_VALUE_TYPE_UINT8_LIST, g_autoptr(), and value.

## ◆ TEST() [2/7]

TEST | ( | FlBinaryCodecTest | ,
|  | DecodeEmpty |
| ) |  |

Definition at line 81 of file fl_binary_codec_test.cc.

81 {
82 g_autoptr(FlValue) value = decode_message("");
83 ASSERT_EQ(fl_value_get_type(value), FL_VALUE_TYPE_UINT8_LIST);
84 ASSERT_EQ(fl_value_get_length(value), static_cast<size_t>(0));
85 }

References decode_message(), fl_value_get_length(), fl_value_get_type(), FL_VALUE_TYPE_UINT8_LIST, g_autoptr(), and value.

## ◆ TEST() [3/7]

TEST | ( | FlBinaryCodecTest | ,
|  | EncodeData |
| ) |  |

Definition at line 45 of file fl_binary_codec_test.cc.

45 {
46 uint8_t data[] = {0x00, 0x01, 0x02, 0xFD, 0xFE, 0xFF};
47 g_autoptr(FlValue) value = fl_value_new_uint8_list(data, 6);
48 g_autofree gchar* hex_string = encode_message(value);
49 EXPECT_STREQ(hex_string, "000102fdfeff");
50 }
encode_message
static gchar * encode_message(FlValue *value)
Definition: fl_binary_codec_test.cc:11
fl_value_new_uint8_list
G_MODULE_EXPORT FlValue * fl_value_new_uint8_list(const uint8_t *data, size_t data_length)
Definition: fl_value.cc:292

References encode_message(), fl_value_new_uint8_list(), g_autoptr(), and value.

## ◆ TEST() [4/7]

TEST | ( | FlBinaryCodecTest | ,
|  | EncodeDecode |
| ) |  |

Definition at line 87 of file fl_binary_codec_test.cc.

87 {
88 g_autoptr(FlBinaryCodec) codec = fl_binary_codec_new();
89
90 uint8_t data[] = {0x00, 0x01, 0x02, 0xFD, 0xFE, 0xFF};
91 g_autoptr(FlValue) input = fl_value_new_uint8_list(data, 6);
92
93 g_autoptr(GError) error = nullptr;
94 g_autoptr(GBytes) message =
95 fl_message_codec_encode_message(FL_MESSAGE_CODEC(codec), input, &error);
96 EXPECT_NE(message, nullptr);
97 EXPECT_EQ(error, nullptr);
98
99 g_autoptr(FlValue) output =
100 fl_message_codec_decode_message(FL_MESSAGE_CODEC(codec), message, &error);
101 EXPECT_EQ(error, nullptr);
102 EXPECT_NE(output, nullptr);
103
104 ASSERT_TRUE(fl_value_equal(input, output));
105 }
fl_value_equal
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:471

References error, fl_binary_codec_new(), fl_message_codec_decode_message(), fl_message_codec_encode_message(), fl_value_equal(), fl_value_new_uint8_list(), g_autoptr(), and message.

## ◆ TEST() [5/7]

TEST | ( | FlBinaryCodecTest | ,
|  | EncodeEmpty |
| ) |  |

Definition at line 52 of file fl_binary_codec_test.cc.

52 {
53 g_autoptr(FlValue) value = fl_value_new_uint8_list(nullptr, 0);
54 g_autofree gchar* hex_string = encode_message(value);
55 EXPECT_STREQ(hex_string, "");
56 }

References encode_message(), fl_value_new_uint8_list(), g_autoptr(), and value.

## ◆ TEST() [6/7]

TEST | ( | FlBinaryCodecTest | ,
|  | EncodeNullptr |
| ) |  |

Definition at line 58 of file fl_binary_codec_test.cc.

58 {
59 encode_message_error(nullptr, FL_MESSAGE_CODEC_ERROR,
60 FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE);
61 }
encode_message_error
static void encode_message_error(FlValue *value, GQuark domain, int code)
Definition: fl_binary_codec_test.cc:23
FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
@ FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE
Definition: fl_message_codec.h:36
FL_MESSAGE_CODEC_ERROR
#define FL_MESSAGE_CODEC_ERROR
Definition: fl_message_codec.h:30

References encode_message_error(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE.

## ◆ TEST() [7/7]

TEST | ( | FlBinaryCodecTest | ,
|  | EncodeUnknownType |
| ) |  |

Definition at line 63 of file fl_binary_codec_test.cc.

63 {
64 g_autoptr(FlValue) value = fl_value_new_null();
65 encode_message_error(value, FL_MESSAGE_CODEC_ERROR,
66 FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE);
67 }
fl_value_new_null
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:251

References encode_message_error(), FL_MESSAGE_CODEC_ERROR, FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE, fl_value_new_null(), g_autoptr(), and value.