FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
thread/test/test_move_function.cpp at develop · boostorg/thread · GitHub
boostorg
/
thread
Public
Notifications
You must be signed in to change notification settings
Fork
171
Star
213
Code
Issues
77
Pull requests
13
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
thread
/
test
/
test_move_function.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
134 lines (112 loc) · 3.04 KB
Breadcrumbs
thread
/
test
/
test_move_function.cpp
Copy path
File metadata and controls
134 lines (112 loc) · 3.04 KB
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
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//
Copyright (C) 2007-8 Anthony Williams
//
//
Distributed under the Boost Software License, Version 1.0. (See accompanying
//
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
#
define
BOOST_THREAD_VERSION
2
#
define
BOOST_TEST_MODULE
Boost.Threads: move function test suite
#
include
<
boost/thread/thread_only.hpp
>
#
include
<
boost/test/unit_test.hpp
>
#
include
<
boost/thread/mutex.hpp
>
#
include
<
boost/shared_ptr.hpp
>
void
do_nothing
()
{}
BOOST_AUTO_TEST_CASE
(test_thread_move_from_lvalue_on_construction)
{
boost::thread
src
(&do_nothing);
boost::thread::id src_id=src.
get_id
();
boost::thread
dest
(
boost::move
(src));
boost::thread::id dest_id=dest.
get_id
();
BOOST_CHECK
(src_id==dest_id);
BOOST_CHECK
(src.
get_id
()==
boost::thread::id
());
dest.
join
();
}
BOOST_AUTO_TEST_CASE
(test_thread_move_from_lvalue_on_assignment)
{
boost::thread
src
(&do_nothing);
boost::thread::id src_id=src.
get_id
();
boost::thread dest;
dest=
boost::move
(src);
boost::thread::id dest_id=dest.
get_id
();
BOOST_CHECK
(src_id==dest_id);
BOOST_CHECK
(src.
get_id
()==
boost::thread::id
());
dest.
join
();
}
boost::thread
start_thread
()
{
return
boost::thread
(&do_nothing);
}
BOOST_AUTO_TEST_CASE
(test_thread_move_from_rvalue_on_construction)
{
boost::thread
x
(
start_thread
());
BOOST_CHECK
(x.
get_id
()!=
boost::thread::id
());
x.
join
();
}
BOOST_AUTO_TEST_CASE
(test_thread_move_from_rvalue_using_explicit_move)
{
//
boost::thread x(boost::move(start_thread()));
boost::thread x=
start_thread
();
BOOST_CHECK
(x.
get_id
()!=
boost::thread::id
());
x.
join
();
}
BOOST_AUTO_TEST_CASE
(test_unique_lock_move_from_lvalue_on_construction)
{
boost::mutex m;
boost::unique_lock<boost::mutex>
l
(m);
BOOST_CHECK
(l.
owns_lock
());
BOOST_CHECK
(l.
mutex
()==&m);
boost::unique_lock<boost::mutex>
l2
(
boost::move
(l));
BOOST_CHECK
(!l.
owns_lock
());
BOOST_CHECK
(!l.
mutex
());
BOOST_CHECK
(l2.
owns_lock
());
BOOST_CHECK
(l2.
mutex
()==&m);
}
boost::unique_lock<boost::mutex>
get_lock
(boost::mutex& m)
{
return
boost::unique_lock<boost::mutex>(m);
}
BOOST_AUTO_TEST_CASE
(test_unique_lock_move_from_rvalue_on_construction)
{
boost::mutex m;
boost::unique_lock<boost::mutex>
l
(
get_lock
(m));
BOOST_CHECK
(l.
owns_lock
());
BOOST_CHECK
(l.
mutex
()==&m);
}
namespace
user_test_ns
{
template
<
typename
T>
T
move
(T& t)
{
return
t.
move
();
}
bool
move_called=
false
;
struct
nc
:
public boost::shared_ptr<
int
>
{
#
ifndef
BOOST_NO_CXX11_RVALUE_REFERENCES
nc
() {}
nc
(nc&&)
{
move_called=
true
;
}
#
endif
nc
move
()
{
move_called=
true
;
return
nc
();
}
};
}
namespace
boost
{
BOOST_THREAD_DCL_MOVABLE
(user_test_ns::nc)
}
BOOST_AUTO_TEST_CASE
(test_move_for_user_defined_type_unaffected)
{
user_test_ns::nc src;
#
ifndef
BOOST_NO_CXX11_RVALUE_REFERENCES
user_test_ns::nc dest=
boost::move
(src);
#
else
user_test_ns::nc dest=
move
(src);
#
endif
BOOST_CHECK
(user_test_ns::move_called);
}
Back
|
FazBrowse Home
|
New Git URL