~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/JavaScriptCore/tests/mozilla/ecma/Date/15.9.5.24-8.js

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* The contents of this file are subject to the Netscape Public
 
2
 * License Version 1.1 (the "License"); you may not use this file
 
3
 * except in compliance with the License. You may obtain a copy of
 
4
 * the License at http://www.mozilla.org/NPL/
 
5
 *
 
6
 * Software distributed under the License is distributed on an "AS
 
7
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 
8
 * implied. See the License for the specific language governing
 
9
 * rights and limitations under the License.
 
10
 *
 
11
 * The Original Code is Mozilla Communicator client code, released March
 
12
 * 31, 1998.
 
13
 *
 
14
 * The Initial Developer of the Original Code is Netscape Communications
 
15
 * Corporation. Portions created by Netscape are
 
16
 * Copyright (C) 1998 Netscape Communications Corporation. All
 
17
 * Rights Reserved.
 
18
 *
 
19
 * Contributor(s): 
 
20
 * 
 
21
 */
 
22
/**
 
23
    File Name:          15.9.5.24-1.js
 
24
    ECMA Section:       15.9.5.24 Date.prototype.setTime(time)
 
25
    Description:
 
26
    1.      If the this value is not a Date object, generate a runtime error.
 
27
    2.      Call ToNumber(time).
 
28
    3.      Call TimeClip(Result(1)).
 
29
    4.      Set the [[Value]] property of the this value to Result(2).
 
30
    5.      Return the value of the [[Value]] property of the this value.
 
31
    Author:             christine@netscape.com
 
32
    Date:               12 november 1997
 
33
 
 
34
*/
 
35
    var TITLE = "Date.prototype.setTime"
 
36
    var SECTION = "15.9.5.24-1";
 
37
    var VERSION = "ECMA_1";
 
38
    startTest();
 
39
 
 
40
    writeHeaderToLog( SECTION + " Date.prototype.setMilliseconds(ms)");
 
41
 
 
42
    var testcases = new Array();
 
43
    getTestCases();
 
44
    test();
 
45
 
 
46
function test() {
 
47
    for ( tc=0; tc < testcases.length; tc++ ) {
 
48
        testcases[tc].passed = writeTestCaseResult(
 
49
                            testcases[tc].expect,
 
50
                            testcases[tc].actual,
 
51
                            testcases[tc].description +" = "+
 
52
                            testcases[tc].actual );
 
53
 
 
54
        testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
 
55
    }
 
56
    stopTest();
 
57
    return ( testcases );
 
58
}
 
59
 
 
60
function getTestCases() {
 
61
    addTestCase( 0, "946684800000" );
 
62
}
 
63
function addTestCase( startms, newms ) {
 
64
 
 
65
    var DateCase = new Date( startms );
 
66
    DateCase.setMilliseconds( newms );
 
67
    var DateString = "var date = new Date("+ startms +"); date.setMilliseconds("+ newms +"); date";
 
68
    var UTCDate = UTCDateFromTime( Number(newms) );
 
69
    var LocalDate = LocalDateFromTime( Number(newms) );
 
70
 
 
71
    var item = testcases.length;
 
72
 
 
73
//    fixed_year = ( ExpectDate.year >=1900 || ExpectDate.year < 2000 ) ? ExpectDate.year - 1900 : ExpectDate.year;
 
74
 
 
75
    testcases[item++] = new TestCase( SECTION, DateString+".getTime()",             UTCDate.value,       DateCase.getTime() );
 
76
    testcases[item++] = new TestCase( SECTION, DateString+".valueOf()",             UTCDate.value,       DateCase.valueOf() );
 
77
 
 
78
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()",      UTCDate.year,    DateCase.getUTCFullYear() );
 
79
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()",         UTCDate.month,  DateCase.getUTCMonth() );
 
80
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()",          UTCDate.date,   DateCase.getUTCDate() );
 
81
//    testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()",           UTCDate.day,    DateCase.getUTCDay() );
 
82
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()",         UTCDate.hours,  DateCase.getUTCHours() );
 
83
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()",       UTCDate.minutes,DateCase.getUTCMinutes() );
 
84
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()",       UTCDate.seconds,DateCase.getUTCSeconds() );
 
85
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()",  UTCDate.ms,     DateCase.getUTCMilliseconds() );
 
86
 
 
87
    testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()",         LocalDate.year,       DateCase.getFullYear() );
 
88
    testcases[item++] = new TestCase( SECTION, DateString+".getMonth()",            LocalDate.month,      DateCase.getMonth() );
 
89
    testcases[item++] = new TestCase( SECTION, DateString+".getDate()",             LocalDate.date,       DateCase.getDate() );
 
90
//    testcases[item++] = new TestCase( SECTION, DateString+".getDay()",              LocalDate.day,        DateCase.getDay() );
 
91
    testcases[item++] = new TestCase( SECTION, DateString+".getHours()",            LocalDate.hours,      DateCase.getHours() );
 
92
    testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()",          LocalDate.minutes,    DateCase.getMinutes() );
 
93
    testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()",          LocalDate.seconds,    DateCase.getSeconds() );
 
94
    testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()",     LocalDate.ms,         DateCase.getMilliseconds() );
 
95
 
 
96
    DateCase.toString = Object.prototype.toString;
 
97
 
 
98
    testcases[item++] = new TestCase( SECTION,
 
99
                                      DateString+".toString=Object.prototype.toString;"+DateString+".toString()",
 
100
                                      "[object Date]",
 
101
                                      DateCase.toString() );
 
102
}
 
103
 
 
104
function MyDate() {
 
105
    this.year = 0;
 
106
    this.month = 0;
 
107
    this.date = 0;
 
108
    this.hours = 0;
 
109
    this.minutes = 0;
 
110
    this.seconds = 0;
 
111
    this.ms = 0;
 
112
}
 
113
function LocalDateFromTime(t) {
 
114
    t = LocalTime(t);
 
115
    return ( MyDateFromTime(t) );
 
116
}
 
117
function UTCDateFromTime(t) {
 
118
 return ( MyDateFromTime(t) );
 
119
}
 
120
function MyDateFromTime( t ) {
 
121
    var d = new MyDate();
 
122
    d.year = YearFromTime(t);
 
123
    d.month = MonthFromTime(t);
 
124
    d.date = DateFromTime(t);
 
125
    d.hours = HourFromTime(t);
 
126
    d.minutes = MinFromTime(t);
 
127
    d.seconds = SecFromTime(t);
 
128
    d.ms = msFromTime(t);
 
129
 
 
130
    d.time = MakeTime( d.hours, d.minutes, d.seconds, d.ms );
 
131
    d.value = TimeClip( MakeDate( MakeDay( d.year, d.month, d.date ), d.time ) );
 
132
    d.day = WeekDay( d.value );
 
133
 
 
134
    return (d);
 
135
}