Browse Source

Testcase for buffer behavior changes

pull/484/head
Sami Vaarala 9 years ago
parent
commit
1aa829a829
  1. 58
      tests/ecmascript/test-bi-typedarray-constructor.js
  2. 42
      tests/ecmascript/test-bi-typedarray-misc-zeroing.js

58
tests/ecmascript/test-bi-typedarray-constructor.js

@ -1699,3 +1699,61 @@ try {
} catch (e) {
print(e.stack || e);
}
/*===
plain buffer argument
object |00666f6fff| |00666f6fff|
|00666f6fff| |fe666f6fff| [object ArrayBuffer]
object |00666f6fff| |000066006f006f00ff00|
|00666f6fff| |feca66006f006f00ff00| [object ArrayBuffer]
buffer |00666f6fff| |00666f6fff|
|00666f6fff| |fe666f6fff| [object ArrayBuffer]
buffer |00666f6fff| |000066006f006f00ff00|
|00666f6fff| |feca66006f006f00ff00| [object ArrayBuffer]
===*/
/* Since Duktape 1.4.0 a plain Duktape buffer is accepted similarly to a
* Duktape.Buffer. Behavior in Duktape 1.3.0 is a bit confusing:
*
* duk> u8 = new Uint8Array(new Duktape.Buffer('foobar'))
* = [object Uint8Array]
* duk> Duktape.enc('jx', u8)
* = |666f6f626172|
* duk> u8 = new Uint8Array(Duktape.Buffer('foobar'))
* = [object Uint8Array]
* duk> Duktape.enc('jx', u8)
* = ||
*/
function plainBufferArgumentTest() {
var buf, view;
function test(buf, view) {
print(typeof buf, Duktape.enc('jx', buf), Duktape.enc('jx', view));
view[0] = 0xcafe; // demonstrate view does not share underlying buffer
print(Duktape.enc('jx', buf), Duktape.enc('jx', view), Object.prototype.toString.call(view.buffer));
}
buf = new Duktape.Buffer(Duktape.dec('hex', '00666f6fff'));
view = new Uint8Array(buf);
test(buf, view);
buf = new Duktape.Buffer(Duktape.dec('hex', '00666f6fff'));
view = new Int16Array(buf);
test(buf, view);
buf = Duktape.dec('hex', '00666f6fff');
view = new Uint8Array(buf);
test(buf, view);
buf = Duktape.dec('hex', '00666f6fff');
view = new Int16Array(buf);
test(buf, view);
}
try {
print('plain buffer argument');
plainBufferArgumentTest();
} catch (e) {
print(e.stack || e);
}

42
tests/ecmascript/test-bi-typedarray-misc-zeroing.js

@ -0,0 +1,42 @@
/*
* Manual test for zeroing behavior with DUK_USE_ZERO_BUFFER_DATA unset.
*
* Even with zeroing disabled, ArrayBuffer and typedarray constructors must
* zero result buffers. Node.js buffers don't need to be zeroed (and Node.js
* won't do that).
*
* The expect string is for DUK_USE_ZERO_BUFFER_DATA set, i.e. all data is
* zeroed (which is the default). This is correct for ArrayBuffer and
* typedarray views, but not for Node.js.
*/
/*---
{
"custom": true
}
---*/
/*===
|00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000|
|00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000|
{type:"Buffer",data:[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}
===*/
function test() {
var buf;
buf = new ArrayBuffer(256);
print(Duktape.enc('jx', buf));
buf = new Uint16Array(128);
print(Duktape.enc('jx', buf));
buf = new Buffer(256);
print(Duktape.enc('jx', buf));
}
try {
test();
} catch (e) {
print(e.stack || e);
}
Loading…
Cancel
Save