diff options
author | Timothy Knight <tknight@google.com> | 2013-08-21 14:33:40 -0700 |
---|---|---|
committer | Timothy Knight <tknight@google.com> | 2013-09-04 16:58:58 +0000 |
commit | 23c8809568b68430f875df759108c58016c44c16 (patch) | |
tree | 2a5882afeb7e9ed693f8358b8d43c892c640b3ed /media/tests/MediaFrameworkTest | |
parent | 7f043de9a9eb0b071b93ddfffdc5ba0f6d1c7309 (diff) | |
download | frameworks_base-23c8809568b68430f875df759108c58016c44c16.zip frameworks_base-23c8809568b68430f875df759108c58016c44c16.tar.gz frameworks_base-23c8809568b68430f875df759108c58016c44c16.tar.bz2 |
Camera2: Updated Rational for denom=0.
Handle NaN and INF using the same semantics as Java floats. No longer
throw an exception if a rational is constructed with a zero-denominator.
This commit is required for the ITS pdk app, since without it, the app
fails when it tries to deserialize rational values that are
(incorrectly) set to 0/0.
Bug: 10337323
Change-Id: I890ec2092f2945abc0f531fc46f9a7f5c71d2dbf
Diffstat (limited to 'media/tests/MediaFrameworkTest')
-rw-r--r-- | media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/RationalTest.java | 51 |
1 files changed, 44 insertions, 7 deletions
diff --git a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/RationalTest.java b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/RationalTest.java index 926719c..9621f92 100644 --- a/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/RationalTest.java +++ b/media/tests/MediaFrameworkTest/src/com/android/mediaframeworktest/unit/RationalTest.java @@ -50,12 +50,20 @@ public class RationalTest extends junit.framework.TestCase { assertEquals(1, r.getNumerator()); assertEquals(2, r.getDenominator()); - // Dividing by zero is not allowed - try { - r = new Rational(1, 0); - fail("Expected Rational constructor to throw an IllegalArgumentException"); - } catch(IllegalArgumentException e) { - } + // Infinity. + r = new Rational(1, 0); + assertEquals(0, r.getNumerator()); + assertEquals(0, r.getDenominator()); + + // Negative infinity. + r = new Rational(-1, 0); + assertEquals(0, r.getNumerator()); + assertEquals(0, r.getDenominator()); + + // NaN. + r = new Rational(0, 0); + assertEquals(0, r.getNumerator()); + assertEquals(0, r.getDenominator()); } @SmallTest @@ -110,5 +118,34 @@ public class RationalTest extends junit.framework.TestCase { assertEquals(moreComplicated, moreComplicated2); assertEquals(moreComplicated2, moreComplicated); + Rational nan = new Rational(0, 0); + Rational nan2 = new Rational(0, 0); + assertTrue(nan.equals(nan)); + assertTrue(nan.equals(nan2)); + assertTrue(nan2.equals(nan)); + assertFalse(nan.equals(r)); + assertFalse(r.equals(nan)); + + // Infinities of the same sign are equal. + Rational posInf = new Rational(1, 0); + Rational posInf2 = new Rational(2, 0); + Rational negInf = new Rational(-1, 0); + Rational negInf2 = new Rational(-2, 0); + assertEquals(posInf, posInf); + assertEquals(negInf, negInf); + assertEquals(posInf, posInf2); + assertEquals(negInf, negInf2); + + // Infinities aren't equal to anything else. + assertFalse(posInf.equals(negInf)); + assertFalse(negInf.equals(posInf)); + assertFalse(negInf.equals(r)); + assertFalse(posInf.equals(r)); + assertFalse(r.equals(negInf)); + assertFalse(r.equals(posInf)); + assertFalse(posInf.equals(nan)); + assertFalse(negInf.equals(nan)); + assertFalse(nan.equals(posInf)); + assertFalse(nan.equals(negInf)); } -}
\ No newline at end of file +} |