aboutsummaryrefslogtreecommitdiffstats
path: root/tests/netx/pac/pac-funcs-test.js
blob: 8a459529de803c5f9dbd5c4c29252b3498794287 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611

var ICEDTEA_CLASSPATH_ORG_IP = "208.78.240.231";
var CLASSPATH_ORG_IP = "199.232.41.10";

var testsFailed = 0;
var testsPassed = 0;

print("loading needed files\n");
file = arguments[0] + "";
load(file)
print("finished loaded needed files\n");


function main() {

	testIsPlainHostName();
	testDnsDomainIs();
	testLocalHostOrDomainIs();
	testIsResolvable();
	testIsInNet();
	testDnsResolve();
	testDnsDomainLevels();
	testShExpMatch();
	testDateRange();
	testTimeRange();
	testWeekdayRange();
	testDateRange2();
	testDateRange3();

	java.lang.System.out.println("Test results: passed: " + testsPassed + "; failed: " + testsFailed + ";");
}

function runTests(name, tests) {
	var undefined_var;
	for ( var i = 0; i < tests.length; i++) {
		runTest(name, tests[i]);
	}
}

function runTest(name, test) {
    var expectedVal = test[0];
    var args = test.slice(1);
    var returnVal;
    try {
        returnVal = name.apply(null, args);
    } catch (e) {
        returnVal = e;
    }
    if (returnVal === expectedVal) {
        java.lang.System.out.println("Passed: " + name.name + "(" + args.join(", ") + ")");
        testsPassed++;
    } else {
        java.lang.System.out.println("FAILED: " + name.name + "(" + args.join(", ") + ")");
        java.lang.System.out.println("        Expected '" + expectedVal + "' but got '" + returnVal + "'");
        testsFailed++;
    }
}


function testIsPlainHostName() {
    var tests = [
        [ false, "icedtea.classpath.org" ],
        [ false, "classpath.org" ],
        [ true, "org" ],
        [ true, "icedtea" ],
        [ false, ".icedtea.classpath.org" ],
        [ false, "icedtea." ],
        [ false, "icedtea.classpath." ]
    ];

    runTests(isPlainHostName, tests);
}

function testDnsDomainIs() {
    var tests = [
        [ true, "icedtea.classpath.org", "icedtea.classpath.org" ],
        [ true, "icedtea.classpath.org", ".classpath.org" ],
        [ true, "icedtea.classpath.org", ".org" ],
        [ false, "icedtea.classpath.org", "icedtea.classpath.com" ],
        [ false, "icedtea.classpath.org", "icedtea.classpath" ],
        [ false, "icedtea.classpath", "icedtea.classpath.org" ],
        [ false, "icedtea", "icedtea.classpath.org" ]
    ];

    runTests(dnsDomainIs, tests);
}

function testLocalHostOrDomainIs() {

    var tests = [
        [ true, "icedtea.classpath.org", "icedtea.classpath.org" ],
        [ true, "icedtea", "icedtea.classpath.org" ],
        [ false, "icedtea.classpath.org", "icedtea.classpath.com" ],
        [ false, "icedtea.classpath", "icedtea.classpath.org" ],
        [ false, "foo.classpath.org", "icedtea.classpath.org" ],
        [ false, "foo", "icedtea.classpath.org" ]
    ];

    runTests(localHostOrDomainIs, tests);
}

function testIsResolvable() {

    var tests = [
        [ true, "icedtea.classpath.org", "icedtea.classpath.org" ],
        [ true, "classpath.org" ],
        [ false, "NotIcedTeaHost" ],
        [ false, "foobar.classpath.org" ],
        [ false, "icedtea.classpath.com" ]
    ];

    runTests(isResolvable, tests);
}

