summaryrefslogtreecommitdiff
path: root/frontend/gamma/tests/SimpleTest/SimpleTest.Async.js
Unidiff
Diffstat (limited to 'frontend/gamma/tests/SimpleTest/SimpleTest.Async.js') (more/less context) (show whitespace changes)
-rw-r--r--frontend/gamma/tests/SimpleTest/SimpleTest.Async.js169
1 files changed, 169 insertions, 0 deletions
diff --git a/frontend/gamma/tests/SimpleTest/SimpleTest.Async.js b/frontend/gamma/tests/SimpleTest/SimpleTest.Async.js
new file mode 100644
index 0000000..040cdbf
--- a/dev/null
+++ b/frontend/gamma/tests/SimpleTest/SimpleTest.Async.js
@@ -0,0 +1,169 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer to http://www.clipperz.com
12
13* Javascript Crypto Library is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version.
17
18* Javascript Crypto Library is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details.
22
23* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see
25 <http://www.gnu.org/licenses/>.
26
27*/
28
29MochiKit.Base.update(Clipperz.Async.Deferred.prototype, {
30/*
31 '_addTest': function(anExpectedValue, aDescription, isDeep, aResult) {
32 if (isDeep) {
33 SimpleTest.isDeeply(aResult, anExpectedValue, aDescription);
34 } else {
35 SimpleTest.is(aResult, anExpectedValue, aDescription);
36 }
37
38 return aResult;
39 },
40*/
41 'addTest': function (anExpectedValue, aDescription, isDeep) {
42 // this.addMethod(this, '_addTest', anExpectedValue, aDescription, isDeep);
43 // this.addCallback(Clipperz.Async.test, anExpectedValue, aDescription, isDeep);
44
45 if (isDeep) {
46 // SimpleTest.isDeeply(aResult, anExpectedValue, aDescription);
47 this.addCallback(Clipperz.Async.Test.isDeeply(anExpectedValue, aDescription));
48 } else {
49 // SimpleTest.is(aResult, anExpectedValue, aDescription);
50 this.addCallback(Clipperz.Async.Test.is(anExpectedValue, aDescription));
51 }
52 },
53
54 //-------------------------------------------------------------------------
55
56 'shouldSucceed': function (aDescription) {
57 this.addCallbackPass(SimpleTest.ok, true, aDescription);
58 this.addErrbackPass (SimpleTest.ok, false, aDescription);
59 this.addBoth(MochiKit.Async.succeed, null);
60 },
61
62 'shouldFail': function (aDescription) {
63 this.addCallbackPass(SimpleTest.ok, false, aDescription);
64 this.addErrbackPass (SimpleTest.ok, true, aDescription);
65 this.addBoth(MochiKit.Async.succeed, null);
66 },
67
68 //-------------------------------------------------------------------------
69
70});
71
72
73Clipperz.Async.Test = {};
74MochiKit.Base.update(Clipperz.Async.Test, {
75
76 'is': function (anExpectedResult, aDescription) {
77 return MochiKit.Base.partial(function (anExpectedResult, aDescription, aResult) {
78 SimpleTest.is(aResult, anExpectedResult, aDescription);
79
80 return aResult;
81 }, anExpectedResult, aDescription);
82 },
83
84 //-------------------------------------------------------------------------
85
86 'ok': function (aDescription) {
87 return MochiKit.Base.partial(function (aDescription, aResult) {
88 SimpleTest.ok(aResult, aDescription);
89
90 return aResult;
91 }, aDescription);
92 },
93
94 //-------------------------------------------------------------------------
95
96 'fail': function(aDescription) {
97 return MochiKit.Base.partial(function (aDescription, aResult) {
98 SimpleTest.ok(!aResult, aDescription);
99
100 return aResult;
101 }, aDescription);
102 },
103
104 //-------------------------------------------------------------------------
105
106 'isDeeply': function (anExpectedResult, aDescription) {
107 return MochiKit.Base.partial(function (anExpectedResult, aDescription, aResult) {
108 SimpleTest.isDeeply(aResult, anExpectedResult, aDescription);
109
110 return aResult;
111 }, anExpectedResult, aDescription);
112 },
113
114 //-------------------------------------------------------------------------
115 __syntaxFix__: "syntax fix"
116});
117
118
119SimpleTest.runDeferredTests = function (aName, aTestSet, aTestArguments) {
120 try {
121 var deferredTests;
122 var aTestName;
123 var title;
124
125 deferredTests = new Clipperz.Async.Deferred(aName + " <deferred test set>", aTestArguments);
126
127 title = aName;
128
129 aTestName = window.location.href.match(/#.*/);
130 if (aTestName && (aTestName != '#')) {
131 aTestName = aTestName[0].slice(1);
132 if (aTestName in aTestSet) {
133 //Clipperz.log("single test execution, via fragment identifier", aTestName);
134 title += ' [' + aTestName + ']';
135 deferredTests.addCallback(aTestSet[aTestName], aTestArguments);
136 deferredTests.addErrback(SimpleTest.ok, false, aTestName);
137 } else {
138 title = 'WRONG TEST NAME'
139 deferredTests.addBoth(is, aTestName, null, "Wrong test name selected to run");
140 }
141 } else {
142 for (aTestName in aTestSet) {
143 deferredTests.addCallback(aTestSet[aTestName], aTestArguments);
144 deferredTests.addErrback(SimpleTest.ok, false, aTestName);
145 deferredTests.addBoth(MochiKit.Async.wait, 0.5);
146 }
147 deferredTests.addBoth(is, true, true, "FINISH: completed the full stack of tests");
148 }
149
150 MochiKit.DOM.currentDocument().title = title;
151
152 deferredTests.addBoth(SimpleTest.finish);
153 deferredTests.callback();
154
155 SimpleTest.waitForExplicitFinish();
156 } catch (err) {
157 var s = "test suite failure!\n";
158 var o = {};
159 var k = null;
160 for (k in err) {
161 // ensure unique keys?!
162 if (!o[k]) {
163 s += k + ": " + err[k] + "\n";
164 o[k] = err[k];
165 }
166 }
167 ok ( false, s );
168 }
169}