From 9e8e976bfe19450dfbaac50f8f7187f4ebb27082 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 2 Dec 2012 09:43:00 +0100 Subject: [PATCH] Work on new unit test for volumes. --- tests/testvolume.cpp | 42 ++++++++++++++++++++++++++++++------------ tests/testvolume.h | 4 +++- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/tests/testvolume.cpp b/tests/testvolume.cpp index 3ea20c23..a8279ccd 100644 --- a/tests/testvolume.cpp +++ b/tests/testvolume.cpp @@ -24,30 +24,48 @@ freely, subject to the following restrictions: #include "testvolume.h" #include "PolyVoxCore/LargeVolume.h" +#include "PolyVoxCore/RawVolume.h" +#include "PolyVoxCore/SimpleVolume.h" #include using namespace PolyVox; -void TestVolume::testSize() +template +int32_t complexVolumeTest(void) { - const int32_t g_uVolumeSideLength = 128; - LargeVolume volData(Region(Vector3DInt32(0,0,0), Vector3DInt32(g_uVolumeSideLength-1, g_uVolumeSideLength-1, g_uVolumeSideLength-1))); - - for (int32_t z = 0; z < g_uVolumeSideLength; z++) + //VolumeType testVolume(Region(-57, -31, 12, 64, 96, 131)); // Deliberatly awkward size + VolumeType testVolume(Region(0, 0, 0, 63, 63, 63)); + for(int z = testVolume.getEnclosingRegion().getLowerZ(); z <= testVolume.getEnclosingRegion().getUpperZ(); z++) { - for (int32_t y = 0; y < g_uVolumeSideLength; y++) + for(int y = testVolume.getEnclosingRegion().getLowerY(); y <= testVolume.getEnclosingRegion().getUpperY(); y++) { - for (int32_t x = 0; x < g_uVolumeSideLength; x++) + for(int x = testVolume.getEnclosingRegion().getLowerX(); x <= testVolume.getEnclosingRegion().getUpperX(); x++) { - volData.setVoxelAt(x,y,z,255); + testVolume.setVoxelAt(x, y, z, x + y + z); } } } - - QCOMPARE(volData.getWidth(), g_uVolumeSideLength); - QCOMPARE(volData.getHeight(), g_uVolumeSideLength); - QCOMPARE(volData.getDepth(), g_uVolumeSideLength); + + return testVolume.getVoxelAt(10,20,30); +} + +void TestVolume::testLarge() +{ + int32_t result = complexVolumeTest< LargeVolume >(); + QCOMPARE(result, static_cast(60)); +} + +void TestVolume::testRaw() +{ + int32_t result = complexVolumeTest< RawVolume >(); + QCOMPARE(result, static_cast(60)); +} + +void TestVolume::testSimple() +{ + int32_t result = complexVolumeTest< SimpleVolume >(); + QCOMPARE(result, static_cast(60)); } QTEST_MAIN(TestVolume) diff --git a/tests/testvolume.h b/tests/testvolume.h index 2bfe79b6..09d470fa 100644 --- a/tests/testvolume.h +++ b/tests/testvolume.h @@ -31,7 +31,9 @@ class TestVolume: public QObject Q_OBJECT private slots: - void testSize(); + void testLarge(); + void testRaw(); + void testSimple(); }; #endif