function testIsInNet() {

	var parts = ICEDTEA_CLASSPATH_ORG_IP.split("\.");

	var fakeParts = ICEDTEA_CLASSPATH_ORG_IP.split("\.");
	fakeParts[0] = fakeParts[0] + 1;

	function createIp(array) {
		return array[0] + "." + array[1] + "." + array[2] + "." + array[3];
	}

	var tests = [
	    [ true, "icedtea.classpath.org", ICEDTEA_CLASSPATH_ORG_IP, "255.255.255.255"],
	    [ true, "icedtea.classpath.org", ICEDTEA_CLASSPATH_ORG_IP, "255.255.255.0"],
	    [ true, "icedtea.classpath.org", ICEDTEA_CLASSPATH_ORG_IP, "255.255.0.0"],
	    [ true, "icedtea.classpath.org", ICEDTEA_CLASSPATH_ORG_IP, "255.0.0.0"],
	    [ true, "icedtea.classpath.org", ICEDTEA_CLASSPATH_ORG_IP, "0.0.0.0"],
	    [ true, "icedtea.classpath.org", ICEDTEA_CLASSPATH_ORG_IP, "255.255.255.255"],
	    [ true, "icedtea.classpath.org", ICEDTEA_CLASSPATH_ORG_IP, "0.0.0.0"],
	    [ true, "icedtea.classpath.org", createIp(parts), "255.255.255.255" ],
	    [ false, "icedtea.classpath.org", createIp(fakeParts), "255.255.255.255"],
	    [ false, "icedtea.classpath.org", createIp(fakeParts), "255.255.255.0"],
	    [ false, "icedtea.classpath.org", createIp(fakeParts), "255.255.0.0"],
	    [ false, "icedtea.classpath.org", createIp(fakeParts), "255.0.0.0"],
	    [ true, "icedtea.classpath.org", createIp(fakeParts), "0.0.0.0"]
	];

	runTests(isInNet, tests);
}

function testDnsResolve() {
    var tests = [
        [ ICEDTEA_CLASSPATH_ORG_IP, "icedtea.classpath.org" ],
        //[ CLASSPATH_ORG_IP, "classpath.org" ],
        [ "127.0.0.1", "localhost" ]
    ];

    runTests(dnsResolve, tests);
}

function testDnsDomainLevels() {
    var tests = [
        [ 0, "org" ],
        [ 1, "classpath.org" ],
        [ 2, "icedtea.classpath.org" ],
        [ 3, "foo.icedtea.classpath.org" ]
    ];

    runTests(dnsDomainLevels, tests);

}
function testShExpMatch() {
    var tests = [
         [ true, "icedtea.classpath.org", "icedtea.classpath.org"],
         [ false, "icedtea.classpath.org", ".org"],
         [ false, "icedtea.classpath.org", "icedtea."],
         [ false, "icedtea", "icedtea.classpath.org"],

         [ true, "icedtea.classpath.org", "*" ],
         [ true, "icedtea.classpath.org", "*.classpath.org" ],
         [ true, "http://icedtea.classpath.org", "*.classpath.org" ],
         [ true, "http://icedtea.classpath.org/foobar/", "*.classpath.org/*" ],
         [ true, "http://icedtea.classpath.org/foobar/", "*/foobar/*" ],
         [ true, "http://icedtea.classpath.org/foobar/", "*foobar*" ],
         [ true, "http://icedtea.classpath.org/foobar/", "*foo*" ],
         [ false, "http://icedtea.classpath.org/foobar/", "*/foo/*" ],
         [ false, "http://icedtea.classpath.org/foobar/", "*/foob/*" ],
         [ false, "http://icedtea.classpath.org/foobar/", "*/fooba/*" ],
         [ false, "http://icedtea.classpath.org/foo/", "*foobar*" ],

         [ true, "1", "?" ],
         [ true, "12", "??" ],
         [ true, "123", "1?3" ],
         [ true, "123", "?23" ],
         [ true, "123", "12?" ],
         [ true, "1234567890", "??????????" ],
         [ false, "1234567890", "?????????" ],
         [ false, "123", "1?1" ],
         [ false, "123", "??" ],

         [ true, "http://icedtea.classpath.org/f1/", "*/f?/*" ],
         [ true, "http://icedtea1.classpath.org/f1/", "*icedtea?.classpath*/f?/*" ],
         [ false, "http://icedtea.classpath.org/f1/", "*/f2/*" ],
         [ true, "http://icedtea.classpath.org/f1/", "*/f?/*" ],
         [ false, "http://icedtea.classpath.org/f1", "f?*"],
         [ false, "http://icedtea.classpath.org/f1", "f?*"],
         [ false, "http://icedtea.classpath.org/f1", "f?*"],

         [ true, "http://icedtea.classpath.org/foobar/", "*.classpath.org/*" ],
         [ true, "http://icedtea.classpath.org/foobar/", "*.classpath.org/*" ],
         [ true, "http://icedtea.classpath.org/foobar/", "*.classpath.org/*" ],

         [ true, "http://icedtea.classpath.org/foo.php?id=bah", "*foo.php*" ],
         [ false, "http://icedtea.classpath.org/foo_php?id=bah", "*foo.php*" ]
     ];

     runTests(shExpMatch, tests);
}

