test/script/basic/dataview_getset.js

changeset 770
64a0ac7d08e7
parent 0
b1a7da25b547
child 962
ac62e33a99b0
equal deleted inserted replaced
769:5a1ae83c295f 770:64a0ac7d08e7
1 /*
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /**
25 * JDK-8015958: DataView constructor is not defined
26 *
27 * @test
28 * @run
29 */
30
31 // checking get/set of values of various types
32 // Also basic endianess check.
33
34 var Float = Java.type("java.lang.Float");
35 var Double = Java.type("java.lang.Double");
36
37 var DOUBLE_MIN = Double.MIN_VALUE;
38 var DOUBLE_MIN_NORMAL = Double.MIN_NORMAL;
39 var FLOAT_MIN = Float.MIN_VALUE;
40 var FLOAT_MIN_NORMAL = Float.MIN_NORMAL;
41
42 var buffer = new ArrayBuffer(12);
43 var dv = new DataView(buffer);
44
45 dv.setInt8(1, 123);
46 Assert.assertEquals(dv.getInt8(1), 123);
47 dv.setInt8(1, 123, true);
48 Assert.assertEquals(dv.getInt8(1, true), 123);
49
50 dv.setUint8(1, 255);
51 Assert.assertEquals(dv.getUint8(1), 255);
52 dv.setUint8(1, 255, true);
53 Assert.assertEquals(dv.getUint8(1, true), 255);
54
55 dv.setInt16(1, 1234);
56 Assert.assertEquals(dv.getInt16(1), 1234);
57 dv.setInt16(1, 1234, true);
58 Assert.assertEquals(dv.getInt16(1, true), 1234);
59
60 dv.setUint16(1, 65535);
61 Assert.assertEquals(dv.getUint16(1), 65535);
62 dv.setUint16(1, 65535, true);
63 Assert.assertEquals(dv.getUint16(1, true), 65535);
64
65 dv.setInt32(1, 1234);
66 Assert.assertEquals(dv.getInt32(1), 1234);
67 dv.setInt32(1, 1234, true);
68 Assert.assertEquals(dv.getInt32(1, true), 1234);
69
70 dv.setUint32(1, 4294967295);
71 Assert.assertEquals(dv.getUint32(1), 4294967295);
72 dv.setUint32(1, 4294967295, true);
73 Assert.assertEquals(dv.getUint32(1, true), 4294967295);
74
75 dv.setFloat64(1, Math.PI);
76 Assert.assertEquals(dv.getFloat64(1), Math.PI, DOUBLE_MIN);
77 dv.setFloat64(1, Math.PI, true);
78 Assert.assertEquals(dv.getFloat64(1, true), Math.PI, DOUBLE_MIN);
79
80 dv.setFloat64(1, DOUBLE_MIN_NORMAL);
81 Assert.assertEquals(dv.getFloat64(1), DOUBLE_MIN_NORMAL, DOUBLE_MIN);
82 dv.setFloat64(1, DOUBLE_MIN_NORMAL, true);
83 Assert.assertEquals(dv.getFloat64(1, true), DOUBLE_MIN_NORMAL, DOUBLE_MIN);
84
85 dv.setFloat32(1, 1.414);
86 Assert["assertEquals(float, float, float)"](dv.getFloat32(1), 1.414, FLOAT_MIN);
87 dv.setFloat32(1, 1.414, true);
88 Assert["assertEquals(float, float, float)"](dv.getFloat32(1, true), 1.414, FLOAT_MIN);
89
90 dv.setFloat32(1, FLOAT_MIN_NORMAL);
91 Assert["assertEquals(float, float, float)"](dv.getFloat32(1), FLOAT_MIN_NORMAL, FLOAT_MIN);
92 dv.setFloat32(1, FLOAT_MIN_NORMAL, true);
93 Assert["assertEquals(float, float, float)"](dv.getFloat32(1, true), FLOAT_MIN_NORMAL, FLOAT_MIN);

mercurial