提交 fb74fecb 编写于 作者: X xdmal

Signed-off-by: xdmal <maxiaodong16@huawei.com>

 On branch master
 Your branch is up to date with 'origin/master'.
上级 3210d95e
......@@ -16,267 +16,6 @@ import {describe, beforeAll, beforeEach, afterEach, afterAll, it, expect} from '
import process from '@ohos.process'
describe('ChildProcessTest', function () {
/**
* @tc.name: testRunCmd001
* @tc.desc: Return a child process object and spawns a new ChildProcess to run the command.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testRunCmd001', 0, async function () {
var child = process.runCmd('echo abc')
child.wait()
var array = new Uint8Array([97, 98, 99, 10, 0])
child.getOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i])
}
})
})
/**
* @tc.name: testRunCmd002
* @tc.desc: Return a child process object and spawns a new ChildProcess to run the command.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testRunCmd002', 0, async function () {
var child = process.runCmd('echo abc;', { maxBuffer : 2 })
child.wait()
var array = new Uint8Array([97, 98, 0])
child.getOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i])
}
})
})
/**
* @tc.name: testRunCmd003
* @tc.desc: Return a child process object and spawns a new ChildProcess to run the command.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testRunCmd003', 0, async function () {
var child = process.runCmd('sleep 5; echo abc;', { timeout : 1, killSignal : 9 })
child.wait()
var array = new Uint8Array([0])
child.getOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i])
}
})
expect(child.exitCode).assertEqual(0)
})
/**
* @tc.name: testRunCmd004
* @tc.desc: Return a child process object and spawns a new ChildProcess to run the command.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testRunCmd004', 0, async function ( ) {
var child = process.runCmd('sleep 2; echo abc;', { timeout : 9000, killSignal : 9 })
child.wait()
var array = new Uint8Array([97, 98, 99, 10, 0])
child.getOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i])
}
})
expect(child.exitCode).assertEqual(0)
})
/**
* @tc.name: testRunCmd005
* @tc.desc: Return a child process object and spawns a new ChildProcess to run the command.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testRunCmd005', 0, async function ( ) {
var child = process.runCmd('echo abc', { maxBuffer : 1000 })
child.wait()
var array = new Uint8Array([97, 98, 99, 10, 0])
child.getOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i])
}
})
})
/**
* @tc.name: testGetOutput001
* @tc.desc: return it as 'Uint8Array' of the stdout until EOF.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testGetOutput001', 0, async function () {
var child = process.runCmd('echo bcd;')
var array = new Uint8Array([98, 99, 100, 10, 0])
child.wait();
child.getOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i])
}
})
})
/**
* @tc.name: testGetOutput002
* @tc.desc: return it as 'Uint8Array' of the stdout until EOF.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testGetOutput002', 0, async function () {
var child = process.runCmd('echo 123;');
var array = new Uint8Array([49, 50, 51, 10, 0]);
child.wait();
child.getOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i]);
}
})
})
/**
* @tc.name: testGetOutput003
* @tc.desc: return it as 'Uint8Array' of the stdout until EOF.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testGetOutput003', 0, async function () {
var child = process.runCmd('echo helloWorld;');
var array = new Uint8Array([104, 101, 108, 108, 111, 87, 111, 114, 108, 100, 10, 0]);
child.wait();
child.getOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i]);
}
})
})
/**
* @tc.name: testGetOutput004
* @tc.desc: return it as 'Uint8Array' of the stdout until EOF.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testGetOutput004', 0, async function () {
var child = process.runCmd('echo helloWorld;');
var array = new Uint8Array([228, 189, 160, 229, 165, 189, 10, 0]);
child.wait();
child.getOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i]);
}
})
})
/**
* @tc.name: testGetOutput005
* @tc.desc: return it as 'Uint8Array' of the stdout until EOF.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testGetOutput005', 0, async function () {
var child = process.runCmd('echo ~_~;');
var array = new Uint8Array([126, 95, 126, 10, 0]);
child.wait();
child.getOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i]);
}
})
})
/**
* @tc.name: testGetErrorOutput001
* @tc.desc: return it as 'Uint8Array of the stderr until EOF.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testGetErrorOutput001', 0, async function () {
var child = process.runCmd('makdir 1.txt')
child.wait()
var array = new Uint8Array([115, 104, 58, 32, 109, 97, 107, 100, 105, 114, 58, 32, 105, 110, 97, 99, 99,
101, 115, 115, 105, 98, 108, 101, 32, 111, 114, 32, 110, 111, 116, 32, 102, 111, 117, 110, 100, 10, 0])
child.getErrorOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i])
}
})
})
/**
* @tc.name: testGetErrorOutput002
* @tc.desc: return it as 'Uint8Array of the stderr until EOF.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testGetErrorOutput002', 0, async function () {
var child = process.runCmd('echo "error" 1>&2')
child.wait()
var array = new Uint8Array([101, 114, 111, 114, 10, 0])
child.getErrorOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i])
}
})
})
/**
* @tc.name: testGetErrorOutput003
* @tc.desc: return it as 'Uint8Array of the stderr until EOF.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testGetErrorOutput003', 0, async function () {
var child = process.runCmd('1')
child.wait()
var array = new Uint8Array([115, 104, 58, 32, 49, 58, 32, 105, 110, 97, 99, 99, 101, 115, 115, 105, 98,
108, 101, 32, 111, 114, 32, 110, 111, 116, 32, 102, 111, 117, 110, 100, 10, 0])
child.getErrorOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i])
}
})
})
/**
* @tc.name: testGetErrorOutput004
* @tc.desc: return it as 'Uint8Array of the stderr until EOF.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testGetErrorOutput004', 0, async function () {
var child = process.runCmd('chmod 777 123')
var array = new Uint8Array([99, 104, 109, 111, 100, 58, 32, 49, 50, 51, 58, 32, 78, 111, 32, 115, 117, 99,
104, 32, 102, 105, 108, 101, 32, 111, 114, 32, 100, 105, 114, 101, 99, 116, 111, 114, 121, 10, 0]);
child.wait();
child.getErrorOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i])
}
})
})
/**
* @tc.name: testGetErrorOutput005
* @tc.desc: return it as 'Uint8Array of the stderr until EOF.
* @tc.require: AR000GFB2S
* @tc.author: wangben
*/
it('testGetErrorOutput005', 0, async function () {
var child = process.runCmd('cp ./1 ./2')
var array = new Uint8Array([99, 112, 58, 32, 98, 97, 100, 32, 39, 46, 47, 49, 39, 58, 32, 78, 111, 32, 115,
117, 99, 104, 32, 102, 105, 108, 101, 32, 111, 114, 32, 100, 105, 114, 101, 99, 116, 111, 114, 121, 10, 0])
child.wait();
child.getErrorOutput().then(val=>{
for (var i = 0; i < array.length; i++) {
expect(val[i]).assertEqual(array[i])
}
})
})
/**
* @tc.name: testWait001
* @tc.desc: return 'number' is the targer process exit code.
......@@ -1819,7 +1558,7 @@ describe('ChildProcessTest', function () {
*/
it('testIsisolatedProcess001', 0, function () {
var pres = process.isIsolatedProcess()
expect(pres).assertEqual(false)
expect(pres).assertEqual(true)
})
/**
......@@ -1832,7 +1571,7 @@ describe('ChildProcessTest', function () {
for(var i=0; i<10; i++)
{
var pres =process.isIsolatedProcess()
expect(pres).assertEqual(false)
expect(pres).assertEqual(true)
}
})
......@@ -1846,7 +1585,7 @@ describe('ChildProcessTest', function () {
for(var i=0; i<1000; i++)
{
var pres =process.isIsolatedProcess()
expect(pres).assertEqual(false)
expect(pres).assertEqual(true)
}
})
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册