Update Iot.js
[platform/upstream/iotjs.git] / test / run_pass / test_fs1.js
1 /* Copyright 2015-present Samsung Electronics Co., Ltd. and other contributors
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15
16
17
18 var fs = require('fs');
19 var assert = require('assert');
20
21
22 var srcFilePath = "../resources/test1.txt";
23 var dstFilePath = "../tmp/test_fs1.txt";
24
25 try {
26   var fd1 = fs.openSync(srcFilePath, 'r');
27   var buffer = new Buffer(128);
28   var bytes1 = fs.readSync(fd1, buffer, 0, buffer.length, 0);
29   fs.closeSync(fd1);
30
31   var fd2 = fs.openSync(dstFilePath, 'w');
32   var bytes2 = fs.writeSync(fd2, buffer, 0, bytes1, 0);
33   fs.closeSync(fd2);
34
35   assert.equal(bytes1, bytes2);
36
37   var fd3 = fs.openSync(srcFilePath, 'r');
38   var bytes3 = fs.readSync(fd3, buffer, 0, buffer.length, 0);
39   fs.closeSync(fd3);
40
41   assert.equal(bytes1, bytes3);
42
43   var result = 'TEST File Read & Write\n';
44
45   assert.equal(buffer.toString(), result);
46 } catch (err) {
47   throw err;
48 }