-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patherror.test.cc
54 lines (47 loc) · 1.5 KB
/
error.test.cc
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
// Copyright (c) 2022 Mikael Simonsson <https://mikaelsimonsson.com>.
// SPDX-License-Identifier: BSL-1.0
#include "snn-core/system/error.hh"
#include "snn-core/unittest.hh"
#include <cerrno>
namespace snn::app
{
namespace
{
bool example()
{
snn_require(system::error_category.message<cstrview>(EPERM) ==
"Operation not permitted");
return true;
}
bool test_error_category()
{
{
constexpr error_code ec{EPERM, system::error_category};
static_assert(ec.value() == 1);
static_assert(ec.category() == system::error_category);
snn_require(ec.message<cstrview>() == "Operation not permitted");
}
{
constexpr error_code ec{-123, system::error_category};
static_assert(ec.value() == -123);
static_assert(ec.category() == system::error_category);
snn_require(ec.message<cstrview>() == "");
}
{
constexpr error_code ec{999'999'999, system::error_category};
static_assert(ec.value() == 999'999'999);
static_assert(ec.category() == system::error_category);
snn_require(ec.message<cstrview>() == "");
}
return true;
}
}
}
namespace snn
{
void unittest()
{
snn_require(app::example());
snn_require(app::test_error_category());
}
}