-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_callAllFunctions.js
87 lines (66 loc) · 1.95 KB
/
test_callAllFunctions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//apply same thing to all functions
/*var data sample = {
timer_handle: null
,propNames:{}
,cantProps:propNames.length
,actual_index: -1
,actual_name:""
,doit_fn:null
,tests
,etc
}
*/
function tic (data) {
if (data.actual_index>=data.cantProps) {
clearInterval(data.timer); //end tic thread
}
else {
data.actual_name=data.propNames[++data.actual_index];
console.log('------'+data.actual_name+'------');
data.doit(data);
}
}
function call_if_function(data){
if (typeof data.obj_to_test[data.actual_name] === 'function') {
//is function -> test it
data.obj_to_test[data.actual_name](data.genericparam
, function(callback_data){
console.log(data.actual_name +', callback data: '+JSON.stringify(callback_data))});
}
function startTic(data, interval)
{
data.timer_handle = setInterval(tic,100, data);
}
exports.callAllFunctions
= function (obj, genericparam)
{
var data;
data.obj_to_test = obj;
data.genericparam = genericparam;
data.propNames = Object.getOwnPropertyNames(obj);
data.cantProps = data.propNames.length;
data.actual_index=-1;
data.doit = call_if_function;
//start tic thread
data.timer_handle = setInterval(tic,100, data);
startTic(data,100);
};
// test.propname = function name
// [ inner array = [param1, param2, callback_fn] ]
//
function callTest(data){
var params=data.tests[data.actual_name]; //array
data.obj_to_test[data.actual_name](params[0],params[1],params[2]); //call fn con los params - params[3] es una callbackfn
}
exports.callAll_Tests
= function (tests, obj)
{
var data;
data.obj_to_test = obj;
data.propNames = Object.keys(tests);
data.cantProps = data.propNames.length;
data.tests = tests;
data.doit = callTest;
//start tic thread
startTic(data,100);
};