| 1 |
/* |
| 2 |
* Copyright (C) 2010 The Android Open Source Project |
| 3 |
* |
| 4 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
* you may not use this file except in compliance with the License. |
| 6 |
* You may obtain a copy of the License at |
| 7 |
* |
| 8 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
* |
| 10 |
* Unless required by applicable law or agreed to in writing, software |
| 11 |
* distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
* See the License for the specific language governing permissions and |
| 14 |
* limitations under the License. |
| 15 |
*/ |
| 16 |
|
| 17 |
package com.android.ide.common.xml; |
| 18 |
|
| 19 |
import com.android.ide.common.xml.ManifestData.SupportsScreens; |
| 20 |
|
| 21 |
import java.io.InputStream; |
| 22 |
|
| 23 |
import junit.framework.TestCase; |
| 24 |
|
| 25 |
public class SupportsScreensTest extends TestCase { |
| 26 |
|
| 27 |
private static final String TESTDATA_PATH = |
| 28 |
"/com/android/sdklib/testdata/"; //$NON-NLS-1$ |
| 29 |
private static final String TESTAPP2_XML = TESTDATA_PATH + |
| 30 |
"AndroidManifest-testapp2.xml"; //$NON-NLS-1$ |
| 31 |
|
| 32 |
public void testDefaultValuesApi3() { |
| 33 |
SupportsScreens supportsScreens = SupportsScreens.getDefaultValues(3); |
| 34 |
|
| 35 |
assertNotNull(supportsScreens); |
| 36 |
assertEquals(Boolean.FALSE, supportsScreens.getAnyDensity()); |
| 37 |
assertEquals(Boolean.FALSE, supportsScreens.getResizeable()); |
| 38 |
assertEquals(Boolean.FALSE, supportsScreens.getSmallScreens()); |
| 39 |
assertEquals(Boolean.TRUE, supportsScreens.getNormalScreens()); |
| 40 |
assertEquals(Boolean.FALSE, supportsScreens.getLargeScreens()); |
| 41 |
} |
| 42 |
|
| 43 |
public void testDefaultValuesApi4() { |
| 44 |
SupportsScreens supportsScreens = SupportsScreens.getDefaultValues(4); |
| 45 |
|
| 46 |
assertNotNull(supportsScreens); |
| 47 |
assertEquals(Boolean.TRUE, supportsScreens.getAnyDensity()); |
| 48 |
assertEquals(Boolean.TRUE, supportsScreens.getResizeable()); |
| 49 |
assertEquals(Boolean.TRUE, supportsScreens.getSmallScreens()); |
| 50 |
assertEquals(Boolean.TRUE, supportsScreens.getNormalScreens()); |
| 51 |
assertEquals(Boolean.TRUE, supportsScreens.getLargeScreens()); |
| 52 |
} |
| 53 |
|
| 54 |
public void testManifestParsing() throws Exception { |
| 55 |
InputStream manifestStream = this.getClass().getResourceAsStream(TESTAPP2_XML); |
| 56 |
|
| 57 |
ManifestData data = AndroidManifestParser.parse(manifestStream); |
| 58 |
assertNotNull(data); |
| 59 |
|
| 60 |
SupportsScreens supportsScreens = data.getSupportsScreensFromManifest(); |
| 61 |
assertNotNull(supportsScreens); |
| 62 |
assertEquals(null, supportsScreens.getAnyDensity()); |
| 63 |
assertEquals(null, supportsScreens.getResizeable()); |
| 64 |
assertEquals(null, supportsScreens.getSmallScreens()); |
| 65 |
assertEquals(null, supportsScreens.getNormalScreens()); |
| 66 |
assertEquals(Boolean.FALSE, supportsScreens.getLargeScreens()); |
| 67 |
|
| 68 |
supportsScreens = data.getSupportsScreensValues(); |
| 69 |
assertNotNull(supportsScreens); |
| 70 |
assertEquals(Boolean.TRUE, supportsScreens.getAnyDensity()); |
| 71 |
assertEquals(Boolean.TRUE, supportsScreens.getResizeable()); |
| 72 |
assertEquals(Boolean.TRUE, supportsScreens.getSmallScreens()); |
| 73 |
assertEquals(Boolean.TRUE, supportsScreens.getNormalScreens()); |
| 74 |
assertEquals(Boolean.FALSE, supportsScreens.getLargeScreens()); |
| 75 |
} |
| 76 |
|
| 77 |
public void testOverlapWith() { |
| 78 |
SupportsScreens supportsN = new SupportsScreens("false|false|false|true|false"); |
| 79 |
SupportsScreens supportsSL = new SupportsScreens("false|false|true|false|true"); |
| 80 |
|
| 81 |
assertTrue(supportsN.overlapWith(supportsSL)); |
| 82 |
assertTrue(supportsSL.overlapWith(supportsN)); |
| 83 |
} |
| 84 |
|
| 85 |
public void testCompareScreenSizesWith() { |
| 86 |
// set instance that support all combo of the three sizes. |
| 87 |
SupportsScreens supportsS = new SupportsScreens("false|false|true|false|false"); |
| 88 |
SupportsScreens supportsN = new SupportsScreens("false|false|false|true|false"); |
| 89 |
SupportsScreens supportsL = new SupportsScreens("false|false|false|false|true"); |
| 90 |
SupportsScreens supportsSL = new SupportsScreens("false|false|true|false|true"); |
| 91 |
|
| 92 |
assertEquals(-1, supportsS.compareScreenSizesWith(supportsN)); |
| 93 |
assertEquals( 1, supportsN.compareScreenSizesWith(supportsS)); |
| 94 |
assertEquals(-1, supportsN.compareScreenSizesWith(supportsL)); |
| 95 |
assertEquals(-1, supportsS.compareScreenSizesWith(supportsL)); |
| 96 |
|
| 97 |
// test thrown exception for overlapWith == true |
| 98 |
try { |
| 99 |
supportsSL.compareScreenSizesWith(supportsN); |
| 100 |
fail("Should have thrown IllegalArgumentException"); |
| 101 |
} catch (IllegalArgumentException e) { |
| 102 |
// success! |
| 103 |
} |
| 104 |
|
| 105 |
// test thrown exception for hasStrictlyDifferentScreenSupportAs == false |
| 106 |
try { |
| 107 |
supportsSL.compareScreenSizesWith(supportsS); |
| 108 |
fail("Should have thrown IllegalArgumentException"); |
| 109 |
} catch (IllegalArgumentException e) { |
| 110 |
// success! |
| 111 |
} |
| 112 |
|
| 113 |
} |
| 114 |
|
| 115 |
public void testHasStrictlyDifferentScreenSupportAs() { |
| 116 |
SupportsScreens supportsS = new SupportsScreens("false|false|true|false|false"); |
| 117 |
SupportsScreens supportsN = new SupportsScreens("false|false|false|true|false"); |
| 118 |
SupportsScreens supportsL = new SupportsScreens("false|false|false|false|true"); |
| 119 |
|
| 120 |
SupportsScreens supportsSN = new SupportsScreens("false|false|true|true|false"); |
| 121 |
SupportsScreens supportsNL = new SupportsScreens("false|false|false|true|true"); |
| 122 |
SupportsScreens supportsSL = new SupportsScreens("false|false|true|false|true"); |
| 123 |
SupportsScreens supportsSNL = new SupportsScreens("false|false|true|true|true"); |
| 124 |
|
| 125 |
assertTrue(supportsS.hasStrictlyDifferentScreenSupportAs(supportsN)); |
| 126 |
assertTrue(supportsS.hasStrictlyDifferentScreenSupportAs(supportsL)); |
| 127 |
assertTrue(supportsN.hasStrictlyDifferentScreenSupportAs(supportsS)); |
| 128 |
assertTrue(supportsN.hasStrictlyDifferentScreenSupportAs(supportsL)); |
| 129 |
assertTrue(supportsL.hasStrictlyDifferentScreenSupportAs(supportsS)); |
| 130 |
assertTrue(supportsL.hasStrictlyDifferentScreenSupportAs(supportsN)); |
| 131 |
|
| 132 |
|
| 133 |
assertFalse(supportsSN.hasStrictlyDifferentScreenSupportAs(supportsS)); |
| 134 |
assertFalse(supportsSN.hasStrictlyDifferentScreenSupportAs(supportsN)); |
| 135 |
assertTrue(supportsSN.hasStrictlyDifferentScreenSupportAs(supportsL)); |
| 136 |
assertFalse(supportsSL.hasStrictlyDifferentScreenSupportAs(supportsS)); |
| 137 |
assertTrue(supportsSL.hasStrictlyDifferentScreenSupportAs(supportsN)); |
| 138 |
assertFalse(supportsSL.hasStrictlyDifferentScreenSupportAs(supportsL)); |
| 139 |
assertTrue(supportsNL.hasStrictlyDifferentScreenSupportAs(supportsS)); |
| 140 |
assertFalse(supportsNL.hasStrictlyDifferentScreenSupportAs(supportsN)); |
| 141 |
assertFalse(supportsNL.hasStrictlyDifferentScreenSupportAs(supportsL)); |
| 142 |
assertFalse(supportsSNL.hasStrictlyDifferentScreenSupportAs(supportsS)); |
| 143 |
assertFalse(supportsSNL.hasStrictlyDifferentScreenSupportAs(supportsN)); |
| 144 |
assertFalse(supportsSNL.hasStrictlyDifferentScreenSupportAs(supportsL)); |
| 145 |
} |
| 146 |
} |