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