From fc7b40b98f90e44d76fd4df8d0457370b972e9ca Mon Sep 17 00:00:00 2001 From: huberyxxiao Date: Thu, 6 Apr 2023 15:49:49 +0800 Subject: [PATCH 1/4] add ut;fix test_utils --- include/cos_api.h | 4 + include/op/bucket_op.h | 14 ++- include/request/data_process_req.h | 23 ++++ include/response/data_process_resp.h | 12 ++ include/util/test_utils.h | 2 + src/cos_api.cpp | 7 +- src/op/bucket_op.cpp | 7 ++ src/response/data_process_resp.cpp | 55 +++++---- src/util/test_utils.cpp | 4 + unittest/src/async_op_test.cpp | 60 +++++++++- unittest/src/bucket_op_test.cpp | 53 +++++++++ unittest/src/object_op_test.cpp | 161 +++++++++++++++++++++++++- unittest/src/object_response_test.cpp | 2 +- 13 files changed, 374 insertions(+), 30 deletions(-) diff --git a/include/cos_api.h b/include/cos_api.h index 08c10fb..bc9834e 100644 --- a/include/cos_api.h +++ b/include/cos_api.h @@ -835,6 +835,10 @@ class CosAPI { // https://cloud.tencent.com/document/product/436/54058 CosResult DocPreview(const DocPreviewReq& req, DocPreviewResp* resp); + /*** 存储桶绑定文档预览 ***/ + CosResult CreateDocBucket(const CreateDocBucketReq& req, + CreateDocBucketResp* resp); + /*** 提交一个文档预览任务 ***/ // https://cloud.tencent.com/document/product/436/54056 CosResult CreateDocProcessJobs(const CreateDocProcessJobsReq& req, diff --git a/include/op/bucket_op.h b/include/op/bucket_op.h index 890390b..2fb2f78 100644 --- a/include/op/bucket_op.h +++ b/include/op/bucket_op.h @@ -412,6 +412,14 @@ class BucketOp : public BaseOp { CosResult PutBucketToCI(const PutBucketToCIReq& req, PutBucketToCIResp* resp); + /// \brief 开通文档预览 + /// \param req CreateDocBucket请求 + /// \param resp CreateDocBucket返回 + /// + /// \return 本次请求的调用情况(如状态码等) + CosResult CreateDocBucket(const CreateDocBucketReq& req, + CreateDocBucketResp* resp); + /// \brief 提交文档转码任务 /// \brief https://cloud.tencent.com/document/product/436/54056 /// \param req CreateDocProcessJobs请求 @@ -467,10 +475,10 @@ class BucketOp : public BaseOp { /// \brief 开通媒体处理 /// \brief https://cloud.tencent.com/document/product/436/72824 - /// \param req DescribeMediaBuckets请求 - /// \param resp DescribeMediaBuckets返回 + /// \param req CreateMediaBucketReq请求 + /// \param resp CreateMediaBucketResp返回 /// - /// \return 本次请求的调用情况(如状态码等) + /// \return 本次请求的调用情况(如状态码等) CosResult CreateMediaBucket(const CreateMediaBucketReq& req, CreateMediaBucketResp* resp); /// \brief 获取媒体文件信息 diff --git a/include/request/data_process_req.h b/include/request/data_process_req.h index dbb1b48..0cd560b 100644 --- a/include/request/data_process_req.h +++ b/include/request/data_process_req.h @@ -331,6 +331,18 @@ struct BucketInfo { } }; +struct CreateDocBucketResult { + std::string request_id; // 请求的唯一ID + BucketInfo doc_bucket; // 媒体Bucket + std::string to_string() const { + std::stringstream ss; + ss << "request_id: " << request_id << std::endl; + ss << doc_bucket.to_string() << std::endl; + ss << std::endl; + return ss.str(); + } +}; + struct DocBucketResponse { std::string request_id; // 请求的唯一 ID int total_count; // 文档预览 Bucket 总数 @@ -667,6 +679,17 @@ class GetQRcodeReq : public ObjectReq { void EnableCover() { AddParam("cover", "1"); } }; +class CreateDocBucketReq : public BucketReq{ + public: + CreateDocBucketReq(const std::string& bucket_name) : BucketReq(bucket_name) { + m_method = "POST"; + m_path = "/docbucket"; + SetHttps(); + } + + virtual ~CreateDocBucketReq() {} +}; + class DescribeDocProcessBucketsReq : public BaseReq { public: DescribeDocProcessBucketsReq() { diff --git a/include/response/data_process_resp.h b/include/response/data_process_resp.h index d55fcf9..d8f47fb 100644 --- a/include/response/data_process_resp.h +++ b/include/response/data_process_resp.h @@ -205,6 +205,18 @@ class PutBucketToCIResp : public BaseResp { virtual ~PutBucketToCIResp() {} }; +class CreateDocBucketResp : public BaseResp { + public: + CreateDocBucketResp() {} + virtual ~CreateDocBucketResp() {} + virtual bool ParseFromXmlString(const std::string& body); + + CreateDocBucketResult GetResult() const { return m_result; } + + private: + CreateDocBucketResult m_result; +}; + class CreateMediaBucketResp : public BaseResp { public: CreateMediaBucketResp() {} diff --git a/include/util/test_utils.h b/include/util/test_utils.h index 6f2d7a2..8feaf49 100644 --- a/include/util/test_utils.h +++ b/include/util/test_utils.h @@ -16,9 +16,11 @@ class TestUtils { static std::string CalcStringMd5(const std::string& str); static std::string CalcStreamSHA1(std::istream& is); static std::string GetEnvVar(const std::string& env_var_name); + #if defined(__linux__) static bool IsDirectoryExists(const std::string& path); static bool MakeDirectory(const std::string& path); static bool RemoveDirectory(const std::string& path); + #endif }; #define GetEnvVar TestUtils::GetEnvVar diff --git a/src/cos_api.cpp b/src/cos_api.cpp index 96c51d6..260fc7a 100644 --- a/src/cos_api.cpp +++ b/src/cos_api.cpp @@ -713,7 +713,7 @@ CosResult CosAPI::MoveObject(const MoveObjectReq& req) { } CosResult CosAPI::PutBucketToCI(const PutBucketToCIReq& req, PutBucketToCIResp* resp) { - return m_bucket_op.PutBucketToCI(req, resp); + return m_bucket_op.PutBucketToCI(req, resp); } CosResult CosAPI::PutImage(PutImageByFileReq& req, @@ -737,6 +737,11 @@ CosAPI::DescribeDocProcessBuckets(const DescribeDocProcessBucketsReq& req, return m_object_op.DescribeDocProcessBuckets(req, resp); } +CosResult CosAPI::CreateDocBucket(const CreateDocBucketReq& req, + CreateDocBucketResp* resp) { + return m_bucket_op.CreateDocBucket(req, resp); +} + CosResult CosAPI::DocPreview(const DocPreviewReq& req, DocPreviewResp* resp) { return m_object_op.DocPreview(req, resp); } diff --git a/src/op/bucket_op.cpp b/src/op/bucket_op.cpp index 2ed9e3c..a0a26d1 100644 --- a/src/op/bucket_op.cpp +++ b/src/op/bucket_op.cpp @@ -589,6 +589,13 @@ CosResult BucketOp::ProcessReq(const BucketReq& req, BaseResp* resp, } } +CosResult BucketOp::CreateDocBucket(const CreateDocBucketReq& req, + CreateDocBucketResp* resp) { + std::string host = CosSysConfig::GetCIHost(req.GetBucketName(), m_config->GetRegion()); + std::string path = req.GetPath(); + return NormalAction(host, path, req, "", false, resp); +} + CosResult BucketOp::CreateDocProcessJobs(const CreateDocProcessJobsReq& req, CreateDocProcessJobsResp* resp) { return ProcessReq(req, resp, true); diff --git a/src/response/data_process_resp.cpp b/src/response/data_process_resp.cpp index dd4af3a..1734182 100644 --- a/src/response/data_process_resp.cpp +++ b/src/response/data_process_resp.cpp @@ -231,6 +231,39 @@ bool DescribeDocProcessBucketsResp::ParseFromXmlString( return true; } +bool CreateDocBucketResp::ParseFromXmlString(const std::string& body) { + std::string tmp_body = body; + rapidxml::xml_document<> doc; + + if (!StringUtil::StringToXml(&tmp_body[0], &doc)) { + SDK_LOG_ERR("Parse string to xml doc error, xml_body=%s", body.c_str()); + return false; + } + + rapidxml::xml_node<>* root = doc.first_node("Response"); + if (NULL == root) { + SDK_LOG_ERR("Missing root node Response, xml_body=%s", body.c_str()); + return false; + } + + rapidxml::xml_node<>* node = root->first_node(); + for (; node != NULL; node = node->next_sibling()) { + const std::string& node_name = node->name(); + if ("RequestId" == node_name) { + m_result.request_id = node->value(); + } else if ("DocBucket" == node_name) { + BucketInfo bucket_info; + DescribeDocProcessBucketsResp::ParseBucketInfo(node, bucket_info); + m_result.doc_bucket = bucket_info; + } else { + SDK_LOG_WARN("Unknown field in Response, field_name=%s", + node_name.c_str()); + return false; + } + } + return true; +} + bool DescribeDocProcessBucketsResp::ParseBucketInfo(rapidxml::xml_node<>* root, BucketInfo& bucket_info) { rapidxml::xml_node<>* node = root->first_node(); @@ -337,10 +370,6 @@ bool DocProcessJobBase::ParseJobsDetail(rapidxml::xml_node<>* root, jobs_detail.input.object = object_node->value(); } else if ("Operation" == node_name) { ParseOperation(jobs_detail_node, jobs_detail.operation); - } else { - SDK_LOG_WARN("Unknown field in JobsDetail, field_name=%s", - node_name.c_str()); - return false; } } return true; @@ -367,9 +396,6 @@ bool DocProcessJobBase::ParseOperation(rapidxml::xml_node<>* root, operation.output.bucket = output_node->value(); } } - } else { - SDK_LOG_WARN("Unknown field in Operation, field_name=%s", - node_name.c_str()); } } return true; @@ -408,9 +434,6 @@ bool DocProcessJobBase::ParseDocProcess(rapidxml::xml_node<>* root, doc_process.quality = StringUtil::StringToInt(doc_process_node->value()); } else if (doc_process_node_name == "Zoom") { doc_process.zoom = StringUtil::StringToInt(doc_process_node->value()); - } else { - SDK_LOG_WARN("Unknown field in DocProcess, field_name=%s", - doc_process_node_name.c_str()); } } return true; @@ -461,9 +484,6 @@ bool DocProcessJobBase::ParseDocProcessResult( } else if (doc_process_result_node_name == "TotalSheetCount") { doc_process_result.total_sheetcount = StringUtil::StringToInt(doc_process_result_node->value()); - } else { - SDK_LOG_WARN("Unknown field in DocProcessResult, field_name=%s", - doc_process_result_node_name.c_str()); } } return true; @@ -554,10 +574,6 @@ bool DocProcessQueueBase::ParseQueueList(rapidxml::xml_node<>* root, queue_list.bucket_id = queue_list_node->value(); } else if ("Category" == queue_list_node_name) { queue_list.category = queue_list_node->value(); - } else { - SDK_LOG_WARN("Unknown field in QueueList, field_name=%s", - queue_list_node_name.c_str()); - return false; } } return true; @@ -593,10 +609,6 @@ bool DescribeDocProcessQueuesResp::ParseFromXmlString(const std::string& body) { ParseQueueList(node, m_queue_list); } else if ("NonExistPIDs" == node_name) { ParseNonExistPIDs(node, m_non_exist_pids); - } else { - SDK_LOG_WARN("Unknown field in Response, field_name=%s", - node_name.c_str()); - return false; } } return true; @@ -671,6 +683,7 @@ bool DescribeMediaBucketsResp::ParseFromXmlString(const std::string& body) { } return true; } + bool CreateMediaBucketResp::ParseFromXmlString(const std::string& body) { std::string tmp_body = body; rapidxml::xml_document<> doc; diff --git a/src/util/test_utils.cpp b/src/util/test_utils.cpp index 99e08ef..e6c9b11 100644 --- a/src/util/test_utils.cpp +++ b/src/util/test_utils.cpp @@ -5,9 +5,11 @@ #include #include +#if defined(__linux__) #include #include #include +#endif #include "Poco/DigestStream.h" #include "Poco/MD5Engine.h" @@ -80,6 +82,7 @@ std::string TestUtils::GetEnvVar(const std::string& env_var_name) { return std::string(tmp); } +#if defined(__linux__) bool TestUtils::IsDirectoryExists(const std::string& path) { struct stat info; if (0 == stat(path.c_str(), &info) && info.st_mode & S_IFDIR) { @@ -102,4 +105,5 @@ bool TestUtils::RemoveDirectory(const std::string& path) { return false; } } +#endif } // namespace qcloud_cos diff --git a/unittest/src/async_op_test.cpp b/unittest/src/async_op_test.cpp index f952f1c..6ac5144 100644 --- a/unittest/src/async_op_test.cpp +++ b/unittest/src/async_op_test.cpp @@ -559,9 +559,9 @@ TEST_F(AsyncOpTest, AsyncPutByStreamWithDoneCallback) { } TEST_F(AsyncOpTest, AsyncPutByStreamWithDoneCallbackWithOutputTaskManager) { + size_t file_size = 100 * 1024 * 1024; + std::string object_name = "test_async_by_stream_" + std::to_string(file_size); { - size_t file_size = ((rand() % 100) + 1) * 1024; - std::string object_name = "test_async_by_stream_" + std::to_string(file_size); std::istringstream iss(TestUtils::GetRandomString(file_size)); // 完成回调 auto multi_put_done_cb = [](const SharedAsyncContext& context, @@ -590,7 +590,61 @@ TEST_F(AsyncOpTest, AsyncPutByStreamWithDoneCallbackWithOutputTaskManager) { CHECK_COMMON_RESULT(context->GetResult()) AsyncResp put_resp = context->GetAsyncResp(); CHECK_COMMON_RESP(put_resp) - + } + { + //异步下载 + Poco::TaskManager* taskManager; + auto multi_get_done_cb = [](const SharedAsyncContext& context, + void* user_data) { + std::cout << "multi async download object: " << context->GetResult().IsSucc() + << std::endl; + }; + std::string local_file_download = object_name + "_download"; + std::cout << "multi async download object: " << object_name + << std::endl; + qcloud_cos::AsyncGetObjectReq get_req(m_bucket_name, object_name, + local_file_download); + // 设置完成回调 + get_req.SetDoneCallback(multi_get_done_cb); + SharedAsyncContext context = m_client->AsyncResumableGetObject(get_req, taskManager); + // 等待2s后取消下载结束 + std::this_thread::sleep_for(std::chrono::seconds(2)); + context->Cancel(); + context->WaitUntilFinish(); + taskManager->joinAll(); + ASSERT_TRUE(!context->GetResult().IsSucc()); + context = m_client->AsyncResumableGetObject(get_req, taskManager); + context->WaitUntilFinish(); + taskManager->joinAll(); + ASSERT_TRUE(context->GetResult().IsSucc()); + TestUtils::RemoveFile(local_file_download); + } + { + //异步下载 + auto multi_get_done_cb = [](const SharedAsyncContext& context, + void* user_data) { + std::cout << "multi async download object: " << context->GetResult().IsSucc() + << std::endl; + }; + std::string local_file_download = object_name + "_download"; + std::cout << "multi async download object: " << object_name + << std::endl; + qcloud_cos::AsyncGetObjectReq get_req(m_bucket_name, object_name, + local_file_download); + // 设置完成回调 + get_req.SetDoneCallback(multi_get_done_cb); + SharedAsyncContext context = m_client->AsyncResumableGetObject(get_req); + // 等待2s后取消下载结束 + std::this_thread::sleep_for(std::chrono::seconds(2)); + context->Cancel(); + context->WaitUntilFinish(); + ASSERT_TRUE(!context->GetResult().IsSucc()); + context = m_client->AsyncResumableGetObject(get_req); + context->WaitUntilFinish(); + ASSERT_TRUE(context->GetResult().IsSucc()); + TestUtils::RemoveFile(local_file_download); + } + { // 删除对象 CosResult del_result; qcloud_cos::DeleteObjectReq del_req(m_bucket_name, object_name); diff --git a/unittest/src/bucket_op_test.cpp b/unittest/src/bucket_op_test.cpp index 5218b14..dbe1fe7 100644 --- a/unittest/src/bucket_op_test.cpp +++ b/unittest/src/bucket_op_test.cpp @@ -1445,4 +1445,57 @@ TEST_F(BucketOpTest, InvalidConfig) { "configuration"); } +TEST_F(BucketOpTest, BucketPolicyTest) { + { + PutBucketPolicyReq req(m_bucket_name); + PutBucketPolicyResp resp; + std::string bucket_policy = + " {" + " \"Statement\": [" + " {" + " \"Principal\": {" + " \"qcs\": [" + " \"*\"" + " ]" + " }," + " \"Effect\": \"allow\"," + " \"Action\": [" + " \"cos:PutObject\"" + " ]," + " \"Resource\": [" //这里改成允许的路径前缀,可以根据自己网站的用户登录态判断允许上传的具体路径,例子: a.jpg 或者 a/* 或者 * (使用通配符*存在重大安全风险, 请谨慎评估使用) + " \"qcs::cos:"; + bucket_policy += GetEnvVar("CPP_SDK_V5_REGION"); + bucket_policy += ":uid/"; + bucket_policy += GetEnvVar("CPP_SDK_V5_APPID"); + bucket_policy += ":"; + bucket_policy += m_bucket_name; + bucket_policy += "/*\"" + " ]," + " \"Condition\": {" + " \"string_equal\": {" + " \"cos:x-cos-mime-limit\": \"image/jpeg\"" + " }" + " }" + " }" + " ]," + " \"Version\": \"2.0\"" + " }"; + req.SetBody(bucket_policy); + CosResult result = m_client->PutBucketPolicy(req, &resp); + EXPECT_TRUE(result.IsSucc()); + } + { + GetBucketPolicyReq req(m_bucket_name); + GetBucketPolicyResp resp; + CosResult result = m_client->GetBucketPolicy(req, &resp); + EXPECT_TRUE(result.IsSucc()); + } + { + DeleteBucketPolicyReq req(m_bucket_name); + DeleteBucketPolicyResp resp; + CosResult result = m_client->DeleteBucketPolicy(req, &resp); + EXPECT_TRUE(result.IsSucc()); + } +} + } // namespace qcloud_cos diff --git a/unittest/src/object_op_test.cpp b/unittest/src/object_op_test.cpp index fe6d581..1f3a73d 100644 --- a/unittest/src/object_op_test.cpp +++ b/unittest/src/object_op_test.cpp @@ -458,7 +458,7 @@ TEST_F(ObjectOpTest, DeleteObjectTest) { } } - +#if defined(__linux__) TEST_F(ObjectOpTest, DeleteObjectsTest) { // 批量上传+批量删除 { @@ -534,6 +534,7 @@ TEST_F(ObjectOpTest, DeleteObjectsTest) { ASSERT_TRUE(del_result.IsSucc()); } } +#endif TEST_F(ObjectOpTest, GetObjectByStreamTest) { { @@ -668,6 +669,7 @@ TEST_F(ObjectOpTest, ImageProcessTest) { CosResult result = m_client->PutImage(req, &resp); ASSERT_TRUE(result.IsSucc()); ASSERT_TRUE(m_client->IsObjectExist(m_bucket_name, newname)); + resp.GetUploadResult().to_string(); } //云上处理 { @@ -691,6 +693,7 @@ TEST_F(ObjectOpTest, ImageProcessTest) { CosResult result = m_client->GetQRcode(req, &resp); ASSERT_TRUE(result.IsSucc()); ASSERT_EQ(resp.GetResult().qr_code_info[0].code_url, "testimage"); + resp.GetResult().to_string(); } CosSysConfig::SetUseDnsCache(use_dns_cache); } @@ -716,6 +719,7 @@ TEST_F(ObjectOpTest, MediaTest) { ASSERT_TRUE(result.IsSucc()); ASSERT_EQ(resp.GetResult().media_bucket.name, m_bucket_name); ASSERT_EQ(resp.GetResult().media_bucket.region, GetEnvVar("CPP_SDK_V5_REGION")); + resp.GetResult().to_string(); } //info { @@ -728,6 +732,7 @@ TEST_F(ObjectOpTest, MediaTest) { ASSERT_EQ(resp.GetResult().media_info.stream.video.width, 640); ASSERT_EQ(resp.GetResult().media_info.stream.audio.codec_name, "aac"); ASSERT_EQ(resp.GetResult().media_info.format.num_stream, 4); + resp.GetResult().to_string(); } //截图 { @@ -742,7 +747,143 @@ TEST_F(ObjectOpTest, MediaTest) { CosSysConfig::SetUseDnsCache(use_dns_cache); } +//文档接口 +TEST_F(ObjectOpTest, DocTest) { + bool use_dns_cache = CosSysConfig::GetUseDnsCache(); + CosSysConfig::SetUseDnsCache(false); + std::string object_name = "document.docx"; + std::string output_object = "/test-ci/test-create-doc-process-${Number}"; + std::string queue_id = ""; + std::string doc_job_id; + //上传媒体 + { + PutObjectByFileReq put_req(m_bucket_name, object_name, "../../demo/test_file/document.docx"); + put_req.SetRecvTimeoutInms(1000 * 200); + PutObjectByFileResp put_resp; + CosResult put_result = m_client->PutObject(put_req, &put_resp); + ASSERT_TRUE(put_result.IsSucc()); + } + //绑定文档预览服务 + { + CreateDocBucketReq req(m_bucket_name); + CreateDocBucketResp resp; + CosResult result = m_client->CreateDocBucket(req, &resp); + ASSERT_TRUE(result.IsSucc()); + ASSERT_EQ(resp.GetResult().doc_bucket.name, m_bucket_name); + ASSERT_EQ(resp.GetResult().doc_bucket.region, GetEnvVar("CPP_SDK_V5_REGION")); + resp.GetResult().to_string(); + } + // 查询文档预览桶列表 + { + DescribeDocProcessBucketsReq req; + DescribeDocProcessBucketsResp resp; + CosResult result = m_client->DescribeDocProcessBuckets(req, &resp); + ASSERT_TRUE(result.IsSucc()); + resp.GetResult().to_string(); + } + // 查询文档预览队列 + { + DescribeDocProcessQueuesReq req(m_bucket_name); + DescribeDocProcessQueuesResp resp; + CosResult result = m_client->DescribeDocProcessQueues(req, &resp); + ASSERT_TRUE(result.IsSucc()); + ASSERT_EQ(resp.GetPageNumber(), 1); + ASSERT_EQ(resp.GetQueueList().bucket_id, m_bucket_name); + ASSERT_EQ(resp.GetQueueList().category, "DocProcessing"); + queue_id = resp.GetQueueList().queue_id; + resp.GetQueueList().to_string(); + resp.GetNonExistPIDs().to_string(); + } + // 更新文档预览队列 + { + UpdateDocProcessQueueReq req(m_bucket_name); + UpdateDocProcessQueueResp resp; + req.SetName("queue-doc-process-1"); + req.SetQueueId(queue_id); + req.SetState("Active"); + NotifyConfig notify_config; + notify_config.url = "http://example.com"; + notify_config.state = "On"; + notify_config.type = "Url"; + notify_config.event = "TaskFinish"; + req.SetNotifyConfig(notify_config); + CosResult result = m_client->UpdateDocProcessQueue(req, &resp); + ASSERT_TRUE(result.IsSucc()); + ASSERT_EQ(resp.GetQueueList().bucket_id, m_bucket_name); + ASSERT_EQ(resp.GetQueueList().name, "queue-doc-process-1"); + ASSERT_EQ(resp.GetQueueList().state, "Active"); + } + + // 创建文档处理任务 + { + CreateDocProcessJobsReq req(m_bucket_name); + CreateDocProcessJobsResp resp; + Input input; + input.object = object_name; + + Operation operation; + Output output; + output.bucket = m_bucket_name; + output.region = GetEnvVar("CPP_SDK_V5_REGION"); + output.object = output_object; + + operation.output = output; + req.SetOperation(operation); + req.SetQueueId(queue_id); + req.SetTag("DocProcess"); + req.SetInput(input); + CosResult result = m_client->CreateDocProcessJobs(req, &resp); + doc_job_id = resp.GetJobsDetail().job_id; + ASSERT_TRUE(result.IsSucc()); + ASSERT_EQ(resp.GetJobsDetail().state, "Submitted"); + resp.GetJobsDetail().to_string(); + } + + // 查询文档预览任务 + { + DescribeDocProcessJobReq req(m_bucket_name); + DescribeDocProcessJobResp resp; + req.SetJobId(doc_job_id); + CosResult result = m_client->DescribeDocProcessJob(req, &resp); + ASSERT_TRUE(result.IsSucc()); + resp.GetJobsDetail().to_string(); + } + + // 查询文档预览任务列表 + { + DescribeDocProcessJobsReq req(m_bucket_name); + DescribeDocProcessJobsResp resp; + req.SetQueueId(queue_id); + CosResult result = m_client->DescribeDocProcessJobs(req, &resp); + ASSERT_TRUE(result.IsSucc()); + for (size_t i = 0; i < resp.GetJobsDetails().size(); i++) { + resp.GetJobsDetails().at(i).to_string(); + } + } + + // 同步文档预览 + { + std::string local_file = "./test_preview.jpg"; + DocPreviewReq req(m_bucket_name, object_name, local_file); + DocPreviewResp resp; + req.SetSrcType("docx"); + req.SetPage(1); + req.SetSheet(1); + req.SetDstType("jpg"); + req.SetExcelPaperDirection(0); + req.SetQuality(100); + req.SetScale(100); + CosResult result = m_client->DocPreview(req, &resp); + resp.GetSheetName(); + resp.GetTotalPage(); + resp.GetErrNo(); + resp.GetTotalSheet(); + TestUtils::RemoveFile(local_file); + } + + CosSysConfig::SetUseDnsCache(use_dns_cache); +} //审核接口 TEST_F(ObjectOpTest, AuditingTest) { @@ -781,6 +922,15 @@ TEST_F(ObjectOpTest, AuditingTest) { AuditingInput input = AuditingInput(); input.SetObject(image_object_name); input.SetDataId("data_id_example2"); + UserInfo user_info; + user_info.SetAppId("appid"); + user_info.SetDeviceId("deviceid"); + user_info.SetIp("ip"); + user_info.SetNickName("nickname"); + user_info.SetRoom("room"); + user_info.SetTokenId("tokenid"); + user_info.SetType("type"); + input.SetUserInfo(user_info); req.AddInput(input); req.SetDetectType("Ads,Porn,Politics,Terrorism"); CosResult result = m_client->BatchImageAuditing(req, &resp); @@ -802,6 +952,15 @@ TEST_F(ObjectOpTest, AuditingTest) { req.SetSnapShot(snap_shot); req.SetDetectType("Porn,Ads,Politics,Terrorism,Abuse,Illegal"); req.SetDetectContent(0); + UserInfo user_info; + user_info.SetAppId("appid"); + user_info.SetDeviceId("deviceid"); + user_info.SetIp("ip"); + user_info.SetNickName("nickname"); + user_info.SetRoom("room"); + user_info.SetTokenId("tokenid"); + user_info.SetType("type"); + req.SetUserInfo(user_info); CosResult result = m_client->CreateVideoAuditingJob(req, &resp); video_job_id = resp.GetJobsDetail().GetJobId(); ASSERT_TRUE(result.IsSucc()); diff --git a/unittest/src/object_response_test.cpp b/unittest/src/object_response_test.cpp index afecc4b..70c79c4 100644 --- a/unittest/src/object_response_test.cpp +++ b/unittest/src/object_response_test.cpp @@ -12,7 +12,7 @@ namespace qcloud_cos { -TEST(ObjectRespTest, DocTest) { +TEST(ObjectRespTest, DocRespTest) { { DocPreviewResp resp; std::map headers = { From 62427639f891262d88662703f2221cc00e040db2 Mon Sep 17 00:00:00 2001 From: huberyxxiao Date: Thu, 6 Apr 2023 16:26:26 +0800 Subject: [PATCH 2/4] fix ut --- unittest/src/async_op_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/unittest/src/async_op_test.cpp b/unittest/src/async_op_test.cpp index 6ac5144..f7dbb4a 100644 --- a/unittest/src/async_op_test.cpp +++ b/unittest/src/async_op_test.cpp @@ -608,7 +608,7 @@ TEST_F(AsyncOpTest, AsyncPutByStreamWithDoneCallbackWithOutputTaskManager) { get_req.SetDoneCallback(multi_get_done_cb); SharedAsyncContext context = m_client->AsyncResumableGetObject(get_req, taskManager); // 等待2s后取消下载结束 - std::this_thread::sleep_for(std::chrono::seconds(2)); + std::this_thread::sleep_for(std::chrono::seconds(1)); context->Cancel(); context->WaitUntilFinish(); taskManager->joinAll(); From d995f712a8682695ce7b6f755037d637330d5526 Mon Sep 17 00:00:00 2001 From: huberyxxiao Date: Thu, 6 Apr 2023 16:53:00 +0800 Subject: [PATCH 3/4] fix ut --- unittest/src/async_op_test.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/unittest/src/async_op_test.cpp b/unittest/src/async_op_test.cpp index f7dbb4a..7649872 100644 --- a/unittest/src/async_op_test.cpp +++ b/unittest/src/async_op_test.cpp @@ -607,8 +607,7 @@ TEST_F(AsyncOpTest, AsyncPutByStreamWithDoneCallbackWithOutputTaskManager) { // 设置完成回调 get_req.SetDoneCallback(multi_get_done_cb); SharedAsyncContext context = m_client->AsyncResumableGetObject(get_req, taskManager); - // 等待2s后取消下载结束 - std::this_thread::sleep_for(std::chrono::seconds(1)); + // 取消下载结束 context->Cancel(); context->WaitUntilFinish(); taskManager->joinAll(); From 32751641131560f314700ddef6e487778b25ebf2 Mon Sep 17 00:00:00 2001 From: huberyxxiao Date: Thu, 6 Apr 2023 17:26:04 +0800 Subject: [PATCH 4/4] fix ut --- unittest/src/async_op_test.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/unittest/src/async_op_test.cpp b/unittest/src/async_op_test.cpp index 7649872..edff544 100644 --- a/unittest/src/async_op_test.cpp +++ b/unittest/src/async_op_test.cpp @@ -607,7 +607,7 @@ TEST_F(AsyncOpTest, AsyncPutByStreamWithDoneCallbackWithOutputTaskManager) { // 设置完成回调 get_req.SetDoneCallback(multi_get_done_cb); SharedAsyncContext context = m_client->AsyncResumableGetObject(get_req, taskManager); - // 取消下载结束 + // 取消下载 context->Cancel(); context->WaitUntilFinish(); taskManager->joinAll(); @@ -633,8 +633,7 @@ TEST_F(AsyncOpTest, AsyncPutByStreamWithDoneCallbackWithOutputTaskManager) { // 设置完成回调 get_req.SetDoneCallback(multi_get_done_cb); SharedAsyncContext context = m_client->AsyncResumableGetObject(get_req); - // 等待2s后取消下载结束 - std::this_thread::sleep_for(std::chrono::seconds(2)); + //取消下载 context->Cancel(); context->WaitUntilFinish(); ASSERT_TRUE(!context->GetResult().IsSucc());