Update Iot.js
[platform/upstream/iotjs.git] / test / run_pass / test_timers2.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 var assert = require('assert');
18 var util = require('util');
19
20
21 var timerFired = false;
22 var shouldnotFired = false;
23
24 setTimeout(function(a, b, c) {
25   assert.equal(arguments.length, 3);
26   assert.equal(arguments[0], 1);
27   assert.equal(arguments[1], 2);
28   assert.equal(arguments[2], 3);
29   assert.equal(a, 1);
30   assert.equal(b, 2);
31   assert.equal(c, 3);
32   timerFired = true;
33 }, 100, 1, 2, 3);
34
35
36 var i = 0;
37 setInterval(function(list) {
38   assert.equal(arguments.length, 1);
39   assert(util.isArray(list));
40   assert.equal(list.length, 5);
41   if (i >= list.length) {
42     clearInterval(this);
43   } else {
44     assert.equal(list[i], i * i);
45     i++;
46   }
47 }, 100, [0, 1, 4, 9, 16]);
48
49
50 var t = setTimeout(function() {
51   shouldnotFired = true;
52 }, 100);
53 clearTimeout(t);
54
55
56 process.on('exit', function(code) {
57   assert.equal(code, 0);
58   assert(timerFired);
59   assert.equal(i, 5);
60   assert.equal(shouldnotFired, false);
61 });