11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst { execFile } = require('child_process');
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_cifunction checkFactory(streamName) {
71cb0ef41Sopenharmony_ci  return common.mustCall((err) => {
81cb0ef41Sopenharmony_ci    assert(err instanceof RangeError);
91cb0ef41Sopenharmony_ci    assert.strictEqual(err.message, `${streamName} maxBuffer length exceeded`);
101cb0ef41Sopenharmony_ci    assert.strictEqual(err.code, 'ERR_CHILD_PROCESS_STDIO_MAXBUFFER');
111cb0ef41Sopenharmony_ci  });
121cb0ef41Sopenharmony_ci}
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci// default value
151cb0ef41Sopenharmony_ci{
161cb0ef41Sopenharmony_ci  execFile(
171cb0ef41Sopenharmony_ci    process.execPath,
181cb0ef41Sopenharmony_ci    ['-e', 'console.log("a".repeat(1024 * 1024))'],
191cb0ef41Sopenharmony_ci    checkFactory('stdout')
201cb0ef41Sopenharmony_ci  );
211cb0ef41Sopenharmony_ci}
221cb0ef41Sopenharmony_ci
231cb0ef41Sopenharmony_ci// default value
241cb0ef41Sopenharmony_ci{
251cb0ef41Sopenharmony_ci  execFile(
261cb0ef41Sopenharmony_ci    process.execPath,
271cb0ef41Sopenharmony_ci    ['-e', 'console.log("a".repeat(1024 * 1024 - 1))'],
281cb0ef41Sopenharmony_ci    common.mustSucceed((stdout, stderr) => {
291cb0ef41Sopenharmony_ci      assert.strictEqual(stdout.trim(), 'a'.repeat(1024 * 1024 - 1));
301cb0ef41Sopenharmony_ci      assert.strictEqual(stderr, '');
311cb0ef41Sopenharmony_ci    })
321cb0ef41Sopenharmony_ci  );
331cb0ef41Sopenharmony_ci}
341cb0ef41Sopenharmony_ci
351cb0ef41Sopenharmony_ci{
361cb0ef41Sopenharmony_ci  const options = { maxBuffer: Infinity };
371cb0ef41Sopenharmony_ci
381cb0ef41Sopenharmony_ci  execFile(
391cb0ef41Sopenharmony_ci    process.execPath,
401cb0ef41Sopenharmony_ci    ['-e', 'console.log("hello world");'],
411cb0ef41Sopenharmony_ci    options,
421cb0ef41Sopenharmony_ci    common.mustSucceed((stdout, stderr) => {
431cb0ef41Sopenharmony_ci      assert.strictEqual(stdout.trim(), 'hello world');
441cb0ef41Sopenharmony_ci      assert.strictEqual(stderr, '');
451cb0ef41Sopenharmony_ci    })
461cb0ef41Sopenharmony_ci  );
471cb0ef41Sopenharmony_ci}
481cb0ef41Sopenharmony_ci
491cb0ef41Sopenharmony_ci{
501cb0ef41Sopenharmony_ci  execFile('echo', ['hello world'], { maxBuffer: 5 }, checkFactory('stdout'));
511cb0ef41Sopenharmony_ci}
521cb0ef41Sopenharmony_ci
531cb0ef41Sopenharmony_ciconst unicode = '中文测试'; // length = 4, byte length = 12
541cb0ef41Sopenharmony_ci
551cb0ef41Sopenharmony_ci{
561cb0ef41Sopenharmony_ci  execFile(
571cb0ef41Sopenharmony_ci    process.execPath,
581cb0ef41Sopenharmony_ci    ['-e', `console.log('${unicode}');`],
591cb0ef41Sopenharmony_ci    { maxBuffer: 10 },
601cb0ef41Sopenharmony_ci    checkFactory('stdout'));
611cb0ef41Sopenharmony_ci}
621cb0ef41Sopenharmony_ci
631cb0ef41Sopenharmony_ci{
641cb0ef41Sopenharmony_ci  execFile(
651cb0ef41Sopenharmony_ci    process.execPath,
661cb0ef41Sopenharmony_ci    ['-e', `console.error('${unicode}');`],
671cb0ef41Sopenharmony_ci    { maxBuffer: 10 },
681cb0ef41Sopenharmony_ci    checkFactory('stderr')
691cb0ef41Sopenharmony_ci  );
701cb0ef41Sopenharmony_ci}
711cb0ef41Sopenharmony_ci
721cb0ef41Sopenharmony_ci{
731cb0ef41Sopenharmony_ci  const child = execFile(
741cb0ef41Sopenharmony_ci    process.execPath,
751cb0ef41Sopenharmony_ci    ['-e', `console.log('${unicode}');`],
761cb0ef41Sopenharmony_ci    { encoding: null, maxBuffer: 10 },
771cb0ef41Sopenharmony_ci    checkFactory('stdout')
781cb0ef41Sopenharmony_ci  );
791cb0ef41Sopenharmony_ci
801cb0ef41Sopenharmony_ci  child.stdout.setEncoding('utf-8');
811cb0ef41Sopenharmony_ci}
821cb0ef41Sopenharmony_ci
831cb0ef41Sopenharmony_ci{
841cb0ef41Sopenharmony_ci  const child = execFile(
851cb0ef41Sopenharmony_ci    process.execPath,
861cb0ef41Sopenharmony_ci    ['-e', `console.error('${unicode}');`],
871cb0ef41Sopenharmony_ci    { encoding: null, maxBuffer: 10 },
881cb0ef41Sopenharmony_ci    checkFactory('stderr')
891cb0ef41Sopenharmony_ci  );
901cb0ef41Sopenharmony_ci
911cb0ef41Sopenharmony_ci  child.stderr.setEncoding('utf-8');
921cb0ef41Sopenharmony_ci}
93