[RFC][icedtea-web][rhino] added tests for corner cases of dateRange and enabled testWeekdayRange

Omair Majid omajid at redhat.com
Wed Nov 9 09:22:44 PST 2011


On 11/08/2011 08:30 AM, Jiri Vanek wrote:
> Hi!
> This tests pickup and covers rhino tests failures, which occurs at the
> start/end of each week.
> eg bottoms of:
> http://10.34.2.200/icedtea-web-dailyreport/ICWDR_1320037429/index.html
> http://10.34.2.200/icedtea-web-dailyreport/ICWDR_1320123820/index.html
> http://10.34.2.200/icedtea-web-dailyreport/ICWDR_1320210219/index.html
> and see  regeressions in Rhino tests
>

Thanks for these. Some of the links, like 'Rhino tests' which leads to
http://10.34.2.200/icedtea-web-dailyreport/ICWDR_1320037429/ICWDR_1320037429/check_o.log, 
look broken.

> More then bug in netx itself, I suspect quite strange functions incDate
> and decDate in tests/netx/pac/pac-funcs-test.js
> Note, that new tests of first day in month are falling all, and tests of
> last day in month are falling  only for 31 days long months.
>

Just to be clear, the patch does not change this behaviour, right?

I suspect you might have to replace incDate/decDate (and related 
methods) to increment the date, month, year tuple (and return that) 
instead of just the date or the month or the year by itself.

> Also I have noticed, taht testWeekdayRange (in same test file) have
> missing  runTests, so this test is never call. I adddd this call, and
> it's three tests are now in and passing

Nice catch!

> I had sorted call of this test *behind* "all currently running tests",
> because I want to keep rhino statistics (which are order-of-test
> dependent) untouched.
>
> To test dateRange  properly against specific dates, I had to modify also
> netx/net/sourceforge/jnlp/runtime/pac-funcs.js. I have moved logic of
> dateRange into new function  isDateInRange which an be called against
> any date.
>   DateRange then preserve api compatibilty and is wrapper for "today"
> upon isDateInRange
>

Good idea.

