Flutter Engine
fl_standard_method_codec_test.cc File Reference
#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"
#include "flutter/shell/platform/linux/fl_method_codec_private.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_message_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_method_call (const gchar *name, FlValue *args)
 
static gchar * encode_success_envelope (FlValue *result)
 
static gchar * encode_error_envelope (const gchar *error_code, const gchar *error_message, FlValue *details)
 
static void decode_method_call (const char *hex_string, gchar **name, FlValue **args)
 
static void decode_error_method_call (const char *hex_string, GQuark domain, gint code)
 
static void decode_response_with_success (const char *hex_string, FlValue *result)
 
static void decode_response_with_error (const char *hex_string, const gchar *code, const gchar *error_message, FlValue *details)
 
static void decode_error_response (const char *hex_string, GQuark domain, gint code)
 
 TEST (FlStandardMethodCodecTest, EncodeMethodCallNullptrArgs)
 
 TEST (FlStandardMethodCodecTest, EncodeMethodCallNullArgs)
 
 TEST (FlStandardMethodCodecTest, EncodeMethodCallStringArgs)
 
 TEST (FlStandardMethodCodecTest, EncodeMethodCallListArgs)
 
 TEST (FlStandardMethodCodecTest, DecodeMethodCallNullArgs)
 
 TEST (FlStandardMethodCodecTest, DecodeMethodCallStringArgs)
 
 TEST (FlStandardMethodCodecTest, DecodeMethodCallListArgs)
 
 TEST (FlStandardMethodCodecTest, DecodeMethodCallNoData)
 
 TEST (FlStandardMethodCodecTest, DecodeMethodCallNullMethodName)
 
 TEST (FlStandardMethodCodecTest, DecodeMethodCallMissingArgs)
 
 TEST (FlStandardMethodCodecTest, EncodeSuccessEnvelopeNullptr)
 
 TEST (FlStandardMethodCodecTest, EncodeSuccessEnvelopeNull)
 
 TEST (FlStandardMethodCodecTest, EncodeSuccessEnvelopeString)
 
 TEST (FlStandardMethodCodecTest, EncodeSuccessEnvelopeList)
 
 TEST (FlStandardMethodCodecTest, EncodeErrorEnvelopeEmptyCode)
 
 TEST (FlStandardMethodCodecTest, EncodeErrorEnvelopeNonMessageOrDetails)
 
 TEST (FlStandardMethodCodecTest, EncodeErrorEnvelopeMessage)
 
 TEST (FlStandardMethodCodecTest, EncodeErrorEnvelopeDetails)
 
 TEST (FlStandardMethodCodecTest, EncodeErrorEnvelopeMessageAndDetails)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseSuccessNull)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseSuccessString)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseSuccessList)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorEmptyCode)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorNoMessageOrDetails)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorMessage)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorDetails)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorMessageAndDetails)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseSuccessNoData)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseSuccessExtraData)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorNoData)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorMissingMessageAndDetails)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorMissingDetails)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseErrorExtraData)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseNotImplemented)
 
 TEST (FlStandardMethodCodecTest, DecodeResponseUnknownEnvelope)
 

Function Documentation

◆ decode_error_method_call()

static void decode_error_method_call ( const char *  hex_string,
GQuark  domain,
gint  code 
)
static

Definition at line 67 of file fl_standard_method_codec_test.cc.

References error, fl_method_codec_decode_method_call(), fl_standard_method_codec_new(), hex_string_to_bytes(), and name.

Referenced by TEST().

69  {
70  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
71  g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
72  g_autoptr(GError) error = nullptr;
73  g_autofree gchar* name = nullptr;
74  g_autoptr(FlValue) args = nullptr;
75  gboolean result = fl_method_codec_decode_method_call(
76  FL_METHOD_CODEC(codec), message, &name, &args, &error);
77  EXPECT_FALSE(result);
78  EXPECT_EQ(name, nullptr);
79  EXPECT_EQ(args, nullptr);
80  EXPECT_TRUE(g_error_matches(error, domain, code));
81 }
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
FlMethodResponse GError ** error
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
GBytes * hex_string_to_bytes(const gchar *hex_string)
Definition: fl_test.cc:24
const char * name
Definition: fuchsia.cc:50
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)

