Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
cf1acba4
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
cf1acba4
编写于
5月 29, 2020
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add more encoding tests
上级
8aa89525
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
129 addition
and
7 deletion
+129
-7
src/util/tests/codingTests.cpp
src/util/tests/codingTests.cpp
+129
-7
未找到文件。
src/util/tests/codingTests.cpp
浏览文件 @
cf1acba4
...
...
@@ -15,6 +15,16 @@ static bool test_fixed_uint16(uint16_t value) {
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_fixed_int16
(
int16_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
int16_t
value_check
=
0
;
void
*
ptr1
=
taosEncodeFixedI16
(
static_cast
<
void
*>
(
buf
),
value
);
void
*
ptr2
=
taosDecodeFixedI16
(
static_cast
<
void
*>
(
buf
),
&
value_check
);
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_fixed_uint32
(
uint32_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
uint32_t
value_check
=
0
;
...
...
@@ -25,6 +35,16 @@ static bool test_fixed_uint32(uint32_t value) {
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_fixed_int32
(
int32_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
int32_t
value_check
=
0
;
void
*
ptr1
=
taosEncodeFixedI32
(
static_cast
<
void
*>
(
buf
),
value
);
void
*
ptr2
=
taosDecodeFixedI32
(
static_cast
<
void
*>
(
buf
),
&
value_check
);
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_fixed_uint64
(
uint64_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
uint64_t
value_check
=
0
;
...
...
@@ -35,6 +55,16 @@ static bool test_fixed_uint64(uint64_t value) {
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_fixed_int64
(
int64_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
int64_t
value_check
=
0
;
void
*
ptr1
=
taosEncodeFixedI64
(
static_cast
<
void
*>
(
buf
),
value
);
void
*
ptr2
=
taosDecodeFixedI64
(
static_cast
<
void
*>
(
buf
),
&
value_check
);
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_variant_uint16
(
uint16_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
uint16_t
value_check
=
0
;
...
...
@@ -45,6 +75,16 @@ static bool test_variant_uint16(uint16_t value) {
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_variant_int16
(
int16_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
int16_t
value_check
=
0
;
void
*
ptr1
=
taosEncodeVariantI16
(
static_cast
<
void
*>
(
buf
),
value
);
void
*
ptr2
=
taosDecodeVariantI16
(
static_cast
<
void
*>
(
buf
),
&
value_check
);
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_variant_uint32
(
uint32_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
uint32_t
value_check
=
0
;
...
...
@@ -55,6 +95,16 @@ static bool test_variant_uint32(uint32_t value) {
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_variant_int32
(
int32_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
int32_t
value_check
=
0
;
void
*
ptr1
=
taosEncodeVariantI32
(
static_cast
<
void
*>
(
buf
),
value
);
void
*
ptr2
=
taosDecodeVariantI32
(
static_cast
<
void
*>
(
buf
),
&
value_check
);
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_variant_uint64
(
uint64_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
uint64_t
value_check
=
0
;
...
...
@@ -65,52 +115,124 @@ static bool test_variant_uint64(uint64_t value) {
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
static
bool
test_variant_int64
(
int64_t
value
)
{
char
buf
[
20
]
=
"
\0
"
;
int64_t
value_check
=
0
;
void
*
ptr1
=
taosEncodeVariantI64
(
static_cast
<
void
*>
(
buf
),
value
);
void
*
ptr2
=
taosDecodeVariantI64
(
static_cast
<
void
*>
(
buf
),
&
value_check
);
return
((
ptr2
!=
NULL
)
&&
(
value
==
value_check
)
&&
(
ptr1
==
ptr2
));
}
TEST
(
codingTest
,
fixed_encode_decode
)
{
srand
(
time
(
0
));
// uint16_t
for
(
uint16_t
value
=
0
;
value
<=
UINT16_MAX
;
value
++
)
{
ASSERT_TRUE
(
test_fixed_uint16
(
value
));
if
(
value
==
UINT16_MAX
)
break
;
}
// int16_t
for
(
int16_t
value
=
INT16_MIN
;
value
<=
INT16_MAX
;
value
++
)
{
ASSERT_TRUE
(
test_fixed_int16
(
value
));
if
(
value
==
INT16_MAX
)
break
;
}
std
::
mt19937
gen32
(
std
::
random_device
{}());
// uint32_t
ASSERT_TRUE
(
test_fixed_uint32
(
0
));
ASSERT_TRUE
(
test_fixed_uint32
(
UINT32_MAX
));
std
::
uniform_int_distribution
<
uint32_t
>
distr1
(
0
,
UINT32_MAX
);
for
(
int
i
=
0
;
i
<
1000000
;
i
++
)
{
ASSERT_TRUE
(
test_fixed_uint32
(
rand
(
)));
ASSERT_TRUE
(
test_fixed_uint32
(
distr1
(
gen32
)));
}
std
::
mt19937_64
gen
(
std
::
random_device
{}());
// int32_t
ASSERT_TRUE
(
test_fixed_int32
(
INT32_MIN
));
ASSERT_TRUE
(
test_fixed_int32
(
INT32_MAX
));
std
::
uniform_int_distribution
<
int32_t
>
distr2
(
INT32_MIN
,
INT32_MAX
);
for
(
int
i
=
0
;
i
<
1000000
;
i
++
)
{
ASSERT_TRUE
(
test_fixed_int32
(
distr2
(
gen32
)));
}
std
::
mt19937_64
gen64
(
std
::
random_device
{}());
// uint64_t
std
::
uniform_int_distribution
<
uint64_t
>
distr3
(
0
,
UINT64_MAX
);
ASSERT_TRUE
(
test_fixed_uint64
(
0
));
ASSERT_TRUE
(
test_fixed_uint64
(
UINT64_MAX
));
for
(
int
i
=
0
;
i
<
1000000
;
i
++
)
{
ASSERT_TRUE
(
test_fixed_uint64
(
gen
()));
ASSERT_TRUE
(
test_fixed_uint64
(
distr3
(
gen64
)));
}
// int64_t
std
::
uniform_int_distribution
<
int64_t
>
distr4
(
INT64_MIN
,
INT64_MAX
);
ASSERT_TRUE
(
test_fixed_int64
(
INT64_MIN
));
ASSERT_TRUE
(
test_fixed_int64
(
INT64_MAX
));
for
(
int
i
=
0
;
i
<
1000000
;
i
++
)
{
ASSERT_TRUE
(
test_fixed_int64
(
distr4
(
gen64
)));
}
}
TEST
(
codingTest
,
variant_encode_decode
)
{
srand
(
time
(
0
));
// uint16_t
for
(
uint16_t
value
=
0
;
value
<=
UINT16_MAX
;
value
++
)
{
ASSERT_TRUE
(
test_variant_uint16
(
value
));
if
(
value
==
UINT16_MAX
)
break
;
}
// int16_t
for
(
int16_t
value
=
INT16_MIN
;
value
<=
INT16_MAX
;
value
++
)
{
ASSERT_TRUE
(
test_variant_int16
(
value
));
if
(
value
==
INT16_MAX
)
break
;
}
std
::
mt19937
gen32
(
std
::
random_device
{}());
// uint32_t
std
::
uniform_int_distribution
<
uint32_t
>
distr1
(
0
,
UINT32_MAX
);
ASSERT_TRUE
(
test_variant_uint32
(
0
));
ASSERT_TRUE
(
test_variant_uint32
(
UINT32_MAX
));
for
(
int
i
=
0
;
i
<
5000000
;
i
++
)
{
ASSERT_TRUE
(
test_variant_uint32
(
rand
()));
ASSERT_TRUE
(
test_variant_uint32
(
distr1
(
gen32
)));
}
// int32_t
std
::
uniform_int_distribution
<
int32_t
>
distr2
(
INT32_MIN
,
INT32_MAX
);
ASSERT_TRUE
(
test_variant_int32
(
INT32_MIN
));
ASSERT_TRUE
(
test_variant_int32
(
INT32_MAX
));
for
(
int
i
=
0
;
i
<
5000000
;
i
++
)
{
ASSERT_TRUE
(
test_variant_int32
(
distr2
(
gen32
)));
}
std
::
mt19937_64
gen
(
std
::
random_device
{}());
std
::
mt19937_64
gen64
(
std
::
random_device
{}());
// uint64_t
std
::
uniform_int_distribution
<
uint64_t
>
distr3
(
0
,
UINT64_MAX
);
ASSERT_TRUE
(
test_variant_uint64
(
0
));
ASSERT_TRUE
(
test_variant_uint64
(
UINT64_MAX
));
for
(
int
i
=
0
;
i
<
5000000
;
i
++
)
{
uint64_t
value
=
gen
();
// uint64_t value = gen();
// printf("%ull\n", value);
ASSERT_TRUE
(
test_variant_uint64
(
distr3
(
gen64
)));
}
// int64_t
std
::
uniform_int_distribution
<
int64_t
>
distr4
(
INT64_MIN
,
INT64_MAX
);
ASSERT_TRUE
(
test_variant_int64
(
INT64_MIN
));
ASSERT_TRUE
(
test_variant_int64
(
INT64_MAX
));
for
(
int
i
=
0
;
i
<
5000000
;
i
++
)
{
// uint64_t value = gen();
// printf("%ull\n", value);
ASSERT_TRUE
(
test_variant_
uint64
(
value
));
ASSERT_TRUE
(
test_variant_
int64
(
distr4
(
gen64
)
));
}
}
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录