Remove redundant Qt6 migration comments that restate obvious API changes: - QtConcurrent::run parameter order explanations (preserved where lambda wrapping needed) - QStringRef/QStringView API changes (shortened to essential info) - QComboBox::activated signal signature change - QMap::unite() removal semantics - QAction include path change - QMouseEvent/QWheelEvent position() API - QList/QVector equivalence in Qt6 - QFuture continuation API - Code generation comments Preserved comments explaining non-obvious Qt6 behavior or necessary API migration details. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
199 lines
5.3 KiB
C++
199 lines
5.3 KiB
C++
/**
|
|
* @RDE_HEADER@
|
|
* Unit Tests for Rubberbands Module - Qt6 Migration
|
|
* $Id$
|
|
* $HeadURL$
|
|
* $Author$
|
|
*/
|
|
|
|
#include <gtest/gtest.h>
|
|
#include <QCoreApplication>
|
|
#include <QPointF>
|
|
#include <QPolygonF>
|
|
#include <QTouchEvent>
|
|
#include <QEventPoint>
|
|
#include <QFuture>
|
|
#include <QtConcurrent>
|
|
#include <chrono>
|
|
#include <thread>
|
|
|
|
namespace
|
|
{
|
|
// Mock class to simulate rubberband behavior for testing
|
|
class MockRubberband
|
|
{
|
|
public:
|
|
MockRubberband() : m_active(false) {}
|
|
|
|
void setActive(bool active) { m_active = active; }
|
|
bool isActive() const { return m_active; }
|
|
|
|
void addPoint(const QPointF& point) { m_points.append(point); }
|
|
int pointCount() const { return m_points.size(); }
|
|
|
|
void clear() { m_points.clear(); }
|
|
|
|
private:
|
|
bool m_active;
|
|
QList<QPointF> m_points;
|
|
};
|
|
}
|
|
|
|
// Test Rubberbands QTouchEvent API (Qt6)
|
|
TEST(RubberbandsTest, QTouchEvent_API_Qt6)
|
|
{
|
|
// Qt6 changes:
|
|
// - touchPoints() -> points()
|
|
// - QEventPoint::screenPos() -> globalPosition()
|
|
|
|
// Verify QEventPoint API exists and works
|
|
// Note: QTouchEvent cannot be directly constructed in tests,
|
|
// but we can verify the point types
|
|
|
|
// Test that QEventPoint has the expected Qt6 methods
|
|
// This is a compile-time check that the API exists
|
|
using PointType = QEventPoint;
|
|
|
|
// Verify the types we use in Rubberbands code
|
|
static_assert(std::is_same_v<decltype(&QEventPoint::position), QPointF(QEventPoint::*)() const>);
|
|
static_assert(std::is_same_v<decltype(&QEventPoint::globalPosition), QPointF(QEventPoint::*)() const>);
|
|
|
|
SUCCEED() << "QEventPoint Qt6 API verified";
|
|
}
|
|
|
|
// Test Rubberbands QFuture continuation pattern
|
|
TEST(RubberbandsTest, QFuture_Continuation_Pattern)
|
|
{
|
|
// This pattern is used in Rubberbands for async operations
|
|
|
|
QFuture<int> future = QtConcurrent::run([]() {
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
|
return 42;
|
|
});
|
|
|
|
bool continuationCalled = false;
|
|
int result = 0;
|
|
|
|
QFuture<void> continued = future.then([&continuationCalled, &result](QFuture<int> f) {
|
|
continuationCalled = true;
|
|
result = f.result();
|
|
});
|
|
|
|
continued.waitForFinished();
|
|
|
|
EXPECT_TRUE(continuationCalled);
|
|
EXPECT_EQ(result, 42);
|
|
}
|
|
|
|
// Test Rubberbands point collection
|
|
TEST(RubberbandsTest, Point_Collection)
|
|
{
|
|
MockRubberband rubberband;
|
|
|
|
EXPECT_FALSE(rubberband.isActive());
|
|
EXPECT_EQ(rubberband.pointCount(), 0);
|
|
|
|
rubberband.setActive(true);
|
|
EXPECT_TRUE(rubberband.isActive());
|
|
|
|
rubberband.addPoint(QPointF(10.0, 20.0));
|
|
rubberband.addPoint(QPointF(30.0, 40.0));
|
|
rubberband.addPoint(QPointF(50.0, 60.0));
|
|
|
|
EXPECT_EQ(rubberband.pointCount(), 3);
|
|
|
|
rubberband.clear();
|
|
EXPECT_EQ(rubberband.pointCount(), 0);
|
|
}
|
|
|
|
// Test Rubberbands polygon operations
|
|
TEST(RubberbandsTest, Polygon_Operations)
|
|
{
|
|
QPolygonF polygon;
|
|
|
|
// Add points
|
|
polygon << QPointF(0, 0) << QPointF(100, 0)
|
|
<< QPointF(100, 100) << QPointF(0, 100);
|
|
|
|
EXPECT_EQ(polygon.size(), 4);
|
|
|
|
// Verify bounding rect
|
|
QRectF bounds = polygon.boundingRect();
|
|
EXPECT_DOUBLE_EQ(bounds.x(), 0.0);
|
|
EXPECT_DOUBLE_EQ(bounds.y(), 0.0);
|
|
EXPECT_DOUBLE_EQ(bounds.width(), 100.0);
|
|
EXPECT_DOUBLE_EQ(bounds.height(), 100.0);
|
|
|
|
// Test point containment
|
|
QPointF center(50.0, 50.0);
|
|
QPointF outside(150.0, 150.0);
|
|
|
|
// Note: QPolygonF doesn't have contains() by default,
|
|
// but we verify the points are accessible
|
|
EXPECT_EQ(polygon[0], QPointF(0, 0));
|
|
EXPECT_EQ(polygon[2], QPointF(100, 100));
|
|
}
|
|
|
|
// Test Rubberbands async operation simulation
|
|
TEST(RubberbandsTest, Async_Operation_Simulation)
|
|
{
|
|
// Simulate async rubberband update operation
|
|
bool operationComplete = false;
|
|
|
|
QFuture<bool> future = QtConcurrent::run([&operationComplete]() {
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
|
operationComplete = true;
|
|
return true;
|
|
});
|
|
|
|
future.waitForFinished();
|
|
|
|
EXPECT_TRUE(operationComplete);
|
|
EXPECT_TRUE(future.result());
|
|
}
|
|
|
|
// Test Rubberbands Qt6 container compatibility
|
|
TEST(RubberbandsTest, Qt6_Container_Compatibility)
|
|
{
|
|
QList<QPointF> points;
|
|
|
|
points.append(QPointF(0, 0));
|
|
points.append(QPointF(10, 10));
|
|
points.append(QPointF(20, 20));
|
|
|
|
EXPECT_EQ(points.size(), 3);
|
|
|
|
// Test range-based for loop
|
|
int index = 0;
|
|
for (const auto& point : points)
|
|
{
|
|
EXPECT_DOUBLE_EQ(point.x(), index * 10.0);
|
|
EXPECT_DOUBLE_EQ(point.y(), index * 10.0);
|
|
++index;
|
|
}
|
|
|
|
// Test const access
|
|
const QList<QPointF>& constPoints = points;
|
|
EXPECT_EQ(constPoints[0].x(), 0.0);
|
|
}
|
|
|
|
// Test Rubberbands touch point processing
|
|
TEST(RubberbandsTest, Touch_Point_Processing)
|
|
{
|
|
// Simulate processing of touch points (Qt6 API)
|
|
QList<QPointF> touchPoints;
|
|
touchPoints << QPointF(100, 200) << QPointF(150, 250) << QPointF(200, 300);
|
|
|
|
EXPECT_EQ(touchPoints.size(), 3);
|
|
|
|
// Process points (simulating what Rubberbands does)
|
|
QPointF centroid(0, 0);
|
|
for (const auto& point : touchPoints)
|
|
{
|
|
centroid += point;
|
|
}
|
|
centroid /= touchPoints.size();
|
|
|
|
EXPECT_DOUBLE_EQ(centroid.x(), 150.0);
|
|
EXPECT_DOUBLE_EQ(centroid.y(), 250.0);
|
|
} |