Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_43355755
engine
提交
cf0e272e
E
engine
项目概览
weixin_43355755
/
engine
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
engine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
cf0e272e
编写于
6月 03, 2020
作者:
R
Robert Ancell
提交者:
GitHub
6月 03, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add missing standard codec alignment bytes (#18724)
上级
1b4d958f
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
110 addition
and
71 deletion
+110
-71
shell/platform/linux/fl_standard_message_codec.cc
shell/platform/linux/fl_standard_message_codec.cc
+34
-0
shell/platform/linux/fl_standard_message_codec_test.cc
shell/platform/linux/fl_standard_message_codec_test.cc
+76
-71
未找到文件。
shell/platform/linux/fl_standard_message_codec.cc
浏览文件 @
cf0e272e
...
...
@@ -64,6 +64,12 @@ static void write_float64(GByteArray* buffer, double value) {
sizeof
(
double
));
}
// Write padding bytes to align to @align multiple of bytes.
static
void
write_align
(
GByteArray
*
buffer
,
guint
align
)
{
while
(
buffer
->
len
%
align
!=
0
)
write_uint8
(
buffer
,
0
);
}
// Checks there is enough data in @buffer to be read.
static
gboolean
check_size
(
GBytes
*
buffer
,
size_t
offset
,
...
...
@@ -77,6 +83,22 @@ static gboolean check_size(GBytes* buffer,
return
TRUE
;
}
// Skip bytes to align next read on @align multiple of bytes.
static
gboolean
read_align
(
GBytes
*
buffer
,
size_t
*
offset
,
size_t
align
,
GError
**
error
)
{
if
((
*
offset
)
%
align
==
0
)
return
TRUE
;
size_t
required
=
align
-
(
*
offset
)
%
align
;
if
(
!
check_size
(
buffer
,
*
offset
,
required
,
error
))
return
FALSE
;
(
*
offset
)
+=
required
;
return
TRUE
;
}
// Gets a pointer to the given offset in @buffer.
static
const
uint8_t
*
get_data
(
GBytes
*
buffer
,
size_t
*
offset
)
{
return
static_cast
<
const
uint8_t
*>
(
g_bytes_get_data
(
buffer
,
nullptr
))
+
...
...
@@ -161,6 +183,8 @@ static FlValue* read_int64_value(GBytes* buffer,
static
FlValue
*
read_float64_value
(
GBytes
*
buffer
,
size_t
*
offset
,
GError
**
error
)
{
if
(
!
read_align
(
buffer
,
offset
,
8
,
error
))
return
nullptr
;
if
(
!
check_size
(
buffer
,
*
offset
,
sizeof
(
double
),
error
))
return
nullptr
;
...
...
@@ -218,6 +242,8 @@ static FlValue* read_int32_list_value(FlStandardMessageCodec* self,
if
(
!
fl_standard_message_codec_read_size
(
self
,
buffer
,
offset
,
&
length
,
error
))
return
nullptr
;
if
(
!
read_align
(
buffer
,
offset
,
4
,
error
))
return
nullptr
;
if
(
!
check_size
(
buffer
,
*
offset
,
sizeof
(
int32_t
)
*
length
,
error
))
return
nullptr
;
FlValue
*
value
=
fl_value_new_int32_list
(
...
...
@@ -237,6 +263,8 @@ static FlValue* read_int64_list_value(FlStandardMessageCodec* self,
if
(
!
fl_standard_message_codec_read_size
(
self
,
buffer
,
offset
,
&
length
,
error
))
return
nullptr
;
if
(
!
read_align
(
buffer
,
offset
,
8
,
error
))
return
nullptr
;
if
(
!
check_size
(
buffer
,
*
offset
,
sizeof
(
int64_t
)
*
length
,
error
))
return
nullptr
;
FlValue
*
value
=
fl_value_new_int64_list
(
...
...
@@ -256,6 +284,8 @@ static FlValue* read_float64_list_value(FlStandardMessageCodec* self,
if
(
!
fl_standard_message_codec_read_size
(
self
,
buffer
,
offset
,
&
length
,
error
))
return
nullptr
;
if
(
!
read_align
(
buffer
,
offset
,
8
,
error
))
return
nullptr
;
if
(
!
check_size
(
buffer
,
*
offset
,
sizeof
(
double
)
*
length
,
error
))
return
nullptr
;
FlValue
*
value
=
fl_value_new_float_list
(
...
...
@@ -438,6 +468,7 @@ gboolean fl_standard_message_codec_write_value(FlStandardMessageCodec* self,
}
case
FL_VALUE_TYPE_FLOAT
:
write_uint8
(
buffer
,
kValueFloat64
);
write_align
(
buffer
,
8
);
write_float64
(
buffer
,
fl_value_get_float
(
value
));
return
TRUE
;
case
FL_VALUE_TYPE_STRING
:
{
...
...
@@ -461,6 +492,7 @@ gboolean fl_standard_message_codec_write_value(FlStandardMessageCodec* self,
write_uint8
(
buffer
,
kValueInt32List
);
size_t
length
=
fl_value_get_length
(
value
);
fl_standard_message_codec_write_size
(
self
,
buffer
,
length
);
write_align
(
buffer
,
4
);
g_byte_array_append
(
buffer
,
reinterpret_cast
<
const
uint8_t
*>
(
fl_value_get_int32_list
(
value
)),
...
...
@@ -471,6 +503,7 @@ gboolean fl_standard_message_codec_write_value(FlStandardMessageCodec* self,
write_uint8
(
buffer
,
kValueInt64List
);
size_t
length
=
fl_value_get_length
(
value
);
fl_standard_message_codec_write_size
(
self
,
buffer
,
length
);
write_align
(
buffer
,
8
);
g_byte_array_append
(
buffer
,
reinterpret_cast
<
const
uint8_t
*>
(
fl_value_get_int64_list
(
value
)),
...
...
@@ -481,6 +514,7 @@ gboolean fl_standard_message_codec_write_value(FlStandardMessageCodec* self,
write_uint8
(
buffer
,
kValueFloat64List
);
size_t
length
=
fl_value_get_length
(
value
);
fl_standard_message_codec_write_size
(
self
,
buffer
,
length
);
write_align
(
buffer
,
8
);
g_byte_array_append
(
buffer
,
reinterpret_cast
<
const
uint8_t
*>
(
fl_value_get_float_list
(
value
)),
...
...
shell/platform/linux/fl_standard_message_codec_test.cc
浏览文件 @
cf0e272e
...
...
@@ -205,104 +205,104 @@ static gchar* encode_float(double value) {
TEST
(
FlStandardMessageCodecTest
,
EncodeFloatZero
)
{
g_autofree
gchar
*
hex_string
=
encode_float
(
0
);
EXPECT_STREQ
(
hex_string
,
"060000000000000000"
);
EXPECT_STREQ
(
hex_string
,
"060000000000000000
00000000000000
"
);
}
TEST
(
FlStandardMessageCodecTest
,
EncodeFloatOne
)
{
g_autofree
gchar
*
hex_string
=
encode_float
(
1
);
EXPECT_STREQ
(
hex_string
,
"06000000000000f03f"
);
EXPECT_STREQ
(
hex_string
,
"06000000000000
00000000000000
f03f"
);
}
TEST
(
FlStandardMessageCodecTest
,
EncodeFloatMinusOne
)
{
g_autofree
gchar
*
hex_string
=
encode_float
(
-
1
);
EXPECT_STREQ
(
hex_string
,
"06000000000000f0bf"
);
EXPECT_STREQ
(
hex_string
,
"06000000000000
00000000000000
f0bf"
);
}
TEST
(
FlStandardMessageCodecTest
,
EncodeFloatHalf
)
{
g_autofree
gchar
*
hex_string
=
encode_float
(
0.5
);
EXPECT_STREQ
(
hex_string
,
"06000000000000e03f"
);
EXPECT_STREQ
(
hex_string
,
"06000000000000
00000000000000
e03f"
);
}
TEST
(
FlStandardMessageCodecTest
,
EncodeFloatFraction
)
{
g_autofree
gchar
*
hex_string
=
encode_float
(
M_PI
);
EXPECT_STREQ
(
hex_string
,
"06182d4454fb210940"
);
EXPECT_STREQ
(
hex_string
,
"06
00000000000000
182d4454fb210940"
);
}
TEST
(
FlStandardMessageCodecTest
,
EncodeFloatMinusZero
)
{
g_autofree
gchar
*
hex_string
=
encode_float
(
-
0.0
);
EXPECT_STREQ
(
hex_string
,
"060000000000000080"
);
EXPECT_STREQ
(
hex_string
,
"0600000000000000
00000000000000
80"
);
}
TEST
(
FlStandardMessageCodecTest
,
EncodeFloatNaN
)
{
g_autofree
gchar
*
hex_string
=
encode_float
(
NAN
);
EXPECT_STREQ
(
hex_string
,
"06000000000000f87f"
);
EXPECT_STREQ
(
hex_string
,
"06000000000000
00000000000000
f87f"
);
}
TEST
(
FlStandardMessageCodecTest
,
EncodeFloatInfinity
)
{
g_autofree
gchar
*
hex_string
=
encode_float
(
INFINITY
);
EXPECT_STREQ
(
hex_string
,
"06000000000000f07f"
);
EXPECT_STREQ
(
hex_string
,
"06000000000000
00000000000000
f07f"
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatZero
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"060000000000000000"
);
g_autoptr
(
FlValue
)
value
=
decode_message
(
"060000000000000000
00000000000000
"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_FLOAT
);
EXPECT_EQ
(
fl_value_get_float
(
value
),
0.0
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatOne
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"06000000000000f03f"
);
g_autoptr
(
FlValue
)
value
=
decode_message
(
"06000000000000
00000000000000
f03f"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_FLOAT
);
EXPECT_EQ
(
fl_value_get_float
(
value
),
1.0
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatMinusOne
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"06000000000000f0bf"
);
g_autoptr
(
FlValue
)
value
=
decode_message
(
"06000000000000
00000000000000
f0bf"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_FLOAT
);
EXPECT_EQ
(
fl_value_get_float
(
value
),
-
1.0
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatHalf
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"06000000000000e03f"
);
g_autoptr
(
FlValue
)
value
=
decode_message
(
"06000000000000
00000000000000
e03f"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_FLOAT
);
EXPECT_EQ
(
fl_value_get_float
(
value
),
0.5
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatPi
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"06182d4454fb210940"
);
g_autoptr
(
FlValue
)
value
=
decode_message
(
"06
00000000000000
182d4454fb210940"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_FLOAT
);
EXPECT_EQ
(
fl_value_get_float
(
value
),
M_PI
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatMinusZero
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"060000000000000080"
);
g_autoptr
(
FlValue
)
value
=
decode_message
(
"0600000000000000
00000000000000
80"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_FLOAT
);
EXPECT_EQ
(
fl_value_get_float
(
value
),
-
0.0
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatNaN
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"06000000000000f87f"
);
g_autoptr
(
FlValue
)
value
=
decode_message
(
"06000000000000
00000000000000
f87f"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_FLOAT
);
EXPECT_TRUE
(
isnan
(
fl_value_get_float
(
value
)));
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatInfinity
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"06000000000000f07f"
);
g_autoptr
(
FlValue
)
value
=
decode_message
(
"06000000000000
00000000000000
f07f"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_FLOAT
);
EXPECT_TRUE
(
isinf
(
fl_value_get_float
(
value
)));
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatNoData
)
{
decode_error_value
(
"0600"
,
FL_MESSAGE_CODEC_ERROR
,
decode_error_value
(
"0600
00000000000000
"
,
FL_MESSAGE_CODEC_ERROR
,
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatShortData1
)
{
decode_error_value
(
"0600"
,
FL_MESSAGE_CODEC_ERROR
,
decode_error_value
(
"0600
00000000000000
"
,
FL_MESSAGE_CODEC_ERROR
,
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatShortData2
)
{
decode_error_value
(
"0600000000000000"
,
FL_MESSAGE_CODEC_ERROR
,
decode_error_value
(
"0600000000000000
00000000000000
"
,
FL_MESSAGE_CODEC_ERROR
,
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
);
}
...
...
@@ -419,25 +419,25 @@ TEST(FlStandardMessageCodecTest, DecodeUint8ListShortData2) {
TEST
(
FlStandardMessageCodecTest
,
EncodeInt32ListEmpty
)
{
g_autoptr
(
FlValue
)
value
=
fl_value_new_int32_list
(
nullptr
,
0
);
g_autofree
gchar
*
hex_string
=
encode_message
(
value
);
EXPECT_STREQ
(
hex_string
,
"0900"
);
EXPECT_STREQ
(
hex_string
,
"0900
0000
"
);
}
TEST
(
FlStandardMessageCodecTest
,
EncodeInt32List
)
{
int32_t
data
[]
=
{
0
,
-
1
,
2
,
-
3
,
4
};
g_autoptr
(
FlValue
)
value
=
fl_value_new_int32_list
(
data
,
5
);
g_autofree
gchar
*
hex_string
=
encode_message
(
value
);
EXPECT_STREQ
(
hex_string
,
"090500000000ffffffff02000000fdffffff04000000"
);
EXPECT_STREQ
(
hex_string
,
"090500000000
0000
ffffffff02000000fdffffff04000000"
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeInt32ListEmpty
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"0900"
);
g_autoptr
(
FlValue
)
value
=
decode_message
(
"0900
0000
"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_INT32_LIST
);
EXPECT_EQ
(
fl_value_get_length
(
value
),
static_cast
<
size_t
>
(
0
));
}
TEST
(
FlStandardMessageCodecTest
,
DecodeInt32List
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"090500000000ffffffff02000000fdffffff04000000"
);
decode_message
(
"090500000000
0000
ffffffff02000000fdffffff04000000"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_INT32_LIST
);
const
int32_t
*
data
=
fl_value_get_int32_list
(
value
);
EXPECT_EQ
(
data
[
0
],
0
);
...
...
@@ -453,12 +453,12 @@ TEST(FlStandardMessageCodecTest, DecodeInt32ListNoData) {
}
TEST
(
FlStandardMessageCodecTest
,
DecodeInt32ListLengthNoData
)
{
decode_error_value
(
"0905"
,
FL_MESSAGE_CODEC_ERROR
,
decode_error_value
(
"0905
0000
"
,
FL_MESSAGE_CODEC_ERROR
,
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeInt32ListShortData1
)
{
decode_error_value
(
"090500"
,
FL_MESSAGE_CODEC_ERROR
,
decode_error_value
(
"090500
0000
"
,
FL_MESSAGE_CODEC_ERROR
,
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
);
}
...
...
@@ -471,27 +471,28 @@ TEST(FlStandardMessageCodecTest, DecodeInt32ListShortData2) {
TEST
(
FlStandardMessageCodecTest
,
EncodeInt64ListEmpty
)
{
g_autoptr
(
FlValue
)
value
=
fl_value_new_int64_list
(
nullptr
,
0
);
g_autofree
gchar
*
hex_string
=
encode_message
(
value
);
EXPECT_STREQ
(
hex_string
,
"0a00"
);
EXPECT_STREQ
(
hex_string
,
"0a00
000000000000
"
);
}
TEST
(
FlStandardMessageCodecTest
,
EncodeInt64List
)
{
int64_t
data
[]
=
{
0
,
-
1
,
2
,
-
3
,
4
};
g_autoptr
(
FlValue
)
value
=
fl_value_new_int64_list
(
data
,
5
);
g_autofree
gchar
*
hex_string
=
encode_message
(
value
);
EXPECT_STREQ
(
hex_string
,
"0a050000000000000000ffffffffffffffff0200000000000000fdffffff"
"ffffffff0400000000000000"
);
EXPECT_STREQ
(
hex_string
,
"0a050000000000000000000000000000ffffffffffffffff0200000000000000fdffffff"
"ffffffff0400000000000000"
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeInt64ListEmpty
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"0a00"
);
g_autoptr
(
FlValue
)
value
=
decode_message
(
"0a00
000000000000
"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_INT64_LIST
);
EXPECT_EQ
(
fl_value_get_length
(
value
),
static_cast
<
size_t
>
(
0
));
}
TEST
(
FlStandardMessageCodecTest
,
DecodeInt64List
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"0a050000000000000000ffffffffffffffff0200000000000000fdffffff"
"0a050000000000000000
000000000000
ffffffffffffffff0200000000000000fdffffff"
"ffffffff0400000000000000"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_INT64_LIST
);
const
int64_t
*
data
=
fl_value_get_int64_list
(
value
);
...
...
@@ -508,18 +509,19 @@ TEST(FlStandardMessageCodecTest, DecodeInt64ListNoData) {
}
TEST
(
FlStandardMessageCodecTest
,
DecodeInt64ListLengthNoData
)
{
decode_error_value
(
"0a05"
,
FL_MESSAGE_CODEC_ERROR
,
decode_error_value
(
"0a05
000000000000
"
,
FL_MESSAGE_CODEC_ERROR
,
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeInt64ListShortData1
)
{
decode_error_value
(
"0a0500"
,
FL_MESSAGE_CODEC_ERROR
,
decode_error_value
(
"0a0500
000000000000
"
,
FL_MESSAGE_CODEC_ERROR
,
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeInt64ListShortData2
)
{
decode_error_value
(
"0a050000000000000000ffffffffffffffff0200000000000000fdffffffffffffff0400"
"0a050000000000000000000000000000ffffffffffffffff0200000000000000fdffffff"
"ffffffff0400"
"0000000000"
,
FL_MESSAGE_CODEC_ERROR
,
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
);
}
...
...
@@ -527,27 +529,28 @@ TEST(FlStandardMessageCodecTest, DecodeInt64ListShortData2) {
TEST
(
FlStandardMessageCodecTest
,
EncodeFloatListEmpty
)
{
g_autoptr
(
FlValue
)
value
=
fl_value_new_float_list
(
nullptr
,
0
);
g_autofree
gchar
*
hex_string
=
encode_message
(
value
);
EXPECT_STREQ
(
hex_string
,
"0b00"
);
EXPECT_STREQ
(
hex_string
,
"0b00
000000000000
"
);
}
TEST
(
FlStandardMessageCodecTest
,
EncodeFloatList
)
{
double
data
[]
=
{
0
,
-
0.5
,
0.25
,
-
0.125
,
0.00625
};
g_autoptr
(
FlValue
)
value
=
fl_value_new_float_list
(
data
,
5
);
g_autofree
gchar
*
hex_string
=
encode_message
(
value
);
EXPECT_STREQ
(
hex_string
,
"0b050000000000000000000000000000e0bf000000000000d03f00000000"
"0000c0bf9a9999999999793f"
);
EXPECT_STREQ
(
hex_string
,
"0b050000000000000000000000000000000000000000e0bf000000000000d03f00000000"
"0000c0bf9a9999999999793f"
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatListEmpty
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"0b00"
);
g_autoptr
(
FlValue
)
value
=
decode_message
(
"0b00
000000000000
"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_FLOAT_LIST
);
EXPECT_EQ
(
fl_value_get_length
(
value
),
static_cast
<
size_t
>
(
0
));
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatList
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"0b050000000000000000000000000000e0bf000000000000d03f00000000"
"0b050000000000000000000000000000
000000000000
e0bf000000000000d03f00000000"
"0000c0bf9a9999999999793f"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_FLOAT_LIST
);
const
double
*
data
=
fl_value_get_float_list
(
value
);
...
...
@@ -564,18 +567,19 @@ TEST(FlStandardMessageCodecTest, DecodeFloatListNoData) {
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatListLengthNoData
)
{
decode_error_value
(
"0b05"
,
FL_MESSAGE_CODEC_ERROR
,
decode_error_value
(
"0b05
000000000000
"
,
FL_MESSAGE_CODEC_ERROR
,
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatListShortData1
)
{
decode_error_value
(
"0b0500"
,
FL_MESSAGE_CODEC_ERROR
,
decode_error_value
(
"0b0500
000000000000
"
,
FL_MESSAGE_CODEC_ERROR
,
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeFloatListShortData2
)
{
decode_error_value
(
"0b050000000000000000000000000000e0bf000000000000d03f000000000000c0bf9a99"
"0b050000000000000000000000000000000000000000e0bf000000000000d03f00000000"
"0000c0bf9a99"
"9999999979"
,
FL_MESSAGE_CODEC_ERROR
,
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
);
}
...
...
@@ -596,8 +600,9 @@ TEST(FlStandardMessageCodecTest, EncodeListTypes) {
fl_value_append_take
(
value
,
fl_value_new_list
());
fl_value_append_take
(
value
,
fl_value_new_map
());
g_autofree
gchar
*
hex_string
=
encode_message
(
value
);
EXPECT_STREQ
(
hex_string
,
"0c070001032a00000006182d4454fb210940070568656c6c6f0c000d00"
);
EXPECT_STREQ
(
hex_string
,
"0c070001032a00000006000000000000182d4454fb210940070568656c6c6f0c000d00"
);
}
TEST
(
FlStandardMessageCodecTest
,
EncodeListNested
)
{
...
...
@@ -626,7 +631,7 @@ TEST(FlStandardMessageCodecTest, DecodeListEmpty) {
TEST
(
FlStandardMessageCodecTest
,
DecodeListTypes
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"0c070001032a00000006182d4454fb210940070568656c6c6f0c000d00"
);
"0c070001032a00000006
000000000000
182d4454fb210940070568656c6c6f0c000d00"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_LIST
);
ASSERT_EQ
(
fl_value_get_length
(
value
),
static_cast
<
size_t
>
(
7
));
ASSERT_EQ
(
fl_value_get_type
(
fl_value_get_list_value
(
value
,
0
)),
...
...
@@ -692,9 +697,9 @@ TEST(FlStandardMessageCodecTest, DecodeListShortData1) {
}
TEST
(
FlStandardMessageCodecTest
,
DecodeListShortData2
)
{
decode_error_value
(
"0c070001032a00000006000000000000f8bf070568656c6c6f0c000d"
,
FL_MESSAGE_CODEC_ERROR
,
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
);
decode_error_value
(
"0c070001032a00000006000000000000182d4454fb210940070568656c6c6f0c000d"
,
FL_MESSAGE_CODEC_ERROR
,
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
);
}
TEST
(
FlStandardMessageCodecTest
,
EncodeDecodeLargeList
)
{
...
...
@@ -738,9 +743,9 @@ TEST(FlStandardMessageCodecTest, EncodeMapKeyTypes) {
fl_value_set_take
(
value
,
fl_value_new_map
(),
fl_value_new_string
(
"map"
));
g_autofree
gchar
*
hex_string
=
encode_message
(
value
);
EXPECT_STREQ
(
hex_string
,
"0d070007046e756c6c010704626f6f6c032a0000000703696e7406
182d4454f
"
"
b2109400705666c6f6174070568656c6c6f0706737472696e670c0007046c69
"
"73740d0007036d6170"
);
"0d070007046e756c6c010704626f6f6c032a0000000703696e7406
000000000
"
"
0182d4454fb2109400705666c6f6174070568656c6c6f0706737472696e670c
"
"
0007046c69
73740d0007036d6170"
);
}
TEST
(
FlStandardMessageCodecTest
,
EncodeMapValueTypes
)
{
...
...
@@ -758,8 +763,8 @@ TEST(FlStandardMessageCodecTest, EncodeMapValueTypes) {
g_autofree
gchar
*
hex_string
=
encode_message
(
value
);
EXPECT_STREQ
(
hex_string
,
"0d0707046e756c6c000704626f6f6c010703696e74032a0000000705666c6f6"
"17406
182d4454fb2109400706737472696e67070568656c6c6f07046c697374
"
"0c0007036d61700d00"
);
"17406
000000000000182d4454fb2109400706737472696e67070568656c6c6f
"
"0
7046c6973740
c0007036d61700d00"
);
}
TEST
(
FlStandardMessageCodecTest
,
EncodeMapNested
)
{
...
...
@@ -777,10 +782,10 @@ TEST(FlStandardMessageCodecTest, EncodeMapNested) {
fl_value_set_string
(
value
,
"int-to-str"
,
int_to_str
);
g_autofree
gchar
*
hex_string
=
encode_message
(
value
);
EXPECT_STREQ
(
hex_string
,
"0d02070a7374722d746f2d696e740d0407047a65726f030000000007036f"
"
6e650301000000070374776f030200000007057468726565030300000007
"
"
0a696e742d746f2d7374720d04030000000007047a65726f030100000007
"
"
036f6e650
302000000070374776f030300000007057468726565"
);
"0d02070a7374722d746f2d696e740d0407047a65726f030000000007036f
6e6
"
"
50301000000070374776f0302000000070574687265650303000000070a696e
"
"
742d746f2d7374720d04030000000007047a65726f030100000007036f6e650
"
"302000000070374776f030300000007057468726565"
);
}
TEST
(
FlStandardMessageCodecTest
,
DecodeMapEmpty
)
{
...
...
@@ -791,9 +796,9 @@ TEST(FlStandardMessageCodecTest, DecodeMapEmpty) {
TEST
(
FlStandardMessageCodecTest
,
DecodeMapKeyTypes
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"0d070007046e756c6c010704626f6f6c032a0000000703696e7406
182d4454fb21094007
"
"
05666c6f6174070568656c6c6f0706737472696e670c0007046c6973740d0007036d617
"
"0"
);
"0d070007046e756c6c010704626f6f6c032a0000000703696e7406
0000000000182d4454
"
"
fb2109400705666c6f6174070568656c6c6f0706737472696e670c0007046c6973740d00
"
"0
7036d6170
"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_MAP
);
ASSERT_EQ
(
fl_value_get_length
(
value
),
static_cast
<
size_t
>
(
7
));
...
...
@@ -850,9 +855,9 @@ TEST(FlStandardMessageCodecTest, DecodeMapKeyTypes) {
TEST
(
FlStandardMessageCodecTest
,
DecodeMapValueTypes
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"0d0707046e756c6c000704626f6f6c010703696e74032a0000000705666c6f617406
182d
"
"
4454fb2109400706737472696e67070568656c6c6f07046c6973740c0007036d61700d0
"
"0"
);
"0d0707046e756c6c000704626f6f6c010703696e74032a0000000705666c6f617406
0000
"
"
00000000182d4454fb2109400706737472696e67070568656c6c6f07046c6973740c0007
"
"0
36d61700d00
"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_MAP
);
ASSERT_EQ
(
fl_value_get_length
(
value
),
static_cast
<
size_t
>
(
7
));
...
...
@@ -909,10 +914,10 @@ TEST(FlStandardMessageCodecTest, DecodeMapValueTypes) {
TEST
(
FlStandardMessageCodecTest
,
DecodeMapNested
)
{
g_autoptr
(
FlValue
)
value
=
decode_message
(
"0d02070a7374722d746f2d696e740d0407047a65726f030000000007036f"
"
6e650301000000070374776f030200000007057468726565030300000007
"
"0
a696e742d746f2d7374720d04030000000007047a65726f030100000007
"
"0
36f6e650302000000070374776f030300000
007057468726565"
);
"0d02070a7374722d746f2d696e740d0407047a65726f030000000007036f
6e6503010000
"
"
00070374776f0302000000070574687265650303000000070a696e742d746f2d7374720d
"
"0
4030000000007047a65726f030100000007036f6e650302000000070374776f03030000
"
"0007057468726565"
);
ASSERT_EQ
(
fl_value_get_type
(
value
),
FL_VALUE_TYPE_MAP
);
ASSERT_EQ
(
fl_value_get_length
(
value
),
static_cast
<
size_t
>
(
2
));
...
...
@@ -971,9 +976,9 @@ TEST(FlStandardMessageCodecTest, DecodeMapShortData1) {
TEST
(
FlStandardMessageCodecTest
,
DecodeMapShortData2
)
{
decode_error_value
(
"0d0707046e756c6c000704626f6f6c010703696e74032a0000000705666c"
"
6f617406000000000000f8bf0706737472696e67070568656c6c6f07046c
"
"
6973740c0007
036d61700d"
,
"0d0707046e756c6c000704626f6f6c010703696e74032a0000000705666c
6f6174060000
"
"
00000000182d4454fb2109400706737472696e67070568656c6c6f07046c6973740c0007
"
"036d61700d"
,
FL_MESSAGE_CODEC_ERROR
,
FL_MESSAGE_CODEC_ERROR_OUT_OF_DATA
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录