Flutter Engine
fl_string_codec_test.cc File Reference
#include "flutter/shell/platform/linux/public/flutter_linux/fl_string_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 FlValuedecode_message (const char *hex_string)
 
 TEST (FlStringCodecTest, EncodeData)
 
 TEST (FlStringCodecTest, EncodeEmpty)
 
 TEST (FlStringCodecTest, EncodeNullptr)
 
 TEST (FlStringCodecTest, EncodeUnknownType)
 
 TEST (FlStringCodecTest, DecodeData)
 
 TEST (FlStringCodecTest, DecodeEmpty)
 
 TEST (FlStringCodecTest, EncodeDecode)
 

Function Documentation

◆ decode_message()

static FlValue* decode_message ( const char *  hex_string)
static

Definition at line 34 of file fl_string_codec_test.cc.

References error, fl_message_codec_decode_message(), fl_string_codec_new(), fl_value_ref(), hex_string_to_bytes(), and value.

Referenced by TEST().

34  {
35  g_autoptr(FlStringCodec) codec = fl_string_codec_new();
36  g_autoptr(GBytes) message = 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), message, &error);
40  EXPECT_EQ(error, nullptr);
41  EXPECT_NE(value, nullptr);
42  return fl_value_ref(value);
43 }
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new()
uint8_t value
GBytes * hex_string_to_bytes(const gchar *hex_string)
Definition: fl_test.cc:24
G_MODULE_EXPORT FlValue * fl_value_ref(FlValue *self)
Definition: fl_value.cc:335
G_MODULE_EXPORT FlValue * fl_message_codec_decode_message(FlMessageCodec *self, GBytes *message, GError **error)

◆ encode_message()

static gchar* encode_message ( FlValue value)
static

Definition at line 11 of file fl_string_codec_test.cc.

References bytes_to_hex_string(), error, fl_message_codec_encode_message(), and fl_string_codec_new().

Referenced by TEST().

11  {
12  g_autoptr(FlStringCodec) codec = fl_string_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 }
FlMethodResponse GError ** error
gchar * bytes_to_hex_string(GBytes *bytes)
Definition: fl_test.cc:33
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new()
uint8_t value
G_MODULE_EXPORT GBytes * fl_message_codec_encode_message(FlMessageCodec *self, FlValue *message, GError **error)

◆ encode_message_error()

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

Definition at line 23 of file fl_string_codec_test.cc.

References error, fl_message_codec_encode_message(), and fl_string_codec_new().

Referenced by TEST().

23  {
24  g_autoptr(FlStringCodec) codec = fl_string_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 }
FlMethodResponse GError ** error
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new()
uint8_t value
G_MODULE_EXPORT GBytes * fl_message_codec_encode_message(FlMessageCodec *self, FlValue *message, GError **error)

◆ TEST() [1/7]

TEST ( FlStringCodecTest  ,
EncodeData   
)

Definition at line 45 of file fl_string_codec_test.cc.

References encode_message(), fl_value_new_string(), and value.

45  {
46  g_autoptr(FlValue) value = fl_value_new_string("hello");
47  g_autofree gchar* hex_string = encode_message(value);
48  EXPECT_STREQ(hex_string, "68656c6c6f");
49 }
static gchar * encode_message(FlValue *value)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
uint8_t value
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247

◆ TEST() [2/7]

TEST ( FlStringCodecTest  ,
EncodeEmpty   
)

Definition at line 51 of file fl_string_codec_test.cc.

References encode_message(), fl_value_new_string(), and value.

51  {
52  g_autoptr(FlValue) value = fl_value_new_string("");
53  g_autofree gchar* hex_string = encode_message(value);
54  EXPECT_STREQ(hex_string, "");
55 }
static gchar * encode_message(FlValue *value)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
uint8_t value
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247

◆ TEST() [3/7]

TEST ( FlStringCodecTest  ,
EncodeNullptr   
)

Definition at line 57 of file fl_string_codec_test.cc.

References encode_message_error(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_UNSUPPORTED_TYPE.

57  {
60 }
#define FL_MESSAGE_CODEC_ERROR
static void encode_message_error(FlValue *value, GQuark domain, int code)

◆ TEST() [4/7]

TEST ( FlStringCodecTest  ,
EncodeUnknownType   
)

Definition at line 62 of file fl_string_codec_test.cc.

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

62  {
63  g_autoptr(FlValue) value = fl_value_new_null();
66 }
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
#define FL_MESSAGE_CODEC_ERROR
static void encode_message_error(FlValue *value, GQuark domain, int code)
uint8_t value
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:222

◆ TEST() [5/7]

TEST ( FlStringCodecTest  ,
DecodeData   
)

Definition at line 68 of file fl_string_codec_test.cc.

References decode_message(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_STRING, and value.

68  {
69  g_autoptr(FlValue) value = decode_message("68656c6c6f");
71  ASSERT_STREQ(fl_value_get_string(value), "hello");
72 }
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
uint8_t value
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:596
static FlValue * decode_message(const char *hex_string)

◆ TEST() [6/7]

TEST ( FlStringCodecTest  ,
DecodeEmpty   
)

Definition at line 74 of file fl_string_codec_test.cc.

References decode_message(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_STRING, and value.

74  {
75  g_autoptr(FlValue) value = decode_message("");
77  ASSERT_STREQ(fl_value_get_string(value), "");
78 }
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
Definition: fl_value.cc:395
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
uint8_t value
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:596
static FlValue * decode_message(const char *hex_string)

◆ TEST() [7/7]

TEST ( FlStringCodecTest  ,
EncodeDecode   
)

Definition at line 80 of file fl_string_codec_test.cc.

References error, fl_message_codec_decode_message(), fl_message_codec_encode_message(), fl_string_codec_new(), fl_value_equal(), and fl_value_new_string().

80  {
81  g_autoptr(FlStringCodec) codec = fl_string_codec_new();
82 
83  g_autoptr(FlValue) input = fl_value_new_string("hello");
84 
85  g_autoptr(GError) error = nullptr;
86  g_autoptr(GBytes) message =
87  fl_message_codec_encode_message(FL_MESSAGE_CODEC(codec), input, &error);
88  EXPECT_NE(message, nullptr);
89  EXPECT_EQ(error, nullptr);
90 
91  g_autoptr(FlValue) output =
92  fl_message_codec_decode_message(FL_MESSAGE_CODEC(codec), message, &error);
93  EXPECT_EQ(error, nullptr);
94  EXPECT_NE(output, nullptr);
95 
96  ASSERT_TRUE(fl_value_equal(input, output));
97 }
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
G_MODULE_EXPORT FlStringCodec * fl_string_codec_new()
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:400
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247
G_MODULE_EXPORT GBytes * fl_message_codec_encode_message(FlMessageCodec *self, FlValue *message, GError **error)
G_MODULE_EXPORT FlValue * fl_message_codec_decode_message(FlMessageCodec *self, GBytes *message, GError **error)