[483] | 1 | define(["doh/runner"], function(doh) { |
---|
| 2 | |
---|
| 3 | |
---|
| 4 | doh.register("doh/selftest/lastTest", function(t){ |
---|
| 5 | t.assertTrue(true); |
---|
| 6 | }); |
---|
| 7 | |
---|
| 8 | var |
---|
| 9 | tObj1 = { a:0, b:1, c:true, d:false, e:{}, f:{a:"x"}, g:"", h:"hellp", i:null}, |
---|
| 10 | tObj2 = { a:0, b:1, c:true, d:false, e:{}, f:{a:"x"}, g:"", h:"hellp", i:null}, // equal |
---|
| 11 | tObja = { a:1, b:1, c:true, d:false, e:{}, f:{a:"x"}, g:"", h:"hellp", i:null}, // delta a |
---|
| 12 | tObjb = { a:0, b:2, c:true, d:false, e:{}, f:{a:"x"}, g:"", h:"hellp", i:null}, // delta b |
---|
| 13 | tObjc = { a:0, b:1, c:false, d:false, e:{}, f:{a:"x"}, g:"", h:"hellp", i:null}, // delta c |
---|
| 14 | tObjd = { a:0, b:1, c:true, d:true, e:{}, f:{a:"x"}, g:"", h:"hellp", i:null}, // delta d |
---|
| 15 | tObje = { a:0, b:1, c:true, d:false, e:{a:"x"}, f:{a:"x"}, g:"", h:"hellp", i:null}, // delta e |
---|
| 16 | tObjf1= { a:0, b:1, c:true, d:false, e:{}, f:{a:"y"}, g:"", h:"hellp", i:null}, // delta f.a |
---|
| 17 | tObjf2= { a:0, b:1, c:true, d:false, e:{}, f:{b:"x"}, g:"", h:"hellp", i:null}, // delta f, property |
---|
| 18 | tObjg = { a:0, b:1, c:true, d:false, e:{}, f:{}, g:"x", h:"hellp", i:null}, // delta g |
---|
| 19 | tObjh = { a:0, b:1, c:true, d:false, e:{}, f:{}, g:"", h:"hello", i:null}, // delta h |
---|
| 20 | tObji = { a:0, b:1, c:true, d:false, e:{}, f:{}, g:"", h:"hellp", i:0}, // delta i |
---|
| 21 | |
---|
| 22 | tArray1 = [0, 1, true, false, {}, {a:"x"}, "", "hello", null], |
---|
| 23 | tArray2 = [0, 1, true, false, {}, {a:"x"}, "", "hello", null], |
---|
| 24 | tArraya = [1, 1, true, false, {}, {a:"x"}, "", "hellp", null], // delta a |
---|
| 25 | tArrayb = [0, 2, true, false, {}, {a:"x"}, "", "hellp", null], // delta b |
---|
| 26 | tArrayc = [0, 1, false, false, {}, {a:"x"}, "", "hellp", null], // delta c |
---|
| 27 | tArrayd = [0, 1, true, true, {}, {a:"x"}, "", "hellp", null], // delta d |
---|
| 28 | tArraye = [0, 1, true, false, {a:"x"}, {a:"x"}, "", "hellp", null], // delta e |
---|
| 29 | tArrayf1= [0, 1, true, false, {}, {a:"y"}, "", "hellp", null], // delta f.a |
---|
| 30 | tArrayf2= [0, 1, true, false, {}, {b:"x"}, "", "hellp", null], // delta f, property |
---|
| 31 | tArrayg = [0, 1, true, false, {}, {}, "x", "hellp", null], // delta g |
---|
| 32 | tArrayh = [0, 1, true, false, {}, {}, "", "hello", null], // delta h |
---|
| 33 | tArrayi = [0, 1, true, false, {}, {}, "", "hellp", 0]; // delta i |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | doh.register("doh/asserts/pass", function(t){ |
---|
| 37 | function check(method, args){ |
---|
| 38 | t[method].apply(t, args); |
---|
| 39 | }; |
---|
| 40 | |
---|
| 41 | check("assertTrue", [true]); |
---|
| 42 | check("assertTrue", [{}]); |
---|
| 43 | check("assertTrue", [1]); |
---|
| 44 | //check("assertTrue", ["hello"]); |
---|
| 45 | |
---|
| 46 | check("assertFalse", [false]); |
---|
| 47 | check("assertFalse", [0]); |
---|
| 48 | check("assertFalse", [null]); |
---|
| 49 | check("assertFalse", [undefined]); |
---|
| 50 | check("assertFalse", [(function(){})()]); |
---|
| 51 | |
---|
| 52 | check("assertEqual", [[], []]); |
---|
| 53 | check("assertEqual", [[1], [1]]); |
---|
| 54 | check("assertEqual", [[1,2], [1,2]]); |
---|
| 55 | check("assertEqual", [[1,2,3], [1,2,3]]); |
---|
| 56 | check("assertEqual", [tObj1, tObj1]); |
---|
| 57 | check("assertEqual", [tObj1, tObj2]); |
---|
| 58 | check("assertEqual", [tArray1, tArray2]); |
---|
| 59 | |
---|
| 60 | check("assertNotEqual", [tObj1, tObja]); |
---|
| 61 | check("assertNotEqual", [tObj1, tObjb]); |
---|
| 62 | check("assertNotEqual", [tObj1, tObjc]); |
---|
| 63 | check("assertNotEqual", [tObj1, tObjd]); |
---|
| 64 | check("assertNotEqual", [tObj1, tObje]); |
---|
| 65 | check("assertNotEqual", [tObj1, tObjf1]); |
---|
| 66 | check("assertNotEqual", [tObj1, tObjf2]); |
---|
| 67 | check("assertNotEqual", [tObj1, tObjg]); |
---|
| 68 | check("assertNotEqual", [tObj1, tObjh]); |
---|
| 69 | check("assertNotEqual", [tObj1, tObji]); |
---|
| 70 | |
---|
| 71 | check("assertNotEqual", [tArray1, tArraya]); |
---|
| 72 | check("assertNotEqual", [tArray1, tArrayb]); |
---|
| 73 | check("assertNotEqual", [tArray1, tArrayc]); |
---|
| 74 | check("assertNotEqual", [tArray1, tArrayd]); |
---|
| 75 | check("assertNotEqual", [tArray1, tArraye]); |
---|
| 76 | check("assertNotEqual", [tArray1, tArrayf1]); |
---|
| 77 | check("assertNotEqual", [tArray1, tArrayf2]); |
---|
| 78 | check("assertNotEqual", [tArray1, tArrayg]); |
---|
| 79 | check("assertNotEqual", [tArray1, tArrayh]); |
---|
| 80 | check("assertNotEqual", [tArray1, tArrayi]); |
---|
| 81 | }); |
---|
| 82 | |
---|
| 83 | doh.register("doh/asserts/fail", function(t){ |
---|
| 84 | function check(method, args){ |
---|
| 85 | try{ |
---|
| 86 | t[method].apply(t, args); |
---|
| 87 | }catch(e){ |
---|
| 88 | t.assertTrue(true); |
---|
| 89 | return; |
---|
| 90 | } |
---|
| 91 | throw new doh._AssertFailure("failed: " + method); |
---|
| 92 | } |
---|
| 93 | check("assertFalse", [true]); |
---|
| 94 | check("assertFalse", [{}]); |
---|
| 95 | check("assertFalse", [1]); |
---|
| 96 | //check("assertFalse", ["hello"]); |
---|
| 97 | |
---|
| 98 | check("assertTrue", [false]); |
---|
| 99 | check("assertTrue", [0]); |
---|
| 100 | check("assertTrue", [null]); |
---|
| 101 | check("assertTrue", [undefined]); |
---|
| 102 | check("assertTrue", [(function(){})()]); |
---|
| 103 | |
---|
| 104 | check("assertNotEqual", [[], []]); |
---|
| 105 | check("assertNotEqual", [[1], [1]]); |
---|
| 106 | check("assertNotEqual", [[1,2], [1,2]]); |
---|
| 107 | check("assertNotEqual", [[1,2,3], [1,2,3]]); |
---|
| 108 | check("assertNotEqual", [tObj1, tObj1]); |
---|
| 109 | check("assertNotEqual", [tObj1, tObj2]); |
---|
| 110 | check("assertNotEqual", [tArray1, tArray2]); |
---|
| 111 | |
---|
| 112 | check("assertEqual", [tObj1, tObja]); |
---|
| 113 | check("assertEqual", [tObj1, tObjb]); |
---|
| 114 | check("assertEqual", [tObj1, tObjc]); |
---|
| 115 | check("assertEqual", [tObj1, tObjd]); |
---|
| 116 | check("assertEqual", [tObj1, tObje]); |
---|
| 117 | check("assertEqual", [tObj1, tObjf1]); |
---|
| 118 | check("assertEqual", [tObj1, tObjf2]); |
---|
| 119 | check("assertEqual", [tObj1, tObjg]); |
---|
| 120 | check("assertEqual", [tObj1, tObjh]); |
---|
| 121 | check("assertEqual", [tObj1, tObji]); |
---|
| 122 | |
---|
| 123 | check("assertEqual", [tArray1, tArraya]); |
---|
| 124 | check("assertEqual", [tArray1, tArrayb]); |
---|
| 125 | check("assertEqual", [tArray1, tArrayc]); |
---|
| 126 | check("assertEqual", [tArray1, tArrayd]); |
---|
| 127 | check("assertEqual", [tArray1, tArraye]); |
---|
| 128 | check("assertEqual", [tArray1, tArrayf1]); |
---|
| 129 | check("assertEqual", [tArray1, tArrayf2]); |
---|
| 130 | check("assertEqual", [tArray1, tArrayg]); |
---|
| 131 | check("assertEqual", [tArray1, tArrayh]); |
---|
| 132 | check("assertEqual", [tArray1, tArrayi]); |
---|
| 133 | }); |
---|
| 134 | |
---|
| 135 | // test the highly overloaded doh.register signature |
---|
| 136 | var currentFixture; |
---|
| 137 | dojo.connect(doh, "_testStarted", function(groupId, fixture){ |
---|
| 138 | currentFixture= fixture; |
---|
| 139 | }); |
---|
| 140 | |
---|
| 141 | var lastId; |
---|
| 142 | function f(id, tid) { |
---|
| 143 | return function() { |
---|
| 144 | if(tid){ |
---|
| 145 | doh.assertTrue(currentFixture.name==tid); |
---|
| 146 | } |
---|
| 147 | if(id){ |
---|
| 148 | doh.assertTrue(lastId+1==id); |
---|
| 149 | lastId= id; |
---|
| 150 | } |
---|
| 151 | }; |
---|
| 152 | }; |
---|
| 153 | |
---|
| 154 | var hijack= doh._setupGroupForRun; |
---|
| 155 | doh._setupGroupForRun= function(groupName){ |
---|
| 156 | lastId= 0; |
---|
| 157 | hijack.call(doh, groupName); |
---|
| 158 | }; |
---|
| 159 | |
---|
| 160 | // note: the tests that are commented out below all have zero for the setup function |
---|
| 161 | // and a real teardown function. For now, this is |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | doh.register("myGroup2-1", f(2), f(1), f(3)); |
---|
| 165 | doh.register("myGroup2-2", f(2), f(1)); |
---|
| 166 | doh.register("myGroup2-4", f(1)); |
---|
| 167 | |
---|
| 168 | dohSelfTestLog5= f(2); |
---|
| 169 | dohSelfTestLog6= f(2); |
---|
| 170 | dohSelfTestLog7= f(1); |
---|
| 171 | dohSelfTestLog8= f(1); |
---|
| 172 | |
---|
| 173 | doh.register("myGroup2-5", "dohSelfTestLog5();", f(1), f(3)); |
---|
| 174 | doh.register("myGroup2-6", "dohSelfTestLog6();", f(1)); |
---|
| 175 | doh.register("myGroup2-8", "dohSelfTestLog8();"); |
---|
| 176 | |
---|
| 177 | doh.register("myGroup2-9", [f(2), f(3)], f(1), f(4)); |
---|
| 178 | doh.register("myGroup2-10", [f(2), f(3)], f(1)); |
---|
| 179 | doh.register("myGroup2-12", [f(1), f(2)]); |
---|
| 180 | |
---|
| 181 | doh.register("myGroup2-13", {t1:f(0, "t1"), t2:f(0, "t2")}, f(1), f(2)); |
---|
| 182 | doh.register("myGroup2-14", {t3:f(0, "t3"), t4:f(0, "t4")}, f(1)); |
---|
| 183 | doh.register("myGroup2-16", {t7:f(0, "t7"), t8:f(0, "t8")}); |
---|
| 184 | |
---|
| 185 | doh.register("myGroup2-17", {name:"t9", runTest:f(2, "t9")}, f(1), f(3)); |
---|
| 186 | doh.register("myGroup2-18", {name:"t10", runTest:f(2, "t10")}, f(1)); |
---|
| 187 | doh.register("myGroup2-20", {name:"t12", runTest:f(1, "t12")}); |
---|
| 188 | |
---|
| 189 | doh.register("myGroup2-21", {name:"tx", runTest:f(3), setUp:f(2)}, f(1), f(4)); |
---|
| 190 | doh.register("myGroup2-22", {name:"tx", runTest:f(3), setUp:f(2)}, f(1)); |
---|
| 191 | doh.register("myGroup2-24", {name:"tx", runTest:f(2), setUp:f(1)}); |
---|
| 192 | |
---|
| 193 | doh.register("myGroup2-25", {name:"tx", runTest:f(2), tearDown:f(3)}, f(1), f(4)); |
---|
| 194 | doh.register("myGroup2-26", {name:"tx", runTest:f(2), tearDown:f(3)}, f(1)); |
---|
| 195 | doh.register("myGroup2-28", {name:"tx", runTest:f(1), tearDown:f(2)}); |
---|
| 196 | |
---|
| 197 | doh.register("myGroup2-29", {name:"tx", runTest:f(3), setUp:f(2), tearDown:f(4)}, f(1), f(5)); |
---|
| 198 | doh.register("myGroup2-30", {name:"tx", runTest:f(3), setUp:f(2), tearDown:f(4)}, f(1)); |
---|
| 199 | doh.register("myGroup2-32", {name:"tx", runTest:f(2), setUp:f(1), tearDown:f(3)}); |
---|
| 200 | |
---|
| 201 | //v1.6- signatures |
---|
| 202 | //TODO |
---|
| 203 | |
---|
| 204 | doh.registerTestType("dohSelfTest", function(group, fixture){ |
---|
| 205 | }); |
---|
| 206 | // a stone-stupid async test |
---|
| 207 | doh.register("doh/async", [{ |
---|
| 208 | name: "doh.Deferred success", |
---|
| 209 | runTest: function(t){ |
---|
| 210 | var d = new doh.Deferred(); |
---|
| 211 | setTimeout(d.getTestCallback(function(){ |
---|
| 212 | t.assertTrue(true); |
---|
| 213 | t.assertFalse(false); |
---|
| 214 | }), 50); |
---|
| 215 | return d; |
---|
| 216 | } |
---|
| 217 | },{ |
---|
| 218 | name: "dojo.Deferred success", |
---|
| 219 | runTest: function(t){ |
---|
| 220 | var d = new dojo.Deferred(); |
---|
| 221 | setTimeout(function(){ |
---|
| 222 | d.resolve(true); |
---|
| 223 | }, 50); |
---|
| 224 | return d; |
---|
| 225 | } |
---|
| 226 | },{ |
---|
| 227 | name: "doh.Deferred failure--SHOULD FAIL", |
---|
| 228 | runTest: function(t){ |
---|
| 229 | console.log("running test that SHOULD FAIL"); |
---|
| 230 | var d = new doh.Deferred(); |
---|
| 231 | setTimeout(d.getTestCallback(function(){ |
---|
| 232 | t.assertTrue(false); |
---|
| 233 | }), 50); |
---|
| 234 | return d; |
---|
| 235 | } |
---|
| 236 | },{ |
---|
| 237 | name: "dojo.Deferred failure--SHOULD FAIL", |
---|
| 238 | runTest: function(t){ |
---|
| 239 | console.log("running test that SHOULD FAIL"); |
---|
| 240 | var d = new dojo.Deferred(); |
---|
| 241 | setTimeout(function(){ |
---|
| 242 | d.reject(new Error("hrm...")); |
---|
| 243 | }, 50); |
---|
| 244 | return d; |
---|
| 245 | } |
---|
| 246 | },{ |
---|
| 247 | name: "doh.Deferred timeout failure--SHOULD FAIL", |
---|
| 248 | timeout: 50, |
---|
| 249 | runTest: function(t){ |
---|
| 250 | console.log("running test that SHOULD FAIL"); |
---|
| 251 | // timeout of 50 |
---|
| 252 | var d = new doh.Deferred(); |
---|
| 253 | setTimeout(d.getTestCallback(function(){ |
---|
| 254 | }), 100); |
---|
| 255 | return d; |
---|
| 256 | } |
---|
| 257 | },{ |
---|
| 258 | name: "dojo.Deferred timeout failure--SHOULD FAIL", |
---|
| 259 | timeout: 50, |
---|
| 260 | runTest: function(t){ |
---|
| 261 | console.log("running test that SHOULD FAIL"); |
---|
| 262 | // timeout of 50 |
---|
| 263 | var d = new dojo.Deferred(); |
---|
| 264 | setTimeout(function(){ |
---|
| 265 | d.callback(true); |
---|
| 266 | }, 100); |
---|
| 267 | return d; |
---|
| 268 | } |
---|
| 269 | }]); |
---|
| 270 | |
---|
| 271 | doh.register("doh/selftest/lastTest", function(t){ |
---|
| 272 | t.assertTrue(true); |
---|
| 273 | }); |
---|
| 274 | }); |
---|