QML_RUNTIME_TESTING should be disabled by default.
[profile/ivi/qtdeclarative.git] / tests / auto / qml / parserstress / tests / ecma / TypeConversion / 9.6.js
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 = '9.6.js';
40
41 /**
42    File Name:          9.6.js
43    ECMA Section:       9.6  Type Conversion:  ToUint32
44    Description:        rules for converting an argument to an unsigned
45    32 bit integer
46
47    this test uses >>> 0 to convert the argument to
48    an unsigned 32bit integer.
49
50    1 call ToNumber on argument
51    2 if result is NaN, 0, -0, Infinity, -Infinity
52    return 0
53    3 compute (sign (result(1)) * floor(abs(result 1)))
54    4 compute result(3) modulo 2^32:
55    5 return result(4)
56
57    special cases:
58    -0          returns 0
59    Infinity    returns 0
60    -Infinity   returns 0
61    0           returns 0
62    ToInt32(ToUint32(x)) == ToInt32(x) for all values of x
63    ** NEED TO DO THIS PART IN A SEPARATE TEST FILE **
64
65
66    Author:             christine@netscape.com
67    Date:               17 july 1997
68 */
69
70 var SECTION = "9.6";
71 var VERSION = "ECMA_1";
72 startTest();
73
74 writeHeaderToLog( SECTION + " Type Conversion:  ToUint32");
75
76 new TestCase( SECTION,    "0 >>> 0",                          0,          0 >>> 0 );
77 //    new TestCase( SECTION,    "+0 >>> 0",                         0,          +0 >>> 0);
78 new TestCase( SECTION,    "-0 >>> 0",                         0,          -0 >>> 0 );
79 new TestCase( SECTION,    "'Infinity' >>> 0",                 0,          "Infinity" >>> 0 );
80 new TestCase( SECTION,    "'-Infinity' >>> 0",                0,          "-Infinity" >>> 0);
81 new TestCase( SECTION,    "'+Infinity' >>> 0",                0,          "+Infinity" >>> 0 );
82 new TestCase( SECTION,    "Number.POSITIVE_INFINITY >>> 0",   0,          Number.POSITIVE_INFINITY >>> 0 );
83 new TestCase( SECTION,    "Number.NEGATIVE_INFINITY >>> 0",   0,          Number.NEGATIVE_INFINITY >>> 0 );
84 new TestCase( SECTION,    "Number.NaN >>> 0",                 0,          Number.NaN >>> 0 );
85
86 new TestCase( SECTION,    "Number.MIN_VALUE >>> 0",           0,          Number.MIN_VALUE >>> 0 );
87 new TestCase( SECTION,    "-Number.MIN_VALUE >>> 0",          0,          Number.MIN_VALUE >>> 0 );
88 new TestCase( SECTION,    "0.1 >>> 0",                        0,          0.1 >>> 0 );
89 new TestCase( SECTION,    "-0.1 >>> 0",                       0,          -0.1 >>> 0 );
90 new TestCase( SECTION,    "1 >>> 0",                          1,          1 >>> 0 );
91 new TestCase( SECTION,    "1.1 >>> 0",                        1,          1.1 >>> 0 );
92
93 new TestCase( SECTION,    "-1.1 >>> 0",                       ToUint32(-1.1),       -1.1 >>> 0 );
94 new TestCase( SECTION,    "-1 >>> 0",                         ToUint32(-1),         -1 >>> 0 );
95
96 new TestCase( SECTION,    "2147483647 >>> 0",         ToUint32(2147483647),     2147483647 >>> 0 );
97 new TestCase( SECTION,    "2147483648 >>> 0",         ToUint32(2147483648),     2147483648 >>> 0 );
98 new TestCase( SECTION,    "2147483649 >>> 0",         ToUint32(2147483649),     2147483649 >>> 0 );
99
100 new TestCase( SECTION,    "4294967295 >>> 0",         ToUint32(4294967295),     4294967295 >>> 0 );
101 new TestCase( SECTION,    "4294967296 >>> 0",         ToUint32(4294967296),     4294967296 >>> 0 );
102 new TestCase( SECTION,    "4294967297 >>> 0",         ToUint32(4294967297),     4294967297 >>> 0 );
103
104 new TestCase( SECTION,    "-2147483647 >>> 0",        ToUint32(-2147483647),    -2147483647 >>> 0 );
105 new TestCase( SECTION,    "-2147483648 >>> 0",        ToUint32(-2147483648),    -2147483648 >>> 0 );
106 new TestCase( SECTION,    "-2147483649 >>> 0",        ToUint32(-2147483649),    -2147483649 >>> 0 );
107
108 new TestCase( SECTION,    "-4294967295 >>> 0",        ToUint32(-4294967295),    -4294967295 >>> 0 );
109 new TestCase( SECTION,    "-4294967296 >>> 0",        ToUint32(-4294967296),    -4294967296 >>> 0 );
110 new TestCase( SECTION,    "-4294967297 >>> 0",        ToUint32(-4294967297),    -4294967297 >>> 0 );
111
112 new TestCase( SECTION,    "'2147483647' >>> 0",       ToUint32(2147483647),     '2147483647' >>> 0 );
113 new TestCase( SECTION,    "'2147483648' >>> 0",       ToUint32(2147483648),     '2147483648' >>> 0 );
114 new TestCase( SECTION,    "'2147483649' >>> 0",       ToUint32(2147483649),     '2147483649' >>> 0 );
115
116 new TestCase( SECTION,    "'4294967295' >>> 0",       ToUint32(4294967295),     '4294967295' >>> 0 );
117 new TestCase( SECTION,    "'4294967296' >>> 0",       ToUint32(4294967296),     '4294967296' >>> 0 );
118 new TestCase( SECTION,    "'4294967297' >>> 0",       ToUint32(4294967297),     '4294967297' >>> 0 );
119
120
121 test();
122
123 function ToUint32( n ) {
124   n = Number( n );
125   var sign = ( n < 0 ) ? -1 : 1;
126
127   if ( Math.abs( n ) == 0 || Math.abs( n ) == Number.POSITIVE_INFINITY) {
128     return 0;
129   }
130   n = sign * Math.floor( Math.abs(n) )
131
132     n = n % Math.pow(2,32);
133
134   if ( n < 0 ){
135     n += Math.pow(2,32);
136   }
137
138   return ( n );
139 }
140