FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpp11/cpp11test/src/test-external_pointer.cpp at main · josh28x/cpp11 · GitHub
josh28x
cpp11
Repository navigation
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpp11
/
cpp11test
/
src
/
test-external_pointer.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
39 lines (29 loc) · 799 Bytes
Breadcrumbs
cpp11
/
cpp11test
/
src
/
test-external_pointer.cpp
Copy path
File metadata and controls
39 lines (29 loc) · 799 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
<
iostream
>
#
include
"
cpp11/external_pointer.hpp
"
#
include
<
testthat.h
>
bool
deleted =
false
;
void
deleter
(
int
* ptr) {
deleted =
true
;
delete
ptr;
}
context
(
"
external_pointer-C++
"
) {
test_that
(
"
external_pointer works
"
) {
std::vector<
int
>* v =
new
std::vector<
int
>;
v->
push_back
(
1
);
v->
push_back
(
2
);
cpp11::external_pointer<std::vector<
int
>>
p
(v);
expect_true
(p->
at
(
0
) ==
1
);
expect_true
(p->
at
(
1
) ==
2
);
p.
release
();
//
Double release should be a no-op
p.
release
();
expect_true
(p.
get
() ==
nullptr
);
}
test_that
(
"
external_pointer works with a custom deleter
"
) {
deleted =
false
;
cpp11::external_pointer<
int
, deleter>
uniq
(
new
int
);
expect_true
(deleted ==
false
);
uniq.
reset
();
expect_true
(deleted ==
true
);
}
}
Back
|
FazBrowse Home
|
New Git URL