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
|
#define BOOST_TEST_MODULE TestNetFSLib
#include <boost/test/unit_test.hpp>
#include <boost/test/data/test_case.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
{
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)
{
std::string outname;
BOOST_CHECK_THROW(getName(id, &outname), NetFS::SystemError);
}
BOOST_DATA_TEST_CASE(notfoundname, BadNames, name)
{
int outid;
BOOST_CHECK_THROW(getID(name, &outid), NetFS::SystemError);
}
BOOST_DATA_TEST_CASE(foundid, GoodNames ^ GoodIds, name, id)
{
std::string outname;
BOOST_REQUIRE_NO_THROW(getName(id, &outname));
BOOST_CHECK_EQUAL(name, outname);
}
BOOST_DATA_TEST_CASE(foundname, GoodNames ^ GoodIds, name, id)
{
int outid;
BOOST_REQUIRE_NO_THROW(getID(name, &outid));
BOOST_CHECK_EQUAL(id, outid);
}
BOOST_AUTO_TEST_SUITE_END();
class TestEntCacheWithFallback : public TestEntCache {
public:
TestEntCacheWithFallback() : TestEntCache({ 4, "fallback" }) { }
};
BOOST_FIXTURE_TEST_SUITE(tecfb, TestEntCacheWithFallback);
BOOST_DATA_TEST_CASE(notfoundid, BadIds, id)
{
std::string outname;
BOOST_REQUIRE_NO_THROW(getName(id, &outname));
BOOST_CHECK_EQUAL(outname, fallback->name);
}
BOOST_DATA_TEST_CASE(notfoundname, BadNames, name)
{
int outid;
BOOST_REQUIRE_NO_THROW(getID(name, &outid));
BOOST_CHECK_EQUAL(outid, fallback->id);
}
BOOST_DATA_TEST_CASE(foundid, GoodNames ^ GoodIds, name, id)
{
std::string outname;
BOOST_REQUIRE_NO_THROW(getName(id, &outname));
BOOST_CHECK_EQUAL(name, outname);
}
BOOST_DATA_TEST_CASE(foundname, GoodNames ^ GoodIds, name, id)
{
int outid;
BOOST_REQUIRE_NO_THROW(getID(name, &outid));
BOOST_CHECK_EQUAL(id, outid);
}
BOOST_AUTO_TEST_SUITE_END();
|