/** * @RDE_HEADER@ * Unit Tests for Rubberbands Module - Qt6 Migration * $Id$ * $HeadURL$ * $Author$ */ #include #include #include #include #include #include #include #include #include #include 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 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); static_assert(std::is_same_v); SUCCEED() << "QEventPoint Qt6 API verified"; } // Test Rubberbands QFuture continuation pattern TEST(RubberbandsTest, QFuture_Continuation_Pattern) { // Qt6: QFuture supports .then() continuations // This pattern is used in Rubberbands for async operations QFuture future = QtConcurrent::run([]() { std::this_thread::sleep_for(std::chrono::milliseconds(10)); return 42; }); bool continuationCalled = false; int result = 0; QFuture continued = future.then([&continuationCalled, &result](QFuture 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 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) { // Qt6: QList and QVector are identical QList 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& 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 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); }