summaryrefslogtreecommitdiff
path: root/test/test-instancing.cpp
blob: 2eb3647d986c7f1f1184b0da1de9407cb887594f (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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#define BOOST_TEST_MODULE instancing

#include "testHelpers.h"
#include "testMainWindow.h"
#include "ui/applicationBase.h"
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>

#include <gfx/gl/instanceVertices.h>

BOOST_GLOBAL_FIXTURE(ApplicationBase);
BOOST_GLOBAL_FIXTURE(TestMainWindow);

BOOST_FIXTURE_TEST_SUITE(i, InstanceVertices<int>)

BOOST_AUTO_TEST_CASE(createDestroy)
{
	BOOST_CHECK(!data);
	map();
	BOOST_REQUIRE(data);
	BOOST_CHECK_EQUAL(0, next);
	BOOST_CHECK(unused.empty());
	unmap();
	BOOST_CHECK(!data);
}

BOOST_AUTO_TEST_CASE(storeRetreive)
{ // Read write raw buffer, not normally allowed
	std::vector<int> test(capacity);
	map();
	std::copy(test.begin(), test.end(), data);
	BOOST_CHECK_EQUAL_COLLECTIONS(test.begin(), test.end(), data, data + capacity);
}

BOOST_AUTO_TEST_CASE(acquireRelease)
{
	{
		auto proxy = acquire();
		*proxy = 20;
		BOOST_CHECK_EQUAL(1, next);
	}
	BOOST_CHECK_EQUAL(1, next);
	BOOST_CHECK_EQUAL(1, unused.size());
	BOOST_CHECK_EQUAL(0, unused.front());
}

BOOST_AUTO_TEST_CASE(acquireReleaseMove)
{
	{
		auto proxy1 = acquire();
		*proxy1 = 20;
		BOOST_CHECK_EQUAL(1, next);
		auto proxy2 = std::move(proxy1);
		*proxy2 = 40;
		BOOST_CHECK_EQUAL(1, next);
	}
	BOOST_CHECK_EQUAL(1, next);
	BOOST_CHECK_EQUAL(1, unused.size());
	BOOST_CHECK_EQUAL(0, unused.front());
}

BOOST_AUTO_TEST_CASE(initialize)
{
	auto proxy = acquire(5);
	BOOST_CHECK_EQUAL(*proxy, 5);
}

BOOST_AUTO_TEST_CASE(resize)
{
	constexpr auto COUNT = 500;
	std::vector<decltype(acquire())> proxies;
	std::vector<int> expected;
	for (auto n = 0; n < COUNT; n++) {
		proxies.push_back(acquire(n));
		expected.emplace_back(n);
	}
	BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(), data, data + COUNT);
	BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(), proxies.begin(), proxies.end());
}

BOOST_AUTO_TEST_SUITE_END()