2 // Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 3 of the License, or
8 // (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 // Test case for TextSnapshot ActionScript class
21 // compile this test case with Ming makeswf, and then
22 // execute it like this gnash -1 -r 0 -v out.swf
24 // TextSnapshot works only on static text, so this test file only tests
25 // AS compatibility (return, argument handling).
28 rcsid
="TextSnapshot.as";
31 #if OUTPUT_VERSION
< 6
33 check_equals
(typeof(TextSnapshot), "function");
38 check
(TextSnapshot.prototype
.hasOwnProperty
('findText'));
39 check
(TextSnapshot.prototype
.hasOwnProperty
('getCount'));
40 check
(TextSnapshot.prototype
.hasOwnProperty
('getSelected'));
41 check
(TextSnapshot.prototype
.hasOwnProperty
('getSelectedText'));
42 check
(TextSnapshot.prototype
.hasOwnProperty
('getText'));
43 check
(TextSnapshot.prototype
.hasOwnProperty
('setSelectColor'));
44 check
(TextSnapshot.prototype
.hasOwnProperty
('hitTestTextNearPos'));
45 check
(TextSnapshot.prototype
.hasOwnProperty
('setSelected'));
47 check_equals
( typeof(TextSnapshot), 'function' );
49 var textsnapshotObj
= new TextSnapshot;
51 check
(textsnapshotObj
instanceof TextSnapshot);
52 check
(!textsnapshotObj
.hasOwnProperty
('findText'));
53 check
(!textsnapshotObj
.hasOwnProperty
('getCount'));
54 check
(!textsnapshotObj
.hasOwnProperty
('getSelected'));
55 check
(!textsnapshotObj
.hasOwnProperty
('getSelectedText'));
56 check
(!textsnapshotObj
.hasOwnProperty
('getText'));
57 check
(!textsnapshotObj
.hasOwnProperty
('setSelectColor'));
58 check
(!textsnapshotObj
.hasOwnProperty
('hitTestTextNearPos'));
59 check
(!textsnapshotObj
.hasOwnProperty
('setSelected'));
61 // test the TextSnapshot constuctor
62 check_equals
( typeof(textsnapshotObj
), 'object' );
64 check_equals
(typeof(textsnapshotObj
.findText
), 'function');
65 check_equals
(typeof(textsnapshotObj
.getCount
), 'function');
66 check_equals
(typeof(textsnapshotObj
.getSelected
), 'function');
67 check_equals
(typeof(textsnapshotObj
.getSelectedText
), 'function');
68 check_equals
(typeof(textsnapshotObj
.getText
), 'function');
69 check_equals
(typeof(textsnapshotObj
.hitTestTextNearPos
), 'function');
70 check_equals
(typeof(textsnapshotObj
.setSelectColor
), 'function');
71 check_equals
(typeof(textsnapshotObj
.setSelected
), 'function');
73 gh
= new TextSnapshot("hello");
74 check_equals
(gh
.toString
(), "[object Object]");
75 check_equals
(gh
.getCount
.toString
(), "[type Function]");
76 check_equals
(gh
.getCount
(), undefined);
79 gh
= new TextSnapshot(o
);
80 check_equals
(gh
.toString
(), "[object Object]");
81 check_equals
(gh
.getCount
.toString
(), "[type Function]");
82 check_equals
(gh
.getCount
(), undefined);
84 gh
= new TextSnapshot(this);
85 check_equals
(gh
.toString
(), "[object Object]");
86 check_equals
(gh
.getCount
.toString
(), "[type Function]");
87 check_equals
(gh
.getCount
(), 0);
89 gh
= new TextSnapshot(this, true);
90 check_equals
(gh
.toString
(), "[object Object]");
91 check_equals
(gh
.getCount
.toString
(), "[type Function]");
92 check_equals
(gh
.getCount
(), undefined);
94 ts
= _root
.getTextSnapshot
();
95 check
(ts
instanceof TextSnapshot);
96 check
(!ts
.hasOwnProperty
('findText'));
97 check
(!ts
.hasOwnProperty
('getCount'));
98 check
(!ts
.hasOwnProperty
('getSelected'));
99 check
(!ts
.hasOwnProperty
('getSelectedText'));
100 check
(!ts
.hasOwnProperty
('getText'));
101 check
(!ts
.hasOwnProperty
('setSelectColor'));
102 check
(!ts
.hasOwnProperty
('hitTestTextNearPos'));
103 check
(!ts
.hasOwnProperty
('setSelected'));
105 // getText() and getCount()
107 check_equals
(typeof(ts
.getCount
()), "number");
108 check_equals
(typeof(ts
.getCount
(0)), "undefined");
109 check_equals
(typeof(ts
.getCount
("a")), "undefined");
110 check_equals
(typeof(ts
.getCount
(true)), "undefined");
111 check_equals
(typeof(ts
.getCount
(0, 1)), "undefined");
112 check_equals
(ts
.getCount
(), 0);
114 check_equals
(typeof(ts
.findText
()), "undefined");
115 check_equals
(typeof(ts
.findText
("a")), "undefined");
116 check_equals
(typeof(ts
.findText
(1)), "undefined");
117 check_equals
(typeof(ts
.findText
(1, "a")), "undefined");
119 // Test with no text.
120 check_equals
(typeof(ts
.findText
(1, "a", true)), "number");
121 check_equals
(typeof(ts
.findText
(1, "a", 1)), "number");
122 check_equals
(typeof(ts
.findText
(1, "a", new Date())), "number");
123 check_equals
(typeof(ts
.findText
("6", "a", new Date())), "number");
124 check_equals
(typeof(ts
.findText
("b", "a", new Date())), "number");
125 check_equals
(typeof(ts
.findText
(-1, "a", new Date())), "number");
126 check_equals
(typeof(ts
.findText
(Infinity, "a", new Date())), "number");
127 check_equals
(typeof(ts
.findText
(-1, "a", new Date(), "e")), "undefined");
128 check_equals
(typeof(ts
.findText
(Infinity, "a", new Date(), 3)), "undefined");
130 check_equals
(ts
.findText
(1, "a", true), -1);
131 check_equals
(ts
.findText
(1, "a", 1), -1);
132 check_equals
(ts
.findText
(1, "a", new Date()), -1);
133 check_equals
(ts
.findText
("6", "a", false), -1);
134 check_equals
(ts
.findText
("b", "a", true), -1);
135 check_equals
(ts
.findText
(-1, "a", new Date()), -1);
136 check_equals
(ts
.findText
(Infinity, "a", new Date()), -1);
138 // Shouldn't work with dynamic text.
139 _root
.createTextField
("tf", 10, 30, 30, 100, 100);
140 _root
.tf
.text
= "ghjkab";
141 ts
= _root
.getTextSnapshot
();
142 check_equals
(ts
.getCount
(), 0);
143 check_equals
(ts
.findText
(1, "a", true), -1);
144 check_equals
(ts
.findText
(1, "a", false), -1);
148 check_equals
(typeof(ts
.getSelected
()), "undefined");
149 check_equals
(typeof(ts
.getSelected
(0)), "undefined");
150 check_equals
(typeof(ts
.getSelected
("a")), "undefined");
151 check_equals
(typeof(ts
.getSelected
(new Date())), "undefined");
152 check_equals
(typeof(ts
.getSelected
([0, 1])), "undefined");
153 check_equals
(typeof(ts
.getSelected
([0, 1], 2)), "boolean");
154 check_equals
(typeof(ts
.getSelected
(0, 1)), "boolean");
155 check_equals
(typeof(ts
.getSelected
(1, 0)), "boolean");
156 check_equals
(typeof(ts
.getSelected
(-1, 3)), "boolean");
157 check_equals
(typeof(ts
.getSelected
(1, 0)), "boolean");
158 check_equals
(typeof(ts
.getSelected
(1, 0)), "boolean");
159 check_equals
(typeof(ts
.getSelected
(0, "a")), "boolean");
160 check_equals
(typeof(ts
.getSelected
("b", 0)), "boolean");
161 check_equals
(typeof(ts
.getSelected
(true, false)), "boolean");
162 check_equals
(typeof(ts
.getSelected
(0, 10, 10)), "undefined");
163 check_equals
(typeof(ts
.getSelected
(0, 10, true)), "undefined");
164 check_equals
(typeof(ts
.getSelected
(0, 10, "a")), "undefined");
166 check_equals
(typeof(ts
.getSelectedText
()), "string");
167 check_equals
(typeof(ts
.getSelectedText
(0)), "string");
168 check_equals
(typeof(ts
.getSelectedText
("a")), "string");
169 check_equals
(typeof(ts
.getSelectedText
(new Date())), "string");
170 check_equals
(typeof(ts
.getSelectedText
([0, 2])), "string");
171 check_equals
(typeof(ts
.getSelectedText
(0, 1)), "undefined");
172 check_equals
(typeof(ts
.getSelectedText
(1, 0)), "undefined");
173 check_equals
(typeof(ts
.getSelectedText
(-1, 3)), "undefined");
174 check_equals
(typeof(ts
.getSelectedText
(1, 0)), "undefined");
175 check_equals
(typeof(ts
.getSelectedText
(1, 0)), "undefined");
176 check_equals
(typeof(ts
.getSelectedText
(0, "a")), "undefined");
177 check_equals
(typeof(ts
.getSelectedText
("b", 0)), "undefined");
178 check_equals
(typeof(ts
.getSelectedText
(true, false)), "undefined");
179 check_equals
(typeof(ts
.getSelectedText
(0, 10, 10)), "undefined");
180 check_equals
(typeof(ts
.getSelectedText
(0, 10, true)), "undefined");
181 check_equals
(typeof(ts
.getSelectedText
(0, 10, "a")), "undefined");
183 check_equals
(typeof(ts
.getText
()), "undefined");
184 check_equals
(typeof(ts
.getText
(0)), "undefined");
185 check_equals
(typeof(ts
.getText
("a")), "undefined");
186 check_equals
(typeof(ts
.getText
(new Date())), "undefined");
187 check_equals
(typeof(ts
.getText
(0, 1)), "string");
188 check_equals
(typeof(ts
.getText
(1, 0)), "string");
189 check_equals
(typeof(ts
.getText
(-1, 3)), "string");
190 check_equals
(typeof(ts
.getText
(1, 0)), "string");
191 check_equals
(typeof(ts
.getText
(1, 0)), "string");
192 check_equals
(typeof(ts
.getText
(0, "a")), "string");
193 check_equals
(typeof(ts
.getText
("b", 0)), "string");
194 check_equals
(typeof(ts
.getText
(true, false)), "string");
195 check_equals
(typeof(ts
.getText
(0, 10, 10)), "string");
196 check_equals
(typeof(ts
.getText
(0, 10, true)), "string");
197 check_equals
(typeof(ts
.getText
(0, 10, "a", 11)), "undefined");
198 check_equals
(typeof(ts
.getText
(0, 10, 10, "hello")), "undefined");
199 check_equals
(typeof(ts
.getText
(0, 10, true, [3, 4])), "undefined");
201 // setSelectColor(). Returns void
202 check_equals
(typeof(ts
.setSelectColor
()), "undefined");
203 check_equals
(typeof(ts
.setSelectColor
(0)), "undefined");
204 check_equals
(typeof(ts
.setSelectColor
(0, 4)), "undefined");
205 check_equals
(typeof(ts
.setSelectColor
(0, 5, 6)), "undefined");
206 check_equals
(typeof(ts
.setSelectColor
(0, 5, true)), "undefined");
207 check_equals
(typeof(ts
.setSelectColor
(0, 5, 8, 5)), "undefined");
209 // hitTestTextNearPos()
210 check_equals
(typeof(ts
.hitTestTextNearPos
()), "undefined");
211 check_equals
(typeof(ts
.hitTestTextNearPos
(0)), "undefined");
212 check_equals
(typeof(ts
.hitTestTextNearPos
("a")), "undefined");
213 check_equals
(typeof(ts
.hitTestTextNearPos
(new Date())), "undefined");
214 xcheck_equals
(typeof(ts
.hitTestTextNearPos
(0, 1)), "number");
215 xcheck_equals
(typeof(ts
.hitTestTextNearPos
(1, 0)), "number");
216 xcheck_equals
(typeof(ts
.hitTestTextNearPos
(-1, 3)), "number");
217 xcheck_equals
(typeof(ts
.hitTestTextNearPos
(1, 0)), "number");
218 xcheck_equals
(typeof(ts
.hitTestTextNearPos
(1, 0)), "number");
219 xcheck_equals
(typeof(ts
.hitTestTextNearPos
(0, "a")), "number");
220 xcheck_equals
(typeof(ts
.hitTestTextNearPos
("b", 0)), "number");
221 xcheck_equals
(typeof(ts
.hitTestTextNearPos
(true, false)), "number");
222 xcheck_equals
(typeof(ts
.hitTestTextNearPos
(0, 10, 10)), "number");
223 xcheck_equals
(typeof(ts
.hitTestTextNearPos
(0, 10, true)), "number");
224 check_equals
(typeof(ts
.hitTestTextNearPos
(0, 10, "a", 11)), "undefined");
225 check_equals
(typeof(ts
.hitTestTextNearPos
(0, 10, 10, "hello")), "undefined");
226 check_equals
(typeof(ts
.hitTestTextNearPos
(0, 10, true, [3, 4])), "undefined");
228 // setSelected() // Three arguments, returns void.
229 check_equals
(typeof(ts
.setSelected
()), "undefined");
230 check_equals
(typeof(ts
.setSelected
(0)), "undefined");
231 check_equals
(typeof(ts
.setSelected
("a")), "undefined");
232 check_equals
(typeof(ts
.setSelected
(new Date())), "undefined");
233 check_equals
(typeof(ts
.setSelected
(0, 1)), "undefined");
234 check_equals
(typeof(ts
.setSelected
(1, 0)), "undefined");
235 check_equals
(typeof(ts
.setSelected
(-1, 3)), "undefined");
236 check_equals
(typeof(ts
.setSelected
(1, 0)), "undefined");
237 check_equals
(typeof(ts
.setSelected
(1, 0)), "undefined");
238 check_equals
(typeof(ts
.setSelected
(0, "a")), "undefined");
239 check_equals
(typeof(ts
.setSelected
("b", 0)), "undefined");
240 check_equals
(typeof(ts
.setSelected
(true, false)), "undefined");
241 check_equals
(typeof(ts
.setSelected
(0, 10, 10)), "undefined");
242 check_equals
(typeof(ts
.setSelected
(0, 10, true)), "undefined");
243 check_equals
(typeof(ts
.setSelected
(0, 10, "a", 11)), "undefined");
244 check_equals
(typeof(ts
.setSelected
(0, 10, 10, "hello")), "undefined");
245 check_equals
(typeof(ts
.setSelected
(0, 10, true, [3, 4])), "undefined");
249 #endif
// OUTPUT_VERSION > 5