Skip to content

Commit

Permalink
Fix test failures on linuxOne and AIX
Browse files Browse the repository at this point in the history
Currently, the test only considers little endian. So, this patch adds
a endian check function(IsLittleEndian()) and then use it instead of
hardcoded value.

Fixes: nodejs/node-addon-api#230
PR-URL: nodejs/node-addon-api#232
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
  • Loading branch information
Marlyfleitas committed Mar 5, 2018
1 parent cf9bc8c commit 3c9e134
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions test/dataview/dataview_read_write.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ function test(binding) {
eval(`binding.dataview_read_write.set${type}(dataview, offset, value)`);
}

function isLittleEndian() {
const buffer = new ArrayBuffer(2);
new DataView(buffer).setInt16(0, 256, true /* littleEndian */);
return new Int16Array(buffer)[0] === 256;
}

function jsReadDataView(dataview, type, offset, value) {
return eval(`dataview.get${type}(offset, true)`);
return eval(`dataview.get${type}(offset, isLittleEndian())`);
}

function jsWriteDataView(dataview, type, offset, value) {
eval(`dataview.set${type}(offset, value, true)`);
eval(`dataview.set${type}(offset, value, isLittleEndian())`);
}

function testReadData(dataview, type, offset, value) {
Expand Down

0 comments on commit 3c9e134

Please sign in to comment.