Browse Source

Animation: assert that TrackView gets keys and values of the same size.

Interesting omission, heh.
pull/617/head
Vladimír Vondruš 3 years ago
parent
commit
24fc74ed22
  1. 1
      src/Magnum/Animation/Test/CMakeLists.txt
  2. 16
      src/Magnum/Animation/Test/TrackViewTest.cpp
  3. 4
      src/Magnum/Animation/Track.h

1
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")

16
src/Magnum/Animation/Test/TrackViewTest.cpp

@ -23,7 +23,9 @@
DEALINGS IN THE SOFTWARE.
*/
#include <sstream>
#include <Corrade/TestSuite/Tester.h>
#include <Corrade/Utility/DebugStl.h> /** @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<Float, Vector3>{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<Float, Vector3>{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<Float, Vector3> data[]{
{1.0f, {3.0f, 1.0f, 0.1f}},

4
src/Magnum/Animation/Track.h

@ -519,7 +519,9 @@ template<class K> class TrackViewStorage {
private:
template<class, class, class> friend class TrackView;
explicit TrackViewStorage(const Containers::StridedArrayView1D<K>& keys, const Containers::StridedArrayView1D<typename std::conditional<std::is_const<K>::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<K>& keys, const Containers::StridedArrayView1D<typename std::conditional<std::is_const<K>::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<K> _keys;
Containers::StridedArrayView1D<typename std::conditional<std::is_const<K>::value, const void, void>::type> _values;

Loading…
Cancel
Save