-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathatomic_override.cpp
More file actions
44 lines (36 loc) · 1.26 KB
/
atomic_override.cpp
File metadata and controls
44 lines (36 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdx/atomic.hpp>
#include <catch2/catch_test_macros.hpp>
#include <cstdint>
#include <type_traits>
TEST_CASE("atomic with overridden type is correctly sized/aligned",
"[atomic_override]") {
auto bs = stdx::atomic<bool>{};
STATIC_REQUIRE(sizeof(decltype(bs)) == sizeof(std::uint32_t));
STATIC_REQUIRE(alignof(decltype(bs)) == alignof(std::uint32_t));
}
TEST_CASE("atomic with overridden type presents interface of original type",
"[atomic_override]") {
auto bs = stdx::atomic<bool>{};
STATIC_REQUIRE(std::is_same_v<decltype(bs.load()), bool>);
}
TEST_CASE("atomic works with overridden type", "[atomic_override]") {
auto bs = stdx::atomic<bool>{};
CHECK(!bs);
CHECK(!bs.exchange(true));
CHECK(bs);
}
TEST_CASE("atomic config works with partial specialization",
"[atomic_override]") {
using elem_t = ::atomic::atomic_type_t<int *>;
STATIC_REQUIRE(std::is_same_v<elem_t, uintptr_t>);
}
#if __cplusplus >= 202002L
namespace {
enum E : std::uint8_t {};
}
TEST_CASE("atomic config works with enum", "[atomic_override]") {
auto bs = stdx::atomic<E>{};
STATIC_REQUIRE(sizeof(decltype(bs)) == sizeof(std::uint32_t));
STATIC_REQUIRE(alignof(decltype(bs)) == alignof(std::uint32_t));
}
#endif