summaryrefslogtreecommitdiff
path: root/libadhocutil/unittests/testLocks.cpp
blob: a7a506a8e3783f0e2dcd354ba5d16b728460d86c (plain)
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
#define BOOST_TEST_MODULE Locks
#include <boost/test/unit_test.hpp>

#include "lockHelpers.h"
#include <shared_mutex>

BOOST_AUTO_TEST_CASE(lock)
{
	std::shared_mutex _lock;
	{
		Lock(_lock);
		BOOST_CHECK(_lck11.owns_lock());
		BOOST_CHECK(!_lock.try_lock());
		BOOST_CHECK(!_lock.try_lock_shared());
	}
	BOOST_CHECK(_lock.try_lock());
	_lock.unlock();
	BOOST_CHECK(_lock.try_lock_shared());
	_lock.unlock_shared();
}

BOOST_AUTO_TEST_CASE(sharedlock)
{
	std::shared_mutex _lock;
	{
		SharedLock(_lock);
		BOOST_CHECK(_lck26.owns_lock());
		BOOST_CHECK(!_lock.try_lock());
		BOOST_CHECK(_lock.try_lock_shared());
		_lock.unlock_shared();
	}
	BOOST_CHECK(_lock.try_lock());
	_lock.unlock();
	BOOST_CHECK(_lock.try_lock_shared());
	_lock.unlock_shared();
}

BOOST_AUTO_TEST_CASE(scopelock)
{
	std::shared_mutex _lock;
	ScopeLock(_lock) {
		BOOST_CHECK(_lck41.owns_lock());
		BOOST_CHECK(!_lock.try_lock());
		BOOST_CHECK(!_lock.try_lock_shared());
	}
	BOOST_CHECK(_lock.try_lock());
	_lock.unlock();
	BOOST_CHECK(_lock.try_lock_shared());
	_lock.unlock_shared();
}

BOOST_AUTO_TEST_CASE(sharedscopelock)
{
	std::shared_mutex _lock;
	SharedScopeLock(_lock) {
		BOOST_CHECK(_lck55.owns_lock());
		BOOST_CHECK(!_lock.try_lock());
		BOOST_CHECK(_lock.try_lock_shared());
		_lock.unlock_shared();
	}
	BOOST_CHECK(_lock.try_lock());
	_lock.unlock();
	BOOST_CHECK(_lock.try_lock_shared());
	_lock.unlock_shared();
}