Toggle navigation
Toggle navigation
此项目
正在载入...
Sign in
胡斌
/
srs
转到一个项目
Toggle navigation
项目
群组
代码片段
帮助
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
winlin
2014-07-20 15:27:05 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9b6c22644dc1e1f051b8eb74cf868098e19b9b56
9b6c2264
1 parent
6f743a2f
add basic utest for config directive
隐藏空白字符变更
内嵌
并排对比
正在显示
2 个修改的文件
包含
242 行增加
和
0 行删除
trunk/src/utest/srs_utest_config.cpp
trunk/src/utest/srs_utest_config.hpp
trunk/src/utest/srs_utest_config.cpp
查看文件 @
9b6c226
...
...
@@ -26,6 +26,32 @@ using namespace std;
#include <srs_app_config.hpp>
#include <srs_kernel_consts.hpp>
#include <srs_kernel_error.hpp>
MockSrsConfigBuffer
::
MockSrsConfigBuffer
(
string
buf
)
{
// read all.
int
filesize
=
(
int
)
buf
.
length
();
if
(
filesize
<=
0
)
{
return
;
}
// create buffer
pos
=
last
=
start
=
new
char
[
filesize
];
end
=
start
+
filesize
;
memcpy
(
start
,
buf
.
data
(),
filesize
);
}
MockSrsConfigBuffer
::~
MockSrsConfigBuffer
()
{
}
int
MockSrsConfigBuffer
::
fullfill
(
const
char
*
/*filename*/
)
{
return
ERROR_SUCCESS
;
}
VOID
TEST
(
ConfigTest
,
CheckMacros
)
{
...
...
@@ -159,3 +185,208 @@ VOID TEST(ConfigTest, CheckMacros)
EXPECT_TRUE
(
false
);
#endif
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseEmpty
)
{
MockSrsConfigBuffer
buf
(
""
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
directives
.
size
());
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseNameOnly
)
{
MockSrsConfigBuffer
buf
(
"winlin;"
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
conf
.
directives
.
size
());
SrsConfDirective
&
dir
=
*
conf
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"winlin"
,
dir
.
name
.
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir
.
args
.
size
());
EXPECT_EQ
(
0
,
(
int
)
dir
.
directives
.
size
());
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseNameArg0Only
)
{
MockSrsConfigBuffer
buf
(
"winlin arg0;"
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
conf
.
directives
.
size
());
SrsConfDirective
&
dir
=
*
conf
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"winlin"
,
dir
.
name
.
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir
.
args
.
size
());
EXPECT_STREQ
(
"arg0"
,
dir
.
arg0
().
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir
.
directives
.
size
());
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseNameArg1Only
)
{
MockSrsConfigBuffer
buf
(
"winlin arg0 arg1;"
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
conf
.
directives
.
size
());
SrsConfDirective
&
dir
=
*
conf
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"winlin"
,
dir
.
name
.
c_str
());
EXPECT_EQ
(
2
,
(
int
)
dir
.
args
.
size
());
EXPECT_STREQ
(
"arg0"
,
dir
.
arg0
().
c_str
());
EXPECT_STREQ
(
"arg1"
,
dir
.
arg1
().
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir
.
directives
.
size
());
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseNameArg2Only
)
{
MockSrsConfigBuffer
buf
(
"winlin arg0 arg1 arg2;"
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
conf
.
directives
.
size
());
SrsConfDirective
&
dir
=
*
conf
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"winlin"
,
dir
.
name
.
c_str
());
EXPECT_EQ
(
3
,
(
int
)
dir
.
args
.
size
());
EXPECT_STREQ
(
"arg0"
,
dir
.
arg0
().
c_str
());
EXPECT_STREQ
(
"arg1"
,
dir
.
arg1
().
c_str
());
EXPECT_STREQ
(
"arg2"
,
dir
.
arg2
().
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir
.
directives
.
size
());
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseNameArg2Dir0
)
{
MockSrsConfigBuffer
buf
(
"winlin arg0 arg1 arg2 {dir0;}"
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
conf
.
directives
.
size
());
SrsConfDirective
&
dir
=
*
conf
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"winlin"
,
dir
.
name
.
c_str
());
EXPECT_EQ
(
3
,
(
int
)
dir
.
args
.
size
());
EXPECT_STREQ
(
"arg0"
,
dir
.
arg0
().
c_str
());
EXPECT_STREQ
(
"arg1"
,
dir
.
arg1
().
c_str
());
EXPECT_STREQ
(
"arg2"
,
dir
.
arg2
().
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir
.
directives
.
size
());
SrsConfDirective
&
dir0
=
*
dir
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"dir0"
,
dir0
.
name
.
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir0
.
args
.
size
());
EXPECT_EQ
(
0
,
(
int
)
dir0
.
directives
.
size
());
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseNameArg2Dir0NoEmpty
)
{
MockSrsConfigBuffer
buf
(
"winlin arg0 arg1 arg2{dir0;}"
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
conf
.
directives
.
size
());
SrsConfDirective
&
dir
=
*
conf
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"winlin"
,
dir
.
name
.
c_str
());
EXPECT_EQ
(
3
,
(
int
)
dir
.
args
.
size
());
EXPECT_STREQ
(
"arg0"
,
dir
.
arg0
().
c_str
());
EXPECT_STREQ
(
"arg1"
,
dir
.
arg1
().
c_str
());
EXPECT_STREQ
(
"arg2"
,
dir
.
arg2
().
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir
.
directives
.
size
());
SrsConfDirective
&
dir0
=
*
dir
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"dir0"
,
dir0
.
name
.
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir0
.
args
.
size
());
EXPECT_EQ
(
0
,
(
int
)
dir0
.
directives
.
size
());
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseNameArg2_Dir0Arg0
)
{
MockSrsConfigBuffer
buf
(
"winlin arg0 arg1 arg2 {dir0 dir_arg0;}"
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
conf
.
directives
.
size
());
SrsConfDirective
&
dir
=
*
conf
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"winlin"
,
dir
.
name
.
c_str
());
EXPECT_EQ
(
3
,
(
int
)
dir
.
args
.
size
());
EXPECT_STREQ
(
"arg0"
,
dir
.
arg0
().
c_str
());
EXPECT_STREQ
(
"arg1"
,
dir
.
arg1
().
c_str
());
EXPECT_STREQ
(
"arg2"
,
dir
.
arg2
().
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir
.
directives
.
size
());
SrsConfDirective
&
dir0
=
*
dir
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"dir0"
,
dir0
.
name
.
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir0
.
args
.
size
());
EXPECT_STREQ
(
"dir_arg0"
,
dir0
.
arg0
().
c_str
());
EXPECT_EQ
(
0
,
(
int
)
dir0
.
directives
.
size
());
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseNameArg2_Dir0Arg0_Dir0
)
{
MockSrsConfigBuffer
buf
(
"winlin arg0 arg1 arg2 {dir0 dir_arg0 {ddir0;}}"
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
conf
.
directives
.
size
());
SrsConfDirective
&
dir
=
*
conf
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"winlin"
,
dir
.
name
.
c_str
());
EXPECT_EQ
(
3
,
(
int
)
dir
.
args
.
size
());
EXPECT_STREQ
(
"arg0"
,
dir
.
arg0
().
c_str
());
EXPECT_STREQ
(
"arg1"
,
dir
.
arg1
().
c_str
());
EXPECT_STREQ
(
"arg2"
,
dir
.
arg2
().
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir
.
directives
.
size
());
SrsConfDirective
&
dir0
=
*
dir
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"dir0"
,
dir0
.
name
.
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir0
.
args
.
size
());
EXPECT_STREQ
(
"dir_arg0"
,
dir0
.
arg0
().
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir0
.
directives
.
size
());
SrsConfDirective
&
ddir0
=
*
dir0
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"ddir0"
,
ddir0
.
name
.
c_str
());
EXPECT_EQ
(
0
,
(
int
)
ddir0
.
args
.
size
());
EXPECT_EQ
(
0
,
(
int
)
ddir0
.
directives
.
size
());
}
VOID
TEST
(
ConfigDirectiveTest
,
ParseNameArg2_Dir0Arg0_Dir0Arg0
)
{
MockSrsConfigBuffer
buf
(
"winlin arg0 arg1 arg2 {dir0 dir_arg0 {ddir0 ddir_arg0;}}"
);
SrsConfDirective
conf
;
EXPECT_TRUE
(
ERROR_SUCCESS
==
conf
.
parse
(
&
buf
));
EXPECT_EQ
(
0
,
(
int
)
conf
.
name
.
length
());
EXPECT_EQ
(
0
,
(
int
)
conf
.
args
.
size
());
EXPECT_EQ
(
1
,
(
int
)
conf
.
directives
.
size
());
SrsConfDirective
&
dir
=
*
conf
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"winlin"
,
dir
.
name
.
c_str
());
EXPECT_EQ
(
3
,
(
int
)
dir
.
args
.
size
());
EXPECT_STREQ
(
"arg0"
,
dir
.
arg0
().
c_str
());
EXPECT_STREQ
(
"arg1"
,
dir
.
arg1
().
c_str
());
EXPECT_STREQ
(
"arg2"
,
dir
.
arg2
().
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir
.
directives
.
size
());
SrsConfDirective
&
dir0
=
*
dir
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"dir0"
,
dir0
.
name
.
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir0
.
args
.
size
());
EXPECT_STREQ
(
"dir_arg0"
,
dir0
.
arg0
().
c_str
());
EXPECT_EQ
(
1
,
(
int
)
dir0
.
directives
.
size
());
SrsConfDirective
&
ddir0
=
*
dir0
.
directives
.
at
(
0
);
EXPECT_STREQ
(
"ddir0"
,
ddir0
.
name
.
c_str
());
EXPECT_EQ
(
1
,
(
int
)
ddir0
.
args
.
size
());
EXPECT_STREQ
(
"ddir_arg0"
,
ddir0
.
arg0
().
c_str
());
EXPECT_EQ
(
0
,
(
int
)
ddir0
.
directives
.
size
());
}
...
...
trunk/src/utest/srs_utest_config.hpp
查看文件 @
9b6c226
...
...
@@ -31,4 +31,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <string>
#include <srs_app_config.hpp>
class
MockSrsConfigBuffer
:
public
_srs_internal
::
SrsConfigBuffer
{
public
:
MockSrsConfigBuffer
(
std
::
string
buf
);
virtual
~
MockSrsConfigBuffer
();
public
:
virtual
int
fullfill
(
const
char
*
filename
);
};
#endif
...
...
请
注册
或
登录
后发表评论