Skip to content

Commit

Permalink
Cover JSON codec. 3.0.62
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Oct 22, 2019
1 parent aee704f commit c7602d8
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 2 deletions.
2 changes: 1 addition & 1 deletion trunk/src/core/srs_core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
// The version config.
#define VERSION_MAJOR 3
#define VERSION_MINOR 0
#define VERSION_REVISION 60
#define VERSION_REVISION 62

// The macros generated by configure script.
#include <srs_auto_headers.hpp>
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/protocol/srs_protocol_json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,7 @@ string SrsJsonAny::dumps()
case SRS_JSON_Number: {
// len(max int64_t) is 20, plus one "+-."
char tmp[22];
snprintf(tmp, 22, "%.6f", to_number());
snprintf(tmp, 22, "%.2f", to_number());
return tmp;
}
case SRS_JSON_Null: {
Expand Down
70 changes: 70 additions & 0 deletions trunk/src/utest/srs_utest_amf0.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2493,3 +2493,73 @@ VOID TEST(ProtocolAMF0Test, Amf0Object2)
}
}

VOID TEST(ProtocolJSONTest, Interfaces)
{
if (true) {
SrsJsonAny* p = SrsJsonAny::str();
EXPECT_TRUE(p->is_string());
EXPECT_TRUE(p->to_str().empty());
srs_freep(p);
}

if (true) {
SrsJsonAny* p = SrsJsonAny::str("hello");
EXPECT_TRUE(p->is_string());
EXPECT_TRUE(string("hello") == p->to_str());
srs_freep(p);
}

if (true) {
SrsJsonAny* p = SrsJsonAny::str("hello", 2);
EXPECT_TRUE(p->is_string());
EXPECT_TRUE(string("he") == p->to_str());
srs_freep(p);
}
}

VOID TEST(ProtocolJSONTest, Dumps)
{
if (true) {
SrsJsonAny* p = SrsJsonAny::str("hello");
EXPECT_TRUE(p->is_string());
EXPECT_STREQ("\"hello\"", p->dumps().c_str());
srs_freep(p);
}

if (true) {
SrsJsonAny* p = SrsJsonAny::boolean(true);
EXPECT_STREQ("true", p->dumps().c_str());
srs_freep(p);
}

if (true) {
SrsJsonAny* p = SrsJsonAny::integer(3);
EXPECT_STREQ("3", p->dumps().c_str());
srs_freep(p);
}

if (true) {
SrsJsonAny* p = SrsJsonAny::number(3.1);
EXPECT_STREQ("3.10", p->dumps().c_str());
srs_freep(p);
}

if (true) {
SrsJsonAny* p = SrsJsonAny::null();
EXPECT_STREQ("null", p->dumps().c_str());
srs_freep(p);
}

if (true) {
SrsJsonObject* p = SrsJsonAny::object();
EXPECT_STREQ("{}", p->dumps().c_str());
srs_freep(p);
}

if (true) {
SrsJsonArray* p = SrsJsonAny::array();
EXPECT_STREQ("[]", p->dumps().c_str());
srs_freep(p);
}
}

0 comments on commit c7602d8

Please sign in to comment.