OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.base.test.util; |
| 6 |
| 7 import android.os.Build; |
| 8 |
| 9 import junit.framework.TestCase; |
| 10 |
| 11 import org.chromium.testing.local.LocalRobolectricTestRunner; |
| 12 import org.junit.Assert; |
| 13 import org.junit.Test; |
| 14 import org.junit.runner.RunWith; |
| 15 import org.robolectric.Robolectric; |
| 16 import org.robolectric.annotation.Config; |
| 17 |
| 18 /** Unit tests for the DisableIf annotation and its SkipCheck implementation. */ |
| 19 @RunWith(LocalRobolectricTestRunner.class) |
| 20 @Config(manifest = Config.NONE, reportSdk = 19) |
| 21 public class DisableIfTest { |
| 22 |
| 23 @Test |
| 24 public void testSdkIsLessThanAndIsLessThan() { |
| 25 TestCase sdkIsLessThan = new TestCase("sdkIsLessThan") { |
| 26 @DisableIf.Build(sdk_is_less_than = 21) |
| 27 public void sdkIsLessThan() {} |
| 28 }; |
| 29 Assert.assertTrue(new DisableIfSkipCheck().shouldSkip(sdkIsLessThan)); |
| 30 } |
| 31 |
| 32 @Test |
| 33 public void testSdkIsLessThanButIsEqual() { |
| 34 TestCase sdkIsEqual = new TestCase("sdkIsEqual") { |
| 35 @DisableIf.Build(sdk_is_less_than = 19) |
| 36 public void sdkIsEqual() {} |
| 37 }; |
| 38 Assert.assertFalse(new DisableIfSkipCheck().shouldSkip(sdkIsEqual)); |
| 39 } |
| 40 |
| 41 @Test |
| 42 public void testSdkIsLessThanButIsGreaterThan() { |
| 43 TestCase sdkIsGreaterThan = new TestCase("sdkIsGreaterThan") { |
| 44 @DisableIf.Build(sdk_is_less_than = 16) |
| 45 public void sdkIsGreaterThan() {} |
| 46 }; |
| 47 Assert.assertFalse(new DisableIfSkipCheck().shouldSkip(sdkIsGreaterThan)
); |
| 48 } |
| 49 |
| 50 @Test |
| 51 public void testSdkIsGreaterThanButIsLessThan() { |
| 52 TestCase sdkIsLessThan = new TestCase("sdkIsLessThan") { |
| 53 @DisableIf.Build(sdk_is_greater_than = 21) |
| 54 public void sdkIsLessThan() {} |
| 55 }; |
| 56 Assert.assertFalse(new DisableIfSkipCheck().shouldSkip(sdkIsLessThan)); |
| 57 } |
| 58 |
| 59 @Test |
| 60 public void testSdkIsGreaterThanButIsEqual() { |
| 61 TestCase sdkIsEqual = new TestCase("sdkIsEqual") { |
| 62 @DisableIf.Build(sdk_is_greater_than = 19) |
| 63 public void sdkIsEqual() {} |
| 64 }; |
| 65 Assert.assertFalse(new DisableIfSkipCheck().shouldSkip(sdkIsEqual)); |
| 66 } |
| 67 |
| 68 @Test |
| 69 public void testSdkIsGreaterThanAndIsGreaterThan() { |
| 70 TestCase sdkIsGreaterThan = new TestCase("sdkIsGreaterThan") { |
| 71 @DisableIf.Build(sdk_is_greater_than = 16) |
| 72 public void sdkIsGreaterThan() {} |
| 73 }; |
| 74 Assert.assertTrue(new DisableIfSkipCheck().shouldSkip(sdkIsGreaterThan))
; |
| 75 } |
| 76 |
| 77 @Test |
| 78 public void testSupportedAbiIncludesAndCpuAbiMatches() { |
| 79 TestCase supportedAbisCpuAbiMatch = new TestCase("supportedAbisCpuAbiMat
ch") { |
| 80 @DisableIf.Build(supported_abis_includes = "foo") |
| 81 public void supportedAbisCpuAbiMatch() {} |
| 82 }; |
| 83 String originalAbi = Build.CPU_ABI; |
| 84 String originalAbi2 = Build.CPU_ABI2; |
| 85 try { |
| 86 Robolectric.Reflection.setFinalStaticField(Build.class, "CPU_ABI", "
foo"); |
| 87 Robolectric.Reflection.setFinalStaticField(Build.class, "CPU_ABI2",
"bar"); |
| 88 Assert.assertTrue(new DisableIfSkipCheck().shouldSkip(supportedAbisC
puAbiMatch)); |
| 89 } finally { |
| 90 Robolectric.Reflection.setFinalStaticField(Build.class, "CPU_ABI", o
riginalAbi); |
| 91 Robolectric.Reflection.setFinalStaticField(Build.class, "CPU_ABI2",
originalAbi2); |
| 92 } |
| 93 } |
| 94 |
| 95 @Test |
| 96 public void testSupportedAbiIncludesAndCpuAbi2Matches() { |
| 97 TestCase supportedAbisCpuAbi2Match = new TestCase("supportedAbisCpuAbi2M
atch") { |
| 98 @DisableIf.Build(supported_abis_includes = "bar") |
| 99 public void supportedAbisCpuAbi2Match() {} |
| 100 }; |
| 101 String originalAbi = Build.CPU_ABI; |
| 102 String originalAbi2 = Build.CPU_ABI2; |
| 103 try { |
| 104 Robolectric.Reflection.setFinalStaticField(Build.class, "CPU_ABI", "
foo"); |
| 105 Robolectric.Reflection.setFinalStaticField(Build.class, "CPU_ABI2",
"bar"); |
| 106 Assert.assertTrue(new DisableIfSkipCheck().shouldSkip(supportedAbisC
puAbi2Match)); |
| 107 } finally { |
| 108 Robolectric.Reflection.setFinalStaticField(Build.class, "CPU_ABI", o
riginalAbi); |
| 109 Robolectric.Reflection.setFinalStaticField(Build.class, "CPU_ABI2",
originalAbi2); |
| 110 } |
| 111 } |
| 112 |
| 113 @Test |
| 114 public void testSupportedAbiIncludesButNoMatch() { |
| 115 TestCase supportedAbisNoMatch = new TestCase("supportedAbisNoMatch") { |
| 116 @DisableIf.Build(supported_abis_includes = "baz") |
| 117 public void supportedAbisNoMatch() {} |
| 118 }; |
| 119 String originalAbi = Build.CPU_ABI; |
| 120 String originalAbi2 = Build.CPU_ABI2; |
| 121 try { |
| 122 Robolectric.Reflection.setFinalStaticField(Build.class, "CPU_ABI", "
foo"); |
| 123 Robolectric.Reflection.setFinalStaticField(Build.class, "CPU_ABI2",
"bar"); |
| 124 Assert.assertFalse(new DisableIfSkipCheck().shouldSkip(supportedAbis
NoMatch)); |
| 125 } finally { |
| 126 Robolectric.Reflection.setFinalStaticField(Build.class, "CPU_ABI", o
riginalAbi); |
| 127 Robolectric.Reflection.setFinalStaticField(Build.class, "CPU_ABI2",
originalAbi2); |
| 128 } |
| 129 } |
| 130 |
| 131 @Test |
| 132 public void testHardwareIsMatches() { |
| 133 TestCase hardwareIsMatches = new TestCase("hardwareIsMatches") { |
| 134 @DisableIf.Build(hardware_is = "hammerhead") |
| 135 public void hardwareIsMatches() {} |
| 136 }; |
| 137 String originalHardware = Build.HARDWARE; |
| 138 try { |
| 139 Robolectric.Reflection.setFinalStaticField(Build.class, "HARDWARE",
"hammerhead"); |
| 140 Assert.assertTrue(new DisableIfSkipCheck().shouldSkip(hardwareIsMatc
hes)); |
| 141 } finally { |
| 142 Robolectric.Reflection.setFinalStaticField(Build.class, "HARDWARE",
originalHardware); |
| 143 } |
| 144 } |
| 145 |
| 146 @Test |
| 147 public void testHardwareIsDoesntMatch() { |
| 148 TestCase hardwareIsDoesntMatch = new TestCase("hardwareIsDoesntMatch") { |
| 149 @DisableIf.Build(hardware_is = "hammerhead") |
| 150 public void hardwareIsDoesntMatch() {} |
| 151 }; |
| 152 String originalHardware = Build.HARDWARE; |
| 153 try { |
| 154 Robolectric.Reflection.setFinalStaticField(Build.class, "HARDWARE",
"mako"); |
| 155 Assert.assertFalse(new DisableIfSkipCheck().shouldSkip(hardwareIsDoe
sntMatch)); |
| 156 } finally { |
| 157 Robolectric.Reflection.setFinalStaticField(Build.class, "HARDWARE",
originalHardware); |
| 158 } |
| 159 } |
| 160 } |
OLD | NEW |