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-03-08 23:09:24 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
95c2e7fd639c2ce65be7c21bc4ef318a583ca1b3
95c2e7fd
1 parent
044138c3
amf0 utest: finish basic utest for amf0
隐藏空白字符变更
内嵌
并排对比
正在显示
3 个修改的文件
包含
120 行增加
和
19 行删除
trunk/src/rtmp/srs_protocol_amf0.cpp
trunk/src/rtmp/srs_protocol_amf0.hpp
trunk/src/utest/srs_utest_amf0.cpp
trunk/src/rtmp/srs_protocol_amf0.cpp
查看文件 @
95c2e7f
...
...
@@ -24,6 +24,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_protocol_amf0.hpp>
#include <utility>
#include <vector>
using
namespace
std
;
#include <srs_kernel_log.hpp>
...
...
@@ -417,7 +418,7 @@ void __SrsUnSortedHashtable::clear()
properties
.
clear
();
}
st
d
::
st
ring
__SrsUnSortedHashtable
::
key_at
(
int
index
)
string
__SrsUnSortedHashtable
::
key_at
(
int
index
)
{
srs_assert
(
index
<
count
());
SrsObjectPropertyType
&
elem
=
properties
[
index
];
...
...
@@ -431,7 +432,7 @@ SrsAmf0Any* __SrsUnSortedHashtable::value_at(int index)
return
elem
.
second
;
}
void
__SrsUnSortedHashtable
::
set
(
st
d
::
st
ring
key
,
SrsAmf0Any
*
value
)
void
__SrsUnSortedHashtable
::
set
(
string
key
,
SrsAmf0Any
*
value
)
{
if
(
!
value
)
{
srs_warn
(
"add a NULL propertity %s"
,
key
.
c_str
());
...
...
@@ -455,7 +456,7 @@ void __SrsUnSortedHashtable::set(std::string key, SrsAmf0Any* value)
properties
.
push_back
(
std
::
make_pair
(
key
,
value
));
}
SrsAmf0Any
*
__SrsUnSortedHashtable
::
get_property
(
st
d
::
st
ring
name
)
SrsAmf0Any
*
__SrsUnSortedHashtable
::
get_property
(
string
name
)
{
std
::
vector
<
SrsObjectPropertyType
>::
iterator
it
;
...
...
@@ -471,7 +472,7 @@ SrsAmf0Any* __SrsUnSortedHashtable::get_property(std::string name)
return
NULL
;
}
SrsAmf0Any
*
__SrsUnSortedHashtable
::
ensure_property_string
(
st
d
::
st
ring
name
)
SrsAmf0Any
*
__SrsUnSortedHashtable
::
ensure_property_string
(
string
name
)
{
SrsAmf0Any
*
prop
=
get_property
(
name
);
...
...
@@ -486,7 +487,7 @@ SrsAmf0Any* __SrsUnSortedHashtable::ensure_property_string(std::string name)
return
prop
;
}
SrsAmf0Any
*
__SrsUnSortedHashtable
::
ensure_property_number
(
st
d
::
st
ring
name
)
SrsAmf0Any
*
__SrsUnSortedHashtable
::
ensure_property_number
(
string
name
)
{
SrsAmf0Any
*
prop
=
get_property
(
name
);
...
...
@@ -713,7 +714,7 @@ int SrsAmf0Object::count()
return
properties
->
count
();
}
st
d
::
st
ring
SrsAmf0Object
::
key_at
(
int
index
)
string
SrsAmf0Object
::
key_at
(
int
index
)
{
return
properties
->
key_at
(
index
);
}
...
...
@@ -723,22 +724,22 @@ SrsAmf0Any* SrsAmf0Object::value_at(int index)
return
properties
->
value_at
(
index
);
}
void
SrsAmf0Object
::
set
(
st
d
::
st
ring
key
,
SrsAmf0Any
*
value
)
void
SrsAmf0Object
::
set
(
string
key
,
SrsAmf0Any
*
value
)
{
properties
->
set
(
key
,
value
);
}
SrsAmf0Any
*
SrsAmf0Object
::
get_property
(
st
d
::
st
ring
name
)
SrsAmf0Any
*
SrsAmf0Object
::
get_property
(
string
name
)
{
return
properties
->
get_property
(
name
);
}
SrsAmf0Any
*
SrsAmf0Object
::
ensure_property_string
(
st
d
::
st
ring
name
)
SrsAmf0Any
*
SrsAmf0Object
::
ensure_property_string
(
string
name
)
{
return
properties
->
ensure_property_string
(
name
);
}
SrsAmf0Any
*
SrsAmf0Object
::
ensure_property_number
(
st
d
::
st
ring
name
)
SrsAmf0Any
*
SrsAmf0Object
::
ensure_property_number
(
string
name
)
{
return
properties
->
ensure_property_number
(
name
);
}
...
...
@@ -900,7 +901,7 @@ int SrsAmf0EcmaArray::count()
return
properties
->
count
();
}
st
d
::
st
ring
SrsAmf0EcmaArray
::
key_at
(
int
index
)
string
SrsAmf0EcmaArray
::
key_at
(
int
index
)
{
return
properties
->
key_at
(
index
);
}
...
...
@@ -910,21 +911,26 @@ SrsAmf0Any* SrsAmf0EcmaArray::value_at(int index)
return
properties
->
value_at
(
index
);
}
void
SrsAmf0EcmaArray
::
set
(
st
d
::
st
ring
key
,
SrsAmf0Any
*
value
)
void
SrsAmf0EcmaArray
::
set
(
string
key
,
SrsAmf0Any
*
value
)
{
properties
->
set
(
key
,
value
);
}
SrsAmf0Any
*
SrsAmf0EcmaArray
::
get_property
(
st
d
::
st
ring
name
)
SrsAmf0Any
*
SrsAmf0EcmaArray
::
get_property
(
string
name
)
{
return
properties
->
get_property
(
name
);
}
SrsAmf0Any
*
SrsAmf0EcmaArray
::
ensure_property_string
(
st
d
::
st
ring
name
)
SrsAmf0Any
*
SrsAmf0EcmaArray
::
ensure_property_string
(
string
name
)
{
return
properties
->
ensure_property_string
(
name
);
}
SrsAmf0Any
*
SrsAmf0EcmaArray
::
ensure_property_number
(
string
name
)
{
return
properties
->
ensure_property_number
(
name
);
}
int
SrsAmf0Size
::
utf8
(
string
value
)
{
return
2
+
value
.
length
();
...
...
@@ -1138,7 +1144,7 @@ int srs_amf0_write_any(SrsStream* stream, SrsAmf0Any* value)
return
value
->
write
(
stream
);
}
int
srs_amf0_read_utf8
(
SrsStream
*
stream
,
st
d
::
st
ring
&
value
)
int
srs_amf0_read_utf8
(
SrsStream
*
stream
,
string
&
value
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -1182,7 +1188,7 @@ int srs_amf0_read_utf8(SrsStream* stream, std::string& value)
return
ret
;
}
int
srs_amf0_write_utf8
(
SrsStream
*
stream
,
st
d
::
st
ring
value
)
int
srs_amf0_write_utf8
(
SrsStream
*
stream
,
string
value
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -1213,7 +1219,7 @@ int srs_amf0_write_utf8(SrsStream* stream, std::string value)
return
ret
;
}
int
srs_amf0_read_string
(
SrsStream
*
stream
,
st
d
::
st
ring
&
value
)
int
srs_amf0_read_string
(
SrsStream
*
stream
,
string
&
value
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
@@ -1236,7 +1242,7 @@ int srs_amf0_read_string(SrsStream* stream, std::string& value)
return
srs_amf0_read_utf8
(
stream
,
value
);
}
int
srs_amf0_write_string
(
SrsStream
*
stream
,
st
d
::
st
ring
value
)
int
srs_amf0_write_string
(
SrsStream
*
stream
,
string
value
)
{
int
ret
=
ERROR_SUCCESS
;
...
...
trunk/src/rtmp/srs_protocol_amf0.hpp
查看文件 @
95c2e7f
...
...
@@ -31,7 +31,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core.hpp>
#include <string>
#include <vector>
class
SrsStream
;
class
SrsAmf0Object
;
...
...
@@ -220,6 +219,7 @@ public:
virtual
void
set
(
std
::
string
key
,
SrsAmf0Any
*
value
);
virtual
SrsAmf0Any
*
get_property
(
std
::
string
name
);
virtual
SrsAmf0Any
*
ensure_property_string
(
std
::
string
name
);
virtual
SrsAmf0Any
*
ensure_property_number
(
std
::
string
name
);
};
/**
...
...
trunk/src/utest/srs_utest_amf0.cpp
查看文件 @
95c2e7f
...
...
@@ -808,4 +808,99 @@ VOID TEST(AMF0Test, ObjectProps)
EXPECT_TRUE
(
NULL
!=
o
->
ensure_property_number
(
"age"
));
EXPECT_TRUE
(
NULL
==
o
->
ensure_property_string
(
"age"
));
}
// count
if
(
true
)
{
o
=
SrsAmf0Any
::
object
();
SrsAutoFree
(
SrsAmf0Object
,
o
,
false
);
EXPECT_EQ
(
0
,
o
->
count
());
o
->
set
(
"name"
,
SrsAmf0Any
::
str
(
"winlin"
));
EXPECT_EQ
(
1
,
o
->
count
());
o
->
set
(
"name"
,
SrsAmf0Any
::
str
(
"winlin"
));
EXPECT_EQ
(
1
,
o
->
count
());
o
->
set
(
"age"
,
SrsAmf0Any
::
number
(
100
));
EXPECT_EQ
(
2
,
o
->
count
());
}
}
VOID
TEST
(
AMF0Test
,
EcmaArrayProps
)
{
SrsAmf0EcmaArray
*
o
=
NULL
;
// get/set property
if
(
true
)
{
o
=
SrsAmf0Any
::
ecma_array
();
SrsAutoFree
(
SrsAmf0EcmaArray
,
o
,
false
);
EXPECT_TRUE
(
NULL
==
o
->
get_property
(
"name"
));
o
->
set
(
"name"
,
SrsAmf0Any
::
str
(
"winlin"
));
EXPECT_TRUE
(
NULL
!=
o
->
get_property
(
"name"
));
EXPECT_TRUE
(
NULL
==
o
->
get_property
(
"age"
));
o
->
set
(
"age"
,
SrsAmf0Any
::
number
(
100
));
EXPECT_TRUE
(
NULL
!=
o
->
get_property
(
"age"
));
}
// index property
if
(
true
)
{
o
=
SrsAmf0Any
::
ecma_array
();
SrsAutoFree
(
SrsAmf0EcmaArray
,
o
,
false
);
o
->
set
(
"name"
,
SrsAmf0Any
::
str
(
"winlin"
));
EXPECT_STREQ
(
"name"
,
o
->
key_at
(
0
).
c_str
());
ASSERT_TRUE
(
o
->
value_at
(
0
)
->
is_string
());
EXPECT_STREQ
(
"winlin"
,
o
->
value_at
(
0
)
->
to_str
().
c_str
());
o
->
set
(
"age"
,
SrsAmf0Any
::
number
(
100
));
EXPECT_STREQ
(
"name"
,
o
->
key_at
(
0
).
c_str
());
ASSERT_TRUE
(
o
->
value_at
(
0
)
->
is_string
());
EXPECT_STREQ
(
"winlin"
,
o
->
value_at
(
0
)
->
to_str
().
c_str
());
EXPECT_STREQ
(
"age"
,
o
->
key_at
(
1
).
c_str
());
ASSERT_TRUE
(
o
->
value_at
(
1
)
->
is_number
());
EXPECT_DOUBLE_EQ
(
100
,
o
->
value_at
(
1
)
->
to_number
());
}
// ensure property
if
(
true
)
{
o
=
SrsAmf0Any
::
ecma_array
();
SrsAutoFree
(
SrsAmf0EcmaArray
,
o
,
false
);
EXPECT_TRUE
(
NULL
==
o
->
ensure_property_string
(
"name"
));
EXPECT_TRUE
(
NULL
==
o
->
ensure_property_number
(
"age"
));
o
->
set
(
"name"
,
SrsAmf0Any
::
str
(
"winlin"
));
EXPECT_TRUE
(
NULL
!=
o
->
ensure_property_string
(
"name"
));
EXPECT_TRUE
(
NULL
==
o
->
ensure_property_number
(
"name"
));
EXPECT_TRUE
(
NULL
==
o
->
ensure_property_number
(
"age"
));
o
->
set
(
"age"
,
SrsAmf0Any
::
number
(
100
));
EXPECT_TRUE
(
NULL
!=
o
->
ensure_property_string
(
"name"
));
EXPECT_TRUE
(
NULL
==
o
->
ensure_property_number
(
"name"
));
EXPECT_TRUE
(
NULL
!=
o
->
ensure_property_number
(
"age"
));
EXPECT_TRUE
(
NULL
==
o
->
ensure_property_string
(
"age"
));
}
// count
if
(
true
)
{
o
=
SrsAmf0Any
::
ecma_array
();
SrsAutoFree
(
SrsAmf0EcmaArray
,
o
,
false
);
EXPECT_EQ
(
0
,
o
->
count
());
o
->
set
(
"name"
,
SrsAmf0Any
::
str
(
"winlin"
));
EXPECT_EQ
(
1
,
o
->
count
());
o
->
set
(
"name"
,
SrsAmf0Any
::
str
(
"winlin"
));
EXPECT_EQ
(
1
,
o
->
count
());
o
->
set
(
"age"
,
SrsAmf0Any
::
number
(
100
));
EXPECT_EQ
(
2
,
o
->
count
());
}
}
...
...
请
注册
或
登录
后发表评论