11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ci
31cb0ef41Sopenharmony_cirequire('../common');
41cb0ef41Sopenharmony_ciconst assert = require('assert');
51cb0ef41Sopenharmony_ciconst fs = require('fs');
61cb0ef41Sopenharmony_ci
71cb0ef41Sopenharmony_cifunction testFd(input, errObj) {
81cb0ef41Sopenharmony_ci  assert.throws(() => fs.fchown(input), errObj);
91cb0ef41Sopenharmony_ci  assert.throws(() => fs.fchownSync(input), errObj);
101cb0ef41Sopenharmony_ci}
111cb0ef41Sopenharmony_ci
121cb0ef41Sopenharmony_cifunction testUid(input, errObj) {
131cb0ef41Sopenharmony_ci  assert.throws(() => fs.fchown(1, input), errObj);
141cb0ef41Sopenharmony_ci  assert.throws(() => fs.fchownSync(1, input), errObj);
151cb0ef41Sopenharmony_ci}
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_cifunction testGid(input, errObj) {
181cb0ef41Sopenharmony_ci  assert.throws(() => fs.fchown(1, 1, input), errObj);
191cb0ef41Sopenharmony_ci  assert.throws(() => fs.fchownSync(1, 1, input), errObj);
201cb0ef41Sopenharmony_ci}
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci['', false, null, undefined, {}, []].forEach((input) => {
231cb0ef41Sopenharmony_ci  const errObj = {
241cb0ef41Sopenharmony_ci    code: 'ERR_INVALID_ARG_TYPE',
251cb0ef41Sopenharmony_ci    name: 'TypeError',
261cb0ef41Sopenharmony_ci    message: /fd|uid|gid/
271cb0ef41Sopenharmony_ci  };
281cb0ef41Sopenharmony_ci  testFd(input, errObj);
291cb0ef41Sopenharmony_ci  testUid(input, errObj);
301cb0ef41Sopenharmony_ci  testGid(input, errObj);
311cb0ef41Sopenharmony_ci});
321cb0ef41Sopenharmony_ci
331cb0ef41Sopenharmony_ci[Infinity, NaN].forEach((input) => {
341cb0ef41Sopenharmony_ci  const errObj = {
351cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
361cb0ef41Sopenharmony_ci    name: 'RangeError',
371cb0ef41Sopenharmony_ci    message: 'The value of "fd" is out of range. It must be an integer. ' +
381cb0ef41Sopenharmony_ci             `Received ${input}`
391cb0ef41Sopenharmony_ci  };
401cb0ef41Sopenharmony_ci  testFd(input, errObj);
411cb0ef41Sopenharmony_ci  errObj.message = errObj.message.replace('fd', 'uid');
421cb0ef41Sopenharmony_ci  testUid(input, errObj);
431cb0ef41Sopenharmony_ci  errObj.message = errObj.message.replace('uid', 'gid');
441cb0ef41Sopenharmony_ci  testGid(input, errObj);
451cb0ef41Sopenharmony_ci});
461cb0ef41Sopenharmony_ci
471cb0ef41Sopenharmony_ci[-2, 2 ** 32].forEach((input) => {
481cb0ef41Sopenharmony_ci  const errObj = {
491cb0ef41Sopenharmony_ci    code: 'ERR_OUT_OF_RANGE',
501cb0ef41Sopenharmony_ci    name: 'RangeError',
511cb0ef41Sopenharmony_ci    message: 'The value of "fd" is out of range. It must be ' +
521cb0ef41Sopenharmony_ci             `>= 0 && <= 2147483647. Received ${input}`
531cb0ef41Sopenharmony_ci  };
541cb0ef41Sopenharmony_ci  testFd(input, errObj);
551cb0ef41Sopenharmony_ci  errObj.message = 'The value of "uid" is out of range. It must be >= -1 && ' +
561cb0ef41Sopenharmony_ci    `<= 4294967295. Received ${input}`;
571cb0ef41Sopenharmony_ci  testUid(input, errObj);
581cb0ef41Sopenharmony_ci  errObj.message = errObj.message.replace('uid', 'gid');
591cb0ef41Sopenharmony_ci  testGid(input, errObj);
601cb0ef41Sopenharmony_ci});
61