diff options
author | Tor Norbye <tnorbye@google.com> | 2013-01-10 11:40:56 -0800 |
---|---|---|
committer | Tor Norbye <tnorbye@google.com> | 2013-01-14 16:44:46 -0800 |
commit | c910f93a712dd761e6a07ba2090ee7382cc4d692 (patch) | |
tree | d2b0ae886b2b7a2ac3c75acb4eea8a83d4668fc2 /lint/cli | |
parent | 2a5b7e72c8eeacb735c64e63e84cd0e06333babb (diff) | |
download | sdk-c910f93a712dd761e6a07ba2090ee7382cc4d692.zip sdk-c910f93a712dd761e6a07ba2090ee7382cc4d692.tar.gz sdk-c910f93a712dd761e6a07ba2090ee7382cc4d692.tar.bz2 |
Api Detector: Flag style definitions
This should help track down problems like
https://github.com/JakeWharton/ActionBarSherlock/issues/446
Change-Id: I5ed721189fcdd1090b2dfd5f64d2222e223aa4c5
Diffstat (limited to 'lint/cli')
3 files changed, 67 insertions, 0 deletions
diff --git a/lint/cli/src/test/java/com/android/tools/lint/MainTest.java b/lint/cli/src/test/java/com/android/tools/lint/MainTest.java index 2ff470e..8ba40aa 100644 --- a/lint/cli/src/test/java/com/android/tools/lint/MainTest.java +++ b/lint/cli/src/test/java/com/android/tools/lint/MainTest.java @@ -139,6 +139,11 @@ public class MainTest extends AbstractCheckTest { "@TargetApi(11), such that this check considers 11 rather than your manifest\n" + "file's minimum SDK as the required API level.\n" + "\n" + + "If you are deliberately setting android: attributes in style definitions, make\n" + + "sure you place this in a values-v11 folder in order to avoid running into\n" + + "runtime conflicts on certain devices where manufacturers have added custom\n" + + "attributes whose ids conflict with the new ones on later platforms.\n" + + "\n" + "Similarly, you can use tools:targetApi=\"11\" in an XML file to indicate that\n" + "the element will only be inflated in an adequate context.\n" + "\n" + diff --git a/lint/cli/src/test/java/com/android/tools/lint/checks/ApiDetectorTest.java b/lint/cli/src/test/java/com/android/tools/lint/checks/ApiDetectorTest.java index 1bcbfaa..a4c7e4a 100644 --- a/lint/cli/src/test/java/com/android/tools/lint/checks/ApiDetectorTest.java +++ b/lint/cli/src/test/java/com/android/tools/lint/checks/ApiDetectorTest.java @@ -786,4 +786,58 @@ public class ApiDetectorTest extends AbstractCheckTest { "apicheck/ApiSourceCheck.class.data=>bin/classes/test/pkg/ApiSourceCheck.class" )); } + + public void testStyleDeclaration() throws Exception { + assertEquals("" + + "res/values/styles2.xml:5: Error: android:actionBarStyle requires API level 11 (current min is 10) [NewApi]\n" + + " <item name=\"android:actionBarStyle\">...</item>\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "1 errors, 0 warnings\n", + + lintProject( + "apicheck/classpath=>.classpath", + "apicheck/minsdk10.xml=>AndroidManifest.xml", + "project.properties1=>project.properties", + "res/values/styles2.xml" + )); + } + + public void testStyleDeclarationInV9() throws Exception { + assertEquals("" + + "res/values-v9/styles2.xml:5: Error: android:actionBarStyle requires API level 11 (current min is 10) [NewApi]\n" + + " <item name=\"android:actionBarStyle\">...</item>\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "1 errors, 0 warnings\n", + + lintProject( + "apicheck/classpath=>.classpath", + "apicheck/minsdk10.xml=>AndroidManifest.xml", + "project.properties1=>project.properties", + "res/values/styles2.xml=>res/values-v9/styles2.xml" + )); + } + + public void testStyleDeclarationInV11() throws Exception { + assertEquals( + "No warnings.", + + lintProject( + "apicheck/classpath=>.classpath", + "apicheck/minsdk10.xml=>AndroidManifest.xml", + "project.properties1=>project.properties", + "res/values/styles2.xml=>res/values-v11/styles2.xml" + )); + } + + public void testStyleDeclarationInV14() throws Exception { + assertEquals( + "No warnings.", + + lintProject( + "apicheck/classpath=>.classpath", + "apicheck/minsdk10.xml=>AndroidManifest.xml", + "project.properties1=>project.properties", + "res/values/styles2.xml=>res/values-v14/styles2.xml" + )); + } } diff --git a/lint/cli/src/test/java/com/android/tools/lint/checks/data/res/values/styles2.xml b/lint/cli/src/test/java/com/android/tools/lint/checks/data/res/values/styles2.xml new file mode 100644 index 0000000..45422cb --- /dev/null +++ b/lint/cli/src/test/java/com/android/tools/lint/checks/data/res/values/styles2.xml @@ -0,0 +1,8 @@ +<resources xmlns:android="http://schemas.android.com/apk/res/android"> + <style android:name="MyStyle" parent="android:Theme.Light"> + <!-- if the minSdk level is less then 11, then this should be a lint error, since android:actionBarStyle is since API 11, + unless this is in a -v11 (or better) resource folder --> + <item name="android:actionBarStyle">...</item> + <item name="android:textColor">#999999</item> + </style> +</resources> |