|
1 /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
|
2 * This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 var passed = 0; |
|
7 var ran = 0; |
|
8 if(tests.length < 1){ |
|
9 dump("FAILED! tests.length was " + tests.length + "\n"); |
|
10 } |
|
11 |
|
12 function logResult(didPass, testcase, extra) { |
|
13 var start = didPass ? "PASS | " : "FAIL | "; |
|
14 print(start + testcase.path + " | Test was: \"" + |
|
15 testcase.desc + "\" | " + testcase.expect + " |"); |
|
16 if (extra) { |
|
17 print(extra); |
|
18 } |
|
19 } |
|
20 |
|
21 |
|
22 function isIID(a,iid){ |
|
23 var rv = false; |
|
24 try{ |
|
25 a.QueryInterface(iid); |
|
26 rv = true; |
|
27 }catch(e){} |
|
28 return rv; |
|
29 } |
|
30 function TestListener(){} |
|
31 |
|
32 TestListener.prototype = { |
|
33 handleResult: function(result){ |
|
34 var feed = result.doc; |
|
35 // QI to something |
|
36 (isIID(feed, Components.interfaces.nsIFeed)); |
|
37 try { |
|
38 if(!eval(testcase.expect)){ |
|
39 logResult(false, testcase); |
|
40 |
|
41 }else{ |
|
42 logResult(true, testcase); |
|
43 passed += 1; |
|
44 } |
|
45 } |
|
46 catch(e) { |
|
47 logResult(false, testcase, "ex: " + e.message); |
|
48 } |
|
49 |
|
50 ran += 1; |
|
51 result = null; |
|
52 } |
|
53 } |
|
54 |
|
55 var startDate = new Date(); |
|
56 |
|
57 for(var i=0; i<tests.length; i++){ |
|
58 var testcase = tests[i]; |
|
59 var uri; |
|
60 if (testcase.base == null) |
|
61 uri = ioService.newURI('http://example.org/'+testcase.path, null,null); |
|
62 else |
|
63 uri = testcase.base |
|
64 |
|
65 var parser = Components.classes["@mozilla.org/feed-processor;1"] |
|
66 .createInstance(Components.interfaces.nsIFeedProcessor); |
|
67 var stream = Components.classes["@mozilla.org/network/file-input-stream;1"] |
|
68 .createInstance(Components.interfaces.nsIFileInputStream); |
|
69 var listener = new TestListener(); |
|
70 try{ |
|
71 stream.init(testcase.file, 0x01, 0444, 0); |
|
72 parser.listener = listener; |
|
73 parser.parseFromStream(stream, uri); |
|
74 }catch(e){ |
|
75 dump("FAILED! Error parsing file " + testcase.file.leafName + |
|
76 "Error: " + e.message + "\n"); |
|
77 }finally{ |
|
78 stream.close(); |
|
79 } |
|
80 |
|
81 } |
|
82 var endDate = new Date(); |
|
83 |
|
84 print("Start: " + startDate); |
|
85 print("End : " + endDate); |
|
86 print("tests: " + tests.length); |
|
87 print("ran: " + ran); |
|
88 print("passed: " + passed); |