11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common'); 31cb0ef41Sopenharmony_ciconst assert = require('assert'); 41cb0ef41Sopenharmony_ciconst fs = require('fs'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ci// This test ensures that input for fchmod is valid, testing for valid 71cb0ef41Sopenharmony_ci// inputs for fd and mode 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ci// Check input type 101cb0ef41Sopenharmony_ci[false, null, undefined, {}, [], ''].forEach((input) => { 111cb0ef41Sopenharmony_ci const errObj = { 121cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 131cb0ef41Sopenharmony_ci name: 'TypeError', 141cb0ef41Sopenharmony_ci message: 'The "fd" argument must be of type number.' + 151cb0ef41Sopenharmony_ci common.invalidArgTypeHelper(input) 161cb0ef41Sopenharmony_ci }; 171cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmod(input), errObj); 181cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmodSync(input), errObj); 191cb0ef41Sopenharmony_ci}); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci[false, null, {}, []].forEach((input) => { 231cb0ef41Sopenharmony_ci const errObj = { 241cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 251cb0ef41Sopenharmony_ci }; 261cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmod(1, input), errObj); 271cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmodSync(1, input), errObj); 281cb0ef41Sopenharmony_ci}); 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ciassert.throws(() => fs.fchmod(1, '123x'), { 311cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_VALUE' 321cb0ef41Sopenharmony_ci}); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci[-1, 2 ** 32].forEach((input) => { 351cb0ef41Sopenharmony_ci const errObj = { 361cb0ef41Sopenharmony_ci code: 'ERR_OUT_OF_RANGE', 371cb0ef41Sopenharmony_ci name: 'RangeError', 381cb0ef41Sopenharmony_ci message: 'The value of "fd" is out of range. It must be >= 0 && <= ' + 391cb0ef41Sopenharmony_ci `2147483647. Received ${input}` 401cb0ef41Sopenharmony_ci }; 411cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmod(input), errObj); 421cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmodSync(input), errObj); 431cb0ef41Sopenharmony_ci}); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci[-1, 2 ** 32].forEach((input) => { 461cb0ef41Sopenharmony_ci const errObj = { 471cb0ef41Sopenharmony_ci code: 'ERR_OUT_OF_RANGE', 481cb0ef41Sopenharmony_ci name: 'RangeError', 491cb0ef41Sopenharmony_ci message: 'The value of "mode" is out of range. It must be >= 0 && <= ' + 501cb0ef41Sopenharmony_ci `4294967295. Received ${input}` 511cb0ef41Sopenharmony_ci }; 521cb0ef41Sopenharmony_ci 531cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmod(1, input), errObj); 541cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmodSync(1, input), errObj); 551cb0ef41Sopenharmony_ci}); 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci[NaN, Infinity].forEach((input) => { 581cb0ef41Sopenharmony_ci const errObj = { 591cb0ef41Sopenharmony_ci code: 'ERR_OUT_OF_RANGE', 601cb0ef41Sopenharmony_ci name: 'RangeError', 611cb0ef41Sopenharmony_ci message: 'The value of "fd" is out of range. It must be an integer. ' + 621cb0ef41Sopenharmony_ci `Received ${input}` 631cb0ef41Sopenharmony_ci }; 641cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmod(input), errObj); 651cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmodSync(input), errObj); 661cb0ef41Sopenharmony_ci errObj.message = errObj.message.replace('fd', 'mode'); 671cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmod(1, input), errObj); 681cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmodSync(1, input), errObj); 691cb0ef41Sopenharmony_ci}); 701cb0ef41Sopenharmony_ci 711cb0ef41Sopenharmony_ci[1.5].forEach((input) => { 721cb0ef41Sopenharmony_ci const errObj = { 731cb0ef41Sopenharmony_ci code: 'ERR_OUT_OF_RANGE', 741cb0ef41Sopenharmony_ci name: 'RangeError', 751cb0ef41Sopenharmony_ci message: 'The value of "fd" is out of range. It must be an integer. ' + 761cb0ef41Sopenharmony_ci `Received ${input}` 771cb0ef41Sopenharmony_ci }; 781cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmod(input), errObj); 791cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmodSync(input), errObj); 801cb0ef41Sopenharmony_ci errObj.message = errObj.message.replace('fd', 'mode'); 811cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmod(1, input), errObj); 821cb0ef41Sopenharmony_ci assert.throws(() => fs.fchmodSync(1, input), errObj); 831cb0ef41Sopenharmony_ci}); 84