From 914fd31f5ce90d0660efe2c418586d9c77c26f66 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 30 Apr 2023 13:27:39 +0100 Subject: Initial commit of glContainer A std::vector like container backed by an OpenGL buffer. --- test/Jamfile.jam | 1 + test/test-glContainer.cpp | 223 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 224 insertions(+) create mode 100644 test/test-glContainer.cpp (limited to 'test') diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 1ce73b7..fb9a996 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -58,6 +58,7 @@ run perf-assetFactory.cpp : -- : test-assetFactory : benchmark benchmark test ; run test-worker.cpp ; run test-instancing.cpp : : : test ; +run test-glContainer.cpp : : : test ; compile test-static-enumDetails.cpp ; compile test-static-stream_support.cpp ; explicit perf-assetFactory ; diff --git a/test/test-glContainer.cpp b/test/test-glContainer.cpp new file mode 100644 index 0000000..efb8f71 --- /dev/null +++ b/test/test-glContainer.cpp @@ -0,0 +1,223 @@ +#define BOOST_TEST_MODULE glContainer + +#include "testHelpers.h" +#include "testMainWindow.h" +#include "ui/applicationBase.h" +#include +#include + +#include "glContainer.h" + +BOOST_TEST_DONT_PRINT_LOG_VALUE(glContainer::iterator); +BOOST_TEST_DONT_PRINT_LOG_VALUE(glContainer::const_iterator); +BOOST_TEST_DONT_PRINT_LOG_VALUE(glContainer::reserve_iterator); +BOOST_TEST_DONT_PRINT_LOG_VALUE(glContainer::const_reserve_iterator); + +BOOST_GLOBAL_FIXTURE(ApplicationBase); +BOOST_GLOBAL_FIXTURE(TestMainWindow); + +BOOST_FIXTURE_TEST_SUITE(i, glContainer) + +BOOST_AUTO_TEST_CASE(createDestroy, *boost::unit_test::timeout(1)) +{ + BOOST_CHECK(!data_); + BOOST_CHECK_NO_THROW(map()); + BOOST_REQUIRE(data_); + BOOST_CHECK_NO_THROW(unmap()); + BOOST_CHECK(!data_); +} + +BOOST_AUTO_TEST_CASE(push_back_test, *boost::unit_test::timeout(1)) +{ + BOOST_CHECK_EQUAL(capacity_, 1); + BOOST_CHECK_EQUAL(size_, 0); + BOOST_CHECK_NO_THROW(push_back(1)); + BOOST_CHECK_NO_THROW(push_back(2)); + BOOST_CHECK_NO_THROW(push_back(3)); + BOOST_CHECK_NO_THROW(push_back(4)); + BOOST_CHECK_EQUAL(capacity_, 4); + BOOST_CHECK_EQUAL(size_, 4); + { + std::array expected1 {1, 2, 3, 4}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); + BOOST_CHECK_EQUAL_COLLECTIONS(rbegin(), rend(), expected1.rbegin(), expected1.rend()); + } +} + +BOOST_AUTO_TEST_CASE(emplace_back_test, *boost::unit_test::timeout(1)) +{ + BOOST_CHECK_EQUAL(capacity_, 1); + BOOST_CHECK_EQUAL(size_, 0); + + BOOST_CHECK_NO_THROW(emplace_back(1)); + BOOST_CHECK_NO_THROW(emplace_back(2)); + BOOST_CHECK_EQUAL(capacity_, 2); + BOOST_CHECK_EQUAL(size_, 2); + + BOOST_CHECK_NO_THROW(reserve(5)); + BOOST_CHECK_EQUAL(capacity_, 5); + BOOST_CHECK_EQUAL(size_, 2); + + BOOST_CHECK_NO_THROW(emplace_back(3)); + BOOST_CHECK_NO_THROW(emplace_back(4)); + BOOST_CHECK_EQUAL(capacity_, 5); + BOOST_CHECK_EQUAL(size_, 4); + + { + std::array expected1 {1, 2, 3, 4}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); + BOOST_CHECK_EQUAL_COLLECTIONS(rbegin(), rend(), expected1.rbegin(), expected1.rend()); + } + + BOOST_CHECK_NO_THROW(emplace_back(5)); + BOOST_CHECK_EQUAL(capacity_, 5); + BOOST_CHECK_EQUAL(size_, 5); + BOOST_CHECK_NO_THROW(emplace_back(6)); + BOOST_CHECK_NO_THROW(emplace_back(7)); + BOOST_CHECK_EQUAL(capacity_, 7); + BOOST_CHECK_EQUAL(size_, 7); + + { + std::array expected2 {1, 2, 3, 4, 5, 6, 7}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected2.begin(), expected2.end()); + BOOST_CHECK_EQUAL_COLLECTIONS(rbegin(), rend(), expected2.rbegin(), expected2.rend()); + } + + BOOST_CHECK_EQUAL(7, end() - begin()); + BOOST_CHECK_EQUAL(7, rend() - rbegin()); +} + +BOOST_AUTO_TEST_CASE(resize_test) +{ + BOOST_CHECK_NO_THROW(push_back(1)); + BOOST_CHECK_NO_THROW(emplace_back(2)); + BOOST_CHECK_NO_THROW(resize(4)); + BOOST_CHECK_EQUAL(capacity_, 4); + BOOST_CHECK_EQUAL(size_, 4); + { + std::array expected1 {1, 2, 0, 0}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); + } + + BOOST_CHECK_NO_THROW(resize(1)); + BOOST_CHECK_EQUAL(capacity_, 1); + BOOST_CHECK_EQUAL(size_, 1); + { + std::array expected2 {1}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected2.begin(), expected2.end()); + } + + BOOST_CHECK_NO_THROW(resize(1)); + BOOST_CHECK_EQUAL(capacity_, 1); + BOOST_CHECK_EQUAL(size_, 1); + + BOOST_CHECK_NO_THROW(resize(0)); + BOOST_CHECK_EQUAL(capacity_, 1); + BOOST_CHECK_EQUAL(size_, 0); + BOOST_CHECK_EQUAL(begin(), end()); + BOOST_CHECK_EQUAL(rbegin(), rend()); +} + +BOOST_AUTO_TEST_CASE(shrink_to_fit_test) +{ + BOOST_CHECK_NO_THROW(reserve(4)); + BOOST_CHECK_NO_THROW(emplace_back(1)); + BOOST_CHECK_NO_THROW(emplace_back(2)); + BOOST_CHECK_EQUAL(capacity_, 4); + BOOST_CHECK_EQUAL(size_, 2); + { + std::array expected1 {1, 2}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); + } + BOOST_CHECK_NO_THROW(shrink_to_fit()); + BOOST_CHECK_EQUAL(capacity_, 2); + BOOST_CHECK_EQUAL(size_, 2); + { + std::array expected1 {1, 2}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); + } + + BOOST_CHECK_NO_THROW(shrink_to_fit()); + BOOST_CHECK_EQUAL(capacity(), 2); + BOOST_CHECK_EQUAL(size(), 2); + + BOOST_CHECK_NO_THROW(clear()); + BOOST_CHECK_EQUAL(capacity(), 2); + BOOST_CHECK_EQUAL(size(), 0); +} + +BOOST_AUTO_TEST_CASE(getters) +{ + BOOST_CHECK(empty()); + BOOST_CHECK_NO_THROW(emplace_back(1)); + BOOST_CHECK(!empty()); + BOOST_CHECK_NO_THROW(emplace_back(2)); + BOOST_CHECK_EQUAL(1, front()); + BOOST_CHECK_EQUAL(2, back()); + BOOST_CHECK_EQUAL(1, at(0)); + BOOST_CHECK_EQUAL(2, at(1)); + BOOST_CHECK_EQUAL(1, (*this)[0]); + BOOST_CHECK_EQUAL(2, (*this)[1]); + BOOST_CHECK_EQUAL(data_, data()); + BOOST_CHECK_THROW(std::ignore = at(2), std::out_of_range); + + const auto & constCont {*this}; + BOOST_CHECK_EQUAL(1, constCont.front()); + BOOST_CHECK_EQUAL(2, constCont.back()); + { + std::array expected1 {1, 2}; + BOOST_CHECK_EQUAL_COLLECTIONS(constCont.begin(), constCont.end(), expected1.begin(), expected1.end()); + BOOST_CHECK_EQUAL_COLLECTIONS(constCont.rbegin(), constCont.rend(), expected1.rbegin(), expected1.rend()); + BOOST_CHECK_EQUAL_COLLECTIONS(constCont.cbegin(), constCont.cend(), expected1.cbegin(), expected1.cend()); + BOOST_CHECK_EQUAL_COLLECTIONS(constCont.crbegin(), constCont.crend(), expected1.crbegin(), expected1.crend()); + } + BOOST_CHECK_EQUAL(1, constCont.at(0)); + BOOST_CHECK_EQUAL(2, constCont.at(1)); + BOOST_CHECK_EQUAL(1, constCont[0]); + BOOST_CHECK_EQUAL(2, constCont[1]); + BOOST_CHECK_EQUAL(data_, constCont.data()); + BOOST_CHECK_THROW(std::ignore = constCont.at(2), std::out_of_range); +} + +BOOST_AUTO_TEST_CASE(random_access) +{ + BOOST_CHECK_NO_THROW(emplace_back(1)); + BOOST_CHECK_NO_THROW(emplace_back(2)); + BOOST_CHECK_NO_THROW(emplace_back(3)); + + auto i = begin(); + BOOST_CHECK_EQUAL(1, *i); + BOOST_CHECK_EQUAL(2, *++i); + BOOST_CHECK_EQUAL(2, *i++); + BOOST_CHECK_EQUAL(3, *i); + BOOST_CHECK_EQUAL(3, *i--); + BOOST_CHECK_EQUAL(2, *i); + BOOST_CHECK_EQUAL(1, *--i); + BOOST_CHECK_EQUAL(1, *i); +} + +BOOST_AUTO_TEST_SUITE_END(); + +struct C { + int x; + float y; +}; + +BOOST_FIXTURE_TEST_SUITE(c, glContainer) + +BOOST_AUTO_TEST_CASE(basic) +{ + BOOST_CHECK_NO_THROW(emplace_back(1, 2.f)); + BOOST_CHECK_EQUAL(1, begin()->x); + BOOST_CHECK_EQUAL(2.f, begin()->y); + BOOST_CHECK_NO_THROW(begin()->x = 3); + BOOST_CHECK_EQUAL(3, begin()->x); + + BOOST_CHECK_NO_THROW(push_back(C {4, 5.f})); + BOOST_CHECK_EQUAL(3, begin()->x); + BOOST_CHECK_EQUAL(2.f, begin()->y); + BOOST_CHECK_EQUAL(4, rbegin()->x); + BOOST_CHECK_EQUAL(5.f, rbegin()->y); +} + +BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3 From 10f9c0e3aac7a3b540ac34b4ff515954219599a5 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 1 May 2023 16:03:49 +0100 Subject: Extend glContainer with most of the interface expected of an STL container --- test/test-glContainer.cpp | 117 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) (limited to 'test') diff --git a/test/test-glContainer.cpp b/test/test-glContainer.cpp index efb8f71..5df56d4 100644 --- a/test/test-glContainer.cpp +++ b/test/test-glContainer.cpp @@ -22,6 +22,9 @@ BOOST_AUTO_TEST_CASE(createDestroy, *boost::unit_test::timeout(1)) { BOOST_CHECK(!data_); BOOST_CHECK_NO_THROW(map()); + BOOST_REQUIRE(!data_); + BOOST_CHECK_NO_THROW(emplace_back(0)); + BOOST_CHECK_NO_THROW(map()); BOOST_REQUIRE(data_); BOOST_CHECK_NO_THROW(unmap()); BOOST_CHECK(!data_); @@ -196,12 +199,78 @@ BOOST_AUTO_TEST_CASE(random_access) BOOST_CHECK_EQUAL(1, *i); } +BOOST_AUTO_TEST_CASE(insert_remove_test) +{ + BOOST_CHECK_NO_THROW(emplace_back(1)); + BOOST_CHECK_NO_THROW(emplace_back(2)); + BOOST_CHECK_NO_THROW(emplace_back(3)); + BOOST_CHECK_NO_THROW(emplace_back(4)); + BOOST_CHECK_NO_THROW(pop_back()); + BOOST_CHECK_EQUAL(size_, 3); + BOOST_CHECK_EQUAL(capacity_, 4); + + BOOST_CHECK_NO_THROW(emplace(begin(), 5)); + BOOST_CHECK_EQUAL(size_, 4); + BOOST_CHECK_EQUAL(capacity_, 4); + { + std::array expected1 {5, 1, 2, 3}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); + } + + { + std::array expected1 {2, 3}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin() + 2, end(), expected1.begin(), expected1.end()); + } + BOOST_CHECK_NO_THROW(insert(begin() + 2, 6)); + BOOST_CHECK_EQUAL(size_, 5); + BOOST_CHECK_EQUAL(capacity_, 5); + { + std::array expected1 {5, 1, 6, 2, 3}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); + } + erase(begin() + 1); + BOOST_CHECK_EQUAL(size_, 4); + BOOST_CHECK_EQUAL(capacity_, 5); + { + std::array expected1 {5, 6, 2, 3}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); + } + erase(begin() + 1, end() - 1); + BOOST_CHECK_EQUAL(size_, 2); + BOOST_CHECK_EQUAL(capacity_, 5); + { + std::array expected1 {5, 3}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); + } +} + +BOOST_AUTO_TEST_CASE(stl) +{ + BOOST_CHECK_NO_THROW(resize(10)); + BOOST_CHECK_NO_THROW(std::generate(begin(), end(), [x = 0]() mutable { + return x++; + })); + BOOST_CHECK_NO_THROW(std::sort(rbegin(), rend())); + { + std::array expected1 {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); + } + const auto newend = std::remove_if(begin(), end(), [](const auto & x) { + return x % 2 == 0; + }); + { + std::array expected1 {9, 7, 5, 3, 1}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), newend, expected1.begin(), expected1.end()); + } +} + BOOST_AUTO_TEST_SUITE_END(); struct C { int x; float y; }; +static_assert(std::is_trivially_destructible_v); BOOST_FIXTURE_TEST_SUITE(c, glContainer) @@ -221,3 +290,51 @@ BOOST_AUTO_TEST_CASE(basic) } BOOST_AUTO_TEST_SUITE_END(); + +struct CC { + ~CC() + { + ++x; + } + int x; + float y; +}; +static_assert(!std::is_trivially_destructible_v); + +BOOST_FIXTURE_TEST_SUITE(cc, glContainer) + +BOOST_AUTO_TEST_CASE(basic) +{ + BOOST_CHECK_NO_THROW(emplace_back(1, 2.f)); + BOOST_CHECK_EQUAL(1, begin()->x); + BOOST_CHECK_EQUAL(2.f, begin()->y); + BOOST_CHECK_NO_THROW(begin()->x = 3); + BOOST_CHECK_EQUAL(3, begin()->x); + + BOOST_CHECK_NO_THROW(push_back(CC {4, 5.f})); + BOOST_CHECK_EQUAL(3, begin()->x); + BOOST_CHECK_EQUAL(2.f, begin()->y); + BOOST_CHECK_EQUAL(4, rbegin()->x); + BOOST_CHECK_EQUAL(5.f, rbegin()->y); + BOOST_CHECK_NO_THROW(pop_back()); + BOOST_CHECK_EQUAL(size(), 1); + BOOST_CHECK_EQUAL(capacity(), 2); + BOOST_CHECK_NO_THROW(resize(3)); + BOOST_CHECK_EQUAL(size(), 3); + BOOST_CHECK_EQUAL(capacity(), 3); + BOOST_CHECK_NO_THROW(resize(1)); + BOOST_CHECK_EQUAL(size(), 1); + BOOST_CHECK_EQUAL(capacity(), 1); +} +BOOST_AUTO_TEST_CASE(insert_remove_test) +{ + BOOST_CHECK_NO_THROW(emplace_back(1, 2.f)); + BOOST_CHECK_NO_THROW(emplace_back(3, 4.f)); + BOOST_CHECK_NO_THROW(emplace(begin(), 5, 6.f)); + BOOST_CHECK_NO_THROW(emplace(begin() + 1, 7, 8.f)); + BOOST_CHECK_NO_THROW(emplace(begin() + 2, 9, 10.f)); + BOOST_CHECK_EQUAL(capacity(), 5); + BOOST_CHECK_EQUAL(size(), 5); +} + +BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3 From d23fbdbe85404da8f8e0f3697852e83cc2192c38 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 1 May 2023 16:08:25 +0100 Subject: glContainer should at least double in capacity as required --- test/test-glContainer.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/test-glContainer.cpp b/test/test-glContainer.cpp index 5df56d4..09d21d1 100644 --- a/test/test-glContainer.cpp +++ b/test/test-glContainer.cpp @@ -77,7 +77,7 @@ BOOST_AUTO_TEST_CASE(emplace_back_test, *boost::unit_test::timeout(1)) BOOST_CHECK_EQUAL(size_, 5); BOOST_CHECK_NO_THROW(emplace_back(6)); BOOST_CHECK_NO_THROW(emplace_back(7)); - BOOST_CHECK_EQUAL(capacity_, 7); + BOOST_CHECK_EQUAL(capacity_, 10); BOOST_CHECK_EQUAL(size_, 7); { @@ -223,21 +223,21 @@ BOOST_AUTO_TEST_CASE(insert_remove_test) } BOOST_CHECK_NO_THROW(insert(begin() + 2, 6)); BOOST_CHECK_EQUAL(size_, 5); - BOOST_CHECK_EQUAL(capacity_, 5); + BOOST_CHECK_EQUAL(capacity_, 8); { std::array expected1 {5, 1, 6, 2, 3}; BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); } erase(begin() + 1); BOOST_CHECK_EQUAL(size_, 4); - BOOST_CHECK_EQUAL(capacity_, 5); + BOOST_CHECK_EQUAL(capacity_, 8); { std::array expected1 {5, 6, 2, 3}; BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); } erase(begin() + 1, end() - 1); BOOST_CHECK_EQUAL(size_, 2); - BOOST_CHECK_EQUAL(capacity_, 5); + BOOST_CHECK_EQUAL(capacity_, 8); { std::array expected1 {5, 3}; BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); @@ -333,6 +333,9 @@ BOOST_AUTO_TEST_CASE(insert_remove_test) BOOST_CHECK_NO_THROW(emplace(begin(), 5, 6.f)); BOOST_CHECK_NO_THROW(emplace(begin() + 1, 7, 8.f)); BOOST_CHECK_NO_THROW(emplace(begin() + 2, 9, 10.f)); + BOOST_CHECK_EQUAL(capacity(), 8); + BOOST_CHECK_EQUAL(size(), 5); + BOOST_CHECK_NO_THROW(shrink_to_fit()); BOOST_CHECK_EQUAL(capacity(), 5); BOOST_CHECK_EQUAL(size(), 5); } -- cgit v1.2.3 From 90214f9707f603741b84798c3672b5b13244a817 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 1 May 2023 16:21:30 +0100 Subject: Add missing test over iterator comparison --- test/test-glContainer.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'test') diff --git a/test/test-glContainer.cpp b/test/test-glContainer.cpp index 09d21d1..33ec992 100644 --- a/test/test-glContainer.cpp +++ b/test/test-glContainer.cpp @@ -264,6 +264,17 @@ BOOST_AUTO_TEST_CASE(stl) } } +BOOST_AUTO_TEST_CASE(iter_compare) +{ + BOOST_CHECK_EQUAL(begin(), end()); + BOOST_CHECK_EQUAL(rbegin(), rend()); + emplace_back(); + BOOST_CHECK_LT(begin(), end()); + BOOST_CHECK_LT(rbegin(), rend()); + BOOST_CHECK_LT(cbegin(), cend()); + BOOST_CHECK_LT(crbegin(), crend()); +} + BOOST_AUTO_TEST_SUITE_END(); struct C { @@ -326,6 +337,7 @@ BOOST_AUTO_TEST_CASE(basic) BOOST_CHECK_EQUAL(size(), 1); BOOST_CHECK_EQUAL(capacity(), 1); } + BOOST_AUTO_TEST_CASE(insert_remove_test) { BOOST_CHECK_NO_THROW(emplace_back(1, 2.f)); -- cgit v1.2.3 From a6457aea04d1705f5b03f9c9e628bebbefdcf64c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 1 May 2023 18:14:49 +0100 Subject: Add the pack container Keeps its elements densely packed together without any interest in order --- test/Jamfile.jam | 1 + test/test-pack.cpp | 41 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 test/test-pack.cpp (limited to 'test') diff --git a/test/Jamfile.jam b/test/Jamfile.jam index fb9a996..3b4e891 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -59,6 +59,7 @@ run perf-persistence.cpp : -- : test-persistence : benchmark t run test-worker.cpp ; run test-instancing.cpp : : : test ; run test-glContainer.cpp : : : test ; +run test-pack.cpp : : : test ; compile test-static-enumDetails.cpp ; compile test-static-stream_support.cpp ; explicit perf-assetFactory ; diff --git a/test/test-pack.cpp b/test/test-pack.cpp new file mode 100644 index 0000000..1f9f061 --- /dev/null +++ b/test/test-pack.cpp @@ -0,0 +1,41 @@ +#define BOOST_TEST_MODULE pack + +#include +#include + +#include "pack.h" +#include + +using IntegerVectorPack = pack; + +BOOST_FIXTURE_TEST_SUITE(pint, IntegerVectorPack) + +BOOST_AUTO_TEST_CASE(basics) +{ + BOOST_CHECK_EQUAL(size(), 0); + BOOST_CHECK_NO_THROW(emplace(1)); + BOOST_CHECK_NO_THROW(emplace(2)); + BOOST_CHECK_NO_THROW(emplace(3)); + BOOST_CHECK_NO_THROW(emplace(4)); + BOOST_CHECK_EQUAL(size(), 4); + { + std::array expected1 {1, 2, 3, 4}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); + } + + BOOST_CHECK_NO_THROW(erase(begin() + 1)); + BOOST_CHECK_EQUAL(size(), 3); + { + std::array expected1 {1, 4, 3}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); + } + + BOOST_CHECK_NO_THROW(erase(--end())); + BOOST_CHECK_EQUAL(size(), 2); + { + std::array expected1 {1, 4}; + BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); + } +} + +BOOST_AUTO_TEST_SUITE_END() -- cgit v1.2.3 From c977c02ba3a6ad6ada3f1a458b41a77f2be2b871 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 1 May 2023 21:29:01 +0100 Subject: Refactor InstanceVertices in terms of glContainer --- test/test-instancing.cpp | 65 ++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 35 deletions(-) (limited to 'test') diff --git a/test/test-instancing.cpp b/test/test-instancing.cpp index 8745484..7d8ea55 100644 --- a/test/test-instancing.cpp +++ b/test/test-instancing.cpp @@ -17,14 +17,8 @@ BOOST_FIXTURE_TEST_SUITE(i, InstanceVertices) BOOST_AUTO_TEST_CASE(createDestroy) { - BOOST_CHECK(!data); - map(); - BOOST_REQUIRE(data); - BOOST_CHECK_EQUAL(0, next); BOOST_CHECK(unused.empty()); BOOST_CHECK(index.empty()); - unmap(); - BOOST_CHECK(!data); } BOOST_AUTO_TEST_CASE(acquireRelease) @@ -32,12 +26,12 @@ BOOST_AUTO_TEST_CASE(acquireRelease) { auto proxy = acquire(); *proxy = 20; - BOOST_CHECK_EQUAL(1, next); + BOOST_CHECK_EQUAL(1, size()); BOOST_REQUIRE_EQUAL(1, index.size()); BOOST_CHECK_EQUAL(0, index.front()); BOOST_CHECK(unused.empty()); } - BOOST_CHECK_EQUAL(0, next); + BOOST_CHECK_EQUAL(0, size()); BOOST_CHECK(unused.empty()); BOOST_CHECK(index.empty()); } @@ -47,13 +41,13 @@ BOOST_AUTO_TEST_CASE(acquireReleaseMove) { auto proxy1 = acquire(); *proxy1 = 20; - BOOST_CHECK_EQUAL(1, next); + BOOST_CHECK_EQUAL(1, size()); auto proxy2 = std::move(proxy1); proxy2 = 40; - BOOST_CHECK_EQUAL(1, next); - BOOST_CHECK_EQUAL(data[0], 40); + BOOST_CHECK_EQUAL(1, size()); + BOOST_CHECK_EQUAL(at(0), 40); } - BOOST_CHECK_EQUAL(0, next); + BOOST_CHECK_EQUAL(0, size()); BOOST_CHECK(unused.empty()); BOOST_CHECK(index.empty()); } @@ -62,13 +56,13 @@ BOOST_AUTO_TEST_CASE(autoMapUnmap) { { auto proxy = acquire(); - BOOST_CHECK(data); + BOOST_CHECK(data_); std::ignore = bufferName(); - BOOST_CHECK(data); - BOOST_CHECK_EQUAL(1, count()); - BOOST_CHECK(!data); + BOOST_CHECK(data_); + BOOST_CHECK_EQUAL(1, size()); + BOOST_CHECK(!data_); } - BOOST_CHECK_EQUAL(0, count()); + BOOST_CHECK_EQUAL(0, size()); } BOOST_AUTO_TEST_CASE(initialize) @@ -89,7 +83,7 @@ BOOST_AUTO_TEST_CASE(resize) 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(), data(), data() + COUNT); BOOST_CHECK_EQUAL_COLLECTIONS(expected.begin(), expected.end(), proxies.begin(), proxies.end()); } @@ -100,11 +94,11 @@ BOOST_AUTO_TEST_CASE(shuffle) BOOST_CHECK_EQUAL(1, proxies.emplace_back(acquire(1))); BOOST_CHECK_EQUAL(2, proxies.emplace_back(acquire(2))); BOOST_CHECK_EQUAL(3, proxies.emplace_back(acquire(3))); - BOOST_CHECK_EQUAL(4, next); - BOOST_CHECK_EQUAL(data + 0, proxies[0].get()); - BOOST_CHECK_EQUAL(data + 1, proxies[1].get()); - BOOST_CHECK_EQUAL(data + 2, proxies[2].get()); - BOOST_CHECK_EQUAL(data + 3, proxies[3].get()); + BOOST_CHECK_EQUAL(4, size()); + BOOST_CHECK_EQUAL(at(0), *proxies[0].get()); + BOOST_CHECK_EQUAL(at(1), *proxies[1].get()); + BOOST_CHECK_EQUAL(at(2), *proxies[2].get()); + BOOST_CHECK_EQUAL(at(3), *proxies[3].get()); BOOST_CHECK(unused.empty()); BOOST_REQUIRE_EQUAL(4, index.size()); BOOST_CHECK_EQUAL(0, index[0]); @@ -113,28 +107,29 @@ BOOST_AUTO_TEST_CASE(shuffle) BOOST_CHECK_EQUAL(3, index[3]); // Remove 1, 3 moves to [1] proxies.erase(proxies.begin() + 1); + BOOST_REQUIRE_EQUAL(3, proxies.size()); BOOST_REQUIRE_EQUAL(4, index.size()); BOOST_REQUIRE_EQUAL(1, unused.size()); BOOST_CHECK_EQUAL(1, unused[0]); - BOOST_CHECK_EQUAL(data + 0, proxies[0].get()); - BOOST_CHECK_EQUAL(data + 2, proxies[1].get()); - BOOST_CHECK_EQUAL(data + 1, proxies[2].get()); - // Remove 1, 2 moves to [1] + BOOST_CHECK_EQUAL(at(0), *proxies[0].get()); + BOOST_CHECK_EQUAL(at(2), *proxies[1].get()); + BOOST_CHECK_EQUAL(at(1), *proxies[2].get()); + // Remove 1, 2 moves to [1] proxies.erase(proxies.begin() + 1); BOOST_REQUIRE_EQUAL(4, index.size()); BOOST_REQUIRE_EQUAL(2, unused.size()); BOOST_CHECK_EQUAL(1, unused[0]); BOOST_CHECK_EQUAL(2, unused[1]); - BOOST_CHECK_EQUAL(data + 0, proxies[0].get()); - BOOST_CHECK_EQUAL(data + 1, proxies[1].get()); + BOOST_CHECK_EQUAL(at(0), *proxies[0].get()); + BOOST_CHECK_EQUAL(at(1), *proxies[1].get()); // Add new, takes 2 at [2] BOOST_CHECK_EQUAL(4, proxies.emplace_back(acquire(4))); BOOST_REQUIRE_EQUAL(4, index.size()); BOOST_REQUIRE_EQUAL(1, unused.size()); BOOST_CHECK_EQUAL(1, unused[0]); - BOOST_CHECK_EQUAL(data + 0, proxies[0].get()); - BOOST_CHECK_EQUAL(data + 1, proxies[1].get()); - BOOST_CHECK_EQUAL(data + 2, proxies[2].get()); + BOOST_CHECK_EQUAL(at(0), *proxies[0].get()); + BOOST_CHECK_EQUAL(at(1), *proxies[1].get()); + BOOST_CHECK_EQUAL(at(2), *proxies[2].get()); } BOOST_DATA_TEST_CASE(shuffle_random, boost::unit_test::data::xrange(0, 10), x) @@ -158,7 +153,7 @@ BOOST_DATA_TEST_CASE(shuffle_random, boost::unit_test::data::xrange(0, 10), x) break; } - BOOST_REQUIRE_EQUAL(next, proxies.size()); + BOOST_REQUIRE_EQUAL(size(), proxies.size()); for (const auto & [n, p] : proxies) { BOOST_REQUIRE_EQUAL(n, p); } @@ -169,10 +164,10 @@ BOOST_DATA_TEST_CASE(shuffle_random, boost::unit_test::data::xrange(0, 10), x) } } BOOST_TEST_CONTEXT(index) { - BOOST_REQUIRE_EQUAL(iused.size(), next); + BOOST_REQUIRE_EQUAL(iused.size(), size()); if (!iused.empty()) { BOOST_REQUIRE_EQUAL(*iused.begin(), 0); - BOOST_REQUIRE_EQUAL(*iused.rbegin(), next - 1); + BOOST_REQUIRE_EQUAL(*iused.rbegin(), size() - 1); } } } -- cgit v1.2.3 From 72ab29786f6d4c97a92cb95c75091537490e2d0f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 6 May 2023 16:42:08 +0100 Subject: Templated BufferedLocation and single buffer storage for RVC locations --- test/test-render.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/test-render.cpp b/test/test-render.cpp index 4bfcad2..0d384a3 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -21,9 +21,9 @@ #include class TestScene : public SceneProvider { - std::shared_ptr train1, train2; const RailVehicleClassPtr brush47rvc = std::dynamic_pointer_cast( AssetFactory::loadXML(RESDIR "/brush47.xml")->assets.at("brush-47")); + std::shared_ptr train1, train2; Terrain terrain {[]() { auto gd = std::make_shared(GeoData::Limits {{0, 0}, {100, 100}}); -- cgit v1.2.3