◆ decode_error_response()

static void decode_error_response ( const char *  hex_string,
GQuark  domain,
gint  code 
)
static

Definition at line 137 of file fl_standard_method_codec_test.cc.

References error, fl_method_codec_decode_response(), fl_standard_method_codec_new(), and hex_string_to_bytes().

Referenced by TEST().

139  {
140  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
141  g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
142  g_autoptr(GError) error = nullptr;
143  g_autoptr(FlMethodResponse) response =
144  fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
145  EXPECT_EQ(response, nullptr);
146  EXPECT_TRUE(g_error_matches(error, domain, code));
147 }
FlMethodResponse GError ** error
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
GBytes * hex_string_to_bytes(const gchar *hex_string)
Definition: fl_test.cc:24

◆ decode_method_call()

static void decode_method_call ( const char *  hex_string,
gchar **  name,
FlValue **  args 
)
static

Definition at line 54 of file fl_standard_method_codec_test.cc.

References error, fl_method_codec_decode_method_call(), fl_standard_method_codec_new(), and hex_string_to_bytes().

Referenced by TEST().

56  {
57  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
58  g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
59  g_autoptr(GError) error = nullptr;
60  gboolean result = fl_method_codec_decode_method_call(
61  FL_METHOD_CODEC(codec), message, name, args, &error);
62  EXPECT_TRUE(result);
63  EXPECT_EQ(error, nullptr);
64 }
FlMethodResponse GError ** error
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
GBytes * hex_string_to_bytes(const gchar *hex_string)
Definition: fl_test.cc:24
const char * name
Definition: fuchsia.cc:50
gboolean fl_method_codec_decode_method_call(FlMethodCodec *self, GBytes *message, gchar **name, FlValue **args, GError **error)

◆ decode_response_with_error()

static void decode_response_with_error ( const char *  hex_string,
const gchar *  code,
const gchar *  error_message,
FlValue details 
)
static

Definition at line 102 of file fl_standard_method_codec_test.cc.

References error, fl_method_codec_decode_response(), fl_method_error_response_get_code(), fl_method_error_response_get_details(), fl_method_error_response_get_message(), fl_standard_method_codec_new(), fl_value_equal(), and hex_string_to_bytes().

Referenced by TEST().

105  {
106  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
107  g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
108  g_autoptr(GError) error = nullptr;
109  g_autoptr(FlMethodResponse) response =
110  fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
111  ASSERT_NE(response, nullptr);
112  EXPECT_EQ(error, nullptr);
113  EXPECT_TRUE(FL_IS_METHOD_ERROR_RESPONSE(response));
114  EXPECT_STREQ(
115  fl_method_error_response_get_code(FL_METHOD_ERROR_RESPONSE(response)),
116  code);
117  if (error_message == nullptr) {
119  FL_METHOD_ERROR_RESPONSE(response)),
120  nullptr);
121  } else {
123  FL_METHOD_ERROR_RESPONSE(response)),
124  error_message);
125  }
126  if (details == nullptr) {
128  FL_METHOD_ERROR_RESPONSE(response)),
129  nullptr);
130  } else {
132  FL_METHOD_ERROR_RESPONSE(response)),
133  details));
134  }
135 }
FlMethodResponse GError ** error
G_MODULE_EXPORT const gchar * fl_method_error_response_get_message(FlMethodErrorResponse *self)
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:400
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
GBytes * hex_string_to_bytes(const gchar *hex_string)
Definition: fl_test.cc:24
G_MODULE_EXPORT const gchar * fl_method_error_response_get_code(FlMethodErrorResponse *self)
G_MODULE_EXPORT FlValue * fl_method_error_response_get_details(FlMethodErrorResponse *self)