function testWeekdayRange() {

    var today = new Date();
    var day = today.getDay();

    function dayToStr(day) {
        switch (day) {
            case -2: return "FRI";
            case -1: return "SAT";
            case 0: return "SUN";
            case 1: return "MON";
            case 2: return "TUE";
            case 3: return "WED";
            case 4: return "THU";
            case 5: return "FRI";
            case 6: return "SAT";
            case 7: return "SUN";
            case 8: return "MON";
            default: return "FRI";
        }

    }

    var tests = [
       [ true, dayToStr(day) ],
       [ false, dayToStr(day+1) ],
       [ false, dayToStr(day-1) ],
    ];

    runTests(weekdayRange, tests);
}

/** Returns an array: [day, month, year] */
function incDate() {
    if ((arguments.length >= 3) && (arguments.length % 2 === 1)) {
        var date = arguments[0];
        var result = date;
        var index = 1;
        while (index < arguments.length) {
            var whichThing = arguments[index];
            var by = arguments[index+1];
            switch (whichThing) {
                case 'year':
                    result = new Date(result.getFullYear()+by, result.getMonth(), result.getDate());
                    break;
                case 'month':
                    result = new Date(result.getFullYear(), result.getMonth()+by, result.getDate());
                    break;
                case 'day':
                    result = new Date(result.getFullYear(), result.getMonth(), result.getDate()+by);
                    break;
            }
            index += 2;
        }
        return [result.getDate(), result.getMonth(), result.getFullYear()];
    }
    throw "Please call incDate properly";
}

function monthToStr(month) {
    switch (month) {
        case -1: return "DEC";
        case 0: return "JAN";
        case 1: return "FEB";
        case 2: return "MAR";
        case 3: return "APR";
        case 4: return "MAY";
        case 5: return "JUN";
        case 6: return "JUL";
        case 7: return "AUG";
        case 8: return "SEP";
        case 9: return "OCT";
        case 10: return "NOV";
        case 11: return "DEC";
        case 12: return "JAN";
        default: throw "Invalid Month" + month;
    }
}

