Upload packaging folder
[platform/upstream/iotjs.git] / tools / test / run_pass / test_fs_writefile_unlink.js
1 /* Copyright 2016-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   @STDOUT=Pass
18  */
19
20 var fs = require('fs');
21 var assert = require('assert');
22
23 var file1 = "../resources/tobeornottobe.txt";
24 var file2 = "../resources/tobeornottobe_async.txt";
25
26 fs.readFile(file1, function(err, buf1) {
27   assert.equal(err, null);
28   fs.writeFile(file2, buf1, function(err) {
29     assert.equal(err, null);
30     fs.exists(file2, function(exists) {
31       assert.equal(exists, true);
32       fs.readFile(file1, function(err, buf2) {
33         assert.equal(err, null);
34         assert.equal(buf1.toString(), buf2.toString());
35         fs.unlink(file2, function(err) {
36           assert.equal(err, null);
37           fs.exists(file2, function(exists) {
38             assert.equal(exists, false);
39             console.log("Pass");
40           });
41         });
42       });
43     });
44   });
45 });