diff --git a/src/ulib/concorrency/mutex.h b/src/ulib/concorrency/mutex.h index 6a93c22..900379d 100644 --- a/src/ulib/concorrency/mutex.h +++ b/src/ulib/concorrency/mutex.h @@ -5,10 +5,13 @@ namespace ulib { namespace detail { class MutexImpl; -} +}// namespace detail + +class MutexGuard; class Mutex { public: + using ScopedLock = MutexGuard; Mutex(); ~Mutex(); void Lock(); diff --git a/tests/3party/nonstd/any_unittest.cpp b/tests/3party/nonstd/any_unittest.cpp new file mode 100644 index 0000000..d3e79be --- /dev/null +++ b/tests/3party/nonstd/any_unittest.cpp @@ -0,0 +1,21 @@ + +#include +#include + +TEST(any, shared_ptr) +{ + std::shared_ptr ptr = std::make_shared(1); + EXPECT_EQ(ptr.use_count(), 1); + { + nonstd::any int_any = ptr; + EXPECT_EQ(ptr.use_count(), 2); + } + EXPECT_EQ(ptr.use_count(), 1); + { + nonstd::any int_any = ptr; + EXPECT_EQ(ptr.use_count(), 2); + std::shared_ptr ptr2 = + nonstd::any_cast>(int_any); + EXPECT_EQ(ptr2.use_count(), 3); + } +} diff --git a/tests/3party/optional/optional_unittest.cpp b/tests/3party/nonstd/optional_unittest.cpp similarity index 67% rename from tests/3party/optional/optional_unittest.cpp rename to tests/3party/nonstd/optional_unittest.cpp index 75c7060..db2cc61 100644 --- a/tests/3party/optional/optional_unittest.cpp +++ b/tests/3party/nonstd/optional_unittest.cpp @@ -17,3 +17,11 @@ TEST(optional, not_has_value) EXPECT_EQ(int_opt.value_or(1), 1); EXPECT_EQ(int_opt.value_or(2), 2); } + +TEST(optional, shared_ptr) +{ + std::shared_ptr ptr = std::make_shared(1); + EXPECT_EQ(ptr.use_count(), 1); + ulib::optional> int_opt = ptr; + EXPECT_EQ(ptr.use_count(), 2); +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 95601d8..a376e3e 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -15,7 +15,8 @@ add_executable( ulib/system/timer_unittest.cpp 3party/eventbus/eventbus_unittest.cpp 3party/inja/inja_unittest.cpp - 3party/optional/optional_unittest.cpp + 3party/nonstd/optional_unittest.cpp + 3party/nonstd/any_unittest.cpp 3party/sqlpp11/sqlpp11_unittest.cpp ulib/utils/defer_unittest.cpp ulib/utils/utils_unittest.cpp