tst_QAbstractSlider: fix strict-aliasing warnings

GCC warned:

  tst_qabstractslider.cpp:858:89: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     Qt::Orientation orientation = *reinterpret_cast<Qt::Orientation*>(&sliderOrientation);
                                                                                         ^
  tst_qabstractslider.cpp:867:72: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing]
     orientation = *reinterpret_cast<Qt::Orientation*>(&wheelOrientation);
                                                                        ^

The solution, of course, would be to use a static_cast here, but
why go via int in the first place? Qt::Orientation can perfectly
well be used in QFETCH, as proven by tst_qmainwindow, among other
things.

Change-Id: I97916a50405e16d114837bc52580ce6666d74b17
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2016-09-28 20:01:35 +02:00
parent 85d7c732e9
commit e0e4269e28

View File

@ -707,8 +707,8 @@ void tst_QAbstractSlider::wheelEvent_data()
QTest::addColumn<int>("wheelScrollLines");
QTest::addColumn<bool>("withModifiers"); // use keyboard modifiers while scrolling? (CTRL and SHIFT)
QTest::addColumn<int>("deltaMultiple"); // multiples of WHEEL_DELTA
QTest::addColumn<int>("sliderOrientation");
QTest::addColumn<int>("wheelOrientation");
QTest::addColumn<Qt::Orientation>("sliderOrientation");
QTest::addColumn<Qt::Orientation>("wheelOrientation");
QTest::addColumn<int>("expectedSliderPosition");
QTest::addColumn<QPoint>("distanceFromBottomRight"); // mpointer's distance from bottom-right corner of widget
@ -721,8 +721,8 @@ void tst_QAbstractSlider::wheelEvent_data()
<< 20 // wheel scroll lines
<< false // with modifiers
<< 1 // delta
<< int(Qt::Vertical) // orientation of slider
<< int(Qt::Vertical) // orientation of wheel
<< Qt::Vertical // orientation of slider
<< Qt::Vertical // orientation of wheel
<< 20 // expected position after
<< QPoint(0,0);
@ -735,8 +735,8 @@ void tst_QAbstractSlider::wheelEvent_data()
<< 20 // wheel scroll lines
<< false // with modifiers
<< 1 // delta
<< int(Qt::Vertical) // orientation of slider
<< int(Qt::Vertical) // orientation of wheel
<< Qt::Vertical // orientation of slider
<< Qt::Vertical // orientation of wheel
#ifndef Q_OS_MAC
<< 1 // expected position after
#else
@ -753,8 +753,8 @@ void tst_QAbstractSlider::wheelEvent_data()
<< 20 // wheel scroll lines
<< false // with modifiers
<< 1 // delta
<< int(Qt::Horizontal) // orientation of slider
<< int(Qt::Vertical) // orientation of wheel
<< Qt::Horizontal // orientation of slider
<< Qt::Vertical // orientation of wheel
#ifndef Q_OS_MAC
<< 1 // expected position after
#else
@ -772,8 +772,8 @@ void tst_QAbstractSlider::wheelEvent_data()
<< 20 // wheel scroll lines
<< false // with modifiers
<< 1 // delta
<< int(Qt::Horizontal) // orientation of slider
<< int(Qt::Vertical) // orientation of wheel
<< Qt::Horizontal // orientation of slider
<< Qt::Vertical // orientation of wheel
#ifndef Q_OS_MAC
<< 1 // expected position after
#else
@ -791,8 +791,8 @@ void tst_QAbstractSlider::wheelEvent_data()
<< 20 // wheel scroll lines
<< false // with modifiers
<< -1 // delta
<< int(Qt::Horizontal) // orientation of slider
<< int(Qt::Horizontal) // orientation of wheel
<< Qt::Horizontal // orientation of slider
<< Qt::Horizontal // orientation of wheel
<< 30 // expected position after
<< QPoint(1,1);
@ -805,8 +805,8 @@ void tst_QAbstractSlider::wheelEvent_data()
<< 1 // wheel scroll lines
<< false // with modifiers
<< -2 // delta
<< int(Qt::Horizontal) // orientation of slider
<< int(Qt::Horizontal) // orientation of wheel
<< Qt::Horizontal // orientation of slider
<< Qt::Horizontal // orientation of wheel
<< 100 // expected position after
<< QPoint(0,0);
@ -819,8 +819,8 @@ void tst_QAbstractSlider::wheelEvent_data()
<< 1 // wheel scroll lines
<< false // with modifiers
<< 2 // delta
<< int(Qt::Horizontal) // orientation of slider
<< int(Qt::Horizontal) // orientation of wheel
<< Qt::Horizontal // orientation of slider
<< Qt::Horizontal // orientation of wheel
<< 0 // expected position after
<< QPoint(0,0);
@ -833,8 +833,8 @@ void tst_QAbstractSlider::wheelEvent_data()
<< 20 // wheel scroll lines
<< true // with modifiers
<< -1 // delta
<< int(Qt::Horizontal) // orientation of slider
<< int(Qt::Horizontal) // orientation of wheel
<< Qt::Horizontal // orientation of slider
<< Qt::Horizontal // orientation of wheel
<< 90 // expected position after
<< QPoint(0,0);
@ -851,8 +851,8 @@ void tst_QAbstractSlider::wheelEvent()
QFETCH(int,wheelScrollLines);
QFETCH(bool,withModifiers);
QFETCH(int,deltaMultiple);
QFETCH(int,sliderOrientation);
QFETCH(int,wheelOrientation);
QFETCH(Qt::Orientation, sliderOrientation);
QFETCH(Qt::Orientation, wheelOrientation);
QFETCH(int,expectedSliderPosition);
QFETCH(QPoint,distanceFromBottomRight);
@ -860,18 +860,16 @@ void tst_QAbstractSlider::wheelEvent()
QVERIFY(applicationInstance != 0);
QApplication::setWheelScrollLines(wheelScrollLines);
Qt::Orientation orientation = *reinterpret_cast<Qt::Orientation*>(&sliderOrientation);
slider->setRange(minimum,maximum);
slider->setSliderPosition(initialSliderPosition);
slider->setSingleStep(singleStep);
slider->setPageStep(pageStep);
slider->setInvertedControls(invertedControls);
slider->setOrientation(orientation);
slider->setOrientation(sliderOrientation);
Qt::KeyboardModifier k = withModifiers ? Qt::ControlModifier : Qt::NoModifier;
orientation = *reinterpret_cast<Qt::Orientation*>(&wheelOrientation);
QWheelEvent event(slider->rect().bottomRight() + distanceFromBottomRight, WHEEL_DELTA * deltaMultiple,
Qt::NoButton, k, orientation);
Qt::NoButton, k, wheelOrientation);
QVERIFY(applicationInstance->sendEvent(slider,&event));
#ifdef Q_OS_MAC
QEXPECT_FAIL("Normal data page", "QTBUG-23679", Continue);
@ -883,7 +881,7 @@ void tst_QAbstractSlider::wheelEvent()
slider->setSliderPosition(initialSliderPosition);
k = withModifiers ? Qt::ShiftModifier : Qt::NoModifier;
event = QWheelEvent(slider->rect().bottomRight() + distanceFromBottomRight, WHEEL_DELTA * deltaMultiple,
Qt::NoButton, k, orientation);
Qt::NoButton, k, wheelOrientation);
QSignalSpy spy1(slider, SIGNAL(actionTriggered(int)));
QSignalSpy spy2(slider, SIGNAL(valueChanged(int)));
QVERIFY(applicationInstance->sendEvent(slider,&event));