dataview_getset.js revision 765:91ef0e039d91
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
34var Float = Java.type("java.lang.Float");
35var Double = Java.type("java.lang.Double");
36
37var DOUBLE_MIN = Double.MIN_VALUE;
38var DOUBLE_MIN_NORMAL = Double.MIN_NORMAL;
39var FLOAT_MIN = Float.MIN_VALUE;
40var FLOAT_MIN_NORMAL = Float.MIN_NORMAL;
41
42var buffer = new ArrayBuffer(12);
43var dv = new DataView(buffer);
44
45dv.setInt8(1, 123);
46Assert.assertEquals(dv.getInt8(1), 123);
47dv.setInt8(1, 123, true);
48Assert.assertEquals(dv.getInt8(1, true), 123);
49
50dv.setUint8(1, 255);
51Assert.assertEquals(dv.getUint8(1), 255);
52dv.setUint8(1, 255, true);
53Assert.assertEquals(dv.getUint8(1, true), 255);
54
55dv.setInt16(1, 1234);
56Assert.assertEquals(dv.getInt16(1), 1234);
57dv.setInt16(1, 1234, true);
58Assert.assertEquals(dv.getInt16(1, true), 1234);
59
60dv.setUint16(1, 65535);
61Assert.assertEquals(dv.getUint16(1), 65535);
62dv.setUint16(1, 65535, true);
63Assert.assertEquals(dv.getUint16(1, true), 65535);
64
65dv.setInt32(1, 1234);
66Assert.assertEquals(dv.getInt32(1), 1234);
67dv.setInt32(1, 1234, true);
68Assert.assertEquals(dv.getInt32(1, true), 1234);
69
70dv.setUint32(1, 4294967295);
71Assert.assertEquals(dv.getUint32(1), 4294967295);
72dv.setUint32(1, 4294967295, true);
73Assert.assertEquals(dv.getUint32(1, true), 4294967295);
74
75dv.setFloat64(1, Math.PI);
76Assert.assertEquals(dv.getFloat64(1), Math.PI, DOUBLE_MIN);
77dv.setFloat64(1, Math.PI, true);
78Assert.assertEquals(dv.getFloat64(1, true), Math.PI, DOUBLE_MIN);
79
80dv.setFloat64(1, DOUBLE_MIN_NORMAL);
81Assert.assertEquals(dv.getFloat64(1), DOUBLE_MIN_NORMAL, DOUBLE_MIN);
82dv.setFloat64(1, DOUBLE_MIN_NORMAL, true);
83Assert.assertEquals(dv.getFloat64(1, true), DOUBLE_MIN_NORMAL, DOUBLE_MIN);
84
85dv.setFloat32(1, 1.414);
86Assert["assertEquals(float, float, float)"](dv.getFloat32(1), 1.414, FLOAT_MIN);
87dv.setFloat32(1, 1.414, true);
88Assert["assertEquals(float, float, float)"](dv.getFloat32(1, true), 1.414, FLOAT_MIN);
89
90dv.setFloat32(1, FLOAT_MIN_NORMAL);
91Assert["assertEquals(float, float, float)"](dv.getFloat32(1), FLOAT_MIN_NORMAL, FLOAT_MIN);
92dv.setFloat32(1, FLOAT_MIN_NORMAL, true);
93Assert["assertEquals(float, float, float)"](dv.getFloat32(1, true), FLOAT_MIN_NORMAL, FLOAT_MIN);
94