diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ece31a6f..66e450233 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,6 +38,7 @@ option(OLP_SDK_ENABLE_TESTING "Flag to enable/disable building unit and integrat option(OLP_SDK_BUILD_DOC "Build SDK documentation" OFF) option(OLP_SDK_NO_EXCEPTION "Disable exception handling" OFF) option(OLP_SDK_USE_STD_OPTIONAL "Use std::optional instead of boost::optional with C++17 and above" OFF) +option(OLP_SDK_USE_STD_ANY "Use std::any instead of boost::any with C++17 and above" OFF) option(OLP_SDK_BOOST_THROW_EXCEPTION_EXTERNAL "The boost::throw_exception() is defined externally" OFF) option(OLP_SDK_BUILD_EXTERNAL_DEPS "Download and build external dependencies" ON) option(OLP_SDK_BUILD_EXAMPLES "Enable examples targets" OFF) diff --git a/docs/get-started.md b/docs/get-started.md index 3a62d72d7..c26f716c7 100644 --- a/docs/get-started.md +++ b/docs/get-started.md @@ -131,6 +131,7 @@ cmake --build . --target docs | `OLP_SDK_BUILD_EXTERNAL_DEPS` | Defaults to `ON`. If enabled, CMake downloads and compiles dependencies. | | `OLP_SDK_NO_EXCEPTION` | Defaults to `OFF`. If enabled, all libraries are built without exceptions. | | `OLP_SDK_USE_STD_OPTIONAL` | Defaults to `OFF`. If enabled, all libraries are built with std::optional type instead of boost::optional for C++17 and above. | +| `OLP_SDK_USE_STD_ANY` | Defaults to `OFF`. If enabled, all libraries are built with std::any type instead of boost::any for C++17 and above. | | `OLP_SDK_BOOST_THROW_EXCEPTION_EXTERNAL` | Defaults to `OFF`. When `OLP_SDK_NO_EXCEPTION` is `ON`, `boost` requires `boost::throw_exception()` to be defined. If enabled, the external definition of `boost::throw_exception()` is used. Otherwise, the library uses own definition. | | `OLP_SDK_MSVC_PARALLEL_BUILD_ENABLE` (Windows Only) | Defaults to `ON`. If enabled, the `/MP` compilation flag is added to build the Data SDK using multiple cores. | | `OLP_SDK_DISABLE_DEBUG_LOGGING`| Defaults to `OFF`. If enabled, the debug and trace level log messages are not printed. | diff --git a/olp-cpp-sdk-core/CMakeLists.txt b/olp-cpp-sdk-core/CMakeLists.txt index 1835cb53a..d5f81f5d5 100644 --- a/olp-cpp-sdk-core/CMakeLists.txt +++ b/olp-cpp-sdk-core/CMakeLists.txt @@ -128,6 +128,7 @@ set(OLP_SDK_PLATFORM_HEADERS ) set(OLP_SDK_PORTING_HEADERS + ./include/olp/core/porting/any.h ./include/olp/core/porting/deprecated.h ./include/olp/core/porting/export.h ./include/olp/core/porting/make_unique.h @@ -450,6 +451,11 @@ if (OLP_SDK_USE_STD_OPTIONAL) PUBLIC OLP_CPP_SDK_USE_STD_OPTIONAL) endif() +if (OLP_SDK_USE_STD_ANY) + target_compile_definitions(${PROJECT_NAME} + PUBLIC OLP_SDK_USE_STD_ANY) +endif() + target_include_directories(${PROJECT_NAME} PUBLIC $ $ diff --git a/olp-cpp-sdk-core/include/olp/core/cache/DefaultCache.h b/olp-cpp-sdk-core/include/olp/core/cache/DefaultCache.h index 0b68a484b..0693b21a4 100644 --- a/olp-cpp-sdk-core/include/olp/core/cache/DefaultCache.h +++ b/olp-cpp-sdk-core/include/olp/core/cache/DefaultCache.h @@ -158,7 +158,7 @@ class CORE_API DefaultCache : public KeyValueCache { * * @return True if the operation is successful; false otherwise. */ - bool Put(const std::string& key, const boost::any& value, + bool Put(const std::string& key, const olp::porting::any& value, const Encoder& encoder, time_t expiry) override; /** @@ -181,7 +181,8 @@ class CORE_API DefaultCache : public KeyValueCache { * * @return The key-value pair. */ - boost::any Get(const std::string& key, const Decoder& decoder) override; + olp::porting::any Get(const std::string& key, + const Decoder& decoder) override; /** * @brief Gets the key and binary data from the cache. diff --git a/olp-cpp-sdk-core/include/olp/core/cache/KeyValueCache.h b/olp-cpp-sdk-core/include/olp/core/cache/KeyValueCache.h index 8767be6fd..8b9135817 100644 --- a/olp-cpp-sdk-core/include/olp/core/cache/KeyValueCache.h +++ b/olp-cpp-sdk-core/include/olp/core/cache/KeyValueCache.h @@ -30,14 +30,14 @@ #include #include #include +#include #include -#include namespace olp { namespace cache { using Encoder = std::function; -using Decoder = std::function; +using Decoder = std::function; template using OperationOutcome = client::ApiResponse; @@ -74,7 +74,7 @@ class CORE_API KeyValueCache { * * @return True if the operation is successful; false otherwise. */ - virtual bool Put(const std::string& key, const boost::any& value, + virtual bool Put(const std::string& key, const olp::porting::any& value, const Encoder& encoder, time_t expiry = kDefaultExpiry) = 0; /** @@ -97,7 +97,8 @@ class CORE_API KeyValueCache { * * @return The key-value pair. */ - virtual boost::any Get(const std::string& key, const Decoder& encoder) = 0; + virtual olp::porting::any Get(const std::string& key, + const Decoder& encoder) = 0; /** * @brief Gets the key and binary data from the cache. diff --git a/olp-cpp-sdk-core/include/olp/core/porting/any.h b/olp-cpp-sdk-core/include/olp/core/porting/any.h new file mode 100644 index 000000000..033fbfe4d --- /dev/null +++ b/olp-cpp-sdk-core/include/olp/core/porting/any.h @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2025 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#pragma once + +#if (__cplusplus >= 201703L) && defined(OLP_SDK_USE_STD_ANY) +#include + +namespace olp { +namespace porting { + +using any = std::any; + +template +inline T any_cast(const any& operand) { + return std::any_cast(operand); +} + +template +inline T any_cast(any& operand) { + return std::any_cast(operand); +} + +template +inline T any_cast(any&& operand) { + return std::any_cast(std::move(operand)); +} + +template +inline const T* any_cast(const any* operand) noexcept { + return std::any_cast(operand); +} + +template +inline T* any_cast(any* operand) noexcept { + return std::any_cast(operand); +} + +inline bool has_value(const any& operand) noexcept { + return operand.has_value(); +} + +inline void reset(any& operand) noexcept { operand.reset(); } + +template +inline any make_any(Args&&... args) { + return std::make_any(std::forward(args)...); +} + +template +inline any make_any(std::initializer_list il, Args&&... args) { + return std::make_any(il, std::forward(args)...); +} + +} // namespace porting +} // namespace olp + +#else +#include + +namespace olp { +namespace porting { + +using any = boost::any; + +template +inline T any_cast(const any& operand) { + return boost::any_cast(operand); +} + +template +inline T any_cast(any& operand) { + return boost::any_cast(operand); +} + +template +inline T any_cast(any&& operand) { + return boost::any_cast(operand); +} + +template +inline const T* any_cast(const any* operand) noexcept { + return boost::any_cast(operand); +} + +template +inline T* any_cast(any* operand) noexcept { + return boost::any_cast(operand); +} + +inline bool has_value(const any& operand) noexcept { return !operand.empty(); } + +inline void reset(any& operand) noexcept { operand = boost::any(); } + +template +inline any make_any(Args&&... args) { + return any(T(std::forward(args)...)); +} + +template +inline any make_any(std::initializer_list il, Args&&... args) { + return any(T(il, std::forward(args)...)); +} + +} // namespace porting +} // namespace olp + +#endif diff --git a/olp-cpp-sdk-core/src/cache/DefaultCache.cpp b/olp-cpp-sdk-core/src/cache/DefaultCache.cpp index c31a7e593..eaa80c44b 100644 --- a/olp-cpp-sdk-core/src/cache/DefaultCache.cpp +++ b/olp-cpp-sdk-core/src/cache/DefaultCache.cpp @@ -42,7 +42,7 @@ bool DefaultCache::Clear() { return impl_->Clear(); } void DefaultCache::Compact() { return impl_->Compact(); } -bool DefaultCache::Put(const std::string& key, const boost::any& value, +bool DefaultCache::Put(const std::string& key, const olp::porting::any& value, const Encoder& encoder, time_t expiry) { return impl_->Put(key, value, encoder, expiry); } @@ -52,7 +52,8 @@ bool DefaultCache::Put(const std::string& key, return impl_->Put(key, value, expiry); } -boost::any DefaultCache::Get(const std::string& key, const Decoder& decoder) { +olp::porting::any DefaultCache::Get(const std::string& key, + const Decoder& decoder) { return impl_->Get(key, decoder); } diff --git a/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp b/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp index 2d1bfd04f..41d841ac5 100644 --- a/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp +++ b/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.cpp @@ -273,7 +273,8 @@ void DefaultCacheImpl::Compact() { } } -bool DefaultCacheImpl::Put(const std::string& key, const boost::any& value, +bool DefaultCacheImpl::Put(const std::string& key, + const olp::porting::any& value, const Encoder& encoder, time_t expiry) { std::lock_guard lock(cache_lock_); if (!is_open_) { @@ -301,11 +302,11 @@ bool DefaultCacheImpl::Put(const std::string& key, return Write(key, value, expiry).IsSuccessful(); } -boost::any DefaultCacheImpl::Get(const std::string& key, - const Decoder& decoder) { +olp::porting::any DefaultCacheImpl::Get(const std::string& key, + const Decoder& decoder) { std::lock_guard lock(cache_lock_); if (!is_open_) { - return boost::any(); + return olp::porting::any(); } if (memory_cache_) { @@ -329,7 +330,7 @@ boost::any DefaultCacheImpl::Get(const std::string& key, return decoded_item; } - return boost::any(); + return olp::porting::any(); } KeyValueCache::ValueTypePtr DefaultCacheImpl::Get(const std::string& key) { @@ -784,10 +785,9 @@ DefaultCache::StorageOpenResult DefaultCacheImpl::SetupProtectedCache() { settings_.disk_path_protected->c_str()); open_mode = static_cast(open_mode | OpenOptions::ReadOnly); - status = - protected_cache_->Open(*settings_.disk_path_protected, - *settings_.disk_path_protected, - protected_storage_settings, open_mode, false); + status = protected_cache_->Open( + *settings_.disk_path_protected, *settings_.disk_path_protected, + protected_storage_settings, open_mode, false); } if (status != OpenResult::Success) { @@ -1068,7 +1068,7 @@ OperationOutcome DefaultCacheImpl::Read( auto value = memory_cache_->Get(key); if (!value.empty()) { PromoteKeyLru(key); - return boost::any_cast(value); + return olp::porting::any_cast(value); } } diff --git a/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.h b/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.h index 9060902d5..98738a1ce 100644 --- a/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.h +++ b/olp-cpp-sdk-core/src/cache/DefaultCacheImpl.h @@ -51,10 +51,10 @@ class DefaultCacheImpl { bool Put(const std::string& key, const KeyValueCache::ValueTypePtr value, time_t expiry); - bool Put(const std::string& key, const boost::any& value, + bool Put(const std::string& key, const olp::porting::any& value, const Encoder& encoder, time_t expiry); - boost::any Get(const std::string& key, const Decoder& decoder); + olp::porting::any Get(const std::string& key, const Decoder& decoder); DefaultCache::ValueTypePtr Get(const std::string& key); diff --git a/olp-cpp-sdk-core/src/cache/InMemoryCache.h b/olp-cpp-sdk-core/src/cache/InMemoryCache.h index 87772ea93..4395a1826 100644 --- a/olp-cpp-sdk-core/src/cache/InMemoryCache.h +++ b/olp-cpp-sdk-core/src/cache/InMemoryCache.h @@ -27,8 +27,8 @@ #include #include +#include #include -#include namespace olp { namespace cache { @@ -42,7 +42,7 @@ class InMemoryCache { static constexpr size_t kSizeMax = std::numeric_limits::max(); static constexpr time_t kExpiryMax = std::numeric_limits::max(); - using ItemTuple = std::tuple; + using ItemTuple = std::tuple; using ItemTuples = std::vector; using TimeProvider = std::function; using ModelCacheCostFunc = std::function; @@ -70,10 +70,10 @@ class InMemoryCache { ModelCacheCostFunc cache_cost = DefaultCacheCost(), TimeProvider time_provider = DefaultTimeProvider()); - bool Put(const std::string& key, const boost::any& item, + bool Put(const std::string& key, const olp::porting::any& item, time_t expire_seconds = kExpiryMax, size_t = 1u); - boost::any Get(const std::string& key); + olp::porting::any Get(const std::string& key); size_t Size() const; void Clear(); diff --git a/olp-cpp-sdk-core/tests/CMakeLists.txt b/olp-cpp-sdk-core/tests/CMakeLists.txt index f343e7571..2b9d25f2e 100644 --- a/olp-cpp-sdk-core/tests/CMakeLists.txt +++ b/olp-cpp-sdk-core/tests/CMakeLists.txt @@ -61,6 +61,8 @@ set(OLP_CPP_SDK_CORE_TESTS_SOURCES ./logging/MessageFormatterTest.cpp ./logging/MockAppender.cpp + ./porting/AnyTest.cpp + ./thread/ContinuationTest.cpp ./thread/ExecutionContextTest.cpp ./thread/PriorityQueueExtendedTest.cpp diff --git a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp index 48436204d..3b1598ec0 100644 --- a/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp +++ b/olp-cpp-sdk-core/tests/cache/DefaultCacheImplTest.cpp @@ -18,6 +18,7 @@ */ #include +#include #include #include @@ -31,6 +32,10 @@ #define WIN32_LEAN_AND_MEAN #include #undef max +#else +#include +#include +#include #endif #include "Helpers.h" @@ -1399,21 +1404,23 @@ class DefaultCacheImplOpenTest public testing::WithParamInterface {}; TEST_P(DefaultCacheImplOpenTest, ReadOnlyDir) { - const auto setup_dir = [&](const olp::porting::optional& cache_path) { - if (cache_path) { - if (olp::utils::Dir::Exists(*cache_path)) { - ASSERT_TRUE(olp::utils::Dir::Remove(*cache_path)); - } - ASSERT_TRUE(olp::utils::Dir::Create(*cache_path)); - ASSERT_TRUE(SetRights(*cache_path, true)); - } - }; - - const auto reset_dir = [&](const olp::porting::optional& cache_path) { - if (cache_path) { - ASSERT_TRUE(olp::utils::Dir::Remove(*cache_path)); - } - }; + const auto setup_dir = + [&](const olp::porting::optional& cache_path) { + if (cache_path) { + if (olp::utils::Dir::Exists(*cache_path)) { + ASSERT_TRUE(olp::utils::Dir::Remove(*cache_path)); + } + ASSERT_TRUE(olp::utils::Dir::Create(*cache_path)); + ASSERT_TRUE(SetRights(*cache_path, true)); + } + }; + + const auto reset_dir = + [&](const olp::porting::optional& cache_path) { + if (cache_path) { + ASSERT_TRUE(olp::utils::Dir::Remove(*cache_path)); + } + }; const OpenTestParameters test_params = GetParam(); @@ -1447,4 +1454,95 @@ std::vector DefaultCacheImplOpenParams() { INSTANTIATE_TEST_SUITE_P(, DefaultCacheImplOpenTest, testing::ValuesIn(DefaultCacheImplOpenParams())); +TEST_F(DefaultCacheImplTest, ProtectedCacheIOErrorFallbackToReadOnly) { + SCOPED_TRACE("IOError fallback to read-only for protected cache"); + + const std::string ioerror_path = + olp::utils::Dir::TempDirectory() + "/unittest_ioerror_fallback"; + + if (olp::utils::Dir::Exists(ioerror_path)) { + helpers::MakeDirectoryAndContentReadonly(ioerror_path, false); + ASSERT_TRUE(olp::utils::Dir::Remove(ioerror_path)); + } + + ASSERT_TRUE(olp::utils::Dir::Create(ioerror_path)); + + { + cache::CacheSettings temp_settings; + temp_settings.disk_path_protected = ioerror_path; + DefaultCacheImplHelper temp_cache(temp_settings); + ASSERT_EQ(temp_cache.Open(), + cache::DefaultCache::StorageOpenResult::Success); + temp_cache.Close(); + } + + // Make all the database files read-only, but keep directory writable. + // This way Dir::IsReadOnly(directory) returns false (directory is writable), + // but LevelDB gets IOError when trying to write to the read-only DB files. +#ifndef _WIN32 + DIR* dir = opendir(ioerror_path.c_str()); + ASSERT_TRUE(dir != nullptr); + struct dirent* entry; + while ((entry = readdir(dir)) != nullptr) { + if (entry->d_type == DT_REG) { + std::string file_path = ioerror_path + "/" + entry->d_name; + if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) + continue; + ASSERT_EQ(chmod(file_path.c_str(), S_IRUSR | S_IRGRP | S_IROTH), 0); + } + } + closedir(dir); + + chmod(ioerror_path.c_str(), + S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); +#else + WIN32_FIND_DATAA find_data; + HANDLE hFind = FindFirstFileA((ioerror_path + "\\*").c_str(), &find_data); + ASSERT_NE(hFind, INVALID_HANDLE_VALUE); + + do { + if (strcmp(find_data.cFileName, ".") == 0 || + strcmp(find_data.cFileName, "..") == 0) { + continue; + } + if ((find_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) == 0) { + // It's a file, make it read-only + std::string file_path = ioerror_path + "\\" + find_data.cFileName; + DWORD attrs = GetFileAttributesA(file_path.c_str()); + ASSERT_NE(attrs, INVALID_FILE_ATTRIBUTES); + ASSERT_TRUE(SetFileAttributesA(file_path.c_str(), + attrs | FILE_ATTRIBUTE_READONLY)); + } + } while (FindNextFileA(hFind, &find_data)); + FindClose(hFind); + + // Ensure directory itself is not read-only (keep it writable) + DWORD dir_attrs = GetFileAttributesA(ioerror_path.c_str()); + ASSERT_NE(dir_attrs, INVALID_FILE_ATTRIBUTES); + if (dir_attrs & FILE_ATTRIBUTE_READONLY) { + ASSERT_TRUE(SetFileAttributesA(ioerror_path.c_str(), + dir_attrs & ~FILE_ATTRIBUTE_READONLY)); + } +#endif + ASSERT_FALSE(olp::utils::Dir::IsReadOnly(ioerror_path)); + + cache::CacheSettings settings; + settings.disk_path_protected = ioerror_path; + settings.openOptions = cache::OpenOptions::Default; + DefaultCacheImplHelper cache(settings); + + // Open should attempt R/W first, get IOError because files are read-only, + // then retry in read-only mode. + auto open_result = cache.Open(); + EXPECT_TRUE( + open_result == cache::DefaultCache::StorageOpenResult::Success || + open_result == + cache::DefaultCache::StorageOpenResult::ProtectedCacheCorrupted || + open_result == + cache::DefaultCache::StorageOpenResult::OpenDiskPathFailure); + + helpers::MakeDirectoryAndContentReadonly(ioerror_path, false); + ASSERT_TRUE(olp::utils::Dir::Remove(ioerror_path)); +} + } // namespace diff --git a/olp-cpp-sdk-core/tests/client/ApiLookupClientImplTest.cpp b/olp-cpp-sdk-core/tests/client/ApiLookupClientImplTest.cpp index 34b6fc284..a26238b30 100644 --- a/olp-cpp-sdk-core/tests/client/ApiLookupClientImplTest.cpp +++ b/olp-cpp-sdk-core/tests/client/ApiLookupClientImplTest.cpp @@ -104,7 +104,7 @@ TEST_F(ApiLookupClientImplTest, LookupApi) { SCOPED_TRACE("Fetch from cache [CacheOnly] negative"); EXPECT_CALL(*cache_, Get(cache_key, _)) .Times(1) - .WillOnce(Return(boost::any())); + .WillOnce(Return(olp::porting::any())); client::CancellationContext context; client::ApiLookupClientImpl client(catalog_hrn, settings_); @@ -154,7 +154,7 @@ TEST_F(ApiLookupClientImplTest, LookupApi) { .WillRepeatedly(Return(true)); EXPECT_CALL(*cache_, Get(cache_key, _)) .Times(1) - .WillOnce(Return(boost::any())); + .WillOnce(Return(olp::porting::any())); client::CancellationContext context; client::ApiLookupClientImpl client(catalog_hrn, settings_); @@ -183,7 +183,9 @@ TEST_F(ApiLookupClientImplTest, LookupApi) { EXPECT_CALL(*cache_, Put(_, _, _, expiry)) .Times(3) .WillRepeatedly(Return(true)); - EXPECT_CALL(*cache_, Get(_, _)).Times(1).WillOnce(Return(boost::any())); + EXPECT_CALL(*cache_, Get(_, _)) + .Times(1) + .WillOnce(Return(olp::porting::any())); client::CancellationContext context; client::ApiLookupClientImpl client(catalog_hrn, settings_); @@ -368,7 +370,9 @@ TEST_F(ApiLookupClientImplTest, LookupApi) { olp::http::HttpStatusCode::OK), kResponseLookupResource)); - EXPECT_CALL(*cache_, Get(_, _)).Times(1).WillOnce(Return(boost::any())); + EXPECT_CALL(*cache_, Get(_, _)) + .Times(1) + .WillOnce(Return(olp::porting::any())); // Response contains three services that are cached independently. EXPECT_CALL(*cache_, Put(_, _, _, _)).Times(3); @@ -569,7 +573,7 @@ TEST_F(ApiLookupClientImplTest, LookupApiAsync) { SCOPED_TRACE("Fetch from cache [CacheOnly] negative"); EXPECT_CALL(*cache_, Get(cache_key, _)) .Times(1) - .WillOnce(Return(boost::any())); + .WillOnce(Return(olp::porting::any())); std::promise promise; auto future = promise.get_future(); @@ -631,7 +635,7 @@ TEST_F(ApiLookupClientImplTest, LookupApiAsync) { .WillRepeatedly(Return(true)); EXPECT_CALL(*cache_, Get(cache_key, _)) .Times(1) - .WillOnce(Return(boost::any())); + .WillOnce(Return(olp::porting::any())); std::promise promise; auto future = promise.get_future(); @@ -665,7 +669,9 @@ TEST_F(ApiLookupClientImplTest, LookupApiAsync) { EXPECT_CALL(*cache_, Put(_, _, _, expiry)) .Times(3) .WillRepeatedly(Return(true)); - EXPECT_CALL(*cache_, Get(_, _)).Times(1).WillOnce(Return(boost::any())); + EXPECT_CALL(*cache_, Get(_, _)) + .Times(1) + .WillOnce(Return(olp::porting::any())); std::promise promise; auto future = promise.get_future(); @@ -803,7 +809,9 @@ TEST_F(ApiLookupClientImplTest, LookupApiAsync) { olp::http::HttpStatusCode::OK), kResponseLookupResource)); - EXPECT_CALL(*cache_, Get(_, _)).Times(1).WillOnce(Return(boost::any())); + EXPECT_CALL(*cache_, Get(_, _)) + .Times(1) + .WillOnce(Return(olp::porting::any())); // Response contains three services that are cached independently. EXPECT_CALL(*cache_, Put(_, _, _, _)).Times(3); diff --git a/olp-cpp-sdk-core/tests/porting/AnyTest.cpp b/olp-cpp-sdk-core/tests/porting/AnyTest.cpp new file mode 100644 index 000000000..df67f823e --- /dev/null +++ b/olp-cpp-sdk-core/tests/porting/AnyTest.cpp @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2025 HERE Europe B.V. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * License-Filename: LICENSE + */ + +#include +#include +#include + +TEST(AnyTest, AnyCastConstReference) { + // Test any_cast with const reference (covers line 84 in any.h) + const olp::porting::any const_any = std::string("test_value"); + + auto result = olp::porting::any_cast(const_any); + EXPECT_EQ("test_value", result); +} + +TEST(AnyTest, AnyCastNonConstReference) { + // Test any_cast with non-const reference + olp::porting::any any_obj = std::string("test_value"); + + auto result = olp::porting::any_cast(any_obj); + EXPECT_EQ("test_value", result); +} + +TEST(AnyTest, AnyCastRValueReference) { + // Test any_cast with rvalue reference + auto result = olp::porting::any_cast( + olp::porting::any(std::string("test_value"))); + EXPECT_EQ("test_value", result); +} + +TEST(AnyTest, AnyCastConstPointer) { + // Test any_cast with const pointer + const olp::porting::any any_obj = std::string("test_value"); + + const std::string* ptr = olp::porting::any_cast(&any_obj); + ASSERT_NE(nullptr, ptr); + EXPECT_EQ("test_value", *ptr); +} + +TEST(AnyTest, AnyCastNonConstPointer) { + // Test any_cast with non-const pointer + olp::porting::any any_obj = std::string("test_value"); + + std::string* ptr = olp::porting::any_cast(&any_obj); + ASSERT_NE(nullptr, ptr); + EXPECT_EQ("test_value", *ptr); +} + +TEST(AnyTest, HasValue) { + // Test has_value function + olp::porting::any empty_any; + EXPECT_FALSE(olp::porting::has_value(empty_any)); + + olp::porting::any filled_any = std::string("test"); + EXPECT_TRUE(olp::porting::has_value(filled_any)); +} + +TEST(AnyTest, Reset) { + // Test reset function + olp::porting::any any_obj = std::string("test_value"); + EXPECT_TRUE(olp::porting::has_value(any_obj)); + + olp::porting::reset(any_obj); + EXPECT_FALSE(olp::porting::has_value(any_obj)); +} + +TEST(AnyTest, MakeAny) { + // Test make_any with variadic arguments + auto any_obj = olp::porting::make_any("test"); + auto result = olp::porting::any_cast(any_obj); + EXPECT_EQ("test", result); +} + +TEST(AnyTest, MakeAnyWithInitializerList) { + // Test make_any with initializer list + auto any_obj = olp::porting::make_any>({1, 2, 3, 4, 5}); + auto result = olp::porting::any_cast>(any_obj); + EXPECT_EQ(5u, result.size()); + EXPECT_EQ(1, result[0]); + EXPECT_EQ(5, result[4]); +} diff --git a/olp-cpp-sdk-dataservice-read/tests/ApiClientLookupTest.cpp b/olp-cpp-sdk-dataservice-read/tests/ApiClientLookupTest.cpp index b0dc79ef0..b63626923 100644 --- a/olp-cpp-sdk-dataservice-read/tests/ApiClientLookupTest.cpp +++ b/olp-cpp-sdk-dataservice-read/tests/ApiClientLookupTest.cpp @@ -77,7 +77,7 @@ TEST(ApiClientLookupTest, LookupApi) { SCOPED_TRACE("Fetch from cache [CacheOnly] negative"); EXPECT_CALL(*cache, Get(cache_key, _)) .Times(1) - .WillOnce(Return(boost::any())); + .WillOnce(Return(olp::porting::any())); client::CancellationContext context; auto response = read::ApiClientLookup::LookupApi( @@ -251,7 +251,7 @@ TEST(ApiClientLookupTest, LookupApiConcurrent) { testing::InSequence s; - EXPECT_CALL(*cache, Get(cache_key, _)).WillOnce(Return(boost::any())); + EXPECT_CALL(*cache, Get(cache_key, _)).WillOnce(Return(olp::porting::any())); EXPECT_CALL(*network, Send(IsGetRequest(lookup_url), _, _, _, _)) .Times(1) .WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus( diff --git a/olp-cpp-sdk-dataservice-read/tests/CatalogRepositoryTest.cpp b/olp-cpp-sdk-dataservice-read/tests/CatalogRepositoryTest.cpp index ea2f30af3..848d60afd 100644 --- a/olp-cpp-sdk-dataservice-read/tests/CatalogRepositoryTest.cpp +++ b/olp-cpp-sdk-dataservice-read/tests/CatalogRepositoryTest.cpp @@ -140,7 +140,7 @@ TEST_F(CatalogRepositoryTest, GetLatestVersionCacheOnlyNotFound) { EXPECT_CALL(*cache_, Get(_, _)) .Times(1) - .WillOnce(testing::Return(boost::any{})); + .WillOnce(testing::Return(olp::porting::any{})); ON_CALL(*network_, Send(_, _, _, _, _)) .WillByDefault([](olp::http::NetworkRequest, olp::http::Network::Payload, @@ -169,7 +169,7 @@ TEST_F(CatalogRepositoryTest, GetLatestVersionCacheOnlyRequestWithMinVersion) { EXPECT_CALL(*cache_, Get(_, _)) .Times(2) - .WillRepeatedly(testing::Return(boost::any{})); + .WillRepeatedly(testing::Return(olp::porting::any{})); ON_CALL(*network_, Send(_, _, _, _, _)) .WillByDefault([](olp::http::NetworkRequest, olp::http::Network::Payload, @@ -218,11 +218,11 @@ TEST_F(CatalogRepositoryTest, GetLatestVersionOnlineOnlyNotFound) { ON_CALL(*cache_, Get(_, _)) .WillByDefault([](const std::string&, const olp::cache::Decoder&) { ADD_FAILURE() << "Cache should not be used in OnlineOnly request"; - return boost::any{}; + return olp::porting::any{}; }); EXPECT_CALL(*cache_, Get(testing::Eq(kMetadataCacheKey), _)) - .WillOnce(testing::Return(boost::any())); + .WillOnce(testing::Return(olp::porting::any())); EXPECT_CALL(*network_, Send(IsGetRequest(kLookupMetadata), _, _, _, _)) .Times(1) @@ -247,11 +247,11 @@ TEST_F(CatalogRepositoryTest, GetLatestVersionOnlineOnlyFound) { ON_CALL(*cache_, Get(_, _)) .WillByDefault([](const std::string&, const olp::cache::Decoder&) { ADD_FAILURE() << "Cache should not be used in OnlineOnly request"; - return boost::any{}; + return olp::porting::any{}; }); EXPECT_CALL(*cache_, Get(testing::Eq(kMetadataCacheKey), _)) - .WillOnce(testing::Return(boost::any())); + .WillOnce(testing::Return(olp::porting::any())); EXPECT_CALL(*network_, Send(IsGetRequest(kLookupMetadata), _, _, _, _)) .WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus( @@ -411,7 +411,7 @@ TEST_F(CatalogRepositoryTest, GetCatalogOnlineOnlyFound) { ON_CALL(*cache_, Get(_, _)) .WillByDefault([](const std::string&, const olp::cache::Decoder&) { ADD_FAILURE() << "Cache should not be used in OnlineOnly request"; - return boost::any{}; + return olp::porting::any{}; }); ON_CALL(*network_, Send(IsGetRequest(kUrlLookupConfig), _, _, _, _)) @@ -437,7 +437,8 @@ TEST_F(CatalogRepositoryTest, GetCatalogOnlineIfNotFound) { auto request = read::CatalogRequest(); request.WithFetchOption(read::OnlineIfNotFound); - EXPECT_CALL(*cache_, Get(_, _)).WillRepeatedly(testing::Return(boost::any{})); + EXPECT_CALL(*cache_, Get(_, _)) + .WillRepeatedly(testing::Return(olp::porting::any{})); EXPECT_CALL(*cache_, Put(testing::Eq(kCatalog + "::config::v1::api"), _, _, _)) @@ -517,7 +518,7 @@ TEST_F(CatalogRepositoryTest, GetCatalogCacheOnlyNotFound) { EXPECT_CALL(*cache_, Get(_, _)) .Times(1) - .WillOnce(testing::Return(boost::any{})); + .WillOnce(testing::Return(olp::porting::any{})); ON_CALL(*network_, Send(_, _, _, _, _)) .WillByDefault([](olp::http::NetworkRequest, olp::http::Network::Payload, @@ -545,7 +546,7 @@ TEST_F(CatalogRepositoryTest, GetCatalogOnlineOnlyNotFound) { ON_CALL(*cache_, Get(_, _)) .WillByDefault([](const std::string&, const olp::cache::Decoder&) { ADD_FAILURE() << "Cache should not be used in OnlineOnly request"; - return boost::any{}; + return olp::porting::any{}; }); EXPECT_CALL(*network_, Send(IsGetRequest(kUrlLookupConfig), _, _, _, _)) diff --git a/olp-cpp-sdk-dataservice-read/tests/DataRepositoryTest.cpp b/olp-cpp-sdk-dataservice-read/tests/DataRepositoryTest.cpp index c1efd8aeb..e34cb34cf 100644 --- a/olp-cpp-sdk-dataservice-read/tests/DataRepositoryTest.cpp +++ b/olp-cpp-sdk-dataservice-read/tests/DataRepositoryTest.cpp @@ -653,7 +653,7 @@ TEST_F(DataRepositoryTest, GetBlobDataFailedToCache) { .WillRepeatedly(testing::Return(olp::client::ApiError::CacheIO())); EXPECT_CALL(*cache_mock, Get(_, _)) - .WillRepeatedly(testing::Return(boost::any())); + .WillRepeatedly(testing::Return(olp::porting::any())); EXPECT_CALL(*cache_mock, Get(_)).WillRepeatedly(testing::Return(nullptr)); EXPECT_CALL(*network_mock_, Send(IsGetRequest(kUrlLookup), _, _, _, _)) @@ -698,7 +698,7 @@ TEST_F(DataRepositoryTest, GetVersionedDataTileFailedToCache) { .WillRepeatedly(testing::Return(olp::client::ApiError::CacheIO())); EXPECT_CALL(*cache_mock, Get(_, _)) - .WillRepeatedly(testing::Return(boost::any())); + .WillRepeatedly(testing::Return(olp::porting::any())); EXPECT_CALL(*cache_mock, Get(_)).WillRepeatedly(testing::Return(nullptr)); EXPECT_CALL(*network_mock_, Send(IsGetRequest(kUrlLookup), _, _, _, _)) diff --git a/olp-cpp-sdk-dataservice-read/tests/PartitionsRepositoryTest.cpp b/olp-cpp-sdk-dataservice-read/tests/PartitionsRepositoryTest.cpp index 964682b03..b728d2b05 100644 --- a/olp-cpp-sdk-dataservice-read/tests/PartitionsRepositoryTest.cpp +++ b/olp-cpp-sdk-dataservice-read/tests/PartitionsRepositoryTest.cpp @@ -205,7 +205,7 @@ TEST_F(PartitionsRepositoryTest, GetPartitionById) { ON_CALL(*cache, Get(_, _)) .WillByDefault([](const std::string&, const cache::Decoder&) { ADD_FAILURE() << "Cache should not be used in OnlineOnly request"; - return boost::any{}; + return olp::porting::any{}; }); }; @@ -1011,7 +1011,7 @@ TEST_F(PartitionsRepositoryTest, GetAggregatedPartitionForVersionedTile) { olp::http::HttpStatusCode::OK), kSubQuadsWithParent)); EXPECT_CALL(*mock_cache, Get(_, _)) - .WillOnce(Return(boost::any(kUrlQueryApi))); + .WillOnce(Return(olp::porting::any(kUrlQueryApi))); EXPECT_CALL(*mock_cache, Get(_)) .WillRepeatedly(Return(KeyValueCache::ValueTypePtr())); EXPECT_CALL(*mock_cache, Write(_, _, _)) @@ -1051,7 +1051,7 @@ TEST_F(PartitionsRepositoryTest, GetAggregatedPartitionForVersionedTile) { .WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus( olp::http::HttpStatusCode::OK), kSubQuads)); - EXPECT_CALL(*mock_cache, Get(_, _)).WillOnce(Return(boost::any())); + EXPECT_CALL(*mock_cache, Get(_, _)).WillOnce(Return(olp::porting::any())); EXPECT_CALL(*mock_cache, Put(_, _, _, _)).WillOnce(Return(true)); EXPECT_CALL(*mock_cache, Get(_)) .WillRepeatedly(Return(KeyValueCache::ValueTypePtr())); @@ -1117,7 +1117,7 @@ TEST_F(PartitionsRepositoryTest, GetAggregatedPartitionForVersionedTile) { ReturnHttpResponse(olp::http::NetworkResponse().WithStatus( olp::http::HttpStatusCode::BAD_REQUEST), kErrorServiceUnavailable)); - EXPECT_CALL(*mock_cache, Get(_, _)).WillOnce(Return(boost::any())); + EXPECT_CALL(*mock_cache, Get(_, _)).WillOnce(Return(olp::porting::any())); EXPECT_CALL(*mock_cache, Get(_)) .WillRepeatedly(Return(KeyValueCache::ValueTypePtr())); @@ -1158,7 +1158,7 @@ TEST_F(PartitionsRepositoryTest, GetAggregatedPartitionForVersionedTile) { ReturnHttpResponse(olp::http::NetworkResponse().WithStatus( olp::http::HttpStatusCode::BAD_REQUEST), kErrorServiceUnavailable)); - EXPECT_CALL(*mock_cache, Get(_, _)).WillOnce(Return(boost::any())); + EXPECT_CALL(*mock_cache, Get(_, _)).WillOnce(Return(olp::porting::any())); EXPECT_CALL(*mock_cache, Put(_, _, _, _)).WillOnce(Return(true)); EXPECT_CALL(*mock_cache, Get(_)) .WillRepeatedly(Return(KeyValueCache::ValueTypePtr())); @@ -1199,7 +1199,7 @@ TEST_F(PartitionsRepositoryTest, GetAggregatedPartitionForVersionedTile) { .WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus( olp::http::HttpStatusCode::OK), kInvalidJson)); - EXPECT_CALL(*mock_cache, Get(_, _)).WillOnce(Return(boost::any())); + EXPECT_CALL(*mock_cache, Get(_, _)).WillOnce(Return(olp::porting::any())); EXPECT_CALL(*mock_cache, Put(_, _, _, _)).WillOnce(Return(true)); EXPECT_CALL(*mock_cache, Get(_)) .WillRepeatedly(Return(KeyValueCache::ValueTypePtr())); @@ -1744,7 +1744,8 @@ TEST_F(PartitionsRepositoryTest, GetVersionedPartitionsBatch_MockedCache) { settings.network_request_handler = mock_network; settings.retry_settings.timeout = 1; - EXPECT_CALL(*cache, Get(_, _)).WillRepeatedly(Return(boost::any{})); + EXPECT_CALL(*cache, Get(_, _)) + .WillRepeatedly(Return(olp::porting::any{})); EXPECT_CALL(*cache, Put(Eq(kCacheKeyMetadata), _, _, _)) .WillRepeatedly(Return(true)); EXPECT_CALL(*cache, Read(_)) @@ -1985,7 +1986,7 @@ TEST_F(PartitionsRepositoryTest, StreamPartitions) { auto async_stream = std::make_shared(); client::CancellationContext context; - EXPECT_CALL(*cache, Get(_, _)).WillOnce(Return(boost::any())); + EXPECT_CALL(*cache, Get(_, _)).WillOnce(Return(olp::porting::any())); EXPECT_CALL(*network, Send(IsGetRequest(kOlpSdkUrlLookupQuery), _, _, _, _)) .WillOnce( ReturnHttpResponse(olp::http::NetworkResponse().WithStatus( @@ -2008,7 +2009,7 @@ TEST_F(PartitionsRepositoryTest, StreamPartitions) { auto async_stream = std::make_shared(); client::CancellationContext context; - EXPECT_CALL(*cache, Get(_, _)).WillOnce(Return(boost::any())); + EXPECT_CALL(*cache, Get(_, _)).WillOnce(Return(olp::porting::any())); EXPECT_CALL(*network, Send(IsGetRequest(kOlpSdkUrlLookupQuery), _, _, _, _)) .WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus( olp::http::HttpStatusCode::OK), @@ -2054,7 +2055,7 @@ TEST_F(PartitionsRepositoryTest, StreamPartitions) { auto async_stream = std::make_shared(); client::CancellationContext context; - EXPECT_CALL(*cache, Get(_, _)).WillOnce(Return(boost::any())); + EXPECT_CALL(*cache, Get(_, _)).WillOnce(Return(olp::porting::any())); EXPECT_CALL(*network, Send(IsGetRequest(kOlpSdkUrlLookupQuery), _, _, _, _)) .WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus( olp::http::HttpStatusCode::OK), @@ -2149,7 +2150,7 @@ TEST_F(PartitionsRepositoryTest_GetPartitionById, EXPECT_CALL(*cache_, Read(cache_key_)) .WillOnce(Return(client::ApiError::NotFound())); EXPECT_CALL(*cache_, Get(Eq(kCacheKeyMetadata), _)) - .WillOnce(Return(boost::any{})); + .WillOnce(Return(olp::porting::any{})); EXPECT_CALL(*network_, Send(IsGetRequest(kOlpSdkUrlLookupQuery), _, _, _, _)) .WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus( @@ -2194,7 +2195,7 @@ TEST_F(PartitionsRepositoryTest_GetPartitionById, .WillOnce(Return(client::ApiError::NotFound())) .WillOnce(Return(response_data)); EXPECT_CALL(*cache_, Get(Eq(kCacheKeyMetadata), _)) - .WillOnce(Return(boost::any{})); + .WillOnce(Return(olp::porting::any{})); EXPECT_CALL(*network_, Send(IsGetRequest(kOlpSdkUrlLookupQuery), _, _, _, _)) .WillOnce(ReturnHttpResponse(olp::http::NetworkResponse().WithStatus( diff --git a/olp-cpp-sdk-dataservice-read/tests/VersionedLayerClientImplTest.cpp b/olp-cpp-sdk-dataservice-read/tests/VersionedLayerClientImplTest.cpp index f7d6cf791..7e41bc113 100644 --- a/olp-cpp-sdk-dataservice-read/tests/VersionedLayerClientImplTest.cpp +++ b/olp-cpp-sdk-dataservice-read/tests/VersionedLayerClientImplTest.cpp @@ -1514,7 +1514,7 @@ TEST(VersionedLayerClientTest, PropagateAllCacheErrors) { .WillRepeatedly(testing::Return(olp::client::ApiError::CacheIO())); EXPECT_CALL(*cache_mock, Get(_, _)) - .WillRepeatedly(testing::Return(boost::any())); + .WillRepeatedly(testing::Return(olp::porting::any())); EXPECT_CALL(*cache_mock, Get(_)).WillRepeatedly(testing::Return(nullptr)); EXPECT_CALL(*cache_mock, Read(_)) .WillRepeatedly(testing::Return(olp::client::ApiError::NotFound())); @@ -1569,7 +1569,7 @@ TEST(VersionedLayerClientTest, PropagateAllCacheErrors) { .WillRepeatedly(testing::Return(olp::client::ApiError::CacheIO())); EXPECT_CALL(*cache_mock, Get(_, _)) - .WillRepeatedly(testing::Return(boost::any())); + .WillRepeatedly(testing::Return(olp::porting::any())); EXPECT_CALL(*cache_mock, Get(_)).WillRepeatedly(testing::Return(nullptr)); EXPECT_CALL(*cache_mock, Read(_)) .WillRepeatedly(testing::Return(olp::client::ApiError::NotFound())); diff --git a/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplPublishToBatchTest.cpp b/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplPublishToBatchTest.cpp index bb3fb83f4..b58adfcda 100644 --- a/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplPublishToBatchTest.cpp +++ b/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplPublishToBatchTest.cpp @@ -202,7 +202,7 @@ TEST_F(VersionedLayerClientImplPublishToBatchTest, PublishToBatch) { EXPECT_CALL(*cache_, Contains(_)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) .WillRepeatedly([](const std::string& /*key*/, - const boost::any& /*value*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -234,7 +234,7 @@ TEST_F(VersionedLayerClientImplPublishToBatchTest, PublishToBatch) { EXPECT_CALL(*cache_, Contains(_)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) .WillRepeatedly([](const std::string& /*key*/, - const boost::any& /*value*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -311,7 +311,7 @@ TEST_F(VersionedLayerClientImplPublishToBatchTest, PublishToBatch) { EXPECT_CALL(*cache_, Contains(_)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) .WillRepeatedly([](const std::string& /*key*/, - const boost::any& /*value*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -344,7 +344,7 @@ TEST_F(VersionedLayerClientImplPublishToBatchTest, PublishToBatch) { EXPECT_CALL(*cache_, Contains(_)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) .WillRepeatedly([](const std::string& /*key*/, - const boost::any& /*value*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -368,7 +368,7 @@ TEST_F(VersionedLayerClientImplPublishToBatchTest, PublishToBatch) { EXPECT_CALL(*cache_, Contains(_)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) .WillRepeatedly([](const std::string& /*key*/, - const boost::any& /*value*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -408,7 +408,7 @@ TEST_F(VersionedLayerClientImplPublishToBatchTest, NetworkErrors) { EXPECT_CALL(*cache_, Contains(_)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) .WillRepeatedly([](const std::string& /*key*/, - const boost::any& /*value*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -440,7 +440,7 @@ TEST_F(VersionedLayerClientImplPublishToBatchTest, NetworkErrors) { EXPECT_CALL(*cache_, Contains(_)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) .WillRepeatedly([](const std::string& /*key*/, - const boost::any& /*value*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -471,7 +471,7 @@ TEST_F(VersionedLayerClientImplPublishToBatchTest, NetworkErrors) { EXPECT_CALL(*cache_, Contains(_)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) .WillRepeatedly([](const std::string& /*key*/, - const boost::any& /*value*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -502,7 +502,7 @@ TEST_F(VersionedLayerClientImplPublishToBatchTest, NetworkErrors) { EXPECT_CALL(*cache_, Contains(_)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) .WillRepeatedly([](const std::string& /*key*/, - const boost::any& /*value*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -532,7 +532,7 @@ TEST_F(VersionedLayerClientImplPublishToBatchTest, NetworkErrors) { EXPECT_CALL(*cache_, Contains(_)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) .WillRepeatedly([](const std::string& /*key*/, - const boost::any& /*value*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -611,7 +611,7 @@ TEST_F(VersionedLayerClientImplPublishToBatchTest, Cancel) { EXPECT_CALL(*cache_, Contains(_)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) .WillRepeatedly([](const std::string& /*key*/, - const boost::any& /*value*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -668,7 +668,7 @@ TEST_F(VersionedLayerClientImplPublishToBatchTest, Cancel) { EXPECT_CALL(*cache_, Contains(_)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) .WillRepeatedly([](const std::string& /*key*/, - const boost::any& /*value*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -721,7 +721,7 @@ TEST_F(VersionedLayerClientImplPublishToBatchTest, Cancel) { EXPECT_CALL(*cache_, Contains(_)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) .WillRepeatedly([](const std::string& /*key*/, - const boost::any& /*value*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); diff --git a/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplTest.cpp b/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplTest.cpp index 4a68f378b..e19ca97be 100644 --- a/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplTest.cpp +++ b/olp-cpp-sdk-dataservice-write/tests/VersionedLayerClientImplTest.cpp @@ -139,7 +139,8 @@ TEST_F(VersionedLayerClientImplTest, StartBatch) { // mock apis caching EXPECT_CALL(*cache_, Get(_, _)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) - .WillOnce([](const std::string& /*key*/, const boost::any& /*value*/, + .WillOnce([](const std::string& /*key*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -176,7 +177,8 @@ TEST_F(VersionedLayerClientImplTest, StartBatch) { // mock apis caching EXPECT_CALL(*cache_, Get(_, _)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) - .WillOnce([](const std::string& /*key*/, const boost::any& /*value*/, + .WillOnce([](const std::string& /*key*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -444,7 +446,8 @@ TEST_F(VersionedLayerClientImplTest, CompleteBatch) { // mock apis caching EXPECT_CALL(*cache_, Get(_, _)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) - .WillOnce([](const std::string& /*key*/, const boost::any& /*value*/, + .WillOnce([](const std::string& /*key*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); @@ -475,7 +478,8 @@ TEST_F(VersionedLayerClientImplTest, CompleteBatch) { // mock apis caching EXPECT_CALL(*cache_, Get(_, _)).Times(1); EXPECT_CALL(*cache_, Put(_, _, _, _)) - .WillOnce([](const std::string& /*key*/, const boost::any& /*value*/, + .WillOnce([](const std::string& /*key*/, + const olp::porting::any& /*value*/, const olp::cache::Encoder& /*encoder*/, time_t /*expiry*/) { return true; }); diff --git a/tests/common/KeyValueCacheTestable.h b/tests/common/KeyValueCacheTestable.h index 9f1356584..bb7f79cf8 100644 --- a/tests/common/KeyValueCacheTestable.h +++ b/tests/common/KeyValueCacheTestable.h @@ -27,7 +27,7 @@ class KeyValueCacheTestable : public olp::cache::KeyValueCache { std::shared_ptr base_cache) : base_cache_{std::move(base_cache)} {} - bool Put(const std::string& key, const boost::any& value, + bool Put(const std::string& key, const olp::porting::any& value, const olp::cache::Encoder& encoder, time_t expiry) override { return base_cache_->Put(key, value, encoder, expiry); } @@ -37,8 +37,8 @@ class KeyValueCacheTestable : public olp::cache::KeyValueCache { return base_cache_->Put(key, value, expiry); } - boost::any Get(const std::string& key, - const olp::cache::Decoder& encoder) override { + olp::porting::any Get(const std::string& key, + const olp::cache::Decoder& encoder) override { return base_cache_->Get(key, encoder); } @@ -97,8 +97,8 @@ class KeyValueCacheTestable : public olp::cache::KeyValueCache { struct CacheWithPutErrors : public KeyValueCacheTestable { using KeyValueCacheTestable::KeyValueCacheTestable; - bool Put(const std::string&, const boost::any&, const olp::cache::Encoder&, - time_t) override { + bool Put(const std::string&, const olp::porting::any&, + const olp::cache::Encoder&, time_t) override { return false; } diff --git a/tests/common/mocks/CacheMock.h b/tests/common/mocks/CacheMock.h index 9ee10664e..610cc8466 100644 --- a/tests/common/mocks/CacheMock.h +++ b/tests/common/mocks/CacheMock.h @@ -33,7 +33,7 @@ class CacheMock : public olp::cache::KeyValueCache { ~CacheMock() override; MOCK_METHOD(bool, Put, - (const std::string&, const boost::any&, + (const std::string&, const olp::porting::any&, const olp::cache::Encoder&, time_t), (override)); @@ -43,8 +43,8 @@ class CacheMock : public olp::cache::KeyValueCache { time_t expiry), (override)); - MOCK_METHOD(boost::any, Get, (const std::string&, const olp::cache::Decoder&), - (override)); + MOCK_METHOD(olp::porting::any, Get, + (const std::string&, const olp::cache::Decoder&), (override)); MOCK_METHOD(std::shared_ptr>, Get, (const std::string&), (override)); diff --git a/tests/integration/olp-cpp-sdk-dataservice-read/VersionedLayerClientTest.cpp b/tests/integration/olp-cpp-sdk-dataservice-read/VersionedLayerClientTest.cpp index 3d8148999..872e2ad7a 100644 --- a/tests/integration/olp-cpp-sdk-dataservice-read/VersionedLayerClientTest.cpp +++ b/tests/integration/olp-cpp-sdk-dataservice-read/VersionedLayerClientTest.cpp @@ -3349,7 +3349,7 @@ TEST_F(DataserviceReadVersionedLayerClientTest, CheckLookupApiCacheExpiration) { "v2::query::v1::api", _)) .Times(1) - .WillOnce(Return(boost::any())); + .WillOnce(Return(olp::porting::any())); EXPECT_CALL(*cache, Put("hrn:here:data::olp-here-test:hereos-internal-test-" "v2::query::v1::api", _, _, expiration_time)) diff --git a/tests/utils/mock-server-client/Expectation.h b/tests/utils/mock-server-client/Expectation.h index e56d31578..1df46e12e 100644 --- a/tests/utils/mock-server-client/Expectation.h +++ b/tests/utils/mock-server-client/Expectation.h @@ -21,8 +21,7 @@ #include -#include - +#include #include #include "JsonHelpers.h" @@ -49,8 +48,8 @@ struct Expectation { olp::porting::optional delay = olp::porting::none; olp::porting::optional status_code = olp::porting::none; - /// Any of BinaryResponse, std::string, boost::any - boost::any body; + /// Any of BinaryResponse, std::string, olp::porting::any + olp::porting::any body; }; struct BinaryResponse { @@ -140,9 +139,11 @@ inline void to_json(const Expectation::ResponseAction& x, serialize("statusCode", x.status_code, value, allocator); if (x.body.type() == typeid(std::string)) { - serialize("body", boost::any_cast(x.body), value, allocator); + serialize("body", olp::porting::any_cast(x.body), value, + allocator); } else if (x.body.type() == typeid(Expectation::BinaryResponse)) { - serialize("body", boost::any_cast(x.body), + serialize("body", + olp::porting::any_cast(x.body), value, allocator); }