function testDateRange() {

    {
        var current = new Date();
        var date = current.getDate();
        var month = current.getMonth();
        var year = current.getFullYear();

        var today = incDate(current, 'day', 0);
        var tomorrow = incDate(current, 'day', 1);
        var yesterday = incDate(current, 'day', -1);

        runTest(dateRange, [ true, date ]);
        runTest(dateRange, [ false, tomorrow[0] ]);
        runTest(dateRange, [ false, yesterday[0] ]);

        runTest(dateRange, [ true, monthToStr(month) ]);
        runTest(dateRange, [ false, monthToStr(month+1) ]);
        runTest(dateRange, [ false, monthToStr(month-1) ]);

        runTest(dateRange, [ true, year ]);
        runTest(dateRange, [ false, year - 1]);
        runTest(dateRange, [ false, year + 1]);

        runTest(dateRange, [ true, date, date ]);
        runTest(dateRange, [ true, today[0], tomorrow[0] ]);
        runTest(dateRange, [ true, yesterday[0], today[0] ]);
        runTest(dateRange, [ true, yesterday[0], tomorrow[0] ]);
        runTest(dateRange, [ false, tomorrow[0], yesterday[0] ]);
        runTest(dateRange, [ false, incDate(current,'day',-2)[0], yesterday[0] ]);
        runTest(dateRange, [ false, tomorrow[0], incDate(current,'day',2)[0] ]);

        runTest(dateRange, [ true, monthToStr(month), monthToStr(month) ]);
        runTest(dateRange, [ true, monthToStr(month), monthToStr(month+1) ]);
        runTest(dateRange, [ true, monthToStr(month-1), monthToStr(month) ]);
        runTest(dateRange, [ true, monthToStr(month-1), monthToStr(month+1) ]);
        runTest(dateRange, [ true, "JAN", "DEC" ]);
        runTest(dateRange, [ true, "FEB", "JAN" ]);
        runTest(dateRange, [ true, "DEC", "NOV" ]);
        runTest(dateRange, [ true, "JUL", "JUN"]);
        runTest(dateRange, [ false, monthToStr(month+1), monthToStr(month+1) ]);
        runTest(dateRange, [ false, monthToStr(month-1), monthToStr(month-1) ]);
        runTest(dateRange, [ false, monthToStr(month+1), monthToStr(month-1) ]);

        runTest(dateRange, [ true, year, year ]);
        runTest(dateRange, [ true, year, year+1 ]);
        runTest(dateRange, [ true, year-1, year ]);
        runTest(dateRange, [ true, year-1, year+1 ]);
        runTest(dateRange, [ false, year-2, year-1 ]);
        runTest(dateRange, [ false, year+1, year+1 ]);
        runTest(dateRange, [ false, year+1, year+2 ]);
        runTest(dateRange, [ false, year+1, year-1 ]);

        runTest(dateRange, [ true, date, monthToStr(month) , date, monthToStr(month) ]);
        runTest(dateRange, [ true, yesterday[0], monthToStr(yesterday[1]) , date, monthToStr(month) ]);
        runTest(dateRange, [ false, yesterday[0], monthToStr(yesterday[1]) , yesterday[0], monthToStr(yesterday[1]) ]);
        runTest(dateRange, [ true, date, monthToStr(month) , tomorrow[0], monthToStr(tomorrow[1]) ]);
        runTest(dateRange, [ false, tomorrow[0], monthToStr(tomorrow[1]) , tomorrow[0], monthToStr(tomorrow[1]) ]);
        runTest(dateRange, [ true, yesterday[0], monthToStr(yesterday[1]) , tomorrow[0], monthToStr(tomorrow[1]) ]);
        runTest(dateRange, [ false, tomorrow[0], monthToStr(tomorrow[1]) , yesterday[0], monthToStr(yesterday[1]) ]);
    }

    {
        var lastMonth = incDate(new Date(), 'month', -1);
        var thisMonth = incDate(new Date(), 'month', 0);
        var nextMonth = incDate(new Date(), 'month', +1);
        runTest(dateRange, [ true, lastMonth[0], monthToStr(lastMonth[1]) , thisMonth[0], monthToStr(thisMonth[1]) ]);
        runTest(dateRange, [ true, thisMonth[0], monthToStr(thisMonth[1]) , nextMonth[0], monthToStr(nextMonth[1]) ]);
        runTest(dateRange, [ true, lastMonth[0], monthToStr(lastMonth[1]) , nextMonth[0], monthToStr(nextMonth[1]) ]);
        var date1 = incDate(new Date(), 'day', +1, 'month', -1);
        var date2 = incDate(new Date(), 'day', -1, 'month', +1);
        runTest(dateRange, [ true, date1[0], monthToStr(date1[1]) , nextMonth[0], monthToStr(nextMonth[1]) ]);
        runTest(dateRange, [ true, lastMonth[0], monthToStr(lastMonth[1]) , date2[0], monthToStr(date2[1]) ]);
        runTest(dateRange, [ false, nextMonth[0], monthToStr(nextMonth[1]) , lastMonth[0], monthToStr(lastMonth[1]) ]);
        var date3 = incDate(new Date(), 'day', +1, 'month', +1);
        var date4 = incDate(new Date(), 'day', +1, 'month', -1);
        runTest(dateRange, [ false, date3[0], monthToStr(date3[1]) , date4[0], monthToStr(date4[1]) ]);

        var date5 = incDate(new Date(), 'day', -1, 'month', -1);
        runTest(dateRange, [ false, date2[0], monthToStr(date2[1]) , date5[0], monthToStr(date5[1]) ]);

        runTest(dateRange, [ true, 1, "JAN", 31, "DEC" ]);
        runTest(dateRange, [ true, 2, "JAN", 1, "JAN" ]);

        var month = new Date().getMonth();
        runTest(dateRange, [ false, 1, monthToStr(month+1), 31, monthToStr(month+1) ]);
        runTest(dateRange, [ false, 1, monthToStr(month-1), 31, monthToStr(month-1) ]);
    }


    {
        var lastMonth = incDate(new Date(), 'month', -1);
        var thisMonth = incDate(new Date(), 'month', 0);
        var nextMonth = incDate(new Date(), 'month', +1);
        runTest(dateRange, [ true, monthToStr(thisMonth[1]), thisMonth[2], monthToStr(thisMonth[1]), thisMonth[2] ]);
        runTest(dateRange, [ true, monthToStr(lastMonth[1]), lastMonth[2], monthToStr(thisMonth[1]), thisMonth[2] ]);
        runTest(dateRange, [ true, monthToStr(thisMonth[1]), thisMonth[2], monthToStr(nextMonth[1]), nextMonth[2] ]);
        runTest(dateRange, [ true, monthToStr(lastMonth[1]), lastMonth[2], monthToStr(nextMonth[1]), nextMonth[2] ]);
        runTest(dateRange, [ true, monthToStr(0), year, monthToStr(11), year ]);

        runTest(dateRange, [ false, monthToStr(nextMonth[1]), nextMonth[2], monthToStr(lastMonth[1]), lastMonth[2] ]);
        runTest(dateRange, [ false, monthToStr(nextMonth[1]), nextMonth[2], monthToStr(nextMonth[1]), nextMonth[2] ]);
        runTest(dateRange, [ false, monthToStr(lastMonth[1]), lastMonth[2], monthToStr(lastMonth[1]), lastMonth[2] ]);

        var lastYear = incDate(new Date(), 'year', -1);
        var nextYear = incDate(new Date(), 'year', +1);

        runTest(dateRange, [ false, monthToStr(lastYear[1]), lastYear[2], monthToStr(lastMonth[1]), lastMonth[2] ]);
        runTest(dateRange, [ true, monthToStr(thisMonth[1]), thisMonth[2], monthToStr(nextYear[1]), nextYear[2] ]);

        var year = new Date().getFullYear();
        var month = new Date().getMonth();

        runTest(dateRange, [ true, monthToStr(month), year-1, monthToStr(month), year ]);
        runTest(dateRange, [ true, monthToStr(month), year-1, monthToStr(month), year+1 ]);
        runTest(dateRange, [ true, monthToStr(0), year, monthToStr(0), year+1 ]);
        runTest(dateRange, [ true, monthToStr(0), year-1, monthToStr(0), year+1 ]);
        runTest(dateRange, [ false, monthToStr(0), year-1, monthToStr(11), year-1 ]);
        runTest(dateRange, [ false, monthToStr(0), year+1, monthToStr(11), year+1 ]);
    }

    {
        var today = incDate(new Date(), 'day', 0);
        var yesterday = incDate(new Date(), 'day', -1);
        var tomorrow = incDate(new Date(), 'day', +1);
        runTest(dateRange, [ true,
            today[0], monthToStr(today[1]), today[2], today[0], monthToStr(today[1]), today[2] ]);
        runTest(dateRange, [ true,
            yesterday[0], monthToStr(yesterday[1]), yesterday[2], tomorrow[0], monthToStr(tomorrow[1]), tomorrow[2] ]);
    }

    {
        var dayLastMonth = incDate(new Date(), 'day', -1, 'month', -1);
        var dayNextMonth = incDate(new Date(), 'day', +1, 'month', +1);
        runTest(dateRange, [ true,
            dayLastMonth[0], monthToStr(dayLastMonth[1]), dayLastMonth[2], dayNextMonth[0], monthToStr(dayNextMonth[1]), dayNextMonth[2] ]);
    }

    {
        var dayLastYear = incDate(new Date(), 'day', -1, 'month', -1, 'year', -1);
        var dayNextYear = incDate(new Date(), 'day', +1, 'month', +1, 'year', +1);
        runTest(dateRange, [ true,
            dayLastYear[0], monthToStr(dayLastYear[1]), dayLastYear[2], dayNextYear[0], monthToStr(dayNextYear[1]), dayNextYear[2] ]);
    }

    {
        var dayLastYear = incDate(new Date(), 'day', +1, 'month', -1, 'year', -1);
        var dayNextYear = incDate(new Date(), 'day', +1, 'month', +1, 'year', +1);
        runTest(dateRange, [ true,
            dayLastYear[0], monthToStr(dayLastYear[1]), dayLastYear[2], dayNextYear[0], monthToStr(dayNextYear[1]), dayNextYear[2] ]);
    }

    {
        var tomorrow = incDate(new Date(), 'day', +1);
        var dayNextYear = incDate(new Date(), 'day', +1, 'month', +1, 'year', +1);
        runTest(dateRange, [ false,
            tomorrow[0], monthToStr(tomorrow[1]), tomorrow[2], dayNextYear[0], monthToStr(dayNextYear[1]), dayNextYear[2] ]);

    }

    {
        var nextMonth = incDate(new Date(), 'month', +1);
        var nextYear = incDate(new Date(), 'day', +1, 'month', +1, 'year', +1);
        runTest(dateRange, [ false,
            nextMonth[0], monthToStr(nextMonth[1]), nextMonth[2], nextYear[0], monthToStr(nextYear[1]), nextYear[2] ]);
    }

    {
        runTest(dateRange, [ true, 1, monthToStr(0), 0, 31, monthToStr(11), 100000 ]);
        runTest(dateRange, [ true, 1, monthToStr(0), year, 31, monthToStr(11), year ]);
        runTest(dateRange, [ true, 1, monthToStr(0), year-1, 31, monthToStr(11), year+1 ]);
        runTest(dateRange, [ false, 1, monthToStr(0), year-1, 31, monthToStr(11), year-1 ]);
        runTest(dateRange, [ false, 1, monthToStr(0), year+1, 31, monthToStr(11), year+1 ]);
     }

}

