mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-12 23:12:21 +00:00
More version-compare tests, and a VersionBetween helper.
This commit is contained in:
parent
0470959842
commit
4e56f1c98b
@ -18,6 +18,7 @@
|
||||
// Benjamin Smedberg
|
||||
// Mike Morgan
|
||||
// Justin Scott
|
||||
// Mike Shaver
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
@ -154,5 +155,23 @@ class VersionCompareComponent extends Object {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is $test between $lower and $upper (inclusive)?
|
||||
* @param string $test complete version under test
|
||||
* @param string $lower complete version of lower bound
|
||||
* @param string $upper complete version of upper bound
|
||||
*/
|
||||
function VersionBetween($test, $lower, $upper) {
|
||||
if ($this->CompareVersions($test, $lower) == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->CompareVersions($test, $upper) == 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -1,5 +1,28 @@
|
||||
<?php
|
||||
class VersionCompareTest extends UnitTestCase {
|
||||
function compareVersions($a, $b) {
|
||||
return $this->VersionCompare->CompareVersions($a, $b);
|
||||
}
|
||||
|
||||
// $test is in the inclusive range bounded by $lower and $upper
|
||||
function assertVersionBetweenClosed($test, $lower, $upper) {
|
||||
$this->assertTrue($this->VersionCompare->VersionBetween($test, $lower, $upper));
|
||||
}
|
||||
|
||||
// $test is NOT in the inclusive range bounded by $lower and $upper
|
||||
function assertVersionNotBetweenClosed($test, $lower, $upper) {
|
||||
$this->assertFalse($this->VersionCompare->VersionBetween($test, $lower, $upper));
|
||||
}
|
||||
|
||||
// The versions are considered equal
|
||||
function assertVersionsEqual($a, $b) {
|
||||
$this->assertEqual($this->compareVersions($a, $b), 0);
|
||||
}
|
||||
|
||||
// The first version is greater than the second
|
||||
function assertVersionGreater($greater, $lesser) {
|
||||
$this->assertEqual($this->compareVersions($greater, $lesser), 1);
|
||||
}
|
||||
|
||||
//Setup the VC Component
|
||||
function setUp() {
|
||||
@ -12,23 +35,43 @@ class VersionCompareTest extends UnitTestCase {
|
||||
$this->assertNoErrors();
|
||||
}
|
||||
|
||||
//Make sure the comparison returns greater
|
||||
function testGreater() {
|
||||
$results = $this->VersionCompare->CompareVersions('1.0.1.4', '1.0');
|
||||
$this->assertEqual($results, 1);
|
||||
// Minor update is greater than base version
|
||||
function testMinorUpdateGreater() {
|
||||
$this->assertVersionGreater('1.0.1.4', '1.0');
|
||||
}
|
||||
|
||||
// A later update with fewer components is greater than earlier+longer
|
||||
function testLaterShorterMinorUpdateGreater() {
|
||||
$this->assertVersionGreater('1.0.2', '1.0.1.5');
|
||||
}
|
||||
|
||||
//Make sure the comparison returns lesser
|
||||
function testLesser() {
|
||||
$results = $this->VersionCompare->CompareVersions('2.0b1', '2.5.0.*');
|
||||
$this->assertEqual($results, -1);
|
||||
}
|
||||
// Beta is less than release-stream wildcard
|
||||
function testBetaLessThanReleaseStreamWildcard() {
|
||||
$this->assertVersionGreater('2.0.0.*', '2.0b1');
|
||||
}
|
||||
|
||||
// Alpha is less than beta, beta less than final
|
||||
function testAlphaBetaRCFinalOrdering() {
|
||||
$this->assertVersionGreater('3.0b1', '3.0a2');
|
||||
$this->assertVersionGreater('2.0', '2.0b3');
|
||||
}
|
||||
|
||||
//Make sure the comparison returns equal
|
||||
function testEqual() {
|
||||
$results = $this->VersionCompare->CompareVersions('1.0.4', '1.0.4.0');
|
||||
$this->assertEqual($results, 0);
|
||||
}
|
||||
// A compatible update is between the release version and the compatible-stream wildcard
|
||||
function testCompatibleUpdateInReleaseStream() {
|
||||
$this->assertVersionBetweenClosed('2.0.0.1', '2.0', '2.0.0.*');
|
||||
}
|
||||
|
||||
// Incompatible updates aren't
|
||||
function testIncompatibleUpdateNotInStream() {
|
||||
$this->assertVersionNotBetweenClosed('2.0.1', '2.0', '2.0.0.*');
|
||||
}
|
||||
|
||||
// Extra zeroes don't matter
|
||||
function testImpliedZeroes() {
|
||||
$this->assertVersionsEqual('1.0', '1.0.0.0');
|
||||
$this->assertVersionsEqual('1.0.0', '1.0');
|
||||
$this->assertVersionsEqual('1.5', '1.5.0.0');
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user