source: trunk/icedtea-web/tests/netx/pac/pac-funcs-test.js

Last change on this file was 418, checked in by dmik, 13 years ago

Merge icedtea-web v1.3 to trunk.

File size: 23.5 KB
Line 
1
2var ICEDTEA_CLASSPATH_ORG_IP = "208.78.240.231";
3var CLASSPATH_ORG_IP = "199.232.41.10";
4
5var testsFailed = 0;
6var testsPassed = 0;
7
8print("loading needed files\n");
9file = arguments[0] + "";
10load(file)
11print("finished loaded needed files\n");
12
13
14function main() {
15
16 testIsPlainHostName();
17 testDnsDomainIs();
18 testLocalHostOrDomainIs();
19 testIsResolvable();
20 testIsInNet();
21 testDnsResolve();
22 testDnsDomainLevels();
23 testShExpMatch();
24 testDateRange();
25 testTimeRange();
26 testWeekdayRange();
27 testDateRange2();
28 testDateRange3();
29
30 java.lang.System.out.println("Test results: passed: " + testsPassed + "; failed: " + testsFailed + ";");
31}
32
33function runTests(name, tests) {
34 var undefined_var;
35 for ( var i = 0; i < tests.length; i++) {
36 runTest(name, tests[i]);
37 }
38}
39
40function runTest(name, test) {
41 var expectedVal = test[0];
42 var args = test.slice(1);
43 var returnVal;
44 try {
45 returnVal = name.apply(null, args);
46 } catch (e) {
47 returnVal = e;
48 }
49 if (returnVal === expectedVal) {
50 java.lang.System.out.println("Passed: " + name.name + "(" + args.join(", ") + ")");
51 testsPassed++;
52 } else {
53 java.lang.System.out.println("FAILED: " + name.name + "(" + args.join(", ") + ")");
54 java.lang.System.out.println(" Expected '" + expectedVal + "' but got '" + returnVal + "'");
55 testsFailed++;
56 }
57}
58
59
60function testIsPlainHostName() {
61 var tests = [
62 [ false, "icedtea.classpath.org" ],
63 [ false, "classpath.org" ],
64 [ true, "org" ],
65 [ true, "icedtea" ],
66 [ false, ".icedtea.classpath.org" ],
67 [ false, "icedtea." ],
68 [ false, "icedtea.classpath." ]
69 ];
70
71 runTests(isPlainHostName, tests);
72}
73
74function testDnsDomainIs() {
75 var tests = [
76 [ true, "icedtea.classpath.org", "icedtea.classpath.org" ],
77 [ true, "icedtea.classpath.org", ".classpath.org" ],
78 [ true, "icedtea.classpath.org", ".org" ],
79 [ false, "icedtea.classpath.org", "icedtea.classpath.com" ],
80 [ false, "icedtea.classpath.org", "icedtea.classpath" ],
81 [ false, "icedtea.classpath", "icedtea.classpath.org" ],
82 [ false, "icedtea", "icedtea.classpath.org" ]
83 ];
84
85 runTests(dnsDomainIs, tests);
86}
87
88function testLocalHostOrDomainIs() {
89
90 var tests = [
91 [ true, "icedtea.classpath.org", "icedtea.classpath.org" ],
92 [ true, "icedtea", "icedtea.classpath.org" ],
93 [ false, "icedtea.classpath.org", "icedtea.classpath.com" ],
94 [ false, "icedtea.classpath", "icedtea.classpath.org" ],
95 [ false, "foo.classpath.org", "icedtea.classpath.org" ],
96 [ false, "foo", "icedtea.classpath.org" ]
97 ];
98
99 runTests(localHostOrDomainIs, tests);
100}
101
102function testIsResolvable() {
103
104 var tests = [
105 [ true, "icedtea.classpath.org", "icedtea.classpath.org" ],
106 [ true, "classpath.org" ],
107 [ false, "NotIcedTeaHost" ],
108 [ false, "foobar.classpath.org" ],
109 [ false, "icedtea.classpath.com" ]
110 ];
111
112 runTests(isResolvable, tests);
113}
114
115function testIsInNet() {
116
117 var parts = ICEDTEA_CLASSPATH_ORG_IP.split("\.");
118
119 var fakeParts = ICEDTEA_CLASSPATH_ORG_IP.split("\.");
120 fakeParts[0] = fakeParts[0] + 1;
121
122 function createIp(array) {
123 return array[0] + "." + array[1] + "." + array[2] + "." + array[3];
124 }
125
126 var tests = [
127 [ true, "icedtea.classpath.org", ICEDTEA_CLASSPATH_ORG_IP, "255.255.255.255"],
128 [ true, "icedtea.classpath.org", ICEDTEA_CLASSPATH_ORG_IP, "255.255.255.0"],
129 [ true, "icedtea.classpath.org", ICEDTEA_CLASSPATH_ORG_IP, "255.255.0.0"],
130 [ true, "icedtea.classpath.org", ICEDTEA_CLASSPATH_ORG_IP, "255.0.0.0"],
131 [ true, "icedtea.classpath.org", ICEDTEA_CLASSPATH_ORG_IP, "0.0.0.0"],
132 [ true, "icedtea.classpath.org", ICEDTEA_CLASSPATH_ORG_IP, "255.255.255.255"],
133 [ true, "icedtea.classpath.org", ICEDTEA_CLASSPATH_ORG_IP, "0.0.0.0"],
134 [ true, "icedtea.classpath.org", createIp(parts), "255.255.255.255" ],
135 [ false, "icedtea.classpath.org", createIp(fakeParts), "255.255.255.255"],
136 [ false, "icedtea.classpath.org", createIp(fakeParts), "255.255.255.0"],
137 [ false, "icedtea.classpath.org", createIp(fakeParts), "255.255.0.0"],
138 [ false, "icedtea.classpath.org", createIp(fakeParts), "255.0.0.0"],
139 [ true, "icedtea.classpath.org", createIp(fakeParts), "0.0.0.0"]
140 ];
141
142 runTests(isInNet, tests);
143}
144
145function testDnsResolve() {
146 var tests = [
147 [ ICEDTEA_CLASSPATH_ORG_IP, "icedtea.classpath.org" ],
148 //[ CLASSPATH_ORG_IP, "classpath.org" ],
149 [ "127.0.0.1", "localhost" ]
150 ];
151
152 runTests(dnsResolve, tests);
153}
154
155function testDnsDomainLevels() {
156 var tests = [
157 [ 0, "org" ],
158 [ 1, "classpath.org" ],
159 [ 2, "icedtea.classpath.org" ],
160 [ 3, "foo.icedtea.classpath.org" ]
161 ];
162
163 runTests(dnsDomainLevels, tests);
164
165}
166function testShExpMatch() {
167 var tests = [
168 [ true, "icedtea.classpath.org", "icedtea.classpath.org"],
169 [ false, "icedtea.classpath.org", ".org"],
170 [ false, "icedtea.classpath.org", "icedtea."],
171 [ false, "icedtea", "icedtea.classpath.org"],
172
173 [ true, "icedtea.classpath.org", "*" ],
174 [ true, "icedtea.classpath.org", "*.classpath.org" ],
175 [ true, "http://icedtea.classpath.org", "*.classpath.org" ],
176 [ true, "http://icedtea.classpath.org/foobar/", "*.classpath.org/*" ],
177 [ true, "http://icedtea.classpath.org/foobar/", "*/foobar/*" ],
178 [ true, "http://icedtea.classpath.org/foobar/", "*foobar*" ],
179 [ true, "http://icedtea.classpath.org/foobar/", "*foo*" ],
180 [ false, "http://icedtea.classpath.org/foobar/", "*/foo/*" ],
181 [ false, "http://icedtea.classpath.org/foobar/", "*/foob/*" ],
182 [ false, "http://icedtea.classpath.org/foobar/", "*/fooba/*" ],
183 [ false, "http://icedtea.classpath.org/foo/", "*foobar*" ],
184
185 [ true, "1", "?" ],
186 [ true, "12", "??" ],
187 [ true, "123", "1?3" ],
188 [ true, "123", "?23" ],
189 [ true, "123", "12?" ],
190 [ true, "1234567890", "??????????" ],
191 [ false, "1234567890", "?????????" ],
192 [ false, "123", "1?1" ],
193 [ false, "123", "??" ],
194
195 [ true, "http://icedtea.classpath.org/f1/", "*/f?/*" ],
196 [ true, "http://icedtea1.classpath.org/f1/", "*icedtea?.classpath*/f?/*" ],
197 [ false, "http://icedtea.classpath.org/f1/", "*/f2/*" ],
198 [ true, "http://icedtea.classpath.org/f1/", "*/f?/*" ],
199 [ false, "http://icedtea.classpath.org/f1", "f?*"],
200 [ false, "http://icedtea.classpath.org/f1", "f?*"],
201 [ false, "http://icedtea.classpath.org/f1", "f?*"],
202
203 [ true, "http://icedtea.classpath.org/foobar/", "*.classpath.org/*" ],
204 [ true, "http://icedtea.classpath.org/foobar/", "*.classpath.org/*" ],
205 [ true, "http://icedtea.classpath.org/foobar/", "*.classpath.org/*" ],
206
207 [ true, "http://icedtea.classpath.org/foo.php?id=bah", "*foo.php*" ],
208 [ false, "http://icedtea.classpath.org/foo_php?id=bah", "*foo.php*" ]
209 ];
210
211 runTests(shExpMatch, tests);
212}
213
214function testWeekdayRange() {
215
216 var today = new Date();
217 var day = today.getDay();
218
219 function dayToStr(day) {
220 switch (day) {
221 case -2: return "FRI";
222 case -1: return "SAT";
223 case 0: return "SUN";
224 case 1: return "MON";
225 case 2: return "TUE";
226 case 3: return "WED";
227 case 4: return "THU";
228 case 5: return "FRI";
229 case 6: return "SAT";
230 case 7: return "SUN";
231 case 8: return "MON";
232 default: return "FRI";
233 }
234
235 }
236
237 var tests = [
238 [ true, dayToStr(day) ],
239 [ false, dayToStr(day+1) ],
240 [ false, dayToStr(day-1) ],
241 ];
242
243 runTests(weekdayRange, tests);
244}
245
246/** Returns an array: [day, month, year] */
247function incDate() {
248 if ((arguments.length >= 3) && (arguments.length % 2 === 1)) {
249 var date = arguments[0];
250 var result = date;
251 var index = 1;
252 while (index < arguments.length) {
253 var whichThing = arguments[index];
254 var by = arguments[index+1];
255 switch (whichThing) {
256 case 'year':
257 result = new Date(result.getFullYear()+by, result.getMonth(), result.getDate());
258 break;
259 case 'month':
260 result = new Date(result.getFullYear(), result.getMonth()+by, result.getDate());
261 break;
262 case 'day':
263 result = new Date(result.getFullYear(), result.getMonth(), result.getDate()+by);
264 break;
265 }
266 index += 2;
267 }
268 return [result.getDate(), result.getMonth(), result.getFullYear()];
269 }
270 throw "Please call incDate properly";
271}
272
273function monthToStr(month) {
274 switch (month) {
275 case -1: return "DEC";
276 case 0: return "JAN";
277 case 1: return "FEB";
278 case 2: return "MAR";
279 case 3: return "APR";
280 case 4: return "MAY";
281 case 5: return "JUN";
282 case 6: return "JUL";
283 case 7: return "AUG";
284 case 8: return "SEP";
285 case 9: return "OCT";
286 case 10: return "NOV";
287 case 11: return "DEC";
288 case 12: return "JAN";
289 default: throw "Invalid Month" + month;
290 }
291}
292
293function testDateRange() {
294
295 {
296 var current = new Date();
297 var date = current.getDate();
298 var month = current.getMonth();
299 var year = current.getFullYear();
300
301 var today = incDate(current, 'day', 0);
302 var tomorrow = incDate(current, 'day', 1);
303 var yesterday = incDate(current, 'day', -1);
304
305 runTest(dateRange, [ true, date ]);
306 runTest(dateRange, [ false, tomorrow[0] ]);
307 runTest(dateRange, [ false, yesterday[0] ]);
308
309 runTest(dateRange, [ true, monthToStr(month) ]);
310 runTest(dateRange, [ false, monthToStr(month+1) ]);
311 runTest(dateRange, [ false, monthToStr(month-1) ]);
312
313 runTest(dateRange, [ true, year ]);
314 runTest(dateRange, [ false, year - 1]);
315 runTest(dateRange, [ false, year + 1]);
316
317 runTest(dateRange, [ true, date, date ]);
318 runTest(dateRange, [ true, today[0], tomorrow[0] ]);
319 runTest(dateRange, [ true, yesterday[0], today[0] ]);
320 runTest(dateRange, [ true, yesterday[0], tomorrow[0] ]);
321 runTest(dateRange, [ false, tomorrow[0], yesterday[0] ]);
322 runTest(dateRange, [ false, incDate(current,'day',-2)[0], yesterday[0] ]);
323 runTest(dateRange, [ false, tomorrow[0], incDate(current,'day',2)[0] ]);
324
325 runTest(dateRange, [ true, monthToStr(month), monthToStr(month) ]);
326 runTest(dateRange, [ true, monthToStr(month), monthToStr(month+1) ]);
327 runTest(dateRange, [ true, monthToStr(month-1), monthToStr(month) ]);
328 runTest(dateRange, [ true, monthToStr(month-1), monthToStr(month+1) ]);
329 runTest(dateRange, [ true, "JAN", "DEC" ]);
330 runTest(dateRange, [ true, "FEB", "JAN" ]);
331 runTest(dateRange, [ true, "DEC", "NOV" ]);
332 runTest(dateRange, [ true, "JUL", "JUN"]);
333 runTest(dateRange, [ false, monthToStr(month+1), monthToStr(month+1) ]);
334 runTest(dateRange, [ false, monthToStr(month-1), monthToStr(month-1) ]);
335 runTest(dateRange, [ false, monthToStr(month+1), monthToStr(month-1) ]);
336
337 runTest(dateRange, [ true, year, year ]);
338 runTest(dateRange, [ true, year, year+1 ]);
339 runTest(dateRange, [ true, year-1, year ]);
340 runTest(dateRange, [ true, year-1, year+1 ]);
341 runTest(dateRange, [ false, year-2, year-1 ]);
342 runTest(dateRange, [ false, year+1, year+1 ]);
343 runTest(dateRange, [ false, year+1, year+2 ]);
344 runTest(dateRange, [ false, year+1, year-1 ]);
345
346 runTest(dateRange, [ true, date, monthToStr(month) , date, monthToStr(month) ]);
347 runTest(dateRange, [ true, yesterday[0], monthToStr(yesterday[1]) , date, monthToStr(month) ]);
348 runTest(dateRange, [ false, yesterday[0], monthToStr(yesterday[1]) , yesterday[0], monthToStr(yesterday[1]) ]);
349 runTest(dateRange, [ true, date, monthToStr(month) , tomorrow[0], monthToStr(tomorrow[1]) ]);
350 runTest(dateRange, [ false, tomorrow[0], monthToStr(tomorrow[1]) , tomorrow[0], monthToStr(tomorrow[1]) ]);
351 runTest(dateRange, [ true, yesterday[0], monthToStr(yesterday[1]) , tomorrow[0], monthToStr(tomorrow[1]) ]);
352 runTest(dateRange, [ false, tomorrow[0], monthToStr(tomorrow[1]) , yesterday[0], monthToStr(yesterday[1]) ]);
353 }
354
355 {
356 var lastMonth = incDate(new Date(), 'month', -1);
357 var thisMonth = incDate(new Date(), 'month', 0);
358 var nextMonth = incDate(new Date(), 'month', +1);
359 runTest(dateRange, [ true, lastMonth[0], monthToStr(lastMonth[1]) , thisMonth[0], monthToStr(thisMonth[1]) ]);
360 runTest(dateRange, [ true, thisMonth[0], monthToStr(thisMonth[1]) , nextMonth[0], monthToStr(nextMonth[1]) ]);
361 runTest(dateRange, [ true, lastMonth[0], monthToStr(lastMonth[1]) , nextMonth[0], monthToStr(nextMonth[1]) ]);
362 var date1 = incDate(new Date(), 'day', +1, 'month', -1);
363 var date2 = incDate(new Date(), 'day', -1, 'month', +1);
364 runTest(dateRange, [ true, date1[0], monthToStr(date1[1]) , nextMonth[0], monthToStr(nextMonth[1]) ]);
365 runTest(dateRange, [ true, lastMonth[0], monthToStr(lastMonth[1]) , date2[0], monthToStr(date2[1]) ]);
366 runTest(dateRange, [ false, nextMonth[0], monthToStr(nextMonth[1]) , lastMonth[0], monthToStr(lastMonth[1]) ]);
367 var date3 = incDate(new Date(), 'day', +1, 'month', +1);
368 var date4 = incDate(new Date(), 'day', +1, 'month', -1);
369 runTest(dateRange, [ false, date3[0], monthToStr(date3[1]) , date4[0], monthToStr(date4[1]) ]);
370
371 var date5 = incDate(new Date(), 'day', -1, 'month', -1);
372 runTest(dateRange, [ false, date2[0], monthToStr(date2[1]) , date5[0], monthToStr(date5[1]) ]);
373
374 runTest(dateRange, [ true, 1, "JAN", 31, "DEC" ]);
375 runTest(dateRange, [ true, 2, "JAN", 1, "JAN" ]);
376
377 var month = new Date().getMonth();
378 runTest(dateRange, [ false, 1, monthToStr(month+1), 31, monthToStr(month+1) ]);
379 runTest(dateRange, [ false, 1, monthToStr(month-1), 31, monthToStr(month-1) ]);
380 }
381
382
383 {
384 var lastMonth = incDate(new Date(), 'month', -1);
385 var thisMonth = incDate(new Date(), 'month', 0);
386 var nextMonth = incDate(new Date(), 'month', +1);
387 runTest(dateRange, [ true, monthToStr(thisMonth[1]), thisMonth[2], monthToStr(thisMonth[1]), thisMonth[2] ]);
388 runTest(dateRange, [ true, monthToStr(lastMonth[1]), lastMonth[2], monthToStr(thisMonth[1]), thisMonth[2] ]);
389 runTest(dateRange, [ true, monthToStr(thisMonth[1]), thisMonth[2], monthToStr(nextMonth[1]), nextMonth[2] ]);
390 runTest(dateRange, [ true, monthToStr(lastMonth[1]), lastMonth[2], monthToStr(nextMonth[1]), nextMonth[2] ]);
391 runTest(dateRange, [ true, monthToStr(0), year, monthToStr(11), year ]);
392
393 runTest(dateRange, [ false, monthToStr(nextMonth[1]), nextMonth[2], monthToStr(lastMonth[1]), lastMonth[2] ]);
394 runTest(dateRange, [ false, monthToStr(nextMonth[1]), nextMonth[2], monthToStr(nextMonth[1]), nextMonth[2] ]);
395 runTest(dateRange, [ false, monthToStr(lastMonth[1]), lastMonth[2], monthToStr(lastMonth[1]), lastMonth[2] ]);
396
397 var lastYear = incDate(new Date(), 'year', -1);
398 var nextYear = incDate(new Date(), 'year', +1);
399
400 runTest(dateRange, [ false, monthToStr(lastYear[1]), lastYear[2], monthToStr(lastMonth[1]), lastMonth[2] ]);
401 runTest(dateRange, [ true, monthToStr(thisMonth[1]), thisMonth[2], monthToStr(nextYear[1]), nextYear[2] ]);
402
403 var year = new Date().getFullYear();
404 var month = new Date().getMonth();
405
406 runTest(dateRange, [ true, monthToStr(month), year-1, monthToStr(month), year ]);
407 runTest(dateRange, [ true, monthToStr(month), year-1, monthToStr(month), year+1 ]);
408 runTest(dateRange, [ true, monthToStr(0), year, monthToStr(0), year+1 ]);
409 runTest(dateRange, [ true, monthToStr(0), year-1, monthToStr(0), year+1 ]);
410 runTest(dateRange, [ false, monthToStr(0), year-1, monthToStr(11), year-1 ]);
411 runTest(dateRange, [ false, monthToStr(0), year+1, monthToStr(11), year+1 ]);
412 }
413
414 {
415 var today = incDate(new Date(), 'day', 0);
416 var yesterday = incDate(new Date(), 'day', -1);
417 var tomorrow = incDate(new Date(), 'day', +1);
418 runTest(dateRange, [ true,
419 today[0], monthToStr(today[1]), today[2], today[0], monthToStr(today[1]), today[2] ]);
420 runTest(dateRange, [ true,
421 yesterday[0], monthToStr(yesterday[1]), yesterday[2], tomorrow[0], monthToStr(tomorrow[1]), tomorrow[2] ]);
422 }
423
424 {
425 var dayLastMonth = incDate(new Date(), 'day', -1, 'month', -1);
426 var dayNextMonth = incDate(new Date(), 'day', +1, 'month', +1);
427 runTest(dateRange, [ true,
428 dayLastMonth[0], monthToStr(dayLastMonth[1]), dayLastMonth[2], dayNextMonth[0], monthToStr(dayNextMonth[1]), dayNextMonth[2] ]);
429 }
430
431 {
432 var dayLastYear = incDate(new Date(), 'day', -1, 'month', -1, 'year', -1);
433 var dayNextYear = incDate(new Date(), 'day', +1, 'month', +1, 'year', +1);
434 runTest(dateRange, [ true,
435 dayLastYear[0], monthToStr(dayLastYear[1]), dayLastYear[2], dayNextYear[0], monthToStr(dayNextYear[1]), dayNextYear[2] ]);
436 }
437
438 {
439 var dayLastYear = incDate(new Date(), 'day', +1, 'month', -1, 'year', -1);
440 var dayNextYear = incDate(new Date(), 'day', +1, 'month', +1, 'year', +1);
441 runTest(dateRange, [ true,
442 dayLastYear[0], monthToStr(dayLastYear[1]), dayLastYear[2], dayNextYear[0], monthToStr(dayNextYear[1]), dayNextYear[2] ]);
443 }
444
445 {
446 var tomorrow = incDate(new Date(), 'day', +1);
447 var dayNextYear = incDate(new Date(), 'day', +1, 'month', +1, 'year', +1);
448 runTest(dateRange, [ false,
449 tomorrow[0], monthToStr(tomorrow[1]), tomorrow[2], dayNextYear[0], monthToStr(dayNextYear[1]), dayNextYear[2] ]);
450
451 }
452
453 {
454 var nextMonth = incDate(new Date(), 'month', +1);
455 var nextYear = incDate(new Date(), 'day', +1, 'month', +1, 'year', +1);
456 runTest(dateRange, [ false,
457 nextMonth[0], monthToStr(nextMonth[1]), nextMonth[2], nextYear[0], monthToStr(nextYear[1]), nextYear[2] ]);
458 }
459
460 {
461 runTest(dateRange, [ true, 1, monthToStr(0), 0, 31, monthToStr(11), 100000 ]);
462 runTest(dateRange, [ true, 1, monthToStr(0), year, 31, monthToStr(11), year ]);
463 runTest(dateRange, [ true, 1, monthToStr(0), year-1, 31, monthToStr(11), year+1 ]);
464 runTest(dateRange, [ false, 1, monthToStr(0), year-1, 31, monthToStr(11), year-1 ]);
465 runTest(dateRange, [ false, 1, monthToStr(0), year+1, 31, monthToStr(11), year+1 ]);
466 }
467
468}
469
470function testDateRange2() {
471
472 var dates = [
473 new Date("January 31, 2011 3:33:33"),
474 new Date("February 28, 2011 3:33:33"),
475 new Date("February 29, 2012 3:33:33"),
476 new Date("March 31, 2011 3:33:33"),
477 new Date("April 30, 2011 3:33:33"),
478 new Date("May 31, 2011 3:33:33"),
479 new Date("June 30, 2011 3:33:33"),
480 new Date("July 31, 2011 3:33:33"),
481 new Date("August 31, 2011 3:33:33"),
482 new Date("September 30, 2011 3:33:33"),
483 new Date("October 31, 2011 3:33:33"),
484 new Date("November 30, 2011 3:33:33"),
485 new Date("December 31, 2011 3:33:33"),
486]
487 for (var i = 0; i < dates.length; i++) {
488 var current = dates[i];
489 var today = incDate(current, 'day', 0);
490 var yesterday = incDate(current, 'day', -1);
491 var tomorrow = incDate(current, 'day', 1);
492 var aYearFromNow = new Date(current.getFullYear()+1, current.getMonth()+1, current.getDate()+1);
493 var later = [aYearFromNow.getDate(), aYearFromNow.getMonth(), aYearFromNow.getFullYear()];
494
495 runTest(isDateInRange_internallForIcedTeaWebTesting, [ true, current,
496 today[0], monthToStr(today[1]) , tomorrow[0], monthToStr(tomorrow[1]) ]);
497 runTest(isDateInRange_internallForIcedTeaWebTesting, [ true, current,
498 yesterday[0], monthToStr(yesterday[1]) , tomorrow[0], monthToStr(tomorrow[1]) ]);
499 runTest(isDateInRange_internallForIcedTeaWebTesting, [ true, current,
500 yesterday[0], monthToStr(yesterday[1]), yesterday[2], tomorrow[0], monthToStr(tomorrow[1]), tomorrow[2] ]);
501 runTest(isDateInRange_internallForIcedTeaWebTesting, [ false, current,
502 tomorrow[0], monthToStr(tomorrow[1]), tomorrow[2], later[0], monthToStr(later[1]), later[2] ]);
503 }
504
505}
506
507function testDateRange3() {
508 var dates = [
509 new Date("January 1, 2011 1:11:11"),
510 new Date("February 1, 2011 1:11:11"),
511 new Date("March 1, 2011 1:11:11"),
512 new Date("April 1, 2011 1:11:11"),
513 new Date("May 1, 2011 1:11:11"),
514 new Date("June 1, 2011 1:11:11"),
515 new Date("July 1, 2011 1:11:11"),
516 new Date("August 1, 2011 1:11:11"),
517 new Date("September 1, 2011 1:11:11"),
518 new Date("October 1, 2011 1:11:11"),
519 new Date("November 1, 2011 1:11:11"),
520 new Date("December 1, 2011 1:11:11"),
521
522 ]
523
524
525
526 for (var i = 0; i < dates.length; i++) {
527 var current = dates[i];
528 var yesterday = incDate(current,'day',-1);
529 var today = incDate(current,'day',0);
530 var tomorrow = incDate(current,'day',1);
531 runTest(isDateInRange_internallForIcedTeaWebTesting, [ true, current,
532 yesterday[0], monthToStr(yesterday[1]) , today[0], monthToStr(today[1]) ]);
533 runTest(isDateInRange_internallForIcedTeaWebTesting, [ true, current,
534 yesterday[0], monthToStr(yesterday[1]) , tomorrow[0], monthToStr(tomorrow[1]) ]);
535 runTest(isDateInRange_internallForIcedTeaWebTesting, [ true, current,
536 yesterday[0], monthToStr(yesterday[1]), yesterday[2], tomorrow[0], monthToStr(tomorrow[1]), tomorrow[2] ]);
537 }
538}
539
540function testTimeRange() {
541 var now = new Date();
542
543 var hour = now.getHours();
544 var min = now.getMinutes();
545 var sec = now.getSeconds();
546
547 function toHour(input) {
548 if (input < 0) {
549 while (input < 0) {
550 input = input + 24;
551 }
552 return (input % 24);
553 } else {
554 return (input % 24);
555 }
556 }
557
558 function toMin(input) {
559 if (input < 0) {
560 while (input < 0) {
561 input = input + 60;
562 }
563 return (input % 60);
564 } else {
565 return (input % 60);
566 }
567 }
568
569 tests = [
570 [ true, hour ],
571 [ false, toHour(hour+1)],
572 [ false, toHour(hour-1)],
573
574 [ true, hour, hour ],
575 [ true, toHour(hour-1), hour ],
576 [ true, hour, toHour(hour+1)],
577 [ true, toHour(hour-1), toHour(hour+1)],
578 [ true, toHour(hour+1), hour ],
579 [ true, hour, toHour(hour-1) ],
580 [ false, toHour(hour-2), toHour(hour-1)],
581 [ false, toHour(hour+1), toHour(hour+2)],
582 [ false, toHour(hour+1), toHour(hour-1) ],
583 [ true, 0, 23 ],
584 [ true, 12, 11 ],
585
586 [ true, hour, min, hour, min ],
587 [ true, hour, min, hour, toMin(min+1) ],
588 [ true, hour, toMin(min-1), hour, min ],
589 [ true, hour, toMin(min-1), hour, toMin(min+1) ],
590 [ true, hour, toMin(min+2), hour, toMin(min+1) ],
591 [ false, hour, toMin(min+1), hour, toMin(min+1) ],
592 [ false, hour, toMin(min-1), hour, toMin(min-1) ],
593 [ false, hour, toMin(min+1), hour, toMin(min-1) ],
594 [ true, toHour(hour-1), min, hour, min ],
595 [ true, hour, min, toHour(hour+1), min ],
596 [ true, toHour(hour-1), min, toHour(hour+1), min ],
597 [ true, 0, 0, 23, 59 ],
598 [ true, 0, 1, 0, 0 ],
599
600 [ true, 0, 1, 0, 0, 0, 0 ],
601 [ true, hour, min, sec, hour, min, sec ],
602 [ true, hour, min, sec, hour, min + 10, sec ],
603 [ true, hour, min, sec - 10, hour, min, sec ],
604 [ true, hour, min, sec, hour, min-1 , sec ],
605
606 ];
607
608 runTests(timeRange, tests);
609}
610
611main();
Note: See TracBrowser for help on using the repository browser.