| | 569 | |
| | 570 | // Now change the view size. We do this calling the main presenter's |
| | 571 | // function instead of the view, because the view here don't have anything |
| | 572 | // to do. |
| | 573 | // The new zoom should be 50/100 = 0.5 |
| | 574 | m_MainPter->pageViewResized (50, 50); |
| | 575 | CPPUNIT_ASSERT (m_View->hasImagePageView ()); |
| | 576 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.5, m_Document->getZoom (), 0.0001); |
| | 577 | |
| | 578 | m_MainPter->pageViewResized (75, 50); |
| | 579 | CPPUNIT_ASSERT (m_View->hasImagePageView ()); |
| | 580 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); |
| | 581 | |
| | 582 | // If we desactive the zoom to width, no resizing changes the |
| | 583 | // zoom. |
| | 584 | m_MainPter->zoomWidthActivated (FALSE); |
| | 585 | CPPUNIT_ASSERT (!m_View->isZoomToWidthActive ()); |
| | 586 | m_MainPter->pageViewResized (50, 50); |
| | 587 | CPPUNIT_ASSERT (!m_View->hasImagePageView ()); |
| | 588 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); |
| | 589 | m_MainPter->pageViewResized (100, 50); |
| | 590 | CPPUNIT_ASSERT (!m_View->hasImagePageView ()); |
| | 591 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.75, m_Document->getZoom (), 0.0001); |
| | 592 | |
| | 593 | // Now rotate and try again. |
| | 594 | m_MainPter->rotateRightActivated (); |
| | 595 | CPPUNIT_ASSERT (m_View->hasImagePageView ()); |
| | 596 | CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); |
| | 597 | // Since rotation is now 90 the zoom level should be 75/250 = 0.3 |
| | 598 | m_MainPter->zoomWidthActivated (TRUE); |
| | 599 | CPPUNIT_ASSERT (m_View->isZoomToWidthActive ()); |
| | 600 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.3, m_Document->getZoom (), 0.0001); |
| | 601 | CPPUNIT_ASSERT (m_View->hasImagePageView ()); |
| | 602 | // Resizing. 50/250 = 0.2 |
| | 603 | m_MainPter->pageViewResized (50, 50); |
| | 604 | CPPUNIT_ASSERT (m_View->hasImagePageView ()); |
| | 605 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); |
| | 606 | |
| | 607 | // Changing any of the zoom in or zoom out features should make the |
| | 608 | // zoom to width not being active. |
| | 609 | m_MainPter->zoomInActivated (); |
| | 610 | CPPUNIT_ASSERT (!m_View->isZoomToWidthActive ()); |
| | 611 | m_MainPter->zoomWidthActivated (TRUE); |
| | 612 | m_MainPter->zoomOutActivated (); |
| | 613 | CPPUNIT_ASSERT (!m_View->isZoomToWidthActive ()); |
| | 614 | } |
| | 615 | |
| | 616 | /// |
| | 617 | /// @brief Tests page's zoom to fit |
| | 618 | /// |
| | 619 | void |
| | 620 | MainPterTest::pageZoomFit () |
| | 621 | { |
| | 622 | m_View->setOpenFileName ("/tmp/test.pdf"); |
| | 623 | m_MainPter->openFileActivated (); |
| | 624 | CPPUNIT_ASSERT (m_View->hasImagePageView ()); |
| | 625 | CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); |
| | 626 | |
| | 627 | // OK, now try to zoom to fit. Since rotation is 0 |
| | 628 | // the zoom level should be 50/250 = 0.2 |
| | 629 | m_MainPter->zoomFitActivated (TRUE); |
| | 630 | CPPUNIT_ASSERT (m_View->isZoomToFitActive ()); |
| | 631 | CPPUNIT_ASSERT (m_View->hasImagePageView ()); |
| | 632 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); |
| | 633 | |
| | 634 | // Resizing the view size. 100/250 = 0.4 |
| | 635 | m_MainPter->pageViewResized (100, 100); |
| | 636 | CPPUNIT_ASSERT (m_View->hasImagePageView ()); |
| | 637 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.4, m_Document->getZoom (), 0.0001); |
| | 638 | m_MainPter->pageViewResized (100, 50); |
| | 639 | CPPUNIT_ASSERT (m_View->hasImagePageView ()); |
| | 640 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); |
| | 641 | |
| | 642 | // Desactivating the zoom to fit. |
| | 643 | m_MainPter->zoomFitActivated (FALSE); |
| | 644 | CPPUNIT_ASSERT (!m_View->isZoomToFitActive ()); |
| | 645 | m_MainPter->pageViewResized (100, 100); |
| | 646 | CPPUNIT_ASSERT (!m_View->hasImagePageView ()); |
| | 647 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); |
| | 648 | m_MainPter->pageViewResized (100, 50); |
| | 649 | CPPUNIT_ASSERT (!m_View->hasImagePageView ()); |
| | 650 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); |
| 580 | | } |
| 581 | | |
| 582 | | /// |
| 583 | | /// @brief Tests page's zoom to fit |
| 584 | | /// |
| 585 | | void |
| 586 | | MainPterTest::pageZoomFit () |
| 587 | | { |
| 588 | | m_View->setOpenFileName ("/tmp/test.pdf"); |
| 589 | | m_MainPter->openFileActivated (); |
| 590 | | CPPUNIT_ASSERT (m_View->hasImagePageView ()); |
| 591 | | CPPUNIT_ASSERT (!m_View->hasImagePageView ()); |
| 592 | | CPPUNIT_ASSERT_DOUBLES_EQUAL (1.0, m_Document->getZoom (), 0.0001); |
| 593 | | |
| 594 | | // OK, now try to zoom to fit. Since rotation is 0 |
| 595 | | // the zoom level should be 50/250 = 0.2 |
| 596 | | m_MainPter->zoomFitActivated (); |
| 597 | | CPPUNIT_ASSERT (m_View->hasImagePageView ()); |
| 598 | | CPPUNIT_ASSERT (!m_View->hasImagePageView ()); |
| 599 | | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.2, m_Document->getZoom (), 0.0001); |
| 600 | | |
| 601 | | // Now rotate and try again. |
| 602 | | m_MainPter->rotateRightActivated (); |
| 603 | | CPPUNIT_ASSERT (m_View->hasImagePageView ()); |
| 604 | | CPPUNIT_ASSERT_EQUAL (90, m_Document->getRotation ()); |
| | 662 | // 100/250 = 0.4 |
| | 663 | m_MainPter->pageViewResized (100, 100); |
| | 664 | CPPUNIT_ASSERT_DOUBLES_EQUAL (0.4, m_Document->getZoom (), 0.0001); |
| | 665 | CPPUNIT_ASSERT (m_View->hasImagePageView ()); |