123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674 |
- #include "CuTest.h"
- #include "aos_log.h"
- #include "aos_util.h"
- #include "aos_string.h"
- #include "aos_status.h"
- #include "aos_transport.h"
- #include "aos_http_io.h"
- #include "oss_auth.h"
- #include "oss_util.h"
- #include "oss_xml.h"
- #include "oss_api.h"
- #include "oss_config.h"
- #include "oss_test_util.h"
- #include "apr_time.h"
- void test_live_setup(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- int is_cname = 0;
- aos_status_t *s = NULL;
- oss_request_options_t *options = NULL;
- oss_acl_e oss_acl = OSS_ACL_PRIVATE;
- //create test bucket
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- s = create_test_bucket(options, TEST_BUCKET_NAME, oss_acl);
- CuAssertIntEquals(tc, 200, s->code);
- aos_pool_destroy(p);
- }
- void test_live_cleanup(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- int is_cname = 0;
- aos_string_t bucket;
- oss_request_options_t *options = NULL;
- aos_table_t *resp_headers = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- //delete test bucket
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- oss_delete_bucket(options, &bucket, &resp_headers);
- apr_sleep(apr_time_from_sec(3));
- aos_pool_destroy(p);
- }
- void test_create_live_channel_default(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- oss_request_options_t *options = NULL;
- aos_status_t *s = NULL;
- aos_list_t publish_url_list;
- aos_list_t play_url_list;
- oss_live_channel_configuration_t *config = NULL;
- oss_live_channel_configuration_t info;
- char *live_channel_name = "test_live_channel_create_def";
- char *live_channel_desc = "my test live channel";
- aos_string_t bucket;
- aos_string_t channel_name;
- oss_live_channel_publish_url_t *publish_url;
- oss_live_channel_play_url_t *play_url;
- char *content = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, 0);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&channel_name, live_channel_name);
- config = oss_create_live_channel_configuration_content(options->pool);
- aos_str_set(&config->name, live_channel_name);
- aos_str_set(&config->description, live_channel_desc);
- // create
- aos_list_init(&publish_url_list);
- aos_list_init(&play_url_list);
- s = oss_create_live_channel(options, &bucket, config, &publish_url_list,
- &play_url_list, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- aos_list_for_each_entry(oss_live_channel_publish_url_t, publish_url, &publish_url_list, node) {
- content = apr_psprintf(p, "%.*s", publish_url->publish_url.len,
- publish_url->publish_url.data);
- CuAssertStrnEquals(tc, AOS_RTMP_PREFIX, strlen(AOS_RTMP_PREFIX), content);
- CuAssertIntEquals(tc, 1, aos_ends_with(&publish_url->publish_url, &channel_name));
- }
- aos_list_for_each_entry(oss_live_channel_play_url_t, play_url, &play_url_list, node) {
- content = apr_psprintf(p, "%.*s", play_url->play_url.len,
- play_url->play_url.data);
- CuAssertStrnEquals(tc, AOS_HTTP_PREFIX, strlen(AOS_HTTP_PREFIX), content);
- CuAssertIntEquals(tc, 1, aos_ends_with(&play_url->play_url, &config->target.play_list_name));
- }
- // get info
- s = oss_get_live_channel_info(options, &bucket, &channel_name, &info, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- content = apr_psprintf(p, "%.*s", info.name.len, info.name.data);
- CuAssertStrEquals(tc, live_channel_name, content);
- content = apr_psprintf(p, "%.*s", info.description.len, info.description.data);
- CuAssertStrEquals(tc, live_channel_desc, content);
- content = apr_psprintf(p, "%.*s", info.status.len, info.status.data);
- CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_ENABLED, content);
- content = apr_psprintf(p, "%.*s", info.target.type.len, info.target.type.data);
- CuAssertStrEquals(tc, LIVE_CHANNEL_DEFAULT_TYPE, content);
- content = apr_psprintf(p, "%.*s", info.target.play_list_name.len, info.target.play_list_name.data);
- CuAssertStrEquals(tc, LIVE_CHANNEL_DEFAULT_PLAYLIST, content);
- CuAssertIntEquals(tc, LIVE_CHANNEL_DEFAULT_FRAG_DURATION, info.target.frag_duration);
- CuAssertIntEquals(tc, LIVE_CHANNEL_DEFAULT_FRAG_COUNT, info.target.frag_count);
- // delete
- s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
- CuAssertIntEquals(tc, 204, s->code);
- aos_pool_destroy(p);
- printf("test_create_live_channel_default ok\n");
- }
- void test_create_live_channel(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- oss_request_options_t *options = NULL;
- aos_status_t *s = NULL;
- aos_list_t publish_url_list;
- aos_list_t play_url_list;
- oss_live_channel_configuration_t *config = NULL;
- oss_live_channel_configuration_t info;
- char *live_channel_name = "test_live_channel_create";
- char *live_channel_desc = "my test live channel,<>{}=?//&";
- aos_string_t bucket;
- aos_string_t channel_name;
- oss_live_channel_publish_url_t *publish_url;
- oss_live_channel_play_url_t *play_url;
- aos_table_t *resp_headers = NULL;
- char *content = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, 0);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&channel_name, live_channel_name);
- config = oss_create_live_channel_configuration_content(options->pool);
- aos_str_set(&config->name, live_channel_name);
- aos_str_set(&config->description, live_channel_desc);
- aos_str_set(&config->status, LIVE_CHANNEL_STATUS_DISABLED);
- aos_str_set(&config->target.type, "HLS");
- aos_str_set(&config->target.play_list_name, "myplay.m3u8");
- config->target.frag_duration = 100;
- config->target.frag_count = 99;
- // create
- aos_list_init(&publish_url_list);
- aos_list_init(&play_url_list);
- s = oss_create_live_channel(options, &bucket, config, &publish_url_list,
- &play_url_list, &resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, resp_headers);
- aos_list_for_each_entry(oss_live_channel_publish_url_t, publish_url, &publish_url_list, node) {
- content = apr_psprintf(p, "%.*s", publish_url->publish_url.len,
- publish_url->publish_url.data);
- CuAssertStrnEquals(tc, AOS_RTMP_PREFIX, strlen(AOS_RTMP_PREFIX), content);
- CuAssertIntEquals(tc, 1, aos_ends_with(&publish_url->publish_url, &channel_name));
- }
- aos_list_for_each_entry(oss_live_channel_play_url_t, play_url, &play_url_list, node) {
- content = apr_psprintf(p, "%.*s", play_url->play_url.len,
- play_url->play_url.data);
- CuAssertStrnEquals(tc, AOS_HTTP_PREFIX, strlen(AOS_HTTP_PREFIX), content);
- CuAssertIntEquals(tc, 1, aos_ends_with(&play_url->play_url, &config->target.play_list_name));
- }
- // get info
- s = oss_get_live_channel_info(options, &bucket, &channel_name, &info, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- content = apr_psprintf(p, "%.*s", info.name.len, info.name.data);
- CuAssertStrEquals(tc, live_channel_name, content);
- content = apr_psprintf(p, "%.*s", info.description.len, info.description.data);
- CuAssertStrEquals(tc, live_channel_desc, content);
- content = apr_psprintf(p, "%.*s", info.status.len, info.status.data);
- CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_DISABLED, content);
- content = apr_psprintf(p, "%.*s", info.target.type.len, info.target.type.data);
- CuAssertStrEquals(tc, "HLS", content);
- content = apr_psprintf(p, "%.*s", info.target.play_list_name.len, info.target.play_list_name.data);
- CuAssertStrEquals(tc, "myplay.m3u8", content);
- CuAssertIntEquals(tc, 100, info.target.frag_duration);
- CuAssertIntEquals(tc, 99, info.target.frag_count);
- // delete
- s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
- CuAssertIntEquals(tc, 204, s->code);
- aos_pool_destroy(p);
- printf("test_create_live_channel ok\n");
- }
- void test_get_live_channel_stat(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- oss_request_options_t *options = NULL;
- aos_status_t *s = NULL;
- aos_list_t publish_url_list;
- aos_list_t play_url_list;
- oss_live_channel_configuration_t *config = NULL;
- oss_live_channel_stat_t live_stat;
- char *live_channel_name = "test_live_channel_stat";
- char *live_channel_desc = "my test live channel";
- aos_string_t bucket;
- aos_string_t channel_name;
- char *content = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, 0);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&channel_name, live_channel_name);
- config = oss_create_live_channel_configuration_content(options->pool);
- aos_str_set(&config->name, live_channel_name);
- aos_str_set(&config->description, live_channel_desc);
- // create
- aos_list_init(&publish_url_list);
- aos_list_init(&play_url_list);
- s = oss_create_live_channel(options, &bucket, config, &publish_url_list,
- &play_url_list, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- // get stat
- s = oss_get_live_channel_stat(options, &bucket, &channel_name, &live_stat, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- content = apr_psprintf(p, "%.*s", live_stat.pushflow_status.len, live_stat.pushflow_status.data);
- CuAssertStrEquals(tc, "Idle", content);
- s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
- CuAssertIntEquals(tc, 204, s->code);
- aos_pool_destroy(p);
- printf("test_get_live_channel_stat ok\n");
- }
- void test_put_live_channel_status(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- oss_request_options_t *options = NULL;
- aos_status_t *s = NULL;
- char *live_channel_name = "test_live_channel_status";
- aos_string_t bucket;
- aos_string_t channel_name;
- aos_string_t channel_stutus;
- oss_live_channel_configuration_t info;
- char *content = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, 0);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&channel_name, live_channel_name);
- // create
- s = create_test_live_channel(options, TEST_BUCKET_NAME, live_channel_name);
- CuAssertIntEquals(tc, 200, s->code);
- // put status
- aos_str_set(&channel_stutus, LIVE_CHANNEL_STATUS_DISABLED);
- s= oss_put_live_channel_status(options, &bucket, &channel_name, &channel_stutus, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- // check by get info
- s = oss_get_live_channel_info(options, &bucket, &channel_name, &info, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- content = apr_psprintf(p, "%.*s", info.name.len, info.name.data);
- CuAssertStrEquals(tc, live_channel_name, content);
- content = apr_psprintf(p, "%.*s", info.status.len, info.status.data);
- CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_DISABLED, content);
- // put status
- aos_str_set(&channel_stutus, LIVE_CHANNEL_STATUS_ENABLED);
- s= oss_put_live_channel_status(options, &bucket, &channel_name, &channel_stutus, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- // check by get info
- s = oss_get_live_channel_info(options, &bucket, &channel_name, &info, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- content = apr_psprintf(p, "%.*s", info.name.len, info.name.data);
- CuAssertStrEquals(tc, live_channel_name, content);
- content = apr_psprintf(p, "%.*s", info.status.len, info.status.data);
- CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_ENABLED, content);
- // delete
- s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
- CuAssertIntEquals(tc, 204, s->code);
- aos_pool_destroy(p);
- printf("test_put_live_channel_status ok\n");
- }
- void test_delete_live_channel(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- oss_request_options_t *options = NULL;
- aos_status_t *s = NULL;
- aos_list_t publish_url_list;
- aos_list_t play_url_list;
- oss_live_channel_configuration_t *config = NULL;
- oss_live_channel_stat_t live_stat;
- char *live_channel_name = "test_live_channel_del";
- char *live_channel_desc = "my test live channel";
- aos_string_t bucket;
- aos_string_t channel_name;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, 0);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&channel_name, live_channel_name);
- config = oss_create_live_channel_configuration_content(options->pool);
- aos_str_set(&config->name, live_channel_name);
- aos_str_set(&config->description, live_channel_desc);
- // create
- aos_list_init(&publish_url_list);
- aos_list_init(&play_url_list);
- s = oss_create_live_channel(options, &bucket, config, &publish_url_list,
- &play_url_list, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- // get stat
- s = oss_get_live_channel_stat(options, &bucket, &channel_name, &live_stat, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- // delete
- s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
- CuAssertIntEquals(tc, 204, s->code);
- // get stat
- s = oss_get_live_channel_stat(options, &bucket, &channel_name, &live_stat, NULL);
- CuAssertIntEquals(tc, 404, s->code);
- CuAssertStrEquals(tc, "NoSuchLiveChannel", s->error_code);
- aos_pool_destroy(p);
- printf("test_delete_live_channel ok\n");
- }
- void test_list_live_channel(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- oss_request_options_t *options = NULL;
- aos_status_t *s = NULL;
- aos_string_t bucket;
- oss_list_live_channel_params_t *params = NULL;
- oss_live_channel_content_t *live_chan;
- char *content = NULL;
- oss_live_channel_publish_url_t *publish_url;
- oss_live_channel_play_url_t *play_url;
- int channel_count = 0;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, 0);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- // create
- s = create_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list1");
- CuAssertIntEquals(tc, 200, s->code);
- s = create_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list2");
- CuAssertIntEquals(tc, 200, s->code);
- s = create_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list3");
- CuAssertIntEquals(tc, 200, s->code);
- s = create_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list4");
- CuAssertIntEquals(tc, 200, s->code);
- s = create_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list5");
- CuAssertIntEquals(tc, 200, s->code);
- // list
- params = oss_create_list_live_channel_params(options->pool);
- aos_str_set(¶ms->prefix, "test_live_channel_list");
- s = oss_list_live_channel(options, &bucket, params, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- channel_count = 0;
- aos_list_for_each_entry(oss_live_channel_content_t, live_chan, ¶ms->live_channel_list, node) {
- channel_count++;
- content = apr_psprintf(p, "%.*s", live_chan->name.len, live_chan->name.data);
- CuAssertStrEquals(tc, apr_psprintf(p, "test_live_channel_list%d", channel_count), content);
- content = apr_psprintf(p, "%.*s", live_chan->description.len, live_chan->description.data);
- CuAssertStrEquals(tc, "live channel description", content);
- content = apr_psprintf(p, "%.*s", live_chan->status.len, live_chan->status.data);
- CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_ENABLED, content);
- content = apr_psprintf(p, "%.*s", live_chan->last_modified.len, live_chan->last_modified.data);
- CuAssertStrnEquals(tc, "201", strlen("201"), content);
- aos_list_for_each_entry(oss_live_channel_publish_url_t, publish_url, &live_chan->publish_url_list, node) {
- content = apr_psprintf(p, "%.*s", publish_url->publish_url.len, publish_url->publish_url.data);
- CuAssertStrnEquals(tc, AOS_RTMP_PREFIX, strlen(AOS_RTMP_PREFIX), content);
- }
- aos_list_for_each_entry(oss_live_channel_play_url_t, play_url, &live_chan->play_url_list, node) {
- content = apr_psprintf(p, "%.*s", play_url->play_url.len, play_url->play_url.data);
- CuAssertStrnEquals(tc, AOS_HTTP_PREFIX, strlen(AOS_HTTP_PREFIX), content);
- }
- }
- CuAssertIntEquals(tc, 5, channel_count);
- // list by prefix
- params = oss_create_list_live_channel_params(options->pool);
- aos_str_set(¶ms->prefix, "test_live_channel_list2");
- s = oss_list_live_channel(options, &bucket, params, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- channel_count = 0;
- aos_list_for_each_entry(oss_live_channel_content_t, live_chan, ¶ms->live_channel_list, node) {
- channel_count++;
- content = apr_psprintf(p, "%.*s", live_chan->name.len, live_chan->name.data);
- CuAssertStrEquals(tc, "test_live_channel_list2", content);
- content = apr_psprintf(p, "%.*s", live_chan->description.len, live_chan->description.data);
- CuAssertStrEquals(tc, "live channel description", content);
- content = apr_psprintf(p, "%.*s", live_chan->status.len, live_chan->status.data);
- CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_ENABLED, content);
- content = apr_psprintf(p, "%.*s", live_chan->last_modified.len, live_chan->last_modified.data);
- CuAssertStrnEquals(tc, "201", strlen("201"), content);
- aos_list_for_each_entry(oss_live_channel_publish_url_t, publish_url, &live_chan->publish_url_list, node) {
- content = apr_psprintf(p, "%.*s", publish_url->publish_url.len, publish_url->publish_url.data);
- CuAssertStrnEquals(tc, AOS_RTMP_PREFIX, strlen(AOS_RTMP_PREFIX), content);
- }
- aos_list_for_each_entry(oss_live_channel_play_url_t, play_url, &live_chan->play_url_list, node) {
- content = apr_psprintf(p, "%.*s", play_url->play_url.len, play_url->play_url.data);
- CuAssertStrnEquals(tc, AOS_HTTP_PREFIX, strlen(AOS_HTTP_PREFIX), content);
- }
- }
- CuAssertIntEquals(tc, 1, channel_count);
- // list by mark
- params = oss_create_list_live_channel_params(options->pool);
- aos_str_set(¶ms->prefix, "test_live_channel_list");
- aos_str_set(¶ms->marker, "test_live_channel_list2");
- s = oss_list_live_channel(options, &bucket, params, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- channel_count = 0;
- aos_list_for_each_entry(oss_live_channel_content_t, live_chan, ¶ms->live_channel_list, node) {
- channel_count++;
- content = apr_psprintf(p, "%.*s", live_chan->name.len, live_chan->name.data);
- CuAssertStrEquals(tc, apr_psprintf(p, "test_live_channel_list%d", channel_count + 2), content);
- content = apr_psprintf(p, "%.*s", live_chan->description.len, live_chan->description.data);
- CuAssertStrEquals(tc, "live channel description", content);
- content = apr_psprintf(p, "%.*s", live_chan->status.len, live_chan->status.data);
- CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_ENABLED, content);
- content = apr_psprintf(p, "%.*s", live_chan->last_modified.len, live_chan->last_modified.data);
- CuAssertStrnEquals(tc, "201", strlen("201"), content);
- aos_list_for_each_entry(oss_live_channel_publish_url_t, publish_url, &live_chan->publish_url_list, node) {
- content = apr_psprintf(p, "%.*s", publish_url->publish_url.len,
- publish_url->publish_url.data);
- CuAssertStrnEquals(tc, AOS_RTMP_PREFIX, strlen(AOS_RTMP_PREFIX), content);
- }
- aos_list_for_each_entry(oss_live_channel_play_url_t, play_url, &live_chan->play_url_list, node) {
- content = apr_psprintf(p, "%.*s", play_url->play_url.len, play_url->play_url.data);
- CuAssertStrnEquals(tc, AOS_HTTP_PREFIX, strlen(AOS_HTTP_PREFIX), content);
- }
- }
- CuAssertIntEquals(tc, 3, channel_count);
- // list by max keys
- params = oss_create_list_live_channel_params(options->pool);
- aos_str_set(¶ms->prefix, "test_live_channel_list");
- params->max_keys = 3;
- s = oss_list_live_channel(options, &bucket, params, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- channel_count = 0;
- aos_list_for_each_entry(oss_live_channel_content_t, live_chan, ¶ms->live_channel_list, node) {
- channel_count++;
- content = apr_psprintf(p, "%.*s", live_chan->name.len, live_chan->name.data);
- CuAssertStrEquals(tc, apr_psprintf(p, "test_live_channel_list%d", channel_count), content);
- content = apr_psprintf(p, "%.*s", live_chan->description.len, live_chan->description.data);
- CuAssertStrEquals(tc, "live channel description", content);
- content = apr_psprintf(p, "%.*s", live_chan->status.len, live_chan->status.data);
- CuAssertStrEquals(tc, LIVE_CHANNEL_STATUS_ENABLED, content);
- content = apr_psprintf(p, "%.*s", live_chan->last_modified.len, live_chan->last_modified.data);
- CuAssertStrnEquals(tc, "201", strlen("201"), content);
- aos_list_for_each_entry(oss_live_channel_publish_url_t, publish_url, &live_chan->publish_url_list, node) {
- content = apr_psprintf(p, "%.*s", publish_url->publish_url.len, publish_url->publish_url.data);
- CuAssertStrnEquals(tc, AOS_RTMP_PREFIX, strlen(AOS_RTMP_PREFIX), content);
- }
- aos_list_for_each_entry(oss_live_channel_play_url_t, play_url, &live_chan->play_url_list, node) {
- content = apr_psprintf(p, "%.*s", play_url->play_url.len, play_url->play_url.data);
- CuAssertStrnEquals(tc, AOS_HTTP_PREFIX, strlen(AOS_HTTP_PREFIX), content);
- }
- }
- CuAssertIntEquals(tc, 3, channel_count);
- s = delete_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list1");
- CuAssertIntEquals(tc, 204, s->code);
- s = delete_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list2");
- CuAssertIntEquals(tc, 204, s->code);
- s = delete_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list3");
- CuAssertIntEquals(tc, 204, s->code);
- s = delete_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list4");
- CuAssertIntEquals(tc, 204, s->code);
- s = delete_test_live_channel(options, TEST_BUCKET_NAME, "test_live_channel_list5");
- CuAssertIntEquals(tc, 204, s->code);
- aos_pool_destroy(p);
- printf("test_list_live_channel ok\n");
- }
- void test_get_live_channel_history(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- oss_request_options_t *options = NULL;
- aos_status_t *s = NULL;
- aos_list_t live_record_list;
- oss_live_record_content_t *live_record;
- char *live_channel_name = "test_live_channel_hist";
- aos_string_t bucket;
- aos_string_t channel_name;
- aos_string_t content;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, 0);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&channel_name, live_channel_name);
- // create
- s = create_test_live_channel(options, TEST_BUCKET_NAME, live_channel_name);
- CuAssertIntEquals(tc, 200, s->code);
- // get history
- aos_list_init(&live_record_list);
- s = oss_get_live_channel_history(options, &bucket, &channel_name, &live_record_list, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- aos_list_for_each_entry(oss_live_record_content_t, live_record, &live_record_list, node) {
- aos_str_set(&content, ".000Z");
- CuAssertIntEquals(tc, 1, aos_ends_with(&live_record->start_time, &content));
- CuAssertIntEquals(tc, 1, aos_ends_with(&live_record->end_time, &content));
- CuAssertTrue(tc, live_record->remote_addr.len >= (int)strlen("0.0.0.0:0"));
- }
- // delete
- s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
- CuAssertIntEquals(tc, 204, s->code);
- aos_pool_destroy(p);
- printf("test_get_live_channel_history ok\n");
- }
- /**
- * Note: the case need put rtmp stream, use command:
- * ffmpeg \-re \-i allstar.flv \-c copy \-f flv "rtmp://oss-live-channel.demo-oss-cn-shenzhen.aliyuncs.com/live/test_live_channel_vod?playlistName=play.m3u8"
- */
- void test_gen_vod_play_list(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- oss_request_options_t *options = NULL;
- aos_status_t *s = NULL;
- char *live_channel_name = "test_live_channel_vod";
- aos_string_t bucket;
- aos_string_t channel_name;
- aos_string_t play_list_name;
- int64_t start_time = 0;
- int64_t end_time = 0;
- oss_acl_e oss_acl;
- aos_table_t *resp_headers = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, 0);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&channel_name, live_channel_name);
- oss_acl = OSS_ACL_PUBLIC_READ_WRITE;
- s = oss_put_bucket_acl(options, &bucket, oss_acl, &resp_headers);
- // create
- s = create_test_live_channel(options, TEST_BUCKET_NAME, live_channel_name);
- CuAssertIntEquals(tc, 200, s->code);
- // post vod
- aos_str_set(&play_list_name, "play.m3u8");
- start_time = apr_time_now() / 1000000 - 3600;
- end_time = apr_time_now() / 1000000 + 3600;
- s = oss_gen_vod_play_list(options, &bucket, &channel_name, &play_list_name,
- start_time, end_time, NULL);
- CuAssertIntEquals(tc, 400, s->code);
- // delete
- s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
- CuAssertIntEquals(tc, 204, s->code);
- aos_pool_destroy(p);
- printf("test_post_vod_play_list ok\n");
- }
- void test_gen_rtmp_signed_url(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- oss_request_options_t *options = NULL;
- aos_status_t *s = NULL;
- char *live_channel_name = "test_live_channel_url";
- aos_string_t bucket;
- aos_string_t channel_name;
- aos_string_t play_list_name;
- oss_acl_e oss_acl;
- aos_table_t *resp_headers = NULL;
- char *rtmp_url = NULL;
- int64_t expires = 0;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, 0);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&channel_name, live_channel_name);
- oss_acl = OSS_ACL_PRIVATE;
- s = oss_put_bucket_acl(options, &bucket, oss_acl, &resp_headers);
- // create
- s = create_test_live_channel(options, TEST_BUCKET_NAME, live_channel_name);
- CuAssertIntEquals(tc, 200, s->code);
- // gen url
- aos_str_set(&play_list_name, "play.m3u8");
- expires = apr_time_now() / 1000000 + 60 * 30;
- rtmp_url = oss_gen_rtmp_signed_url(options, &bucket, &channel_name,
- &play_list_name, expires);
- // manual check passed
- CuAssertStrnEquals(tc, AOS_RTMP_PREFIX, strlen(AOS_RTMP_PREFIX), rtmp_url);
- // delete
- s = oss_delete_live_channel(options, &bucket, &channel_name, NULL);
- CuAssertIntEquals(tc, 204, s->code);
- aos_pool_destroy(p);
- printf("test_gen_rtmp_signed_url ok\n");
- }
- CuSuite *test_oss_live()
- {
- CuSuite* suite = CuSuiteNew();
- SUITE_ADD_TEST(suite, test_live_setup);
- SUITE_ADD_TEST(suite, test_create_live_channel_default);
- SUITE_ADD_TEST(suite, test_create_live_channel);
- SUITE_ADD_TEST(suite, test_put_live_channel_status);
- SUITE_ADD_TEST(suite, test_get_live_channel_stat);
- SUITE_ADD_TEST(suite, test_delete_live_channel);
- SUITE_ADD_TEST(suite, test_list_live_channel);
- SUITE_ADD_TEST(suite, test_get_live_channel_history);
- SUITE_ADD_TEST(suite, test_gen_vod_play_list);
- SUITE_ADD_TEST(suite, test_gen_rtmp_signed_url);
- SUITE_ADD_TEST(suite, test_live_cleanup);
- return suite;
- }
|