[6] | 1 | |
---|
| 2 | #include <cppunit/CompilerOutputter.h> |
---|
| 3 | #include <cppunit/extensions/TestFactoryRegistry.h> |
---|
| 4 | #include <cppunit/ui/text/TestRunner.h> |
---|
| 5 | #include "SWWReaderTest.h" |
---|
| 6 | |
---|
| 7 | |
---|
| 8 | // Registers the fixture |
---|
| 9 | CPPUNIT_TEST_SUITE_REGISTRATION( SWWReaderTest ); |
---|
| 10 | |
---|
| 11 | |
---|
| 12 | |
---|
| 13 | void SWWReaderTest::setUp() |
---|
| 14 | { |
---|
| 15 | _sww = new SWWReader("../SWWReaderTest/test.sww"); |
---|
| 16 | } |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | void SWWReaderTest::testValid() |
---|
| 20 | { |
---|
| 21 | CPPUNIT_ASSERT( _sww->isValid() ); |
---|
| 22 | } |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | |
---|
| 26 | void SWWReaderTest::testNumberOfVertices() |
---|
| 27 | { |
---|
| 28 | const size_t nvertices = 20; |
---|
| 29 | CPPUNIT_ASSERT_EQUAL( _sww->getNumberOfVertices(), nvertices ); |
---|
| 30 | } |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | |
---|
| 34 | void SWWReaderTest::testTime() |
---|
| 35 | { |
---|
| 36 | const unsigned int ntimesteps = 3; |
---|
| 37 | CPPUNIT_ASSERT_EQUAL( _sww->getNumberOfTimesteps(), ntimesteps ); |
---|
| 38 | |
---|
| 39 | // hard-coded values from sww file |
---|
| 40 | const float time_array[3] = {0.0, 0.5, 1.0}; |
---|
| 41 | for (unsigned int i=0; i<ntimesteps; i++) |
---|
| 42 | CPPUNIT_ASSERT_EQUAL( _sww->getTime(i), time_array[i] ); |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | |
---|
| 46 | |
---|
| 47 | void SWWReaderTest::testBedslopeVertexArray() |
---|
| 48 | { |
---|
| 49 | osg::ref_ptr<osg::Vec3Array> actual = _sww->getBedslopeVertexArray(); |
---|
| 50 | |
---|
| 51 | // expected number of bedslope vertices |
---|
| 52 | const size_t nvertices = 20; |
---|
| 53 | CPPUNIT_ASSERT_EQUAL( actual->size(), nvertices ); |
---|
| 54 | |
---|
| 55 | // hard-coded values extracted from sww file |
---|
| 56 | using osg::Vec3; |
---|
| 57 | using osg::Vec3Array; |
---|
| 58 | Vec3Array *expected = new Vec3Array(20); |
---|
| 59 | (*expected)[ 0] = Vec3( 0.000000, 0.000000, 0.000000 ); |
---|
| 60 | (*expected)[ 1] = Vec3( 0.000000, 0.666667, 0.222222 ); |
---|
| 61 | (*expected)[ 2] = Vec3( 0.000000, 1.333333, 0.444444 ); |
---|
| 62 | (*expected)[ 3] = Vec3( 0.000000, 2.000000, 0.666667 ); |
---|
| 63 | (*expected)[ 4] = Vec3( 0.500000, 0.000000, -0.166667 ); |
---|
| 64 | (*expected)[ 5] = Vec3( 0.500000, 0.666667, 0.055556 ); |
---|
| 65 | (*expected)[ 6] = Vec3( 0.500000, 1.333333, 0.277778 ); |
---|
| 66 | (*expected)[ 7] = Vec3( 0.500000, 2.000000, 0.500000 ); |
---|
| 67 | (*expected)[ 8] = Vec3( 1.000000, 0.000000, -0.333333 ); |
---|
| 68 | (*expected)[ 9] = Vec3( 1.000000, 0.666667, -0.111111 ); |
---|
| 69 | (*expected)[10] = Vec3( 1.000000, 1.333333, 0.111111 ); |
---|
| 70 | (*expected)[11] = Vec3( 1.000000, 2.000000, 0.333333 ); |
---|
| 71 | (*expected)[12] = Vec3( 1.500000, 0.000000, -0.500000 ); |
---|
| 72 | (*expected)[13] = Vec3( 1.500000, 0.666667, -0.277778 ); |
---|
| 73 | (*expected)[14] = Vec3( 1.500000, 1.333333, -0.055556 ); |
---|
| 74 | (*expected)[15] = Vec3( 1.500000, 2.000000, 0.166667 ); |
---|
| 75 | (*expected)[16] = Vec3( 2.000000, 0.000000, -0.666667 ); |
---|
| 76 | (*expected)[17] = Vec3( 2.000000, 0.666667, -0.444444 ); |
---|
| 77 | (*expected)[18] = Vec3( 2.000000, 1.333333, -0.222222 ); |
---|
| 78 | (*expected)[19] = Vec3( 2.000000, 2.000000, 0.000000 ); |
---|
| 79 | |
---|
| 80 | for (size_t i=0; i<nvertices; i++) |
---|
| 81 | CPPUNIT_ASSERT_VEC3_EQUAL( actual->at(i), expected->at(i) ); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | void SWWReaderTest::testBedslopeIndexArray() |
---|
| 87 | { |
---|
| 88 | osg::ref_ptr<osg::UIntArray> actual = _sww->getBedslopeIndexArray(); |
---|
| 89 | |
---|
| 90 | // expected number of bedslope indices |
---|
| 91 | const size_t nindices = 24*3; |
---|
| 92 | CPPUNIT_ASSERT_EQUAL( actual->size(), nindices ); |
---|
| 93 | |
---|
| 94 | // hard-coded values extracted from sww file |
---|
| 95 | const unsigned int expected[72] = { 4, 5, 0, 1, 0, 5, 5, 6, 1, |
---|
| 96 | 2, 1, 6, 6, 7, 2, 3, 2, 7, 8, 9, 4, 5, 4, 9, 9, 10, 5, |
---|
| 97 | 6, 5, 10, 10, 11, 6, 7, 6, 11, 12, 13, 8, 9, 8, 13, |
---|
| 98 | 13, 14, 9, 10, 9, 14, 14, 15, 10, 11, 10, 15, 16, 17, 12, |
---|
| 99 | 13, 12, 17, 17, 18, 13, 14, 13, 18, 18, 19, 14, 15, 14, 19 }; |
---|
| 100 | |
---|
| 101 | for (size_t i=0; i<nindices; i++) |
---|
| 102 | CPPUNIT_ASSERT_EQUAL( actual->at(i), expected[i] ); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | |
---|
| 106 | |
---|
| 107 | void SWWReaderTest::testConnectivity() |
---|
| 108 | { |
---|
| 109 | // shared vertices for triangle 17 |
---|
| 110 | triangle_list actual = _sww->getConnectivity(17); |
---|
| 111 | |
---|
| 112 | const size_t nshared = 3; |
---|
| 113 | CPPUNIT_ASSERT_EQUAL( actual.size(), nshared ); |
---|
| 114 | const unsigned int expected[nshared] = { 18, 19, 20 }; |
---|
| 115 | for (size_t i=0; i<nshared; i++) |
---|
| 116 | CPPUNIT_ASSERT_EQUAL( actual.at(i), expected[i] ); |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | |
---|
| 120 | |
---|
| 121 | void SWWReaderTest::testBedslopeNormalArray() |
---|
| 122 | { |
---|
| 123 | osg::ref_ptr<osg::Vec3Array> actual = _sww->getBedslopeNormalArray(); |
---|
| 124 | |
---|
| 125 | // expected number of bedslope normals |
---|
| 126 | const size_t nvertices = 24; |
---|
| 127 | CPPUNIT_ASSERT_EQUAL( actual->size(), nvertices ); |
---|
| 128 | |
---|
| 129 | // hard-coded values (bedslope is flat plane) |
---|
| 130 | using osg::Vec3; |
---|
| 131 | using osg::Vec3Array; |
---|
| 132 | Vec3Array *expected = new Vec3Array; |
---|
| 133 | expected->assign(24, Vec3( 0.301511, -0.301511, 0.904534 ) ); |
---|
| 134 | |
---|
| 135 | for (size_t i=0; i<nvertices; i++) |
---|
| 136 | CPPUNIT_ASSERT_VEC3_EQUAL( actual->at(i), expected->at(i) ); |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | void SWWReaderTest::tearDown() |
---|
| 143 | { |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | int main(int argc, char* argv[]) |
---|
| 150 | { |
---|
| 151 | // Get the top level suite from the registry |
---|
| 152 | CppUnit::Test *suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); |
---|
| 153 | |
---|
| 154 | // Add test |
---|
| 155 | CppUnit::TextUi::TestRunner runner; |
---|
| 156 | runner.addTest( suite ); |
---|
| 157 | |
---|
| 158 | // Change default outputter to a compiler error format outputter |
---|
| 159 | runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), std::cerr ) ); |
---|
| 160 | |
---|
| 161 | // Run tests |
---|
| 162 | bool wasSucessful = runner.run(); |
---|
| 163 | |
---|
| 164 | // Error code 1 if any tests failed |
---|
| 165 | return wasSucessful ? 0 : 1; |
---|
| 166 | } |
---|