1//
2//   Copyright (C) 2007, 2009, 2010 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.
13//
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
17
18
19// These are already checked in Global.as, and it would be
20// clear if things don't work as expected
21check_equals(typeof(setInterval), 'function');
22check_equals(typeof(clearInterval), 'function');
23
24do_this = function() {
25	++this_counter;
26	var now = getTimer();
27	var int = now-this_timer;
28	this_timer = now;
29	check(int >= this_ms, this_ms+" interval (this) called after " + int + " milliseconds [" + __FILE__ + ":" + __LINE__ + "]");
30	note("Doing this "+this_counter+" after " + int + " milliseconds");
31	if ( this_counter > 3 )
32	{
33		clearInterval(this_interval);
34		note("This interval cleared ");
35		if ( this_counter > 4 )
36		{
37			note('Setting another interval');
38			A = function() {};
39			A.prototype.name = 'A';
40			A.prototype.test = function() { return 'Atest'; };
41			B = function() {}; B.prototype = new A;
42			B.prototype.test = function() {
43				check_equals(super.test(), 'Atest');
44				check_equals(super.name, 'A');
45				totals(18, __FILE__ + ":" + __LINE__ );
46				test_completed = 1;
47				clearInterval(method_interval);
48				loadMovie("fscommand:quit", _level0);
49
50			};
51
52			o = new B;
53			method_interval = setInterval(o, 'test', 1);
54		}
55	}
56};
57
58do_that = function() {
59	++that_counter;
60	var now = getTimer();
61	var int = now-that_timer;
62	that_timer = now;
63	check(int >= that_ms, that_ms+" interval (that) called after " + int + " milliseconds [" + __FILE__ + ":" + __LINE__ + "]");
64	//note("Doing that "+that_counter+" after " + int + " milliseconds");
65	if ( that_counter > 3 )
66	{
67		clearInterval(that_interval);
68		note("That interval cleared ");
69		this_time = getTimer();
70		this_ms = 1;
71		this_interval = setInterval(do_this, 1);
72		// interval 1 is NOT reused
73		check_equals(this_interval, 4); // interval 3 is set from within do_that
74	}
75};
76
77push_args = function() {
78	check_equals(arguments.length, 3);
79	clearInterval(push_interval);
80	note("Pushing "+arguments.length+" args");
81	for (var i=0; i<arguments.length; i++)
82	{
83		pushed_args[i] = arguments[i];
84	}
85};
86
87this_counter = 0;
88this_timer = getTimer();
89this_ms = 1; // 0.0001;
90this_interval  = setInterval(do_this, 1); // 0.0001);
91check_equals(this_interval, 1);
92
93that_counter = 0;
94that_ms = 1000;
95that_timer = getTimer();
96that_interval  = setInterval(do_that, 1000);
97check_equals(that_interval, 2);
98
99pushed_args = new Array;
100push_interval  = setInterval(push_args, 200, 8, 9, 10);
101check_equals(push_interval, 3);
102
103
104stop();
105