From 5e687fbd58860f3170b0bcbc0eacd5a7873eb909 Mon Sep 17 00:00:00 2001 From: David Williams Date: Sun, 28 Mar 2010 00:11:41 +0000 Subject: [PATCH] Added unit test for Array class. --- library/PolyVoxCore/include/Array.h | 6 +-- tests/CMakeLists.txt | 10 ++-- tests/TestArray.cpp | 82 +++++++++++++++++++++++++++++ tests/TestArray.h | 37 +++++++++++++ 4 files changed, 129 insertions(+), 6 deletions(-) create mode 100644 tests/TestArray.cpp create mode 100644 tests/TestArray.h diff --git a/library/PolyVoxCore/include/Array.h b/library/PolyVoxCore/include/Array.h index aa488009..f4700d98 100644 --- a/library/PolyVoxCore/include/Array.h +++ b/library/PolyVoxCore/include/Array.h @@ -42,7 +42,7 @@ namespace PolyVox public: Array(const uint32_t (&Dimensions)[noOfDims]) - : m_pElements(0) + :m_pElements(0) ,m_pDimensions(0) ,m_pOffsets(0) ,m_uNoOfElements(0) @@ -75,8 +75,8 @@ namespace PolyVox Array(&m_pElements[uIndex*m_pOffsets[0]], m_pDimensions+1, m_pOffsets+1); } - const Array - operator [](uint32_t uIndex) const + + const Array operator [](uint32_t uIndex) const { assert(uIndex + +#include + +using namespace PolyVox; + +void TestArray::testReadWrite() +{ + int width = 5; + int height = 10; + int depth = 20; + + Array<3, int> myArray(ArraySizes(width)(height)(depth)); + + int ct = 1; + int expectedTotal = 0; + for(int z = 0; z < depth; z++) + { + for(int y = 0; y < height; y++) + { + for(int x = 0; x < width; x++) + { + myArray[x][y][z] = ct; + expectedTotal += myArray[x][y][z]; + ct++; + } + } + } + + ct = 1; + int total = 0; + for(int z = 0; z < depth; z++) + { + for(int y = 0; y < height; y++) + { + for(int x = 0; x < width; x++) + { + QCOMPARE(myArray[x][y][z], ct); + total += myArray[x][y][z]; + ct++; + } + } + } + + QCOMPARE(total, expectedTotal); + + /*const PolyVox::uint16_t g_uVolumeSideLength = 128; + Volume volData(g_uVolumeSideLength, g_uVolumeSideLength, g_uVolumeSideLength); + + volData.tidyUpMemory(0); + + QCOMPARE(volData.getWidth(), g_uVolumeSideLength); + QCOMPARE(volData.getHeight(), g_uVolumeSideLength); + QCOMPARE(volData.getDepth(), g_uVolumeSideLength);*/ +} + +QTEST_MAIN(TestArray) diff --git a/tests/TestArray.h b/tests/TestArray.h new file mode 100644 index 00000000..2bebbdcc --- /dev/null +++ b/tests/TestArray.h @@ -0,0 +1,37 @@ +/******************************************************************************* +Copyright (c) 2010 Matt Williams + +This software is provided 'as-is', without any express or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + + 3. This notice may not be removed or altered from any source + distribution. +*******************************************************************************/ + +#ifndef __PolyVox_TestVolume_H__ +#define __PolyVox_TestVolume_H__ + +#include + +class TestArray: public QObject +{ + Q_OBJECT + + private slots: + void testReadWrite(); +}; + +#endif