-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
516 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
157 changes: 157 additions & 0 deletions
157
ohos_addon_example/entry/src/ohosTest/ets/test/Buffer.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
import { describe, it, DEFAULT } from './util/framework.test'; | ||
import binding from './util/binding'; | ||
import assert from './util/assert.test'; | ||
import { runGCTests } from './util/gc.test'; | ||
import { buffer } from '@kit.ArkTS'; | ||
|
||
declare class ArkTools { | ||
static hintGC: () => void | ||
} | ||
|
||
export default function testCase() { | ||
describe("Buffer", () => { | ||
it("RunBuffer", DEFAULT, () => { | ||
return runGCTests([ | ||
'Internal Buffer', | ||
() => { | ||
const test = binding.buffer.createBuffer(); | ||
binding.buffer.checkBuffer(test); | ||
assert.ok(test instanceof ArrayBuffer); | ||
|
||
const test2 = buffer.alloc(test.length); | ||
test.copy(test2.buffer); | ||
binding.buffer.checkBuffer(test2.buffer); | ||
}, | ||
|
||
'Buffer copy', | ||
() => { | ||
const test = binding.buffer.createBufferCopy(); | ||
binding.buffer.checkBuffer(test); | ||
assert.ok(test instanceof ArrayBuffer); | ||
}, | ||
|
||
'External Buffer', | ||
() => { | ||
const test = binding.buffer.createExternalBuffer(); | ||
binding.buffer.checkBuffer(test); | ||
assert.ok(test instanceof ArrayBuffer); | ||
assert.strictEqual(0, binding.buffer.getFinalizeCount()); | ||
}, | ||
() => { | ||
ArkTools.hintGC(); | ||
assert.strictEqual(0, binding.buffer.getFinalizeCount()); | ||
}, | ||
|
||
'External Buffer with finalizer', | ||
() => { | ||
const test = binding.buffer.createExternalBufferWithFinalize(); | ||
binding.buffer.checkBuffer(test); | ||
assert.ok(test instanceof ArrayBuffer); | ||
assert.strictEqual(0, binding.buffer.getFinalizeCount()); | ||
}, | ||
() => { | ||
ArkTools.hintGC(); | ||
}, | ||
() => { | ||
assert.strictEqual(1, binding.buffer.getFinalizeCount()); | ||
}, | ||
|
||
'External Buffer with finalizer hint', | ||
() => { | ||
const test = binding.buffer.createExternalBufferWithFinalizeHint(); | ||
binding.buffer.checkBuffer(test); | ||
assert.ok(test instanceof ArrayBuffer); | ||
assert.strictEqual(0, binding.buffer.getFinalizeCount()); | ||
}, | ||
() => { | ||
ArkTools.hintGC(); | ||
}, | ||
() => { | ||
assert.strictEqual(1, binding.buffer.getFinalizeCount()); | ||
}, | ||
|
||
'Create or Copy External Buffer', | ||
() => { | ||
const test = binding.buffer.createOrCopyExternalBuffer(); | ||
binding.buffer.checkBuffer(test); | ||
assert.ok(test instanceof ArrayBuffer); | ||
assert.strictEqual(0, binding.buffer.getFinalizeCount()); | ||
}, | ||
() => { | ||
ArkTools.hintGC(); | ||
assert.strictEqual(0, binding.buffer.getFinalizeCount()); | ||
}, | ||
|
||
'Create or Copy External Buffer with finalizer', | ||
() => { | ||
const test = binding.buffer.createOrCopyExternalBufferWithFinalize(); | ||
binding.buffer.checkBuffer(test); | ||
assert.ok(test instanceof ArrayBuffer); | ||
assert.strictEqual(0, binding.buffer.getFinalizeCount()); | ||
}, | ||
() => { | ||
ArkTools.hintGC(); | ||
}, | ||
() => { | ||
assert.strictEqual(1, binding.buffer.getFinalizeCount()); | ||
}, | ||
|
||
'Create or Copy External Buffer with finalizer hint', | ||
() => { | ||
const test = binding.buffer.createOrCopyExternalBufferWithFinalizeHint(); | ||
binding.buffer.checkBuffer(test); | ||
assert.ok(test instanceof ArrayBuffer); | ||
assert.strictEqual(0, binding.buffer.getFinalizeCount()); | ||
}, | ||
() => { | ||
ArkTools.hintGC(); | ||
}, | ||
() => { | ||
assert.strictEqual(1, binding.buffer.getFinalizeCount()); | ||
}, | ||
|
||
'Create or Copy External Buffer when NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED defined', | ||
() => { | ||
const test = binding.bufferNoExternal.createOrCopyExternalBuffer(); | ||
binding.buffer.checkBuffer(test); | ||
assert.ok(test instanceof ArrayBuffer); | ||
assert.strictEqual(0, binding.buffer.getFinalizeCount()); | ||
}, | ||
() => { | ||
ArkTools.hintGC(); | ||
assert.strictEqual(0, binding.buffer.getFinalizeCount()); | ||
}, | ||
|
||
'Create or Copy External Buffer with finalizer when NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED defined', | ||
() => { | ||
const test = binding.bufferNoExternal.createOrCopyExternalBufferWithFinalize(); | ||
binding.buffer.checkBuffer(test); | ||
assert.ok(test instanceof ArrayBuffer); | ||
// finalizer should have been called when the buffer was created. | ||
assert.strictEqual(1, binding.buffer.getFinalizeCount()); | ||
}, | ||
() => { | ||
ArkTools.hintGC(); | ||
}, | ||
() => { | ||
assert.strictEqual(1, binding.buffer.getFinalizeCount()); | ||
}, | ||
|
||
'Create or Copy External Buffer with finalizer hint when NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED defined', | ||
() => { | ||
const test = binding.bufferNoExternal.createOrCopyExternalBufferWithFinalizeHint(); | ||
binding.buffer.checkBuffer(test); | ||
assert.ok(test instanceof ArrayBuffer); | ||
// finalizer should have been called when the buffer was created. | ||
assert.strictEqual(1, binding.buffer.getFinalizeCount()); | ||
}, | ||
() => { | ||
ArkTools.hintGC(); | ||
}, | ||
() => { | ||
assert.strictEqual(1, binding.buffer.getFinalizeCount()); | ||
} | ||
]); | ||
}) | ||
}) | ||
} |
39 changes: 39 additions & 0 deletions
39
ohos_addon_example/entry/src/ohosTest/ets/test/DataView/DataView.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { describe, it, DEFAULT } from '../util/framework.test'; | ||
import binding from '../util/binding'; | ||
import assert from '../util/assert.test'; | ||
|
||
export default function testCase() { | ||
describe("DataView", () => { | ||
it("RunDataView", DEFAULT, () => { | ||
function testDataViewCreation (factory, arrayBuffer, offset?, length?) { | ||
const view = factory(arrayBuffer, offset, length); | ||
offset = offset || 0; | ||
assert.ok(dataview.getArrayBuffer(view) instanceof ArrayBuffer); | ||
assert.strictEqual(dataview.getArrayBuffer(view), arrayBuffer); | ||
assert.strictEqual(dataview.getByteOffset(view), offset); | ||
assert.strictEqual(dataview.getByteLength(view), | ||
length || arrayBuffer.byteLength - offset); | ||
} | ||
|
||
function testInvalidRange (factory, arrayBuffer, offset, length) { | ||
assert.throws(() => { | ||
factory(arrayBuffer, offset, length); | ||
}, RangeError); | ||
} | ||
|
||
const dataview = binding.dataview; | ||
const arrayBuffer = new ArrayBuffer(10); | ||
|
||
testDataViewCreation(dataview.createDataView1, arrayBuffer); | ||
testDataViewCreation(dataview.createDataView2, arrayBuffer, 2); | ||
testDataViewCreation(dataview.createDataView2, arrayBuffer, 10); | ||
testDataViewCreation(dataview.createDataView3, arrayBuffer, 2, 4); | ||
testDataViewCreation(dataview.createDataView3, arrayBuffer, 10, 0); | ||
|
||
// @ts-ignore | ||
testInvalidRange(dataview.createDataView2, arrayBuffer, 11); | ||
testInvalidRange(dataview.createDataView3, arrayBuffer, 11, 0); | ||
testInvalidRange(dataview.createDataView3, arrayBuffer, 6, 5); | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
...addon_example/entry/src/ohosTest/ets/test/GlobalObject/GlobalObjectDeleteProperty.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { describe, it, DEFAULT } from '../util/framework.test'; | ||
import binding from '../util/binding'; | ||
import assert from '../util/assert.test'; | ||
|
||
export default function testCase() { | ||
describe("GlobalObjectDeleteProperty", () => { | ||
it("RunGlobalObjectDeleteProperty", DEFAULT, () => { | ||
const KEY_TYPE = { | ||
C_STR: 'KEY_AS_C_STRING', | ||
CPP_STR: 'KEY_AS_CPP_STRING', | ||
NAPI: 'KEY_AS_NAPI_VALUES', | ||
INT_32: 'KEY_AS_INT_32_NUM' | ||
}; | ||
|
||
function assertNotGlobalObjectHasNoProperty (key, keyType) { | ||
switch (keyType) { | ||
case KEY_TYPE.NAPI: | ||
assert.notStrictEqual(binding.globalObject.hasPropertyWithNapiValue(key), true); | ||
break; | ||
|
||
case KEY_TYPE.C_STR: | ||
assert.notStrictEqual(binding.globalObject.hasPropertyWithCStyleString(key), true); | ||
break; | ||
|
||
case KEY_TYPE.CPP_STR: | ||
assert.notStrictEqual(binding.globalObject.hasPropertyWithCppStyleString(key), true); | ||
break; | ||
|
||
case KEY_TYPE.INT_32: | ||
assert.notStrictEqual(binding.globalObject.hasPropertyWithInt32(key), true); | ||
break; | ||
} | ||
} | ||
|
||
function assertErrMessageIsThrown (propertyCheckExistenceFunction, errMsg) { | ||
assert.throws(() => { | ||
propertyCheckExistenceFunction(undefined); | ||
}, errMsg); | ||
} | ||
|
||
binding.globalObject.createMockTestObject(); | ||
|
||
binding.globalObject.deletePropertyWithCStyleString('c_str_key'); | ||
binding.globalObject.deletePropertyWithCppStyleString('cpp_string_key'); | ||
binding.globalObject.deletePropertyWithCppStyleString('circular'); | ||
binding.globalObject.deletePropertyWithInt32(15); | ||
binding.globalObject.deletePropertyWithNapiValue('2'); | ||
|
||
assertNotGlobalObjectHasNoProperty('c_str_key', KEY_TYPE.C_STR); | ||
assertNotGlobalObjectHasNoProperty('cpp_string_key', KEY_TYPE.CPP_STR); | ||
assertNotGlobalObjectHasNoProperty('circular', KEY_TYPE.CPP_STR); | ||
assertNotGlobalObjectHasNoProperty(15, true); | ||
assertNotGlobalObjectHasNoProperty('2', KEY_TYPE.NAPI); | ||
|
||
assertErrMessageIsThrown(binding.globalObject.hasPropertyWithCppStyleString, 'Error: A string was expected'); | ||
assertErrMessageIsThrown(binding.globalObject.hasPropertyWithCStyleString, 'Error: A string was expected'); | ||
assertErrMessageIsThrown(binding.globalObject.hasPropertyWithInt32, 'Error: A number was expected'); | ||
}) | ||
}) | ||
} |
63 changes: 63 additions & 0 deletions
63
ohos_addon_example/entry/src/ohosTest/ets/test/GlobalObject/GlobalObjectGetProperty.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { describe, it, DEFAULT } from '../util/framework.test'; | ||
import binding from '../util/binding'; | ||
import assert from '../util/assert.test'; | ||
|
||
export default function testCase() { | ||
describe("GlobalObjectGetProperty", () => { | ||
it("RunGlobalObjectGetProperty", DEFAULT, () => { | ||
const KEY_TYPE = { | ||
C_STR: 'KEY_AS_C_STRING', | ||
CPP_STR: 'KEY_AS_CPP_STRING', | ||
NAPI: 'KEY_AS_NAPI_VALUES', | ||
INT_32: 'KEY_AS_INT_32_NUM' | ||
}; | ||
|
||
binding.globalObject.createMockTestObject(); | ||
function assertGlobalObjectPropertyIs (key, attribute, keyType) { | ||
let napiObjectAttr; | ||
switch (keyType) { | ||
case KEY_TYPE.NAPI: | ||
napiObjectAttr = binding.globalObject.getPropertyWithNapiValue(key); | ||
assert.deepStrictEqual(attribute, napiObjectAttr); | ||
break; | ||
|
||
case KEY_TYPE.C_STR: | ||
napiObjectAttr = binding.globalObject.getPropertyWithCString(key); | ||
assert.deepStrictEqual(attribute, napiObjectAttr); | ||
break; | ||
|
||
case KEY_TYPE.CPP_STR: | ||
napiObjectAttr = binding.globalObject.getPropertyWithCppString(key); | ||
assert.deepStrictEqual(attribute, napiObjectAttr); | ||
break; | ||
|
||
case KEY_TYPE.INT_32: | ||
napiObjectAttr = binding.globalObject.getPropertyWithInt32(key); | ||
assert.deepStrictEqual(attribute, napiObjectAttr); | ||
break; | ||
} | ||
} | ||
|
||
function assertErrMessageIsThrown (propertyFetchFunction, errMsg) { | ||
assert.throws(() => { | ||
propertyFetchFunction(undefined); | ||
}, errMsg); | ||
} | ||
|
||
// @ts-ignore | ||
assertGlobalObjectPropertyIs('2', global['2'], KEY_TYPE.NAPI); | ||
// @ts-ignore | ||
assertGlobalObjectPropertyIs('c_str_key', global.c_str_key, KEY_TYPE.C_STR); | ||
// @ts-ignore | ||
assertGlobalObjectPropertyIs('cpp_string_key', global.cpp_string_key, KEY_TYPE.CPP_STR); | ||
// @ts-ignore | ||
assertGlobalObjectPropertyIs('circular', global.circular, KEY_TYPE.CPP_STR); | ||
// @ts-ignore | ||
assertGlobalObjectPropertyIs(15, global['15'], KEY_TYPE.INT_32); | ||
|
||
assertErrMessageIsThrown(binding.globalObject.getPropertyWithCString, 'Error: A string was expected'); | ||
assertErrMessageIsThrown(binding.globalObject.getPropertyWithCppString, 'Error: A string was expected'); | ||
assertErrMessageIsThrown(binding.globalObject.getPropertyWithInt32, 'Error: A number was expected'); | ||
}) | ||
}) | ||
} |
Oops, something went wrong.