diff --git a/sdk/core/azure-core/test/ut/CMakeLists.txt b/sdk/core/azure-core/test/ut/CMakeLists.txt index fb1617e75..13d5878cd 100644 --- a/sdk/core/azure-core/test/ut/CMakeLists.txt +++ b/sdk/core/azure-core/test/ut/CMakeLists.txt @@ -42,6 +42,7 @@ endif() add_executable ( azure-core-test + test_traits.hpp authorization_challenge_parser_test.cpp azure_core_test.cpp base64_test.cpp diff --git a/sdk/core/azure-core/test/ut/etag_test.cpp b/sdk/core/azure-core/test/ut/etag_test.cpp index 6369b6a35..07db77bfc 100644 --- a/sdk/core/azure-core/test/ut/etag_test.cpp +++ b/sdk/core/azure-core/test/ut/etag_test.cpp @@ -1,6 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // SPDX-License-Identifier: MIT - +#include "test_traits.hpp" #include #include @@ -259,6 +259,54 @@ TEST(ETag, EqualsWeak) EXPECT_FALSE(ETag::Equals(weakTagtwo, weakTagTwo, ETag::ETagComparison::Weak)); } +TEST(Etag, Assignable) +{ + EXPECT_TRUE(ClassTraits::is_assignable()); + EXPECT_TRUE(ClassTraits::is_assignable()); + EXPECT_FALSE(ClassTraits::is_trivially_assignable()); + EXPECT_FALSE(ClassTraits::is_trivially_assignable()); + EXPECT_TRUE(ClassTraits::is_nothrow_assignable()); + EXPECT_FALSE(ClassTraits::is_nothrow_assignable()); +} + +TEST(Etag, Constructible) +{ + EXPECT_TRUE((ClassTraits::is_constructible())); + EXPECT_FALSE((ClassTraits::is_trivially_constructible())); + EXPECT_FALSE((ClassTraits::is_nothrow_constructible())); + EXPECT_TRUE(ClassTraits::is_default_constructible()); + EXPECT_FALSE(ClassTraits::is_trivially_default_constructible()); + EXPECT_FALSE(ClassTraits::is_nothrow_default_constructible()); +} + +TEST(Etag, CopyAndMoveConstructible) +{ + EXPECT_TRUE(ClassTraits::is_copy_constructible()); + EXPECT_FALSE(ClassTraits::is_trivially_copy_constructible()); + EXPECT_FALSE(ClassTraits::is_nothrow_copy_constructible()); + EXPECT_TRUE(ClassTraits::is_move_constructible()); + EXPECT_FALSE(ClassTraits::is_trivially_move_constructible()); + EXPECT_TRUE(ClassTraits::is_nothrow_move_constructible()); +} + +TEST(Etag, CopyAndMoveAssignable) +{ + EXPECT_TRUE(ClassTraits::is_copy_assignable()); + EXPECT_FALSE(ClassTraits::is_trivially_copy_assignable()); + EXPECT_FALSE(ClassTraits::is_nothrow_copy_assignable()); + EXPECT_TRUE(ClassTraits::is_move_assignable()); + EXPECT_FALSE(ClassTraits::is_trivially_move_assignable()); + EXPECT_TRUE(ClassTraits::is_nothrow_move_assignable()); +} + +TEST(Etag, Destructible) +{ + EXPECT_TRUE(ClassTraits::is_destructible()); + EXPECT_FALSE(ClassTraits::is_trivially_destructible()); + EXPECT_TRUE(ClassTraits::is_nothrow_destructible()); + EXPECT_FALSE(ClassTraits::has_virtual_destructor()); +} + #if GTEST_HAS_DEATH_TEST TEST(ETag, PreCondition) { diff --git a/sdk/core/azure-core/test/ut/test_traits.hpp b/sdk/core/azure-core/test/ut/test_traits.hpp new file mode 100644 index 000000000..bac24179c --- /dev/null +++ b/sdk/core/azure-core/test/ut/test_traits.hpp @@ -0,0 +1,132 @@ +#include + +template struct ClassTraits +{ + static_assert(std::is_class::value, "ClassTraits can only be used with class types"); + + // Check if T is constructible from Args + static constexpr bool is_constructible() { return std::is_constructible::value; } + + // Check if T is trivially constructible from Args + static constexpr bool is_trivially_constructible() + { + return std::is_trivially_constructible::value; + } + + // Check if T is nothrow constructible from Args + static constexpr bool is_nothrow_constructible() + { + return std::is_nothrow_constructible::value; + } + + // Check if T has a default constructor + static constexpr bool is_default_constructible() + { + return std::is_default_constructible::value; + } + + // Check if T has a trivially default constructor + static constexpr bool is_trivially_default_constructible() + { + return std::is_trivially_default_constructible::value; + } + + // Check if T has a nothrow default constructor + static constexpr bool is_nothrow_default_constructible() + { + return std::is_nothrow_default_constructible::value; + } + + // Check if T is copy-constructible + static constexpr bool is_copy_constructible() { return std::is_copy_constructible::value; } + + // Check if T is trivially copy-constructible + static constexpr bool is_trivially_copy_constructible() + { + return std::is_trivially_copy_constructible::value; + } + + // Check if T is nothrow copy-constructible + static constexpr bool is_nothrow_copy_constructible() + { + return std::is_nothrow_copy_constructible::value; + } + + // Check if T is move-constructible + static constexpr bool is_move_constructible() { return std::is_move_constructible::value; } + + // Check if T is trivially move-constructible + static constexpr bool is_trivially_move_constructible() + { + return std::is_trivially_move_constructible::value; + } + + // Check if T is nothrow move-constructible + static constexpr bool is_nothrow_move_constructible() + { + return std::is_nothrow_move_constructible::value; + } + + // Check if T is assignable from U + template static constexpr bool is_assignable() + { + return std::is_assignable::value; + } + + // Check if T is trivially assignable from U + template static constexpr bool is_trivially_assignable() + { + return std::is_trivially_assignable::value; + } + + // Check if T is nothrow assignable from U + template static constexpr bool is_nothrow_assignable() + { + return std::is_nothrow_assignable::value; + } + + // Check if T is copy-assignable + static constexpr bool is_copy_assignable() { return std::is_copy_assignable::value; } + + // Check if T is trivially copy-assignable + static constexpr bool is_trivially_copy_assignable() + { + return std::is_trivially_copy_assignable::value; + } + + // Check if T is nothrow copy-assignable + static constexpr bool is_nothrow_copy_assignable() + { + return std::is_nothrow_copy_assignable::value; + } + + // Check if T is move-assignable + static constexpr bool is_move_assignable() { return std::is_move_assignable::value; } + + // Check if T is trivially move-assignable + static constexpr bool is_trivially_move_assignable() + { + return std::is_trivially_move_assignable::value; + } + + // Check if T is nothrow move-assignable + static constexpr bool is_nothrow_move_assignable() + { + return std::is_nothrow_move_assignable::value; + } + + // Check if T is destructible + static constexpr bool is_destructible() { return std::is_destructible::value; } + + // Check if T is trivially destructible + static constexpr bool is_trivially_destructible() + { + return std::is_trivially_destructible::value; + } + + // Check if T is nothrow destructible + static constexpr bool is_nothrow_destructible() { return std::is_nothrow_destructible::value; } + + // Check if T has virtual destructor + static constexpr bool has_virtual_destructor() { return std::has_virtual_destructor::value; } +}; \ No newline at end of file