From 8fc60fd3238b5932d83e8d47aeafb8481fcfe3be Mon Sep 17 00:00:00 2001 From: mahaifeng Date: Fri, 2 Aug 2024 11:45:35 +0800 Subject: [PATCH] =?UTF-8?q?[arraybuffer]=E6=B7=BB=E5=8A=A0toByteBuffer?= =?UTF-8?q?=E4=B8=8EfromByteBuffer=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uni_modules/uts-tests/utssdk/ArrayBuffer.uts | 45 ++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/uni_modules/uts-tests/utssdk/ArrayBuffer.uts b/uni_modules/uts-tests/utssdk/ArrayBuffer.uts index de05cab..5f4dd0a 100644 --- a/uni_modules/uts-tests/utssdk/ArrayBuffer.uts +++ b/uni_modules/uts-tests/utssdk/ArrayBuffer.uts @@ -9,6 +9,9 @@ import { TUint8Array } from './TUint8Array.uts' import { TUint8ClampedArray } from './TUint8ClampedArray.uts' import { TUint16Array } from './TUint16Array.uts' import { TUint32Array } from './TUint32Array.uts' +// #ifdef UNI-APP-X && APP-ANDROID +import ByteBuffer from 'java.nio.ByteBuffer'; +// #endif const tDataView = new TDataView(); const float32 = new TFloat32Array(); @@ -24,6 +27,48 @@ const int16 = new TInt16Array() export function testArrayBuffer() : Result { return describe("ArrayBuffer", () => { // #ifdef (UNI-APP-X && APP-ANDROID) || WEB + test('arraybuffer_isview', () => { + // #TEST ArrayBuffer.isView + var arrayBuffer = new ArrayBuffer(16) + var float64 = new Float64Array(arrayBuffer); + var isView = ArrayBuffer.isView(float64) + console.log(isView)//true + + var a = 1 + var isViewA = ArrayBuffer.isView(a) + console.log(isViewA)//false + // #END + expect(isView).toEqual(true); + + expect(isViewA).toEqual(false); + }) + // #ifdef UNI-APP-X && APP-ANDROID + test('arraybuffer_toByteBuffer', () => { + // #TEST ArrayBuffer.fromByteBuffer,ArrayBuffer.toByteBuffer + var byteBuffer = ByteBuffer.allocate(100) + byteBuffer.put(1) + byteBuffer.put(2) + var buffer = ArrayBuffer.fromByteBuffer(byteBuffer) + console.log('arraybuffer_toByteBuffer', buffer) + var int8 = new Int8Array(buffer) + console.log(int8[0])//1 + console.log(int8[1])//2 + + byteBuffer = buffer.toByteBuffer() + console.log('arraybuffer_toByteBuffer', byteBuffer) + + byteBuffer.rewind() + console.log(byteBuffer[0])//1 + console.log(byteBuffer[1])//2 + // #END + expect(int8[0]).toEqual(1); + expect(int8[1]).toEqual(2); + expect(byteBuffer[0]).toEqual(1); + expect(byteBuffer[1]).toEqual(2); + }) + // #endif + + //dataview start test('dataview_constructor', () => { tDataView.setConstructor() -- GitLab