Add automated tests on function-type FSCommand parameter passing.
[gnash.git] / testsuite / misc-ming.all / loop / loop_test2runner.cpp
blob0b30b4ac397c5ac3ed44facbe6744ffd2fb3bb10
1 /*
2 * Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
21 #define INPUT_FILENAME "loop_test2.swf"
23 #include "MovieTester.h"
24 #include "MovieClip.h"
25 #include "DisplayObject.h"
26 #include "DisplayList.h"
27 #include "log.h"
29 #include "check.h"
30 #include <string>
31 #include <cassert>
33 using namespace gnash;
34 using namespace std;
35 using namespace gnash::geometry;
37 TRYMAIN(_runtest);
38 int
39 trymain(int /*argc*/, char** /*argv*/)
41 typedef gnash::geometry::SnappingRanges2d<int> Ranges;
42 typedef gnash::geometry::Range2d<int> Bounds;
44 string filename = string(TGTDIR) + string("/") + string(INPUT_FILENAME);
45 MovieTester tester(filename);
47 gnash::LogFile& dbglogfile = gnash::LogFile::getDefaultInstance();
48 dbglogfile.setVerbosity(1);
50 // Colors we'll use during the test
51 rgba red(255,0,0,255);
52 rgba white(255,255,255,255);
53 rgba black(0,0,0,255);
55 // Ranges we'll use during the test
56 Range2d<int> redRange(300,300,360,360);
57 Range2d<int> blackRange(330,270,450,390);
59 // Coordinates we'll use during testing
60 int x_left = 270; // on the left of any DisplayObject
61 int x_red = 310; // on the red square
62 int x_int = 340; // on the intersection between the red and black squares
63 int x_black = 370; // on black square
64 int x_right = 460; // on the right of any DisplayObject
65 int y = 330;
67 Ranges invalidated;
68 MovieClip* root = tester.getRootMovie();
69 assert(root);
71 // FRAME 1 (start)
73 check_equals(root->get_frame_count(), 4);
74 check_equals(root->getPlayState(), MovieClip::PLAYSTATE_PLAY);
75 check_equals(root->get_current_frame(), 0);
76 check_equals(root->getDisplayList().size(), 1); // dejagnu clip
77 invalidated = tester.getInvalidatedRanges();
78 check( invalidated.contains(76, 4) ); // the "-xtrace enabled-" label...
80 tester.advance(); // FRAME 2, place DisplayObjects (black on top)
81 invalidated = tester.getInvalidatedRanges();
83 check_equals(root->getPlayState(), MovieClip::PLAYSTATE_PLAY);
84 check_equals(root->get_current_frame(), 1);
85 check_equals(root->getDisplayList().size(), 3); // dejagnu + red square + black square
87 // check invalidated bounds contain both the red and black square
88 check( invalidated.contains(redRange) );
89 check( invalidated.contains(blackRange) );
91 // Check that the black square is over the red square
92 check_pixel(x_left, y, 2, white, 2);
93 check_pixel(x_red, y, 2, red, 2);
94 check_pixel(x_int, y, 2, black, 2); // black is *over* red square
95 check_pixel(x_black, y, 2, black, 2);
96 check_pixel(x_right, y, 2, white, 2);
98 tester.advance(); // FRAME 3, depth-swap the two DisplayObjects
99 invalidated = tester.getInvalidatedRanges();
101 check_equals(root->getPlayState(), MovieClip::PLAYSTATE_PLAY);
102 check_equals(root->get_current_frame(), 2);
103 check_equals(root->getDisplayList().size(), 3); // dejagnu + red square + black square
105 // check invalidated bounds to contain the intersection
106 // between the two DisplayObjects.
108 check( invalidated.contains(Intersection(redRange,blackRange)) );
110 // Check that the black square is now behind the red square
111 check_pixel(x_left, y, 2, white, 2);
112 check_pixel(x_red, y, 2, red, 2);
113 check_pixel(x_int, y, 2, red, 2); // black is *behind* red square
114 check_pixel(x_black, y, 2, black, 2);
115 check_pixel(x_right, y, 2, white, 2);
117 tester.advance(); // FRAME 4, jump to frame 2 and stop
118 invalidated = tester.getInvalidatedRanges();
120 check_equals(root->getPlayState(), MovieClip::PLAYSTATE_STOP);
121 check_equals(root->get_current_frame(), 1);
122 check_equals(root->getDisplayList().size(), 3); // dejagnu + red square + black square
124 // Invalidated bounds can't be Null because something is printed
125 // in the XTRACE window... Anyway, the squares should be far enoguh
126 // to assume the invalidated bounds won't contain their intersection
128 // Gnash has an huge invalidated bounds for the whole movie lifetime, btw....
130 xcheck( ! invalidated.intersects(Intersection(redRange,blackRange)) );
132 // Check that the black square is still behind the red square
133 check_pixel(x_left, y, 2, white, 2);
134 check_pixel(x_red, y, 2, red, 2);
135 check_pixel(x_int, y, 2, red, 2); // black is *behind* red square
136 check_pixel(x_black, y, 2, black, 2);
137 check_pixel(x_right, y, 2, white, 2);
138 return 0;