11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_ciconst common = require('../common');
41cb0ef41Sopenharmony_ciconst fixtures = require('../common/fixtures');
51cb0ef41Sopenharmony_ciconst fs = require('fs');
61cb0ef41Sopenharmony_ciconst assert = require('assert');
71cb0ef41Sopenharmony_ciconst filepath = fixtures.path('x.txt');
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ciconst expected = Buffer.from('xyz\n');
101cb0ef41Sopenharmony_ciconst defaultBufferAsync = Buffer.alloc(16384);
111cb0ef41Sopenharmony_ciconst bufferAsOption = Buffer.allocUnsafe(expected.byteLength);
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_cifunction testValid(message, ...options) {
141cb0ef41Sopenharmony_ci  const paramsMsg = `${message} (as params)`;
151cb0ef41Sopenharmony_ci  const paramsFilehandle = fs.openSync(filepath, 'r');
161cb0ef41Sopenharmony_ci  fs.read(paramsFilehandle, ...options, common.mustSucceed((bytesRead, buffer) => {
171cb0ef41Sopenharmony_ci    assert.strictEqual(bytesRead, expected.byteLength, paramsMsg);
181cb0ef41Sopenharmony_ci    assert.deepStrictEqual(defaultBufferAsync.byteLength, buffer.byteLength, paramsMsg);
191cb0ef41Sopenharmony_ci    fs.closeSync(paramsFilehandle);
201cb0ef41Sopenharmony_ci  }));
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci  const optionsMsg = `${message} (as options)`;
231cb0ef41Sopenharmony_ci  const optionsFilehandle = fs.openSync(filepath, 'r');
241cb0ef41Sopenharmony_ci  fs.read(optionsFilehandle, bufferAsOption, ...options, common.mustSucceed((bytesRead, buffer) => {
251cb0ef41Sopenharmony_ci    assert.strictEqual(bytesRead, expected.byteLength, optionsMsg);
261cb0ef41Sopenharmony_ci    assert.deepStrictEqual(bufferAsOption.byteLength, buffer.byteLength, optionsMsg);
271cb0ef41Sopenharmony_ci    fs.closeSync(optionsFilehandle);
281cb0ef41Sopenharmony_ci  }));
291cb0ef41Sopenharmony_ci}
301cb0ef41Sopenharmony_ci
311cb0ef41Sopenharmony_citestValid('Not passing in any object');
321cb0ef41Sopenharmony_citestValid('Passing in a null', null);
331cb0ef41Sopenharmony_citestValid('Passing in an empty object', common.mustNotMutateObjectDeep({}));
341cb0ef41Sopenharmony_citestValid('Passing in an object', common.mustNotMutateObjectDeep({
351cb0ef41Sopenharmony_ci  offset: 0,
361cb0ef41Sopenharmony_ci  length: bufferAsOption.byteLength,
371cb0ef41Sopenharmony_ci  position: 0,
381cb0ef41Sopenharmony_ci}));
39