~ubuntu-branches/ubuntu/raring/scummvm/raring

« back to all changes in this revision

Viewing changes to engines/testbed/graphics.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Moritz Muehlenhoff
  • Date: 2011-05-25 19:02:23 UTC
  • mto: (21.1.2 sid)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: james.westby@ubuntu.com-20110525190223-fiqm0oaec714xk31
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 * along with this program; if not, write to the Free Software
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
20
 *
21
 
 * $URL: https://scummvm.svn.sourceforge.net/svnroot/scummvm/scummvm/tags/release-1-2-1/engines/testbed/graphics.cpp $
22
 
 * $Id: graphics.cpp 52685 2010-09-12 14:20:52Z sev $
 
21
 * $URL$
 
22
 * $Id$
23
23
 */
24
24
 
25
25
#include "common/events.h"
33
33
 
34
34
#include "graphics/cursorman.h"
35
35
#include "graphics/fontman.h"
 
36
#include "graphics/palette.h"
36
37
#include "graphics/surface.h"
37
38
#include "graphics/VectorRendererSpec.h"
38
39
 
39
40
namespace Testbed {
40
41
 
41
 
byte GFXTestSuite::_palette[256 * 4] = {0, 0, 0, 0, 255, 255, 255, 0, 255, 255, 255, 0};
 
42
byte GFXTestSuite::_palette[256 * 3] = {0, 0, 0, 255, 255, 255, 255, 255, 255};
42
43
 
43
44
GFXTestSuite::GFXTestSuite() {
44
45
        // Initialize color palettes
45
46
        // The fourth field is for alpha channel which is unused
46
47
        // Assuming 8bpp as of now
47
 
        g_system->setPalette(_palette, 0, 3);
 
48
        g_system->getPaletteManager()->setPalette(_palette, 0, 3);
48
49
 
49
50
        // Init Mouse Palette (White-black-yellow)
50
51
        GFXtests::initMousePalette();
62
63
        // Mouse Layer tests (Palettes and movements)
63
64
        addTest("PalettizedCursors", &GFXtests::palettizedCursors);
64
65
        addTest("MouseMovements", &GFXtests::mouseMovements);
65
 
        // FIXME: Scaled cursor crsh with odd dimmensions
 
66
        // FIXME: Scaled cursor crash with odd dimmensions
66
67
        addTest("ScaledCursors", &GFXtests::scaledCursors);
67
68
 
68
69
        // Effects
79
80
}
80
81
 
81
82
void GFXTestSuite::setCustomColor(uint r, uint g, uint b) {
82
 
        _palette[8] = r;
83
 
        _palette[9] = g;
84
 
        _palette[10] = b;
85
 
        
 
83
        _palette[6] = r;
 
84
        _palette[7] = g;
 
85
        _palette[8] = b;
 
86
 
86
87
        // Set colorNum kColorSpecial with a special color.
87
 
        int absIndx = kColorSpecial * 4;
 
88
        int absIndx = kColorSpecial * 3;
88
89
        _palette[absIndx + 1] = 173;
89
90
        _palette[absIndx + 2] = 255;
90
91
        _palette[absIndx + 3] = 47;
91
 
        g_system->setPalette(_palette, 0, 256);
 
92
        g_system->getPaletteManager()->setPalette(_palette, 0, 256);
92
93
}
93
94
 
94
95
// Helper functions used by GFX tests
95
96
 
96
97
void GFXtests::initMousePalette() {
97
 
        byte palette[3 * 4]; // Black, white and yellow
 
98
        byte palette[3 * 3]; // Black, white and yellow
98
99
 
99
100
        palette[0] = palette[1] = palette[2] = 0;
100
 
        palette[4] = palette[5] = palette[6] = 255;
101
 
        palette[8] = palette[9] = 255;
102
 
        palette[10] = 0;
 
101
        palette[3] = palette[4] = palette[5] = 255;
 
102
        palette[6] = palette[7] = 255;
 
103
        palette[8] = 0;
103
104
 
104
105
        CursorMan.replaceCursorPalette(palette, 0, 3);
105
106
}
229
230
        // Rotate the colors starting from address palette "size" times
230
231
 
231
232
        // take a temporary palette color
232
 
        byte tColor[4] = {0};
 
233
        byte tColor[3] = {0};
233
234
        // save first color in it.
234
 
