michael@0: // Versions to test listed in ascending order, none can be equal michael@0: var comparisons = [ michael@0: "0.9", michael@0: "0.9.1", michael@0: "1.0pre1", michael@0: "1.0pre2", michael@0: "1.0", michael@0: "1.1pre", michael@0: "1.1pre1a", michael@0: "1.1pre1", michael@0: "1.1pre10a", michael@0: "1.1pre10", michael@0: "1.1", michael@0: "1.1.0.1", michael@0: "1.1.1", michael@0: "1.1.*", michael@0: "1.*", michael@0: "2.0", michael@0: "2.1", michael@0: "3.0.-1", michael@0: "3.0" michael@0: ]; michael@0: michael@0: // Every version in this list means the same version number michael@0: var equality = [ michael@0: "1.1pre", michael@0: "1.1pre0", michael@0: "1.0+" michael@0: ]; michael@0: michael@0: function run_test() michael@0: { michael@0: var vc = Components.classes["@mozilla.org/xpcom/version-comparator;1"] michael@0: .getService(Components.interfaces.nsIVersionComparator); michael@0: michael@0: for (var i = 0; i < comparisons.length; i++) { michael@0: for (var j = 0; j < comparisons.length; j++) { michael@0: var result = vc.compare(comparisons[i], comparisons[j]); michael@0: if (i == j) { michael@0: if (result != 0) michael@0: do_throw(comparisons[i] + " should be the same as itself"); michael@0: } michael@0: else if (i < j) { michael@0: if (!(result < 0)) michael@0: do_throw(comparisons[i] + " should be less than " + comparisons[j]); michael@0: } michael@0: else if (!(result > 0)) { michael@0: do_throw(comparisons[i] + " should be greater than " + comparisons[j]); michael@0: } michael@0: } michael@0: } michael@0: michael@0: for (i = 0; i < equality.length; i++) { michael@0: for (j = 0; j < equality.length; j++) { michael@0: if (vc.compare(equality[i], equality[j]) != 0) michael@0: do_throw(equality[i] + " should equal " + equality[j]); michael@0: } michael@0: } michael@0: }