• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16/*
17 * @tc.name:dataview
18 * @tc.desc:test dataview
19 * @tc.type: FUNC
20 * @tc.require: issue#I7NUZM
21 */
22const buffer = new ArrayBuffer(16);
23const view = new DataView(buffer);
24view.setInt32({}, 0x1337, {});
25print(view.getInt32({}, {}));
26
27try {
28    var buffer1 = new ArrayBuffer(64);
29    var dataview = new DataView(buffer1, 8, 24);
30    dataview.setInt32(0, 1n);
31} catch(e) {
32    print(e)
33}
34
35const buf = new ArrayBuffer(16);
36const first = new DataView(buf, 0, 8);
37const second = new DataView(buf, 8);
38// test setInt32
39second.setInt32(0, NaN);
40print(second.getInt32(0));
41second.setInt32(0, 13.54);
42print(second.getInt32(0));
43second.setInt32(0, -413.54);
44print(second.getInt32(0));
45second.setInt32(1, 2147483648);
46print(second.getInt32(1));
47second.setInt32(1, 13.54);
48print(second.getInt32(0));
49second.setInt32(0, Infinity);
50print(second.getInt32(0));
51second.setInt32(0, 27, true);
52print(second.getInt32(0));
53
54// test setFloat32
55second.setFloat32(0, NaN);
56print(second.getInt32(0));
57second.setFloat32(0, 13.54);
58print(second.getInt32(0));
59second.setFloat32(0, -413.54);
60print(second.getInt32(0));
61second.setFloat32(1, 2147483648);
62print(second.getInt32(1));
63second.setFloat32(1, 13.54);
64print(second.getInt32(0));
65second.setFloat32(0, Infinity);
66print(second.getInt32(0));
67second.setFloat32(0, 27, true);
68print(second.getInt32(0));
69
70// test setFloat64
71second.setFloat64(0, NaN);
72print(second.getInt32(0));
73second.setFloat64(0, 13.54);
74print(second.getInt32(0));
75second.setFloat64(0, -413.54);
76print(second.getInt32(0));
77second.setFloat64(0, 2147483648);
78print(second.getInt32(1));
79second.setFloat64(0, 13.54);
80print(second.getInt32(0));
81second.setFloat64(0, Infinity);
82print(second.getInt32(0));
83second.setFloat64(0, 27, true);
84print(second.getInt32(0));
85
86let ab = new ArrayBuffer(0x100);
87try {
88    let dv1 = new DataView(ab, 0x10, 0xfffffff8);
89} catch(e) {
90    print(e)
91}
92try {
93    let dv2 = new DataView(ab, -1, 0xfffffff8);
94} catch(e) {
95    print(e)
96}
97try {
98    let dv3 = new DataView(ab, 2**53, 0xfffffff8);
99} catch(e) {
100    print(e)
101}
102try {
103    let dv4 = new DataView(ab, 0x10, -1);
104} catch(e) {
105    print(e)
106}
107try {
108    let dv5 = new DataView(ab, 0x10, 2**53);
109} catch(e) {
110    print(e)
111}
112
113try {
114    var dv6 = new DataView(ab, 64, 14);
115    dv6.setFloat64(0x7fffffff, +254, true);
116} catch(e) {
117    print(e)
118}