| 1 |
import QtQuick 2.0 |
| 2 |
import io.thp.pyotherside 1.5 |
| 3 |
import QtTest 1.2 |
| 4 |
|
| 5 |
TestCase { |
| 6 |
Python { |
| 7 |
id: py |
| 8 |
Component.onCompleted: { |
| 9 |
addImportPath(Qt.resolvedUrl('.')); |
| 10 |
importModule_sync('tst_bytes'); |
| 11 |
} |
| 12 |
} |
| 13 |
|
| 14 |
function test_bytes_from_python() { |
| 15 |
var buf = py.evaluate('tst_bytes.get_bytes()'); |
| 16 |
var view = new DataView(buf); |
| 17 |
|
| 18 |
var a = view.getInt8(0, true); |
| 19 |
var b = view.getInt16(1, true); |
| 20 |
var c = view.getInt32(3, true); |
| 21 |
|
| 22 |
console.log('Data retrieved from Python (as string):', buf); |
| 23 |
console.log('First element decoded:', a); |
| 24 |
console.log('Second element decoded:', b); |
| 25 |
console.log('Third element decoded:', c); |
| 26 |
|
| 27 |
compare(a, 123); |
| 28 |
compare(b, 456); |
| 29 |
compare(c, 789); |
| 30 |
} |
| 31 |
|
| 32 |
function test_bytes_to_python() { |
| 33 |
var buf = new ArrayBuffer(8); |
| 34 |
var view = new DataView(buf); |
| 35 |
|
| 36 |
view.setInt16(0, 1337, true); |
| 37 |
view.setInt16(2, -4711, true); |
| 38 |
view.setUInt32(4, 0xCAFEBABE, true); |
| 39 |
|
| 40 |
compare(py.call_sync('tst_bytes.set_bytes', [buf]), true); |
| 41 |
} |
| 42 |
} |