~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.3.2-2.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.3.1.js
 
24
    ECMA Section:       15.9.3.1 new Date (year, month, date, hours, minutes, seconds, ms)
 
25
    Description:        The [[Prototype]] property of the newly constructed
 
26
                        object is set to the original Date prototype object,
 
27
                        the one that is the initial value of Date.prototype.
 
28
 
 
29
                        The [[Class]] property of the newly constructed object
 
30
                        is set as follows:
 
31
                        1. Call ToNumber(year)
 
32
                        2. Call ToNumber(month)
 
33
                        3. Call ToNumber(date)
 
34
                        4. Call ToNumber(hours)
 
35
                        5. Call ToNumber(minutes)
 
36
                        6. Call ToNumber(seconds)
 
37
                        7. Call ToNumber(ms)
 
38
                        8.  If Result(1)is NaN and 0 <= ToInteger(Result(1)) <=
 
39
                            99, Result(8) is 1900+ToInteger(Result(1)); otherwise,
 
40
                            Result(8) is Result(1)
 
41
                        9.  Compute MakeDay(Result(8), Result(2), Result(3)
 
42
                        10. Compute MakeTime(Result(4), Result(5), Result(6),
 
43
                            Result(7)
 
44
                        11. Compute MakeDate(Result(9), Result(10))
 
45
                        12. Set the [[Value]] property of the newly constructed
 
46
                            object to TimeClip(UTC(Result(11))).
 
47
 
 
48
 
 
49
                        This tests the returned value of a newly constructed
 
50
                        Date object.
 
51
 
 
52
    Author:             christine@netscape.com
 
53
    Date:               7 july 1997
 
54
*/
 
55
 
 
56
    var TIME        = 0;
 
57
    var UTC_YEAR    = 1;
 
58
    var UTC_MONTH   = 2;
 
59
    var UTC_DATE    = 3;
 
60
    var UTC_DAY     = 4;
 
61
    var UTC_HOURS   = 5;
 
62
    var UTC_MINUTES = 6;
 
63
    var UTC_SECONDS = 7;
 
64
    var UTC_MS      = 8;
 
65
 
 
66
    var YEAR        = 9;
 
67
    var MONTH       = 10;
 
68
    var DATE        = 11;
 
69
    var DAY         = 12;
 
70
    var HOURS       = 13;
 
71
    var MINUTES     = 14;
 
72
    var SECONDS     = 15;
 
73
    var MS          = 16;
 
74
 
 
75
//  for TCMS, the testcases array must be global.
 
76
    var SECTION = "15.9.3.1";
 
77
    var TITLE =   "Date( year, month, date, hours, minutes, seconds )";
 
78
 
 
79
    writeHeaderToLog( SECTION+" " +TITLE );
 
80
 
 
81
    var testcases = new Array();
 
82
    getTestCases();
 
83
 
 
84
//  all tests must call a function that returns an array of TestCase object
 
85
    test();
 
86
 
 
87
function getTestCases( ) {
 
88
 
 
89
    // Dates around 2000
 
90
 
 
91
    addNewTestCase( new Date( 1999,11,31,15,59,59),
 
92
                    "new Date( 1999,11,31,15,59,59)",
 
93
                    [946684799000,1999,11,31,5,23,59,59,0,1999,11,31,5,15,59,59,0] );
 
94
 
 
95
    addNewTestCase( new Date( 1999,11,31,16,0,0),
 
96
                    "new Date( 1999,11,31,16,0,0)",
 
97
                    [946684800000,2000,0,1,6,0,0,0,0,1999,11,31,5, 16,0,0,0] );
 
98
 
 
99
    addNewTestCase( new Date( 2000,0,1,0,0,0),
 
100
                    "new Date( 2000,0,1,0,0,0)",
 
101
                    [946713600000,2000,0,1,6,8,0,0,0,2000,0,1,6,0,0,0,0] );
 
102
/*
 
103
    // Dates around 1900
 
104
 
 
105
    addNewTestCase( new Date(1899,11,31,16,0,0),
 
106
                    "new Date(1899,11,31,16,0,0)",
 
107
                    [-2208988800000,1900,0,1,1,0,0,0,0,1899,11,31,0,16,0,0,0] );
 
108
 
 
109
    addNewTestCase( new Date(1899,11,31,15,59,59),
 
110
                    "new Date(1899,11,31,15,59,59)",
 
111
                    [-2208988801000,1899,11,31,0,23,59,59,0,1899,11,31,0,15,59,59,0] );
 
112
 
 
113
    addNewTestCase( new Date(1900,0,1,0,0,0),
 
114
                    "new Date(1900,0,1,0,0,0)",
 
115
                    [-2208960000000,1900,0,1,1,8,0,0,0,1900,0,1,1,0,0,0,0] );
 
116
 
 
117
    addNewTestCase( new Date(1900,0,1,0,0,1),
 
118
                    "new Date(1900,0,1,0,0,1)",
 
119
                    [-2208959999000,1900,0,1,1,8,0,1,0,1900,0,1,1,0,0,1,0] );
 
120
 
 
121
    var UTC_FEB_29_2000 = TIME_2000 + msPerDay*31 + msPerDay*28;
 
122
    var PST_FEB_29_2000 = UTC_FEB_29_2000 + 8*msPerHour;
 
123
 
 
124
    // Dates around Feb 29, 2000
 
125
    addNewTestCase( new Date(2000,1,28,16,0,0,0),
 
126
                    "new Date(2000,1,28,16,0,0,0)",
 
127
                    [UTC_FEB_29_2000,2000,1,29,2,0,0,0,0,2000,1,28,1,16,0,0,0,0] );
 
128
 
 
129
    addNewTestCase( new Date(2000,1,29,0,0,0,0),
 
130
                    "new Date(2000,1,29,0,0,0,0)",
 
131
                    [PST_FEB_29_2000,2000,1,29,2,8,0,0,0,2000,1,29,2,0,0,0,0] );
 
132
 
 
133
    addNewTestCase( new Date(2000,1,29,24,0,0,0),
 
134
                    "new Date(2000,1,29,24,0,0,0)",
 
135
                    [PST_FEB_29_2000+msPerDay,2000,2,1,3,8,0,0,0,2000,2,1,3,0,0,0,0] );
 
136
 
 
137
    // Dates around Jan 1, 2005
 
138
 
 
139
    var UTC_JAN_1_2005 = TIME_2000 + TimeInYear(2000) + TimeInYear(2001) +
 
140
    TimeInYear(2002)+ TimeInYear(2003) + TimeInYear(2004);
 
141
    var PST_JAN_1_2005 = UTC_JAN_1_2005 + 8*msPerHour;
 
142
 
 
143
    addNewTestCase( new Date(2005,0,1,0,0,0,0),
 
144
                    "new Date(2005,0,1,0,0,0,0)",
 
145
                    [PST_JAN_1_2005,2005,0,1,6,8,0,0,0,2005,0,1,6,0,0,0,0] );
 
146
 
 
147
    addNewTestCase( new Date(2004,11,31,16,0,0,0),
 
148
                    "new Date(2004,11,31,16,0,0,0)",
 
149
                    [UTC_JAN_1_2005,2005,0,1,6,0,0,0,0,2004,11,31,5,16,0,0,0] );
 
150
*/
 
151
/*
 
152
   This test case is incorrect.  Need to fix the DaylightSavings functions in
 
153
   shell.js for this to work properly.
 
154
 
 
155
    // Daylight Savings Time
 
156
 
 
157
    var DST_START_1998 = UTC( GetSecondSundayInMarch(TimeFromYear(1998)) + 2*msPerHour )
 
158
 
 
159
    addNewTestCase( new Date(1998,3,5,1,59,59,999),
 
160
                    "new Date(1998,3,5,1,59,59,999)",
 
161
                    [DST_START_1998-1,1998,3,5,0,9,59,59,999,1998,3,5,0,1,59,59,999] );
 
162
 
 
163
    addNewTestCase( new Date(1998,3,5,2,0,0,0),
 
164
                    "new Date(1998,3,5,2,0,0,0)",
 
165
                    [DST_START_1998,1998,3,5,0,10,0,0,0,1998,3,5,0,3,0,0,0]);
 
166
 
 
167
    var DST_END_1998 = UTC( GetFirstSundayInNovember(TimeFromYear(1998)) + 2*msPerHour );
 
168
 
 
169
    addNewTestCase ( new Date(1998,9,25,1,59,59,999),
 
170
                    "new Date(1998,9,25,1,59,59,999)",
 
171
                    [DST_END_1998-1,1998,9,25,0,8,59,59,999,1998,9,25,0,1,59,59,999] );
 
172
 
 
173
    addNewTestCase ( new Date(1998,9,25,2,0,0,0),
 
174
                    "new Date(1998,9,25,2,0,0,0)",
 
175
                    [DST_END_1998,1998,9,25,0,9,0,0,0,1998,9,25,0,1,0,0,0] );
 
176
*/
 
177
}
 
178
 
 
179
function addNewTestCase( DateCase, DateString, ResultArray ) {
 
180
    //adjust hard-coded ResultArray for tester's timezone instead of PST
 
181
    adjustResultArray(ResultArray);
 
182
 
 
183
    item = testcases.length;
 
184
 
 
185
    testcases[item++] = new TestCase( SECTION, DateString+".getTime()", ResultArray[TIME],       DateCase.getTime() );
 
186
    testcases[item++] = new TestCase( SECTION, DateString+".valueOf()", ResultArray[TIME],       DateCase.valueOf() );
 
187
 
 
188
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCFullYear()",      ResultArray[UTC_YEAR],   DateCase.getUTCFullYear() );
 
189
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMonth()",         ResultArray[UTC_MONTH],  DateCase.getUTCMonth() );
 
190
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCDate()",          ResultArray[UTC_DATE],   DateCase.getUTCDate() );
 
191
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCDay()",           ResultArray[UTC_DAY],    DateCase.getUTCDay() );
 
192
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCHours()",         ResultArray[UTC_HOURS],  DateCase.getUTCHours() );
 
193
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMinutes()",       ResultArray[UTC_MINUTES],DateCase.getUTCMinutes() );
 
194
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCSeconds()",       ResultArray[UTC_SECONDS],DateCase.getUTCSeconds() );
 
195
    testcases[item++] = new TestCase( SECTION, DateString+".getUTCMilliseconds()",  ResultArray[UTC_MS],     DateCase.getUTCMilliseconds() );
 
196
 
 
197
    testcases[item++] = new TestCase( SECTION, DateString+".getFullYear()",         ResultArray[YEAR],       DateCase.getFullYear() );
 
198
    testcases[item++] = new TestCase( SECTION, DateString+".getMonth()",            ResultArray[MONTH],      DateCase.getMonth() );
 
199
    testcases[item++] = new TestCase( SECTION, DateString+".getDate()",             ResultArray[DATE],       DateCase.getDate() );
 
200
    testcases[item++] = new TestCase( SECTION, DateString+".getDay()",              ResultArray[DAY],        DateCase.getDay() );
 
201
    testcases[item++] = new TestCase( SECTION, DateString+".getHours()",            ResultArray[HOURS],      DateCase.getHours() );
 
202
    testcases[item++] = new TestCase( SECTION, DateString+".getMinutes()",          ResultArray[MINUTES],    DateCase.getMinutes() );
 
203
    testcases[item++] = new TestCase( SECTION, DateString+".getSeconds()",          ResultArray[SECONDS],    DateCase.getSeconds() );
 
204
    testcases[item++] = new TestCase( SECTION, DateString+".getMilliseconds()",     ResultArray[MS],         DateCase.getMilliseconds() );
 
205
 
 
206
}
 
207
 
 
208
function test() {
 
209
    for( tc=0; tc < testcases.length; tc++ ) {
 
210
        testcases[tc].passed = writeTestCaseResult(
 
211
                                testcases[tc].expect,
 
212
                                testcases[tc].actual,
 
213
                                testcases[tc].description +" = " +
 
214
                                testcases[tc].actual );
 
215
    }
 
216
    stopTest();
 
217
    return testcases;
 
218
}
 
219