preCICE v3.1.1
Loading...
Searching...
No Matches
MultiLockTest.cpp
Go to the documentation of this file.
1#include <map>
2#include <string>
3#include "math/constants.hpp"
5#include "testing/Testing.hpp"
6#include "utils/MultiLock.hpp"
7#include "utils/String.hpp"
8
9using namespace precice;
10using namespace precice::utils;
11
12BOOST_AUTO_TEST_SUITE(UtilsTests)
13BOOST_AUTO_TEST_SUITE(MultiLockTests)
14
16{
17 PRECICE_TEST(1_rank);
19
20 BOOST_TEST(mlock.checkAll());
21 BOOST_TEST(!mlock.contains("A"));
22 BOOST_CHECK_THROW(mlock.check("A"), LockNotFoundException);
23 BOOST_CHECK_THROW(mlock.lock("A"), LockNotFoundException);
24 BOOST_CHECK_THROW(mlock.unlock("A"), LockNotFoundException);
25 BOOST_TEST(mlock.size() == 0);
26 BOOST_TEST(mlock.countUnlocked() == 0);
27 BOOST_TEST(mlock.countLocked() == 0);
28
29 mlock.add("A", true);
30 BOOST_TEST(mlock.contains("A"));
31 BOOST_TEST(!mlock.contains("B"));
32 BOOST_TEST(mlock.check("A"));
33 BOOST_TEST(mlock.checkAll());
34 BOOST_TEST(mlock.size() == 1);
35 BOOST_TEST(mlock.countUnlocked() == 0);
36 BOOST_TEST(mlock.countLocked() == 1);
37
38 mlock.add("B", false);
39 BOOST_TEST(mlock.check("A"));
40 BOOST_TEST(mlock.contains("B"));
41 BOOST_TEST(!mlock.check("B"));
42 BOOST_TEST(!mlock.checkAll());
43 BOOST_TEST(mlock.size() == 2);
44 BOOST_TEST(mlock.countUnlocked() == 1);
45 BOOST_TEST(mlock.countLocked() == 1);
46
47 mlock.lock("B");
48 BOOST_TEST(mlock.check("A"));
49 BOOST_TEST(mlock.check("B"));
50 BOOST_TEST(mlock.checkAll());
51 BOOST_TEST(mlock.size() == 2);
52 BOOST_TEST(mlock.countUnlocked() == 0);
53 BOOST_TEST(mlock.countLocked() == 2);
54
55 mlock.unlockAll();
56 BOOST_TEST(!mlock.check("A"));
57 BOOST_TEST(!mlock.check("B"));
58 BOOST_TEST(!mlock.checkAll());
59 BOOST_TEST(mlock.countUnlocked() == 2);
60 BOOST_TEST(mlock.countLocked() == 0);
61
62 mlock.lockAll();
63 BOOST_TEST(mlock.check("A"));
64 BOOST_TEST(mlock.check("B"));
65 BOOST_TEST(mlock.checkAll());
66 BOOST_TEST(mlock.countUnlocked() == 0);
67 BOOST_TEST(mlock.countLocked() == 2);
68}
69
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(MultiLockTest)
#define PRECICE_TEST(...)
Definition Testing.hpp:27
Class handling multiple locks allowing global lock and unlock operations.
Definition MultiLock.hpp:27
size_t countLocked() const
Returns the count of locked locks.
bool check(const K &name) const
Checks the status of a lock.
size_t countUnlocked() const
Returns the count of unlocked locks.
void add(Key name, bool state)
Adds a lock with a given state.
Definition MultiLock.hpp:42
void lock(const K &name)
Locks a given lock.
Definition MultiLock.hpp:52
void lockAll() noexcept
Locks all known locks.
Definition MultiLock.hpp:63
void unlockAll() noexcept
Unlocks all known locks.
Definition MultiLock.hpp:86
bool checkAll() const noexcept
Checks whether all locks are locked.
size_type size() const noexcept
Returns the total count of locks.
bool contains(const K &name) const noexcept
Checks whether a lock is known.
void unlock(const K &name)
Unlocks a given lock.
Definition MultiLock.hpp:75
contains precice-related utilities.
Main namespace of the precice library.