        memcpy(tColor, &palette[0], 4 * sizeof(byte));
 
235
        memcpy(tColor, &palette[0], 3 * sizeof(byte));
235
236
 
236
237
        // Move each color upward by 1
237
238
        for (int i = 0; i < size - 1; i++) {
238
 
                memcpy(&palette[i * 4], &palette[(i + 1) * 4], 4 * sizeof(byte));
 
239
                memcpy(&palette[i * 3], &palette[(i + 1) * 3], 3 * sizeof(byte));
239
240
        }
240
241
        // Assign last color to tcolor
241
 
        memcpy(&palette[(size - 1) * 4], tColor, 4 * sizeof(byte));
 
242
        memcpy(&palette[(size - 1) * 3], tColor, 3 * sizeof(byte));
242
243
}
243
244
 
244
245
/**
270
271
                if (!gfxScalarMode.equals("")) {
271
272
                        info = "The cursor size (yellow) should match the red rectangle.";
272
273
                }
273
 
                
 
274
 
274
275
                Testsuite::writeOnScreen(info, pt);
275
276
 
276
277
                info = "GFX Mode";
346
347
 * Used by aspectRatio()
347
348
 */
348
349
void GFXtests::drawEllipse(int cx, int cy, int a, int b) {
349
 
        
 
350
 
350
351
        // Take a buffer of screen size
351
352
        int width = g_system->getWidth();
352
353
        int height = Testsuite::getDisplayRegionCoordinates().y;
353
354
        byte *buffer = new byte[height * width];
354
 
        float theta;
 
355
        double theta;
355
356
        int x, y, x1, y1;
356
357
 
357
358
        memset(buffer, 0, sizeof(byte) * width * height);
360
361
 
361
362
        // Illuminate the points lying on ellipse
362
363
 
363
 
        for (theta = 0; theta <= PI / 2; theta += PI / 360) {
 
364
        for (theta = 0; theta <= M_PI / 2; theta += M_PI / 360) {
364
365
                x = (int)(b * sin(theta) + 0.5);
365
366
                y = (int)(a * cos(theta) + 0.5);
366
367
 
397
398
/**
398
399
 * Tests the fullscreen mode by: toggling between fullscreen and windowed mode
399
400
 */
400
 
bool GFXtests::fullScreenMode() {
 
401
TestExitStatus GFXtests::fullScreenMode() {
401
402
        Testsuite::clearScreen();
402
403
        Common::String info = "Fullscreen test. Here you should expect a toggle between windowed and fullscreen states depending "
403
404
        "upon your initial state.";
404
405
 
405
406
        Common::Point pt(0, 100);
406
407
        Testsuite::writeOnScreen("Testing fullscreen mode", pt);
407
 
        
 
408
 
408
409
        if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
409
410
                Testsuite::logPrintf("Info! Skipping test : FullScreenMode\n");
410
 
                return true;
 
411
                return kTestSkipped;
411
412
        }
412
413
 
413
414
        bool isFeaturePresent;
414
415
        bool isFeatureEnabled;
415
 
        bool passed = true;
 
416
        TestExitStatus passed = kTestPassed;
416
417
        Common::String prompt;
417
418
        OptionSelected shouldSelect;
418
419
 
435
436
 
436
437
                if (!Testsuite::handleInteractiveInput(prompt, "Fullscreen", "Windowed", shouldSelect)) {
437
438
                        // User selected incorrect current state
438
 
                        passed = false;
 
439
                        passed = kTestFailed;
439
440
                        Testsuite::logDetailedPrintf("g_system->getFeatureState() failed\n");
440
441
                }
441
442
 
453
454
 
454
455
                if (!Testsuite::handleInteractiveInput(prompt, "Fullscreen", "Windowed", shouldSelect)) {
455
456
                        // User selected incorrect mode
456
 
                        passed = false;
 
457
                        passed = kTestFailed;
457
458
                        Testsuite::logDetailedPrintf("g_system->setFeatureState() failed\n");
458
459
                }
459
460
 
468
469
                if (!Testsuite::handleInteractiveInput(prompt, "Yes, it is", "Nopes", shouldSelect)) {
469
470
                        // User selected incorrect mode
470
471
                        Testsuite::logDetailedPrintf("switching back to initial state failed\n");
471
 
                        passed = false;
 
472
                        passed = kTestFailed;
472
473
                }
473
474
 
474
475
        } else {
481
482
/**
482
483
 * Tests the aspect ratio correction by: drawing an ellipse, when corrected the ellipse should render to a circle
483
484
 */
484
 
bool GFXtests::aspectRatio() {
485
 
        
 
485
TestExitStatus GFXtests::aspectRatio() {
 
486
 
486
487
        Testsuite::clearScreen();
487
488
        Common::String info = "Aspect Ratio Correction test. If aspect ratio correction is enabled you should expect a circle on screen,"
488
489
        " an ellipse otherwise.";
489
490
 
490
491
        if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
491
492
                Testsuite::logPrintf("Info! Skipping test : Aspect Ratio\n");
492
 
                return true;
 
493
                return kTestSkipped;
493
494
        }
494
495
        // Draw an ellipse on the screen
495
496
        drawEllipse(80, 160, 72, 60);
496
497
 
497
498
        bool isFeaturePresent;
498
499
        bool isFeatureEnabled;
499
 
        bool passed = true;
 
500
        TestExitStatus passed = kTestPassed;
500
501
        Common::String prompt;
501
502
        OptionSelected shouldSelect;
502
503
 
510
511
                prompt = " What does the curve on screen appears to you ?";
511
512
                if (!Testsuite::handleInteractiveInput(prompt, "Circle", "Ellipse", shouldSelect)) {
512
513
                        // User selected incorrect option
513
 
                        passed = false;
 
514
                        passed = kTestFailed;
514
515
                        Testsuite::logDetailedPrintf("Aspect Ratio Correction failed\n");
515
516
                }
516
517
 
524
525
                prompt = " What does the curve on screen appears to you ?";
525
526
                if (!Testsuite::handleInteractiveInput(prompt, "Circle", "Ellipse", shouldSelect)) {
526
527
                        // User selected incorrect option
527
 
                        passed = false;
 
528
                        passed = kTestFailed;
528
529
                        Testsuite::logDetailedPrintf("Aspect Ratio Correction failed\n");
529
530
                }
530
531
 
540
541
        if (Testsuite::handleInteractiveInput("This should definetely be your initial state?", "Yes, it is", "Nopes", kOptionRight)) {
541
542
                // User selected incorrect mode
542
543
                Testsuite::logDetailedPrintf("Switching back to initial state failed\n");
543
 
                passed = false;
 
544
                passed = kTestFailed;
544
545
        }
545
546
 
546
547
        return passed;
550
551
 * Tests Palettized cursors.
551
552
 * Method: Create a yellow colored cursor, should be able to move it. Once you click test terminates
552
553
 */
553
 
bool GFXtests::palettizedCursors() {
 
554
TestExitStatus GFXtests::palettizedCursors() {
554
555
 
555
556
        Testsuite::clearScreen();
556
557
        Common::String info = "Palettized Cursors test.\n "
562
563
 
563
564
        if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
564
565
                Testsuite::logPrintf("Info! Skipping test : Palettized Cursors\n");
565
 
                return true;
 
566
                return kTestSkipped;
566
567
        }
567
 
        
568
 
        bool passed = true;
 
568
 
 
569
        TestExitStatus passed = kTestPassed;
569
570
 
570
571
        // Testing with cursor Palette
571
572
        setupMouseLoop();
572
 
        
 
573
 
573
574
        if (Testsuite::handleInteractiveInput("Which color did the cursor appeared to you?", "Yellow", "Any other", kOptionRight)) {
574
575
                Testsuite::logDetailedPrintf("Couldn't use cursor palette for rendering cursor\n");
575
 
                passed = false;
 
576
                passed = kTestFailed;
576
577
        }
577
578
 
578
579
        // Testing with game Palette
581
582
 
582
583
        if (Testsuite::handleInteractiveInput("Which color did the cursor appeared to you?", "Red", "Any other", kOptionRight)) {
583
584
                Testsuite::logDetailedPrintf("Couldn't use Game palette for rendering cursor\n");
584
 
                passed = false;
 
585
                passed = kTestFailed;
585
586
        }
586
587
 
587
 
        if (!Testsuite::handleInteractiveInput("Did test run as was described?")) {
588
 
                passed = false;
 
588
        if (!Testsuite::handleInteractiveInput("     Did test run as was described?     ")) {
 
589
                passed = kTestFailed;
589
590
        }
590
591
 
591
592
        // re-enable cursor palette
599
600
 * Tests automated mouse movements. "Warp" functionality provided by the backend.
600
601
 */
601
602
 
602
 
bool GFXtests::mouseMovements() {
 
603
TestExitStatus GFXtests::mouseMovements() {
603
604
        Testsuite::clearScreen();
604
 
        // Make mouse visible
 
605
        // Ensure that the cursor is visible
605
606
        CursorMan.showMouse(true);
606
 
        
 
607
 
607
608
        Common::String info = "Testing Automated Mouse movements.\n"
608
609
                                                "You should expect cursor hotspot(top-left corner) to automatically move from (0, 0) to (100, 100).\n"
609
 
                                                "There we have a rectangle drawn, finally the cursor would lie centred in that rectangle.";
 
610
                                                "There we have a rectangle drawn, finally the cursor would lie centered in that rectangle.";
610
611
 
611
612
        if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
612
613
                Testsuite::logPrintf("Info! Skipping test : Mouse Movements\n");
613
 
                return true;
 
614
                return kTestSkipped;
614
615
        }
615
 
        
 
616
 
616
617
        // Draw Rectangle
617
618
        Graphics::Surface *screen = g_system->lockScreen();
 
619
        // Ensure that 2 represents red in current palette
 
620
        GFXTestSuite::setCustomColor(255, 0, 0);
618
621
        screen->fillRect(Common::Rect::center(106, 106, 14, 14), 2);
619
622
        g_system->unlockScreen();
620
623
 
635
638
        g_system->delayMillis(1500);
636
639
        CursorMan.showMouse(false);
637
640
 
638
 
        if (Testsuite::handleInteractiveInput("Was the cursor symmetrically contained in the rectangle at (100, 100)?", "Yes", "No", kOptionRight)) {
639
 
                return false;
 
641
        if (Testsuite::handleInteractiveInput("Was the cursor centered in the rectangle at (100, 100)?", "Yes", "No", kOptionRight)) {
 
642
                return kTestFailed;
640
643
        }
641
644
 
642
 
        return true;
 
645
        return kTestPassed;
643
646
}
644
647
 
645
648
 
648
651
 * This basically blits the screen by the contents of its buffer.
649
652
 *
650
653
 */
651
 
bool GFXtests::copyRectToScreen() {
652
 
        
 
654
TestExitStatus GFXtests::copyRectToScreen() {
 
655
 
653
656
        Testsuite::clearScreen();
654
657
        Common::String info = "Testing Blitting a Bitmap to screen.\n"
655
 
                "You should expect to see a 20x40 yellow horizontal rectangle centred at the screen.";
 
658
                "You should expect to see a 20x40 yellow horizontal rectangle centered at the screen.";
656
659
 
657
660
        if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
658
661
                Testsuite::logPrintf("Info! Skipping test : Blitting Bitmap\n");
659
 
                return true;
 
662
                return kTestSkipped;
660
663
        }
661
 
        
 
664
 
662
665
        GFXTestSuite::setCustomColor(255, 255, 0);
663
666
        byte buffer[20 * 40];
664
667
        memset(buffer, 2, 20 * 40);
670
673
        g_system->updateScreen();
671
674
        g_system->delayMillis(1000);
672
675
 
673
 
        if (Testsuite::handleInteractiveInput("Did you see yellow rectangle?", "Yes", "No", kOptionRight)) {
674
 
                return false;
 
676
        if (Testsuite::handleInteractiveInput("      Did you see yellow rectangle ?       ", "Yes", "No", kOptionRight)) {
 
677
                return kTestFailed;
675
678
        }
676
679
 
677
 
        return true;
 
680
        return kTestPassed;
678
681
}
679
682
 
680
683
/**
681
684
 * Testing feature : Iconifying window
682
685
 * It is expected the screen minimizes when this feature is enabled
683
686
 */
684
 
bool GFXtests::iconifyWindow() {
685
 
        
 
687
TestExitStatus GFXtests::iconifyWindow() {
 
688
 
686
689
        Testsuite::clearScreen();
687
690
        Common::String info = "Testing Iconify Window mode.\n If the feature is supported by the backend, "
688
691
                "you should expect the window to be minimized.\n However you would manually need to de-iconify.";
689
692
 
690
693
        if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
691
694
                Testsuite::logPrintf("Info! Skipping test : Iconifying window\n");
692
 
                return true;
 
695
                return kTestSkipped;
693
696
        }
694
 
        
 
697
 
695
698
        Common::Point pt(0, 100);
696
699
        Testsuite::writeOnScreen("Testing Iconifying window", pt);
697
700
 
718
721
                Testsuite::displayMessage("feature not supported");
719
722
        }
720
723
 
721
 
        if (Testsuite::handleInteractiveInput("Did you see window minimized?", "Yes", "No", kOptionRight)) {
722
 
                return false;
 
724
        if (Testsuite::handleInteractiveInput("  Did you see the window minimized?  ", "Yes", "No", kOptionRight)) {
 
725
                return kTestFailed;
723
726
        }
724
727
 
725
 
        return true;
 
728
        return kTestPassed;
726
729
}
727
730
 
728
731
/**
729
732
 * Testing feature: Scaled cursors
730
733
 */
731
 
bool GFXtests::scaledCursors() {
 
734
TestExitStatus GFXtests::scaledCursors() {
732
735
 
733
736
        Testsuite::clearScreen();
734
737
        Common::String info = "Testing : Scaled cursors\n"
735
738
                "Here every graphics mode is tried with a cursorTargetScale of 1, 2 and 3.\n"
736
 
                "The expected cursor size is drawn as a rectangle, the cursor should entirely cover that rectangle.\n"
 
739
                "The expected cursor size is drawn as a rectangle.\n The cursor should approximately match that rectangle.\n"
737
740
                "This may take time, You may skip the later scalers and just examine the first three i.e 1x, 2x and 3x";
738
741
 
 
742
        bool isAspectRatioCorrected = g_system->getFeatureState(OSystem::kFeatureAspectRatioCorrection);
 
743
 
 
744
        if (isAspectRatioCorrected) {
 
745
                info += "\nDisabling Aspect ratio correction, for letting cusors match exactly, will be restored after this test.";
 
746
        }
 
747
        
739
748
        if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
740
749
                Testsuite::logPrintf("Info! Skipping test : Scaled Cursors\n");
741
 
                return true;
 
750
                return kTestSkipped;
742
751
        }
743
752
 
744
753
        int maxLimit = 1000;
746
755
                maxLimit = 3;
747
756
        }
748
757
 
 
758
 
 
759
        if (isAspectRatioCorrected) {   
 
760
                g_system->beginGFXTransaction();
 
761
                g_system->setFeatureState(OSystem::kFeatureAspectRatioCorrection, false);
 
762
                g_system->endGFXTransaction();
 
763
        }
 
764
 
749
765
        const int currGFXMode = g_system->getGraphicsMode();
750
766
        const OSystem::GraphicsMode *gfxMode = g_system->getSupportedGraphicsModes();
751
767
 
753
769
                // for every graphics mode display cursors for cursorTargetScale 1, 2 and 3
754
770
                // Switch Graphics mode
755
771
                // FIXME: Crashes with "3x" mode now.:
 
772
                
 
773
                info = Common::String::format("Testing : Scaled cursors with GFX Mode %s\n", gfxMode->name);
 
774
                if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
 
775
                        Testsuite::logPrintf("\tInfo! Skipping sub-test : Scaled Cursors :: GFX Mode %s\n", gfxMode->name);
 
776
                        gfxMode++;
 
777
                        maxLimit--;
 
778
                        continue;
 
779
                }
 
780
                if (Engine::shouldQuit()) {
 
781
                        // Explicit exit requested
 
782
                        Testsuite::logPrintf("Info! Explicit exit requested during scaling test, this test may be incomplete\n");
 
783
                        return kTestSkipped;
 
784
                }
 
785
                
756
786
                g_system->beginGFXTransaction();
757
787
 
758
788
                bool isGFXModeSet = g_system->setGraphicsMode(gfxMode->id);
771
801
                        Testsuite::clearScreen();
772
802
                } else {
773
803
                        Testsuite::logDetailedPrintf("Switching to graphics mode %s failed\n", gfxMode->name);
774
 
                        return false;
 
804
                        return kTestFailed;
775
805
                }
776
806
                gfxMode++;
777
807
                maxLimit--;
 
808
 
 
809
                info = "Did the expected cursor size and the actual cursor size matched?";
 
810
                if (Testsuite::handleInteractiveInput(info, "Yes", "No", kOptionRight)) {
 
811
                        Testsuite::logPrintf("\tInfo! Failed sub-test : Scaled Cursors :: GFX Mode %s\n", gfxMode->name);
 
812
                }
 
813
                
 
814
                if (Engine::shouldQuit()) {
 
815
                        // Explicit exit requested
 
816
                        Testsuite::logPrintf("Info! Explicit exit requested during scaling test, this test may be incomplete\n");
 
817
                        return kTestSkipped;
 
818
                }
 
819
 
778
820
        }
779
821
 
780
822
        // Restore Original State
781
823
        g_system->beginGFXTransaction();
782
824
        bool isGFXModeSet = g_system->setGraphicsMode(currGFXMode);
783
825
        g_system->initSize(320, 200);
 
826
 
 
827
        if (isAspectRatioCorrected) {
 
828
                g_system->setFeatureState(OSystem::kFeatureAspectRatioCorrection, true);
 
829
        }
 
830
        
784
831
        OSystem::TransactionError gfxError = g_system->endGFXTransaction();
785
832
 
786
833
        if (gfxError != OSystem::kTransactionSuccess || !isGFXModeSet) {
787
834
                Testsuite::logDetailedPrintf("Switcing to initial state failed\n");
788
 
                return false;
 
835
                return kTestFailed;
789
836
        }
790
837
 
791
838
        // Done with cursors, Make them invisible, any other test may enable and use it.
792
839
        CursorMan.showMouse(false);
793
 
        return true;
 
840
        return kTestPassed;
794
841
}
795
842
 
796
 
bool GFXtests::shakingEffect() {
797
 
        
 
843
TestExitStatus GFXtests::shakingEffect() {
 
844
 
798
845
        Testsuite::clearScreen();
799
846
        Common::String info = "Shaking test. You should expect the graphics(text/bars etc) drawn on the screen to shake!";
800
847
 
801
848
        if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
802
849
                Testsuite::logPrintf("Info! Skipping test : Shaking Effect\n");
803
 
                return true;
 
850
                return kTestSkipped;
804
851
        }
805
852
 
806
853
        Common::Point pt(0, 100);
807
854
        Testsuite::writeOnScreen("If Shaking Effect works, this should shake!", pt);
808
 
        int times = 35;
 
855
        int times = 15;
809
856
        while (times--) {
810
857
                g_system->setShakePos(25);
 
858
                g_system->delayMillis(50);
811
859
                g_system->updateScreen();
812
860
                g_system->setShakePos(0);
 
861
                g_system->delayMillis(50);
813
862
                g_system->updateScreen();
814
863
        }
815
864
        g_system->delayMillis(1500);
816
865
 
817
866
        if (Testsuite::handleInteractiveInput("Did the Shaking test worked as you were expecting?", "Yes", "No", kOptionRight)) {
818
867
                Testsuite::logDetailedPrintf("Shaking Effect didn't worked");
819
 
                return false;
 
868
                return kTestFailed;
820
869
        }
821
 
        return true;
 
870
        return kTestPassed;
822
871
}
823
872
 
824
 
bool GFXtests::focusRectangle() {
825
 
        
 
873
TestExitStatus GFXtests::focusRectangle() {
 
874
 
826
875
        Testsuite::clearScreen();
827
876
        Common::String info = "Testing : Setting and hiding Focus \n"
828
877
                "If this feature is implemented, the focus should be toggled between the two rectangles on the corners";
829
878
 
830
879
        if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
831
880
                Testsuite::logPrintf("Info! Skipping test : focus Rectangle\n");
832
 
                return true;
 
881
                return kTestSkipped;
833
882
        }
834
 
        
 
883
 
835
884
        const Graphics::Font &font(*FontMan.getFontByUsage(Graphics::FontManager::kConsoleFont));
836
885
 
837
886
        Graphics::Surface *screen = g_system->lockScreen();
867
916
                Testsuite::logDetailedPrintf("Focus Rectangle feature doesn't works. Check platform.\n");
868
917
        }
869
918
 
870
 
        return true;
 
919
        return kTestPassed;
871
920
}
872
921
 
873
 
bool GFXtests::overlayGraphics() {
 
922
TestExitStatus GFXtests::overlayGraphics() {
874
923
        Testsuite::clearScreen();
875
924
        Common::String info = "Overlay Graphics. You should expect to see a green colored rectangle on the screen";
876
925
 
877
926
        if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
878
927
                Testsuite::logPrintf("Info! Skipping test : Overlay Graphics\n");
879
 
                return true;
 
928
                return kTestSkipped;
880
929
        }
881
 
        
 
930
 
882
931
        Graphics::PixelFormat pf = g_system->getOverlayFormat();
883
932
 
884
933
        OverlayColor buffer[50 * 100];
899
948
 
900
949
        if (Testsuite::handleInteractiveInput("Did you see a green overlayed rectangle?", "Yes", "No", kOptionRight)) {
901
950
                Testsuite::logDetailedPrintf("Overlay Rectangle feature doesn't works\n");
902
 
                return false;
 
951
                return kTestFailed;
903
952
        }
904
953
 
905
 
        return true;
 
954
        return kTestPassed;
906
955
}
907
956
 
908
 
bool GFXtests::paletteRotation() {
909
 
        
 
957
TestExitStatus GFXtests::paletteRotation() {
 
958
 
910
959
        Common::String info = "Palette rotation. Here we draw a full 256 colored rainbow and then rotate it.\n"
911
960
                                                "Note that the screen graphics change without having to draw anything.\n"
912
 
                                                "The palette should appear to rotate, Click the mouse button to exit.";
 
961
                                                "The palette should appear to rotate, as a result, the background will change its color too.\n"
 
962
                                                "Click the mouse button to exit.";
913
963
 
914
964
        if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
915
965
                Testsuite::logPrintf("Info! Skipping test : palette Rotation\n");
916
 
                return true;
 
966
                return kTestSkipped;
917
967
        }
 
968
        Common::Point pt(0, 10);
918
969
        Testsuite::clearEntireScreen();
919
970
 
920
971
        // Use 256 colors
921
 
        byte palette[256 * 4] = {0};
 
972
        byte palette[256 * 3] = {0};
922
973
 
923
974
        int r, g, b;
924
975
        int colIndx;
925
976
 
926
977
        for (int i = 0; i < 256; i++) {
927
978
                HSVtoRGB(r, g, b, i, 1, 1);
928
 
                colIndx = i * 4;
 
979
                colIndx = i * 3;
929
980
                palette[colIndx] = r;
930
981
                palette[colIndx + 1] = g;
931
982
                palette[colIndx + 2] = b;
932
983
        }
933
984
 
934
985
        // Initialize this palette.
935
 
        g_system->setPalette(palette, 0, 256);
 
986
        g_system->getPaletteManager()->setPalette(palette, 0, 256);
936
987
 
937
988
        // Draw 256 Rectangles, each 1 pixel wide and 10 pixels long
938
989
        // one for 0-255 color range other for 0-127-255 range
951
1002
        }
952
1003
 
953
1004
        g_system->copyRectToScreen(buffer, 256, 22, 50, 256, 30);
954
 
        
 
1005
 
955
1006
        // Show mouse
956
1007
        CursorMan.showMouse(true);
957
1008
        g_system->updateScreen();
959
1010
 
960
1011
        bool toRotate = true;
961
1012
        Common::Event event;
962
 
        
 
1013
 
963
1014
        while (toRotate) {
964
1015
                while (g_system->getEventManager()->pollEvent(event)) {
965
1016
                        if (event.type == Common::EVENT_LBUTTONDOWN || event.type == Common::EVENT_RBUTTONDOWN) {
970
1021
                rotatePalette(palette, 256);
971
1022
 
972
1023
                g_system->delayMillis(10);
973
 
                g_system->setPalette(palette, 0, 256);
 
1024
                g_system->getPaletteManager()->setPalette(palette, 0, 256);
974
1025
                g_system->updateScreen();
975
1026
        }
976
1027
 
979
1030
        GFXTestSuite::setCustomColor(255, 0, 0);
980
1031
        Testsuite::clearScreen();
981
1032
 
982
 
        if(Testsuite::handleInteractiveInput("Did you saw a rotation in colors of rectangles displayed on screen?", "Yes", "No", kOptionRight)) {
983
 
                return false;
 
1033
        if(Testsuite::handleInteractiveInput("Did you see a rotation in colors of rectangles displayed on screen?", "Yes", "No", kOptionRight)) {
 
1034
                return kTestFailed;
984
1035
        }
985
1036
 
986
 
        return true;
 
1037
        return kTestPassed;
987
1038
}
988
1039
 
989
 
bool GFXtests::cursorTrails() {
 
1040
TestExitStatus GFXtests::cursorTrails() {
990
1041
        Common::String info = "With some shake offset the cursor was known to leave trails in the GUI\n"
991
1042
                                                "Here we set some offset and ask user to check for mouse trails, \n"
992
1043
                                                "the test is passed when there are no trails";
993
1044
 
994
1045
        if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
995
1046
                Testsuite::logPrintf("Info! Skipping test : Cursor Trails\n");
996
 
                return true;
 
1047
                return kTestSkipped;
997
1048
        }
998
 
        bool passed = false;
 
1049
        TestExitStatus passed = kTestFailed;
999
1050
        g_system->setShakePos(25);
1000
1051
        g_system->updateScreen();
1001
1052
        if (Testsuite::handleInteractiveInput("Does the cursor leaves trails while moving?", "Yes", "No", kOptionRight)) {
1002
 
                passed = true;
 
1053
                passed = kTestPassed;
1003
1054
        }
1004
1055
        g_system->setShakePos(0);
1005
1056
        g_system->updateScreen();
1006
1057
        return passed;
1007
1058
}
1008
1059
 
1009
 
bool GFXtests::pixelFormats() {
 
1060
TestExitStatus GFXtests::pixelFormats() {
1010
1061
        Testsuite::clearScreen();
1011
1062
        Common::String info = "Testing pixel formats. Here we iterate over all the supported pixel formats and display some colors using them\n"
1012
1063
                "This may take long, especially if the backend supports many pixel formats";
1013
1064
 
1014
1065
        if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
1015
 
                Testsuite::logPrintf("Info! Skipping test : focus Rectangle\n");
1016
 
                return true;
 
1066
                Testsuite::logPrintf("Info! Skipping test : Pixel Formats\n");
 
1067
                return kTestSkipped;
1017
1068
        }
1018
1069
 
1019
1070
        Common::List<Graphics::PixelFormat> pfList = g_system->getSupportedFormats();
1054
1105
 
1055
1106
                Common::Point pt(0, 170);
1056
1107
                Common::String msg;
1057
 
                // XXX: Can use snprintf?
1058
 
                msg = Common::String::printf("Testing Pixel Formats, %d of %d", numFormatsTested, pfList.size());
 
1108
                msg = Common::String::format("Testing Pixel Formats, %d of %d", numFormatsTested, pfList.size());
1059
1109
                Testsuite::writeOnScreen(msg, pt, true);
1060
1110
 
1061
1111
                // CopyRectToScreen could have been used, but that may involve writing code which
1064
1114
 
1065
1115
                Graphics::Surface *screen = g_system->lockScreen();
1066
1116
 
1067
 
                // Draw 6 rectangles centred at (50, 160), piled over one another
 
1117
                // Draw 6 rectangles centered at (50, 160), piled over one another
1068
1118
                // each with color in colors[]
1069
1119
                for (int i = 0; i < 6; i++) {
1070
1120
                        screen->fillRect(Common::Rect::center(160, 20 + i * 10, 100, 10), colors[i]);
1091
1141
        Testsuite::clearScreen();
1092
1142
 
1093
1143
        if (numFailed) {
1094
 
                Testsuite::logDetailedPrintf("Pixel Format test: Failed : %d, Passed : %d, Ignored %d\n", numFailed, numPassed, numFormatsTested - (numPassed + numFailed));
1095
 
                return false;
 
1144
                Testsuite::logDetailedPrintf("Pixel Format test: Failed : %d, Passed : %d, Ignored %d\n",numFailed, numPassed, numFormatsTested - (numPassed + numFailed));
 
1145
                return kTestFailed;
1096
1146
        }
1097
1147
 
1098
 
        return true;
 
1148
        return kTestPassed;
1099
1149
}
1100
1150
 
1101
1151
} // End of namespace Testbed