◆ decode_response_with_success()

static void decode_response_with_success ( const char *  hex_string,
FlValue result 
)
static

Definition at line 85 of file fl_standard_method_codec_test.cc.

References error, fl_method_codec_decode_response(), fl_method_success_response_get_result(), fl_standard_method_codec_new(), fl_value_equal(), and hex_string_to_bytes().

Referenced by TEST().

86  {
87  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
88  g_autoptr(GBytes) message = hex_string_to_bytes(hex_string);
89  g_autoptr(GError) error = nullptr;
90  g_autoptr(FlMethodResponse) response =
91  fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
92  ASSERT_NE(response, nullptr);
93  EXPECT_EQ(error, nullptr);
94  EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
96  FL_METHOD_SUCCESS_RESPONSE(response)),
97  result));
98 }
FlMethodResponse GError ** error
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *self)
G_MODULE_EXPORT bool fl_value_equal(FlValue *a, FlValue *b)
Definition: fl_value.cc:400
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)
GBytes * hex_string_to_bytes(const gchar *hex_string)
Definition: fl_test.cc:24

◆ encode_error_envelope()

static gchar* encode_error_envelope ( const gchar *  error_code,
const gchar *  error_message,
FlValue details 
)
static

Definition at line 40 of file fl_standard_method_codec_test.cc.

References bytes_to_hex_string(), error, fl_method_codec_encode_error_envelope(), and fl_standard_method_codec_new().

Referenced by TEST().

42  {
43  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
44  g_autoptr(GError) error = nullptr;
45  g_autoptr(GBytes) message = fl_method_codec_encode_error_envelope(
46  FL_METHOD_CODEC(codec), error_code, error_message, details, &error);
47  EXPECT_NE(message, nullptr);
48  EXPECT_EQ(error, nullptr);
49 
50  return bytes_to_hex_string(message);
51 }
FlMethodResponse GError ** error
gchar * bytes_to_hex_string(GBytes *bytes)
Definition: fl_test.cc:33
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
GBytes * fl_method_codec_encode_error_envelope(FlMethodCodec *self, const gchar *code, const gchar *message, FlValue *details, GError **error)

◆ encode_method_call()

static gchar* encode_method_call ( const gchar *  name,
FlValue args 
)
static

Definition at line 15 of file fl_standard_method_codec_test.cc.

References bytes_to_hex_string(), error, fl_method_codec_encode_method_call(), and fl_standard_method_codec_new().

Referenced by TEST().

15  {
16  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
17  g_autoptr(GError) error = nullptr;
18  g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
19  FL_METHOD_CODEC(codec), name, args, &error);
20  EXPECT_NE(message, nullptr);
21  EXPECT_EQ(error, nullptr);
22 
23  return bytes_to_hex_string(message);
24 }
GBytes * fl_method_codec_encode_method_call(FlMethodCodec *self, const gchar *name, FlValue *args, GError **error)
FlMethodResponse GError ** error
gchar * bytes_to_hex_string(GBytes *bytes)
Definition: fl_test.cc:33
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
const char * name
Definition: fuchsia.cc:50

◆ encode_success_envelope()

static gchar* encode_success_envelope ( FlValue result)
static

Definition at line 28 of file fl_standard_method_codec_test.cc.

References bytes_to_hex_string(), error, fl_method_codec_encode_success_envelope(), and fl_standard_method_codec_new().

Referenced by TEST().

28  {
29  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
30  g_autoptr(GError) error = nullptr;
31  g_autoptr(GBytes) message = fl_method_codec_encode_success_envelope(
32  FL_METHOD_CODEC(codec), result, &error);
33  EXPECT_NE(message, nullptr);
34  EXPECT_EQ(error, nullptr);
35 
36  return bytes_to_hex_string(message);
37 }
FlMethodResponse GError ** error
gchar * bytes_to_hex_string(GBytes *bytes)
Definition: fl_test.cc:33
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
GBytes * fl_method_codec_encode_success_envelope(FlMethodCodec *self, FlValue *result, GError **error)

