|
|
|
@ -28,6 +28,12 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
#include <srs_app_server.hpp>
|
|
|
|
|
#include <srs_app_config.hpp>
|
|
|
|
|
#include <srs_app_log.hpp>
|
|
|
|
|
#include <srs_protocol_amf0.hpp>
|
|
|
|
|
#include <srs_core_autofree.hpp>
|
|
|
|
|
#include <srs_protocol_json.hpp>
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
// Temporary disk config.
|
|
|
|
|
std::string _srs_tmp_file_prefix = "/tmp/srs-utest-";
|
|
|
|
@ -130,3 +136,284 @@ VOID TEST(SampleTest, FastSampleMacrosTest)
|
|
|
|
|
EXPECT_NEAR(10, 15, 5);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VOID TEST(ProtocolAMF0Test, Interfaces)
|
|
|
|
|
{
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsAmf0Any* p = SrsAmf0Any::str("hello");
|
|
|
|
|
SrsAutoFree(SrsAmf0Any, p);
|
|
|
|
|
|
|
|
|
|
EXPECT_TRUE(p->is_string());
|
|
|
|
|
EXPECT_FALSE(p->is_boolean());
|
|
|
|
|
EXPECT_FALSE(p->is_number());
|
|
|
|
|
EXPECT_FALSE(p->is_null());
|
|
|
|
|
EXPECT_FALSE(p->is_undefined());
|
|
|
|
|
EXPECT_FALSE(p->is_object());
|
|
|
|
|
EXPECT_FALSE(p->is_object_eof());
|
|
|
|
|
EXPECT_FALSE(p->is_ecma_array());
|
|
|
|
|
EXPECT_FALSE(p->is_strict_array());
|
|
|
|
|
EXPECT_FALSE(p->is_date());
|
|
|
|
|
EXPECT_FALSE(p->is_complex_object());
|
|
|
|
|
EXPECT_TRUE(string("hello") == p->to_str());
|
|
|
|
|
EXPECT_STREQ("hello", p->to_str_raw());
|
|
|
|
|
|
|
|
|
|
char* d = p->human_print(NULL, NULL);
|
|
|
|
|
EXPECT_STREQ("String hello\n", d);
|
|
|
|
|
delete[] d;
|
|
|
|
|
|
|
|
|
|
SrsJsonAny* j = p->to_json();
|
|
|
|
|
EXPECT_TRUE(j->is_string());
|
|
|
|
|
EXPECT_TRUE(string("hello") == j->to_str());
|
|
|
|
|
srs_freep(j);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsAmf0Any* p = SrsAmf0Any::boolean();
|
|
|
|
|
SrsAutoFree(SrsAmf0Any, p);
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(p->is_string());
|
|
|
|
|
EXPECT_TRUE(p->is_boolean());
|
|
|
|
|
EXPECT_FALSE(p->is_number());
|
|
|
|
|
EXPECT_FALSE(p->is_null());
|
|
|
|
|
EXPECT_FALSE(p->is_undefined());
|
|
|
|
|
EXPECT_FALSE(p->is_object());
|
|
|
|
|
EXPECT_FALSE(p->is_object_eof());
|
|
|
|
|
EXPECT_FALSE(p->is_ecma_array());
|
|
|
|
|
EXPECT_FALSE(p->is_strict_array());
|
|
|
|
|
EXPECT_FALSE(p->is_date());
|
|
|
|
|
EXPECT_FALSE(p->is_complex_object());
|
|
|
|
|
EXPECT_FALSE(p->to_boolean());
|
|
|
|
|
|
|
|
|
|
char* d = p->human_print(NULL, NULL);
|
|
|
|
|
EXPECT_STREQ("Boolean false\n", d);
|
|
|
|
|
delete[] d;
|
|
|
|
|
|
|
|
|
|
SrsJsonAny* j = p->to_json();
|
|
|
|
|
EXPECT_TRUE(j->is_boolean());
|
|
|
|
|
EXPECT_FALSE(j->to_boolean());
|
|
|
|
|
srs_freep(j);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsAmf0Any* p = SrsAmf0Any::number();
|
|
|
|
|
SrsAutoFree(SrsAmf0Any, p);
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(p->is_string());
|
|
|
|
|
EXPECT_FALSE(p->is_boolean());
|
|
|
|
|
EXPECT_FALSE(!p->is_number());
|
|
|
|
|
EXPECT_FALSE(p->is_null());
|
|
|
|
|
EXPECT_FALSE(p->is_undefined());
|
|
|
|
|
EXPECT_FALSE(p->is_object());
|
|
|
|
|
EXPECT_FALSE(p->is_object_eof());
|
|
|
|
|
EXPECT_FALSE(p->is_ecma_array());
|
|
|
|
|
EXPECT_FALSE(p->is_strict_array());
|
|
|
|
|
EXPECT_FALSE(p->is_date());
|
|
|
|
|
EXPECT_FALSE(p->is_complex_object());
|
|
|
|
|
EXPECT_TRUE(0.0 == p->to_number());
|
|
|
|
|
|
|
|
|
|
char* d = p->human_print(NULL, NULL);
|
|
|
|
|
EXPECT_STREQ("Number 0.0\n", d);
|
|
|
|
|
delete[] d;
|
|
|
|
|
|
|
|
|
|
SrsJsonAny* j = p->to_json();
|
|
|
|
|
EXPECT_TRUE(j->is_integer());
|
|
|
|
|
EXPECT_TRUE(0.0 == j->to_integer());
|
|
|
|
|
srs_freep(j);
|
|
|
|
|
|
|
|
|
|
p->set_number(100.1);
|
|
|
|
|
EXPECT_TRUE(100.1 == p->to_number());
|
|
|
|
|
|
|
|
|
|
j = p->to_json();
|
|
|
|
|
EXPECT_TRUE(j->is_number());
|
|
|
|
|
EXPECT_TRUE(100.1 == j->to_number());
|
|
|
|
|
srs_freep(j);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsAmf0Any* p = SrsAmf0Any::date();
|
|
|
|
|
SrsAutoFree(SrsAmf0Any, p);
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(p->is_string());
|
|
|
|
|
EXPECT_FALSE(p->is_boolean());
|
|
|
|
|
EXPECT_FALSE(p->is_number());
|
|
|
|
|
EXPECT_FALSE(p->is_null());
|
|
|
|
|
EXPECT_FALSE(p->is_undefined());
|
|
|
|
|
EXPECT_FALSE(p->is_object());
|
|
|
|
|
EXPECT_FALSE(p->is_object_eof());
|
|
|
|
|
EXPECT_FALSE(p->is_ecma_array());
|
|
|
|
|
EXPECT_FALSE(p->is_strict_array());
|
|
|
|
|
EXPECT_FALSE(!p->is_date());
|
|
|
|
|
EXPECT_FALSE(p->is_complex_object());
|
|
|
|
|
EXPECT_TRUE(0 == p->to_date());
|
|
|
|
|
EXPECT_TRUE(0 == p->to_date_time_zone());
|
|
|
|
|
|
|
|
|
|
char* d = p->human_print(NULL, NULL);
|
|
|
|
|
EXPECT_STREQ("Date 0/0\n", d);
|
|
|
|
|
delete[] d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsAmf0Any* p = SrsAmf0Any::null();
|
|
|
|
|
SrsAutoFree(SrsAmf0Any, p);
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(p->is_string());
|
|
|
|
|
EXPECT_FALSE(p->is_boolean());
|
|
|
|
|
EXPECT_FALSE(p->is_number());
|
|
|
|
|
EXPECT_FALSE(!p->is_null());
|
|
|
|
|
EXPECT_FALSE(p->is_undefined());
|
|
|
|
|
EXPECT_FALSE(p->is_object());
|
|
|
|
|
EXPECT_FALSE(p->is_object_eof());
|
|
|
|
|
EXPECT_FALSE(p->is_ecma_array());
|
|
|
|
|
EXPECT_FALSE(p->is_strict_array());
|
|
|
|
|
EXPECT_FALSE(p->is_date());
|
|
|
|
|
EXPECT_FALSE(p->is_complex_object());
|
|
|
|
|
|
|
|
|
|
char* d = p->human_print(NULL, NULL);
|
|
|
|
|
EXPECT_STREQ("Null\n", d);
|
|
|
|
|
delete[] d;
|
|
|
|
|
|
|
|
|
|
SrsJsonAny* j = p->to_json();
|
|
|
|
|
EXPECT_TRUE(j->is_null());
|
|
|
|
|
srs_freep(j);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsAmf0Any* p = SrsAmf0Any::undefined();
|
|
|
|
|
SrsAutoFree(SrsAmf0Any, p);
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(p->is_string());
|
|
|
|
|
EXPECT_FALSE(p->is_boolean());
|
|
|
|
|
EXPECT_FALSE(p->is_number());
|
|
|
|
|
EXPECT_FALSE(p->is_null());
|
|
|
|
|
EXPECT_FALSE(!p->is_undefined());
|
|
|
|
|
EXPECT_FALSE(p->is_object());
|
|
|
|
|
EXPECT_FALSE(p->is_object_eof());
|
|
|
|
|
EXPECT_FALSE(p->is_ecma_array());
|
|
|
|
|
EXPECT_FALSE(p->is_strict_array());
|
|
|
|
|
EXPECT_FALSE(p->is_date());
|
|
|
|
|
EXPECT_FALSE(p->is_complex_object());
|
|
|
|
|
|
|
|
|
|
char* d = p->human_print(NULL, NULL);
|
|
|
|
|
EXPECT_STREQ("Undefined\n", d);
|
|
|
|
|
delete[] d;
|
|
|
|
|
|
|
|
|
|
SrsJsonAny* j = p->to_json();
|
|
|
|
|
EXPECT_TRUE(j->is_null());
|
|
|
|
|
srs_freep(j);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsAmf0Any* p = SrsAmf0Any::object();
|
|
|
|
|
SrsAutoFree(SrsAmf0Any, p);
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(p->is_string());
|
|
|
|
|
EXPECT_FALSE(p->is_boolean());
|
|
|
|
|
EXPECT_FALSE(p->is_number());
|
|
|
|
|
EXPECT_FALSE(p->is_null());
|
|
|
|
|
EXPECT_FALSE(p->is_undefined());
|
|
|
|
|
EXPECT_FALSE(!p->is_object());
|
|
|
|
|
EXPECT_FALSE(p->is_object_eof());
|
|
|
|
|
EXPECT_FALSE(p->is_ecma_array());
|
|
|
|
|
EXPECT_FALSE(p->is_strict_array());
|
|
|
|
|
EXPECT_FALSE(p->is_date());
|
|
|
|
|
EXPECT_FALSE(!p->is_complex_object());
|
|
|
|
|
EXPECT_TRUE(NULL != p->to_object());
|
|
|
|
|
|
|
|
|
|
char* d = p->human_print(NULL, NULL);
|
|
|
|
|
EXPECT_STREQ("Object (0 items)\n", d);
|
|
|
|
|
delete[] d;
|
|
|
|
|
|
|
|
|
|
SrsJsonAny* j = p->to_json();
|
|
|
|
|
EXPECT_TRUE(j->is_object());
|
|
|
|
|
srs_freep(j);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsAmf0Any* p = SrsAmf0Any::object_eof();
|
|
|
|
|
SrsAutoFree(SrsAmf0Any, p);
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(p->is_string());
|
|
|
|
|
EXPECT_FALSE(p->is_boolean());
|
|
|
|
|
EXPECT_FALSE(p->is_number());
|
|
|
|
|
EXPECT_FALSE(p->is_null());
|
|
|
|
|
EXPECT_FALSE(p->is_undefined());
|
|
|
|
|
EXPECT_FALSE(p->is_object());
|
|
|
|
|
EXPECT_FALSE(!p->is_object_eof());
|
|
|
|
|
EXPECT_FALSE(p->is_ecma_array());
|
|
|
|
|
EXPECT_FALSE(p->is_strict_array());
|
|
|
|
|
EXPECT_FALSE(p->is_date());
|
|
|
|
|
EXPECT_FALSE(!p->is_complex_object());
|
|
|
|
|
|
|
|
|
|
SrsJsonAny* j = p->to_json();
|
|
|
|
|
EXPECT_TRUE(j->is_null());
|
|
|
|
|
srs_freep(j);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsAmf0Any* p = SrsAmf0Any::ecma_array();
|
|
|
|
|
SrsAutoFree(SrsAmf0Any, p);
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(p->is_string());
|
|
|
|
|
EXPECT_FALSE(p->is_boolean());
|
|
|
|
|
EXPECT_FALSE(p->is_number());
|
|
|
|
|
EXPECT_FALSE(p->is_null());
|
|
|
|
|
EXPECT_FALSE(p->is_undefined());
|
|
|
|
|
EXPECT_FALSE(p->is_object());
|
|
|
|
|
EXPECT_FALSE(p->is_object_eof());
|
|
|
|
|
EXPECT_FALSE(!p->is_ecma_array());
|
|
|
|
|
EXPECT_FALSE(p->is_strict_array());
|
|
|
|
|
EXPECT_FALSE(p->is_date());
|
|
|
|
|
EXPECT_FALSE(!p->is_complex_object());
|
|
|
|
|
EXPECT_TRUE(NULL != p->to_ecma_array());
|
|
|
|
|
|
|
|
|
|
char* d = p->human_print(NULL, NULL);
|
|
|
|
|
EXPECT_STREQ("EcmaArray (0 items)\n", d);
|
|
|
|
|
delete[] d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsAmf0Any* p = SrsAmf0Any::strict_array();
|
|
|
|
|
SrsAutoFree(SrsAmf0Any, p);
|
|
|
|
|
|
|
|
|
|
EXPECT_FALSE(p->is_string());
|
|
|
|
|
EXPECT_FALSE(p->is_boolean());
|
|
|
|
|
EXPECT_FALSE(p->is_number());
|
|
|
|
|
EXPECT_FALSE(p->is_null());
|
|
|
|
|
EXPECT_FALSE(p->is_undefined());
|
|
|
|
|
EXPECT_FALSE(p->is_object());
|
|
|
|
|
EXPECT_FALSE(p->is_object_eof());
|
|
|
|
|
EXPECT_FALSE(p->is_ecma_array());
|
|
|
|
|
EXPECT_FALSE(!p->is_strict_array());
|
|
|
|
|
EXPECT_FALSE(p->is_date());
|
|
|
|
|
EXPECT_FALSE(!p->is_complex_object());
|
|
|
|
|
EXPECT_TRUE(NULL != p->to_strict_array());
|
|
|
|
|
|
|
|
|
|
char* d = p->human_print(NULL, NULL);
|
|
|
|
|
EXPECT_STREQ("StrictArray (0 items)\n", d);
|
|
|
|
|
delete[] d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsAmf0Any* p = SrsAmf0Any::object();
|
|
|
|
|
SrsAutoFree(SrsAmf0Any, p);
|
|
|
|
|
EXPECT_FALSE(!p->is_complex_object());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsAmf0Any* p = SrsAmf0Any::object_eof();
|
|
|
|
|
SrsAutoFree(SrsAmf0Any, p);
|
|
|
|
|
EXPECT_FALSE(!p->is_complex_object());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsAmf0Any* p = SrsAmf0Any::ecma_array();
|
|
|
|
|
SrsAutoFree(SrsAmf0Any, p);
|
|
|
|
|
EXPECT_FALSE(!p->is_complex_object());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (true) {
|
|
|
|
|
SrsAmf0Any* p = SrsAmf0Any::strict_array();
|
|
|
|
|
SrsAutoFree(SrsAmf0Any, p);
|
|
|
|
|
EXPECT_FALSE(!p->is_complex_object());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|