feat add test for any
All checks were successful
rpcrypto-build / build (Debug, himix200.toolchain.cmake) (push) Successful in 1m10s
rpcrypto-build / build (Release, hisiv510.toolchain.cmake) (push) Successful in 1m13s
rpcrypto-build / build (Debug, hisiv510.toolchain.cmake) (push) Successful in 1m21s
rpcrypto-build / build (Release, himix200.toolchain.cmake) (push) Successful in 1m21s
linux-hisiv500-gcc / linux-gcc-hisiv500 (push) Successful in 1m33s
linux-mips64-gcc / linux-gcc-mips64el (push) Successful in 1m46s
linux-x64-gcc / linux-gcc (push) Successful in 2m4s

This commit is contained in:
tqcq 2024-01-19 16:54:14 +08:00
parent 925efe8abe
commit 0529df0411
4 changed files with 35 additions and 2 deletions

View File

@ -5,10 +5,13 @@ namespace ulib {
namespace detail { namespace detail {
class MutexImpl; class MutexImpl;
} }// namespace detail
class MutexGuard;
class Mutex { class Mutex {
public: public:
using ScopedLock = MutexGuard;
Mutex(); Mutex();
~Mutex(); ~Mutex();
void Lock(); void Lock();

View File

@ -0,0 +1,21 @@
#include <gtest/gtest.h>
#include <any.h>
TEST(any, shared_ptr)
{
std::shared_ptr<int> ptr = std::make_shared<int>(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<int> ptr2 =
nonstd::any_cast<std::shared_ptr<int>>(int_any);
EXPECT_EQ(ptr2.use_count(), 3);
}
}

View File

@ -17,3 +17,11 @@ TEST(optional, not_has_value)
EXPECT_EQ(int_opt.value_or(1), 1); EXPECT_EQ(int_opt.value_or(1), 1);
EXPECT_EQ(int_opt.value_or(2), 2); EXPECT_EQ(int_opt.value_or(2), 2);
} }
TEST(optional, shared_ptr)
{
std::shared_ptr<int> ptr = std::make_shared<int>(1);
EXPECT_EQ(ptr.use_count(), 1);
ulib::optional<std::shared_ptr<int>> int_opt = ptr;
EXPECT_EQ(ptr.use_count(), 2);
}

View File

@ -15,7 +15,8 @@ add_executable(
ulib/system/timer_unittest.cpp ulib/system/timer_unittest.cpp
3party/eventbus/eventbus_unittest.cpp 3party/eventbus/eventbus_unittest.cpp
3party/inja/inja_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 3party/sqlpp11/sqlpp11_unittest.cpp
ulib/utils/defer_unittest.cpp ulib/utils/defer_unittest.cpp
ulib/utils/utils_unittest.cpp ulib/utils/utils_unittest.cpp