-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGenericTestFramework.js
More file actions
61 lines (57 loc) · 1.42 KB
/
GenericTestFramework.js
File metadata and controls
61 lines (57 loc) · 1.42 KB
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
/*
* This is a mini test framework that provides some boilerplate code
* to simplify tasks such as testing APIs that talk to remote parties
*/
var GenericTestFramework = {
tests: null,
inputs: null,
logMessageJoin: 0,
logMessage: "",
configure: function(config, listJoin, logMessageJoin) {
this.logMessageJoin = logMessageJoin;
this.tests = config.tests;
if (config.inputs instanceof Array && config.inputs.length) {
this.inputs = config.inputs;
} else {
this.inputs = null;
}
var i, n = this.tests.length, t = [];
for (i=0; i < n; i++) {
t.push({ s1: this.tests[i].name });
}
if (t.length) {
CF.listAdd(listJoin, t);
}
},
onTestButtonPressed: function(listIndex) {
var testFunction = this.tests[listIndex].run;
if (testFunction != null) {
if (this.inputs == null) {
try {
testFunction({});
}
catch (e) {
CF.log("Exception catched while running test function for " + this.tests[listIndex].name + ": " + e);
}
} else {
var that = this;
CF.getJoins(this.inputs, function(joins) {
try {
testFunction(joins);
}
catch (e) {
CF.log("Exception catched while running test function for " + that.tests[listIndex].name + ": " + e);
}
});
}
}
},
onClearLog: function() {
this.logMessage = "";
CF.setJoin("s300", "");
},
log: function(message) {
this.logMessage += message + "\n";
CF.setJoin("s300", this.logMessage);
}
};