1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/tests/unit/test_versioncomparator.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,59 @@ 1.4 +// Versions to test listed in ascending order, none can be equal 1.5 +var comparisons = [ 1.6 + "0.9", 1.7 + "0.9.1", 1.8 + "1.0pre1", 1.9 + "1.0pre2", 1.10 + "1.0", 1.11 + "1.1pre", 1.12 + "1.1pre1a", 1.13 + "1.1pre1", 1.14 + "1.1pre10a", 1.15 + "1.1pre10", 1.16 + "1.1", 1.17 + "1.1.0.1", 1.18 + "1.1.1", 1.19 + "1.1.*", 1.20 + "1.*", 1.21 + "2.0", 1.22 + "2.1", 1.23 + "3.0.-1", 1.24 + "3.0" 1.25 +]; 1.26 + 1.27 +// Every version in this list means the same version number 1.28 +var equality = [ 1.29 + "1.1pre", 1.30 + "1.1pre0", 1.31 + "1.0+" 1.32 +]; 1.33 + 1.34 +function run_test() 1.35 +{ 1.36 + var vc = Components.classes["@mozilla.org/xpcom/version-comparator;1"] 1.37 + .getService(Components.interfaces.nsIVersionComparator); 1.38 + 1.39 + for (var i = 0; i < comparisons.length; i++) { 1.40 + for (var j = 0; j < comparisons.length; j++) { 1.41 + var result = vc.compare(comparisons[i], comparisons[j]); 1.42 + if (i == j) { 1.43 + if (result != 0) 1.44 + do_throw(comparisons[i] + " should be the same as itself"); 1.45 + } 1.46 + else if (i < j) { 1.47 + if (!(result < 0)) 1.48 + do_throw(comparisons[i] + " should be less than " + comparisons[j]); 1.49 + } 1.50 + else if (!(result > 0)) { 1.51 + do_throw(comparisons[i] + " should be greater than " + comparisons[j]); 1.52 + } 1.53 + } 1.54 + } 1.55 + 1.56 + for (i = 0; i < equality.length; i++) { 1.57 + for (j = 0; j < equality.length; j++) { 1.58 + if (vc.compare(equality[i], equality[j]) != 0) 1.59 + do_throw(equality[i] + " should equal " + equality[j]); 1.60 + } 1.61 + } 1.62 +}