function testDateRange2() {

  var dates = [   
	new Date("January 31, 2011 3:33:33"),
	new Date("February 28, 2011 3:33:33"),
	new Date("February 29, 2012 3:33:33"),
	new Date("March 31, 2011 3:33:33"),
	new Date("April 30, 2011 3:33:33"),
	new Date("May 31, 2011 3:33:33"),
	new Date("June 30, 2011 3:33:33"),
	new Date("July 31, 2011 3:33:33"),
	new Date("August 31, 2011 3:33:33"),
	new Date("September 30, 2011 3:33:33"),
	new Date("October 31, 2011 3:33:33"),
	new Date("November 30, 2011 3:33:33"),
	new Date("December 31, 2011 3:33:33"),
]
  for (var i = 0; i < dates.length; i++)  {
      var current = dates[i];
      var today = incDate(current, 'day', 0);
      var yesterday = incDate(current, 'day', -1);
      var tomorrow = incDate(current, 'day', 1);
      var aYearFromNow = new Date(current.getFullYear()+1, current.getMonth()+1, current.getDate()+1);
      var later = [aYearFromNow.getDate(), aYearFromNow.getMonth(), aYearFromNow.getFullYear()];

      runTest(isDateInRange_internallForIcedTeaWebTesting, [ true, current,
        today[0], monthToStr(today[1]) , tomorrow[0], monthToStr(tomorrow[1]) ]);
      runTest(isDateInRange_internallForIcedTeaWebTesting, [ true, current,
        yesterday[0], monthToStr(yesterday[1]) , tomorrow[0], monthToStr(tomorrow[1]) ]);
      runTest(isDateInRange_internallForIcedTeaWebTesting, [ true, current,
        yesterday[0], monthToStr(yesterday[1]), yesterday[2], tomorrow[0], monthToStr(tomorrow[1]), tomorrow[2] ]);
      runTest(isDateInRange_internallForIcedTeaWebTesting, [ false, current,
        tomorrow[0], monthToStr(tomorrow[1]), tomorrow[2], later[0], monthToStr(later[1]), later[2] ]);
  }

}

