From 8df51fc107568b6c3cc2ea205676efe726ea7ddb Mon Sep 17 00:00:00 2001 From: JeffreySaathoff <107890382+JeffreySaathoff@users.noreply.github.com> Date: Wed, 15 Feb 2023 10:35:11 -0800 Subject: [PATCH] Add implementation for EnumDownloads (#158) --- sdk-cpp/include/do_config.h | 2 +- sdk-cpp/include/do_download.h | 12 +++- sdk-cpp/include/do_errors.h | 23 ++++--- sdk-cpp/src/do_download.cpp | 47 ++++++++++++- .../src/internal/com/do_config_internal.cpp | 2 +- .../com/do_download_property_internal.cpp | 4 +- sdk-cpp/src/internal/com/download_impl.cpp | 68 ++++++++++++++++++- .../internal/do_download_property_internal.h | 3 + sdk-cpp/src/internal/do_error_helpers.h | 21 +----- sdk-cpp/src/internal/download_impl.h | 8 +++ .../src/internal/rest/do_config_internal.cpp | 4 +- .../rest/do_download_property_internal.cpp | 20 +++--- sdk-cpp/src/internal/rest/download_impl.cpp | 27 ++++++-- sdk-cpp/tests/download_properties_tests.cpp | 30 +++++++- sdk-cpp/tests/download_tests_common.cpp | 18 ++--- 15 files changed, 218 insertions(+), 71 deletions(-) diff --git a/sdk-cpp/include/do_config.h b/sdk-cpp/include/do_config.h index b69b595d..f96610e7 100644 --- a/sdk-cpp/include/do_config.h +++ b/sdk-cpp/include/do_config.h @@ -6,7 +6,7 @@ /* This file exposes apis for helping set an iot_connection_string for the DO agent, so that an application can supply a Microsoft Connected Cache device's hostname -While this file will compile for all platforms, they only serve a purpose for the DeliveryOptimization Agent on linux devices, all other usage will fail and return e_not_impl +While this file will compile for all platforms, they only serve a purpose for the DeliveryOptimization Agent on linux devices, all other usage will fail and return errc::not_impl */ #ifdef __cplusplus diff --git a/sdk-cpp/include/do_download.h b/sdk-cpp/include/do_download.h index 374f158c..fb23cd6b 100644 --- a/sdk-cpp/include/do_download.h +++ b/sdk-cpp/include/do_download.h @@ -8,6 +8,7 @@ #include #include #include +#include #include "do_download_status.h" #include "do_download_property.h" @@ -48,7 +49,7 @@ class download static std::error_code download_url_to_path(const std::string& uri, const std::string& downloadFilePath, const std::atomic_bool& isCancelled, std::chrono::seconds timeoutSecs = std::chrono::hours(24)) noexcept; // Certain properties are not supported on older versions of Windows, resulting in - // msdo::errc::do_e_unknown_property_id from the following methods. See do_download_property.h. + // msdo::errc::unknown_property_id from the following methods. See do_download_property.h. std::error_code set_property(download_property prop, const download_property_value& value) noexcept; std::error_code get_property(download_property prop, download_property_value& value) noexcept; @@ -82,10 +83,17 @@ class download return set_property(download_property::cost_policy, static_cast(value)); } + // Returns existing downloads + static std::error_code get_downloads(std::vector>& out) noexcept; + + // Returns existing downloads, filtered by download_property::id, uri, catalog_id, caller_name or download_file_path + static std::error_code get_downloads(download_property prop, const std::string& value, std::vector>& out) noexcept; + static std::error_code get_downloads(download_property prop, const std::wstring& value, std::vector>& out) noexcept; + private: download(); - std::shared_ptr _download; + std::unique_ptr _download; }; } // namespace deliveryoptimization diff --git a/sdk-cpp/include/do_errors.h b/sdk-cpp/include/do_errors.h index d5933e1a..d3c3be9f 100644 --- a/sdk-cpp/include/do_errors.h +++ b/sdk-cpp/include/do_errors.h @@ -11,19 +11,20 @@ namespace microsoft { namespace deliveryoptimization { - -enum class errc : int32_t +namespace errc { - e_not_impl = static_cast(0x80004001), // E_NOTIMPL - unexpected = static_cast(0x8000FFFF), // E_UNEXPECTED - invalid_arg = static_cast(0x80070057), // E_INVALIDARG - not_found = static_cast(0x80070490), // E_NOT_SET (ERROR_NOT_FOUND) - no_service = static_cast(0x80D01001), // DO_E_NO_SERVICE - download_no_progress = static_cast(0x80D02002), // DO_E_DOWNLOAD_NO_PROGRESS - do_e_unknown_property_id = static_cast(0x80D02011), // DO_E_UNKNOWN_PROPERTY_ID - do_e_invalid_state = static_cast(0x80D02013), // DO_E_INVALID_STATE -}; +constexpr auto not_impl = static_cast(0x80004001); // E_NOTIMPL +constexpr auto unexpected = static_cast(0x8000FFFF); // E_UNEXPECTED +constexpr auto invalid_arg = static_cast(0x80070057); // E_INVALIDARG +constexpr auto not_found = static_cast(0x80070490); // E_NOT_SET (ERROR_NOT_FOUND) +constexpr auto no_service = static_cast(0x80D01001); // DO_E_NO_SERVICE +constexpr auto download_no_progress = static_cast(0x80D02002); // DO_E_DOWNLOAD_NO_PROGRESS +constexpr auto no_downloads = static_cast(0x80D02005); // DO_E_NO_DOWNLOADS +constexpr auto unknown_property_id = static_cast(0x80D02011); // DO_E_UNKNOWN_PROPERTY_ID +constexpr auto invalid_state = static_cast(0x80D02013); // DO_E_INVALID_STATE + +} //namespace errc } //namespace deliveryoptimization } //namespace microsoft diff --git a/sdk-cpp/src/do_download.cpp b/sdk-cpp/src/do_download.cpp index 43737343..e6a4c422 100644 --- a/sdk-cpp/src/do_download.cpp +++ b/sdk-cpp/src/do_download.cpp @@ -21,7 +21,7 @@ namespace deliveryoptimization download::download() { - _download = std::make_shared(); + _download = std::make_unique(); } download::~download() = default; @@ -36,7 +36,6 @@ std::error_code download::make(const std::string& uri, const std::string& downlo { out.reset(); std::unique_ptr tmp(new download()); - tmp->_download = std::make_shared(); DO_RETURN_IF_FAILED(tmp->_download->Init(uri, downloadFilePath)); out = std::move(tmp); return DO_OK; @@ -166,7 +165,7 @@ static std::error_code g_TryOverrideDownlevelOsSetPropertyError(download_propert { // Temporary backward-compatibility for MSEdge. // These properties were not supported in IDODownload interface until build 19041. - if ((ec.value() == static_cast(errc::do_e_unknown_property_id)) && + if ((ec.value() == errc::unknown_property_id) && ((prop == download_property::correlation_vector) || (prop == download_property::integrity_check_info))) { return DO_OK; @@ -188,5 +187,47 @@ std::error_code download::get_property(download_property prop, download_property return _download->GetProperty(prop, val); } +std::error_code download::get_downloads(std::vector>& out) noexcept +{ + out.clear(); + std::vector> results; + DO_RETURN_IF_FAILED(msdod::CDownloadImpl::EnumDownloads(results)); + for (auto& result : results) + { + std::unique_ptr tmp(new download()); + tmp->_download = std::move(result); + out.push_back(std::move(tmp)); + } + return DO_OK; +} + +std::error_code download::get_downloads(download_property prop, const std::string& value, std::vector>& out) noexcept +{ + out.clear(); + std::vector> results; + DO_RETURN_IF_FAILED(msdod::CDownloadImpl::EnumDownloads(prop, value, results)); + for (auto& result : results) + { + std::unique_ptr tmp(new download()); + tmp->_download = std::move(result); + out.push_back(std::move(tmp)); + } + return DO_OK; +} + +std::error_code download::get_downloads(download_property prop, const std::wstring& value, std::vector>& out) noexcept +{ + out.clear(); + std::vector> results; + DO_RETURN_IF_FAILED(msdod::CDownloadImpl::EnumDownloads(prop, value, results)); + for (auto& result : results) + { + std::unique_ptr tmp(new download()); + tmp->_download = std::move(result); + out.push_back(std::move(tmp)); + } + return DO_OK; +} + } // namespace deliveryoptimization } // namespace microsoft diff --git a/sdk-cpp/src/internal/com/do_config_internal.cpp b/sdk-cpp/src/internal/com/do_config_internal.cpp index af2b95c6..e98ceadb 100644 --- a/sdk-cpp/src/internal/com/do_config_internal.cpp +++ b/sdk-cpp/src/internal/com/do_config_internal.cpp @@ -7,7 +7,7 @@ namespace msdo = microsoft::deliveryoptimization; int internal_set_iot_connection_string(const char* value) { - return static_cast(msdo::errc::e_not_impl); + return msdo::errc::not_impl; } char* internal_get_components_version() diff --git a/sdk-cpp/src/internal/com/do_download_property_internal.cpp b/sdk-cpp/src/internal/com/do_download_property_internal.cpp index a6942d78..9055c2c6 100644 --- a/sdk-cpp/src/internal/com/do_download_property_internal.cpp +++ b/sdk-cpp/src/internal/com/do_download_property_internal.cpp @@ -16,7 +16,7 @@ namespace deliveryoptimization namespace details { -static std::error_code UTF8toWstr(const std::string& str, std::wstring& wstr) +std::error_code UTF8toWstr(const std::string& str, std::wstring& wstr) { wstr.clear(); size_t cch = str.size(); @@ -33,7 +33,7 @@ static std::error_code UTF8toWstr(const std::string& str, std::wstring& wstr) return DO_OK; } -static std::error_code WstrToUTF8(const std::wstring& wstr, std::string& str) +std::error_code WstrToUTF8(const std::wstring& wstr, std::string& str) { str.clear(); size_t cch = wstr.size(); diff --git a/sdk-cpp/src/internal/com/download_impl.cpp b/sdk-cpp/src/internal/com/download_impl.cpp index c0ee60aa..b7ff6080 100644 --- a/sdk-cpp/src/internal/com/download_impl.cpp +++ b/sdk-cpp/src/internal/com/download_impl.cpp @@ -136,7 +136,7 @@ std::error_code CDownloadImpl::Init(const std::string& uri, const std::string& d ComPtr spDownload; RETURN_IF_FAILED(manager->CreateDownload(&spDownload)); - RETURN_IF_FAILED(CoSetProxyBlanket(static_cast(spDownload.Get()), RPC_C_AUTHN_DEFAULT, + RETURN_IF_FAILED(CoSetProxyBlanket(spDownload.Get(), RPC_C_AUTHN_DEFAULT, RPC_C_AUTHZ_NONE, COLE_DEFAULT_PRINCIPAL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, nullptr, EOAC_STATIC_CLOAKING)); @@ -295,6 +295,72 @@ std::error_code CDownloadImpl::SetRanges(const download_range* ranges, size_t co return DO_OK; } +std::error_code CDownloadImpl::EnumDownloads(std::vector>& out) noexcept +{ + out.clear(); + return _EnumDownloads(nullptr, out); +} + +std::error_code CDownloadImpl::EnumDownloads(download_property prop, const std::string& value, std::vector>& out) noexcept +{ + out.clear(); + std::wstring wval; + DO_RETURN_IF_FAILED(UTF8toWstr(value, wval)); + return EnumDownloads(prop, wval, out); +} + +std::error_code CDownloadImpl::EnumDownloads(download_property prop, const std::wstring& value, std::vector>& out) noexcept +{ + out.clear(); + DO_DOWNLOAD_ENUM_CATEGORY category; + DO_RETURN_IF_FAILED(ConvertToComProperty(prop, category.Property)); + category.Value = value.c_str(); + return _EnumDownloads(&category, out); +} + +std::error_code CDownloadImpl::_EnumDownloads(const DO_DOWNLOAD_ENUM_CATEGORY* pCategory, std::vector>& out) noexcept +{ + out.clear(); + ComPtr manager; + RETURN_IF_FAILED(CoCreateInstance(__uuidof(DeliveryOptimization), nullptr, CLSCTX_LOCAL_SERVER, IID_PPV_ARGS(&manager))); + ComPtr spEnum; + RETURN_IF_FAILED(manager->EnumDownloads(pCategory, &spEnum)); + + std::vector> results; + ULONG cFetched = 0; + do + { + ComPtr spunk; + RETURN_IF_FAILED(spEnum->Next(1, &spunk, &cFetched)); + if (cFetched == 1) + { + ComPtr spDownload; + RETURN_IF_FAILED(spunk->QueryInterface(IID_PPV_ARGS(&spDownload))); + + RETURN_IF_FAILED(CoSetProxyBlanket(spDownload.Get(), RPC_C_AUTHN_DEFAULT, + RPC_C_AUTHZ_NONE, COLE_DEFAULT_PRINCIPAL, RPC_C_AUTHN_LEVEL_DEFAULT, RPC_C_IMP_LEVEL_IMPERSONATE, + nullptr, EOAC_STATIC_CLOAKING)); + + auto tmp = std::make_unique(); + tmp->_spDownload = std::move(spDownload); + + // Assume full file in created state, else leave ranges null + msdo::download_status status; + DO_RETURN_IF_FAILED(tmp->GetStatus(status)); + if (status.state() == msdo::download_state::created) + { + tmp->_spRanges = std::make_unique(); + tmp->_spRanges->RangeCount = 0; // empty == full file + } + + results.push_back(std::move(tmp)); + } + } while (cFetched > 0); + + out = std::move(results); + return DO_OK; +} + } // namespace details } // namespace deliveryoptimization } // namespace microsoft diff --git a/sdk-cpp/src/internal/do_download_property_internal.h b/sdk-cpp/src/internal/do_download_property_internal.h index 3085e07e..a984e441 100644 --- a/sdk-cpp/src/internal/do_download_property_internal.h +++ b/sdk-cpp/src/internal/do_download_property_internal.h @@ -23,6 +23,9 @@ namespace details { #if defined(DO_INTERFACE_COM) +std::error_code UTF8toWstr(const std::string& str, std::wstring& wstr); +std::error_code WstrToUTF8(const std::wstring& wstr, std::string& str); + struct unique_variant : VARIANT { unique_variant(); diff --git a/sdk-cpp/src/internal/do_error_helpers.h b/sdk-cpp/src/internal/do_error_helpers.h index 1e5da012..849a4668 100644 --- a/sdk-cpp/src/internal/do_error_helpers.h +++ b/sdk-cpp/src/internal/do_error_helpers.h @@ -52,19 +52,10 @@ inline std::error_code make_error_code(int32_t e) return std::error_code(e, do_category()); } -inline std::error_code make_error_code(errc e) -{ - return std::error_code(static_cast(e), do_category()); -} - -#ifndef FAILED -#define FAILED(hr) (((int32_t)(hr)) < 0) -#endif - #ifndef RETURN_IF_FAILED #define RETURN_IF_FAILED(hr) { \ int32_t __hr = (hr); \ - if (FAILED(__hr)) return std::error_code(__hr, do_category()); } + if (__hr < 0) return std::error_code(__hr, do_category()); } #endif #ifdef DO_ENABLE_EXCEPTIONS @@ -83,11 +74,6 @@ class exception : public std::exception { } - exception(errc code) : - exception(std::error_code(static_cast(code), do_category())) - { - } - const char* what() const noexcept override { return _msg.c_str(); @@ -128,11 +114,6 @@ inline void ThrowException(int32_t errorCode) throw exception(errorCode); } -inline void ThrowException(errc errorCode) -{ - throw exception(errorCode); -} - #endif // DO_ENABLE_EXCEPTIONS } // namespace details diff --git a/sdk-cpp/src/internal/download_impl.h b/sdk-cpp/src/internal/download_impl.h index 1ca2d4fa..cc12edc6 100644 --- a/sdk-cpp/src/internal/download_impl.h +++ b/sdk-cpp/src/internal/download_impl.h @@ -4,6 +4,8 @@ #ifndef _DELIVERY_OPTIMIZATION_DOWNLOAD_IMPL_H #define _DELIVERY_OPTIMIZATION_DOWNLOAD_IMPL_H +#include + #include "download_interface.h" #if defined(DO_INTERFACE_COM) @@ -39,8 +41,14 @@ class CDownloadImpl : public IDownload std::error_code SetProperty(download_property key, const download_property_value& val) noexcept override; std::error_code SetRanges(const download_range* ranges, size_t count) noexcept override; + static std::error_code EnumDownloads(std::vector>& out) noexcept; + static std::error_code EnumDownloads(download_property prop, const std::string& value, std::vector>& out) noexcept; + static std::error_code EnumDownloads(download_property prop, const std::wstring& value, std::vector>& out) noexcept; + private: #if defined(DO_INTERFACE_COM) + static std::error_code CDownloadImpl::_EnumDownloads(const DO_DOWNLOAD_ENUM_CATEGORY* pCategory, std::vector>& out) noexcept; + Microsoft::WRL::ComPtr _spDownload; std::unique_ptr _spRanges; #elif defined(DO_INTERFACE_REST) diff --git a/sdk-cpp/src/internal/rest/do_config_internal.cpp b/sdk-cpp/src/internal/rest/do_config_internal.cpp index d2410dd8..0a27f628 100644 --- a/sdk-cpp/src/internal/rest/do_config_internal.cpp +++ b/sdk-cpp/src/internal/rest/do_config_internal.cpp @@ -15,7 +15,7 @@ #include "do_persistence.h" #include "do_version.h" #elif defined(DO_CLIENT_DOSVC) -#include "do_errors.h" // msdo::errc::e_not_impl +#include "do_errors.h" // msdo::errc::not_impl #endif namespace msdo = microsoft::deliveryoptimization; @@ -190,7 +190,7 @@ void internal_free_version_buf(char** ppBuffer) int internal_set_iot_connection_string(const char* value) { - return static_cast(msdo::errc::e_not_impl); + return msdo::errc::not_impl; } char* internal_get_components_version() diff --git a/sdk-cpp/src/internal/rest/do_download_property_internal.cpp b/sdk-cpp/src/internal/rest/do_download_property_internal.cpp index daba8795..4be88d30 100644 --- a/sdk-cpp/src/internal/rest/do_download_property_internal.cpp +++ b/sdk-cpp/src/internal/rest/do_download_property_internal.cpp @@ -14,52 +14,52 @@ namespace details std::error_code CDownloadPropertyValueInternal::Init(const std::string& val) noexcept { - return make_error_code(errc::e_not_impl); + return make_error_code(errc::not_impl); } std::error_code CDownloadPropertyValueInternal::Init(const std::wstring& val) noexcept { - return make_error_code(errc::e_not_impl); + return make_error_code(errc::not_impl); } std::error_code CDownloadPropertyValueInternal::Init(uint32_t val) noexcept { - return make_error_code(errc::e_not_impl); + return make_error_code(errc::not_impl); } std::error_code CDownloadPropertyValueInternal::Init(uint64_t val) noexcept { - return make_error_code(errc::e_not_impl); + return make_error_code(errc::not_impl); } std::error_code CDownloadPropertyValueInternal::Init(bool val) noexcept { - return make_error_code(errc::e_not_impl); + return make_error_code(errc::not_impl); } std::error_code CDownloadPropertyValueInternal::As(bool& val) const noexcept { - return make_error_code(errc::e_not_impl); + return make_error_code(errc::not_impl); } std::error_code CDownloadPropertyValueInternal::As(uint32_t& val) const noexcept { - return make_error_code(errc::e_not_impl); + return make_error_code(errc::not_impl); } std::error_code CDownloadPropertyValueInternal::As(uint64_t& val) const noexcept { - return make_error_code(errc::e_not_impl); + return make_error_code(errc::not_impl); } std::error_code CDownloadPropertyValueInternal::As(std::string& val) const noexcept { - return make_error_code(errc::e_not_impl); + return make_error_code(errc::not_impl); } std::error_code CDownloadPropertyValueInternal::As(std::wstring& val) const noexcept { - return make_error_code(errc::e_not_impl); + return make_error_code(errc::not_impl); } } // namespace details diff --git a/sdk-cpp/src/internal/rest/download_impl.cpp b/sdk-cpp/src/internal/rest/download_impl.cpp index 2161e358..a1755c3d 100644 --- a/sdk-cpp/src/internal/rest/download_impl.cpp +++ b/sdk-cpp/src/internal/rest/download_impl.cpp @@ -48,7 +48,7 @@ std::error_code CDownloadImpl::Init(const std::string& uri, const std::string& d // Handle DOCS in Shutdown state while Create request was issued, client will restart and this loop will break // TODO(jimson): SDK doesn't have the capability to start do-client-lite.service if not running already. Test this // code path when it is implemented. - if (e.error_code().value() != static_cast(msdo::errc::no_service)) + if (e.error_code().value() != msdo::errc::no_service) { return e.error_code(); } @@ -137,27 +137,42 @@ std::error_code CDownloadImpl::GetStatus(msdo::download_status& outStatus) noexc std::error_code CDownloadImpl::GetProperty(msdo::download_property key, msdo::download_property_value& value) noexcept { - return make_error_code(msdo::errc::e_not_impl); + return make_error_code(msdo::errc::not_impl); } std::error_code CDownloadImpl::SetProperty(msdo::download_property key, const msdo::download_property_value& val) noexcept { - return make_error_code(msdo::errc::e_not_impl); + return make_error_code(msdo::errc::not_impl); } std::error_code CDownloadImpl::SetStatusCallback(const status_callback_t& callback, download& download) noexcept { - return make_error_code(msdo::errc::e_not_impl); + return make_error_code(msdo::errc::not_impl); } std::error_code CDownloadImpl::SetStreamCallback(const output_stream_callback_t& callback) noexcept { - return make_error_code(msdo::errc::e_not_impl); + return make_error_code(msdo::errc::not_impl); } std::error_code CDownloadImpl::SetRanges(const download_range* ranges, size_t count) noexcept { - return make_error_code(errc::e_not_impl); + return make_error_code(errc::not_impl); +} + +std::error_code CDownloadImpl::EnumDownloads(std::vector>& out) noexcept +{ + return make_error_code(errc::not_impl); +} + +std::error_code CDownloadImpl::EnumDownloads(download_property prop, const std::string& value, std::vector>& out) noexcept +{ + return make_error_code(errc::not_impl); +} + +std::error_code CDownloadImpl::EnumDownloads(download_property prop, const std::wstring& value, std::vector>& out) noexcept +{ + return make_error_code(errc::not_impl); } std::error_code CDownloadImpl::_DownloadOperationCall(const std::string& type) noexcept diff --git a/sdk-cpp/tests/download_properties_tests.cpp b/sdk-cpp/tests/download_properties_tests.cpp index d49b041c..02427424 100644 --- a/sdk-cpp/tests/download_properties_tests.cpp +++ b/sdk-cpp/tests/download_properties_tests.cpp @@ -70,7 +70,7 @@ TEST_F(DownloadPropertyTests, SmallDownloadWithPhfDigestandCvTest) std::unique_ptr simpleDownload; ASSERT_EQ(msdo::download::make(g_smallFileUrl, g_tmpFileName, simpleDownload).value(), 0); - std::vector expectedErrors = { 0, static_cast(msdo::errc::do_e_unknown_property_id) }; + std::vector expectedErrors = { 0, msdo::errc::unknown_property_id }; int32_t code = simpleDownload->set_property(msdo::download_property::integrity_check_mandatory, false).value(); VerifyError(code, expectedErrors); @@ -91,7 +91,7 @@ TEST_F(DownloadPropertyTests, InvalidPhfDigestTest) std::unique_ptr simpleDownload; ASSERT_EQ(msdo::download::make(g_smallFileUrl, g_tmpFileName, simpleDownload).value(), 0); - std::vector expectedErrors = { 0, static_cast(msdo::errc::invalid_arg) }; + std::vector expectedErrors = { 0, msdo::errc::invalid_arg }; int32_t code = simpleDownload->set_property(msdo::download_property::integrity_check_info, "blah").value(); VerifyError(code, expectedErrors); @@ -236,13 +236,37 @@ TEST_F(DownloadPropertyTests, BasicRangesTest) ASSERT_EQ(downloadedBytes, 1100); } +TEST_F(DownloadPropertyTests, BasicEnumDownloadsTest) +{ + auto download1 = msdot::download::make(g_smallFileUrl, g_tmpFileName); + + std::string downloadId1; + download1->get_property(msdo::download_property::id, downloadId1); + + std::vector> downloads; + ASSERT_EQ(msdo::download::get_downloads(msdo::download_property::id, downloadId1, downloads).value(), 0); + ASSERT_EQ(downloads.size(), 1); + + auto download2 = std::make_unique(std::move(downloads[0])); + std::string downloadId2; + download2->get_property(msdo::download_property::id, downloadId2); + ASSERT_EQ(downloadId1, downloadId2); + + download2->start_and_wait_until_completion(); + + std::this_thread::sleep_for(1s); + + ASSERT_EQ(msdo::download::get_downloads(msdo::download_property::id, downloadId1, downloads).value(), msdo::errc::no_downloads); + ASSERT_EQ(downloads.size(), 0); +} + #elif defined(DO_CLIENT_AGENT) TEST_F(DownloadPropertyTests, SmallDownloadSetCallerNameFailureTest) { msdo::download_property_value callerName; auto ec = msdo::download_property_value::make("dosdkcpp_tests", callerName); - ASSERT_EQ(ec.value(), static_cast(msdo::errc::e_not_impl)); + ASSERT_EQ(ec.value(), msdo::errc::not_impl); } #else diff --git a/sdk-cpp/tests/download_tests_common.cpp b/sdk-cpp/tests/download_tests_common.cpp index 3e8fab55..e8b9b1ca 100644 --- a/sdk-cpp/tests/download_tests_common.cpp +++ b/sdk-cpp/tests/download_tests_common.cpp @@ -296,7 +296,7 @@ TEST_F(DownloadTests, Download1NeverStartedDownload2CancelledSameFileTest) } catch (const msdod::exception& e) { - ASSERT_EQ(e.error_code().value(), static_cast(msdo::errc::not_found)); + ASSERT_EQ(e.error_code().value(), msdo::errc::not_found); } ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); } @@ -325,9 +325,9 @@ TEST_F(DownloadTests, ResumeOnAlreadyDownloadedFileTest) catch (const msdod::exception& e) { #if defined(DO_INTERFACE_COM) - ASSERT_EQ(e.error_code().value(), static_cast(msdo::errc::do_e_invalid_state)); + ASSERT_EQ(e.error_code().value(), msdo::errc::invalid_state); #elif defined(DO_INTERFACE_REST) - ASSERT_EQ(e.error_code().value(), static_cast(msdo::errc::not_found)); + ASSERT_EQ(e.error_code().value(), msdo::errc::not_found); #endif } } @@ -357,9 +357,9 @@ TEST_F(DownloadTests, CancelDownloadOnCompletedState) catch (const msdod::exception& e) { #if defined(DO_INTERFACE_COM) - ASSERT_EQ(e.error_code().value(), static_cast(msdo::errc::do_e_invalid_state)); + ASSERT_EQ(e.error_code().value(), msdo::errc::invalid_state); #elif defined(DO_INTERFACE_REST) - ASSERT_EQ(e.error_code().value(), static_cast(msdo::errc::not_found)); + ASSERT_EQ(e.error_code().value(), msdo::errc::not_found); #endif }; } @@ -389,9 +389,9 @@ TEST_F(DownloadTests, CancelDownloadInTransferredState) catch (const msdod::exception& e) { #if defined(DO_INTERFACE_COM) - ASSERT_EQ(e.error_code().value(), static_cast(msdo::errc::do_e_invalid_state)); + ASSERT_EQ(e.error_code().value(), msdo::errc::invalid_state); #elif defined(DO_INTERFACE_REST) - ASSERT_EQ(e.error_code().value(), static_cast(msdo::errc::not_found)); + ASSERT_EQ(e.error_code().value(), msdo::errc::not_found); #endif } } @@ -607,7 +607,7 @@ TEST_F(DownloadTests, SimpleBlockingDownloadTest_ClientNotRunning) } catch (const msdod::exception& e) { - ASSERT_EQ(e.error_code().value(), static_cast(msdo::errc::no_service)); + ASSERT_EQ(e.error_code().value(), msdo::errc::no_service); } ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); } @@ -631,7 +631,7 @@ TEST_F(DownloadTests, SimpleBlockingDownloadTest_ClientNotRunningPortFilePresent } catch (const msdod::exception& e) { - ASSERT_EQ(e.error_code().value(), static_cast(msdo::errc::no_service)); + ASSERT_EQ(e.error_code().value(), msdo::errc::no_service); } ASSERT_FALSE(boost::filesystem::exists(g_tmpFileName)); }