11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_cirequire('../common'); 41cb0ef41Sopenharmony_ciconst assert = require('assert'); 51cb0ef41Sopenharmony_ciconst path = require('path'); 61cb0ef41Sopenharmony_ciconst fs = require('fs'); 71cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_citmpdir.refresh(); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst expected = 'ümlaut. Лорем 運務ホソモ指及 आपको करने विकास 紙読決多密所 أضف'; 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ciconst getFileName = (i) => path.join(tmpdir.path, `writev_sync_${i}.txt`); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ci/** 161cb0ef41Sopenharmony_ci * Testing with a array of buffers input 171cb0ef41Sopenharmony_ci */ 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci// fs.writevSync with array of buffers with all parameters 201cb0ef41Sopenharmony_ci{ 211cb0ef41Sopenharmony_ci const filename = getFileName(1); 221cb0ef41Sopenharmony_ci const fd = fs.openSync(filename, 'w'); 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci const buffer = Buffer.from(expected); 251cb0ef41Sopenharmony_ci const bufferArr = [buffer, buffer]; 261cb0ef41Sopenharmony_ci const expectedLength = bufferArr.length * buffer.byteLength; 271cb0ef41Sopenharmony_ci 281cb0ef41Sopenharmony_ci let written = fs.writevSync(fd, [Buffer.from('')], null); 291cb0ef41Sopenharmony_ci assert.strictEqual(written, 0); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci written = fs.writevSync(fd, bufferArr, null); 321cb0ef41Sopenharmony_ci assert.strictEqual(written, expectedLength); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_ci fs.closeSync(fd); 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci assert(Buffer.concat(bufferArr).equals(fs.readFileSync(filename))); 371cb0ef41Sopenharmony_ci} 381cb0ef41Sopenharmony_ci 391cb0ef41Sopenharmony_ci// fs.writevSync with array of buffers without position 401cb0ef41Sopenharmony_ci{ 411cb0ef41Sopenharmony_ci const filename = getFileName(2); 421cb0ef41Sopenharmony_ci const fd = fs.openSync(filename, 'w'); 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ci const buffer = Buffer.from(expected); 451cb0ef41Sopenharmony_ci const bufferArr = [buffer, buffer, buffer]; 461cb0ef41Sopenharmony_ci const expectedLength = bufferArr.length * buffer.byteLength; 471cb0ef41Sopenharmony_ci 481cb0ef41Sopenharmony_ci let written = fs.writevSync(fd, [Buffer.from('')]); 491cb0ef41Sopenharmony_ci assert.strictEqual(written, 0); 501cb0ef41Sopenharmony_ci 511cb0ef41Sopenharmony_ci written = fs.writevSync(fd, bufferArr); 521cb0ef41Sopenharmony_ci assert.strictEqual(written, expectedLength); 531cb0ef41Sopenharmony_ci 541cb0ef41Sopenharmony_ci fs.closeSync(fd); 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci assert(Buffer.concat(bufferArr).equals(fs.readFileSync(filename))); 571cb0ef41Sopenharmony_ci} 581cb0ef41Sopenharmony_ci 591cb0ef41Sopenharmony_ci// fs.writevSync with empty array of buffers 601cb0ef41Sopenharmony_ci{ 611cb0ef41Sopenharmony_ci const filename = getFileName(3); 621cb0ef41Sopenharmony_ci const fd = fs.openSync(filename, 'w'); 631cb0ef41Sopenharmony_ci const written = fs.writevSync(fd, []); 641cb0ef41Sopenharmony_ci assert.strictEqual(written, 0); 651cb0ef41Sopenharmony_ci fs.closeSync(fd); 661cb0ef41Sopenharmony_ci 671cb0ef41Sopenharmony_ci} 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci/** 701cb0ef41Sopenharmony_ci * Testing with wrong input types 711cb0ef41Sopenharmony_ci */ 721cb0ef41Sopenharmony_ci{ 731cb0ef41Sopenharmony_ci const filename = getFileName(4); 741cb0ef41Sopenharmony_ci const fd = fs.openSync(filename, 'w'); 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ci [false, 'test', {}, [{}], ['sdf'], null, undefined].forEach((i) => { 771cb0ef41Sopenharmony_ci assert.throws( 781cb0ef41Sopenharmony_ci () => fs.writevSync(fd, i, null), { 791cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 801cb0ef41Sopenharmony_ci name: 'TypeError' 811cb0ef41Sopenharmony_ci } 821cb0ef41Sopenharmony_ci ); 831cb0ef41Sopenharmony_ci }); 841cb0ef41Sopenharmony_ci 851cb0ef41Sopenharmony_ci fs.closeSync(fd); 861cb0ef41Sopenharmony_ci} 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ci// fs.writevSync with wrong fd types 891cb0ef41Sopenharmony_ci[false, 'test', {}, [{}], null, undefined].forEach((i) => { 901cb0ef41Sopenharmony_ci assert.throws( 911cb0ef41Sopenharmony_ci () => fs.writevSync(i), 921cb0ef41Sopenharmony_ci { 931cb0ef41Sopenharmony_ci code: 'ERR_INVALID_ARG_TYPE', 941cb0ef41Sopenharmony_ci name: 'TypeError' 951cb0ef41Sopenharmony_ci } 961cb0ef41Sopenharmony_ci ); 971cb0ef41Sopenharmony_ci}); 98