> diff -r 89b7a28ccafb netx/net/sourceforge/jnlp/runtime/pac-funcs.js
> --- a/netx/net/sourceforge/jnlp/runtime/pac-funcs.js	Mon Oct 31 16:31:41 2011 -0400
> +++ b/netx/net/sourceforge/jnlp/runtime/pac-funcs.js	Tue Nov 08 14:27:33 2011 +0100
> @@ -325,20 +325,22 @@
>    * of the above ways of calling.
>    */
>   function dateRange() {
> +switch (arguments.length) {

Indentation looks a little wrong here.

> +        case 1: return isDateInRange(new Date(),arguments[0]);
> +        case 2: return isDateInRange(new Date(),arguments[0],arguments[1]);
> +        case 3: return isDateInRange(new Date(),arguments[0],arguments[1],arguments[2]);
> +        case 4: return isDateInRange(new Date(),arguments[0],arguments[1],arguments[2],arguments[3]);
> +        case 5: return isDateInRange(new Date(),arguments[0],arguments[1],arguments[2],arguments[3],arguments[4]);
> +        case 6: return isDateInRange(new Date(),arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5]);
> +        case 7: return isDateInRange(new Date(),arguments[0],arguments[1],arguments[2],arguments[3],arguments[4],arguments[5],arguments[6]); //GMT
> +        default:
> +            return false;
> +	}
> +}
>
> -    // note: watch out for wrapping around of dates. date ranges, like
> -    // month=9 to month=8, wrap around and cover the entire year. this
> -    // makes everything more interesting
> +function isDateInRange() {
>
> -    var gmt;
> -	if (arguments.length>  1) {
> -		if (arguments[arguments.length-1] === "GMT") {
> -			gmt = true;
> -            arguments.splice(0,arguments.length-1);
> -        }
> -	}
> -
> -    function isDate(date) {
> + function isDate(date) {

Why the change in indentation?

>           if (typeof(date) === 'number'&&  (date<= 31&&  date>= 1)) {
>               return true;
>           }
> @@ -578,8 +580,19 @@
>           }
>       }
>
> +    // note: watch out for wrapping around of dates. date ranges, like
> +    // month=9 to month=8, wrap around and cover the entire year. this
> +    // makes everything more interesting
> +
> +    var gmt;
> +	if (arguments.length>  2) {
> +		if (arguments[arguments.length-1] === "GMT") {
> +			gmt = true;
> +            arguments.splice(0,arguments.length-1);
> +        }
> +	}
>       // TODO: change date to gmt, whatever
> -    var today = new Date();
> +    var today = arguments[0]
>
>       var arg1;
>       var arg2;
> @@ -588,9 +601,9 @@
>       var arg5;
>       var arg6;
>
> -    switch (arguments.length) {
> +    switch (arguments.length-1) {
>           case 1:
> -            var arg = arguments[0];
> +            var arg = arguments[1];
>               if (isDate(arg)) {
>                   if (today.getDate() === arg) {
>                       return true;
> @@ -611,8 +624,8 @@
>                   }
>               }
>           case 2:
> -            arg1 = arguments[0];
> -            arg2 = arguments[1];
> +            arg1 = arguments[1];
> +            arg2 = arguments[2];
>               if (isDate(arg1)&&  isDate(arg2)) {
>                   var date1 = arg1;
>                   var date2 = arg2;
> @@ -634,10 +647,10 @@
>                   return false;
>               }
>           case 4:
> -            arg1 = arguments[0];
> -            arg2 = arguments[1];
> -            arg3 = arguments[2];
> -            arg4 = arguments[3];
> +            arg1 = arguments[1];
> +            arg2 = arguments[2];
> +            arg3 = arguments[3];
> +            arg4 = arguments[4];
>
>               if (isDate(arg1)&&  isMonth(arg2)&&  isDate(arg3)&&  isMonth(arg4)) {
>                   var date1 = arg1;
> @@ -658,12 +671,12 @@
>                   return false;
>               }
>           case 6:
> -            arg1 = arguments[0];
> -            arg2 = arguments[1];
> -            arg3 = arguments[2];
> -            arg4 = arguments[3];
> -            arg5 = arguments[4];
> -            arg6 = arguments[5];
> +            arg1 = arguments[1];
> +            arg2 = arguments[2];
> +            arg3 = arguments[3];
> +            arg4 = arguments[4];
> +            arg5 = arguments[5];
> +            arg6 = arguments[6];
>               if (isDate(arg1)&&  isMonth(arg2)&&  isYear(arg3)&&
>                   isDate(arg4)&&  isMonth(arg5)&&  isYear(arg6)) {
>                   var day1 = arg1;
> diff -r 89b7a28ccafb tests/netx/pac/pac-funcs-test.js
> --- a/tests/netx/pac/pac-funcs-test.js	Mon Oct 31 16:31:41 2011 -0400
> +++ b/tests/netx/pac/pac-funcs-test.js	Tue Nov 08 14:27:33 2011 +0100
> @@ -21,9 +21,11 @@
>   	testDnsResolve();
>   	testDnsDomainLevels();
>   	testShExpMatch();
> -	testWeekdayRange();
>   	testDateRange();
>   	testTimeRange();
> +	testWeekdayRange();
> +	testDateRange2();
> +	testDateRange3();
>
>   	java.lang.System.out.println("Test results: passed: " + testsPassed + "; failed: " + testsFailed + ";");
>   }
> @@ -235,11 +237,11 @@
>          [ false, dayToStr(day+1) ],
>          [ false, dayToStr(day-1) ],
>       ];
> +
> +    runTests(weekdayRange, tests);
>   }
>
> -function testDateRange() {
> -
> -    function incDate(date) {
> +function incDate(date) {
>           return (date + 1 - 1) % 31 +1 ;
>       }
>

Indentation looks wrong here.

> @@ -267,6 +269,9 @@
>           }
>       }
>
> +function testDateRange() {
> +
> +
>       var today = new Date();
>       var date = today.getDate();
>       var month = today.getMonth();
> @@ -369,6 +374,80 @@
>
>   }
>
> +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 today = dates[i];
> +    var date = today.getDate();
> +    var month = today.getMonth();
> +    var year = today.getYear();
> +
> +    var tests = [
> +
> +     [ true, today, date, monthToStr(month) , incDate(date), monthToStr(month) ],
> +      [ true, today, decDate(date), monthToStr(month) , incDate(date), monthToStr(month) ],
> +      [ true, today, decDate(date), monthToStr(month), year, incDate(date), monthToStr(month), year ],
> +      [ false, today, incDate(date), monthToStr(month), year, incDate(date), monthToStr(month+1), year+1 ],
> +
> +    ];
> +
> +    runTests(isDateInRange, tests);
> +}
> +
> +}

Also weird indentation here.

> +
> +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 today = dates[i]
> +    var date = today.getDate();
> +    var month = today.getMonth();
> +    var year = today.getYear();
> +
> +    var tests = [
> +      [ true, today, decDate(date), monthToStr(month) , date, monthToStr(month) ],
> +      [ true, today, decDate(date), monthToStr(month) , incDate(date), monthToStr(month) ],
> +      [ true, today, decDate(date), monthToStr(month), year, incDate(date), monthToStr(month), year ],
> +
> +    ];
> +
> +    runTests(isDateInRange, tests);
> +}
> +}

And likewise.

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

The tests themselves look fine to me.

Thanks again for catching this and creating a patch!

Cheers,
Omair



More information about the distro-pkg-dev mailing list