123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956 |
- #include "CuTest.h"
- #include "aos_log.h"
- #include "aos_util.h"
- #include "aos_string.h"
- #include "aos_status.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"
- void test_object_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_object_cleanup(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- int is_cname = 0;
- aos_string_t bucket;
- oss_request_options_t *options = NULL;
- char *object_name1 = "oss_test_put_object.ts";
- char *object_name2 = "oss_test_put_object_from_file.jpg";
- char *object_name3 = "oss_test_object_by_url";
- char *object_name4 = "oss_test_append_object";
- char *object_name5 = "oss_test_append_object_from_file";
- char *object_name6 = "oss_test_copy_object";
- char *object_name7 = "video_1.ts";
- char *object_name8 = "video_2.ts";
- char *object_name9 = "oss_test_put_object_from_file2.txt";
- char *object_name10 = "put_object_from_buffer_with_default_content_type";
- 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 object */
- delete_test_object(options, TEST_BUCKET_NAME, object_name1);
- delete_test_object(options, TEST_BUCKET_NAME, object_name2);
- delete_test_object(options, TEST_BUCKET_NAME, object_name3);
- delete_test_object(options, TEST_BUCKET_NAME, object_name4);
- delete_test_object(options, TEST_BUCKET_NAME, object_name5);
- delete_test_object(options, TEST_BUCKET_NAME, object_name6);
- delete_test_object(options, TEST_BUCKET_NAME, object_name7);
- delete_test_object(options, TEST_BUCKET_NAME, object_name8);
- delete_test_object(options, TEST_BUCKET_NAME, object_name9);
- delete_test_object(options, TEST_BUCKET_NAME, object_name10);
- /* 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_put_object_from_buffer(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- char *object_name = "oss_test_put_object.ts";
- char *str = "test oss c sdk";
- aos_status_t *s = NULL;
- int is_cname = 0;
- aos_string_t bucket;
- aos_string_t object;
- aos_table_t *headers = NULL;
- aos_table_t *head_headers = NULL;
- aos_table_t *head_resp_headers = NULL;
- char *content_type = NULL;
- oss_request_options_t *options = NULL;
- /* test put object */
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- headers = aos_table_make(p, 1);
- apr_table_set(headers, "x-oss-meta-author", "oss");
- s = create_test_object(options, TEST_BUCKET_NAME, object_name, str, headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, headers);
- aos_pool_destroy(p);
- /* head object */
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
- init_test_request_options(options, is_cname);
- s = oss_head_object(options, &bucket, &object,
- head_headers, &head_resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, head_resp_headers);
-
- content_type = (char*)(apr_table_get(head_resp_headers, OSS_CONTENT_TYPE));
- CuAssertStrEquals(tc, "video/MP2T", content_type);
- printf("test_put_object_from_buffer ok\n");
- }
- void test_put_object_from_buffer_with_default_content_type(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- char *object_name = "put_object_from_buffer_with_default_content_type";
- char *str = "test oss c sdk";
- aos_status_t *s = NULL;
- int is_cname = 0;
- aos_string_t bucket;
- aos_string_t object;
- aos_table_t *headers = NULL;
- aos_table_t *head_headers = NULL;
- aos_table_t *head_resp_headers = NULL;
- char *content_type = NULL;
- oss_request_options_t *options = NULL;
- /* test put object */
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- headers = aos_table_make(p, 1);
- apr_table_set(headers, "x-oss-meta-author", "oss");
- s = create_test_object(options, TEST_BUCKET_NAME, object_name, str, headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, headers);
- aos_pool_destroy(p);
- /* head object */
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
- init_test_request_options(options, is_cname);
- s = oss_head_object(options, &bucket, &object,
- head_headers, &head_resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, head_resp_headers);
-
- content_type = (char*)(apr_table_get(head_resp_headers, OSS_CONTENT_TYPE));
- CuAssertStrEquals(tc, "application/octet-stream", content_type);
- printf("test_put_object_from_buffer_with_default_content_type ok\n");
- }
- void test_put_object_from_buffer_with_specified(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- char *object_name = "./xxx/./ddd/";
- char *str = "test oss c sdk";
- aos_status_t *s = NULL;
- int is_cname = 0;
- aos_string_t bucket;
- aos_string_t object;
- aos_table_t *headers = NULL;
- aos_table_t *head_headers = NULL;
- aos_table_t *head_resp_headers = NULL;
- oss_request_options_t *options = NULL;
- /* test put object */
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- headers = aos_table_make(p, 1);
- apr_table_set(headers, "x-oss-meta-author", "oss");
- s = create_test_object(options, TEST_BUCKET_NAME, object_name, str, headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, headers);
- aos_pool_destroy(p);
- /* head object */
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
- init_test_request_options(options, is_cname);
- s = oss_head_object(options, &bucket, &object,
- head_headers, &head_resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, head_resp_headers);
- printf("test_put_object_from_buffer_with_specified ok\n");
- }
- void test_put_object_from_file(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- char *object_name = "video_1.ts";
- char *filename = __FILE__;
- aos_string_t bucket;
- aos_string_t object;
- aos_status_t *s = NULL;
- oss_request_options_t *options = NULL;
- int is_cname = 0;
- aos_table_t *headers = NULL;
- aos_table_t *head_headers = NULL;
- aos_table_t *head_resp_headers = NULL;
- char *content_type = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- headers = aos_table_make(p, 5);
- s = create_test_object_from_file(options, TEST_BUCKET_NAME,
- object_name, filename, headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, headers);
- aos_pool_destroy(p);
- /* head object */
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
- init_test_request_options(options, is_cname);
- s = oss_head_object(options, &bucket, &object,
- head_headers, &head_resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, head_resp_headers);
-
- content_type = (char*)(apr_table_get(head_resp_headers, OSS_CONTENT_TYPE));
- CuAssertStrEquals(tc, "application/octet-stream", content_type);
- printf("test_put_object_from_file ok\n");
- }
- void test_put_object_with_large_length_header(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- char *object_name = "video_2.ts";
- char *filename = __FILE__;
- aos_status_t *s = NULL;
- oss_request_options_t *options = NULL;
- int is_cname = 0;
- int i = 0;
- int header_length = 0;
- aos_table_t *headers = NULL;
- char *user_meta = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- header_length = 1024 * 5;
- user_meta = (char*)calloc(header_length, 1);
- for (; i < header_length - 1; i++) {
- user_meta[i] = 'a';
- }
- user_meta[header_length - 1] = '\0';
- headers = aos_table_make(p, 2);
- apr_table_set(headers, "x-oss-meta-user-meta", user_meta);
- s = create_test_object_from_file(options, TEST_BUCKET_NAME,
- object_name, filename, headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, headers);
- free(user_meta);
- aos_pool_destroy(p);
- printf("test_put_object_with_large_length_header_back_bound ok\n");
- }
- void test_put_object_from_file_with_content_type(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- char *object_name = "oss_test_put_object_from_file2.txt";
- char *filename = __FILE__;
- aos_string_t bucket;
- aos_string_t object;
- aos_status_t *s = NULL;
- oss_request_options_t *options = NULL;
- int is_cname = 0;
- aos_table_t *headers = NULL;
- aos_table_t *head_headers = NULL;
- aos_table_t *head_resp_headers = NULL;
- char *content_type = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- headers = aos_table_make(options->pool, 1);
- apr_table_set(headers, OSS_CONTENT_TYPE, "image/jpeg");
- s = create_test_object_from_file(options, TEST_BUCKET_NAME,
- object_name, filename, headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, headers);
- aos_pool_destroy(p);
- /* head object */
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
- init_test_request_options(options, is_cname);
- s = oss_head_object(options, &bucket, &object,
- head_headers, &head_resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, head_resp_headers);
-
- content_type = (char*)(apr_table_get(head_resp_headers, OSS_CONTENT_TYPE));
- CuAssertStrEquals(tc, "image/jpeg", content_type);
- printf("test_put_object_from_file ok\n");
- }
- void test_get_object_to_buffer(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- aos_string_t bucket;
- char *object_name = "oss_test_put_object.ts";
- aos_string_t object;
- int is_cname = 0;
- oss_request_options_t *options = NULL;
- aos_table_t *headers = NULL;
- aos_table_t *params = NULL;
- aos_table_t *resp_headers = NULL;
- aos_status_t *s = NULL;
- aos_list_t buffer;
- aos_buf_t *content = NULL;
- char *expect_content = "test oss c sdk";
- char *buf = NULL;
- int64_t len = 0;
- int64_t size = 0;
- int64_t pos = 0;
- char *content_type = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
- aos_list_init(&buffer);
- /* test get object to buffer */
- s = oss_get_object_to_buffer(options, &bucket, &object, headers,
- params, &buffer, &resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, resp_headers);
- /* get buffer len */
- len = aos_buf_list_len(&buffer);
- buf = aos_pcalloc(p, (apr_size_t)(len + 1));
- buf[len] = '\0';
- /* copy buffer content to memory */
- aos_list_for_each_entry(aos_buf_t, content, &buffer, node) {
- size = aos_buf_size(content);
- memcpy(buf + pos, content->pos, (size_t)size);
- pos += size;
- }
- CuAssertStrEquals(tc, expect_content, buf);
- content_type = (char*)(apr_table_get(resp_headers, OSS_CONTENT_TYPE));
- CuAssertStrEquals(tc, "video/MP2T", content_type);
- aos_pool_destroy(p);
- printf("test_get_object_to_buffer ok\n");
- }
- void test_get_object_to_buffer_with_range(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- aos_string_t bucket;
- char *object_name = "oss_test_put_object.ts";
- aos_string_t object;
- int is_cname = 0;
- oss_request_options_t *options = NULL;
- aos_table_t *headers = NULL;
- aos_table_t *params = NULL;
- aos_table_t *resp_headers = NULL;
- aos_status_t *s = NULL;
- aos_list_t buffer;
- aos_buf_t *content = NULL;
- char *expect_content = "oss c sdk";
- char *buf = NULL;
- int64_t len = 0;
- int64_t size = 0;
- int64_t pos = 0;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
- headers = aos_table_make(p, 1);
- apr_table_set(headers, "Range", " bytes=5-13");
- aos_list_init(&buffer);
- /* test get object to buffer */
- s = oss_get_object_to_buffer(options, &bucket, &object, headers,
- params, &buffer, &resp_headers);
- CuAssertIntEquals(tc, 206, s->code);
- CuAssertPtrNotNull(tc, resp_headers);
- /* get buffer len */
- len = aos_buf_list_len(&buffer);
- buf = aos_pcalloc(p, (apr_size_t)(len + 1));
- buf[len] = '\0';
- /* copy buffer content to memory */
- aos_list_for_each_entry(aos_buf_t, content, &buffer, node) {
- size = aos_buf_size(content);
- memcpy(buf + pos, content->pos, (size_t)size);
- pos += size;
- }
- CuAssertStrEquals(tc, expect_content, buf);
- aos_pool_destroy(p);
- printf("test_get_object_to_buffer_with_range ok\n");
- }
- void test_get_object_to_file(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- aos_string_t bucket;
- char *object_name = "oss_test_put_object_from_file2.txt";
- aos_string_t object;
- char *filename = "oss_test_get_object_to_file";
- char *source_filename = __FILE__;
- aos_string_t file;
- oss_request_options_t *options = NULL;
- int is_cname = 0;
- aos_table_t *headers = NULL;
- aos_table_t *params = NULL;
- aos_table_t *resp_headers = NULL;
- aos_status_t *s = NULL;
- char *content_type = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
- aos_str_set(&file, filename);
- /* test get object to file */
- s = oss_get_object_to_file(options, &bucket, &object, headers,
- params, &file, &resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertIntEquals(tc, get_file_size(source_filename), get_file_size(filename));
- content_type = (char*)(apr_table_get(resp_headers, OSS_CONTENT_TYPE));
- CuAssertStrEquals(tc, "image/jpeg", content_type);
- CuAssertPtrNotNull(tc, resp_headers);
- remove(filename);
- aos_pool_destroy(p);
- printf("test_get_object_to_file ok\n");
- }
- void test_head_object(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- aos_string_t bucket;
- aos_string_t object;
- char *object_name = "oss_test_put_object.ts";
- int is_cname = 0;
- oss_request_options_t *options = NULL;
- aos_table_t *headers = NULL;
- aos_table_t *resp_headers = NULL;
- aos_status_t *s = NULL;
- char *user_meta = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
- headers = aos_table_make(p, 0);
- /* test head object */
- s = oss_head_object(options, &bucket, &object, headers, &resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, resp_headers);
-
- user_meta = (char*)(apr_table_get(resp_headers, "x-oss-meta-author"));
- CuAssertStrEquals(tc, "oss", user_meta);
- aos_pool_destroy(p);
- printf("test_head_object ok\n");
- }
- void test_head_object_with_not_exist(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- aos_string_t bucket;
- aos_string_t object;
- char *object_name = "not_exist.object";
- int is_cname = 0;
- oss_request_options_t *options = NULL;
- aos_table_t *headers = NULL;
- aos_table_t *resp_headers = NULL;
- aos_status_t *s = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
- headers = aos_table_make(p, 0);
- /* test head object */
- s = oss_head_object(options, &bucket, &object, headers, &resp_headers);
- CuAssertIntEquals(tc, 404, s->code);
- CuAssertStrEquals(tc, "UnknownError", s->error_code);
- CuAssertTrue(tc, NULL == s->error_msg);
- CuAssertTrue(tc, 0 != strlen(s->req_id));
- CuAssertPtrNotNull(tc, resp_headers);
- aos_pool_destroy(p);
- printf("test_head_object ok\n");
- }
- void test_delete_object(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- aos_string_t bucket;
- char *object_name = "oss_test_put_object";
- aos_string_t object;
- int is_cname = 0;
- oss_request_options_t *options = NULL;
- aos_table_t *resp_headers = NULL;
- aos_status_t *s = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
-
- /* test delete object */
- s = oss_delete_object(options, &bucket, &object, &resp_headers);
- CuAssertIntEquals(tc, 204, s->code);
- CuAssertPtrNotNull(tc, resp_headers);
- aos_pool_destroy(p);
- printf("test_delete_object ok\n");
- }
- void test_copy_object(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- aos_string_t source_bucket;
- char *source_object_name = "oss_test_put_object.ts";
- aos_string_t source_object;
- aos_string_t dest_bucket;
- char *dest_object_name = "oss_test_copy_object";
- aos_string_t dest_object;
- oss_request_options_t *options = NULL;
- int is_cname = 0;
- aos_table_t *headers = NULL;
- aos_table_t *resp_headers = NULL;
- aos_status_t *s = NULL;
- aos_table_t *head_headers = NULL;
- aos_table_t *head_resp_headers = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- aos_str_set(&source_bucket, TEST_BUCKET_NAME);
- aos_str_set(&source_object, source_object_name);
- aos_str_set(&dest_bucket, TEST_BUCKET_NAME);
- aos_str_set(&dest_object, dest_object_name);
- headers = aos_table_make(p, 5);
- /* test copy object */
- s = oss_copy_object(options, &source_bucket, &source_object,
- &dest_bucket, &dest_object, headers, &resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, resp_headers);
- aos_pool_destroy(p);
- apr_sleep(apr_time_from_sec(1));
- /* head object */
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- s = oss_head_object(options, &dest_bucket, &dest_object,
- head_headers, &head_resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, head_resp_headers);
- aos_pool_destroy(p);
- printf("test_copy_object ok\n");
- }
- void test_copy_object_with_source_url_encode(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- aos_string_t source_bucket;
- char *source_object_name = "y9n/g/%E9%98%B4%E9%98%B3%E5%B8%88-%E9%A3%9F%E6%A2%A6%E8%B2%98.ts";
- char *filename = __FILE__;
- aos_string_t source_object;
- aos_string_t dest_bucket;
- char *dest_object_name = "oss_test_copy_object";
- aos_string_t dest_object;
- oss_request_options_t *options = NULL;
- int is_cname = 0;
- aos_table_t *resp_headers = NULL;
- aos_status_t *s = NULL;
- aos_table_t *head_headers = NULL;
- aos_table_t *head_resp_headers = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- aos_str_set(&source_bucket, TEST_BUCKET_NAME);
- aos_str_set(&source_object, source_object_name);
- aos_str_set(&dest_bucket, TEST_BUCKET_NAME);
- aos_str_set(&dest_object, dest_object_name);
- /* put object */
- s = create_test_object_from_file(options, TEST_BUCKET_NAME,
- source_object_name, filename, NULL);
- CuAssertIntEquals(tc, 200, s->code);
- aos_pool_destroy(p);
- /* test copy object */
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- s = oss_copy_object(options, &source_bucket, &source_object,
- &dest_bucket, &dest_object, NULL, &resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, resp_headers);
- aos_pool_destroy(p);
- apr_sleep(apr_time_from_sec(1));
- /* head object */
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- s = oss_head_object(options, &dest_bucket, &dest_object,
- head_headers, &head_resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, head_resp_headers);
- /* delete object */
- s = oss_delete_object(options, &source_bucket, &source_object, &resp_headers);
- CuAssertIntEquals(tc, 204, s->code);
- s = oss_delete_object(options, &dest_bucket, &dest_object, &resp_headers);
- CuAssertIntEquals(tc, 204, s->code);
- aos_pool_destroy(p);
- printf("test_copy_object_with_source_url_encode ok\n");
- }
- void test_copy_object_negative(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- aos_string_t source_bucket;
- char *source_object_name = NULL;
- aos_string_t source_object;
- aos_string_t dest_bucket;
- char *dest_object_name = "oss_test_copy_object";
- aos_string_t dest_object;
- oss_request_options_t *options = NULL;
- int is_cname = 0;
- aos_status_t *s = NULL;
- char buffer[AOS_MAX_QUERY_ARG_LEN+1];
- memset(buffer, 'A', AOS_MAX_QUERY_ARG_LEN);
- buffer[AOS_MAX_QUERY_ARG_LEN] = '\0';
- source_object_name = buffer;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- aos_str_set(&source_bucket, TEST_BUCKET_NAME);
- aos_str_set(&source_object, source_object_name);
- aos_str_set(&dest_bucket, TEST_BUCKET_NAME);
- aos_str_set(&dest_object, dest_object_name);
- /* test copy object */
- s = oss_copy_object(options, &source_bucket, &source_object,
- &dest_bucket, &dest_object, NULL, NULL);
- CuAssertIntEquals(tc, 400, s->code);
- CuAssertStrEquals(tc, "InvalidObjectName", s->error_code);
- aos_pool_destroy(p);
- printf("test_copy_object_negative ok\n");
- }
- void test_object_by_url(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- oss_request_options_t *options = NULL;
- aos_table_t *headers = NULL;
- aos_table_t *params = NULL;
- aos_table_t *resp_headers = NULL;
- aos_http_request_t *req = NULL;
- aos_list_t buffer;
- aos_status_t *s = NULL;
- aos_string_t url;
- apr_time_t now;
- int two_minute = 120;
- int is_cname = 0;
- char *object_name = "oss_test_object_by_url";
- aos_string_t bucket;
- aos_string_t object;
- char *str = "test oss c sdk for object url api";
- char *filename = __FILE__;
- char *filename_download = "oss_test_object_by_url";
- aos_string_t file;
- int64_t effective_time;
- char *url_str = NULL;
- aos_buf_t *content = NULL;
-
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- req = aos_http_request_create(p);
- headers = aos_table_make(p, 0);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
- aos_str_set(&file, filename);
- aos_list_init(&buffer);
- now = apr_time_now();
- effective_time = now / 1000000 + two_minute;
- /* test effective url for put_object_from_buffer */
- req->method = HTTP_PUT;
- url_str = gen_test_signed_url(options, TEST_BUCKET_NAME,
- object_name, effective_time, req);
- aos_str_set(&url, url_str);
- aos_list_init(&buffer);
- content = aos_buf_pack(p, str, strlen(str));
- aos_list_add_tail(&content->node, &buffer);
- s = oss_put_object_from_buffer_by_url(options, &url,
- &buffer, headers, &resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, resp_headers);
- /* test effective url for put_object_from_file */
- resp_headers = NULL;
- s = oss_put_object_from_file_by_url(options, &url, &file,
- headers, &resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, resp_headers);
- /* test effective url for get_object_to_buffer */
- req->method = HTTP_GET;
- url_str = gen_test_signed_url(options, TEST_BUCKET_NAME,
- object_name, effective_time, req);
- aos_str_set(&url, url_str);
- s = oss_get_object_to_buffer_by_url(options, &url, headers, params,
- &buffer, &resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- /* test effective url for get_object_to_file */
- resp_headers = NULL;
- aos_str_set(&file, filename_download);
- s = oss_get_object_to_file_by_url(options, &url, headers,
- headers, &file, &resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertIntEquals(tc, get_file_size(filename), get_file_size(filename_download));
- CuAssertPtrNotNull(tc, resp_headers);
- /* test effective url for head_object */
- resp_headers = NULL;
- req->method = HTTP_HEAD;
- url_str = gen_test_signed_url(options, TEST_BUCKET_NAME,
- object_name, effective_time, req);
- aos_str_set(&url, url_str);
- s = oss_head_object_by_url(options, &url, headers, &resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, resp_headers);
- remove(filename_download);
- aos_pool_destroy(p);
- printf("test_object_by_url ok\n");
- }
- void test_append_object_from_buffer(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- char *object_name = "oss_test_append_object";
- aos_string_t bucket;
- aos_string_t object;
- char *str = "test oss c sdk";
- aos_status_t *s = NULL;
- int is_cname = 0;
- int64_t position = 0;
- aos_table_t *headers = NULL;
- aos_table_t *headers1 = NULL;
- aos_table_t *resp_headers = NULL;
- oss_request_options_t *options = NULL;
- aos_list_t buffer;
- aos_buf_t *content = NULL;
- char *next_append_position = NULL;
- /* test append object */
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- headers = aos_table_make(p, 0);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
- s = oss_head_object(options, &bucket, &object, headers, &resp_headers);
- if(s->code == 200) {
- next_append_position = (char*)(apr_table_get(resp_headers,
- "x-oss-next-append-position"));
- position = atoi(next_append_position);
- }
- CuAssertPtrNotNull(tc, resp_headers);
- /* append object */
- resp_headers = NULL;
- headers1 = aos_table_make(p, 0);
- aos_list_init(&buffer);
- content = aos_buf_pack(p, str, strlen(str));
- aos_list_add_tail(&content->node, &buffer);
- s = oss_append_object_from_buffer(options, &bucket, &object,
- position, &buffer, headers1, &resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, resp_headers);
- aos_pool_destroy(p);
- printf("test_append_object_from_buffer ok\n");
- }
- void test_append_object_from_file(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- char *object_name = "oss_test_append_object_from_file";
- aos_string_t bucket;
- aos_string_t object;
- char *filename = __FILE__;
- aos_string_t append_file;
- aos_status_t *s = NULL;
- int is_cname = 0;
- int64_t position = 0;
- aos_table_t *headers = NULL;
- aos_table_t *resp_headers = NULL;
- oss_request_options_t *options = NULL;
- /* test append object */
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- headers = aos_table_make(p, 0);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
- aos_str_set(&append_file, filename);
- s = oss_append_object_from_file(options, &bucket, &object, position,
- &append_file, headers, &resp_headers);
- CuAssertIntEquals(tc, 200, s->code);
- CuAssertPtrNotNull(tc, resp_headers);
- aos_pool_destroy(p);
- printf("test_append_object_from_file ok\n");
- }
- void test_get_not_exist_object_to_file(CuTest *tc)
- {
- aos_pool_t *p = NULL;
- aos_string_t bucket;
- char *object_name = "oss_test_put_object_from_file_not_exist_.txt";
- aos_string_t object;
- char *filename = "oss_test_get_object_to_file_not_exist";
- aos_string_t file;
- oss_request_options_t *options = NULL;
- int is_cname = 0;
- aos_table_t *headers = NULL;
- aos_table_t *params = NULL;
- aos_table_t *resp_headers = NULL;
- aos_status_t *s = NULL;
- aos_pool_create(&p, NULL);
- options = oss_request_options_create(p);
- init_test_request_options(options, is_cname);
- aos_str_set(&bucket, TEST_BUCKET_NAME);
- aos_str_set(&object, object_name);
- aos_str_set(&file, filename);
- /* test get object to file */
- s = oss_get_object_to_file(options, &bucket, &object, headers,
- params, &file, &resp_headers);
- CuAssertIntEquals(tc, 404, s->code);
- CuAssertIntEquals(tc, -1, get_file_size(filename));
- aos_pool_destroy(p);
- printf("test_get_not_exist_object_to_file ok\n");
- }
- CuSuite *test_oss_object()
- {
- CuSuite* suite = CuSuiteNew();
- SUITE_ADD_TEST(suite, test_object_setup);
- SUITE_ADD_TEST(suite, test_put_object_from_buffer);
- SUITE_ADD_TEST(suite, test_put_object_from_file);
- SUITE_ADD_TEST(suite, test_put_object_from_buffer_with_specified);
- SUITE_ADD_TEST(suite, test_get_object_to_buffer);
- SUITE_ADD_TEST(suite, test_get_object_to_buffer_with_range);
- SUITE_ADD_TEST(suite, test_put_object_from_file_with_content_type);
- SUITE_ADD_TEST(suite, test_put_object_from_buffer_with_default_content_type);
- SUITE_ADD_TEST(suite, test_put_object_with_large_length_header);
- SUITE_ADD_TEST(suite, test_get_object_to_file);
- SUITE_ADD_TEST(suite, test_head_object);
- SUITE_ADD_TEST(suite, test_head_object_with_not_exist);
- SUITE_ADD_TEST(suite, test_copy_object);
- SUITE_ADD_TEST(suite, test_copy_object_with_source_url_encode);
- SUITE_ADD_TEST(suite, test_copy_object_negative);
- SUITE_ADD_TEST(suite, test_object_by_url);
- SUITE_ADD_TEST(suite, test_delete_object);
- SUITE_ADD_TEST(suite, test_append_object_from_buffer);
- SUITE_ADD_TEST(suite, test_append_object_from_file);
- SUITE_ADD_TEST(suite, test_object_cleanup);
-
- return suite;
- }
|