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
|
#define BOOST_TEST_MODULE TestNetFSLib
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
#include <entCache.impl.h>
#include <lockHelpers.h>
struct TestEntry {
TestEntry(int i, std::string n) : id(i), name(std::move(n)) { }
int id;
std::string name;
};
using TestEntCache = EntCache<TestEntry>;
template<>
void
EntCache<TestEntry>::fillCache() const noexcept
{
Lock(lock);
idcache->insert(std::make_shared<TestEntry>(1, "user1"));
idcache->insert(std::make_shared<TestEntry>(2, "user2"));
idcache->insert(std::make_shared<TestEntry>(3, "user3"));
}
const auto GoodIds = boost::unit_test::data::make({1, 2, 3});
const auto BadIds = boost::unit_test::data::make({0, -1, 10});
const auto GoodNames = boost::unit_test::data::make({"user1", "user2", "user3"});
const auto BadNames = boost::unit_test::data::make({"", "bad", "user4"});
BOOST_FIXTURE_TEST_SUITE(tec, TestEntCache);
BOOST_DATA_TEST_CASE(notfoundid, BadIds, id)
{
BOOST_CHECK(!getEntry(id));
}
BOOST_DATA_TEST_CASE(notfoundname, BadNames, name)
{
BOOST_CHECK(!getEntry(name));
}
BOOST_DATA_TEST_CASE(foundid, GoodNames ^ GoodIds, name, id)
{
BOOST_CHECK_EQUAL(getEntry(id)->name, name);
}
BOOST_DATA_TEST_CASE(foundname, GoodNames ^ GoodIds, name, id)
{
BOOST_CHECK_EQUAL(getEntry(name)->id, id);
}
BOOST_AUTO_TEST_SUITE_END();
BOOST_AUTO_TEST_CASE(group_membership)
{
Group g(0, "root");
g.members.insert(0);
g.members.insert(1);
g.members.insert(5);
BOOST_REQUIRE_EQUAL(3, g.members.size());
BOOST_CHECK(g.hasMember(0));
BOOST_CHECK(g.hasMember(1));
BOOST_CHECK(g.hasMember(5));
BOOST_CHECK(!g.hasMember(3));
BOOST_CHECK(!g.hasMember(6));
}
|