Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
F
freeswitch
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
张华
freeswitch
Commits
1d8c136d
提交
1d8c136d
authored
7月 02, 2015
作者:
Brian West
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
testing example, need to form this into a framework
上级
9a269505
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
79 行增加
和
0 行删除
+79
-0
test_cond_api.lua
scripts/lua/test_cond_api.lua
+79
-0
没有找到文件。
scripts/lua/test_cond_api.lua
0 → 100644
浏览文件 @
1d8c136d
-- Test various cond api to verify consistency.
-- string compared to string (eg. 'string1' == 'string2') compares by value
-- string compared to number (eg. 'string' == 5) compares its string length
-- string compared to any type with 'lt(<) gt(>) ge(>=) le(<=)' operators are compared to their legnth (even if both values are strings).
-- number compared to number works just like you'd expect :)
-- only print failed tests
local
FAILED_ONLY
=
true
;
local
ops
=
{
"=="
,
"!="
,
">="
,
"<="
,
">"
,
"<"
};
local
tests
=
{
-- cmp value, expected results for each operator, MAPPINGS[idx]
{
{
"1"
,
"1"
},
{
1
,
2
,
1
,
1
,
2
,
2
},
'test 2 equal integers'
},
{
{
"1"
,
"2"
},
{
2
,
1
,
2
,
1
,
2
,
1
},
'test 2 non equal integers'
},
{
{
"1.000001"
,
"1.000001"
},
{
1
,
2
,
1
,
1
,
2
,
2
},
'test 2 equal float'
},
{
{
"1.000001"
,
"1.000002"
},
{
2
,
1
,
2
,
1
,
2
,
1
},
'test 2 non equal float'
},
{
{
"'hello'"
,
"'hello'"
},
{
1
,
2
,
1
,
1
,
2
,
2
},
'test 2 equal quoted strings'
},
{
{
"hello"
,
"hello"
},
{
1
,
2
,
1
,
1
,
2
,
2
},
'test 2 equal unquoted strings'
},
{
{
"hello"
,
"HELLO"
},
{
2
,
1
,
1
,
1
,
2
,
2
},
'test 2 non equal unquoted strings'
},
{
{
"hello"
,
"5"
},
{
1
,
2
,
1
,
1
,
2
,
2
},
'test lenght of unquoted string with equal number'
},
{
{
"'hello'"
,
"5"
},
{
1
,
2
,
1
,
1
,
2
,
2
},
'test length of quoted string with equal number'
},
{
{
"' hello'"
,
"5"
},
{
2
,
1
,
1
,
2
,
1
,
2
},
'test length of quoted string includes preceding space'
},
{
{
" hello"
,
"5"
},
{
1
,
2
,
1
,
1
,
2
,
2
},
'test length of unquoted string excludes preceding space'
},
{
{
"'hello'"
,
"6"
},
{
2
,
1
,
2
,
1
,
2
,
1
},
'test length of quoted string is against non equal number'
},
{
{
"'01'"
,
"01"
},
{
2
,
1
,
1
,
2
,
1
,
2
},
'test number quoted (as string) against number'
},
{
{
"''"
,
"''"
},
{
1
,
2
,
1
,
1
,
2
,
2
},
'test quoted empty strings'
},
{
{
"' '"
,
"''"
},
{
2
,
1
,
1
,
2
,
1
,
2
},
'test quoted space against empty string'
},
{
{
""
,
" "
},
{
3
,
3
,
3
,
3
,
3
,
3
},
'test unquoted empty values returns ERR'
},
{
{
"'Isn\\'t it \"
great
\
"?!\\t'"
,
"'Isn\\'t it \"
great
\
"?!\\t'"
},
{
1
,
2
,
1
,
1
,
2
,
2
},
'test quoted string with special escaped chars'
},
{
{
"'Isn't it \"
great
\
"?!\\t'"
,
"'Isn't it \"
great
\
"?!\\t'"
},
{
3
,
3
,
3
,
3
,
3
,
3
},
'test quoted string with unescaped single quote returns ERR'
},
};
stream
:
write
(
"Testing cond api\n"
);
local
commands
=
{
-- command, description, truth val, false val, err val
{
" ? true : false"
,
"command with spaces"
,
{
"true"
,
"false"
,
"-ERR"
}},
{
" ? true:false"
,
"command without spaces"
,
{
"true"
,
"false"
,
"-ERR"
}},
{
" ? true :"
,
"command with missing ternary false value"
,
{
"true"
,
""
,
"-ERR"
}},
{
"?true:false"
,
"command with no spaces between values"
,
{
"-ERR"
,
"-ERR"
,
"-ERR"
}},
}
local
num_tests
=
0
;
local
num_passed
=
0
;
local
api
=
freeswitch
.
API
();
-- do for each command
for
_
,
cmd
in
pairs
(
commands
)
do
for
ti
,
test
in
pairs
(
tests
)
do
if
(
not
FAILED_ONLY
)
then
stream
:
write
(
string.format
(
"
\n
Testing #[%d]: `%s` (%s)\n"
,
ti
,
test
[
3
],
cmd
[
2
]));
end
for
i
,
op
in
pairs
(
ops
)
do
command
=
"cond "
..
test
[
1
][
1
]
..
" "
..
op
..
" "
..
test
[
1
][
2
]
..
cmd
[
1
];
reply
=
api
:
executeString
(
command
);
expected
=
cmd
[
3
][
test
[
2
][
i
]];
if
(
reply
~=
nil
)
then
passed
=
(
reply
==
expected
);
if
(
passed
)
then
num_passed
=
num_passed
+
1
;
pass_text
=
"PASSED"
;
else
pass_text
=
"FAILED"
end
-- print runned test
if
(
not
FAILED_ONLY
or
not
passed
)
then
stream
:
write
(
string.format
(
"%s:\tTest #[%d]: [%s (%s)] \t--- expected: [%s], actual: [%s]\n"
,
pass_text
,
ti
,
command
,
cmd
[
2
],
expected
,
reply
));
end
else
stream
:
write
(
"FAILED!\t"
..
command
..
"
\n
"
);
end
num_tests
=
num_tests
+
1
;
end
end
end
stream
:
write
(
string.format
(
"
\n
RAN: [%d], PASSED: [%d], FAILED: [%d]"
,
num_tests
,
num_passed
,
num_tests
-
num_passed
));
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论