Wire Sysio
Wire Sysion 1.0.0
Loading...
Searching...
No Matches
guarded_ptr_tests.cpp
Go to the documentation of this file.
1
#include <sysio/vm/guarded_ptr.hpp>
2
3
#include <
catch2/catch.hpp
>
4
5
using namespace
sysio::vm
;
6
7
struct
S
{
int
value
; };
8
9
TEST_CASE
(
"Testing guarded_ptr"
,
"[guarded_ptr_tests]"
) {
10
int
a
[10];
11
{
12
guarded_ptr<int>
ptr(
a
,
sizeof
(
a
)/
sizeof
(
a
[0]));
13
ptr += 10;
14
CHECK
(ptr.
raw
() ==
a
+ 10);
15
}
16
{
17
guarded_ptr<int>
ptr(
a
,
sizeof
(
a
)/
sizeof
(
a
[0]));
18
CHECK_THROWS_AS
(ptr += 11, guarded_ptr_exception);
19
}
20
{
21
guarded_ptr<int>
ptr(
a
,
sizeof
(
a
)/
sizeof
(
a
[0]));
22
ptr += 0;
23
CHECK
(ptr.
raw
() ==
a
+ 0);
24
}
25
// operator++
26
{
27
guarded_ptr<int>
ptr(
a
, 1);
28
auto
& result = ++ptr;
29
CHECK
(ptr.
raw
() ==
a
+ 1);
30
CHECK
(&result == &ptr);
31
}
32
{
33
guarded_ptr<int>
ptr(
a
, 0);
34
CHECK_THROWS_AS
(++ptr, guarded_ptr_exception);
35
}
36
{
37
guarded_ptr<int>
ptr(
a
, 1);
38
auto
result = ptr++;
39
CHECK
(ptr.
raw
() ==
a
+ 1);
40
CHECK
(result.raw() ==
a
);
41
}
42
{
43
guarded_ptr<int>
ptr(
a
, 0);
44
CHECK_THROWS_AS
(ptr++, guarded_ptr_exception);
45
}
46
// operator+
47
{
48
const
guarded_ptr<int>
ptr(
a
, 10);
49
auto
result = ptr + 10;
50
CHECK
(result.raw() ==
a
+ 10);
51
}
52
{
53
const
guarded_ptr<int>
ptr(
a
, 10);
54
CHECK_THROWS_AS
(ptr + 11, guarded_ptr_exception);
55
}
56
{
57
const
guarded_ptr<int>
ptr(
a
, 10);
58
auto
result = 10 + ptr;
59
CHECK
(result.raw() ==
a
+ 10);
60
}
61
{
62
const
guarded_ptr<int>
ptr(
a
, 10);
63
CHECK_THROWS_AS
(11 + ptr, guarded_ptr_exception);
64
}
65
// operator*
66
{
67
const
guarded_ptr<int>
ptr(
a
, 1);
68
*ptr = 42;
69
CHECK
(
a
[0] == 42);
70
}
71
{
72
const
guarded_ptr<int>
ptr(
a
, 0);
73
CHECK_THROWS_AS
(*ptr, guarded_ptr_exception);
74
}
75
// operator->
76
S
s
[10];
77
{
78
const
guarded_ptr<S>
ptr(
s
, 1);
79
ptr->value = 42;
80
CHECK
(
s
[0].
value
== 42);
81
}
82
{
83
const
guarded_ptr<S>
ptr(
s
, 0);
84
CHECK_THROWS_AS
(ptr->value, guarded_ptr_exception);
85
}
86
// at
87
{
88
const
guarded_ptr<int>
ptr(
a
, 1);
89
a
[0] = 42;
90
CHECK
(ptr.
at
() == 42);
91
}
92
{
93
const
guarded_ptr<int>
ptr(
a
, 0);
94
CHECK_THROWS_AS
(ptr.
at
(), guarded_ptr_exception);
95
}
96
{
97
const
guarded_ptr<int>
ptr(
a
, 10);
98
a
[9] = 43;
99
CHECK
(ptr.
at
(9) == 43);
100
}
101
{
102
const
guarded_ptr<int>
ptr(
a
, 10);
103
CHECK_THROWS_AS
(ptr.
at
(10), guarded_ptr_exception);
104
}
105
// TODO: add_bounds/fit_bounds/bounds/offset
106
}
CHECK
#define CHECK(cond)
Definition
util.h:80
CHECK_THROWS_AS
#define CHECK_THROWS_AS(expr, exceptionType)
Definition
catch.hpp:203
TEST_CASE
#define TEST_CASE(...)
Definition
catch.hpp:222
sysio::vm
Definition
controller.hpp:23
value
#define value
Definition
pkcs11.h:157
a
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition
pointer.h:1181
catch.hpp
S
Definition
Tricky.tests.cpp:326
S::value
int value
Definition
guarded_ptr_tests.cpp:7
sysio::vm::guarded_ptr
Definition
guarded_ptr.hpp:10
sysio::vm::guarded_ptr::at
T at(size_t index) const
Definition
guarded_ptr.hpp:91
sysio::vm::guarded_ptr::raw
T * raw()
Definition
guarded_ptr.hpp:57
s
char * s
Definition
yubihsm_pkcs11.c:524
libraries
sys-vm
tests
guarded_ptr_tests.cpp
Generated by
1.12.0