summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-11-06 20:48:33 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2023-11-07 01:02:02 +0000
commit2f8d7643d03f39fa848576692264d0fe3a37ed91 (patch)
treef4578e2ce3020c04a206f9eb0bc02587de5b3d6a /test
parentDon't request a specific OpenGL version, just check we get something sufficie... (diff)
downloadilt-2f8d7643d03f39fa848576692264d0fe3a37ed91.tar.bz2
ilt-2f8d7643d03f39fa848576692264d0fe3a37ed91.tar.xz
ilt-2f8d7643d03f39fa848576692264d0fe3a37ed91.zip
Reformat with new clang-format
Diffstat (limited to 'test')
-rw-r--r--test/enumDetailsData.h3
-rw-r--r--test/test-assetFactory.cpp11
-rw-r--r--test/test-collection.cpp2
-rw-r--r--test/test-geo.cpp7
-rw-r--r--test/test-glContainer.cpp3
-rw-r--r--test/test-glContextBhvr.cpp2
-rw-r--r--test/test-instancing.cpp1
-rw-r--r--test/test-lib.cpp1
-rw-r--r--test/test-maths.cpp7
-rw-r--r--test/test-network.cpp3
-rw-r--r--test/test-persistence.cpp4
-rw-r--r--test/test-render.cpp9
-rw-r--r--test/test-text.cpp2
-rw-r--r--test/testMainWindow.h1
-rw-r--r--test/testRenderOutput.h1
15 files changed, 57 insertions, 0 deletions
diff --git a/test/enumDetailsData.h b/test/enumDetailsData.h
index 713d742..b7bd601 100644
--- a/test/enumDetailsData.h
+++ b/test/enumDetailsData.h
@@ -3,13 +3,16 @@
enum GlobalUnscoped { aa, b, c };
enum class GlobalScoped { aa, b, c };
+
namespace ns {
enum Unscoped { aa, b, c };
enum class Scoped { aa, b, c };
}
+
namespace test1 {
enum class DefaultDense { a, bee, ci, de };
}
+
namespace test2 {
enum class NumberedSparse { a = 0, bee = 3, ci = -20, de = 100 };
}
diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp
index 18dc778..145481e 100644
--- a/test/test-assetFactory.cpp
+++ b/test/test-assetFactory.cpp
@@ -24,44 +24,52 @@ BOOST_GLOBAL_FIXTURE(ApplicationBase);
BOOST_GLOBAL_FIXTURE(TestMainWindow);
const std::filesystem::path TMP {"/tmp"};
+
class FactoryFixture : public TestRenderOutputSize<glm::ivec2 {2048, 1024}>, public SceneProvider {
public:
FactoryFixture() : sceneRenderer {size, output} { }
+
~FactoryFixture()
{
auto outpath = (TMP / boost::unit_test::framework::current_test_case().full_name()).replace_extension(".tga");
std::filesystem::create_directories(outpath.parent_path());
Texture::save(outImage, outpath.c_str());
}
+
void
content(const SceneShader & shader) const override
{
shader.basic.use(Location {{0, 0, 0}, {0, 0, 0}});
objects.apply(&Renderable::render, shader);
}
+
void
lights(const SceneShader & shader) const override
{
shader.pointLight.add({-3, 1, 5}, {1, 1, 1}, .1F);
}
+
void
environment(const SceneShader &, const SceneRenderer & sceneRenderer) const override
{
sceneRenderer.setAmbientLight({.4, .4, .4});
sceneRenderer.setDirectionalLight({.6, .6, .6}, east + south + south + down, *this);
}
+
void
shadows(const ShadowMapper & mapper) const override
{
mapper.dynamicPoint.use(Location {{0, 0, 0}, {0, 0, 0}});
objects.apply(&Renderable::shadows, mapper);
}
+
void
render(float dist = 10.f)
{
sceneRenderer.camera.setView({-dist, dist * 1.2f, dist * 1.2f}, south + east + down);
sceneRenderer.render(*this);
}
+
Collection<const Renderable> objects;
private:
@@ -69,6 +77,7 @@ private:
};
BOOST_FIXTURE_TEST_SUITE(m, FactoryFixture);
+
BOOST_AUTO_TEST_CASE(brush47xml, *boost::unit_test::timeout(5))
{
auto mf = AssetFactory::loadXML(RESDIR "/brush47.xml");
@@ -115,6 +124,7 @@ BOOST_AUTO_TEST_CASE(foliage, *boost::unit_test::timeout(5))
render(5);
}
+
BOOST_AUTO_TEST_SUITE_END();
BOOST_AUTO_TEST_CASE(loadall)
@@ -125,6 +135,7 @@ BOOST_AUTO_TEST_CASE(loadall)
}
template<typename T> using InOut = std::tuple<T, T>;
+
BOOST_DATA_TEST_CASE(normalizeColourName,
boost::unit_test::data::make<InOut<std::string>>({
{"", ""},
diff --git a/test/test-collection.cpp b/test/test-collection.cpp
index 16db792..00204fc 100644
--- a/test/test-collection.cpp
+++ b/test/test-collection.cpp
@@ -13,12 +13,14 @@ public:
Base() = default;
virtual ~Base() = default;
DEFAULT_MOVE_COPY(Base);
+
virtual bool
add()
{
total += 1;
return false;
}
+
unsigned int total {0};
};
diff --git a/test/test-geo.cpp b/test/test-geo.cpp
index e672e54..9874fb7 100644
--- a/test/test-geo.cpp
+++ b/test/test-geo.cpp
@@ -108,6 +108,7 @@ BOOST_AUTO_TEST_CASE(get_height_at)
using TestRayTracerData = std::tuple<glm::vec2, glm::vec2, glm::vec2::value_type, std::vector<glm::vec2>>;
BOOST_TEST_DECORATOR(*boost::unit_test::timeout(1))
+
BOOST_DATA_TEST_CASE(raytracer,
boost::unit_test::data::make<TestRayTracerData>({
{{1, 2}, {4, 5}, 4,
@@ -145,6 +146,7 @@ BOOST_DATA_TEST_CASE(raytracer,
using TestRayData = std::tuple<glm::vec3, glm::vec3, glm::vec3>;
BOOST_TEST_DECORATOR(*boost::unit_test::timeout(1))
+
BOOST_DATA_TEST_CASE(intersect_ray,
boost::unit_test::data::make<TestRayData>({
{{-1, -1, 1.0}, {1, 1, 0}, {0, 0, 1}},
@@ -169,6 +171,7 @@ BOOST_DATA_TEST_CASE(intersect_ray,
nodes[at(1, 1)].height = 4;
const auto intersect = intersectRay({start, glm::normalize(dir)});
+
BOOST_CHECK_IF(has_intersect, intersect) {
BOOST_CHECK_CLOSE_VEC(*intersect, pos);
}
@@ -178,6 +181,7 @@ auto xs = boost::unit_test::data::xrange(-20.F, 0.F, 0.6F), ys = boost::unit_tes
auto targetsx = boost::unit_test::data::xrange(0.2F, 4.9F, 1.3F),
targetsy = boost::unit_test::data::xrange(0.3F, 4.9F, 1.3F);
BOOST_TEST_DECORATOR(*boost::unit_test::timeout(1))
+
BOOST_DATA_TEST_CASE(intersect_ray_many, xs * ys * targetsx * targetsy, x, y, targetx, targety)
{
// at(x,y) is index based
@@ -189,8 +193,10 @@ BOOST_DATA_TEST_CASE(intersect_ray_many, xs * ys * targetsx * targetsy, x, y, ta
const glm::vec3 start {x, y, 10};
const auto target {this->positionAt({targetx, targety})};
const Ray ray {start, glm::normalize(target - start)};
+
BOOST_TEST_CONTEXT(ray) {
const auto intersect = intersectRay(ray);
+
BOOST_CHECK_IF(has_intersect, intersect) {
BOOST_CHECK_CLOSE_VEC(*intersect, target);
}
@@ -198,6 +204,7 @@ BOOST_DATA_TEST_CASE(intersect_ray_many, xs * ys * targetsx * targetsy, x, y, ta
}
BOOST_TEST_DECORATOR(*boost::unit_test::timeout(1))
+
BOOST_DATA_TEST_CASE(intersect_ray_miss,
boost::unit_test::data::make<Ray>({
{{3, 3, 5}, {-1, -1, 0}},
diff --git a/test/test-glContainer.cpp b/test/test-glContainer.cpp
index 33ec992..cd57a6b 100644
--- a/test/test-glContainer.cpp
+++ b/test/test-glContainer.cpp
@@ -281,6 +281,7 @@ struct C {
int x;
float y;
};
+
static_assert(std::is_trivially_destructible_v<C>);
BOOST_FIXTURE_TEST_SUITE(c, glContainer<C>)
@@ -307,9 +308,11 @@ struct CC {
{
++x;
}
+
int x;
float y;
};
+
static_assert(!std::is_trivially_destructible_v<CC>);
BOOST_FIXTURE_TEST_SUITE(cc, glContainer<CC>)
diff --git a/test/test-glContextBhvr.cpp b/test/test-glContextBhvr.cpp
index 769f61f..26b45d9 100644
--- a/test/test-glContextBhvr.cpp
+++ b/test/test-glContextBhvr.cpp
@@ -11,12 +11,14 @@
BOOST_GLOBAL_FIXTURE(ApplicationBase);
#define TEST_WINDOW_PARAMS __FILE__, 0, 0, 640, 480, static_cast<Uint32>(SDL_WINDOW_OPENGL | SDL_WINDOW_HIDDEN)
+
static void
CreateProgramTest()
{
const ProgramRef p;
BOOST_REQUIRE(p);
}
+
BOOST_AUTO_TEST_CASE(windowContextThingsBehaviour1)
{
BOOST_REQUIRE(!glCreateProgram); // Init not called yet
diff --git a/test/test-instancing.cpp b/test/test-instancing.cpp
index 7d8ea55..c1860a4 100644
--- a/test/test-instancing.cpp
+++ b/test/test-instancing.cpp
@@ -163,6 +163,7 @@ BOOST_DATA_TEST_CASE(shuffle_random, boost::unit_test::data::xrange(0, 10), x)
iused.emplace(index[i]);
}
}
+
BOOST_TEST_CONTEXT(index) {
BOOST_REQUIRE_EQUAL(iused.size(), size());
if (!iused.empty()) {
diff --git a/test/test-lib.cpp b/test/test-lib.cpp
index aaf6292..58b769a 100644
--- a/test/test-lib.cpp
+++ b/test/test-lib.cpp
@@ -9,6 +9,7 @@
#include <set>
std::set<GLuint> active;
+
void
generator(GLsizei n, GLuint * out)
{
diff --git a/test/test-maths.cpp b/test/test-maths.cpp
index a4a881d..2560319 100644
--- a/test/test-maths.cpp
+++ b/test/test-maths.cpp
@@ -36,6 +36,7 @@ static_assert(east.x > 0);
static_assert(west == -east);
// (-ve, y, z) is "west"
static_assert(west.x < 0);
+
//
// Therefore, the geographic world exists west -ve to east +ve and from south -ve to north +ve. Forward shall be
// considered +ve motion; the "front" of a vehicle shall have a +ve value in y axis.
@@ -110,9 +111,11 @@ const auto rots = boost::unit_test::data::make<std::tuple<glm::vec3, glm::mat4 (
{east, rotate_pitch, "pitch"},
{north, rotate_roll, "roll"},
});
+
BOOST_DATA_TEST_CASE(test_rotations, (angs + random_angs) * rots, angle, ai, axis, ilt_func, name)
{
(void)ai;
+
BOOST_TEST_CONTEXT(name) {
const auto g {glm::rotate(angle, axis)}, ilt {ilt_func(angle)};
for (glm::length_t c = 0; c < 4; c++) {
@@ -130,6 +133,7 @@ BOOST_DATA_TEST_CASE(test_rotations, (angs + random_angs) * rots, angle, ai, axi
// An arc shall be defined as a centre point, start point and end point. The arc shall progress positively from start to
// end in a clockwise manner. Arc start shall be the yaw from centre to start, arc end shall be greater than arc start.
using pos3_to_arc = std::tuple<glm::vec3, glm::vec3, glm::vec3, Arc>;
+
BOOST_DATA_TEST_CASE(test_create_arc,
boost::unit_test::data::make<pos3_to_arc>({
{{0, 0, 0}, north, east, {0, half_pi}},
@@ -148,6 +152,7 @@ BOOST_DATA_TEST_CASE(test_create_arc,
}
using fac = std::tuple<glm::vec2, float, glm::vec2, float, glm::vec2, bool>;
+
BOOST_DATA_TEST_CASE(test_find_arc_centre,
boost::unit_test::data::make<fac>({
{{2, 2}, pi, {3, 3}, half_pi, {3, 2}, true},
@@ -178,6 +183,7 @@ struct TestLinkStraight : public LinkStraight {
};
using StraightsData = std::tuple<glm::vec3, float /*angFor*/, float /* angBack*/>;
+
BOOST_DATA_TEST_CASE(straight1,
boost::unit_test::data::make<StraightsData>({
{north, 0, pi},
@@ -210,6 +216,7 @@ struct TestLinkCurve : public LinkCurve {
};
using CurvesData = std::tuple<glm::vec3 /*e1*/, glm::vec3 /*ctr*/, float /*angFor*/, float /* angBack*/>;
+
BOOST_DATA_TEST_CASE(curve1,
boost::unit_test::data::make<CurvesData>({
{north + east, east, 0, -half_pi},
diff --git a/test/test-network.cpp b/test/test-network.cpp
index a8db2b6..ab0818a 100644
--- a/test/test-network.cpp
+++ b/test/test-network.cpp
@@ -25,8 +25,11 @@ BOOST_GLOBAL_FIXTURE(TestMainWindow);
struct TestLink : public LinkStraight {
TestLink(const Node::Ptr & a, const Node::Ptr & b) : TestLink {a, b, (a->pos - b->pos)} { }
+
TestLink(Node::Ptr a, Node::Ptr b, glm::vec2 l) : Link {{std::move(a), 0}, {std::move(b), pi}, glm::length(l)} { }
+
TestLink(Node::Ptr a, Node::Ptr b, float l) : Link {{std::move(a), 0}, {std::move(b), pi}, l} { }
+
using StraightLink = TestLink;
using CurveLink = TestLink;
};
diff --git a/test/test-persistence.cpp b/test/test-persistence.cpp
index 38bbf2f..abb68c2 100644
--- a/test/test-persistence.cpp
+++ b/test/test-persistence.cpp
@@ -26,6 +26,7 @@ struct JPP {
BOOST_REQUIRE(to);
return to;
}
+
// Presumably BOOST_TEST_CONTEXT is implemented as an if (...) { }
throw std::logic_error("We shouldn't ever get here, but apparently we can!");
}
@@ -213,6 +214,7 @@ auto const TEST_STRINGS_DECODE_ONLY = boost::unit_test::data::make<svs>({
{R"J("\u056b ARMENIAN SMALL LETTER INI")J", "ի ARMENIAN SMALL LETTER INI"},
{R"J("\u0833 SAMARITAN PUNCTUATION BAU")J", "࠳ SAMARITAN PUNCTUATION BAU"},
});
+
BOOST_DATA_TEST_CASE(load_strings, TEST_STRINGS + TEST_STRINGS_DECODE_ONLY, in, exp)
{
std::stringstream str {in};
@@ -220,6 +222,7 @@ BOOST_DATA_TEST_CASE(load_strings, TEST_STRINGS + TEST_STRINGS_DECODE_ONLY, in,
}
using cpstr = std::tuple<unsigned long, std::string_view>;
+
BOOST_DATA_TEST_CASE(utf8_decode,
boost::unit_test::data::make<cpstr>({
{9, "\t"},
@@ -296,6 +299,7 @@ BOOST_AUTO_TEST_CASE(get_default_id)
{
SubObject2 so;
const auto id {so.getId()};
+
BOOST_TEST_CONTEXT(id) {
auto ptr = std::stoul(id, nullptr, 16);
BOOST_CHECK_EQUAL(ptr, reinterpret_cast<decltype(ptr)>(&so));
diff --git a/test/test-render.cpp b/test/test-render.cpp
index 0d384a3..b16f241 100644
--- a/test/test-render.cpp
+++ b/test/test-render.cpp
@@ -43,16 +43,19 @@ public:
train2->bogies.front().setPosition(train2->bogies.front().position() + train2->location.position());
train2->bogies.back().setPosition(train2->bogies.back().position() + train2->location.position());
}
+
void
content(const SceneShader & shader) const override
{
terrain.render(shader);
brush47rvc->render(shader);
}
+
void
lights(const SceneShader &) const override
{
}
+
void
shadows(const ShadowMapper & shadowMapper) const override
{
@@ -95,6 +98,7 @@ BOOST_AUTO_TEST_CASE(pointlight)
{
SceneRenderer ss {size, output};
ss.camera.setView({-10, -10, 60}, glm::normalize(glm::vec3 {1, 1, -0.5F}));
+
class PointLightScene : public TestScene {
public:
void
@@ -103,6 +107,7 @@ BOOST_AUTO_TEST_CASE(pointlight)
r.setAmbientLight({0.2F, 0.2F, 0.2F});
r.setDirectionalLight({0.2F, 0.2F, 0.2F}, west + down, *this);
}
+
void
lights(const SceneShader & shader) const override
{
@@ -113,6 +118,7 @@ BOOST_AUTO_TEST_CASE(pointlight)
}
}
};
+
const PointLightScene scene;
ss.render(scene);
Texture::save(outImage, "/tmp/pointlight.tga");
@@ -122,6 +128,7 @@ BOOST_AUTO_TEST_CASE(spotlight)
{
SceneRenderer ss {size, output};
ss.camera.setView({-10, -10, 60}, glm::normalize(glm::vec3 {1, 1, -0.5F}));
+
class PointLightScene : public TestScene {
public:
void
@@ -130,6 +137,7 @@ BOOST_AUTO_TEST_CASE(spotlight)
r.setAmbientLight({0.2F, 0.2F, 0.2F});
r.setDirectionalLight({0.2F, 0.2F, 0.2F}, west + down, *this);
}
+
void
lights(const SceneShader & shader) const override
{
@@ -139,6 +147,7 @@ BOOST_AUTO_TEST_CASE(spotlight)
shader.spotLight.add({60, 50, 3}, north + east, {1.0, 1.0, 1.0}, 0.0001F, .7F);
}
};
+
const PointLightScene scene;
ss.render(scene);
Texture::save(outImage, "/tmp/spotlight.tga");
diff --git a/test/test-text.cpp b/test/test-text.cpp
index 629892f..166a6fa 100644
--- a/test/test-text.cpp
+++ b/test/test-text.cpp
@@ -36,6 +36,7 @@ struct FontTest : public Font {
BOOST_TEST_DONT_PRINT_LOG_VALUE(Font::CharData);
using TextureSizeTestData = std::tuple<unsigned, unsigned, unsigned>;
+
BOOST_DATA_TEST_CASE(fontTextureSize, boost::unit_test::data::make<unsigned>({2, 3, 10, 50, 250}), fontHeight)
{
auto isPowerOfTwo = [](auto x) {
@@ -64,6 +65,7 @@ BOOST_AUTO_TEST_CASE(initialize_chardata)
}
using CharDataTest = std::tuple<decltype(get_codepoint(nullptr)), Font::CharData>;
+
BOOST_DATA_TEST_CASE(initialize_chardata_A,
boost::unit_test::data::make<CharDataTest>({
{'A', {0, {34, 35}, {627, 0}, {-1, 35}, 32}},
diff --git a/test/testMainWindow.h b/test/testMainWindow.h
index bc9c0bd..445491d 100644
--- a/test/testMainWindow.h
+++ b/test/testMainWindow.h
@@ -7,6 +7,7 @@ class TestMainWindow : public Window {
// in the same way a real main window would always exist.
public:
TestMainWindow();
+
void
tick(TickDuration) override
{
diff --git a/test/testRenderOutput.h b/test/testRenderOutput.h
index f5cd56b..13c380f 100644
--- a/test/testRenderOutput.h
+++ b/test/testRenderOutput.h
@@ -17,6 +17,7 @@ public:
glRenderBuffer depth;
glTexture outImage;
};
+
template<glm::ivec2 Size> class TestRenderOutputSize : public TestRenderOutput {
public:
TestRenderOutputSize() : TestRenderOutput {Size} { }