diff --git a/src/Magnum/Animation/Test/CMakeLists.txt b/src/Magnum/Animation/Test/CMakeLists.txt index 9b5717d9f..62241e59a 100644 --- a/src/Magnum/Animation/Test/CMakeLists.txt +++ b/src/Magnum/Animation/Test/CMakeLists.txt @@ -37,4 +37,5 @@ corrade_add_test(AnimationTrackViewTest TrackViewTest.cpp LIBRARIES Magnum) set_property(TARGET AnimationInterpolationTest + AnimationTrackViewTest APPEND PROPERTY COMPILE_DEFINITIONS "CORRADE_GRACEFUL_ASSERT") diff --git a/src/Magnum/Animation/Test/TrackViewTest.cpp b/src/Magnum/Animation/Test/TrackViewTest.cpp index dad64bae8..62b90cc35 100644 --- a/src/Magnum/Animation/Test/TrackViewTest.cpp +++ b/src/Magnum/Animation/Test/TrackViewTest.cpp @@ -23,7 +23,9 @@ DEALINGS IN THE SOFTWARE. */ +#include #include +#include /** @todo remove once Debug is stream-free */ #include "Magnum/Animation/Track.h" #include "Magnum/Math/Half.h" @@ -47,6 +49,7 @@ struct TrackViewTest: TestSuite::Tester { void constructSingleArrayInterpolationDefaults(); void constructSingleArrayInterpolationInterpolator(); void constructSingleArrayInterpolationInterpolatorDefaults(); + void constructInconsistentViewSize(); void constructCopyStorage(); void convertToConstView(); @@ -106,6 +109,7 @@ TrackViewTest::TrackViewTest() { &TrackViewTest::constructSingleArrayInterpolationDefaults, &TrackViewTest::constructSingleArrayInterpolationInterpolator, &TrackViewTest::constructSingleArrayInterpolationInterpolatorDefaults, + &TrackViewTest::constructInconsistentViewSize, &TrackViewTest::constructCopyStorage, &TrackViewTest::convertToConstView}); @@ -560,6 +564,18 @@ void TrackViewTest::constructSingleArrayInterpolationInterpolatorDefaults() { CORRADE_COMPARE(ca[1], (std::pair{5.0f, {0.3f, 0.6f, 1.0f}})); } +void TrackViewTest::constructInconsistentViewSize() { + CORRADE_SKIP_IF_NO_ASSERT(); + + Float keys[2]{}; + Vector3 values[3]{}; + + std::ostringstream out; + Error redirectError{&out}; + TrackView{keys, values, Math::select}; + CORRADE_COMPARE(out.str(), "Animation::TrackView: expected key and value view to have the same size but got 2 and 3\n"); +} + void TrackViewTest::constructCopyStorage() { std::pair data[]{ {1.0f, {3.0f, 1.0f, 0.1f}}, diff --git a/src/Magnum/Animation/Track.h b/src/Magnum/Animation/Track.h index e09effd1a..c7f716964 100644 --- a/src/Magnum/Animation/Track.h +++ b/src/Magnum/Animation/Track.h @@ -519,7 +519,9 @@ template class TrackViewStorage { private: template friend class TrackView; - explicit TrackViewStorage(const Containers::StridedArrayView1D& keys, const Containers::StridedArrayView1D::value, const void, void>::type>& values, Interpolation interpolation, void(*interpolator)(), Extrapolation before, Extrapolation after) noexcept: _keys{keys}, _values{values}, _interpolator{interpolator}, _interpolation{interpolation}, _before{before}, _after{after} {} + explicit TrackViewStorage(const Containers::StridedArrayView1D& keys, const Containers::StridedArrayView1D::value, const void, void>::type>& values, Interpolation interpolation, void(*interpolator)(), Extrapolation before, Extrapolation after) noexcept: _keys{keys}, _values{values}, _interpolator{interpolator}, _interpolation{interpolation}, _before{before}, _after{after} { + CORRADE_ASSERT(keys.size() == values.size(), "Animation::TrackView: expected key and value view to have the same size but got" << keys.size() << "and" << values.size(), ); + } Containers::StridedArrayView1D _keys; Containers::StridedArrayView1D::value, const void, void>::type> _values;