void BaseTestDataAccess::testDataView() { NDSize zcount = {2, 5, 2}; NDSize zoffset = {0, 5, 2}; DataView io = DataView(data_array, zcount, zoffset); CPPUNIT_ASSERT_EQUAL(zcount, io.dataExtent()); CPPUNIT_ASSERT_EQUAL(data_array.dataType(), io.dataType()); typedef boost::multi_array<double, 3> array_type; array_type data(boost::extents[2][5][2]); io.getData(data); const array_type::size_type *ext = data.shape(); for (size_t i = 0; i < 3; i++) { CPPUNIT_ASSERT_EQUAL(static_cast<array_type::size_type >(zcount[i]), ext[i]); } array_type ref; data_array.getData(ref); for(size_t i = 0; i < zcount[0]; ++i) { for(size_t j = 0; j < zcount[1]; ++j) { for(size_t k = 0; k < zcount[2]; ++k) { CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i + 0][j + 5][k + 2], data[i][j][k], std::numeric_limits<double>::epsilon()); data[i][j][k] = 0.0; } } } io.setData(data, {0, 0, 0}); data_array.getData(ref); for(size_t i = 0; i < zcount[0]; ++i) { for(size_t j = 0; j < zcount[1]; ++j) { for(size_t k = 0; k < zcount[2]; ++k) { CPPUNIT_ASSERT_DOUBLES_EQUAL(ref[i + 0][j + 5][k + 2], 0.0, std::numeric_limits<double>::epsilon()); } } } double val = 0.0; CPPUNIT_ASSERT_THROW(io.getData(val, {}, {0, 0, 3}), OutOfBounds); array_type r2d2(boost::extents[3][3][3]); CPPUNIT_ASSERT_THROW(io.getData(r2d2, {3, 3, 3}, {}), OutOfBounds); CPPUNIT_ASSERT_THROW(io.dataExtent(zcount), std::runtime_error); }