-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstacktrace.cpp
More file actions
114 lines (83 loc) · 3.11 KB
/
Copy pathstacktrace.cpp
File metadata and controls
114 lines (83 loc) · 3.11 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Eggs.Stacktrace
//
// Copyright (c) 2026 Agustin Berge
//
// Distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt
#include <eggs/stacktrace.hpp>
#if __cplusplus >= 202002L
# include <compare>
#endif
#include <functional>
#include <sstream>
#include <stdexcept>
#include <utility>
#include "detail/assert.hpp"
int main()
{
// -- current() returns empty stacktrace with null backend ------------------
auto st = eggs::stacktrace::current();
EGGS_TEST_ASSERT(st.empty());
EGGS_TEST_ASSERT(st.size() == 0u);
EGGS_TEST_ASSERT(st.begin() == st.end());
EGGS_TEST_ASSERT(st.cbegin() == st.cend());
EGGS_TEST_ASSERT(st.rbegin() == st.rend());
EGGS_TEST_ASSERT(st.crbegin() == st.crend());
EGGS_TEST_ASSERT(st.crbegin() == st.rbegin());
// -- Two-parameter overload ------------------------------------------------
auto st2 = eggs::stacktrace::current(0, 10);
EGGS_TEST_ASSERT(st2.empty());
auto st3 = eggs::stacktrace::current(5);
EGGS_TEST_ASSERT(st3.empty());
// -- max_size --------------------------------------------------------------
EGGS_TEST_ASSERT(st.max_size() > 0u);
// -- Element access --------------------------------------------------------
bool threw = false;
try {
(void)st.at(0);
} catch (std::out_of_range const&) {
threw = true;
}
EGGS_TEST_ASSERT(threw);
// -- Copy / move construction ------------------------------------------------
eggs::stacktrace copied(st);
EGGS_TEST_ASSERT(copied.empty());
EGGS_TEST_ASSERT(copied == st);
eggs::stacktrace moved(std::move(copied));
EGGS_TEST_ASSERT(moved.empty());
EGGS_TEST_ASSERT(moved == st);
eggs::stacktrace copy_assigned;
copy_assigned = st;
EGGS_TEST_ASSERT(copy_assigned == st);
eggs::stacktrace move_assigned;
move_assigned = std::move(copy_assigned);
EGGS_TEST_ASSERT(move_assigned == st);
// -- swap ------------------------------------------------------------------
eggs::stacktrace a, b;
a.swap(b);
EGGS_TEST_ASSERT(a.empty() && b.empty());
swap(a, b);
EGGS_TEST_ASSERT(a.empty() && b.empty());
// -- operator== -----------------------------------------------------------
EGGS_TEST_ASSERT(a == b);
EGGS_TEST_ASSERT(!(a != b));
// -- Ordering ----------------------------------------------------------------
#if __cplusplus >= 202002L
EGGS_TEST_ASSERT((a <=> b) == std::strong_ordering::equal);
#endif
EGGS_TEST_ASSERT(!(a < b));
EGGS_TEST_ASSERT(!(a > b));
EGGS_TEST_ASSERT(a <= b);
EGGS_TEST_ASSERT(a >= b);
// -- to_string -------------------------------------------------------------
EGGS_TEST_ASSERT(eggs::to_string(st) == "");
// -- operator<< -----------------------------------------------------------
std::ostringstream oss;
oss << st;
EGGS_TEST_ASSERT(oss.str() == "");
// -- Hash --------------------------------------------------------------------
std::hash<eggs::stacktrace> h;
EGGS_TEST_ASSERT(h(st) == h(a));
return 0;
}