function testDateRange3() {
  var dates = [   
	new Date("January 1, 2011 1:11:11"),
	new Date("February 1, 2011 1:11:11"),
	new Date("March 1, 2011 1:11:11"),
	new Date("April 1, 2011 1:11:11"),
	new Date("May 1, 2011 1:11:11"),
	new Date("June 1, 2011 1:11:11"),
	new Date("July 1, 2011 1:11:11"),
	new Date("August 1, 2011 1:11:11"),
	new Date("September 1, 2011 1:11:11"),
	new Date("October 1, 2011 1:11:11"),
	new Date("November 1, 2011 1:11:11"),
	new Date("December 1, 2011 1:11:11"),

    ]



  for (var i = 0; i < dates.length; i++)  {
    var current = dates[i];
    var yesterday = incDate(current,'day',-1);
    var today = incDate(current,'day',0);
    var tomorrow = incDate(current,'day',1);
    runTest(isDateInRange_internallForIcedTeaWebTesting, [ true, current,
      yesterday[0], monthToStr(yesterday[1]) , today[0], monthToStr(today[1]) ]);
    runTest(isDateInRange_internallForIcedTeaWebTesting, [ true, current,
      yesterday[0], monthToStr(yesterday[1]) , tomorrow[0], monthToStr(tomorrow[1]) ]);
    runTest(isDateInRange_internallForIcedTeaWebTesting, [ true, current,
      yesterday[0], monthToStr(yesterday[1]), yesterday[2], tomorrow[0], monthToStr(tomorrow[1]), tomorrow[2] ]);
  }
}

