~ubuntu-branches/ubuntu/saucy/qtdeclarative-opensource-src/saucy

« back to all changes in this revision

Viewing changes to tests/auto/qml/parserstress/tests/ecma/Array/15.4.4.5-3.js

  • Committer: Package Import Robot
  • Author(s): Timo Jyrinki
  • Date: 2013-02-05 14:17:19 UTC
  • Revision ID: package-import@ubuntu.com-20130205141719-qqeyml8wslpyez52
Tags: upstream-5.0.1
ImportĀ upstreamĀ versionĀ 5.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Mozilla Public License Version
 
6
 * 1.1 (the "License"); you may not use this file except in compliance with
 
7
 * the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/MPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is Mozilla Communicator client code, released
 
16
 * March 31, 1998.
 
17
 *
 
18
 * The Initial Developer of the Original Code is
 
19
 * Netscape Communications Corporation.
 
20
 * Portions created by the Initial Developer are Copyright (C) 1998
 
21
 * the Initial Developer. All Rights Reserved.
 
22
 *
 
23
 * Contributor(s):
 
24
 *
 
25
 * Alternatively, the contents of this file may be used under the terms of
 
26
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
27
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
28
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
29
 * of those above. If you wish to allow use of your version of this file only
 
30
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
31
 * use your version of this file under the terms of the MPL, indicate your
 
32
 * decision by deleting the provisions above and replace them with the notice
 
33
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
34
 * the provisions above, a recipient may use your version of this file under
 
35
 * the terms of any one of the MPL, the GPL or the LGPL.
 
36
 *
 
37
 * ***** END LICENSE BLOCK ***** */
 
38
 
 
39
gTestfile = '15.4.4.5-3.js';
 
40
 
 
41
/**
 
42
   File Name:          15.4.4.5-3.js
 
43
   ECMA Section:       Array.prototype.sort(comparefn)
 
44
   Description:
 
45
 
 
46
   This is a regression test for
 
47
   http://scopus/bugsplat/show_bug.cgi?id=117144
 
48
 
 
49
   Verify that sort is successfull, even if the sort compare function returns
 
50
   a very large negative or positive value.
 
51
 
 
52
   Author:             christine@netscape.com
 
53
   Date:               12 november 1997
 
54
*/
 
55
 
 
56
 
 
57
var SECTION = "15.4.4.5-3";
 
58
var VERSION = "ECMA_1";
 
59
startTest();
 
60
var TITLE   = "Array.prototype.sort(comparefn)";
 
61
 
 
62
writeHeaderToLog( SECTION + " "+ TITLE);
 
63
 
 
64
var array = new Array();
 
65
 
 
66
array[array.length] = new Date( TIME_2000 * Math.PI );
 
67
array[array.length] = new Date( TIME_2000 * 10 );
 
68
array[array.length] = new Date( TIME_1900 + TIME_1900  );
 
69
array[array.length] = new Date(0);
 
70
array[array.length] = new Date( TIME_2000 );
 
71
array[array.length] = new Date( TIME_1900 + TIME_1900 +TIME_1900 );
 
72
array[array.length] = new Date( TIME_1900 * Math.PI );
 
73
array[array.length] = new Date( TIME_1900 * 10 );
 
74
array[array.length] = new Date( TIME_1900 );
 
75
array[array.length] = new Date( TIME_2000 + TIME_2000 );
 
76
array[array.length] = new Date( 1899, 0, 1 );
 
77
array[array.length] = new Date( 2000, 1, 29 );
 
78
array[array.length] = new Date( 2000, 0, 1 );
 
79
array[array.length] = new Date( 1999, 11, 31 );
 
80
 
 
81
var testarr1 = new Array();
 
82
clone( array, testarr1 );
 
83
testarr1.sort( comparefn1 );
 
84
 
 
85
var testarr2 = new Array();
 
86
clone( array, testarr2 );
 
87
testarr2.sort( comparefn2 );
 
88
 
 
89
testarr3 = new Array();
 
90
clone( array, testarr3 );
 
91
testarr3.sort( comparefn3 );
 
92
 
 
93
// when there's no sort function, sort sorts by the toString value of Date.
 
94
 
 
95
var testarr4 = new Array();
 
96
clone( array, testarr4 );
 
97
testarr4.sort();
 
98
 
 
99
var realarr = new Array();
 
100
clone( array, realarr );
 
101
realarr.sort( realsort );
 
102
 
 
103
var stringarr = new Array();
 
104
clone( array, stringarr );
 
105
stringarr.sort( stringsort );
 
106
 
 
107
for ( var i = 0; i < array.length; i++) {
 
108
  new TestCase(
 
109
    SECTION,
 
110
    "testarr1["+i+"]",
 
111
    realarr[i],
 
112
    testarr1[i] );
 
113
}
 
114
 
 
115
for ( var i=0; i < array.length; i++) {
 
116
  new TestCase(
 
117
    SECTION,
 
118
    "testarr2["+i+"]",
 
119
    realarr[i],
 
120
    testarr2[i] );
 
121
}
 
122
 
 
123
for ( var i=0; i < array.length; i++) {
 
124
  new TestCase(
 
125
    SECTION,
 
126
    "testarr3["+i+"]",
 
127
    realarr[i],
 
128
    testarr3[i] );
 
129
}
 
130
 
 
131
for ( var i=0; i < array.length; i++) {
 
132
  new TestCase(
 
133
    SECTION,
 
134
    "testarr4["+i+"]",
 
135
    stringarr[i].toString(),
 
136
    testarr4[i].toString() );
 
137
}
 
138
 
 
139
test();
 
140
 
 
141
function comparefn1( x, y ) {
 
142
  return x - y;
 
143
}
 
144
function comparefn2( x, y ) {
 
145
  return x.valueOf() - y.valueOf();
 
146
}
 
147
function realsort( x, y ) {
 
148
  return ( x.valueOf() == y.valueOf() ? 0 : ( x.valueOf() > y.valueOf() ? 1 : -1 ) );
 
149
}
 
150
function comparefn3( x, y ) {
 
151
  return ( x == y ? 0 : ( x > y ? 1: -1 ) );
 
152
}
 
153
function clone( source, target ) {
 
154
  for (i = 0; i < source.length; i++ ) {
 
155
    target[i] = source[i];
 
156
  }
 
157
}
 
158
function stringsort( x, y ) {
 
159
  for ( var i = 0; i < x.toString().length; i++ ) {
 
160
    var d = (x.toString()).charCodeAt(i) - (y.toString()).charCodeAt(i);
 
161
    if ( d > 0 ) {
 
162
      return 1;
 
163
    } else {
 
164
      if ( d < 0 ) {
 
165
        return -1;
 
166
      } else {
 
167
        continue;
 
168
      }
 
169
    }
 
170
 
 
171
    var d = x.length - y.length;
 
172
 
 
173
    if  ( d > 0 ) {
 
174
      return 1;
 
175
    } else {
 
176
      if ( d < 0 ) {
 
177
        return -1;
 
178
      }
 
179
    }
 
180
  }
 
181
  return 0;
 
182
}