◆ TEST() [1/35]

TEST ( FlStandardMethodCodecTest  ,
EncodeMethodCallNullptrArgs   
)

Definition at line 149 of file fl_standard_method_codec_test.cc.

References encode_method_call().

149  {
150  g_autofree gchar* hex_string = encode_method_call("hello", nullptr);
151  EXPECT_STREQ(hex_string, "070568656c6c6f00");
152 }
static gchar * encode_method_call(const gchar *name, FlValue *args)

◆ TEST() [2/35]

TEST ( FlStandardMethodCodecTest  ,
EncodeMethodCallNullArgs   
)

Definition at line 154 of file fl_standard_method_codec_test.cc.

References encode_method_call(), fl_value_new_null(), and value.

154  {
155  g_autoptr(FlValue) value = fl_value_new_null();
156  g_autofree gchar* hex_string = encode_method_call("hello", value);
157  EXPECT_STREQ(hex_string, "070568656c6c6f00");
158 }
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
uint8_t value
static gchar * encode_method_call(const gchar *name, FlValue *args)
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:222

◆ TEST() [3/35]

TEST ( FlStandardMethodCodecTest  ,
EncodeMethodCallStringArgs   
)

Definition at line 160 of file fl_standard_method_codec_test.cc.

References encode_method_call(), and fl_value_new_string().

160  {
161  g_autoptr(FlValue) args = fl_value_new_string("world");
162  g_autofree gchar* hex_string = encode_method_call("hello", args);
163  EXPECT_STREQ(hex_string, "070568656c6c6f0705776f726c64");
164 }
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
static gchar * encode_method_call(const gchar *name, FlValue *args)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247

◆ TEST() [4/35]

TEST ( FlStandardMethodCodecTest  ,
EncodeMethodCallListArgs   
)

Definition at line 166 of file fl_standard_method_codec_test.cc.

References encode_method_call(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), and fl_value_new_string().