function testTimeRange() {
    var now = new Date();

    var hour = now.getHours();
    var min = now.getMinutes();
    var sec = now.getSeconds();

    function toHour(input) {
        if (input < 0) {
            while (input < 0) {
                input = input + 24;
            }
            return (input % 24);
        } else {
            return (input % 24);
        }
    }

    function toMin(input) {
        if (input < 0) {
            while (input < 0) {
                input = input + 60;
            }
            return (input % 60);
        } else {
            return (input % 60);
        }
    }

    tests = [
        [ true, hour ],
        [ false, toHour(hour+1)],
        [ false, toHour(hour-1)],

        [ true, hour, hour ],
        [ true, toHour(hour-1), hour ],
        [ true, hour, toHour(hour+1)],
        [ true, toHour(hour-1), toHour(hour+1)],
        [ true, toHour(hour+1), hour ],
        [ true, hour, toHour(hour-1) ],
        [ false, toHour(hour-2), toHour(hour-1)],
        [ false, toHour(hour+1), toHour(hour+2)],
        [ false, toHour(hour+1), toHour(hour-1) ],
        [ true, 0, 23 ],
        [ true, 12, 11 ],

        [ true, hour, min, hour, min ],
        [ true, hour, min, hour, toMin(min+1) ],
        [ true, hour, toMin(min-1), hour, min ],
        [ true, hour, toMin(min-1), hour, toMin(min+1) ],
        [ true, hour, toMin(min+2), hour, toMin(min+1) ],
        [ false, hour, toMin(min+1), hour, toMin(min+1) ],
        [ false, hour, toMin(min-1), hour, toMin(min-1) ],
        [ false, hour, toMin(min+1), hour, toMin(min-1) ],
        [ true, toHour(hour-1), min, hour, min ],
        [ true, hour, min, toHour(hour+1), min ],
        [ true, toHour(hour-1), min, toHour(hour+1), min ],
        [ true, 0, 0, 23, 59 ],
        [ true, 0, 1, 0, 0 ],

        [ true, 0, 1, 0, 0, 0, 0 ],
        [ true, hour, min, sec, hour, min, sec ],
        [ true, hour, min, sec, hour, min + 10, sec ],
        [ true, hour, min, sec - 10, hour, min, sec ],
        [ true, hour, min, sec, hour, min-1 , sec ],

    ];

    runTests(timeRange, tests);
}

main();