diff options
author | Denis Shienkov <denis.shienkov@gmail.com> | 2017-10-19 16:40:12 +0300 |
---|---|---|
committer | Denis Shienkov <denis.shienkov@gmail.com> | 2017-11-07 05:49:49 +0000 |
commit | 66aa42314346a49b1219df125b730349e8051f05 (patch) | |
tree | b8c066ab804eda2db980c18c3d3dc35f3ce41acf /tests/auto/blackbox/testdata/jsextensions-binaryfile | |
parent | 583aad43f59fa52baddb720946de7e1eb6c081ec (diff) |
Add BinaryFile service to manipulate binary files
[ChangeLog] Added the BinaryFile service for reading
and writing binary data files.
Change-Id: I93378c448a367472c4dd9ad5e715f70d88d7f58e
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'tests/auto/blackbox/testdata/jsextensions-binaryfile')
-rw-r--r-- | tests/auto/blackbox/testdata/jsextensions-binaryfile/binaryfile.qbs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/auto/blackbox/testdata/jsextensions-binaryfile/binaryfile.qbs b/tests/auto/blackbox/testdata/jsextensions-binaryfile/binaryfile.qbs new file mode 100644 index 000000000..7d3ada851 --- /dev/null +++ b/tests/auto/blackbox/testdata/jsextensions-binaryfile/binaryfile.qbs @@ -0,0 +1,48 @@ +import qbs +import qbs.BinaryFile + +Product { + type: ["dummy"] + Rule { + multiplex: true + Artifact { + filePath: "dummy.dat" + fileTags: ["dummy"] + } + prepare: { + var commands = []; + var cmd = new JavaScriptCommand(); + cmd.silent = true; + cmd.sourceCode = function() { + var source = new BinaryFile("source.dat", BinaryFile.WriteOnly); + source.write([ 0x01, 0x02 ]); // First data. + // Do not close the file to test the auto close functionality. + }; + commands.push(cmd); + cmd = new JavaScriptCommand(); + cmd.silent = true; + cmd.sourceCode = function() { + source = new BinaryFile("source.dat", BinaryFile.ReadWrite); + source.seek(source.size()); + source.write([ 0x03, 0x04 ]); // Second data. + source.close(); + source = new BinaryFile("source.dat", BinaryFile.ReadWrite); + var destination = new BinaryFile("destination.dat", BinaryFile.WriteOnly); + destination.write(source.atEof() ? [ 0xFF ] : [ 0x00 ]); + while (true) { + var data = source.read(1); + if (!data || data.length == 0) + break; + destination.write(data); + } + source.resize(0); // truncate + destination.write([ 0x05, 0x06 ]); // Third data. + destination.write(source.atEof() ? [ 0xFF ] : [ 0x00 ]); + source.close(); + destination.close(); + }; + commands.push(cmd); + return commands; + } + } +} |