166  {
167  g_autoptr(FlValue) args = fl_value_new_list();
170  g_autofree gchar* hex_string = encode_method_call("hello", args);
171  EXPECT_STREQ(hex_string, "070568656c6c6f0c020705636f756e74032a000000");
172 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:514
static gchar * encode_method_call(const gchar *name, FlValue *args)
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247

◆ TEST() [5/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeMethodCallNullArgs   
)

Definition at line 174 of file fl_standard_method_codec_test.cc.

References decode_method_call(), fl_value_get_type(), FL_VALUE_TYPE_NULL, and name.

174  {
175  g_autofree gchar* name = nullptr;
176  g_autoptr(FlValue) args = nullptr;
177  decode_method_call("070568656c6c6f00", &name, &args);
178  EXPECT_STREQ(name, "hello");
179  ASSERT_EQ(fl_value_get_type(args), FL_VALUE_TYPE_NULL);
180 }
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
static void decode_method_call(const char *hex_string, gchar **name, FlValue **args)
const char * name
Definition: fuchsia.cc:50

◆ TEST() [6/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeMethodCallStringArgs   
)

Definition at line 182 of file fl_standard_method_codec_test.cc.

References decode_method_call(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_STRING, and name.

182  {
183  g_autofree gchar* name = nullptr;
184  g_autoptr(FlValue) args = nullptr;
185  decode_method_call("070568656c6c6f0705776f726c64", &name, &args);
186  EXPECT_STREQ(name, "hello");
187  ASSERT_EQ(fl_value_get_type(args), FL_VALUE_TYPE_STRING);
188  EXPECT_STREQ(fl_value_get_string(args), "world");
189 }
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
static void decode_method_call(const char *hex_string, gchar **name, FlValue **args)
const char * name
Definition: fuchsia.cc:50
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:596

◆ TEST() [7/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeMethodCallListArgs   
)

Definition at line 191 of file fl_standard_method_codec_test.cc.

References decode_method_call(), fl_value_get_int(), fl_value_get_length(), fl_value_get_list_value(), fl_value_get_string(), fl_value_get_type(), FL_VALUE_TYPE_INT, FL_VALUE_TYPE_LIST, FL_VALUE_TYPE_STRING, and name.

191  {
192  g_autofree gchar* name = nullptr;
193  g_autoptr(FlValue) args = nullptr;
194  decode_method_call("070568656c6c6f0c020705636f756e74032a000000", &name,
195  &args);
196  EXPECT_STREQ(name, "hello");
197  ASSERT_EQ(fl_value_get_type(args), FL_VALUE_TYPE_LIST);
198  EXPECT_EQ(fl_value_get_length(args), static_cast<size_t>(2));
199 
200  FlValue* arg0 = fl_value_get_list_value(args, 0);
201  ASSERT_EQ(fl_value_get_type(arg0), FL_VALUE_TYPE_STRING);
202  EXPECT_STREQ(fl_value_get_string(arg0), "count");
203 
204  FlValue* arg1 = fl_value_get_list_value(args, 1);
205  ASSERT_EQ(fl_value_get_type(arg1), FL_VALUE_TYPE_INT);
206  EXPECT_EQ(fl_value_get_int(arg1), 42);
207 }
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
G_MODULE_EXPORT int64_t fl_value_get_int(FlValue *self)
Definition: fl_value.cc:582
static void decode_method_call(const char *hex_string, gchar **name, FlValue **args)
G_MODULE_EXPORT FlValue * fl_value_get_list_value(FlValue *self, size_t index)
Definition: fl_value.cc:677
const char * name
Definition: fuchsia.cc:50
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:596
G_MODULE_EXPORT size_t fl_value_get_length(FlValue *self)
Definition: fl_value.cc:631

◆ TEST() [8/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeMethodCallNoData   
)

Definition at line 209 of file fl_standard_method_codec_test.cc.

References decode_error_method_call(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA.

209  {
212 }
#define FL_MESSAGE_CODEC_ERROR
static void decode_error_method_call(const char *hex_string, GQuark domain, gint code)

◆ TEST() [9/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeMethodCallNullMethodName   
)

Definition at line 214 of file fl_standard_method_codec_test.cc.

References decode_error_method_call(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_FAILED.

214  {
217 }
#define FL_MESSAGE_CODEC_ERROR
static void decode_error_method_call(const char *hex_string, GQuark domain, gint code)

◆ TEST() [10/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeMethodCallMissingArgs   
)

Definition at line 219 of file fl_standard_method_codec_test.cc.

References decode_error_method_call(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA.

219  {
222 }
#define FL_MESSAGE_CODEC_ERROR
static void decode_error_method_call(const char *hex_string, GQuark domain, gint code)

◆ TEST() [11/35]

TEST ( FlStandardMethodCodecTest  ,
EncodeSuccessEnvelopeNullptr   
)

Definition at line 224 of file fl_standard_method_codec_test.cc.

References encode_success_envelope().

224  {
225  g_autofree gchar* hex_string = encode_success_envelope(nullptr);
226  EXPECT_STREQ(hex_string, "0000");
227 }
static gchar * encode_success_envelope(FlValue *result)

◆ TEST() [12/35]

TEST ( FlStandardMethodCodecTest  ,
EncodeSuccessEnvelopeNull   
)

Definition at line 229 of file fl_standard_method_codec_test.cc.

References encode_success_envelope(), and fl_value_new_null().

229  {
230  g_autoptr(FlValue) result = fl_value_new_null();
231  g_autofree gchar* hex_string = encode_success_envelope(result);
232  EXPECT_STREQ(hex_string, "0000");
233 }
static gchar * encode_success_envelope(FlValue *result)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:222

◆ TEST() [13/35]

TEST ( FlStandardMethodCodecTest  ,
EncodeSuccessEnvelopeString   
)

Definition at line 235 of file fl_standard_method_codec_test.cc.

References encode_success_envelope(), and fl_value_new_string().

235  {
236  g_autoptr(FlValue) result = fl_value_new_string("hello");
237  g_autofree gchar* hex_string = encode_success_envelope(result);
238  EXPECT_STREQ(hex_string, "00070568656c6c6f");
239 }
static gchar * encode_success_envelope(FlValue *result)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247

◆ TEST() [14/35]

TEST ( FlStandardMethodCodecTest  ,
EncodeSuccessEnvelopeList   
)

Definition at line 241 of file fl_standard_method_codec_test.cc.

References encode_success_envelope(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), and fl_value_new_string().

241  {
242  g_autoptr(FlValue) result = fl_value_new_list();
243  fl_value_append_take(result, fl_value_new_string("count"));
245  g_autofree gchar* hex_string = encode_success_envelope(result);
246  EXPECT_STREQ(hex_string, "000c020705636f756e74032a000000");
247 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
static gchar * encode_success_envelope(FlValue *result)
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:514
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247

◆ TEST() [15/35]

TEST ( FlStandardMethodCodecTest  ,
EncodeErrorEnvelopeEmptyCode   
)

Definition at line 249 of file fl_standard_method_codec_test.cc.

References encode_error_envelope().

249  {
250  g_autofree gchar* hex_string = encode_error_envelope("", nullptr, nullptr);
251  EXPECT_STREQ(hex_string, "0107000000");
252 }
static gchar * encode_error_envelope(const gchar *error_code, const gchar *error_message, FlValue *details)

◆ TEST() [16/35]

TEST ( FlStandardMethodCodecTest  ,
EncodeErrorEnvelopeNonMessageOrDetails   
)

Definition at line 254 of file fl_standard_method_codec_test.cc.

References encode_error_envelope().

254  {
255  g_autofree gchar* hex_string =
256  encode_error_envelope("error", nullptr, nullptr);
257  EXPECT_STREQ(hex_string, "0107056572726f720000");
258 }
static gchar * encode_error_envelope(const gchar *error_code, const gchar *error_message, FlValue *details)

◆ TEST() [17/35]

TEST ( FlStandardMethodCodecTest  ,
EncodeErrorEnvelopeMessage   
)

Definition at line 260 of file fl_standard_method_codec_test.cc.

References encode_error_envelope().

260  {
261  g_autofree gchar* hex_string =
262  encode_error_envelope("error", "message", nullptr);
263  EXPECT_STREQ(hex_string, "0107056572726f7207076d65737361676500");
264 }
static gchar * encode_error_envelope(const gchar *error_code, const gchar *error_message, FlValue *details)

◆ TEST() [18/35]

TEST ( FlStandardMethodCodecTest  ,
EncodeErrorEnvelopeDetails   
)

Definition at line 266 of file fl_standard_method_codec_test.cc.

References encode_error_envelope(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), and fl_value_new_string().

266  {
267  g_autoptr(FlValue) details = fl_value_new_list();
268  fl_value_append_take(details, fl_value_new_string("count"));
270  g_autofree gchar* hex_string =
271  encode_error_envelope("error", nullptr, details);
272  EXPECT_STREQ(hex_string, "0107056572726f72000c020705636f756e74032a000000");
273 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
static gchar * encode_error_envelope(const gchar *error_code, const gchar *error_message, FlValue *details)
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:514
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247

◆ TEST() [19/35]

TEST ( FlStandardMethodCodecTest  ,
EncodeErrorEnvelopeMessageAndDetails   
)

Definition at line 275 of file fl_standard_method_codec_test.cc.

References encode_error_envelope(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), and fl_value_new_string().

275  {
276  g_autoptr(FlValue) details = fl_value_new_list();
277  fl_value_append_take(details, fl_value_new_string("count"));
279  g_autofree gchar* hex_string =
280  encode_error_envelope("error", "message", details);
281  EXPECT_STREQ(
282  hex_string,
283  "0107056572726f7207076d6573736167650c020705636f756e74032a000000");
284 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
static gchar * encode_error_envelope(const gchar *error_code, const gchar *error_message, FlValue *details)
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:514
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247

◆ TEST() [20/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseSuccessNull   
)

Definition at line 286 of file fl_standard_method_codec_test.cc.

References decode_response_with_success(), and fl_value_new_null().

286  {
287  g_autoptr(FlValue) result = fl_value_new_null();
288  decode_response_with_success("0000", result);
289 }
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
static void decode_response_with_success(const char *hex_string, FlValue *result)
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition: fl_value.cc:222

◆ TEST() [21/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseSuccessString   
)

Definition at line 291 of file fl_standard_method_codec_test.cc.

References decode_response_with_success(), and fl_value_new_string().

291  {
292  g_autoptr(FlValue) result = fl_value_new_string("hello");
293  decode_response_with_success("00070568656c6c6f", result);
294 }
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
static void decode_response_with_success(const char *hex_string, FlValue *result)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247

◆ TEST() [22/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseSuccessList   
)

Definition at line 296 of file fl_standard_method_codec_test.cc.

References decode_response_with_success(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), and fl_value_new_string().

296  {
297  g_autoptr(FlValue) result = fl_value_new_list();
298  fl_value_append_take(result, fl_value_new_string("count"));
300  decode_response_with_success("000c020705636f756e74032a000000", result);
301 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:514
static void decode_response_with_success(const char *hex_string, FlValue *result)
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247

◆ TEST() [23/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorEmptyCode   
)

Definition at line 303 of file fl_standard_method_codec_test.cc.

References decode_response_with_error().

303  {
304  decode_response_with_error("0107000000", "", nullptr, nullptr);
305 }
static void decode_response_with_error(const char *hex_string, const gchar *code, const gchar *error_message, FlValue *details)

◆ TEST() [24/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorNoMessageOrDetails   
)

Definition at line 307 of file fl_standard_method_codec_test.cc.

References decode_response_with_error().

307  {
308  decode_response_with_error("0107056572726f720000", "error", nullptr, nullptr);
309 }
static void decode_response_with_error(const char *hex_string, const gchar *code, const gchar *error_message, FlValue *details)

◆ TEST() [25/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorMessage   
)

Definition at line 311 of file fl_standard_method_codec_test.cc.

References decode_response_with_error().

311  {
312  decode_response_with_error("0107056572726f7207076d65737361676500", "error",
313  "message", nullptr);
314 }
static void decode_response_with_error(const char *hex_string, const gchar *code, const gchar *error_message, FlValue *details)

◆ TEST() [26/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorDetails   
)

Definition at line 316 of file fl_standard_method_codec_test.cc.

References decode_response_with_error(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), and fl_value_new_string().

316  {
317  g_autoptr(FlValue) details = fl_value_new_list();
318  fl_value_append_take(details, fl_value_new_string("count"));
320  decode_response_with_error("0107056572726f72000c020705636f756e74032a000000",
321  "error", nullptr, details);
322 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:514
static void decode_response_with_error(const char *hex_string, const gchar *code, const gchar *error_message, FlValue *details)
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247

◆ TEST() [27/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorMessageAndDetails   
)

Definition at line 324 of file fl_standard_method_codec_test.cc.

References decode_response_with_error(), fl_value_append_take(), fl_value_new_int(), fl_value_new_list(), and fl_value_new_string().

324  {
325  g_autoptr(FlValue) details = fl_value_new_list();
326  fl_value_append_take(details, fl_value_new_string("count"));
329  "0107056572726f7207076d6573736167650c020705636f756e74032a000000", "error",
330  "message", details);
331 }
G_MODULE_EXPORT FlValue * fl_value_new_list()
Definition: fl_value.cc:310
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:39
G_MODULE_EXPORT void fl_value_append_take(FlValue *self, FlValue *value)
Definition: fl_value.cc:514
static void decode_response_with_error(const char *hex_string, const gchar *code, const gchar *error_message, FlValue *details)
G_MODULE_EXPORT FlValue * fl_value_new_int(int64_t value)
Definition: fl_value.cc:233
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:247

◆ TEST() [28/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseSuccessNoData   
)

Definition at line 333 of file fl_standard_method_codec_test.cc.

References decode_error_response(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA.

333  {
336 }
#define FL_MESSAGE_CODEC_ERROR
static void decode_error_response(const char *hex_string, GQuark domain, gint code)

◆ TEST() [29/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseSuccessExtraData   
)

Definition at line 338 of file fl_standard_method_codec_test.cc.

References decode_error_response(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_FAILED.

338  {
341 }
#define FL_MESSAGE_CODEC_ERROR
static void decode_error_response(const char *hex_string, GQuark domain, gint code)

◆ TEST() [30/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorNoData   
)

Definition at line 343 of file fl_standard_method_codec_test.cc.

References decode_error_response(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA.

343  {
346 }
#define FL_MESSAGE_CODEC_ERROR
static void decode_error_response(const char *hex_string, GQuark domain, gint code)

◆ TEST() [31/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorMissingMessageAndDetails   
)

Definition at line 348 of file fl_standard_method_codec_test.cc.

References decode_error_response(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA.

348  {
349  decode_error_response("0107056572726f72", FL_MESSAGE_CODEC_ERROR,
351 }
#define FL_MESSAGE_CODEC_ERROR
static void decode_error_response(const char *hex_string, GQuark domain, gint code)

◆ TEST() [32/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorMissingDetails   
)

Definition at line 353 of file fl_standard_method_codec_test.cc.

References decode_error_response(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA.

353  {
354  decode_error_response("0107056572726f7200", FL_MESSAGE_CODEC_ERROR,
356 }
#define FL_MESSAGE_CODEC_ERROR
static void decode_error_response(const char *hex_string, GQuark domain, gint code)

◆ TEST() [33/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseErrorExtraData   
)

Definition at line 358 of file fl_standard_method_codec_test.cc.

References decode_error_response(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_FAILED.

358  {
359  decode_error_response("0107056572726f72000000", FL_MESSAGE_CODEC_ERROR,
361 }
#define FL_MESSAGE_CODEC_ERROR
static void decode_error_response(const char *hex_string, GQuark domain, gint code)

◆ TEST() [34/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseNotImplemented   
)

Definition at line 363 of file fl_standard_method_codec_test.cc.

References error, fl_method_codec_decode_response(), and fl_standard_method_codec_new().

363  {
364  g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
365  g_autoptr(GBytes) message = g_bytes_new(nullptr, 0);
366  g_autoptr(GError) error = nullptr;
367  g_autoptr(FlMethodResponse) response =
368  fl_method_codec_decode_response(FL_METHOD_CODEC(codec), message, &error);
369  ASSERT_NE(response, nullptr);
370  EXPECT_EQ(error, nullptr);
371  EXPECT_TRUE(FL_IS_METHOD_NOT_IMPLEMENTED_RESPONSE(response));
372 }
FlMethodResponse GError ** error
G_MODULE_EXPORT FlStandardMethodCodec * fl_standard_method_codec_new()
FlMethodResponse * fl_method_codec_decode_response(FlMethodCodec *self, GBytes *message, GError **error)

◆ TEST() [35/35]

TEST ( FlStandardMethodCodecTest  ,
DecodeResponseUnknownEnvelope   
)

Definition at line 374 of file fl_standard_method_codec_test.cc.

References decode_error_response(), FL_MESSAGE_CODEC_ERROR, and FL_MESSAGE_CODEC_ERROR_FAILED.

374  {
377 }
#define FL_MESSAGE_CODEC_ERROR
static void decode_error_response(const char *hex_string, GQuark domain, gint code)