diff options
62 files changed, 1893 insertions, 761 deletions
diff --git a/lint/cli/src/com/android/tools/lint/Main.java b/lint/cli/src/com/android/tools/lint/Main.java index 6cdb689..20825cb 100644 --- a/lint/cli/src/com/android/tools/lint/Main.java +++ b/lint/cli/src/com/android/tools/lint/Main.java @@ -105,29 +105,29 @@ public class Main extends LintClient { private static final int ERRNO_HELP = 4; private static final int ERRNO_INVALIDARGS = 5; - private List<Warning> mWarnings = new ArrayList<Warning>(); - private Set<String> mSuppress = new HashSet<String>(); - private Set<String> mEnabled = new HashSet<String>(); + protected List<Warning> mWarnings = new ArrayList<Warning>(); + protected Set<String> mSuppress = new HashSet<String>(); + protected Set<String> mEnabled = new HashSet<String>(); /** If non-null, only run the specified checks (possibly modified by enable/disables) */ - private Set<String> mCheck = null; - private boolean mHasErrors; - private boolean mSetExitCode; - private boolean mFullPath; - private int mErrorCount; - private int mWarningCount; - private boolean mShowLines = true; - private List<Reporter> mReporters = Lists.newArrayList(); - private boolean mQuiet; - private boolean mWarnAll; - private boolean mNoWarnings; - private boolean mAllErrors; - private List<File> mSources; - private List<File> mClasses; - - private Configuration mDefaultConfiguration; - private IssueRegistry mRegistry; - private LintDriver mDriver; - private boolean mShowAll; + protected Set<String> mCheck = null; + protected boolean mHasErrors; + protected boolean mSetExitCode; + protected boolean mFullPath; + protected int mErrorCount; + protected int mWarningCount; + protected boolean mShowLines = true; + protected List<Reporter> mReporters = Lists.newArrayList(); + protected boolean mQuiet; + protected boolean mWarnAll; + protected boolean mNoWarnings; + protected boolean mAllErrors; + protected List<File> mSources; + protected List<File> mClasses; + + protected Configuration mDefaultConfiguration; + protected IssueRegistry mRegistry; + protected LintDriver mDriver; + protected boolean mShowAll; /** Creates a CLI driver */ public Main() { @@ -1149,6 +1149,9 @@ public class Main extends LintClient { static String getLineOfOffset(String contents, int offset) { int end = contents.indexOf('\n', offset); + if (end == -1) { + end = contents.indexOf('\r', offset); + } return contents.substring(offset, end != -1 ? end : contents.length()); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AbstractCheckTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AbstractCheckTest.java index da84ae1..4351a7e 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AbstractCheckTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AbstractCheckTest.java @@ -19,6 +19,8 @@ package com.android.tools.lint.checks; import com.android.tools.lint.LintCliXmlParser; import com.android.tools.lint.LombokParser; import com.android.tools.lint.Main; +import com.android.tools.lint.Reporter; +import com.android.tools.lint.TextReporter; import com.android.tools.lint.client.api.Configuration; import com.android.tools.lint.client.api.IDomParser; import com.android.tools.lint.client.api.IJavaParser; @@ -28,7 +30,6 @@ import com.android.tools.lint.detector.api.Context; import com.android.tools.lint.detector.api.Detector; import com.android.tools.lint.detector.api.Issue; import com.android.tools.lint.detector.api.Location; -import com.android.tools.lint.detector.api.Position; import com.android.tools.lint.detector.api.Project; import com.android.tools.lint.detector.api.Severity; import com.google.common.io.Files; @@ -38,6 +39,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; +import java.io.StringWriter; import java.net.URISyntaxException; import java.net.URL; import java.security.CodeSource; @@ -92,23 +94,7 @@ public abstract class AbstractCheckTest extends TestCase { protected String checkLint(List<File> files) throws Exception { mOutput = new StringBuilder(); TestLintClient lintClient = new TestLintClient(); - LintDriver driver = new LintDriver(new CustomIssueRegistry(), lintClient); - driver.analyze(files, null /* scope */); - - List<String> errors = lintClient.getErrors(); - Collections.sort(errors); - for (String error : errors) { - if (mOutput.length() > 0) { - mOutput.append('\n'); - } - mOutput.append(error); - } - - if (mOutput.length() == 0) { - mOutput.append("No warnings."); - } - - String result = mOutput.toString(); + String result = lintClient.analyze(files); // The output typically contains a few directory/filenames. // On Windows we need to change the separators to the unix-style @@ -269,84 +255,71 @@ public abstract class AbstractCheckTest extends TestCase { } public class TestLintClient extends Main { - private List<String> mErrors = new ArrayList<String>(); + private StringWriter mWriter = new StringWriter(); - public List<String> getErrors() { - return mErrors; + TestLintClient() { + mReporters.add(new TextReporter(this, mWriter, false)); } - @Override - public void report(Context context, Issue issue, Severity severity, Location location, - String message, Object data) { - StringBuilder sb = new StringBuilder(); + public String analyze(List<File> files) throws Exception { + mDriver = new LintDriver(new CustomIssueRegistry(), this); + mDriver.analyze(files, null /* scope */); - if (issue == IssueRegistry.LINT_ERROR) { - return; + Collections.sort(mWarnings); + + for (Reporter reporter : mReporters) { + reporter.write(mErrorCount, mWarningCount, mWarnings); } - if (location != null && location.getFile() != null) { - // Include parent directory for locations that have alternates, since - // frequently the file name is the same across different resource folders - // and we want to make sure in the tests that we're indeed passing the - // right files in as secondary locations - if (location.getSecondary() != null || includeParentPath()) { - sb.append(location.getFile().getParentFile().getName() + "/" - + location.getFile().getName()); - } else { - sb.append(location.getFile().getName()); - } + mOutput.append(mWriter.toString()); - sb.append(':'); + if (mOutput.length() == 0) { + mOutput.append("No warnings."); + } - Position startPosition = location.getStart(); - if (startPosition != null) { - int line = startPosition.getLine(); - if (line >= 0) { - // line is 0-based, should display 1-based - sb.append(Integer.toString(line + 1)); - sb.append(':'); - } - } + String result = mOutput.toString(); + if (result.equals("\nNo issues found.\n")) { + result = "No warnings."; + } - sb.append(' '); + if (sTempDir != null && result.contains(sTempDir.getPath())) { + result = result.replace(sTempDir.getCanonicalFile().getPath(), "/TESTROOT"); + result = result.replace(sTempDir.getAbsoluteFile().getPath(), "/TESTROOT"); + result = result.replace(sTempDir.getPath(), "/TESTROOT"); + } + + return result; + } + + public String getErrors() throws Exception { + return mWriter.toString(); + } + + @Override + public void report(Context context, Issue issue, Severity severity, Location location, + String message, Object data) { + if (issue == IssueRegistry.LINT_ERROR) { + return; } if (severity == Severity.FATAL) { // Treat fatal errors like errors in the golden files. severity = Severity.ERROR; } - sb.append(severity.getDescription()); - sb.append(": "); - - sb.append(message); + // For messages into all secondary locations to ensure they get + // specifically included in the text report if (location != null && location.getSecondary() != null) { - location = location.getSecondary(); - while (location != null) { - if (location.getMessage() != null) { - sb.append('\n'); - sb.append("=> "); - sb.append(location.getFile().getParentFile().getName() + "/" - + location.getFile().getName()); - sb.append(':'); - Position startPosition = location.getStart(); - if (startPosition != null) { - int line = startPosition.getLine(); - if (line >= 0) { - // line is 0-based, should display 1-based - sb.append(Integer.toString(line + 1)); - sb.append(':'); - } - } - sb.append(' '); - if (location.getMessage() != null) { - sb.append(location.getMessage()); - } + Location l = location.getSecondary(); + while (l != null) { + if (l.getMessage() == null) { + l.setMessage("<No location-specific message"); } - location = location.getSecondary(); + l = l.getSecondary(); } } - mErrors.add(sb.toString()); + + super.report(context, issue, severity, location, message, data); } @Override diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AccessibilityDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AccessibilityDetectorTest.java index 9ba2826..9f8d13d 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AccessibilityDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AccessibilityDetectorTest.java @@ -27,10 +27,15 @@ public class AccessibilityDetectorTest extends AbstractCheckTest { public void testAccessibility() throws Exception { assertEquals( - "accessibility.xml:4: Warning: [Accessibility] Missing contentDescription " + - "attribute on image\n" + - "accessibility.xml:5: Warning: [Accessibility] Missing contentDescription " + - "attribute on image", - lintProject("res/layout/accessibility.xml")); + "res/layout/accessibility.xml:4: Warning: [Accessibility] Missing contentDescription attribute on image [ContentDescription]\n" + + " <ImageView android:id=\"@+id/android_logo\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\" android:src=\"@drawable/android_button\" android:focusable=\"false\" android:clickable=\"false\" android:layout_weight=\"1.0\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/accessibility.xml:5: Warning: [Accessibility] Missing contentDescription attribute on image [ContentDescription]\n" + + " <ImageButton android:importantForAccessibility=\"yes\" android:id=\"@+id/android_logo2\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\" android:src=\"@drawable/android_button\" android:focusable=\"false\" android:clickable=\"false\" android:layout_weight=\"1.0\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 2 warnings\n" + + "", + + lintProject("res/layout/accessibility.xml")); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AlwaysShowActionDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AlwaysShowActionDetectorTest.java index f38500b..51273d1 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AlwaysShowActionDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AlwaysShowActionDetectorTest.java @@ -27,22 +27,39 @@ public class AlwaysShowActionDetectorTest extends AbstractCheckTest { public void testXmlMenus() throws Exception { assertEquals( - "menu-land/actions.xml:6: Warning: Prefer \"ifRoom\" instead of \"always\"", + "res/menu-land/actions.xml:6: Warning: Prefer \"ifRoom\" instead of \"always\" [AlwaysShowAction]\n" + + " android:showAsAction=\"always|collapseActionView\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + " res/menu-land/actions.xml:13: <No location-specific message\n" + + " res/menu-land/actions.xml:18: <No location-specific message\n" + + " res/menu-land/actions.xml:54: <No location-specific message\n" + + "0 errors, 1 warnings\n" + + "", lintProject("res/menu-land/actions.xml")); } public void testXmlMenusWithFlags() throws Exception { assertEquals( - "menu-land/actions2.xml:6: Warning: Prefer \"ifRoom\" instead of \"always\"", + "res/menu-land/actions2.xml:6: Warning: Prefer \"ifRoom\" instead of \"always\" [AlwaysShowAction]\n" + + " android:showAsAction=\"always|collapseActionView\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + " res/menu-land/actions2.xml:13: <No location-specific message\n" + + " res/menu-land/actions2.xml:18: <No location-specific message\n" + + " res/menu-land/actions2.xml:54: <No location-specific message\n" + + "0 errors, 1 warnings\n" + + "", lintProject("res/menu-land/actions2.xml")); } public void testJavaFail() throws Exception { assertEquals( - "ActionTest1.java:7: Warning: Prefer \"SHOW_AS_ACTION_IF_ROOM\" instead of " + - "\"SHOW_AS_ACTION_ALWAYS\"", + "src/test/pkg/ActionTest1.java:7: Warning: Prefer \"SHOW_AS_ACTION_IF_ROOM\" instead of \"SHOW_AS_ACTION_ALWAYS\" [AlwaysShowAction]\n" + + " System.out.println(MenuItem.SHOW_AS_ACTION_ALWAYS);\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", // Only references to ALWAYS lintProject("src/test/pkg/ActionTest1.java.txt=>src/test/pkg/ActionTest1.java")); diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AnnotationDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AnnotationDetectorTest.java index 962b559..4c9d34d 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AnnotationDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/AnnotationDetectorTest.java @@ -25,10 +25,20 @@ import java.util.List; public class AnnotationDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "WrongAnnotation.java:11: Error: The @SuppresLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method\n" + - "WrongAnnotation.java:13: Error: The @SuppresLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method\n" + - "WrongAnnotation.java:8: Error: The @SuppresLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method\n" + - "WrongAnnotation.java:9: Error: The @SuppresLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method", + "src/test/pkg/WrongAnnotation.java:8: Error: The @SuppresLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" + + " public static void foobar(View view, @SuppressLint(\"NewApi\") int foo) { // Invalid: class-file check\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/WrongAnnotation.java:9: Error: The @SuppresLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" + + " @SuppressLint(\"NewApi\") // Invalid\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/WrongAnnotation.java:11: Error: The @SuppresLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" + + " @SuppressLint({\"SdCardPath\", \"NewApi\"}) // Invalid: class-file based check on local variable\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/WrongAnnotation.java:13: Error: The @SuppresLint annotation cannot be used on a local variable with the lint check 'NewApi': move out to the surrounding method [LocalSuppress]\n" + + " @android.annotation.SuppressLint({\"SdCardPath\", \"NewApi\"}) // Invalid (FQN)\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "4 errors, 0 warnings\n" + + "", lintProject( "src/test/pkg/WrongAnnotation.java.txt=>src/test/pkg/WrongAnnotation.java" diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ApiDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ApiDetectorTest.java index 686c730..b6cc828 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ApiDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ApiDetectorTest.java @@ -27,20 +27,36 @@ public class ApiDetectorTest extends AbstractCheckTest { public void testXmlApi1() throws Exception { assertEquals( - "colors.xml:9: Error: @android:color/holo_red_light requires API level 14 (current min is 1)\n" + - "layout.xml:15: Error: View requires API level 11 (current min is 1): <CalendarView>\n" + - "layout.xml:21: Error: View requires API level 14 (current min is 1): <GridLayout>\n" + - "layout.xml:22: Error: @android:attr/actionBarSplitStyle requires API level 14 (current min is 1)\n" + - "layout.xml:23: Error: @android:color/holo_red_light requires API level 14 (current min is 1)\n" + - "layout.xml:9: Error: View requires API level 5 (current min is 1): <QuickContactBadge>\n" + - "themes.xml:9: Error: @android:color/holo_red_light requires API level 14 (current min is 1)", + "res/color/colors.xml:9: Error: @android:color/holo_red_light requires API level 14 (current min is 1) [NewApi]\n" + + " <item name=\"android:windowBackground\"> @android:color/holo_red_light </item>\n" + + " ^\n" + + "res/layout/layout.xml:9: Error: View requires API level 5 (current min is 1): <QuickContactBadge> [NewApi]\n" + + " <QuickContactBadge\n" + + " ^\n" + + "res/layout/layout.xml:15: Error: View requires API level 11 (current min is 1): <CalendarView> [NewApi]\n" + + " <CalendarView\n" + + " ^\n" + + "res/layout/layout.xml:21: Error: View requires API level 14 (current min is 1): <GridLayout> [NewApi]\n" + + " <GridLayout\n" + + " ^\n" + + "res/layout/layout.xml:22: Error: @android:attr/actionBarSplitStyle requires API level 14 (current min is 1) [NewApi]\n" + + " foo=\"@android:attr/actionBarSplitStyle\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/layout.xml:23: Error: @android:color/holo_red_light requires API level 14 (current min is 1) [NewApi]\n" + + " bar=\"@android:color/holo_red_light\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/values/themes.xml:9: Error: @android:color/holo_red_light requires API level 14 (current min is 1) [NewApi]\n" + + " <item name=\"android:windowBackground\"> @android:color/holo_red_light </item>\n" + + " ^\n" + + "7 errors, 0 warnings\n" + + "", - lintProject( - "apicheck/minsdk1.xml=>AndroidManifest.xml", - "apicheck/layout.xml=>res/layout/layout.xml", - "apicheck/themes.xml=>res/values/themes.xml", - "apicheck/themes.xml=>res/color/colors.xml" - )); + lintProject( + "apicheck/minsdk1.xml=>AndroidManifest.xml", + "apicheck/layout.xml=>res/layout/layout.xml", + "apicheck/themes.xml=>res/values/themes.xml", + "apicheck/themes.xml=>res/color/colors.xml" + )); } public void testXmlApi14() throws Exception { @@ -57,18 +73,30 @@ public class ApiDetectorTest extends AbstractCheckTest { public void testXmlApiFolderVersion11() throws Exception { assertEquals( - "colors.xml:9: Error: @android:color/holo_red_light requires API level 14 (current min is 1)\n" + - "layout.xml:21: Error: View requires API level 14 (current min is 1): <GridLayout>\n" + - "layout.xml:22: Error: @android:attr/actionBarSplitStyle requires API level 14 (current min is 1)\n" + - "layout.xml:23: Error: @android:color/holo_red_light requires API level 14 (current min is 1)\n" + - "themes.xml:9: Error: @android:color/holo_red_light requires API level 14 (current min is 1)", + "res/color-v11/colors.xml:9: Error: @android:color/holo_red_light requires API level 14 (current min is 1) [NewApi]\n" + + " <item name=\"android:windowBackground\"> @android:color/holo_red_light </item>\n" + + " ^\n" + + "res/layout-v11/layout.xml:21: Error: View requires API level 14 (current min is 1): <GridLayout> [NewApi]\n" + + " <GridLayout\n" + + " ^\n" + + "res/layout-v11/layout.xml:22: Error: @android:attr/actionBarSplitStyle requires API level 14 (current min is 1) [NewApi]\n" + + " foo=\"@android:attr/actionBarSplitStyle\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout-v11/layout.xml:23: Error: @android:color/holo_red_light requires API level 14 (current min is 1) [NewApi]\n" + + " bar=\"@android:color/holo_red_light\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/values-v11/themes.xml:9: Error: @android:color/holo_red_light requires API level 14 (current min is 1) [NewApi]\n" + + " <item name=\"android:windowBackground\"> @android:color/holo_red_light </item>\n" + + " ^\n" + + "5 errors, 0 warnings\n" + + "", - lintProject( - "apicheck/minsdk1.xml=>AndroidManifest.xml", - "apicheck/layout.xml=>res/layout-v11/layout.xml", - "apicheck/themes.xml=>res/values-v11/themes.xml", - "apicheck/themes.xml=>res/color-v11/colors.xml" - )); + lintProject( + "apicheck/minsdk1.xml=>AndroidManifest.xml", + "apicheck/layout.xml=>res/layout-v11/layout.xml", + "apicheck/themes.xml=>res/values-v11/themes.xml", + "apicheck/themes.xml=>res/color-v11/colors.xml" + )); } public void testXmlApiFolderVersion14() throws Exception { @@ -85,18 +113,44 @@ public class ApiDetectorTest extends AbstractCheckTest { public void testApi1() throws Exception { assertEquals( - "ApiCallTest.java:18: Error: Class requires API level 8 (current min is 1): org.w3c.dom.DOMLocator\n" + - "ApiCallTest.java:20: Error: Call requires API level 11 (current min is 1): android.app.Activity#getActionBar\n" + - "ApiCallTest.java:23: Error: Class requires API level 8 (current min is 1): org.w3c.dom.DOMError\n" + - "ApiCallTest.java:24: Error: Class requires API level 8 (current min is 1): org.w3c.dom.DOMErrorHandler\n" + - "ApiCallTest.java:27: Error: Call requires API level 3 (current min is 1): android.widget.Chronometer#getOnChronometerTickListener\n" + - "ApiCallTest.java:30: Error: Call requires API level 11 (current min is 1): android.widget.Chronometer#setTextIsSelectable\n" + - "ApiCallTest.java:33: Error: Field requires API level 11 (current min is 1): dalvik.bytecode.OpcodeInfo#MAXIMUM_VALUE\n" + - "ApiCallTest.java:38: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport.BatteryInfo\n" + - "ApiCallTest.java:38: Error: Field requires API level 14 (current min is 1): android.app.ApplicationErrorReport#batteryInfo\n" + - "ApiCallTest.java:41: Error: Field requires API level 11 (current min is 1): android.graphics.PorterDuff$Mode#OVERLAY\n" + - "ApiCallTest.java:45: Error: Class requires API level 14 (current min is 1): android.widget.GridLayout\n" + - "ApiCallTest.java:49: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport", + "src/foo/bar/ApiCallTest.java:18: Error: Class requires API level 8 (current min is 1): org.w3c.dom.DOMLocator [NewApi]\n" + + " public void method(Chronometer chronometer, DOMLocator locator) {\n" + + " ~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:20: Error: Call requires API level 11 (current min is 1): android.app.Activity#getActionBar [NewApi]\n" + + " getActionBar(); // API 11\n" + + " ~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:23: Error: Class requires API level 8 (current min is 1): org.w3c.dom.DOMError [NewApi]\n" + + " DOMError error = null; // API 8\n" + + " ~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:24: Error: Class requires API level 8 (current min is 1): org.w3c.dom.DOMErrorHandler [NewApi]\n" + + " Class<?> clz = DOMErrorHandler.class; // API 8\n" + + " ~~~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:27: Error: Call requires API level 3 (current min is 1): android.widget.Chronometer#getOnChronometerTickListener [NewApi]\n" + + " chronometer.getOnChronometerTickListener(); // API 3 \n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:30: Error: Call requires API level 11 (current min is 1): android.widget.Chronometer#setTextIsSelectable [NewApi]\n" + + " chronometer.setTextIsSelectable(true); // API 11\n" + + " ~~~~~~~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:33: Error: Field requires API level 11 (current min is 1): dalvik.bytecode.OpcodeInfo#MAXIMUM_VALUE [NewApi]\n" + + " int field = OpcodeInfo.MAXIMUM_VALUE; // API 11\n" + + " ~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:38: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport.BatteryInfo [NewApi]\n" + + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + + " ^\n" + + "src/foo/bar/ApiCallTest.java:38: Error: Field requires API level 14 (current min is 1): android.app.ApplicationErrorReport#batteryInfo [NewApi]\n" + + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + + " ~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:41: Error: Field requires API level 11 (current min is 1): android.graphics.PorterDuff$Mode#OVERLAY [NewApi]\n" + + " Mode mode = PorterDuff.Mode.OVERLAY; // API 11\n" + + " ~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:45: Error: Class requires API level 14 (current min is 1): android.widget.GridLayout [NewApi]\n" + + " GridLayout getGridLayout() { // API 14\n" + + " ~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:49: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport [NewApi]\n" + + " private ApplicationErrorReport getReport() {\n" + + " ~~~~~~~~~\n" + + "12 errors, 0 warnings\n" + + "", lintProject( "apicheck/classpath=>.classpath", @@ -108,18 +162,44 @@ public class ApiDetectorTest extends AbstractCheckTest { public void testApi2() throws Exception { assertEquals( - "ApiCallTest.java:18: Error: Class requires API level 8 (current min is 2): org.w3c.dom.DOMLocator\n" + - "ApiCallTest.java:20: Error: Call requires API level 11 (current min is 2): android.app.Activity#getActionBar\n" + - "ApiCallTest.java:23: Error: Class requires API level 8 (current min is 2): org.w3c.dom.DOMError\n" + - "ApiCallTest.java:24: Error: Class requires API level 8 (current min is 2): org.w3c.dom.DOMErrorHandler\n" + - "ApiCallTest.java:27: Error: Call requires API level 3 (current min is 2): android.widget.Chronometer#getOnChronometerTickListener\n" + - "ApiCallTest.java:30: Error: Call requires API level 11 (current min is 2): android.widget.Chronometer#setTextIsSelectable\n" + - "ApiCallTest.java:33: Error: Field requires API level 11 (current min is 2): dalvik.bytecode.OpcodeInfo#MAXIMUM_VALUE\n" + - "ApiCallTest.java:38: Error: Class requires API level 14 (current min is 2): android.app.ApplicationErrorReport.BatteryInfo\n" + - "ApiCallTest.java:38: Error: Field requires API level 14 (current min is 2): android.app.ApplicationErrorReport#batteryInfo\n" + - "ApiCallTest.java:41: Error: Field requires API level 11 (current min is 2): android.graphics.PorterDuff$Mode#OVERLAY\n" + - "ApiCallTest.java:45: Error: Class requires API level 14 (current min is 2): android.widget.GridLayout\n" + - "ApiCallTest.java:49: Error: Class requires API level 14 (current min is 2): android.app.ApplicationErrorReport", + "src/foo/bar/ApiCallTest.java:18: Error: Class requires API level 8 (current min is 2): org.w3c.dom.DOMLocator [NewApi]\n" + + " public void method(Chronometer chronometer, DOMLocator locator) {\n" + + " ~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:20: Error: Call requires API level 11 (current min is 2): android.app.Activity#getActionBar [NewApi]\n" + + " getActionBar(); // API 11\n" + + " ~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:23: Error: Class requires API level 8 (current min is 2): org.w3c.dom.DOMError [NewApi]\n" + + " DOMError error = null; // API 8\n" + + " ~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:24: Error: Class requires API level 8 (current min is 2): org.w3c.dom.DOMErrorHandler [NewApi]\n" + + " Class<?> clz = DOMErrorHandler.class; // API 8\n" + + " ~~~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:27: Error: Call requires API level 3 (current min is 2): android.widget.Chronometer#getOnChronometerTickListener [NewApi]\n" + + " chronometer.getOnChronometerTickListener(); // API 3 \n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:30: Error: Call requires API level 11 (current min is 2): android.widget.Chronometer#setTextIsSelectable [NewApi]\n" + + " chronometer.setTextIsSelectable(true); // API 11\n" + + " ~~~~~~~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:33: Error: Field requires API level 11 (current min is 2): dalvik.bytecode.OpcodeInfo#MAXIMUM_VALUE [NewApi]\n" + + " int field = OpcodeInfo.MAXIMUM_VALUE; // API 11\n" + + " ~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:38: Error: Class requires API level 14 (current min is 2): android.app.ApplicationErrorReport.BatteryInfo [NewApi]\n" + + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + + " ^\n" + + "src/foo/bar/ApiCallTest.java:38: Error: Field requires API level 14 (current min is 2): android.app.ApplicationErrorReport#batteryInfo [NewApi]\n" + + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + + " ~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:41: Error: Field requires API level 11 (current min is 2): android.graphics.PorterDuff$Mode#OVERLAY [NewApi]\n" + + " Mode mode = PorterDuff.Mode.OVERLAY; // API 11\n" + + " ~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:45: Error: Class requires API level 14 (current min is 2): android.widget.GridLayout [NewApi]\n" + + " GridLayout getGridLayout() { // API 14\n" + + " ~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:49: Error: Class requires API level 14 (current min is 2): android.app.ApplicationErrorReport [NewApi]\n" + + " private ApplicationErrorReport getReport() {\n" + + " ~~~~~~~~~\n" + + "12 errors, 0 warnings\n" + + "", lintProject( "apicheck/classpath=>.classpath", @@ -131,17 +211,41 @@ public class ApiDetectorTest extends AbstractCheckTest { public void testApi4() throws Exception { assertEquals( - "ApiCallTest.java:18: Error: Class requires API level 8 (current min is 4): org.w3c.dom.DOMLocator\n" + - "ApiCallTest.java:20: Error: Call requires API level 11 (current min is 4): android.app.Activity#getActionBar\n" + - "ApiCallTest.java:23: Error: Class requires API level 8 (current min is 4): org.w3c.dom.DOMError\n" + - "ApiCallTest.java:24: Error: Class requires API level 8 (current min is 4): org.w3c.dom.DOMErrorHandler\n" + - "ApiCallTest.java:30: Error: Call requires API level 11 (current min is 4): android.widget.Chronometer#setTextIsSelectable\n" + - "ApiCallTest.java:33: Error: Field requires API level 11 (current min is 4): dalvik.bytecode.OpcodeInfo#MAXIMUM_VALUE\n" + - "ApiCallTest.java:38: Error: Class requires API level 14 (current min is 4): android.app.ApplicationErrorReport.BatteryInfo\n" + - "ApiCallTest.java:38: Error: Field requires API level 14 (current min is 4): android.app.ApplicationErrorReport#batteryInfo\n" + - "ApiCallTest.java:41: Error: Field requires API level 11 (current min is 4): android.graphics.PorterDuff$Mode#OVERLAY\n" + - "ApiCallTest.java:45: Error: Class requires API level 14 (current min is 4): android.widget.GridLayout\n" + - "ApiCallTest.java:49: Error: Class requires API level 14 (current min is 4): android.app.ApplicationErrorReport", + "src/foo/bar/ApiCallTest.java:18: Error: Class requires API level 8 (current min is 4): org.w3c.dom.DOMLocator [NewApi]\n" + + " public void method(Chronometer chronometer, DOMLocator locator) {\n" + + " ~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:20: Error: Call requires API level 11 (current min is 4): android.app.Activity#getActionBar [NewApi]\n" + + " getActionBar(); // API 11\n" + + " ~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:23: Error: Class requires API level 8 (current min is 4): org.w3c.dom.DOMError [NewApi]\n" + + " DOMError error = null; // API 8\n" + + " ~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:24: Error: Class requires API level 8 (current min is 4): org.w3c.dom.DOMErrorHandler [NewApi]\n" + + " Class<?> clz = DOMErrorHandler.class; // API 8\n" + + " ~~~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:30: Error: Call requires API level 11 (current min is 4): android.widget.Chronometer#setTextIsSelectable [NewApi]\n" + + " chronometer.setTextIsSelectable(true); // API 11\n" + + " ~~~~~~~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:33: Error: Field requires API level 11 (current min is 4): dalvik.bytecode.OpcodeInfo#MAXIMUM_VALUE [NewApi]\n" + + " int field = OpcodeInfo.MAXIMUM_VALUE; // API 11\n" + + " ~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:38: Error: Class requires API level 14 (current min is 4): android.app.ApplicationErrorReport.BatteryInfo [NewApi]\n" + + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + + " ^\n" + + "src/foo/bar/ApiCallTest.java:38: Error: Field requires API level 14 (current min is 4): android.app.ApplicationErrorReport#batteryInfo [NewApi]\n" + + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + + " ~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:41: Error: Field requires API level 11 (current min is 4): android.graphics.PorterDuff$Mode#OVERLAY [NewApi]\n" + + " Mode mode = PorterDuff.Mode.OVERLAY; // API 11\n" + + " ~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:45: Error: Class requires API level 14 (current min is 4): android.widget.GridLayout [NewApi]\n" + + " GridLayout getGridLayout() { // API 14\n" + + " ~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:49: Error: Class requires API level 14 (current min is 4): android.app.ApplicationErrorReport [NewApi]\n" + + " private ApplicationErrorReport getReport() {\n" + + " ~~~~~~~~~\n" + + "11 errors, 0 warnings\n" + + "", lintProject( "apicheck/classpath=>.classpath", @@ -153,14 +257,32 @@ public class ApiDetectorTest extends AbstractCheckTest { public void testApi10() throws Exception { assertEquals( - "ApiCallTest.java:20: Error: Call requires API level 11 (current min is 10): android.app.Activity#getActionBar\n" + - "ApiCallTest.java:30: Error: Call requires API level 11 (current min is 10): android.widget.Chronometer#setTextIsSelectable\n" + - "ApiCallTest.java:33: Error: Field requires API level 11 (current min is 10): dalvik.bytecode.OpcodeInfo#MAXIMUM_VALUE\n" + - "ApiCallTest.java:38: Error: Class requires API level 14 (current min is 10): android.app.ApplicationErrorReport.BatteryInfo\n" + - "ApiCallTest.java:38: Error: Field requires API level 14 (current min is 10): android.app.ApplicationErrorReport#batteryInfo\n" + - "ApiCallTest.java:41: Error: Field requires API level 11 (current min is 10): android.graphics.PorterDuff$Mode#OVERLAY\n" + - "ApiCallTest.java:45: Error: Class requires API level 14 (current min is 10): android.widget.GridLayout\n" + - "ApiCallTest.java:49: Error: Class requires API level 14 (current min is 10): android.app.ApplicationErrorReport", + "src/foo/bar/ApiCallTest.java:20: Error: Call requires API level 11 (current min is 10): android.app.Activity#getActionBar [NewApi]\n" + + " getActionBar(); // API 11\n" + + " ~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:30: Error: Call requires API level 11 (current min is 10): android.widget.Chronometer#setTextIsSelectable [NewApi]\n" + + " chronometer.setTextIsSelectable(true); // API 11\n" + + " ~~~~~~~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:33: Error: Field requires API level 11 (current min is 10): dalvik.bytecode.OpcodeInfo#MAXIMUM_VALUE [NewApi]\n" + + " int field = OpcodeInfo.MAXIMUM_VALUE; // API 11\n" + + " ~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:38: Error: Class requires API level 14 (current min is 10): android.app.ApplicationErrorReport.BatteryInfo [NewApi]\n" + + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + + " ^\n" + + "src/foo/bar/ApiCallTest.java:38: Error: Field requires API level 14 (current min is 10): android.app.ApplicationErrorReport#batteryInfo [NewApi]\n" + + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + + " ~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:41: Error: Field requires API level 11 (current min is 10): android.graphics.PorterDuff$Mode#OVERLAY [NewApi]\n" + + " Mode mode = PorterDuff.Mode.OVERLAY; // API 11\n" + + " ~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:45: Error: Class requires API level 14 (current min is 10): android.widget.GridLayout [NewApi]\n" + + " GridLayout getGridLayout() { // API 14\n" + + " ~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest.java:49: Error: Class requires API level 14 (current min is 10): android.app.ApplicationErrorReport [NewApi]\n" + + " private ApplicationErrorReport getReport() {\n" + + " ~~~~~~~~~\n" + + "8 errors, 0 warnings\n" + + "", lintProject( "apicheck/classpath=>.classpath", @@ -184,10 +306,20 @@ public class ApiDetectorTest extends AbstractCheckTest { public void testInheritStatic() throws Exception { assertEquals( - "ApiCallTest5.java:16: Error: Call requires API level 11 (current min is 2): android.view.View#resolveSizeAndState\n" + - "ApiCallTest5.java:18: Error: Call requires API level 11 (current min is 2): android.view.View#resolveSizeAndState\n" + - "ApiCallTest5.java:20: Error: Call requires API level 11 (current min is 2): android.view.View#combineMeasuredStates\n" + - "ApiCallTest5.java:21: Error: Call requires API level 11 (current min is 2): android.view.View#combineMeasuredStates", + "src/foo/bar/ApiCallTest5.java:16: Error: Call requires API level 11 (current min is 2): android.view.View#resolveSizeAndState [NewApi]\n" + + " int measuredWidth = View.resolveSizeAndState(widthMeasureSpec,\n" + + " ~~~~~~~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest5.java:18: Error: Call requires API level 11 (current min is 2): android.view.View#resolveSizeAndState [NewApi]\n" + + " int measuredHeight = resolveSizeAndState(heightMeasureSpec,\n" + + " ~~~~~~~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest5.java:20: Error: Call requires API level 11 (current min is 2): android.view.View#combineMeasuredStates [NewApi]\n" + + " View.combineMeasuredStates(0, 0);\n" + + " ~~~~~~~~~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiCallTest5.java:21: Error: Call requires API level 11 (current min is 2): android.view.View#combineMeasuredStates [NewApi]\n" + + " ApiCallTest5.combineMeasuredStates(0, 0);\n" + + " ~~~~~~~~~~~~~~~~~~~~~\n" + + "4 errors, 0 warnings\n" + + "", lintProject( "apicheck/classpath=>.classpath", @@ -201,7 +333,11 @@ public class ApiDetectorTest extends AbstractCheckTest { // Test virtual dispatch in a local class which extends some other local class (which // in turn extends an Android API) assertEquals( - "ApiCallTest3.java:10: Error: Call requires API level 11 (current min is 1): android.app.Activity#getActionBar", + "src/test/pkg/ApiCallTest3.java:10: Error: Call requires API level 11 (current min is 1): android.app.Activity#getActionBar [NewApi]\n" + + " getActionBar(); // API 11\n" + + " ~~~~~~~~~~~~\n" + + "1 errors, 0 warnings\n" + + "", lintProject( "apicheck/classpath=>.classpath", @@ -215,10 +351,20 @@ public class ApiDetectorTest extends AbstractCheckTest { public void testViewClassLayoutReference() throws Exception { assertEquals( - "view.xml:16: Error: View requires API level 11 (current min is 1): <CalendarView>\n" + - "view.xml:24: Error: ?android:attr/dividerHorizontal requires API level 11 (current min is 1)\n" + - "view.xml:25: Error: ?android:attr/textColorLinkInverse requires API level 11 (current min is 1)\n" + - "view.xml:9: Error: View requires API level 5 (current min is 1): <QuickContactBadge>", + "res/layout/view.xml:9: Error: View requires API level 5 (current min is 1): <QuickContactBadge> [NewApi]\n" + + " <view\n" + + " ^\n" + + "res/layout/view.xml:16: Error: View requires API level 11 (current min is 1): <CalendarView> [NewApi]\n" + + " <view\n" + + " ^\n" + + "res/layout/view.xml:24: Error: ?android:attr/dividerHorizontal requires API level 11 (current min is 1) [NewApi]\n" + + " unknown=\"?android:attr/dividerHorizontal\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/view.xml:25: Error: ?android:attr/textColorLinkInverse requires API level 11 (current min is 1) [NewApi]\n" + + " android:textColor=\"?android:attr/textColorLinkInverse\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "4 errors, 0 warnings\n" + + "", lintProject( "apicheck/minsdk1.xml=>AndroidManifest.xml", @@ -229,7 +375,11 @@ public class ApiDetectorTest extends AbstractCheckTest { public void testIOException() throws Exception { // See http://code.google.com/p/android/issues/detail?id=35190 assertEquals( - "ApiCallTest6.java:8: Error: Call requires API level 9 (current min is 1): java.io.IOException#<init>", + "src/test/pkg/ApiCallTest6.java:8: Error: Call requires API level 9 (current min is 1): java.io.IOException#<init> [NewApi]\n" + + " IOException ioException = new IOException(throwable);\n" + + " ~~~~~~~~~~~\n" + + "1 errors, 0 warnings\n" + + "", lintProject( "apicheck/classpath=>.classpath", @@ -248,22 +398,50 @@ public class ApiDetectorTest extends AbstractCheckTest { // These errors are correctly -not- suppressed because they // appear in method3 (line 74-98) which is annotated with a // @SuppressLint annotation specifying only an unrelated issue id - "SuppressTest1.java:74: Error: Class requires API level 8 (current min is 1): org.w3c.dom.DOMLocator\n" + - "SuppressTest1.java:76: Error: Call requires API level 11 (current min is 1): android.app.Activity#getActionBar\n" + - "SuppressTest1.java:79: Error: Class requires API level 8 (current min is 1): org.w3c.dom.DOMError\n" + - "SuppressTest1.java:80: Error: Class requires API level 8 (current min is 1): org.w3c.dom.DOMErrorHandler\n" + - "SuppressTest1.java:83: Error: Call requires API level 3 (current min is 1): android.widget.Chronometer#getOnChronometerTickListener\n" + - "SuppressTest1.java:86: Error: Call requires API level 11 (current min is 1): android.widget.Chronometer#setTextIsSelectable\n" + - "SuppressTest1.java:89: Error: Field requires API level 11 (current min is 1): dalvik.bytecode.OpcodeInfo#MAXIMUM_VALUE\n" + - "SuppressTest1.java:94: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport.BatteryInfo\n" + - "SuppressTest1.java:94: Error: Field requires API level 14 (current min is 1): android.app.ApplicationErrorReport#batteryInfo\n" + - "SuppressTest1.java:97: Error: Field requires API level 11 (current min is 1): android.graphics.PorterDuff$Mode#OVERLAY\n" + + "src/foo/bar/SuppressTest1.java:74: Error: Class requires API level 8 (current min is 1): org.w3c.dom.DOMLocator [NewApi]\n" + + " public void method3(Chronometer chronometer, DOMLocator locator) {\n" + + " ~~~~~~~~~~\n" + + "src/foo/bar/SuppressTest1.java:76: Error: Call requires API level 11 (current min is 1): android.app.Activity#getActionBar [NewApi]\n" + + " getActionBar(); // API 11\n" + + " ~~~~~~~~~~~~\n" + + "src/foo/bar/SuppressTest1.java:79: Error: Class requires API level 8 (current min is 1): org.w3c.dom.DOMError [NewApi]\n" + + " DOMError error = null; // API 8\n" + + " ~~~~~~~~\n" + + "src/foo/bar/SuppressTest1.java:80: Error: Class requires API level 8 (current min is 1): org.w3c.dom.DOMErrorHandler [NewApi]\n" + + " Class<?> clz = DOMErrorHandler.class; // API 8\n" + + " ~~~~~~~~~~~~~~~\n" + + "src/foo/bar/SuppressTest1.java:83: Error: Call requires API level 3 (current min is 1): android.widget.Chronometer#getOnChronometerTickListener [NewApi]\n" + + " chronometer.getOnChronometerTickListener(); // API 3\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/foo/bar/SuppressTest1.java:86: Error: Call requires API level 11 (current min is 1): android.widget.Chronometer#setTextIsSelectable [NewApi]\n" + + " chronometer.setTextIsSelectable(true); // API 11\n" + + " ~~~~~~~~~~~~~~~~~~~\n" + + "src/foo/bar/SuppressTest1.java:89: Error: Field requires API level 11 (current min is 1): dalvik.bytecode.OpcodeInfo#MAXIMUM_VALUE [NewApi]\n" + + " int field = OpcodeInfo.MAXIMUM_VALUE; // API 11\n" + + " ~~~~~~~~~~~~~\n" + + "src/foo/bar/SuppressTest1.java:94: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport.BatteryInfo [NewApi]\n" + + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + + " ^\n" + + "src/foo/bar/SuppressTest1.java:94: Error: Field requires API level 14 (current min is 1): android.app.ApplicationErrorReport#batteryInfo [NewApi]\n" + + " BatteryInfo batteryInfo = getReport().batteryInfo;\n" + + " ~~~~~~~~~~~\n" + + "src/foo/bar/SuppressTest1.java:97: Error: Field requires API level 11 (current min is 1): android.graphics.PorterDuff$Mode#OVERLAY [NewApi]\n" + + " Mode mode = PorterDuff.Mode.OVERLAY; // API 11\n" + + " ~~~~~~~\n" + // Note: These annotations are within the methods, not ON the methods, so they have // no effect (because they don't end up in the bytecode) - "SuppressTest4.java:16: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport\n" + - "SuppressTest4.java:19: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport.BatteryInfo\n" + - "SuppressTest4.java:19: Error: Field requires API level 14 (current min is 1): android.app.ApplicationErrorReport#batteryInfo", + + "src/foo/bar/SuppressTest4.java:16: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport [NewApi]\n" + + " ApplicationErrorReport report = null;\n" + + " ~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/foo/bar/SuppressTest4.java:19: Error: Class requires API level 14 (current min is 1): android.app.ApplicationErrorReport.BatteryInfo [NewApi]\n" + + " BatteryInfo batteryInfo = report.batteryInfo;\n" + + " ^\n" + + "src/foo/bar/SuppressTest4.java:19: Error: Field requires API level 14 (current min is 1): android.app.ApplicationErrorReport#batteryInfo [NewApi]\n" + + " BatteryInfo batteryInfo = report.batteryInfo;\n" + + " ~~~~~~~~~~~\n" + + "13 errors, 0 warnings\n", lintProject( "apicheck/classpath=>.classpath", @@ -284,8 +462,14 @@ public class ApiDetectorTest extends AbstractCheckTest { // These errors are correctly -not- suppressed because they // appear outside the middle inner class suppressing its own errors // and its child's errors - "ApiCallTest4.java:38: Error: Call requires API level 14 (current min is 1): android.widget.GridLayout#<init>\n" + - "ApiCallTest4.java:9: Error: Call requires API level 14 (current min is 1): android.widget.GridLayout#<init>", + "src/test/pkg/ApiCallTest4.java:9: Error: Call requires API level 14 (current min is 1): android.widget.GridLayout#<init> [NewApi]\n" + + " new GridLayout(null, null, 0);\n" + + " ~~~~~~~~~~\n" + + "src/test/pkg/ApiCallTest4.java:38: Error: Call requires API level 14 (current min is 1): android.widget.GridLayout#<init> [NewApi]\n" + + " new GridLayout(null, null, 0);\n" + + " ~~~~~~~~~~\n" + + "2 errors, 0 warnings\n" + + "", lintProject( "apicheck/classpath=>.classpath", @@ -301,9 +485,17 @@ public class ApiDetectorTest extends AbstractCheckTest { public void testApiTargetAnnotation() throws Exception { assertEquals( - "ApiTargetTest.java:13: Error: Class requires API level 8 (current min is 1): org.w3c.dom.DOMErrorHandler\n" + - "ApiTargetTest.java:25: Error: Class requires API level 8 (current min is 4): org.w3c.dom.DOMErrorHandler\n" + - "ApiTargetTest.java:39: Error: Class requires API level 8 (current min is 7): org.w3c.dom.DOMErrorHandler", + "src/foo/bar/ApiTargetTest.java:13: Error: Class requires API level 8 (current min is 1): org.w3c.dom.DOMErrorHandler [NewApi]\n" + + " Class<?> clz = DOMErrorHandler.class; // API 8\n" + + " ~~~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiTargetTest.java:25: Error: Class requires API level 8 (current min is 4): org.w3c.dom.DOMErrorHandler [NewApi]\n" + + " Class<?> clz = DOMErrorHandler.class; // API 8\n" + + " ~~~~~~~~~~~~~~~\n" + + "src/foo/bar/ApiTargetTest.java:39: Error: Class requires API level 8 (current min is 7): org.w3c.dom.DOMErrorHandler [NewApi]\n" + + " Class<?> clz = DOMErrorHandler.class; // API 8\n" + + " ~~~~~~~~~~~~~~~\n" + + "3 errors, 0 warnings\n" + + "", lintProject( "apicheck/classpath=>.classpath", @@ -316,7 +508,11 @@ public class ApiDetectorTest extends AbstractCheckTest { public void testTargetAnnotationInner() throws Exception { assertEquals( - "ApiTargetTest2.java:32: Error: Call requires API level 14 (current min is 3): android.widget.GridLayout#<init>", + "src/test/pkg/ApiTargetTest2.java:32: Error: Call requires API level 14 (current min is 3): android.widget.GridLayout#<init> [NewApi]\n" + + " new GridLayout(null, null, 0);\n" + + " ~~~~~~~~~~\n" + + "1 errors, 0 warnings\n" + + "", lintProject( "apicheck/classpath=>.classpath", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ArraySizeDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ArraySizeDetectorTest.java index 37f6af2..629f43c 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ArraySizeDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ArraySizeDetectorTest.java @@ -26,12 +26,18 @@ public class ArraySizeDetectorTest extends AbstractCheckTest { } public void testArraySizes() throws Exception { assertEquals( - "values/arrays.xml:10: Warning: Array signal_strength has an inconsistent number of items (5 in values/arrays.xml, 6 in values-land/arrays.xml)\n" + - "=> values-land/arrays.xml:2: Declaration with array size (6)\n" + - "values/arrays.xml:3: Warning: Array security_questions has an inconsistent number of items (3 in values-nl-rNL/arrays.xml, 4 in values-cs/arrays.xml)\n" + - "=> values-cs/arrays.xml:3: Declaration with array size (4)\n" + - "=> values-es/strings.xml:12: Declaration with array size (4)\n" + - "=> values-nl-rNL/arrays.xml:3: Declaration with array size (3)", + "res/values/arrays.xml:3: Warning: Array security_questions has an inconsistent number of items (3 in values-nl-rNL/arrays.xml, 4 in values-cs/arrays.xml) [InconsistentArrays]\n" + + " <string-array name=\"security_questions\">\n" + + " ^\n" + + " res/values-cs/arrays.xml:3: Declaration with array size (4)\n" + + " res/values-es/strings.xml:12: Declaration with array size (4)\n" + + " res/values-nl-rNL/arrays.xml:3: Declaration with array size (3)\n" + + "res/values/arrays.xml:10: Warning: Array signal_strength has an inconsistent number of items (5 in values/arrays.xml, 6 in values-land/arrays.xml) [InconsistentArrays]\n" + + " <array name=\"signal_strength\">\n" + + " ^\n" + + " res/values-land/arrays.xml:2: Declaration with array size (6)\n" + + "0 errors, 2 warnings\n" + + "", lintProject( "res/values/arrays.xml", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ButtonDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ButtonDetectorTest.java index ae43039..f9fb059 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ButtonDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ButtonDetectorTest.java @@ -37,13 +37,29 @@ public class ButtonDetectorTest extends AbstractCheckTest { public void testButtonOrder() throws Exception { sTestIssue = ButtonDetector.ORDER; assertEquals( - "buttonbar.xml:124: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:12: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:140: Warning: OK button should be on the right (was \"Ok | CANCEL\", should be \"CANCEL | Ok\")\n" + - "buttonbar.xml:156: Warning: OK button should be on the right (was \"OK | Abort\", should be \"Abort | OK\")\n" + - "buttonbar.xml:177: Warning: Cancel button should be on the left (was \"Send | Cancel\", should be \"Cancel | Send\")\n" + - "buttonbar.xml:44: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:92: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")", + "res/layout/buttonbar.xml:12: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout/buttonbar.xml:44: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout/buttonbar.xml:92: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout/buttonbar.xml:124: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout/buttonbar.xml:140: Warning: OK button should be on the right (was \"Ok | CANCEL\", should be \"CANCEL | Ok\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout/buttonbar.xml:156: Warning: OK button should be on the right (was \"OK | Abort\", should be \"Abort | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout/buttonbar.xml:177: Warning: Cancel button should be on the left (was \"Send | Cancel\", should be \"Cancel | Send\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "0 errors, 7 warnings\n" + + "", lintProject( "apicheck/minsdk14.xml=>AndroidManifest.xml", @@ -55,13 +71,29 @@ public class ButtonDetectorTest extends AbstractCheckTest { // If the layout is in v14, it had better have the right order sTestIssue = ButtonDetector.ORDER; assertEquals( - "buttonbar.xml:124: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:12: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:140: Warning: OK button should be on the right (was \"Ok | CANCEL\", should be \"CANCEL | Ok\")\n" + - "buttonbar.xml:156: Warning: OK button should be on the right (was \"OK | Abort\", should be \"Abort | OK\")\n" + - "buttonbar.xml:177: Warning: Cancel button should be on the left (was \"Send | Cancel\", should be \"Cancel | Send\")\n" + - "buttonbar.xml:44: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:92: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")", + "res/layout-v14/buttonbar.xml:12: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-v14/buttonbar.xml:44: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-v14/buttonbar.xml:92: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-v14/buttonbar.xml:124: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-v14/buttonbar.xml:140: Warning: OK button should be on the right (was \"Ok | CANCEL\", should be \"CANCEL | Ok\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-v14/buttonbar.xml:156: Warning: OK button should be on the right (was \"OK | Abort\", should be \"Abort | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-v14/buttonbar.xml:177: Warning: Cancel button should be on the left (was \"Send | Cancel\", should be \"Cancel | Send\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "0 errors, 7 warnings\n" + + "", lintProject( "minsdk5targetsdk14.xml=>AndroidManifest.xml", @@ -73,13 +105,29 @@ public class ButtonDetectorTest extends AbstractCheckTest { // Similar to test 3, but also complain if the -v version is *higher* than 14 sTestIssue = ButtonDetector.ORDER; assertEquals( - "buttonbar.xml:124: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:12: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:140: Warning: OK button should be on the right (was \"Ok | CANCEL\", should be \"CANCEL | Ok\")\n" + - "buttonbar.xml:156: Warning: OK button should be on the right (was \"OK | Abort\", should be \"Abort | OK\")\n" + - "buttonbar.xml:177: Warning: Cancel button should be on the left (was \"Send | Cancel\", should be \"Cancel | Send\")\n" + - "buttonbar.xml:44: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:92: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")", + "res/layout-v16/buttonbar.xml:12: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-v16/buttonbar.xml:44: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-v16/buttonbar.xml:92: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-v16/buttonbar.xml:124: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-v16/buttonbar.xml:140: Warning: OK button should be on the right (was \"Ok | CANCEL\", should be \"CANCEL | Ok\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-v16/buttonbar.xml:156: Warning: OK button should be on the right (was \"OK | Abort\", should be \"Abort | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-v16/buttonbar.xml:177: Warning: Cancel button should be on the left (was \"Send | Cancel\", should be \"Cancel | Send\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "0 errors, 7 warnings\n" + + "", lintProject( "minsdk5targetsdk14.xml=>AndroidManifest.xml", @@ -91,13 +139,29 @@ public class ButtonDetectorTest extends AbstractCheckTest { // Targeting 14 but using a layout that also needs to work for older platforms: sTestIssue = ButtonDetector.ORDER; assertEquals( - "buttonbar.xml:124: Warning: Layout uses the wrong button order for API >= 14: Create a layout-v14/buttonbar.xml file with opposite order: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:12: Warning: Layout uses the wrong button order for API >= 14: Create a layout-v14/buttonbar.xml file with opposite order: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:140: Warning: Layout uses the wrong button order for API >= 14: Create a layout-v14/buttonbar.xml file with opposite order: OK button should be on the right (was \"Ok | CANCEL\", should be \"CANCEL | Ok\")\n" + - "buttonbar.xml:156: Warning: Layout uses the wrong button order for API >= 14: Create a layout-v14/buttonbar.xml file with opposite order: OK button should be on the right (was \"OK | Abort\", should be \"Abort | OK\")\n" + - "buttonbar.xml:177: Warning: Layout uses the wrong button order for API >= 14: Create a layout-v14/buttonbar.xml file with opposite order: Cancel button should be on the left (was \"Send | Cancel\", should be \"Cancel | Send\")\n" + - "buttonbar.xml:44: Warning: Layout uses the wrong button order for API >= 14: Create a layout-v14/buttonbar.xml file with opposite order: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:92: Warning: Layout uses the wrong button order for API >= 14: Create a layout-v14/buttonbar.xml file with opposite order: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")", + "res/layout/buttonbar.xml:12: Warning: Layout uses the wrong button order for API >= 14: Create a layout-v14/buttonbar.xml file with opposite order: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout/buttonbar.xml:44: Warning: Layout uses the wrong button order for API >= 14: Create a layout-v14/buttonbar.xml file with opposite order: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout/buttonbar.xml:92: Warning: Layout uses the wrong button order for API >= 14: Create a layout-v14/buttonbar.xml file with opposite order: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout/buttonbar.xml:124: Warning: Layout uses the wrong button order for API >= 14: Create a layout-v14/buttonbar.xml file with opposite order: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout/buttonbar.xml:140: Warning: Layout uses the wrong button order for API >= 14: Create a layout-v14/buttonbar.xml file with opposite order: OK button should be on the right (was \"Ok | CANCEL\", should be \"CANCEL | Ok\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout/buttonbar.xml:156: Warning: Layout uses the wrong button order for API >= 14: Create a layout-v14/buttonbar.xml file with opposite order: OK button should be on the right (was \"OK | Abort\", should be \"Abort | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout/buttonbar.xml:177: Warning: Layout uses the wrong button order for API >= 14: Create a layout-v14/buttonbar.xml file with opposite order: Cancel button should be on the left (was \"Send | Cancel\", should be \"Cancel | Send\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "0 errors, 7 warnings\n" + + "", lintProject( "minsdk5targetsdk14.xml=>AndroidManifest.xml", @@ -130,7 +194,11 @@ public class ButtonDetectorTest extends AbstractCheckTest { public void testButtonOrderRelativeLayout2() throws Exception { sTestIssue = ButtonDetector.ORDER; assertEquals( - "buttonbar3.xml:27: Warning: Cancel button should be on the left", + "res/layout/buttonbar3.xml:27: Warning: Cancel button should be on the left [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "apicheck/minsdk14.xml=>AndroidManifest.xml", @@ -150,8 +218,14 @@ public class ButtonDetectorTest extends AbstractCheckTest { public void testCase() throws Exception { sTestIssue = ButtonDetector.CASE; assertEquals( - "buttonbar-values.xml:10: Warning: The standard Android way to capitalize CANCEL is \"Cancel\" (tip: use @android:string/ok instead)\n" + - "buttonbar-values.xml:9: Warning: The standard Android way to capitalize Ok is \"OK\" (tip: use @android:string/ok instead)", + "res/values/buttonbar-values.xml:9: Warning: The standard Android way to capitalize Ok is \"OK\" (tip: use @android:string/ok instead) [ButtonCase]\n" + + " <string name=\"resume2\"> Ok </string>\n" + + " ^\n" + + "res/values/buttonbar-values.xml:10: Warning: The standard Android way to capitalize CANCEL is \"Cancel\" (tip: use @android:string/ok instead) [ButtonCase]\n" + + " <string name=\"giveup2\">\"CANCEL\"</string>\n" + + " ^\n" + + "0 errors, 2 warnings\n" + + "", lintProject("res/layout/buttonbar.xml", "res/values/buttonbar-values.xml")); } @@ -159,7 +233,11 @@ public class ButtonDetectorTest extends AbstractCheckTest { public void testBack() throws Exception { sTestIssue = ButtonDetector.BACKBUTTON; assertEquals( - "buttonbar.xml:183: Warning: Back buttons are not standard on Android; see design guide's navigation section", + "res/layout/buttonbar.xml:183: Warning: Back buttons are not standard on Android; see design guide's navigation section [BackButton]\n" + + " <Button\n" + + " ^\n" + + "0 errors, 1 warnings\n" + + "", lintProject("res/layout/buttonbar.xml", "res/values/buttonbar-values.xml")); } @@ -179,31 +257,53 @@ public class ButtonDetectorTest extends AbstractCheckTest { public void testEnglishLocales() throws Exception { sTestIssue = ButtonDetector.ORDER; assertEquals( - "buttonbar.xml:124: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:12: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:140: Warning: OK button should be on the right (was \"Ok | CANCEL\", should be \"CANCEL | Ok\")\n" + - "buttonbar.xml:156: Warning: OK button should be on the right (was \"OK | Abort\", should be \"Abort | OK\")\n" + - "buttonbar.xml:177: Warning: Cancel button should be on the left (was \"Send | Cancel\", should be \"Cancel | Send\")\n" + - "buttonbar.xml:44: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:92: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")", + "res/layout-en-rGB/buttonbar.xml:12: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-en-rGB/buttonbar.xml:44: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-en-rGB/buttonbar.xml:92: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-en-rGB/buttonbar.xml:124: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-en-rGB/buttonbar.xml:140: Warning: OK button should be on the right (was \"Ok | CANCEL\", should be \"CANCEL | Ok\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-en-rGB/buttonbar.xml:156: Warning: OK button should be on the right (was \"OK | Abort\", should be \"Abort | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-en-rGB/buttonbar.xml:177: Warning: Cancel button should be on the left (was \"Send | Cancel\", should be \"Cancel | Send\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "0 errors, 7 warnings\n" + + "", - lintProject( - "apicheck/minsdk14.xml=>AndroidManifest.xml", - "res/layout/buttonbar.xml=>res/layout-en-rGB/buttonbar.xml", - "res/values/buttonbar-values.xml=>res/values-en-rGB/buttonbar-values.xml")); + lintProject( + "apicheck/minsdk14.xml=>AndroidManifest.xml", + "res/layout/buttonbar.xml=>res/layout-en-rGB/buttonbar.xml", + "res/values/buttonbar-values.xml=>res/values-en-rGB/buttonbar-values.xml")); } public void testOtherLocales() throws Exception { sTestIssue = ButtonDetector.ORDER; assertEquals( - // Hardcoded values only - "buttonbar.xml:12: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")\n" + - "buttonbar.xml:44: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\")", + // Hardcoded values only + "res/layout-de/buttonbar.xml:12: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "res/layout-de/buttonbar.xml:44: Warning: OK button should be on the right (was \"OK | Cancel\", should be \"Cancel | OK\") [ButtonOrder]\n" + + " <Button\n" + + " ^\n" + + "0 errors, 2 warnings\n" + + "", - lintProject( - "apicheck/minsdk14.xml=>AndroidManifest.xml", - "res/layout/buttonbar.xml=>res/layout-de/buttonbar.xml", - "res/values/buttonbar-values.xml=>res/values-de/buttonbar-values.xml")); + lintProject( + "apicheck/minsdk14.xml=>AndroidManifest.xml", + "res/layout/buttonbar.xml=>res/layout-de/buttonbar.xml", + "res/values/buttonbar-values.xml=>res/values-de/buttonbar-values.xml")); } public void testOtherLocales2() throws Exception { diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ChildCountDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ChildCountDetectorTest.java index b668c31..517ca4d 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ChildCountDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ChildCountDetectorTest.java @@ -27,9 +27,12 @@ public class ChildCountDetectorTest extends AbstractCheckTest { public void testChildCount() throws Exception { assertEquals( - "has_children.xml:3: Warning: A list/grid should have no children declared " + - "in XML", - lintFiles("res/layout/has_children.xml")); + "res/layout/has_children.xml:3: Warning: A list/grid should have no children declared in XML [AdapterViewChildren]\n" + + "<ListView\n" + + "^\n" + + "0 errors, 1 warnings\n" + + "", + lintFiles("res/layout/has_children.xml")); } public void testChildCount2() throws Exception { diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ColorUsageDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ColorUsageDetectorTest.java index f30f05e..d1a04e1 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ColorUsageDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ColorUsageDetectorTest.java @@ -27,9 +27,17 @@ public class ColorUsageDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "WrongColor.java:11: Error: Should pass resolved color instead of resource id here: getResources().getColor(R.color.red)\n" + - "WrongColor.java:12: Error: Should pass resolved color instead of resource id here: getResources().getColor(android.R.color.red)\n" + - "WrongColor.java:9: Error: Should pass resolved color instead of resource id here: getResources().getColor(R.color.blue)", + "src/test/pkg/WrongColor.java:9: Error: Should pass resolved color instead of resource id here: getResources().getColor(R.color.blue) [ResourceAsColor]\n" + + " paint2.setColor(R.color.blue);\n" + + " ~~~~~~~~~~~~\n" + + "src/test/pkg/WrongColor.java:11: Error: Should pass resolved color instead of resource id here: getResources().getColor(R.color.red) [ResourceAsColor]\n" + + " textView.setTextColor(R.color.red);\n" + + " ~~~~~~~~~~~\n" + + "src/test/pkg/WrongColor.java:12: Error: Should pass resolved color instead of resource id here: getResources().getColor(android.R.color.red) [ResourceAsColor]\n" + + " textView.setTextColor(android.R.color.red);\n" + + " ~~~~~~~~~~~~~~~~~~~\n" + + "3 errors, 0 warnings\n" + + "", lintProject("src/test/pkg/WrongColor.java.txt=>src/test/pkg/WrongColor.java")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/DeprecationDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/DeprecationDetectorTest.java index 5185737..0e4ec2f 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/DeprecationDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/DeprecationDetectorTest.java @@ -27,9 +27,14 @@ public class DeprecationDetectorTest extends AbstractCheckTest { public void testApi1() throws Exception { assertEquals( - "deprecation.xml:18: Warning: android:editable is deprecated: Use an <EditText> to make it editable\n" + - //"deprecation.xml:19: Warning: android:enabled is deprecated: Use state_enabled instead\n" + - "deprecation.xml:2: Warning: AbsoluteLayout is deprecated", + "res/layout/deprecation.xml:2: Warning: AbsoluteLayout is deprecated [Deprecated]\n" + + "<AbsoluteLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + + "^\n" + + "res/layout/deprecation.xml:18: Warning: android:editable is deprecated: Use an <EditText> to make it editable [Deprecated]\n" + + " android:editable=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 2 warnings\n" + + "", lintProject( "apicheck/minsdk1.xml=>AndroidManifest.xml", @@ -38,15 +43,32 @@ public class DeprecationDetectorTest extends AbstractCheckTest { public void testApi4() throws Exception { assertEquals( - "deprecation.xml:16: Warning: android:autoText is deprecated: Use inputType instead\n" + - "deprecation.xml:17: Warning: android:capitalize is deprecated: Use inputType instead\n" + - "deprecation.xml:18: Warning: android:editable is deprecated: Use an <EditText> to make it editable\n" + - //"deprecation.xml:19: Warning: android:enabled is deprecated: Use state_enabled instead\n" + - "deprecation.xml:20: Warning: android:inputMethod is deprecated: Use inputType instead\n" + - "deprecation.xml:21: Warning: android:numeric is deprecated: Use inputType instead\n" + - "deprecation.xml:22: Warning: android:password is deprecated: Use inputType instead\n" + - "deprecation.xml:23: Warning: android:phoneNumber is deprecated: Use inputType instead\n" + - "deprecation.xml:2: Warning: AbsoluteLayout is deprecated", + "res/layout/deprecation.xml:2: Warning: AbsoluteLayout is deprecated [Deprecated]\n" + + "<AbsoluteLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + + "^\n" + + "res/layout/deprecation.xml:16: Warning: android:autoText is deprecated: Use inputType instead [Deprecated]\n" + + " android:autoText=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/deprecation.xml:17: Warning: android:capitalize is deprecated: Use inputType instead [Deprecated]\n" + + " android:capitalize=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/deprecation.xml:18: Warning: android:editable is deprecated: Use an <EditText> to make it editable [Deprecated]\n" + + " android:editable=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/deprecation.xml:20: Warning: android:inputMethod is deprecated: Use inputType instead [Deprecated]\n" + + " android:inputMethod=\"@+id/foo\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/deprecation.xml:21: Warning: android:numeric is deprecated: Use inputType instead [Deprecated]\n" + + " android:numeric=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/deprecation.xml:22: Warning: android:password is deprecated: Use inputType instead [Deprecated]\n" + + " android:password=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/deprecation.xml:23: Warning: android:phoneNumber is deprecated: Use inputType instead [Deprecated]\n" + + " android:phoneNumber=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 8 warnings\n" + + "", lintProject( "apicheck/minsdk4.xml=>AndroidManifest.xml", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/DetectMissingPrefixTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/DetectMissingPrefixTest.java index 2f15558..8a4f6b0 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/DetectMissingPrefixTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/DetectMissingPrefixTest.java @@ -27,17 +27,27 @@ public class DetectMissingPrefixTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "namespace.xml:2: Warning: Attribute is missing the Android namespace prefix\n" + - "namespace.xml:3: Warning: Attribute is missing the Android namespace prefix", - - lintFiles("res/layout/namespace.xml")); + "res/layout/namespace.xml:2: Warning: Attribute is missing the Android namespace prefix [MissingPrefix]\n" + + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" android:id=\"@+id/newlinear\" android:orientation=\"vertical\" android:layout_width=\"match_parent\" android:layout_height=\"match_parent\" orientation=\"true\">\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/namespace.xml:3: Warning: Attribute is missing the Android namespace prefix [MissingPrefix]\n" + + " <Button style=\"@style/setupWizardOuterFrame\" android.text=\"Button\" android:id=\"@+id/button1\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\"></Button>\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 2 warnings\n" + + "", + + lintFiles("res/layout/namespace.xml")); } public void testCustomNamespace() throws Exception { assertEquals( - "namespace2.xml:8: Warning: Attribute is missing the Android namespace prefix", + "res/layout/namespace2.xml:8: Warning: Attribute is missing the Android namespace prefix [MissingPrefix]\n" + + " customprefix:orientation=\"vertical\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", - lintFiles("res/layout/namespace2.xml")); + lintFiles("res/layout/namespace2.xml")); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/DuplicateIdDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/DuplicateIdDetectorTest.java index 284ea42..72a9035 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/DuplicateIdDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/DuplicateIdDetectorTest.java @@ -27,23 +27,35 @@ public class DuplicateIdDetectorTest extends AbstractCheckTest { public void testDuplicate() throws Exception { assertEquals( - "layout/duplicate.xml:5: Warning: Duplicate id @+id/android_logo, already defined earlier in this layout\n" + - "=> layout/duplicate.xml:4: @+id/android_logo originally defined here", + "res/layout/duplicate.xml:5: Warning: Duplicate id @+id/android_logo, already defined earlier in this layout [DuplicateIds]\n" + + " <ImageButton android:id=\"@+id/android_logo\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\" android:src=\"@drawable/android_button\" android:focusable=\"false\" android:clickable=\"false\" android:layout_weight=\"1.0\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + " res/layout/duplicate.xml:4: @+id/android_logo originally defined here\n" + + "0 errors, 1 warnings\n" + + "", lintFiles("res/layout/duplicate.xml")); } public void testDuplicateChains() throws Exception { assertEquals( - "layout/layout1.xml:7: Warning: Duplicate id @+id/button1, defined or included multiple times in layout/layout1.xml: [layout/layout1.xml defines @+id/button1, layout/layout1.xml => layout/layout2.xml => layout/layout3.xml defines @+id/button1, layout/layout1.xml => layout/layout2.xml => layout/layout4.xml defines @+id/button1]\n" + - "=> layout/layout1.xml:13: Defined here\n" + - "=> layout/layout3.xml:8: Defined here, included via layout/layout1.xml => layout/layout2.xml => layout/layout3.xml defines @+id/button1\n" + - "=> layout/layout4.xml:8: Defined here, included via layout/layout1.xml => layout/layout2.xml => layout/layout4.xml defines @+id/button1\n" + - "layout/layout1.xml:7: Warning: Duplicate id @+id/button2, defined or included multiple times in layout/layout1.xml: [layout/layout1.xml defines @+id/button2, layout/layout1.xml => layout/layout2.xml => layout/layout4.xml defines @+id/button2]\n" + - "=> layout/layout1.xml:19: Defined here\n" + - "=> layout/layout4.xml:14: Defined here, included via layout/layout1.xml => layout/layout2.xml => layout/layout4.xml defines @+id/button2\n" + - "layout/layout2.xml:18: Warning: Duplicate id @+id/button1, defined or included multiple times in layout/layout2.xml: [layout/layout2.xml => layout/layout3.xml defines @+id/button1, layout/layout2.xml => layout/layout4.xml defines @+id/button1]\n" + - "=> layout/layout3.xml:8: Defined here, included via layout/layout2.xml => layout/layout3.xml defines @+id/button1\n" + - "=> layout/layout4.xml:8: Defined here, included via layout/layout2.xml => layout/layout4.xml defines @+id/button1", + "res/layout/layout1.xml:7: Warning: Duplicate id @+id/button1, defined or included multiple times in layout/layout1.xml: [layout/layout1.xml defines @+id/button1, layout/layout1.xml => layout/layout2.xml => layout/layout3.xml defines @+id/button1, layout/layout1.xml => layout/layout2.xml => layout/layout4.xml defines @+id/button1] [DuplicateIncludedIds]\n" + + " <include\n" + + " ^\n" + + " res/layout/layout1.xml:13: Defined here\n" + + " res/layout/layout3.xml:8: Defined here, included via layout/layout1.xml => layout/layout2.xml => layout/layout3.xml defines @+id/button1\n" + + " res/layout/layout4.xml:8: Defined here, included via layout/layout1.xml => layout/layout2.xml => layout/layout4.xml defines @+id/button1\n" + + "res/layout/layout1.xml:7: Warning: Duplicate id @+id/button2, defined or included multiple times in layout/layout1.xml: [layout/layout1.xml defines @+id/button2, layout/layout1.xml => layout/layout2.xml => layout/layout4.xml defines @+id/button2] [DuplicateIncludedIds]\n" + + " <include\n" + + " ^\n" + + " res/layout/layout1.xml:19: Defined here\n" + + " res/layout/layout4.xml:14: Defined here, included via layout/layout1.xml => layout/layout2.xml => layout/layout4.xml defines @+id/button2\n" + + "res/layout/layout2.xml:18: Warning: Duplicate id @+id/button1, defined or included multiple times in layout/layout2.xml: [layout/layout2.xml => layout/layout3.xml defines @+id/button1, layout/layout2.xml => layout/layout4.xml defines @+id/button1] [DuplicateIncludedIds]\n" + + " <include\n" + + " ^\n" + + " res/layout/layout3.xml:8: Defined here, included via layout/layout2.xml => layout/layout3.xml defines @+id/button1\n" + + " res/layout/layout4.xml:8: Defined here, included via layout/layout2.xml => layout/layout4.xml defines @+id/button1\n" + + "0 errors, 3 warnings\n" + + "", // layout1: defines @+id/button1, button2 // layout3: defines @+id/button1 @@ -62,9 +74,13 @@ public class DuplicateIdDetectorTest extends AbstractCheckTest { public void testSuppress() throws Exception { assertEquals( - "layout/layout2.xml:18: Warning: Duplicate id @+id/button1, defined or included multiple times in layout/layout2.xml: [layout/layout2.xml => layout/layout3.xml defines @+id/button1, layout/layout2.xml => layout/layout4.xml defines @+id/button1]\n" + - "=> layout/layout3.xml:8: Defined here, included via layout/layout2.xml => layout/layout3.xml defines @+id/button1\n" + - "=> layout/layout4.xml:8: Defined here, included via layout/layout2.xml => layout/layout4.xml defines @+id/button1", + "res/layout/layout2.xml:18: Warning: Duplicate id @+id/button1, defined or included multiple times in layout/layout2.xml: [layout/layout2.xml => layout/layout3.xml defines @+id/button1, layout/layout2.xml => layout/layout4.xml defines @+id/button1] [DuplicateIncludedIds]\n" + + " <include\n" + + " ^\n" + + " res/layout/layout3.xml:8: Defined here, included via layout/layout2.xml => layout/layout3.xml defines @+id/button1\n" + + " res/layout/layout4.xml:8: Defined here, included via layout/layout2.xml => layout/layout4.xml defines @+id/button1\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "res/layout/layout1_ignore.xml=>res/layout/layout1.xml", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ExtraTextDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ExtraTextDetectorTest.java index 5016828..9f6c2d3 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ExtraTextDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ExtraTextDetectorTest.java @@ -27,9 +27,11 @@ public class ExtraTextDetectorTest extends AbstractCheckTest { public void testBroken() throws Exception { assertEquals( - "broken.xml:6: Warning: Unexpected text found in layout file: \"ImageButton " + - "android:id=\"@+id/android_logo2\" android:layout_width=\"wrap_content\"" + - " android:layout_heigh...\"", - lintProject("res/layout/broken.xml")); + "res/layout/broken.xml:6: Warning: Unexpected text found in layout file: \"ImageButton android:id=\"@+id/android_logo2\" android:layout_width=\"wrap_content\" android:layout_heigh...\" [ExtraText]\n" + + " <Button android:text=\"Button\" android:id=\"@+id/button2\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\"></Button>\n" + + " ^\n" + + "0 errors, 1 warnings\n" + + "", + lintProject("res/layout/broken.xml")); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/FieldGetterDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/FieldGetterDetectorTest.java index 0c5db09..81c6f20 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/FieldGetterDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/FieldGetterDetectorTest.java @@ -27,11 +27,23 @@ public class FieldGetterDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "GetterTest.java:47: Warning: Calling getter method getFoo1() on self is slower than field access (mFoo1)\n" + - "GetterTest.java:48: Warning: Calling getter method getFoo2() on self is slower than field access (mFoo2)\n" + - "GetterTest.java:52: Warning: Calling getter method isBar1() on self is slower than field access (mBar1)\n" + - "GetterTest.java:54: Warning: Calling getter method getFoo1() on self is slower than field access (mFoo1)\n" + - "GetterTest.java:55: Warning: Calling getter method getFoo2() on self is slower than field access (mFoo2)", + "src/test/bytecode/GetterTest.java:47: Warning: Calling getter method getFoo1() on self is slower than field access (mFoo1) [FieldGetter]\n" + + " getFoo1();\n" + + " ~~~~~~~\n" + + "src/test/bytecode/GetterTest.java:48: Warning: Calling getter method getFoo2() on self is slower than field access (mFoo2) [FieldGetter]\n" + + " getFoo2();\n" + + " ~~~~~~~\n" + + "src/test/bytecode/GetterTest.java:52: Warning: Calling getter method isBar1() on self is slower than field access (mBar1) [FieldGetter]\n" + + " isBar1();\n" + + " ~~~~~~\n" + + "src/test/bytecode/GetterTest.java:54: Warning: Calling getter method getFoo1() on self is slower than field access (mFoo1) [FieldGetter]\n" + + " this.getFoo1();\n" + + " ~~~~~~~\n" + + "src/test/bytecode/GetterTest.java:55: Warning: Calling getter method getFoo2() on self is slower than field access (mFoo2) [FieldGetter]\n" + + " this.getFoo2();\n" + + " ~~~~~~~\n" + + "0 errors, 5 warnings\n" + + "", lintProject( "bytecode/.classpath=>.classpath", @@ -70,11 +82,23 @@ public class FieldGetterDetectorTest extends AbstractCheckTest { public void testJar() throws Exception { assertEquals( - "GetterTest.java:47: Warning: Calling getter method getFoo1() on self is slower than field access (mFoo1)\n" + - "GetterTest.java:48: Warning: Calling getter method getFoo2() on self is slower than field access (mFoo2)\n" + - "GetterTest.java:52: Warning: Calling getter method isBar1() on self is slower than field access (mBar1)\n" + - "GetterTest.java:54: Warning: Calling getter method getFoo1() on self is slower than field access (mFoo1)\n" + - "GetterTest.java:55: Warning: Calling getter method getFoo2() on self is slower than field access (mFoo2)", + "src/test/bytecode/GetterTest.java:47: Warning: Calling getter method getFoo1() on self is slower than field access (mFoo1) [FieldGetter]\n" + + " getFoo1();\n" + + " ~~~~~~~\n" + + "src/test/bytecode/GetterTest.java:48: Warning: Calling getter method getFoo2() on self is slower than field access (mFoo2) [FieldGetter]\n" + + " getFoo2();\n" + + " ~~~~~~~\n" + + "src/test/bytecode/GetterTest.java:52: Warning: Calling getter method isBar1() on self is slower than field access (mBar1) [FieldGetter]\n" + + " isBar1();\n" + + " ~~~~~~\n" + + "src/test/bytecode/GetterTest.java:54: Warning: Calling getter method getFoo1() on self is slower than field access (mFoo1) [FieldGetter]\n" + + " this.getFoo1();\n" + + " ~~~~~~~\n" + + "src/test/bytecode/GetterTest.java:55: Warning: Calling getter method getFoo2() on self is slower than field access (mFoo2) [FieldGetter]\n" + + " this.getFoo2();\n" + + " ~~~~~~~\n" + + "0 errors, 5 warnings\n" + + "", lintProject( "bytecode/classpath-jar=>.classpath", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/FragmentDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/FragmentDetectorTest.java index 467f286..f732f71 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/FragmentDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/FragmentDetectorTest.java @@ -27,12 +27,26 @@ public class FragmentDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "FragmentTest.java:10: Warning: This fragment class should be public (test.pkg.FragmentTest.Fragment1)\n" + - "FragmentTest.java:15: Warning: This fragment inner class should be static (test.pkg.FragmentTest.Fragment2)\n" + - "FragmentTest.java:21: Warning: The default constructor must be public\n" + - "FragmentTest.java:26: Warning: This fragment should provide a default constructor (a public constructor with no arguments) (test.pkg.FragmentTest.Fragment4)\n" + - "FragmentTest.java:27: Warning: Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(Bundle) instead\n" + - "FragmentTest.java:36: Warning: Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(Bundle) instead", + "src/test/pkg/FragmentTest.java:10: Warning: This fragment class should be public (test.pkg.FragmentTest.Fragment1) [ValidFragment]\n" + + " private static class Fragment1 extends Fragment {\n" + + " ^\n" + + "src/test/pkg/FragmentTest.java:15: Warning: This fragment inner class should be static (test.pkg.FragmentTest.Fragment2) [ValidFragment]\n" + + " public class Fragment2 extends Fragment {\n" + + " ^\n" + + "src/test/pkg/FragmentTest.java:21: Warning: The default constructor must be public [ValidFragment]\n" + + " private Fragment3() {\n" + + " ~~~~~~~~~\n" + + "src/test/pkg/FragmentTest.java:26: Warning: This fragment should provide a default constructor (a public constructor with no arguments) (test.pkg.FragmentTest.Fragment4) [ValidFragment]\n" + + " public static class Fragment4 extends Fragment {\n" + + " ~~~~~~~~~\n" + + "src/test/pkg/FragmentTest.java:27: Warning: Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(Bundle) instead [ValidFragment]\n" + + " private Fragment4(int dummy) {\n" + + " ~~~~~~~~~\n" + + "src/test/pkg/FragmentTest.java:36: Warning: Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(Bundle) instead [ValidFragment]\n" + + " public Fragment5(int dummy) {\n" + + " ~~~~~~~~~\n" + + "0 errors, 6 warnings\n" + + "", lintProject( "bytecode/FragmentTest$Fragment1.class.data=>bin/classes/test/pkg/FragmentTest$Fragment1.class", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/GridLayoutDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/GridLayoutDetectorTest.java index e91d434..dee52e1 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/GridLayoutDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/GridLayoutDetectorTest.java @@ -27,7 +27,11 @@ public class GridLayoutDetectorTest extends AbstractCheckTest { public void testGridLayout1() throws Exception { assertEquals( - "gridlayout.xml:36: Error: Column attribute (3) exceeds declared grid column count (2)", + "res/layout/gridlayout.xml:36: Error: Column attribute (3) exceeds declared grid column count (2) [GridLayout]\n" + + " android:layout_column=\"3\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "1 errors, 0 warnings\n" + + "", lintFiles("res/layout/gridlayout.xml")); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/HandlerDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/HandlerDetectorTest.java index e0fb840..1e9350c 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/HandlerDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/HandlerDetectorTest.java @@ -27,8 +27,14 @@ public class HandlerDetectorTest extends AbstractCheckTest { public void testRegistered() throws Exception { assertEquals( - "HandlerTest.java:12: Warning: This Handler class should be static or leaks might occur (test.pkg.HandlerTest.Inner)\n" + - "HandlerTest.java:18: Warning: This Handler class should be static or leaks might occur (test.pkg.HandlerTest.1)", + "src/test/pkg/HandlerTest.java:12: Warning: This Handler class should be static or leaks might occur (test.pkg.HandlerTest.Inner) [HandlerLeak]\n" + + " public class Inner extends Handler { // ERROR\n" + + " ~~~~~\n" + + "src/test/pkg/HandlerTest.java:18: Warning: This Handler class should be static or leaks might occur (test.pkg.HandlerTest.1) [HandlerLeak]\n" + + " Handler anonymous = new Handler() { // ERROR\n" + + " ~~~~~~~\n" + + "0 errors, 2 warnings\n" + + "", lintProject( "bytecode/HandlerTest.java.txt=>src/test/pkg/HandlerTest.java", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/HardcodedDebugModeDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/HardcodedDebugModeDetectorTest.java index 197fae7..edb6c50 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/HardcodedDebugModeDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/HardcodedDebugModeDetectorTest.java @@ -27,9 +27,12 @@ public class HardcodedDebugModeDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "AndroidManifest.xml:10: Warning: Avoid hardcoding the debug mode; leaving " + - "it out allows debug and release builds to automatically assign one", - lintProject("debuggable.xml=>AndroidManifest.xml")); + "AndroidManifest.xml:10: Warning: Avoid hardcoding the debug mode; leaving it out allows debug and release builds to automatically assign one [HardcodedDebugMode]\n" + + " android:debuggable=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", + lintProject("debuggable.xml=>AndroidManifest.xml")); } public void testOk() throws Exception { diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/HardcodedValuesDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/HardcodedValuesDetectorTest.java index 06ff9b6..6bef3b7 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/HardcodedValuesDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/HardcodedValuesDetectorTest.java @@ -27,10 +27,14 @@ public class HardcodedValuesDetectorTest extends AbstractCheckTest { public void testStrings() throws Exception { assertEquals( - "accessibility.xml:3: Warning: [I18N] Hardcoded string \"Button\", " + - "should use @string resource\n" + - "accessibility.xml:6: Warning: [I18N] Hardcoded string \"Button\", " + - "should use @string resource", + "res/layout/accessibility.xml:3: Warning: [I18N] Hardcoded string \"Button\", should use @string resource [HardcodedText]\n" + + " <Button android:text=\"Button\" android:id=\"@+id/button1\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\"></Button>\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/accessibility.xml:6: Warning: [I18N] Hardcoded string \"Button\", should use @string resource [HardcodedText]\n" + + " <Button android:text=\"Button\" android:id=\"@+id/button2\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\"></Button>\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 2 warnings\n" + + "", lintFiles("res/layout/accessibility.xml")); } @@ -38,8 +42,11 @@ public class HardcodedValuesDetectorTest extends AbstractCheckTest { // All but one errors in the file contain ignore attributes - direct, inherited // and lists assertEquals( - "ignores.xml:61: Warning: [I18N] Hardcoded string \"Hardcoded\", should use " + - "@string resource", + "res/layout/ignores.xml:61: Warning: [I18N] Hardcoded string \"Hardcoded\", should use @string resource [HardcodedText]\n" + + " android:text=\"Hardcoded\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintFiles("res/layout/ignores.xml")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/IconDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/IconDetectorTest.java index d33088f..f45ae08 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/IconDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/IconDetectorTest.java @@ -27,11 +27,14 @@ public class IconDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "drawable-hdpi: Warning: Missing the following drawables in drawable-hdpi: sample_icon.gif (found in drawable-mdpi)\n" + - "drawable/ic_launcher.png: Warning: The ic_launcher.png icon has identical contents in the following configuration folders: drawable-mdpi, drawable\n" + - "ic_launcher.png: Warning: Found bitmap drawable res/drawable/ic_launcher.png in densityless folder\n" + - "res: Warning: Missing density variation folders in res: drawable-xhdpi\n" + - "sample_icon.gif: Warning: Using the .gif format for bitmaps is discouraged", + "res/drawable-mdpi/sample_icon.gif: Warning: Using the .gif format for bitmaps is discouraged [GifUsage]\n" + + "res/drawable/ic_launcher.png: Warning: The ic_launcher.png icon has identical contents in the following configuration folders: drawable-mdpi, drawable [IconDuplicatesConfig]\n" + + " res/drawable-mdpi/ic_launcher.png: <No location-specific message\n" + + "res/drawable/ic_launcher.png: Warning: Found bitmap drawable res/drawable/ic_launcher.png in densityless folder [IconLocation]\n" + + "res/drawable-hdpi: Warning: Missing the following drawables in drawable-hdpi: sample_icon.gif (found in drawable-mdpi) [IconDensities]\n" + + "res: Warning: Missing density variation folders in res: drawable-xhdpi [IconMissingDensityFolder]\n" + + "0 errors, 5 warnings\n" + + "", lintProject( // Use minSDK4 to ensure that we get warnings about missing drawables @@ -57,9 +60,13 @@ public class IconDetectorTest extends AbstractCheckTest { public void test2() throws Exception { assertEquals( - "drawable-hdpi/other.9.png: Warning: The following unrelated icon files have identical contents: appwidget_bg.9.png, other.9.png\n" + - "drawable-hdpi/unrelated.png: Warning: The following unrelated icon files have identical contents: ic_launcher.png, unrelated.png\n" + - "res: Warning: Missing density variation folders in res: drawable-mdpi, drawable-xhdpi", + "res/drawable-hdpi/other.9.png: Warning: The following unrelated icon files have identical contents: appwidget_bg.9.png, other.9.png [IconDuplicates]\n" + + " res/drawable-hdpi/appwidget_bg.9.png: <No location-specific message\n" + + "res/drawable-hdpi/unrelated.png: Warning: The following unrelated icon files have identical contents: ic_launcher.png, unrelated.png [IconDuplicates]\n" + + " res/drawable-hdpi/ic_launcher.png: <No location-specific message\n" + + "res: Warning: Missing density variation folders in res: drawable-mdpi, drawable-xhdpi [IconMissingDensityFolder]\n" + + "0 errors, 3 warnings\n" + + "", lintProject( "res/drawable-hdpi/unrelated.png", @@ -72,9 +79,13 @@ public class IconDetectorTest extends AbstractCheckTest { public void testNoDpi() throws Exception { assertEquals( - "drawable-xlarge-nodpi-v11/frame.png: Warning: The frame.png icon has identical contents in the following configuration folders: drawable-mdpi, drawable-nodpi, drawable-xlarge-nodpi-v11\n" + - "frame.png: Warning: The following images appear in both -nodpi and in a density folder: frame.png\n" + - "res: Warning: Missing density variation folders in res: drawable-hdpi, drawable-xhdpi", + "res/drawable-mdpi/frame.png: Warning: The following images appear in both -nodpi and in a density folder: frame.png [IconNoDpi]\n" + + "res/drawable-xlarge-nodpi-v11/frame.png: Warning: The frame.png icon has identical contents in the following configuration folders: drawable-mdpi, drawable-nodpi, drawable-xlarge-nodpi-v11 [IconDuplicatesConfig]\n" + + " res/drawable-nodpi/frame.png: <No location-specific message\n" + + " res/drawable-mdpi/frame.png: <No location-specific message\n" + + "res: Warning: Missing density variation folders in res: drawable-hdpi, drawable-xhdpi [IconMissingDensityFolder]\n" + + "0 errors, 3 warnings\n" + + "", lintProject( "res/drawable-mdpi/frame.png", @@ -85,8 +96,18 @@ public class IconDetectorTest extends AbstractCheckTest { public void testNoDpi2() throws Exception { // Having additional icon names in the no-dpi folder should not cause any complaints assertEquals( - "drawable-xhdpi/frame.png: Warning: The following unrelated icon files have identical contents: frame.png, frame.png, frame.png, file1.png, file2.png, frame.png\n" + - "drawable-xhdpi/frame.png: Warning: The image frame.png varies significantly in its density-independent (dip) size across the various density versions: drawable-ldpi/frame.png: 629x387 dp (472x290 px), drawable-mdpi/frame.png: 472x290 dp (472x290 px), drawable-hdpi/frame.png: 315x193 dp (472x290 px), drawable-xhdpi/frame.png: 236x145 dp (472x290 px)", + "res/drawable-xhdpi/frame.png: Warning: The image frame.png varies significantly in its density-independent (dip) size across the various density versions: drawable-ldpi/frame.png: 629x387 dp (472x290 px), drawable-mdpi/frame.png: 472x290 dp (472x290 px), drawable-hdpi/frame.png: 315x193 dp (472x290 px), drawable-xhdpi/frame.png: 236x145 dp (472x290 px) [IconDipSize]\n" + + " res/drawable-hdpi/frame.png: <No location-specific message\n" + + " res/drawable-mdpi/frame.png: <No location-specific message\n" + + " res/drawable-ldpi/frame.png: <No location-specific message\n" + + "res/drawable-xhdpi/frame.png: Warning: The following unrelated icon files have identical contents: frame.png, frame.png, frame.png, file1.png, file2.png, frame.png [IconDuplicates]\n" + + " res/drawable-nodpi/file2.png: <No location-specific message\n" + + " res/drawable-nodpi/file1.png: <No location-specific message\n" + + " res/drawable-mdpi/frame.png: <No location-specific message\n" + + " res/drawable-ldpi/frame.png: <No location-specific message\n" + + " res/drawable-hdpi/frame.png: <No location-specific message\n" + + "0 errors, 2 warnings\n" + + "", lintProject( "res/drawable-mdpi/frame.png=>res/drawable-mdpi/frame.png", @@ -99,8 +120,11 @@ public class IconDetectorTest extends AbstractCheckTest { public void testNoDpiMix() throws Exception { assertEquals( - "drawable-mdpi/frame.xml: Warning: The following images appear in both -nodpi and in a density folder: frame.png, frame.xml\n" + - "res: Warning: Missing density variation folders in res: drawable-hdpi, drawable-xhdpi", + "res/drawable-mdpi/frame.xml: Warning: The following images appear in both -nodpi and in a density folder: frame.png, frame.xml [IconNoDpi]\n" + + " res/drawable-mdpi/frame.png: <No location-specific message\n" + + "res: Warning: Missing density variation folders in res: drawable-hdpi, drawable-xhdpi [IconMissingDensityFolder]\n" + + "0 errors, 2 warnings\n" + + "", lintProject( "res/drawable-mdpi/frame.png", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/InefficientWeightDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/InefficientWeightDetectorTest.java index c48658f..f7d4a44 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/InefficientWeightDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/InefficientWeightDetectorTest.java @@ -27,20 +27,34 @@ public class InefficientWeightDetectorTest extends AbstractCheckTest { public void testWeights() throws Exception { assertEquals( - "inefficient_weight.xml:10: Warning: Use a layout_width of 0dip instead of match_parent for better performance\n" + - "inefficient_weight.xml:24: Warning: Use a layout_height of 0dip instead of wrap_content for better performance", + "res/layout/inefficient_weight.xml:10: Warning: Use a layout_width of 0dip instead of match_parent for better performance [InefficientWeight]\n" + + " android:layout_width=\"match_parent\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/inefficient_weight.xml:24: Warning: Use a layout_height of 0dip instead of wrap_content for better performance [InefficientWeight]\n" + + " android:layout_height=\"wrap_content\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 2 warnings\n" + + "", lintFiles("res/layout/inefficient_weight.xml")); } public void testWeights2() throws Exception { assertEquals( - "nested_weights.xml:23: Warning: Nested weights are bad for performance", + "res/layout/nested_weights.xml:23: Warning: Nested weights are bad for performance [NestedWeights]\n" + + " android:layout_weight=\"1\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintFiles("res/layout/nested_weights.xml")); } public void testWeights3() throws Exception { assertEquals( - "baseline_weights.xml:2: Warning: Set android:baselineAligned=\"false\" on this element for better performance", + "res/layout/baseline_weights.xml:2: Warning: Set android:baselineAligned=\"false\" on this element for better performance [DisableBaselineAlignment]\n" + + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + + "^\n" + + "0 errors, 1 warnings\n" + + "", lintFiles("res/layout/baseline_weights.xml")); } @@ -54,7 +68,11 @@ public class InefficientWeightDetectorTest extends AbstractCheckTest { public void testNoVerticalWeights4() throws Exception { // Orientation not specified ==> horizontal assertEquals( - "baseline_weights3.xml:2: Warning: Set android:baselineAligned=\"false\" on this element for better performance", + "res/layout/baseline_weights3.xml:2: Warning: Set android:baselineAligned=\"false\" on this element for better performance [DisableBaselineAlignment]\n" + + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + + "^\n" + + "0 errors, 1 warnings\n" + + "", lintFiles("res/layout/baseline_weights3.xml")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/JavaPerformanceDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/JavaPerformanceDetectorTest.java index 98c664e..1d2974c 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/JavaPerformanceDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/JavaPerformanceDetectorTest.java @@ -27,25 +27,65 @@ public class JavaPerformanceDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "JavaPerformanceTest.java:103: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead)\n" + - "JavaPerformanceTest.java:109: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead)\n" + - "JavaPerformanceTest.java:112: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead)\n" + - "JavaPerformanceTest.java:113: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead)\n" + - "JavaPerformanceTest.java:114: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead)\n" + - "JavaPerformanceTest.java:116: Warning: Avoid object allocations during draw operations: Use Canvas.getClipBounds(Rect) instead of Canvas.getClipBounds() which allocates a temporary Rect\n" + - "JavaPerformanceTest.java:140: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead)\n" + - "JavaPerformanceTest.java:145: Warning: Use Integer.valueOf(42) instead\n" + - "JavaPerformanceTest.java:146: Warning: Use Long.valueOf(42L) instead\n" + - "JavaPerformanceTest.java:147: Warning: Use Boolean.valueOf(true) instead\n" + - "JavaPerformanceTest.java:148: Warning: Use Character.valueOf('c') instead\n" + - "JavaPerformanceTest.java:149: Warning: Use Float.valueOf(1.0f) instead\n" + - "JavaPerformanceTest.java:150: Warning: Use Double.valueOf(1.0) instead\n" + - "JavaPerformanceTest.java:28: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead)\n" + - "JavaPerformanceTest.java:29: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead)\n" + - "JavaPerformanceTest.java:33: Warning: Use Integer.valueOf(5) instead\n" + - "JavaPerformanceTest.java:70: Warning: Use new SparseArray<String>(...) instead for better performance\n" + - "JavaPerformanceTest.java:72: Warning: Use new SparseBooleanArray(...) instead for better performance\n" + - "JavaPerformanceTest.java:74: Warning: Use new SparseIntArray(...) instead for better performance", + "src/test/pkg/JavaPerformanceTest.java:28: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead) [DrawAllocation]\n" + + " new String(\"foo\");\n" + + " ~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:29: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead) [DrawAllocation]\n" + + " String s = new String(\"bar\");\n" + + " ~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:103: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead) [DrawAllocation]\n" + + " new String(\"flag me\");\n" + + " ~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:109: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead) [DrawAllocation]\n" + + " new String(\"flag me\");\n" + + " ~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:112: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead) [DrawAllocation]\n" + + " Bitmap.createBitmap(100, 100, null);\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:113: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead) [DrawAllocation]\n" + + " android.graphics.Bitmap.createScaledBitmap(null, 100, 100, false);\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:114: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead) [DrawAllocation]\n" + + " BitmapFactory.decodeFile(null);\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:116: Warning: Avoid object allocations during draw operations: Use Canvas.getClipBounds(Rect) instead of Canvas.getClipBounds() which allocates a temporary Rect [DrawAllocation]\n" + + " canvas.getClipBounds(); // allocates on your behalf\n" + + " ~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:140: Warning: Avoid object allocations during draw/layout operations (preallocate and reuse instead) [DrawAllocation]\n" + + " new String(\"foo\");\n" + + " ~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:70: Warning: Use new SparseArray<String>(...) instead for better performance [UseSparseArrays]\n" + + " Map<Integer, String> myMap = new HashMap<Integer, String>();\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:72: Warning: Use new SparseBooleanArray(...) instead for better performance [UseSparseArrays]\n" + + " Map<Integer, Boolean> myBoolMap = new HashMap<Integer, Boolean>();\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:74: Warning: Use new SparseIntArray(...) instead for better performance [UseSparseArrays]\n" + + " Map<Integer, Integer> myIntMap = new java.util.HashMap<Integer, Integer>();\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:33: Warning: Use Integer.valueOf(5) instead [UseValueOf]\n" + + " Integer i = new Integer(5);\n" + + " ~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:145: Warning: Use Integer.valueOf(42) instead [UseValueOf]\n" + + " Integer i1 = new Integer(42);\n" + + " ~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:146: Warning: Use Long.valueOf(42L) instead [UseValueOf]\n" + + " Long l1 = new Long(42L);\n" + + " ~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:147: Warning: Use Boolean.valueOf(true) instead [UseValueOf]\n" + + " Boolean b1 = new Boolean(true);\n" + + " ~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:148: Warning: Use Character.valueOf('c') instead [UseValueOf]\n" + + " Character c1 = new Character('c');\n" + + " ~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:149: Warning: Use Float.valueOf(1.0f) instead [UseValueOf]\n" + + " Float f1 = new Float(1.0f);\n" + + " ~~~~~~~~~~~~~~~\n" + + "src/test/pkg/JavaPerformanceTest.java:150: Warning: Use Double.valueOf(1.0) instead [UseValueOf]\n" + + " Double d1 = new Double(1.0);\n" + + " ~~~~~~~~~~~~~~~\n" + + "0 errors, 19 warnings\n" + + "", lintProject("src/test/pkg/JavaPerformanceTest.java.txt=>" + "src/test/pkg/JavaPerformanceTest.java")); diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ManifestOrderDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ManifestOrderDetectorTest.java index 54bb1f3..ad5274c 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ManifestOrderDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ManifestOrderDetectorTest.java @@ -35,78 +35,129 @@ public class ManifestOrderDetectorTest extends AbstractCheckTest { public void testBrokenOrder() throws Exception { assertEquals( - "AndroidManifest.xml:16: Warning: <uses-sdk> tag appears after <application> " + - "tag\n" + - "AndroidManifest.xml:16: Warning: <uses-sdk> tag should specify a target API " + - "level (the highest verified version; when running on later versions, " + - "compatibility behaviors may be enabled) with android:targetSdkVersion=\"?\"", + "AndroidManifest.xml:16: Warning: <uses-sdk> tag appears after <application> tag [ManifestOrder]\n" + + " <uses-sdk android:minSdkVersion=\"Froyo\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:16: Warning: <uses-sdk> tag should specify a target API level (the highest verified version; when running on later versions, compatibility behaviors may be enabled) with android:targetSdkVersion=\"?\" [UsesMinSdkAttributes]\n" + + " <uses-sdk android:minSdkVersion=\"Froyo\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 2 warnings\n" + + "", - lintProject( - "broken-manifest.xml=>AndroidManifest.xml", - "res/values/strings.xml")); + lintProject( + "broken-manifest.xml=>AndroidManifest.xml", + "res/values/strings.xml")); } public void testMissingUsesSdk() throws Exception { assertEquals( - "AndroidManifest.xml: Warning: Manifest should specify a minimum API level " + - "with <uses-sdk android:minSdkVersion=\"?\" />; if it really supports all " + - "versions of Android set it to 1.", - lintProject( - "missingusessdk.xml=>AndroidManifest.xml", - "res/values/strings.xml")); + "AndroidManifest.xml: Warning: Manifest should specify a minimum API level with <uses-sdk android:minSdkVersion=\"?\" />; if it really supports all versions of Android set it to 1. [UsesMinSdkAttributes]\n" + + "0 errors, 1 warnings\n", + lintProject( + "missingusessdk.xml=>AndroidManifest.xml", + "res/values/strings.xml")); } public void testMissingMinSdk() throws Exception { assertEquals( - "AndroidManifest.xml:7: Warning: <uses-sdk> tag should specify a minimum API " + - "level with android:minSdkVersion=\"?\"", - lintProject( - "missingmin.xml=>AndroidManifest.xml", - "res/values/strings.xml")); + "AndroidManifest.xml:7: Warning: <uses-sdk> tag should specify a minimum API level with android:minSdkVersion=\"?\" [UsesMinSdkAttributes]\n" + + " <uses-sdk android:targetSdkVersion=\"10\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", + lintProject( + "missingmin.xml=>AndroidManifest.xml", + "res/values/strings.xml")); } public void testMultipleSdk() throws Exception { assertEquals( - "AndroidManifest.xml:7: Warning: <uses-sdk> tag should specify a target API level (the highest verified version; when running on later versions, compatibility behaviors may be enabled) with android:targetSdkVersion=\"?\"\n" + - "AndroidManifest.xml:9: Warning: <uses-sdk> tag should specify a minimum API level with android:minSdkVersion=\"?\"\n" + - "ManifestOrderDetectorTest_testMultipleSdk/AndroidManifest.xml:8: Error: There should only be a single <uses-sdk> element in the manifest: merge these together\n" + - "=> ManifestOrderDetectorTest_testMultipleSdk/AndroidManifest.xml:7: Also appears here\n" + - "=> ManifestOrderDetectorTest_testMultipleSdk/AndroidManifest.xml:9: Also appears here", + "AndroidManifest.xml:8: Error: There should only be a single <uses-sdk> element in the manifest: merge these together [MultipleUsesSdk]\n" + + " <uses-sdk android:targetSdkVersion=\"14\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + " AndroidManifest.xml:7: Also appears here\n" + + " AndroidManifest.xml:9: Also appears here\n" + + "AndroidManifest.xml:7: Warning: <uses-sdk> tag should specify a target API level (the highest verified version; when running on later versions, compatibility behaviors may be enabled) with android:targetSdkVersion=\"?\" [UsesMinSdkAttributes]\n" + + " <uses-sdk android:minSdkVersion=\"5\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:9: Warning: <uses-sdk> tag should specify a minimum API level with android:minSdkVersion=\"?\" [UsesMinSdkAttributes]\n" + + " <uses-sdk android:maxSdkVersion=\"15\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "1 errors, 2 warnings\n" + + "", - lintProject( - "multiplesdk.xml=>AndroidManifest.xml", - "res/values/strings.xml")); + lintProject( + "multiplesdk.xml=>AndroidManifest.xml", + "res/values/strings.xml")); } public void testWrongLocation() throws Exception { assertEquals( - "AndroidManifest.xml:10: Error: The <permission> element must be a direct child of the <manifest> root element\n" + - "AndroidManifest.xml:11: Error: The <permission-tree> element must be a direct child of the <manifest> root element\n" + - "AndroidManifest.xml:12: Error: The <permission-group> element must be a direct child of the <manifest> root element\n" + - "AndroidManifest.xml:14: Error: The <uses-sdk> element must be a direct child of the <manifest> root element\n" + - "AndroidManifest.xml:15: Error: The <uses-configuration> element must be a direct child of the <manifest> root element\n" + - "AndroidManifest.xml:16: Error: The <uses-feature> element must be a direct child of the <manifest> root element\n" + - "AndroidManifest.xml:17: Error: The <supports-screens> element must be a direct child of the <manifest> root element\n" + - "AndroidManifest.xml:18: Error: The <compatible-screens> element must be a direct child of the <manifest> root element\n" + - "AndroidManifest.xml:19: Error: The <supports-gl-texture> element must be a direct child of the <manifest> root element\n" + - "AndroidManifest.xml:24: Error: The <uses-library> element must be a direct child of the <application> element\n" + - "AndroidManifest.xml:25: Error: The <activity> element must be a direct child of the <application> element\n" + - "AndroidManifest.xml:8: Error: The <uses-sdk> element must be a direct child of the <manifest> root element\n" + - "AndroidManifest.xml:8: Warning: <uses-sdk> tag appears after <application> tag\n" + - "AndroidManifest.xml:8: Warning: <uses-sdk> tag should specify a target API level (the highest verified version; when running on later versions, compatibility behaviors may be enabled) with android:targetSdkVersion=\"?\"\n" + - "AndroidManifest.xml:9: Error: The <uses-permission> element must be a direct child of the <manifest> root element\n" + - "ManifestOrderDetectorTest_testWrongLocation/AndroidManifest.xml:14: Error: There should only be a single <uses-sdk> element in the manifest: merge these together\n" + - "=> ManifestOrderDetectorTest_testWrongLocation/AndroidManifest.xml:8: Also appears here", + "AndroidManifest.xml:14: Error: There should only be a single <uses-sdk> element in the manifest: merge these together [MultipleUsesSdk]\n" + + " <uses-sdk />\n" + + " ~~~~~~~~~~~~\n" + + " AndroidManifest.xml:8: Also appears here\n" + + "AndroidManifest.xml:8: Error: The <uses-sdk> element must be a direct child of the <manifest> root element [WrongManifestParent]\n" + + " <uses-sdk android:minSdkVersion=\"Froyo\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:9: Error: The <uses-permission> element must be a direct child of the <manifest> root element [WrongManifestParent]\n" + + " <uses-permission />\n" + + " ~~~~~~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:10: Error: The <permission> element must be a direct child of the <manifest> root element [WrongManifestParent]\n" + + " <permission />\n" + + " ~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:11: Error: The <permission-tree> element must be a direct child of the <manifest> root element [WrongManifestParent]\n" + + " <permission-tree />\n" + + " ~~~~~~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:12: Error: The <permission-group> element must be a direct child of the <manifest> root element [WrongManifestParent]\n" + + " <permission-group />\n" + + " ~~~~~~~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:14: Error: The <uses-sdk> element must be a direct child of the <manifest> root element [WrongManifestParent]\n" + + " <uses-sdk />\n" + + " ~~~~~~~~~~~~\n" + + "AndroidManifest.xml:15: Error: The <uses-configuration> element must be a direct child of the <manifest> root element [WrongManifestParent]\n" + + " <uses-configuration />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:16: Error: The <uses-feature> element must be a direct child of the <manifest> root element [WrongManifestParent]\n" + + " <uses-feature />\n" + + " ~~~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:17: Error: The <supports-screens> element must be a direct child of the <manifest> root element [WrongManifestParent]\n" + + " <supports-screens />\n" + + " ~~~~~~~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:18: Error: The <compatible-screens> element must be a direct child of the <manifest> root element [WrongManifestParent]\n" + + " <compatible-screens />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:19: Error: The <supports-gl-texture> element must be a direct child of the <manifest> root element [WrongManifestParent]\n" + + " <supports-gl-texture />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:24: Error: The <uses-library> element must be a direct child of the <application> element [WrongManifestParent]\n" + + " <uses-library />\n" + + " ~~~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:25: Error: The <activity> element must be a direct child of the <application> element [WrongManifestParent]\n" + + " <activity android:name=\".HelloWorld\"\n" + + " ^\n" + + "AndroidManifest.xml:8: Warning: <uses-sdk> tag appears after <application> tag [ManifestOrder]\n" + + " <uses-sdk android:minSdkVersion=\"Froyo\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:8: Warning: <uses-sdk> tag should specify a target API level (the highest verified version; when running on later versions, compatibility behaviors may be enabled) with android:targetSdkVersion=\"?\" [UsesMinSdkAttributes]\n" + + " <uses-sdk android:minSdkVersion=\"Froyo\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "14 errors, 2 warnings\n" + + "", - lintProject("broken-manifest2.xml=>AndroidManifest.xml")); + lintProject("broken-manifest2.xml=>AndroidManifest.xml")); } public void testDuplicateActivity() throws Exception { assertEquals( - "AndroidManifest.xml:16: Error: Duplicate registration for activity com.example.helloworld.HelloWorld", + "AndroidManifest.xml:16: Error: Duplicate registration for activity com.example.helloworld.HelloWorld [DuplicateActivity]\n" + + " <activity android:name=\"com.example.helloworld.HelloWorld\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "1 errors, 0 warnings\n" + + "", - lintProject( - "duplicate-manifest.xml=>AndroidManifest.xml", - "res/values/strings.xml")); + lintProject( + "duplicate-manifest.xml=>AndroidManifest.xml", + "res/values/strings.xml")); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/MathDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/MathDetectorTest.java index 4c5580d..8ec64ec 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/MathDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/MathDetectorTest.java @@ -27,15 +27,23 @@ public class MathDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "MathTest.java:12: Warning: Use android.util.FloatMath#sqrt() instead of java.lang.Math#sqrt to avoid argument float to double conversion\n" + - "MathTest.java:18: Warning: Use android.util.FloatMath#sqrt() instead of java.lang.Math#sqrt to avoid double to float return value conversion\n" + - "MathTest.java:23: Warning: Use android.util.FloatMath#sqrt() instead of java.lang.Math#sqrt to avoid argument float to double conversion", + "src/test/bytecode/MathTest.java:12: Warning: Use android.util.FloatMath#sqrt() instead of java.lang.Math#sqrt to avoid argument float to double conversion [FloatMath]\n" + + " floatResult = (float) Math.sqrt(x);\n" + + " ~~~~\n" + + "src/test/bytecode/MathTest.java:18: Warning: Use android.util.FloatMath#sqrt() instead of java.lang.Math#sqrt to avoid double to float return value conversion [FloatMath]\n" + + " floatResult = (float) Math.sqrt(x);\n" + + " ~~~~\n" + + "src/test/bytecode/MathTest.java:23: Warning: Use android.util.FloatMath#sqrt() instead of java.lang.Math#sqrt to avoid argument float to double conversion [FloatMath]\n" + + " doubleResult = Math.sqrt(x);\n" + + " ~~~~\n" + + "0 errors, 3 warnings\n" + + "", - lintProject( - "bytecode/.classpath=>.classpath", - "bytecode/AndroidManifest.xml=>AndroidManifest.xml", - "bytecode/MathTest.java.txt=>src/test/bytecode/MathTest.java", - "bytecode/MathTest.class.data=>bin/classes/test/bytecode/MathTest.class" - )); + lintProject( + "bytecode/.classpath=>.classpath", + "bytecode/AndroidManifest.xml=>AndroidManifest.xml", + "bytecode/MathTest.java.txt=>src/test/bytecode/MathTest.java", + "bytecode/MathTest.class.data=>bin/classes/test/bytecode/MathTest.class" + )); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/MergeRootFrameLayoutDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/MergeRootFrameLayoutDetectorTest.java index 14dda8f..22a001f 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/MergeRootFrameLayoutDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/MergeRootFrameLayoutDetectorTest.java @@ -28,20 +28,28 @@ public class MergeRootFrameLayoutDetectorTest extends AbstractCheckTest { public void testMergeRefFromJava() throws Exception { assertEquals( - "simple.xml:3: Warning: This <FrameLayout> can be replaced with a <merge> tag", - lintProject( - "res/layout/simple.xml", - "src/test/pkg/ImportFrameActivity.java.txt=>src/test/pkg/ImportFrameActivity.java" - )); + "res/layout/simple.xml:3: Warning: This <FrameLayout> can be replaced with a <merge> tag [MergeRootFrame]\n" + + "<FrameLayout\n" + + "^\n" + + "0 errors, 1 warnings\n" + + "", + lintProject( + "res/layout/simple.xml", + "src/test/pkg/ImportFrameActivity.java.txt=>src/test/pkg/ImportFrameActivity.java" + )); } public void testMergeRefFromInclude() throws Exception { assertEquals( - "simple.xml:3: Warning: This <FrameLayout> can be replaced with a <merge> tag", - lintProject( - "res/layout/simple.xml", - "res/layout/simpleinclude.xml" - )); + "res/layout/simple.xml:3: Warning: This <FrameLayout> can be replaced with a <merge> tag [MergeRootFrame]\n" + + "<FrameLayout\n" + + "^\n" + + "0 errors, 1 warnings\n" + + "", + lintProject( + "res/layout/simple.xml", + "res/layout/simpleinclude.xml" + )); } public void testMergeRefFromIncludeSuppressed() throws Exception { diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NamespaceDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NamespaceDetectorTest.java index 560db91..0912733 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NamespaceDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NamespaceDetectorTest.java @@ -27,8 +27,11 @@ public class NamespaceDetectorTest extends AbstractCheckTest { public void testCustom() throws Exception { assertEquals( - "customview.xml:16: Error: When using a custom namespace attribute in a library " + - "project, use the namespace \"http://schemas.android.com/apk/res-auto\" instead.", + "res/layout/customview.xml:16: Error: When using a custom namespace attribute in a library project, use the namespace \"http://schemas.android.com/apk/res-auto\" instead. [LibraryCustomView]\n" + + " foo:misc=\"Custom attribute\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "1 errors, 0 warnings\n" + + "", lintProject( "multiproject/library-manifest.xml=>AndroidManifest.xml", @@ -66,29 +69,35 @@ public class NamespaceDetectorTest extends AbstractCheckTest { public void testTypo() throws Exception { assertEquals( - "wrong_namespace.xml:2: Warning: Unexpected namespace URI bound to the " + - "\"android\" prefix, was http://schemas.android.com/apk/res/andriod, " + - "expected http://schemas.android.com/apk/res/android", + "res/layout/wrong_namespace.xml:2: Warning: Unexpected namespace URI bound to the \"android\" prefix, was http://schemas.android.com/apk/res/andriod, expected http://schemas.android.com/apk/res/android [NamespaceTypo]\n" + + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/andriod\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", - lintProject("res/layout/wrong_namespace.xml")); + lintProject("res/layout/wrong_namespace.xml")); } public void testTypo2() throws Exception { assertEquals( - "wrong_namespace2.xml:2: Warning: URI is case sensitive: was " + - "\"http://schemas.android.com/apk/res/Android\", expected " + - "\"http://schemas.android.com/apk/res/android\"", + "res/layout/wrong_namespace2.xml:2: Warning: URI is case sensitive: was \"http://schemas.android.com/apk/res/Android\", expected \"http://schemas.android.com/apk/res/android\" [NamespaceTypo]\n" + + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/Android\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", - lintProject("res/layout/wrong_namespace2.xml")); + lintProject("res/layout/wrong_namespace2.xml")); } public void testTypo3() throws Exception { assertEquals( - "wrong_namespace3.xml:2: Warning: Unexpected namespace URI bound to the " + - "\"android\" prefix, was http://schemas.android.com/apk/res/androi, " + - "expected http://schemas.android.com/apk/res/android", + "res/layout/wrong_namespace3.xml:2: Warning: Unexpected namespace URI bound to the \"android\" prefix, was http://schemas.android.com/apk/res/androi, expected http://schemas.android.com/apk/res/android [NamespaceTypo]\n" + + "<LinearLayout xmlns:a=\"http://schemas.android.com/apk/res/androi\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", - lintProject("res/layout/wrong_namespace3.xml")); + lintProject("res/layout/wrong_namespace3.xml")); } public void testTypoOk() throws Exception { @@ -100,10 +109,16 @@ public class NamespaceDetectorTest extends AbstractCheckTest { public void testUnused() throws Exception { assertEquals( - "unused_namespace.xml:3: Warning: Unused namespace unused1\n" + - "unused_namespace.xml:4: Warning: Unused namespace unused2", - - lintProject("res/layout/unused_namespace.xml")); + "res/layout/unused_namespace.xml:3: Warning: Unused namespace unused1 [UnusedNamespace]\n" + + " xmlns:unused1=\"http://schemas.android.com/apk/res/unused1\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/unused_namespace.xml:4: Warning: Unused namespace unused2 [UnusedNamespace]\n" + + " xmlns:unused2=\"http://schemas.android.com/apk/res/unused1\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 2 warnings\n" + + "", + + lintProject("res/layout/unused_namespace.xml")); } public void testUnusedOk() throws Exception { diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NestedScrollingWidgetDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NestedScrollingWidgetDetectorTest.java index dfcd131..55da17e 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NestedScrollingWidgetDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NestedScrollingWidgetDetectorTest.java @@ -27,8 +27,11 @@ public class NestedScrollingWidgetDetectorTest extends AbstractCheckTest { public void testNested() throws Exception { assertEquals( - "scrolling.xml:13: Warning: The vertically scrolling ScrollView should not " + - "contain another vertically scrolling widget (ListView)", - lintFiles("res/layout/scrolling.xml")); + "res/layout/scrolling.xml:13: Warning: The vertically scrolling ScrollView should not contain another vertically scrolling widget (ListView) [NestedScrolling]\n" + + " <ListView\n" + + " ^\n" + + "0 errors, 1 warnings\n", + + lintFiles("res/layout/scrolling.xml")); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NonInternationalizedSmsDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NonInternationalizedSmsDetectorTest.java index d51acb2..46e494e 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NonInternationalizedSmsDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/NonInternationalizedSmsDetectorTest.java @@ -27,7 +27,11 @@ public class NonInternationalizedSmsDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "NonInternationalizedSmsDetectorTest.java:18: Warning: To make sure the SMS can be sent by all users, please start the SMS numberwith a + and a country code or restrict the code invocation to people in the country you are targeting.", + "src/test/pkg/NonInternationalizedSmsDetectorTest.java:18: Warning: To make sure the SMS can be sent by all users, please start the SMS numberwith a + and a country code or restrict the code invocation to people in the country you are targeting. [UnlocalizedSms]\n" + + " sms.sendMultipartTextMessage(\"001234567890\", null, null, null, null);\n" + + " ~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintProject("src/test/pkg/NonInternationalizedSmsDetectorTest.java.txt=>src/test/pkg/NonInternationalizedSmsDetectorTest.java")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ObsoleteLayoutParamsDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ObsoleteLayoutParamsDetectorTest.java index 86af3ac..87211a2 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ObsoleteLayoutParamsDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ObsoleteLayoutParamsDetectorTest.java @@ -27,13 +27,29 @@ public class ObsoleteLayoutParamsDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "wrongparams.xml:11: Warning: Invalid layout param in a FrameLayout: layout_weight\n" + - "wrongparams.xml:23: Warning: Invalid layout param in a LinearLayout: layout_alignParentLeft\n" + - "wrongparams.xml:24: Warning: Invalid layout param in a LinearLayout: layout_alignParentTop\n" + - "wrongparams.xml:33: Warning: Invalid layout param in a LinearLayout: layout_alignBottom\n" + - "wrongparams.xml:34: Warning: Invalid layout param in a LinearLayout: layout_toRightOf\n" + - "wrongparams.xml:42: Warning: Invalid layout param in a LinearLayout: layout_alignLeft\n" + - "wrongparams.xml:43: Warning: Invalid layout param in a LinearLayout: layout_below", + "res/layout/wrongparams.xml:11: Warning: Invalid layout param in a FrameLayout: layout_weight [ObsoleteLayoutParam]\n" + + " android:layout_weight=\"1\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/wrongparams.xml:23: Warning: Invalid layout param in a LinearLayout: layout_alignParentLeft [ObsoleteLayoutParam]\n" + + " android:layout_alignParentLeft=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/wrongparams.xml:24: Warning: Invalid layout param in a LinearLayout: layout_alignParentTop [ObsoleteLayoutParam]\n" + + " android:layout_alignParentTop=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/wrongparams.xml:33: Warning: Invalid layout param in a LinearLayout: layout_alignBottom [ObsoleteLayoutParam]\n" + + " android:layout_alignBottom=\"@+id/button1\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/wrongparams.xml:34: Warning: Invalid layout param in a LinearLayout: layout_toRightOf [ObsoleteLayoutParam]\n" + + " android:layout_toRightOf=\"@+id/button1\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/wrongparams.xml:42: Warning: Invalid layout param in a LinearLayout: layout_alignLeft [ObsoleteLayoutParam]\n" + + " android:layout_alignLeft=\"@+id/button1\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/wrongparams.xml:43: Warning: Invalid layout param in a LinearLayout: layout_below [ObsoleteLayoutParam]\n" + + " android:layout_below=\"@+id/button1\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 7 warnings\n" + + "", lintProject("res/layout/wrongparams.xml")); } @@ -50,7 +66,11 @@ public class ObsoleteLayoutParamsDetectorTest extends AbstractCheckTest { public void test3() throws Exception { // Test includes across files (wrong layout param on root element) assertEquals( - "wrongparams3.xml:5: Warning: Invalid layout param 'layout_alignParentTop' (included from within a LinearLayout in layout/wrongparams4.xml)", + "res/layout/wrongparams3.xml:5: Warning: Invalid layout param 'layout_alignParentTop' (included from within a LinearLayout in layout/wrongparams4.xml) [ObsoleteLayoutParam]\n" + + " android:layout_alignParentTop=\"true\" >\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintProject("res/layout/wrongparams4.xml", "res/layout/wrongparams3.xml")); } @@ -58,8 +78,14 @@ public class ObsoleteLayoutParamsDetectorTest extends AbstractCheckTest { public void test4() throws Exception { // Test includes with a <merge> (wrong layout param on child of root merge element) assertEquals( - "wrongparams5.xml:15: Warning: Invalid layout param 'layout_alignParentLeft' (included from within a LinearLayout in layout/wrongparams6.xml)\n" + - "wrongparams5.xml:8: Warning: Invalid layout param 'layout_alignParentTop' (included from within a LinearLayout in layout/wrongparams6.xml)", + "res/layout/wrongparams5.xml:8: Warning: Invalid layout param 'layout_alignParentTop' (included from within a LinearLayout in layout/wrongparams6.xml) [ObsoleteLayoutParam]\n" + + " android:layout_alignParentTop=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/wrongparams5.xml:15: Warning: Invalid layout param 'layout_alignParentLeft' (included from within a LinearLayout in layout/wrongparams6.xml) [ObsoleteLayoutParam]\n" + + " android:layout_alignParentLeft=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 2 warnings\n" + + "", lintProject("res/layout/wrongparams5.xml", "res/layout/wrongparams6.xml")); } @@ -67,7 +93,11 @@ public class ObsoleteLayoutParamsDetectorTest extends AbstractCheckTest { public void testIgnore() throws Exception { assertEquals( // Ignoring all but one of the warnings - "wrongparams.xml:12: Warning: Invalid layout param in a FrameLayout: layout_weight", + "res/layout/wrongparams.xml:12: Warning: Invalid layout param in a FrameLayout: layout_weight [ObsoleteLayoutParam]\n" + + " android:layout_weight=\"1\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintProject("res/layout/wrongparams_ignore.xml=>res/layout/wrongparams.xml")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/OnClickDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/OnClickDetectorTest.java index 53362ea..e9f70d4 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/OnClickDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/OnClickDetectorTest.java @@ -27,15 +27,35 @@ public class OnClickDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "OnClickActivity.java:27: Error: On click handler wrong5(View) must be public\n" + - "OnClickActivity.java:31: Error: On click handler wrong6(View) should not be static\n" + - "OnClickActivity.java:45: Error: On click handler wrong7(View) must be public\n" + - "onclick.xml:10: Error: Corresponding method handler 'public void nonexistent(android.view.View)' not found\n" + - "onclick.xml:16: Error: Corresponding method handler 'public void wrong1(android.view.View)' not found\n" + - "onclick.xml:22: Error: Corresponding method handler 'public void wrong2(android.view.View)' not found\n" + - "onclick.xml:28: Error: Corresponding method handler 'public void wrong3(android.view.View)' not found\n" + - "onclick.xml:34: Error: Corresponding method handler 'public void wrong4(android.view.View)' not found\n" + - "onclick.xml:58: Error: Corresponding method handler 'public void simple_typo(android.view.View)' not found (did you mean void test.pkg.OnClickActivity#simple_tyop(android.view.View) ?)", + "src/test/pkg/OnClickActivity.java:27: Error: On click handler wrong5(View) must be public [OnClick]\n" + + " void wrong5(View view) {\n" + + " ~~~~~~\n" + + "src/test/pkg/OnClickActivity.java:31: Error: On click handler wrong6(View) should not be static [OnClick]\n" + + " public static void wrong6(View view) {\n" + + " ~~~~~~\n" + + "src/test/pkg/OnClickActivity.java:45: Error: On click handler wrong7(View) must be public [OnClick]\n" + + " void wrong7(View view) {\n" + + " ~~~~~~\n" + + "res/layout/onclick.xml:10: Error: Corresponding method handler 'public void nonexistent(android.view.View)' not found [OnClick]\n" + + " android:onClick=\"nonexistent\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/onclick.xml:16: Error: Corresponding method handler 'public void wrong1(android.view.View)' not found [OnClick]\n" + + " android:onClick=\"wrong1\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/onclick.xml:22: Error: Corresponding method handler 'public void wrong2(android.view.View)' not found [OnClick]\n" + + " android:onClick=\"wrong2\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/onclick.xml:28: Error: Corresponding method handler 'public void wrong3(android.view.View)' not found [OnClick]\n" + + " android:onClick=\"wrong3\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/onclick.xml:34: Error: Corresponding method handler 'public void wrong4(android.view.View)' not found [OnClick]\n" + + " android:onClick=\"wrong4\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/onclick.xml:58: Error: Corresponding method handler 'public void simple_typo(android.view.View)' not found (did you mean void test.pkg.OnClickActivity#simple_tyop(android.view.View) ?) [OnClick]\n" + + " android:onClick=\"simple_typo\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "9 errors, 0 warnings\n" + + "", lintProject( "bytecode/.classpath=>.classpath", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/OverdrawDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/OverdrawDetectorTest.java index bd8eb4d..7da4004 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/OverdrawDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/OverdrawDetectorTest.java @@ -27,10 +27,20 @@ public class OverdrawDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "main.xml:5: Warning: Possible overdraw: Root element paints background @drawable/ic_launcher with a theme that also paints a background (inferred theme is @style/MyTheme_First)\n" + - "second.xml:5: Warning: Possible overdraw: Root element paints background @drawable/ic_launcher with a theme that also paints a background (inferred theme is @style/MyTheme)\n" + - "sixth.xml:4: Warning: Possible overdraw: Root element paints background @drawable/custombg with a theme that also paints a background (inferred theme is @style/MyTheme)\n" + - "third.xml:5: Warning: Possible overdraw: Root element paints background @drawable/ic_launcher with a theme that also paints a background (inferred theme is @style/MyTheme_Third)", + "res/layout/main.xml:5: Warning: Possible overdraw: Root element paints background @drawable/ic_launcher with a theme that also paints a background (inferred theme is @style/MyTheme_First) [Overdraw]\n" + + " android:background=\"@drawable/ic_launcher\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/second.xml:5: Warning: Possible overdraw: Root element paints background @drawable/ic_launcher with a theme that also paints a background (inferred theme is @style/MyTheme) [Overdraw]\n" + + " android:background=\"@drawable/ic_launcher\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/sixth.xml:4: Warning: Possible overdraw: Root element paints background @drawable/custombg with a theme that also paints a background (inferred theme is @style/MyTheme) [Overdraw]\n" + + " android:background=\"@drawable/custombg\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/third.xml:5: Warning: Possible overdraw: Root element paints background @drawable/ic_launcher with a theme that also paints a background (inferred theme is @style/MyTheme_Third) [Overdraw]\n" + + " android:background=\"@drawable/ic_launcher\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 4 warnings\n" + + "", lintProject( "overdraw/.classpath=>.classpath", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/PrivateKeyDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/PrivateKeyDetectorTest.java index 7e338a9..ff72dcb 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/PrivateKeyDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/PrivateKeyDetectorTest.java @@ -32,8 +32,8 @@ public class PrivateKeyDetectorTest extends AbstractCheckTest { public void testPrivateKey() throws Exception { assertEquals( - "res/private_key.pem: Warning: The res/private_key.pem file seems to be a " + - "private key file. Please make sure not to embed this in your APK file.", + "res/private_key.pem: Warning: The res/private_key.pem file seems to be a private key file. Please make sure not to embed this in your APK file. [PackagedPrivateKey]\n" + + "0 errors, 1 warnings\n", lintProject( // Not a private key file "res/values/strings.xml=>res/values/strings/xml", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/PrivateResourceDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/PrivateResourceDetectorTest.java index 26e8a2b..ce1b717 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/PrivateResourceDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/PrivateResourceDetectorTest.java @@ -27,8 +27,11 @@ public class PrivateResourceDetectorTest extends AbstractCheckTest { public void testPrivate() throws Exception { assertEquals( - "private.xml:3: Error: Illegal resource reference: @*android resources are " + - "private and not always present", - lintProject("res/layout/private.xml")); + "res/layout/private.xml:3: Error: Illegal resource reference: @*android resources are private and not always present [PrivateResource]\n" + + " <ImageView android:id=\"@+id/android_logo\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\" android:src=\"@*android:drawable/android_button\" android:focusable=\"false\" android:clickable=\"false\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "1 errors, 0 warnings\n" + + "", + lintProject("res/layout/private.xml")); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ProguardDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ProguardDetectorTest.java index f3d872b..c493b8c 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ProguardDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ProguardDetectorTest.java @@ -27,30 +27,37 @@ public class ProguardDetectorTest extends AbstractCheckTest { public void testProguard() throws Exception { assertEquals( - "proguard.cfg:21: Error: Obsolete ProGuard file; use -keepclasseswithmembers " + - "instead of -keepclasseswithmembernames", - lintFiles("proguard.cfg")); + "proguard.cfg:21: Error: Obsolete ProGuard file; use -keepclasseswithmembers instead of -keepclasseswithmembernames [Proguard]\n" + + "-keepclasseswithmembernames class * {\n" + + "^\n" + + "1 errors, 0 warnings\n" + + "", + lintFiles("proguard.cfg")); } public void testProguardNewPath() throws Exception { assertEquals( - "proguard-project.txt:21: Error: Obsolete ProGuard file; use " + - "-keepclasseswithmembers instead of -keepclasseswithmembernames", - lintFiles("proguard.cfg=>proguard-project.txt")); + "proguard-project.txt:21: Error: Obsolete ProGuard file; use -keepclasseswithmembers instead of -keepclasseswithmembernames [Proguard]\n" + + "-keepclasseswithmembernames class * {\n" + + "^\n" + + "1 errors, 0 warnings\n" + + "", + lintFiles("proguard.cfg=>proguard-project.txt")); } public void testProguardRandomName() throws Exception { assertEquals( - "myfile.txt:21: Error: Obsolete ProGuard file; use -keepclasseswithmembers " + - "instead of -keepclasseswithmembernames\n" + - "myfile.txt:8: Warning: Local ProGuard configuration contains general " + - "Android configuration: Inherit these settings instead? Modify " + - "project.properties to define proguard.config=${sdk.dir}/tools/proguard/" + - "proguard-android.txt:myfile.txt and then keep only project-specific " + - "configuration here", - lintProject( - "proguard.cfg=>myfile.txt", - "proguard.properties=>project.properties")); + "myfile.txt:21: Error: Obsolete ProGuard file; use -keepclasseswithmembers instead of -keepclasseswithmembernames [Proguard]\n" + + "-keepclasseswithmembernames class * {\n" + + "^\n" + + "myfile.txt:8: Warning: Local ProGuard configuration contains general Android configuration: Inherit these settings instead? Modify project.properties to define proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:myfile.txt and then keep only project-specific configuration here [ProguardSplit]\n" + + "-keep public class * extends android.app.Activity\n" + + "^\n" + + "1 errors, 1 warnings\n" + + "", + lintProject( + "proguard.cfg=>myfile.txt", + "proguard.properties=>project.properties")); } public void testSilent() throws Exception { @@ -73,14 +80,14 @@ public class ProguardDetectorTest extends AbstractCheckTest { public void testSplit() throws Exception { assertEquals( - "proguard.cfg:14: Warning: Local ProGuard configuration contains general " + - "Android configuration: Inherit these settings instead? Modify " + - "project.properties to define " + - "proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard.cfg " + - "and then keep only project-specific configuration here", + "proguard.cfg:14: Warning: Local ProGuard configuration contains general Android configuration: Inherit these settings instead? Modify project.properties to define proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard.cfg and then keep only project-specific configuration here [ProguardSplit]\n" + + "-keep public class * extends android.app.Activity\n" + + "^\n" + + "0 errors, 1 warnings\n" + + "", - lintFiles( - "proguard.pro=>proguard.cfg", - "project.properties2=>project.properties")); + lintFiles( + "proguard.pro=>proguard.cfg", + "project.properties2=>project.properties")); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/PxUsageDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/PxUsageDetectorTest.java index 76282e2..77ebd70 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/PxUsageDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/PxUsageDetectorTest.java @@ -27,24 +27,46 @@ public class PxUsageDetectorTest extends AbstractCheckTest { public void testPx() throws Exception { assertEquals( - "now_playing_after.xml:41: Warning: Avoid using \"px\" as units; use \"dp\" instead", + "res/layout/now_playing_after.xml:41: Warning: Avoid using \"px\" as units; use \"dp\" instead [PxUsage]\n" + + " android:layout_width=\"1px\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintFiles("res/layout/now_playing_after.xml")); } public void testSp() throws Exception { assertEquals( - "textsize.xml:11: Warning: Should use \"sp\" instead of \"dp\" for text sizes\n" + - "textsize.xml:16: Warning: Should use \"sp\" instead of \"dp\" for text sizes", + "res/layout/textsize.xml:11: Warning: Should use \"sp\" instead of \"dp\" for text sizes [SpUsage]\n" + + " android:textSize=\"14dp\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/textsize.xml:16: Warning: Should use \"sp\" instead of \"dp\" for text sizes [SpUsage]\n" + + " android:textSize=\"14dip\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 2 warnings\n" + + "", lintFiles("res/layout/textsize.xml")); } public void testStyles() throws Exception { assertEquals( - "pxsp.xml:12: Warning: Should use \"sp\" instead of \"dp\" for text sizes\n" + - "pxsp.xml:17: Warning: Avoid using \"px\" as units; use \"dp\" instead\n" + - "pxsp.xml:18: Warning: Avoid using \"px\" as units; use \"dp\" instead\n" + - "pxsp.xml:6: Warning: Should use \"sp\" instead of \"dp\" for text sizes\n" + - "pxsp.xml:9: Warning: Avoid using \"px\" as units; use \"dp\" instead", + "res/values/pxsp.xml:9: Warning: Avoid using \"px\" as units; use \"dp\" instead [PxUsage]\n" + + " <item name=\"android:textSize\">50px</item>\n" + + " ^\n" + + "res/values/pxsp.xml:17: Warning: Avoid using \"px\" as units; use \"dp\" instead [PxUsage]\n" + + " <item name=\"android:paddingRight\"> 50px </item>\n" + + " ^\n" + + "res/values/pxsp.xml:18: Warning: Avoid using \"px\" as units; use \"dp\" instead [PxUsage]\n" + + " <item name=\"android:paddingTop\">50px</item>\n" + + " ^\n" + + "res/values/pxsp.xml:6: Warning: Should use \"sp\" instead of \"dp\" for text sizes [SpUsage]\n" + + " <item name=\"android:textSize\">50dp</item>\n" + + " ^\n" + + "res/values/pxsp.xml:12: Warning: Should use \"sp\" instead of \"dp\" for text sizes [SpUsage]\n" + + " <item name=\"android:textSize\"> 50dip </item>\n" + + " ^\n" + + "0 errors, 5 warnings\n" + + "", lintFiles("res/values/pxsp.xml")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/RegistrationDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/RegistrationDetectorTest.java index 2369fad..23a5ac3 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/RegistrationDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/RegistrationDetectorTest.java @@ -27,10 +27,20 @@ public class RegistrationDetectorTest extends AbstractCheckTest { public void testRegistered() throws Exception { assertEquals( - "OnClickActivity.java:8: Warning: The <activity> test.pkg.OnClickActivity is not registered in the manifest\n" + - "TestProvider.java:8: Warning: The <provider> test.pkg.TestProvider is not registered in the manifest\n" + - "TestProvider2.java:3: Warning: The <provider> test.pkg.TestProvider2 is not registered in the manifest\n" + - "TestService.java:7: Warning: The <service> test.pkg.TestService is not registered in the manifest", + "src/test/pkg/OnClickActivity.java:8: Warning: The <activity> test.pkg.OnClickActivity is not registered in the manifest [Registered]\n" + + "public class OnClickActivity extends Activity {\n" + + " ~~~~~~~~~~~~~~~\n" + + "src/test/pkg/TestProvider.java:8: Warning: The <provider> test.pkg.TestProvider is not registered in the manifest [Registered]\n" + + "public class TestProvider extends ContentProvider {\n" + + " ~~~~~~~~~~~~\n" + + "src/test/pkg/TestProvider2.java:3: Warning: The <provider> test.pkg.TestProvider2 is not registered in the manifest [Registered]\n" + + "public class TestProvider2 extends TestProvider {\n" + + "^\n" + + "src/test/pkg/TestService.java:7: Warning: The <service> test.pkg.TestService is not registered in the manifest [Registered]\n" + + "public class TestService extends Service {\n" + + " ~~~~~~~~~~~\n" + + "0 errors, 4 warnings\n" + + "", lintProject( "bytecode/.classpath=>.classpath", @@ -61,11 +71,23 @@ public class RegistrationDetectorTest extends AbstractCheckTest { public void testWrongRegistrations() throws Exception { assertEquals( - "OnClickActivity.java:8: Warning: test.pkg.OnClickActivity is a <activity> but is registered in the manifest as a <receiver>\n" + - "TestProvider.java:8: Warning: test.pkg.TestProvider is a <provider> but is registered in the manifest as a <activity>\n" + - "TestProvider2.java:3: Warning: test.pkg.TestProvider2 is a <provider> but is registered in the manifest as a <service>\n" + - "TestReceiver.java:7: Warning: test.pkg.TestReceiver is a <receiver> but is registered in the manifest as a <service>\n" + - "TestService.java:7: Warning: test.pkg.TestService is a <service> but is registered in the manifest as a <provider>", + "src/test/pkg/OnClickActivity.java:8: Warning: test.pkg.OnClickActivity is a <activity> but is registered in the manifest as a <receiver> [Registered]\n" + + "public class OnClickActivity extends Activity {\n" + + " ~~~~~~~~~~~~~~~\n" + + "src/test/pkg/TestProvider.java:8: Warning: test.pkg.TestProvider is a <provider> but is registered in the manifest as a <activity> [Registered]\n" + + "public class TestProvider extends ContentProvider {\n" + + " ~~~~~~~~~~~~\n" + + "src/test/pkg/TestProvider2.java:3: Warning: test.pkg.TestProvider2 is a <provider> but is registered in the manifest as a <service> [Registered]\n" + + "public class TestProvider2 extends TestProvider {\n" + + "^\n" + + "src/test/pkg/TestReceiver.java:7: Warning: test.pkg.TestReceiver is a <receiver> but is registered in the manifest as a <service> [Registered]\n" + + "public class TestReceiver extends BroadcastReceiver {\n" + + " ~~~~~~~~~~~~\n" + + "src/test/pkg/TestService.java:7: Warning: test.pkg.TestService is a <service> but is registered in the manifest as a <provider> [Registered]\n" + + "public class TestService extends Service {\n" + + " ~~~~~~~~~~~\n" + + "0 errors, 5 warnings\n" + + "", lintProject( "bytecode/.classpath=>.classpath", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ScrollViewChildDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ScrollViewChildDetectorTest.java index 678c3a8..ba79c50 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ScrollViewChildDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ScrollViewChildDetectorTest.java @@ -27,8 +27,11 @@ public class ScrollViewChildDetectorTest extends AbstractCheckTest { public void testScrollView() throws Exception { assertEquals( - "wrong_dimension.xml:10: Warning: This LinearLayout should use " + - "android:layout_width=\"wrap_content\"", + "res/layout/wrong_dimension.xml:10: Warning: This LinearLayout should use android:layout_width=\"wrap_content\" [ScrollViewSize]\n" + + " android:layout_width=\"match_parent\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintFiles("res/layout/wrong_dimension.xml")); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SdCardDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SdCardDetectorTest.java index 58c019d..1acbb87 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SdCardDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SdCardDetectorTest.java @@ -27,23 +27,47 @@ public class SdCardDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "SdCardTest.java:13: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead\n" + - "SdCardTest.java:14: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead\n" + - "SdCardTest.java:15: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead\n" + - "SdCardTest.java:16: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead\n" + - "SdCardTest.java:20: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead\n" + - "SdCardTest.java:22: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead\n" + - "SdCardTest.java:24: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead\n" + - "SdCardTest.java:30: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead\n" + - "SdCardTest.java:31: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead", - - lintProject("src/test/pkg/SdCardTest.java.txt=>src/test/pkg/SdCardTest.java")); + "src/test/pkg/SdCardTest.java:13: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath]\n" + + " private static final String SDCARD_TEST_HTML = \"/sdcard/test.html\";\n" + + " ~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/SdCardTest.java:14: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath]\n" + + " public static final String SDCARD_ROOT = \"/sdcard\";\n" + + " ~~~~~~~~~\n" + + "src/test/pkg/SdCardTest.java:15: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath]\n" + + " public static final String PACKAGES_PATH = \"/sdcard/o/packages/\";\n" + + " ~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/SdCardTest.java:16: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath]\n" + + " File deviceDir = new File(\"/sdcard/vr\");\n" + + " ~~~~~~~~~~~~\n" + + "src/test/pkg/SdCardTest.java:20: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath]\n" + + " android.os.Debug.startMethodTracing(\"/sdcard/launcher\");\n" + + " ~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/SdCardTest.java:22: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath]\n" + + " if (new File(\"/sdcard\").exists()) {\n" + + " ~~~~~~~~~\n" + + "src/test/pkg/SdCardTest.java:24: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath]\n" + + " String FilePath = \"/sdcard/\" + new File(\"test\");\n" + + " ~~~~~~~~~~\n" + + "src/test/pkg/SdCardTest.java:30: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath]\n" + + " intent.putExtra(\"path-filter\", \"/sdcard(/.+)*\");\n" + + " ~~~~~~~~~~~~~~~\n" + + "src/test/pkg/SdCardTest.java:31: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath]\n" + + " intent.putExtra(\"start-dir\", \"/sdcard\");\n" + + " ~~~~~~~~~\n" + + "0 errors, 9 warnings\n" + + "", + + lintProject("src/test/pkg/SdCardTest.java.txt=>src/test/pkg/SdCardTest.java")); } public void testSuppress() throws Exception { assertEquals( // The only reference in the file not covered by an annotation - "SuppressTest5.java:40: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead", + "src/test/pkg/SuppressTest5.java:40: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath]\n" + + " String notAnnotated = \"/sdcard/mypath\";\n" + + " ~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", // File with lots of /sdcard references, but with @SuppressLint warnings // on fields, methods, variable declarations etc @@ -52,7 +76,11 @@ public class SdCardDetectorTest extends AbstractCheckTest { public void testUtf8Bom() throws Exception { assertEquals( - "Utf8BomTest.java:4: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead", + "src/test/pkg/Utf8BomTest.java:4: Warning: Do not hardcode \"/sdcard/\"; use Environment.getExternalStorageDirectory().getPath() instead [SdCardPath]\n" + + " String s = \"/sdcard/mydir\";\n" + + " ~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintProject("src/test/pkg/Utf8BomTest.java.data=>src/test/pkg/Utf8BomTest.java")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SecureRandomDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SecureRandomDetectorTest.java index 67fc3c1..0ecbe02 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SecureRandomDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SecureRandomDetectorTest.java @@ -27,13 +27,29 @@ public class SecureRandomDetectorTest extends AbstractCheckTest { public void test1() throws Exception { assertEquals( - "SecureRandomTest.java:12: Warning: It is dangerous to seed SecureRandom with the current time because that value is more predictable to an attacker than the default seed.\n" + - "SecureRandomTest.java:14: Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed().\n" + - "SecureRandomTest.java:15: Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed().\n" + - "SecureRandomTest.java:16: Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed().\n" + - "SecureRandomTest.java:17: Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed().\n" + - "SecureRandomTest.java:18: Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed().\n" + - "SecureRandomTest.java:28: Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed().", + "src/test/pkg/SecureRandomTest.java:12: Warning: It is dangerous to seed SecureRandom with the current time because that value is more predictable to an attacker than the default seed. [SecureRandom]\n" + + " random1.setSeed(System.currentTimeMillis()); // OK\n" + + " ~~~~~~~\n" + + "src/test/pkg/SecureRandomTest.java:14: Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom]\n" + + " random1.setSeed(0); // Wrong\n" + + " ~~~~~~~\n" + + "src/test/pkg/SecureRandomTest.java:15: Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom]\n" + + " random1.setSeed(1); // Wrong\n" + + " ~~~~~~~\n" + + "src/test/pkg/SecureRandomTest.java:16: Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom]\n" + + " random1.setSeed((int)1023); // Wrong\n" + + " ~~~~~~~\n" + + "src/test/pkg/SecureRandomTest.java:17: Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom]\n" + + " random1.setSeed(1023L); // Wrong\n" + + " ~~~~~~~\n" + + "src/test/pkg/SecureRandomTest.java:18: Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom]\n" + + " random1.setSeed(FIXED_SEED); // Wrong\n" + + " ~~~~~~~\n" + + "src/test/pkg/SecureRandomTest.java:28: Warning: Do not call setSeed() on a SecureRandom with a fixed seed: it is not secure. Use getSeed(). [SecureRandom]\n" + + " random3.setSeed(0); // Wrong: owner is java/util/Random, but applied to SecureRandom object\n" + + " ~~~~~~~\n" + + "0 errors, 7 warnings\n" + + "", // Missing error on line 40, using flow analysis to determine that the seed byte // array passed into the SecureRandom constructor is static. diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SecurityDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SecurityDetectorTest.java index a52041d..1c293c3 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SecurityDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SecurityDetectorTest.java @@ -27,7 +27,11 @@ public class SecurityDetectorTest extends AbstractCheckTest { public void testBroken() throws Exception { assertEquals( - "AndroidManifest.xml:12: Warning: Exported service does not require permission", + "AndroidManifest.xml:12: Warning: Exported service does not require permission [ExportedService]\n" + + " <service\n" + + " ^\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "exportservice1.xml=>AndroidManifest.xml", "res/values/strings.xml")); @@ -35,7 +39,11 @@ public class SecurityDetectorTest extends AbstractCheckTest { public void testBroken2() throws Exception { assertEquals( - "AndroidManifest.xml:12: Warning: Exported service does not require permission", + "AndroidManifest.xml:12: Warning: Exported service does not require permission [ExportedService]\n" + + " <service\n" + + " ^\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "exportservice2.xml=>AndroidManifest.xml", "res/values/strings.xml")); @@ -44,7 +52,11 @@ public class SecurityDetectorTest extends AbstractCheckTest { public void testBroken3() throws Exception { // Not defining exported, but have intent-filters assertEquals( - "AndroidManifest.xml:12: Warning: Exported service does not require permission", + "AndroidManifest.xml:12: Warning: Exported service does not require permission [ExportedService]\n" + + " <service\n" + + " ^\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "exportservice5.xml=>AndroidManifest.xml", "res/values/strings.xml")); @@ -70,8 +82,14 @@ public class SecurityDetectorTest extends AbstractCheckTest { public void testUri() throws Exception { assertEquals( - "AndroidManifest.xml:25: Warning: Content provider shares everything; this is potentially dangerous.\n" + - "AndroidManifest.xml:26: Warning: Content provider shares everything; this is potentially dangerous.", + "AndroidManifest.xml:25: Warning: Content provider shares everything; this is potentially dangerous. [GrantAllUris]\n" + + " <grant-uri-permission android:path=\"/\"/>\n" + + " ~~~~~~~~~~~~~~~~\n" + + "AndroidManifest.xml:26: Warning: Content provider shares everything; this is potentially dangerous. [GrantAllUris]\n" + + " <grant-uri-permission android:pathPrefix=\"/\"/>\n" + + " ~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 2 warnings\n" + + "", lintProject( "grantpermission.xml=>AndroidManifest.xml", @@ -81,11 +99,17 @@ public class SecurityDetectorTest extends AbstractCheckTest { // exportprovider1.xml has two exported content providers with no permissions public void testContentProvider1() throws Exception { assertEquals( - "AndroidManifest.xml:14: Warning: Exported content providers can provide access to potentially sensitive data\n" + - "AndroidManifest.xml:20: Warning: Exported content providers can provide access to potentially sensitive data", - lintProject( - "exportprovider1.xml=>AndroidManifest.xml", - "res/values/strings.xml")); + "AndroidManifest.xml:14: Warning: Exported content providers can provide access to potentially sensitive data [ExportedContentProvider]\n" + + " <provider\n" + + " ^\n" + + "AndroidManifest.xml:20: Warning: Exported content providers can provide access to potentially sensitive data [ExportedContentProvider]\n" + + " <provider\n" + + " ^\n" + + "0 errors, 2 warnings\n" + + "", + lintProject( + "exportprovider1.xml=>AndroidManifest.xml", + "res/values/strings.xml")); } // exportprovider2.xml has no un-permissioned exported content providers @@ -99,10 +123,20 @@ public class SecurityDetectorTest extends AbstractCheckTest { public void testWorldWriteable() throws Exception { assertEquals( - "WorldWriteableFile.java:25: Warning: Using MODE_WORLD_WRITEABLE when creating files can be risky, review carefully\n" + - "WorldWriteableFile.java:26: Warning: Using MODE_WORLD_READABLE when creating files can be risky, review carefully\n" + - "WorldWriteableFile.java:30: Warning: Using MODE_WORLD_WRITEABLE when creating files can be risky, review carefully\n" + - "WorldWriteableFile.java:31: Warning: Using MODE_WORLD_READABLE when creating files can be risky, review carefully", + "src/test/pkg/WorldWriteableFile.java:26: Warning: Using MODE_WORLD_READABLE when creating files can be risky, review carefully [WorldReadableFiles]\n" + + " out = openFileOutput(mFile.getName(), MODE_WORLD_READABLE);\n" + + " ~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/WorldWriteableFile.java:31: Warning: Using MODE_WORLD_READABLE when creating files can be risky, review carefully [WorldReadableFiles]\n" + + " prefs = getSharedPreferences(mContext, MODE_WORLD_READABLE);\n" + + " ~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/WorldWriteableFile.java:25: Warning: Using MODE_WORLD_WRITEABLE when creating files can be risky, review carefully [WorldWriteableFiles]\n" + + " out = openFileOutput(mFile.getName(), MODE_WORLD_WRITEABLE);\n" + + " ~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/WorldWriteableFile.java:30: Warning: Using MODE_WORLD_WRITEABLE when creating files can be risky, review carefully [WorldWriteableFiles]\n" + + " prefs = getSharedPreferences(mContext, MODE_WORLD_WRITEABLE);\n" + + " ~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 4 warnings\n" + + "", lintProject( // Java files must be renamed in source tree @@ -120,7 +154,11 @@ public class SecurityDetectorTest extends AbstractCheckTest { public void testActivity1() throws Exception { assertEquals( - "AndroidManifest.xml:12: Warning: Exported activity does not require permission", + "AndroidManifest.xml:12: Warning: Exported activity does not require permission [ExportedActivity]\n" + + " <activity\n" + + " ^\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "exportactivity1.xml=>AndroidManifest.xml", "res/values/strings.xml")); @@ -147,7 +185,11 @@ public class SecurityDetectorTest extends AbstractCheckTest { public void testActivity4() throws Exception { // Not defining exported, but have intent-filters assertEquals( - "AndroidManifest.xml:12: Warning: Exported activity does not require permission", + "AndroidManifest.xml:12: Warning: Exported activity does not require permission [ExportedActivity]\n" + + " <activity\n" + + " ^\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "exportactivity4.xml=>AndroidManifest.xml", "res/values/strings.xml")); @@ -164,7 +206,11 @@ public class SecurityDetectorTest extends AbstractCheckTest { public void testReceiver1() throws Exception { assertEquals( - "AndroidManifest.xml:12: Warning: Exported receiver does not require permission", + "AndroidManifest.xml:12: Warning: Exported receiver does not require permission [ExportedReceiver]\n" + + " <receiver\n" + + " ^\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "exportreceiver1.xml=>AndroidManifest.xml", "res/values/strings.xml")); @@ -191,7 +237,11 @@ public class SecurityDetectorTest extends AbstractCheckTest { public void testReceiver4() throws Exception { // Not defining exported, but have intent-filters assertEquals( - "AndroidManifest.xml:12: Warning: Exported receiver does not require permission", + "AndroidManifest.xml:12: Warning: Exported receiver does not require permission [ExportedReceiver]\n" + + " <receiver\n" + + " ^\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "exportreceiver4.xml=>AndroidManifest.xml", "res/values/strings.xml")); diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SetJavaScriptEnabledDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SetJavaScriptEnabledDetectorTest.java index f5d2b60..4979e6a 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SetJavaScriptEnabledDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SetJavaScriptEnabledDetectorTest.java @@ -25,12 +25,14 @@ public class SetJavaScriptEnabledDetectorTest extends AbstractCheckTest { return new SetJavaScriptEnabledDetector(); } - public void testAccessibility() throws Exception { + public void test() throws Exception { assertEquals( - "SetJavaScriptEnabled.java:14: Warning: Using setJavaScriptEnabled " + - "can introduce XSS vulnerabilities into you application, review " + - "carefully.", - lintProject( - "src/test/pkg/SetJavaScriptEnabled.java.txt=>src/test/pkg/SetJavaScriptEnabled.java")); + "src/test/pkg/SetJavaScriptEnabled.java:14: Warning: Using setJavaScriptEnabled can introduce XSS vulnerabilities into you application, review carefully. [SetJavaScriptEnabled]\n" + + " webView.getSettings().setJavaScriptEnabled(true); // bad\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", + lintProject( + "src/test/pkg/SetJavaScriptEnabled.java.txt=>src/test/pkg/SetJavaScriptEnabled.java")); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SharedPrefsDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SharedPrefsDetectorTest.java index 574b23a..b77f3bd 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SharedPrefsDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/SharedPrefsDetectorTest.java @@ -27,8 +27,14 @@ public class SharedPrefsDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "SharedPrefsTest.java:54: Warning: SharedPreferences.edit() without a corresponding commit() or apply() call\n" + - "SharedPrefsTest.java:62: Warning: SharedPreferences.edit() without a corresponding commit() or apply() call", + "src/test/pkg/SharedPrefsTest.java:54: Warning: SharedPreferences.edit() without a corresponding commit() or apply() call [CommitPrefEdits]\n" + + " SharedPreferences.Editor editor = preferences.edit();\n" + + " ~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/SharedPrefsTest.java:62: Warning: SharedPreferences.edit() without a corresponding commit() or apply() call [CommitPrefEdits]\n" + + " SharedPreferences.Editor editor = preferences.edit();\n" + + " ~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 2 warnings\n" + + "", lintProject("src/test/pkg/SharedPrefsTest.java.txt=>" + "src/test/pkg/SharedPrefsTest.java")); diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StateListDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StateListDetectorTest.java index 9176773..9ff67f4 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StateListDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StateListDetectorTest.java @@ -27,21 +27,29 @@ public class StateListDetectorTest extends AbstractCheckTest { public void testStates() throws Exception { assertEquals( - "drawable/states.xml:3: Warning: This item is unreachable because a previous item (item #1) is a more general match than this one\n" + - "=> drawable/states.xml:2: Earlier item which masks item", - lintProject("res/drawable/states.xml")); + "res/drawable/states.xml:3: Warning: This item is unreachable because a previous item (item #1) is a more general match than this one [StateListReachable]\n" + + " <item android:state_pressed=\"true\"\n" + + " ^\n" + + " res/drawable/states.xml:2: Earlier item which masks item\n" + + "0 errors, 1 warnings\n" + + "", + lintProject("res/drawable/states.xml")); } public void testCustomStates() throws Exception { assertEquals( - "No warnings.", - lintProject("res/drawable/states2.xml")); + "No warnings.", + lintProject("res/drawable/states2.xml")); } public void testStates3() throws Exception { assertEquals( - "drawable/states3.xml:24: Warning: This item is unreachable because a previous item (item #1) is a more general match than this one\n" + - "=> drawable/states3.xml:18: Earlier item which masks item", - lintProject("res/drawable/states3.xml")); + "res/drawable/states3.xml:24: Warning: This item is unreachable because a previous item (item #1) is a more general match than this one [StateListReachable]\n" + + " <item android:state_checked=\"false\" android:state_window_focused=\"false\"\n" + + " ^\n" + + " res/drawable/states3.xml:18: Earlier item which masks item\n" + + "0 errors, 1 warnings\n" + + "", + lintProject("res/drawable/states3.xml")); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StringFormatDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StringFormatDetectorTest.java index a53440e..0ffaa08 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StringFormatDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StringFormatDetectorTest.java @@ -30,23 +30,43 @@ public class StringFormatDetectorTest extends AbstractCheckTest { public void testAll() throws Exception { assertEquals( - "formatstrings.xml:5: Warning: Formatting string 'missing' is not referencing numbered arguments [1, 2]\n" + - "pkg/StringFormatActivity.java:13: Error: Wrong argument type for formatting argument '#1' in hello: conversion is 'd', received String\n" + - "=> values-es/formatstrings.xml:3: Conflicting argument declaration here\n" + - "pkg/StringFormatActivity.java:15: Error: Wrong argument count, format string hello2 requires 3 but format call supplies 2\n" + - "=> values-es/formatstrings.xml:4: This definition requires 3 arguments\n" + - "pkg/StringFormatActivity.java:24: Error: Wrong argument count, format string hello2 requires 3 but format call supplies 2\n" + - "=> values-es/formatstrings.xml:4: This definition requires 3 arguments\n" + - "pkg/StringFormatActivity.java:25: Error: Wrong argument count, format string hello2 requires 3 but format call supplies 2\n" + - "=> values-es/formatstrings.xml:4: This definition requires 3 arguments\n" + - "pkg/StringFormatActivity.java:26: Error: Wrong argument count, format string hello2 requires 3 but format call supplies 2\n" + - "=> values-es/formatstrings.xml:4: This definition requires 3 arguments\n" + - "pkg/StringFormatActivity.java:33: Error: Wrong argument type for formatting argument '#1' in hello: conversion is 'd', received String\n" + - "=> values-es/formatstrings.xml:3: Conflicting argument declaration here\n" + - "values-es/formatstrings.xml:3: Error: Inconsistent formatting types for argument #1 in format string hello ('%1$d'): Found both 's' and 'd' (in values/formatstrings.xml)\n" + - "=> values/formatstrings.xml:3: Conflicting argument type here\n" + - "values-es/formatstrings.xml:4: Warning: Inconsistent number of arguments in formatting string hello2; found both 2 and 3\n" + - "=> values/formatstrings.xml:4: Conflicting number of arguments here", + "src/test/pkg/StringFormatActivity.java:13: Error: Wrong argument type for formatting argument '#1' in hello: conversion is 'd', received String [StringFormatMatches]\n" + + " String output1 = String.format(hello, target);\n" + + " ~~~~~~\n" + + " res/values-es/formatstrings.xml:3: Conflicting argument declaration here\n" + + "src/test/pkg/StringFormatActivity.java:15: Error: Wrong argument count, format string hello2 requires 3 but format call supplies 2 [StringFormatMatches]\n" + + " String output2 = String.format(hello2, target, \"How are you\");\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + " res/values-es/formatstrings.xml:4: This definition requires 3 arguments\n" + + "src/test/pkg/StringFormatActivity.java:24: Error: Wrong argument count, format string hello2 requires 3 but format call supplies 2 [StringFormatMatches]\n" + + " String.format(getResources().getString(R.string.hello2), target, \"How are you\");\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + " res/values-es/formatstrings.xml:4: This definition requires 3 arguments\n" + + "src/test/pkg/StringFormatActivity.java:25: Error: Wrong argument count, format string hello2 requires 3 but format call supplies 2 [StringFormatMatches]\n" + + " getResources().getString(hello2, target, \"How are you\");\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + " res/values-es/formatstrings.xml:4: This definition requires 3 arguments\n" + + "src/test/pkg/StringFormatActivity.java:26: Error: Wrong argument count, format string hello2 requires 3 but format call supplies 2 [StringFormatMatches]\n" + + " getResources().getString(R.string.hello2, target, \"How are you\");\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + " res/values-es/formatstrings.xml:4: This definition requires 3 arguments\n" + + "src/test/pkg/StringFormatActivity.java:33: Error: Wrong argument type for formatting argument '#1' in hello: conversion is 'd', received String [StringFormatMatches]\n" + + " String output1 = String.format(hello, target);\n" + + " ~~~~~~\n" + + " res/values-es/formatstrings.xml:3: Conflicting argument declaration here\n" + + "res/values-es/formatstrings.xml:3: Error: Inconsistent formatting types for argument #1 in format string hello ('%1$d'): Found both 's' and 'd' (in values/formatstrings.xml) [StringFormatMatches]\n" + + " <string name=\"hello\">%1$d</string>\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + " res/values/formatstrings.xml:3: Conflicting argument type here\n" + + "res/values-es/formatstrings.xml:4: Warning: Inconsistent number of arguments in formatting string hello2; found both 2 and 3 [StringFormatCount]\n" + + " <string name=\"hello2\">%3$d: %1$s, %2$s?</string>\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + " res/values/formatstrings.xml:4: Conflicting number of arguments here\n" + + "res/values/formatstrings.xml:5: Warning: Formatting string 'missing' is not referencing numbered arguments [1, 2] [StringFormatCount]\n" + + " <string name=\"missing\">Hello %3$s World</string>\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "7 errors, 2 warnings\n" + + "", lintProject( "res/values/formatstrings.xml", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StyleCycleDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StyleCycleDetectorTest.java index f31a26b..d4823d7 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StyleCycleDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/StyleCycleDetectorTest.java @@ -27,15 +27,22 @@ public class StyleCycleDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "styles.xml:9: Error: Style DetailsPage_EditorialBuyButton should not extend itself", + "res/values/styles.xml:9: Error: Style DetailsPage_EditorialBuyButton should not extend itself [StyleCycle]\n" + + "<style name=\"DetailsPage_EditorialBuyButton\" parent=\"@style/DetailsPage_EditorialBuyButton\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "1 errors, 0 warnings\n" + + "", lintProject("res/values/styles.xml")); } public void test2() throws Exception { assertEquals( - "stylecycle.xml:3: Error: Potential cycle: PropertyToggle is the implied parent " + - "of PropertyToggle.Base and this defines the opposite", + "res/values/stylecycle.xml:3: Error: Potential cycle: PropertyToggle is the implied parent of PropertyToggle.Base and this defines the opposite [StyleCycle]\n" + + " <style name=\"PropertyToggle\" parent=\"@style/PropertyToggle.Base\"></style>\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "1 errors, 0 warnings\n" + + "", lintProject("res/values/stylecycle.xml")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TextFieldDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TextFieldDetectorTest.java index 58cdde8..85e4b8d 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TextFieldDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TextFieldDetectorTest.java @@ -27,7 +27,11 @@ public class TextFieldDetectorTest extends AbstractCheckTest { public void testField() throws Exception { assertEquals( - "note_edit.xml:50: Warning: This text field does not specify an inputType or a hint", + "res/layout/note_edit.xml:50: Warning: This text field does not specify an inputType or a hint [TextFields]\n" + + " <EditText\n" + + " ^\n" + + "0 errors, 1 warnings\n" + + "", lintFiles("res/layout/note_edit.xml")); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TextViewDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TextViewDetectorTest.java index a0bbb50..8c63bd8 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TextViewDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TextViewDetectorTest.java @@ -27,27 +27,71 @@ public class TextViewDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "edit_textview.xml:13: Warning: Attribute android:autoText should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:14: Warning: Attribute android:bufferType should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:15: Warning: Attribute android:capitalize should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:16: Warning: Attribute android:cursorVisible should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:17: Warning: Attribute android:digits should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:18: Warning: Attribute android:editable should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:19: Warning: Attribute android:editorExtras should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:22: Warning: Attribute android:imeActionId should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:23: Warning: Attribute android:imeActionLabel should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:24: Warning: Attribute android:imeOptions should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:25: Warning: Attribute android:inputMethod should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:26: Warning: Attribute android:inputType should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:27: Warning: Attribute android:numeric should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:28: Warning: Attribute android:password should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:29: Warning: Attribute android:phoneNumber should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:30: Warning: Attribute android:privateImeOptions should not be used with <TextView>: Change element type to <EditText> ?\n" + - "edit_textview.xml:38: Warning: Attribute android:cursorVisible should not be used with <Button>: intended for editable text widgets\n" + - "edit_textview.xml:44: Warning: Attribute android:cursorVisible should not be used with <CheckedTextView>: intended for editable text widgets\n" + - "edit_textview.xml:50: Warning: Attribute android:cursorVisible should not be used with <CheckBox>: intended for editable text widgets\n" + - "edit_textview.xml:56: Warning: Attribute android:cursorVisible should not be used with <RadioButton>: intended for editable text widgets\n" + - "edit_textview.xml:62: Warning: Attribute android:cursorVisible should not be used with <ToggleButton>: intended for editable text widgets", + "res/layout/edit_textview.xml:13: Warning: Attribute android:autoText should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:autoText=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:14: Warning: Attribute android:bufferType should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:bufferType=\"editable\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:15: Warning: Attribute android:capitalize should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:capitalize=\"words\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:16: Warning: Attribute android:cursorVisible should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:cursorVisible=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:17: Warning: Attribute android:digits should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:digits=\"\"\n" + + " ~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:18: Warning: Attribute android:editable should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:editable=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:19: Warning: Attribute android:editorExtras should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:editorExtras=\"@+id/foobar\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:22: Warning: Attribute android:imeActionId should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:imeActionId=\"@+id/foo\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:23: Warning: Attribute android:imeActionLabel should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:imeActionLabel=\"\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:24: Warning: Attribute android:imeOptions should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:imeOptions=\"\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:25: Warning: Attribute android:inputMethod should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:inputMethod=\"\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:26: Warning: Attribute android:inputType should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:inputType=\"text\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:27: Warning: Attribute android:numeric should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:numeric=\"\"\n" + + " ~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:28: Warning: Attribute android:password should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:password=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:29: Warning: Attribute android:phoneNumber should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:phoneNumber=\"true\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:30: Warning: Attribute android:privateImeOptions should not be used with <TextView>: Change element type to <EditText> ? [TextViewEdits]\n" + + " android:privateImeOptions=\"\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:38: Warning: Attribute android:cursorVisible should not be used with <Button>: intended for editable text widgets [TextViewEdits]\n" + + " android:cursorVisible=\"true\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:44: Warning: Attribute android:cursorVisible should not be used with <CheckedTextView>: intended for editable text widgets [TextViewEdits]\n" + + " android:cursorVisible=\"true\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:50: Warning: Attribute android:cursorVisible should not be used with <CheckBox>: intended for editable text widgets [TextViewEdits]\n" + + " android:cursorVisible=\"true\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:56: Warning: Attribute android:cursorVisible should not be used with <RadioButton>: intended for editable text widgets [TextViewEdits]\n" + + " android:cursorVisible=\"true\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/edit_textview.xml:62: Warning: Attribute android:cursorVisible should not be used with <ToggleButton>: intended for editable text widgets [TextViewEdits]\n" + + " android:cursorVisible=\"true\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 21 warnings\n" + + "", lintFiles("res/layout/edit_textview.xml")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ToastDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ToastDetectorTest.java index 0b8c984..07941b7 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ToastDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ToastDetectorTest.java @@ -27,10 +27,20 @@ public class ToastDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "ToastTest.java:31: Warning: Toast created but not shown: did you forget to call show() ?\n" + - "ToastTest.java:32: Warning: Expected duration Toast.LENGTH_SHORT or Toast.LENGTH_LONG, a custom duration value is not supported\n" + - "ToastTest.java:32: Warning: Toast created but not shown: did you forget to call show() ?\n" + - "ToastTest.java:38: Warning: Toast created but not shown: did you forget to call show() ?", + "src/test/pkg/ToastTest.java:31: Warning: Toast created but not shown: did you forget to call show() ? [ShowToast]\n" + + " Toast.makeText(context, \"foo\", Toast.LENGTH_LONG);\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/ToastTest.java:32: Warning: Expected duration Toast.LENGTH_SHORT or Toast.LENGTH_LONG, a custom duration value is not supported [ShowToast]\n" + + " Toast toast = Toast.makeText(context, R.string.app_name, 5000);\n" + + " ~~~~\n" + + "src/test/pkg/ToastTest.java:32: Warning: Toast created but not shown: did you forget to call show() ? [ShowToast]\n" + + " Toast toast = Toast.makeText(context, R.string.app_name, 5000);\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "src/test/pkg/ToastTest.java:38: Warning: Toast created but not shown: did you forget to call show() ? [ShowToast]\n" + + " Toast.makeText(context, \"foo\", Toast.LENGTH_LONG);\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 4 warnings\n" + + "", lintProject("src/test/pkg/ToastTest.java.txt=>src/test/pkg/ToastTest.java")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TooManyViewsDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TooManyViewsDetectorTest.java index a184b7e..51b977d 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TooManyViewsDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TooManyViewsDetectorTest.java @@ -27,15 +27,21 @@ public class TooManyViewsDetectorTest extends AbstractCheckTest { public void testTooMany() throws Exception { assertEquals( - "too_many.xml:399: Warning: too_many.xml has more than 80 views, bad for " + - "performance", - lintFiles("res/layout/too_many.xml")); + "res/layout/too_many.xml:399: Warning: too_many.xml has more than 80 views, bad for performance [TooManyViews]\n" + + " <Button\n" + + " ^\n" + + "0 errors, 1 warnings\n" + + "", + lintFiles("res/layout/too_many.xml")); } public void testTooDeep() throws Exception { assertEquals( - "too_deep.xml:46: Warning: too_deep.xml has more than 10 levels, bad for " + - "performance", - lintFiles("res/layout/too_deep.xml")); + "res/layout/too_deep.xml:46: Warning: too_deep.xml has more than 10 levels, bad for performance [TooDeepLayout]\n" + + " <LinearLayout\n" + + " ^\n" + + "0 errors, 1 warnings\n" + + "", + lintFiles("res/layout/too_deep.xml")); } } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TranslationDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TranslationDetectorTest.java index 39231dd..f0284fd 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TranslationDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TranslationDetectorTest.java @@ -34,12 +34,24 @@ public class TranslationDetectorTest extends AbstractCheckTest { TranslationDetector.COMPLETE_REGIONS = false; assertEquals( // Sample files from the Home app - "values-cs/arrays.xml:3: Error: \"security_questions\" is translated here but not found in default locale\n" + - "=> values-es/strings.xml:12: Also translated here\n" + - "values-de-rDE/strings.xml:11: Error: \"continue_skip_label\" is translated here but not found in default locale\n" + - "values/strings.xml:20: Error: \"show_all_apps\" is not translated in nl-rNL\n" + - "values/strings.xml:23: Error: \"menu_wallpaper\" is not translated in nl-rNL\n" + - "values/strings.xml:25: Error: \"menu_settings\" is not translated in cs, de-rDE, es, es-rUS, nl-rNL", + "res/values/strings.xml:20: Error: \"show_all_apps\" is not translated in nl-rNL [MissingTranslation]\n" + + " <string name=\"show_all_apps\">All</string>\n" + + " ~~~~~~~~~~~~~~~~~~~~\n" + + "res/values/strings.xml:23: Error: \"menu_wallpaper\" is not translated in nl-rNL [MissingTranslation]\n" + + " <string name=\"menu_wallpaper\">Wallpaper</string>\n" + + " ~~~~~~~~~~~~~~~~~~~~~\n" + + "res/values/strings.xml:25: Error: \"menu_settings\" is not translated in cs, de-rDE, es, es-rUS, nl-rNL [MissingTranslation]\n" + + " <string name=\"menu_settings\">Settings</string>\n" + + " ~~~~~~~~~~~~~~~~~~~~\n" + + "res/values-cs/arrays.xml:3: Error: \"security_questions\" is translated here but not found in default locale [ExtraTranslation]\n" + + " <string-array name=\"security_questions\">\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + " res/values-es/strings.xml:12: Also translated here\n" + + "res/values-de-rDE/strings.xml:11: Error: \"continue_skip_label\" is translated here but not found in default locale [ExtraTranslation]\n" + + " <string name=\"continue_skip_label\">\"Weiter\"</string>\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "5 errors, 0 warnings\n" + + "", lintProject( "res/values/strings.xml", @@ -57,12 +69,27 @@ public class TranslationDetectorTest extends AbstractCheckTest { TranslationDetector.COMPLETE_REGIONS = true; assertEquals( // Sample files from the Home app - "values-de-rDE/strings.xml:11: Error: \"continue_skip_label\" is translated here but not found in default locale\n" + - "values/strings.xml:19: Error: \"home_title\" is not translated in es-rUS\n" + - "values/strings.xml:20: Error: \"show_all_apps\" is not translated in es-rUS, nl-rNL\n" + - "values/strings.xml:23: Error: \"menu_wallpaper\" is not translated in es-rUS, nl-rNL\n" + - "values/strings.xml:25: Error: \"menu_settings\" is not translated in cs, de-rDE, es-rUS, nl-rNL\n" + - "values/strings.xml:29: Error: \"wallpaper_instructions\" is not translated in es-rUS", + "res/values/strings.xml:19: Error: \"home_title\" is not translated in es-rUS [MissingTranslation]\n" + + " <string name=\"home_title\">Home Sample</string>\n" + + " ~~~~~~~~~~~~~~~~~\n" + + "res/values/strings.xml:20: Error: \"show_all_apps\" is not translated in es-rUS, nl-rNL [MissingTranslation]\n" + + " <string name=\"show_all_apps\">All</string>\n" + + " ~~~~~~~~~~~~~~~~~~~~\n" + + "res/values/strings.xml:23: Error: \"menu_wallpaper\" is not translated in es-rUS, nl-rNL [MissingTranslation]\n" + + " <string name=\"menu_wallpaper\">Wallpaper</string>\n" + + " ~~~~~~~~~~~~~~~~~~~~~\n" + + "res/values/strings.xml:25: Error: \"menu_settings\" is not translated in cs, de-rDE, es-rUS, nl-rNL [MissingTranslation]\n" + + " <string name=\"menu_settings\">Settings</string>\n" + + " ~~~~~~~~~~~~~~~~~~~~\n" + + "res/values/strings.xml:29: Error: \"wallpaper_instructions\" is not translated in es-rUS [MissingTranslation]\n" + + " <string name=\"wallpaper_instructions\">Tap picture to set portrait wallpaper</string>\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + " res/values-land/strings.xml:19: <No location-specific message\n" + + "res/values-de-rDE/strings.xml:11: Error: \"continue_skip_label\" is translated here but not found in default locale [ExtraTranslation]\n" + + " <string name=\"continue_skip_label\">\"Weiter\"</string>\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "6 errors, 0 warnings\n" + + "", lintProject( "res/values/strings.xml", @@ -141,9 +168,11 @@ public class TranslationDetectorTest extends AbstractCheckTest { public void testNonTranslatable1() throws Exception { TranslationDetector.COMPLETE_REGIONS = true; assertEquals( - // Sample files from the Home app - "values-nb/nontranslatable.xml:3: Error: The resource string \"dummy\" has been " + - "marked as translatable=\"false\"", + "res/values-nb/nontranslatable.xml:3: Error: The resource string \"dummy\" has been marked as translatable=\"false\" [ExtraTranslation]\n" + + " <string name=\"dummy\">Ignore Me</string>\n" + + " ~~~~~~~~~~~~\n" + + "1 errors, 0 warnings\n" + + "", lintProject("res/values/nontranslatable.xml", "res/values/nontranslatable2.xml=>res/values-nb/nontranslatable.xml")); @@ -152,9 +181,11 @@ public class TranslationDetectorTest extends AbstractCheckTest { public void testNonTranslatable2() throws Exception { TranslationDetector.COMPLETE_REGIONS = true; assertEquals( - // Sample files from the Home app - "values-nb/nontranslatable.xml:3: Error: Non-translatable resources should only " + - "be defined in the base values/ folder", + "res/values-nb/nontranslatable.xml:3: Error: Non-translatable resources should only be defined in the base values/ folder [ExtraTranslation]\n" + + " <string name=\"dummy\" translatable=\"false\">Ignore Me</string>\n" + + " ~~~~~~~~~~~~~~~~~~~~\n" + + "1 errors, 0 warnings\n" + + "", lintProject("res/values/nontranslatable.xml=>res/values-nb/nontranslatable.xml")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TypoDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TypoDetectorTest.java index 864c065..51d8a75 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TypoDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TypoDetectorTest.java @@ -29,46 +29,100 @@ public class TypoDetectorTest extends AbstractCheckTest { public void testPlainValues() throws Exception { assertEquals( - "strings.xml:10: Warning: \"throught\" is a common misspelling; did you mean \"thought\" or \"through\" or \"throughout\" ?\n" + - "strings.xml:12: Warning: \"Seach\" is a common misspelling; did you mean \"Search\" ?\n" + - "strings.xml:16: Warning: \"Tuscon\" is a common misspelling; did you mean \"Tucson\" ?\n" + - "strings.xml:20: Warning: \"Ok\" is usually capitalized as \"OK\"\n" + - "strings.xml:6: Warning: \"Andriod\" is a common misspelling; did you mean \"Android\" ?\n" + - "strings.xml:6: Warning: \"activites\" is a common misspelling; did you mean \"activities\" ?\n" + - "strings.xml:8: Warning: \"Cmoputer\" is a common misspelling; did you mean \"Computer\" ?", + "res/values/strings.xml:6: Warning: \"Andriod\" is a common misspelling; did you mean \"Android\" ? [Typos]\n" + + " <string name=\"s2\">Andriod activites!</string>\n" + + " ^\n" + + "res/values/strings.xml:6: Warning: \"activites\" is a common misspelling; did you mean \"activities\" ? [Typos]\n" + + " <string name=\"s2\">Andriod activites!</string>\n" + + " ^\n" + + "res/values/strings.xml:8: Warning: \"Cmoputer\" is a common misspelling; did you mean \"Computer\" ? [Typos]\n" + + " <string name=\"s3\"> (Cmoputer </string>\n" + + " ^\n" + + "res/values/strings.xml:10: Warning: \"throught\" is a common misspelling; did you mean \"thought\" or \"through\" or \"throughout\" ? [Typos]\n" + + " <string name=\"s4\"><b>throught</b></string>\n" + + " ^\n" + + "res/values/strings.xml:12: Warning: \"Seach\" is a common misspelling; did you mean \"Search\" ? [Typos]\n" + + " <string name=\"s5\">Seach</string>\n" + + " ^\n" + + "res/values/strings.xml:16: Warning: \"Tuscon\" is a common misspelling; did you mean \"Tucson\" ? [Typos]\n" + + " <string name=\"s7\">Tuscon tuscon</string>\n" + + " ^\n" + + "res/values/strings.xml:20: Warning: \"Ok\" is usually capitalized as \"OK\" [Typos]\n" + + " <string name=\"dlg_button_ok\">Ok</string>\n" + + " ^\n" + + "0 errors, 7 warnings\n" + + "", lintProject("res/values/typos.xml=>res/values/strings.xml")); } public void testEnLanguage() throws Exception { assertEquals( - "strings-en.xml:10: Warning: \"throught\" is a common misspelling; did you mean \"thought\" or \"through\" or \"throughout\" ?\n" + - "strings-en.xml:12: Warning: \"Seach\" is a common misspelling; did you mean \"Search\" ?\n" + - "strings-en.xml:16: Warning: \"Tuscon\" is a common misspelling; did you mean \"Tucson\" ?\n" + - "strings-en.xml:20: Warning: \"Ok\" is usually capitalized as \"OK\"\n" + - "strings-en.xml:6: Warning: \"Andriod\" is a common misspelling; did you mean \"Android\" ?\n" + - "strings-en.xml:6: Warning: \"activites\" is a common misspelling; did you mean \"activities\" ?\n" + - "strings-en.xml:8: Warning: \"Cmoputer\" is a common misspelling; did you mean \"Computer\" ?", + "res/values-en-rUS/strings-en.xml:6: Warning: \"Andriod\" is a common misspelling; did you mean \"Android\" ? [Typos]\n" + + " <string name=\"s2\">Andriod activites!</string>\n" + + " ^\n" + + "res/values-en-rUS/strings-en.xml:6: Warning: \"activites\" is a common misspelling; did you mean \"activities\" ? [Typos]\n" + + " <string name=\"s2\">Andriod activites!</string>\n" + + " ^\n" + + "res/values-en-rUS/strings-en.xml:8: Warning: \"Cmoputer\" is a common misspelling; did you mean \"Computer\" ? [Typos]\n" + + " <string name=\"s3\"> (Cmoputer </string>\n" + + " ^\n" + + "res/values-en-rUS/strings-en.xml:10: Warning: \"throught\" is a common misspelling; did you mean \"thought\" or \"through\" or \"throughout\" ? [Typos]\n" + + " <string name=\"s4\"><b>throught</b></string>\n" + + " ^\n" + + "res/values-en-rUS/strings-en.xml:12: Warning: \"Seach\" is a common misspelling; did you mean \"Search\" ? [Typos]\n" + + " <string name=\"s5\">Seach</string>\n" + + " ^\n" + + "res/values-en-rUS/strings-en.xml:16: Warning: \"Tuscon\" is a common misspelling; did you mean \"Tucson\" ? [Typos]\n" + + " <string name=\"s7\">Tuscon tuscon</string>\n" + + " ^\n" + + "res/values-en-rUS/strings-en.xml:20: Warning: \"Ok\" is usually capitalized as \"OK\" [Typos]\n" + + " <string name=\"dlg_button_ok\">Ok</string>\n" + + " ^\n" + + "0 errors, 7 warnings\n" + + "", lintProject("res/values/typos.xml=>res/values-en-rUS/strings-en.xml")); } public void testNorwegian() throws Exception { // UTF-8 handling assertEquals( - "typos.xml:10: Warning: \"altid\" is a common misspelling; did you mean \"alltid\" ?\n" + - "typos.xml:12: Warning: \"Altid\" is a common misspelling; did you mean \"Alltid\" ?\n" + - "typos.xml:18: Warning: \"karri¾re\" is a common misspelling; did you mean \"karrire\" ?\n" + - "typos.xml:6: Warning: \"Andriod\" is a common misspelling; did you mean \"Android\" ?\n" + - "typos.xml:6: Warning: \"morro\" is a common misspelling; did you mean \"moro\" ?\n" + - "typos.xml:8: Warning: \"Parallel\" is a common misspelling; did you mean \"Parallell\" ?", + "res/values-nb/typos.xml:6: Warning: \"Andriod\" is a common misspelling; did you mean \"Android\" ? [Typos]\n" + + " <string name=\"s2\">Mer morro med Andriod</string>\n" + + " ^\n" + + "res/values-nb/typos.xml:6: Warning: \"morro\" is a common misspelling; did you mean \"moro\" ? [Typos]\n" + + " <string name=\"s2\">Mer morro med Andriod</string>\n" + + " ^\n" + + "res/values-nb/typos.xml:8: Warning: \"Parallel\" is a common misspelling; did you mean \"Parallell\" ? [Typos]\n" + + " <string name=\"s3\"> Parallel </string>\n" + + " ^\n" + + "res/values-nb/typos.xml:10: Warning: \"altid\" is a common misspelling; did you mean \"alltid\" ? [Typos]\n" + + " <string name=\"s4\"><b>altid</b></string>\n" + + " ^\n" + + "res/values-nb/typos.xml:12: Warning: \"Altid\" is a common misspelling; did you mean \"Alltid\" ? [Typos]\n" + + " <string name=\"s5\">Altid</string>\n" + + " ^\n" + + "res/values-nb/typos.xml:18: Warning: \"karri¾re\" is a common misspelling; did you mean \"karrire\" ? [Typos]\n" + + " <string name=\"s7\">Koding er en spennende karri¾re</string>\n" + + " ^\n" + + "0 errors, 6 warnings\n" + + "", lintProject("res/values-nb/typos.xml")); } public void testGerman() throws Exception { // Test globbing and multiple word matching assertEquals( - "typos.xml:10: Warning: \"zurŸck gefoobaren\" is a common misspelling; did you mean \"zurŸckgefoobaren\" ?\n" + - "typos.xml:6: Warning: \"befindet eine\" is a common misspelling; did you mean \"befindet sich eine\" ?\n" + - "typos.xml:9: Warning: \"Authorisierungscode\" is a common misspelling; did you mean \"Autorisierungscode\" ?", + "res/values-de/typos.xml:6: Warning: \"befindet eine\" is a common misspelling; did you mean \"befindet sich eine\" ? [Typos]\n" + + " wo befindet eine ip\n" + + " ^\n" + + "res/values-de/typos.xml:9: Warning: \"Authorisierungscode\" is a common misspelling; did you mean \"Autorisierungscode\" ? [Typos]\n" + + " <string name=\"s2\">(Authorisierungscode!)</string>\n" + + " ^\n" + + "res/values-de/typos.xml:10: Warning: \"zurŸck gefoobaren\" is a common misspelling; did you mean \"zurŸckgefoobaren\" ? [Typos]\n" + + " <string name=\"s3\"> zurŸck gefoobaren!</string>\n" + + " ^\n" + + "0 errors, 3 warnings\n" + + "", lintProject("res/values-de/typos.xml")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TypographyDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TypographyDetectorTest.java index 7ea2eb8..16d0107 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TypographyDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/TypographyDetectorTest.java @@ -32,22 +32,56 @@ public class TypographyDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "typography.xml:10: Warning: Avoid quoting with grave accents; use apostrophes or better yet directional quotes instead\n" + - "typography.xml:11: Warning: Replace straight quotes ('') with directional quotes (‘’, ‘ and ’) ?\n" + - "typography.xml:12: Warning: Use fraction character ½ (½) instead of 1/2 ?\n" + - "typography.xml:13: Warning: Use fraction character ¼ (¼) instead of 1/4 ?\n" + - "typography.xml:15: Warning: Replace \"...\" with ellipsis character (…, …) ?\n" + - "typography.xml:17: Warning: Replace \"-\" with an \"en dash\" character (–, –) ?\n" + - "typography.xml:18: Warning: Replace \"-\" with an \"en dash\" character (–, –) ?\n" + - "typography.xml:20: Warning: Replace \"--\" with an \"em dash\" character (—, —) ?\n" + - "typography.xml:24: Warning: Replace \"-\" with an \"en dash\" character (–, –) ?\n" + - "typography.xml:25: Warning: Use fraction character ½ (½) instead of 1/2 ?\n" + - "typography.xml:3: Warning: Replace straight quotes ('') with directional quotes (‘’, ‘ and ’) ?\n" + - "typography.xml:5: Warning: Replace straight quotes (\") with directional quotes (“â€, “ and ”) ?\n" + - "typography.xml:6: Warning: Replace straight quotes (\") with directional quotes (“â€, “ and ”) ?\n" + - "typography.xml:7: Warning: Replace apostrophe (') with typographic apostrophe (’, ’) ?\n" + - "typography.xml:8: Warning: Replace (c) with copyright symbol © (©) ?\n" + - "typography.xml:9: Warning: Replace apostrophe (') with typographic apostrophe (’, ’) ?", + "res/values/typography.xml:17: Warning: Replace \"-\" with an \"en dash\" character (–, –) ? [TypographyDashes]\n" + + " <string name=\"ndash\">For ages 3-5</string>\n" + + " ^\n" + + "res/values/typography.xml:18: Warning: Replace \"-\" with an \"en dash\" character (–, –) ? [TypographyDashes]\n" + + " <string name=\"ndash2\">Copyright 2007 - 2011</string>\n" + + " ^\n" + + "res/values/typography.xml:20: Warning: Replace \"--\" with an \"em dash\" character (—, —) ? [TypographyDashes]\n" + + " <string name=\"mdash\">Not found -- please try again</string>\n" + + " ^\n" + + "res/values/typography.xml:24: Warning: Replace \"-\" with an \"en dash\" character (–, –) ? [TypographyDashes]\n" + + " <item>Ages 3-5</item>\n" + + " ^\n" + + "res/values/typography.xml:15: Warning: Replace \"...\" with ellipsis character (…, …) ? [TypographyEllipsis]\n" + + " <string name=\"ellipsis\">40 times...</string>\n" + + " ^\n" + + "res/values/typography.xml:12: Warning: Use fraction character ½ (½) instead of 1/2 ? [TypographyFractions]\n" + + " <string name=\"fraction1\">5 1/2 times</string>\n" + + " ^\n" + + "res/values/typography.xml:13: Warning: Use fraction character ¼ (¼) instead of 1/4 ? [TypographyFractions]\n" + + " <string name=\"fraction4\">1/4 times</string>\n" + + " ^\n" + + "res/values/typography.xml:25: Warning: Use fraction character ½ (½) instead of 1/2 ? [TypographyFractions]\n" + + " <item>Age 5 1/2</item>\n" + + " ^\n" + + "res/values/typography.xml:3: Warning: Replace straight quotes ('') with directional quotes (‘’, ‘ and ’) ? [TypographyQuotes]\n" + + " <string name=\"home_title\">Home 'Sample'</string>\n" + + " ^\n" + + "res/values/typography.xml:5: Warning: Replace straight quotes (\") with directional quotes (“â€, “ and ”) ? [TypographyQuotes]\n" + + " <string name=\"show_all_apps2\">Show \"All\"</string>\n" + + " ^\n" + + "res/values/typography.xml:6: Warning: Replace straight quotes (\") with directional quotes (“â€, “ and ”) ? [TypographyQuotes]\n" + + " <string name=\"escaped\">Skip \\\"All\\\"</string>\n" + + " ^\n" + + "res/values/typography.xml:7: Warning: Replace apostrophe (') with typographic apostrophe (’, ’) ? [TypographyQuotes]\n" + + " <string name=\"single\">Android's</string>\n" + + " ^\n" + + "res/values/typography.xml:9: Warning: Replace apostrophe (') with typographic apostrophe (’, ’) ? [TypographyQuotes]\n" + + " <string name=\"badquotes1\">`First'</string>\n" + + " ^\n" + + "res/values/typography.xml:10: Warning: Avoid quoting with grave accents; use apostrophes or better yet directional quotes instead [TypographyQuotes]\n" + + " <string name=\"badquotes2\">``second''</string>\n" + + " ^\n" + + "res/values/typography.xml:11: Warning: Replace straight quotes ('') with directional quotes (‘’, ‘ and ’) ? [TypographyQuotes]\n" + + " <string name=\"notbadquotes\">Type Option-` then 'Escape'</string>\n" + + " ^\n" + + "res/values/typography.xml:8: Warning: Replace (c) with copyright symbol © (©) ? [TypographyOther]\n" + + " <string name=\"copyright\">(c) 2011</string>\n" + + " ^\n" + + "0 errors, 16 warnings\n" + + "", lintProject("res/values/typography.xml")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UnusedResourceDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UnusedResourceDetectorTest.java index bf32e2b..f57cf00 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UnusedResourceDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UnusedResourceDetectorTest.java @@ -43,10 +43,14 @@ public class UnusedResourceDetectorTest extends AbstractCheckTest { public void testUnused() throws Exception { mEnableIds = false; assertEquals( - "accessibility.xml: Warning: The resource R.layout.accessibility appears to be unused\n" + - "main.xml: Warning: The resource R.layout.main appears to be unused\n" + - "other.xml: Warning: The resource R.layout.other appears to be unused\n" + - "strings2.xml:3: Warning: The resource R.string.hello appears to be unused", + "res/layout/accessibility.xml: Warning: The resource R.layout.accessibility appears to be unused [UnusedResources]\n" + + "res/layout/main.xml: Warning: The resource R.layout.main appears to be unused [UnusedResources]\n" + + "res/layout/other.xml: Warning: The resource R.layout.other appears to be unused [UnusedResources]\n" + + "res/values/strings2.xml:3: Warning: The resource R.string.hello appears to be unused [UnusedResources]\n" + + " <string name=\"hello\">Hello</string>\n" + + " ~~~~~~~~~~~~\n" + + "0 errors, 4 warnings\n" + + "", lintProject( "res/values/strings2.xml", @@ -64,17 +68,27 @@ public class UnusedResourceDetectorTest extends AbstractCheckTest { mEnableIds = true; assertEquals( - "Warning: The resource R.id.imageView1 appears to be unused\n" + - "Warning: The resource R.id.include1 appears to be unused\n" + - "Warning: The resource R.id.linearLayout2 appears to be unused\n" + - "Warning: The resource R.layout.main appears to be unused\n" + - "Warning: The resource R.layout.other appears to be unused\n" + - "Warning: The resource R.string.hello appears to be unused\n" + - "accessibility.xml: Warning: The resource R.layout.accessibility appears to be unused\n" + - "accessibility.xml:2: Warning: The resource R.id.newlinear appears to be unused\n" + - "accessibility.xml:3: Warning: The resource R.id.button1 appears to be unused\n" + - "accessibility.xml:4: Warning: The resource R.id.android_logo appears to be unused\n" + - "accessibility.xml:5: Warning: The resource R.id.android_logo2 appears to be unused", + "res/layout/accessibility.xml: Warning: The resource R.layout.accessibility appears to be unused [UnusedResources]\n" + + "Warning: The resource R.layout.main appears to be unused [UnusedResources]\n" + + "Warning: The resource R.layout.other appears to be unused [UnusedResources]\n" + + "Warning: The resource R.string.hello appears to be unused [UnusedResources]\n" + + "Warning: The resource R.id.imageView1 appears to be unused [UnusedIds]\n" + + "Warning: The resource R.id.include1 appears to be unused [UnusedIds]\n" + + "Warning: The resource R.id.linearLayout2 appears to be unused [UnusedIds]\n" + + "res/layout/accessibility.xml:2: Warning: The resource R.id.newlinear appears to be unused [UnusedIds]\n" + + "<LinearLayout xmlns:android=\"http://schemas.android.com/apk/res/android\" android:id=\"@+id/newlinear\" android:orientation=\"vertical\" android:layout_width=\"match_parent\" android:layout_height=\"match_parent\">\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/accessibility.xml:3: Warning: The resource R.id.button1 appears to be unused [UnusedIds]\n" + + " <Button android:text=\"Button\" android:id=\"@+id/button1\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\"></Button>\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/accessibility.xml:4: Warning: The resource R.id.android_logo appears to be unused [UnusedIds]\n" + + " <ImageView android:id=\"@+id/android_logo\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\" android:src=\"@drawable/android_button\" android:focusable=\"false\" android:clickable=\"false\" android:layout_weight=\"1.0\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/accessibility.xml:5: Warning: The resource R.id.android_logo2 appears to be unused [UnusedIds]\n" + + " <ImageButton android:importantForAccessibility=\"yes\" android:id=\"@+id/android_logo2\" android:layout_width=\"wrap_content\" android:layout_height=\"wrap_content\" android:src=\"@drawable/android_button\" android:focusable=\"false\" android:clickable=\"false\" android:layout_weight=\"1.0\" />\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 11 warnings\n" + + "", lintProject( // Rename .txt files to .java @@ -86,7 +100,11 @@ public class UnusedResourceDetectorTest extends AbstractCheckTest { public void testArrayReference() throws Exception { assertEquals( - "arrayusage.xml:3: Warning: The resource R.array.my_array appears to be unused", + "res/values/arrayusage.xml:3: Warning: The resource R.array.my_array appears to be unused [UnusedResources]\n" + + "<string-array name=\"my_array\">\n" + + " ~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "AndroidManifest.xml", @@ -95,7 +113,9 @@ public class UnusedResourceDetectorTest extends AbstractCheckTest { public void testAttrs() throws Exception { assertEquals( - "customattrlayout.xml: Warning: The resource R.layout.customattrlayout appears to be unused", + "res/layout/customattrlayout.xml: Warning: The resource R.layout.customattrlayout appears to be unused [UnusedResources]\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "res/values/customattr.xml", @@ -140,7 +160,11 @@ public class UnusedResourceDetectorTest extends AbstractCheckTest { // string1 is defined and used in the library project // string2 is defined in the library project and used in the master project // string3 is defined in the library project and not used anywhere - "strings.xml:7: Warning: The resource R.string.string3 appears to be unused", + "/TESTROOT/UnusedResourceDetectorTest_testMultiProject/LibraryProject/res/values/strings.xml:7: Warning: The resource R.string.string3 appears to be unused [UnusedResources]\n" + + " <string name=\"string3\">String 3</string>\n" + + " ~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", checkLint(Arrays.asList(master, library))); } @@ -167,7 +191,11 @@ public class UnusedResourceDetectorTest extends AbstractCheckTest { public void testPlurals() throws Exception { assertEquals( - "plurals.xml:3: Warning: The resource R.plurals.my_plural appears to be unused", + "res/values/plurals.xml:3: Warning: The resource R.plurals.my_plural appears to be unused [UnusedResources]\n" + + " <plurals name=\"my_plural\">\n" + + " ~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "res/values/strings4.xml", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UseCompoundDrawableDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UseCompoundDrawableDetectorTest.java index 6b29043..146ff6f 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UseCompoundDrawableDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UseCompoundDrawableDetectorTest.java @@ -27,9 +27,12 @@ public class UseCompoundDrawableDetectorTest extends AbstractCheckTest { public void testCompound() throws Exception { assertEquals( - "compound.xml:3: Warning: This tag and its children can be replaced by one " + - "<TextView/> and a compound drawable", - lintFiles("res/layout/compound.xml")); + "res/layout/compound.xml:3: Warning: This tag and its children can be replaced by one <TextView/> and a compound drawable [UseCompoundDrawables]\n" + + "<LinearLayout\n" + + "^\n" + + "0 errors, 1 warnings\n" + + "", + lintFiles("res/layout/compound.xml")); } public void testCompound2() throws Exception { diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UselessViewDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UselessViewDetectorTest.java index 735b1c2..c34b987 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UselessViewDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/UselessViewDetectorTest.java @@ -27,14 +27,20 @@ public class UselessViewDetectorTest extends AbstractCheckTest { public void testUseless() throws Exception { assertEquals( - "useless.xml:13: Warning: This LinearLayout layout or its FrameLayout parent " + - "is useless\n" + - "useless.xml:47: Warning: This LinearLayout layout or its FrameLayout parent " + - "is useless; transfer the background attribute to the other view\n" + - "useless.xml:65: Warning: This LinearLayout layout or its FrameLayout parent " + - "is useless; transfer the background attribute to the other view\n" + - "useless.xml:85: Warning: This FrameLayout view is useless (no children, " + - "no background, no id, no style)", + "res/layout/useless.xml:85: Warning: This FrameLayout view is useless (no children, no background, no id, no style) [UselessLeaf]\n" + + " <FrameLayout\n" + + " ^\n" + + "res/layout/useless.xml:13: Warning: This LinearLayout layout or its FrameLayout parent is useless [UselessParent]\n" + + " <LinearLayout\n" + + " ^\n" + + "res/layout/useless.xml:47: Warning: This LinearLayout layout or its FrameLayout parent is useless; transfer the background attribute to the other view [UselessParent]\n" + + " <LinearLayout\n" + + " ^\n" + + "res/layout/useless.xml:65: Warning: This LinearLayout layout or its FrameLayout parent is useless; transfer the background attribute to the other view [UselessParent]\n" + + " <LinearLayout\n" + + " ^\n" + + "0 errors, 4 warnings\n" + + "", lintFiles("res/layout/useless.xml")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/Utf8DetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/Utf8DetectorTest.java index e21ffe4..d1a118d 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/Utf8DetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/Utf8DetectorTest.java @@ -27,15 +27,21 @@ public class Utf8DetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "encoding.xml:1: Warning: iso-latin-1: Not using UTF-8 as the file encoding. " + - "This can lead to subtle bugs with non-ascii characters", + "res/layout/encoding.xml:1: Warning: iso-latin-1: Not using UTF-8 as the file encoding. This can lead to subtle bugs with non-ascii characters [EnforceUTF8]\n" + + "<?xml version=\"1.0\" encoding=\"iso-latin-1\"?>\n" + + " ~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintProject("res/layout/encoding.xml")); } public void testWithR() throws Exception { assertEquals( - "encoding2.xml:1: Warning: iso-latin-1: Not using UTF-8 as the file encoding. " + - "This can lead to subtle bugs with non-ascii characters", + "res/layout/encoding2.xml:1: Warning: iso-latin-1: Not using UTF-8 as the file encoding. This can lead to subtle bugs with non-ascii characters [EnforceUTF8]\n" + + "<?xml version=\"1.0\" encoding=\"iso-latin-1\"?>\n" + + " ~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", // encoding2.xml = encoding.xml but with \n => \r lintProject("res/layout/encoding2.xml")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ViewConstructorDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ViewConstructorDetectorTest.java index dccb667..5517646 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ViewConstructorDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ViewConstructorDetectorTest.java @@ -27,13 +27,10 @@ public class ViewConstructorDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "CustomView1.java: Warning: Custom view test/pkg/CustomView1 is missing" + - " constructor used by tools: (Context) or (Context,AttributeSet) or " + - "(Context,AttributeSet,int)\n" + - - "CustomView2.java: Warning: Custom view test/pkg/CustomView2 is missing " + - "constructor used by tools: (Context) or (Context,AttributeSet) or " + - "(Context,AttributeSet,int)", + "src/test/bytecode/CustomView1.java: Warning: Custom view test/pkg/CustomView1 is missing constructor used by tools: (Context) or (Context,AttributeSet) or (Context,AttributeSet,int) [ViewConstructor]\n" + + "src/test/bytecode/CustomView2.java: Warning: Custom view test/pkg/CustomView2 is missing constructor used by tools: (Context) or (Context,AttributeSet) or (Context,AttributeSet,int) [ViewConstructor]\n" + + "0 errors, 2 warnings\n" + + "", lintProject( "bytecode/.classpath=>.classpath", @@ -49,9 +46,9 @@ public class ViewConstructorDetectorTest extends AbstractCheckTest { public void testInheritLocal() throws Exception { assertEquals( - "CustomViewTest.java: Warning: Custom view test/pkg/CustomViewTest is missing " + - "constructor used by tools: (Context) or (Context,AttributeSet) or " + - "(Context,AttributeSet,int)", + "src/test/pkg/CustomViewTest.java: Warning: Custom view test/pkg/CustomViewTest is missing constructor used by tools: (Context) or (Context,AttributeSet) or (Context,AttributeSet,int) [ViewConstructor]\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "bytecode/.classpath=>.classpath", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ViewTypeDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ViewTypeDetectorTest.java index 2ea876f..a200de0 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ViewTypeDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/ViewTypeDetectorTest.java @@ -27,7 +27,11 @@ public class ViewTypeDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "WrongCastActivity.java:13: Error: Unexpected cast to ToggleButton: layout tag was Button", + "src/test/pkg/WrongCastActivity.java:13: Error: Unexpected cast to ToggleButton: layout tag was Button [WrongViewCast]\n" + + " ToggleButton toggleButton = (ToggleButton) findViewById(R.id.button);\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "1 errors, 0 warnings\n" + + "", lintProject( "res/layout/casts.xml", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/WakelockDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/WakelockDetectorTest.java index 0b39eb6..e2830e0 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/WakelockDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/WakelockDetectorTest.java @@ -27,7 +27,11 @@ public class WakelockDetectorTest extends AbstractCheckTest { public void test1() throws Exception { assertEquals( - "WakelockActivity1.java:15: Warning: Found a wakelock acquire() but no release() calls anywhere", + "src/test/pkg/WakelockActivity1.java:15: Warning: Found a wakelock acquire() but no release() calls anywhere [Wakelock]\n" + + " mWakeLock.acquire(); // Never released\n" + + " ~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "bytecode/.classpath=>.classpath", @@ -40,7 +44,11 @@ public class WakelockDetectorTest extends AbstractCheckTest { public void test2() throws Exception { assertEquals( - "WakelockActivity2.java:13: Warning: Wakelocks should be released in onPause, not onDestroy", + "src/test/pkg/WakelockActivity2.java:13: Warning: Wakelocks should be released in onPause, not onDestroy [Wakelock]\n" + + " mWakeLock.release(); // Should be done in onPause instead\n" + + " ~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "bytecode/.classpath=>.classpath", @@ -53,7 +61,11 @@ public class WakelockDetectorTest extends AbstractCheckTest { public void test3() throws Exception { assertEquals( - "WakelockActivity3.java:13: Warning: The release() call is not always reached", + "src/test/pkg/WakelockActivity3.java:13: Warning: The release() call is not always reached [Wakelock]\n" + + " lock.release(); // Should be in finally block\n" + + " ~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "bytecode/.classpath=>.classpath", @@ -66,7 +78,11 @@ public class WakelockDetectorTest extends AbstractCheckTest { public void test4() throws Exception { assertEquals( - "WakelockActivity4.java:10: Warning: The release() call is not always reached", + "src/test/pkg/WakelockActivity4.java:10: Warning: The release() call is not always reached [Wakelock]\n" + + " getLock().release(); // Should be in finally block\n" + + " ~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "bytecode/.classpath=>.classpath", @@ -79,8 +95,11 @@ public class WakelockDetectorTest extends AbstractCheckTest { public void test5() throws Exception { assertEquals( - // Missing 13 - "WakelockActivity5.java:13: Warning: The release() call is not always reached", + "src/test/pkg/WakelockActivity5.java:13: Warning: The release() call is not always reached [Wakelock]\n" + + " lock.release(); // Should be in finally block\n" + + " ~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintProject( "bytecode/.classpath=>.classpath", @@ -93,9 +112,17 @@ public class WakelockDetectorTest extends AbstractCheckTest { public void test6() throws Exception { assertEquals( - "WakelockActivity6.java:19: Warning: The release() call is not always reached\n" + - "WakelockActivity6.java:28: Warning: The release() call is not always reached\n" + - "WakelockActivity6.java:65: Warning: The release() call is not always reached", + "src/test/pkg/WakelockActivity6.java:19: Warning: The release() call is not always reached [Wakelock]\n" + + " lock.release(); // Wrong\n" + + " ~~~~~~~\n" + + "src/test/pkg/WakelockActivity6.java:28: Warning: The release() call is not always reached [Wakelock]\n" + + " lock.release(); // Wrong\n" + + " ~~~~~~~\n" + + "src/test/pkg/WakelockActivity6.java:65: Warning: The release() call is not always reached [Wakelock]\n" + + " lock.release(); // Wrong\n" + + " ~~~~~~~\n" + + "0 errors, 3 warnings\n" + + "", lintProject( "bytecode/.classpath=>.classpath", diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/WrongIdDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/WrongIdDetectorTest.java index 5783bd1..15675ba 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/WrongIdDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/WrongIdDetectorTest.java @@ -27,10 +27,20 @@ public class WrongIdDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "layout1.xml:14: Error: The id \"button5\" is not defined anywhere. Did you mean one of {button1, button2, button3, button4} ?\n" + - "layout1.xml:15: Warning: The id \"my_id2\" is not referring to any views in this layout\n" + - "layout1.xml:17: Error: The id \"my_id3\" is not defined anywhere. Did you mean my_id2 ?\n" + - "layout1.xml:18: Error: The id \"my_id1\" is defined but not assigned to any views. Did you mean my_id2 ?", + "res/layout/layout1.xml:14: Error: The id \"button5\" is not defined anywhere. Did you mean one of {button1, button2, button3, button4} ? [UnknownId]\n" + + " android:layout_alignBottom=\"@+id/button5\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/layout1.xml:17: Error: The id \"my_id3\" is not defined anywhere. Did you mean my_id2 ? [UnknownId]\n" + + " android:layout_alignRight=\"@+id/my_id3\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/layout1.xml:18: Error: The id \"my_id1\" is defined but not assigned to any views. Did you mean my_id2 ? [UnknownId]\n" + + " android:layout_alignTop=\"@+id/my_id1\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/layout1.xml:15: Warning: The id \"my_id2\" is not referring to any views in this layout [UnknownIdInLayout]\n" + + " android:layout_alignLeft=\"@+id/my_id2\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "3 errors, 1 warnings\n" + + "", lintProject( "wrongid/layout1.xml=>res/layout/layout1.xml", @@ -41,10 +51,20 @@ public class WrongIdDetectorTest extends AbstractCheckTest { public void testSingleFile() throws Exception { assertEquals( - "layout1.xml:14: Warning: The id \"button5\" is not referring to any views in this layout\n" + - "layout1.xml:15: Warning: The id \"my_id2\" is not referring to any views in this layout\n" + - "layout1.xml:17: Warning: The id \"my_id3\" is not referring to any views in this layout\n" + - "layout1.xml:18: Warning: The id \"my_id1\" is not referring to any views in this layout", + "res/layout/layout1.xml:14: Warning: The id \"button5\" is not referring to any views in this layout [UnknownIdInLayout]\n" + + " android:layout_alignBottom=\"@+id/button5\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/layout1.xml:15: Warning: The id \"my_id2\" is not referring to any views in this layout [UnknownIdInLayout]\n" + + " android:layout_alignLeft=\"@+id/my_id2\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/layout1.xml:17: Warning: The id \"my_id3\" is not referring to any views in this layout [UnknownIdInLayout]\n" + + " android:layout_alignRight=\"@+id/my_id3\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "res/layout/layout1.xml:18: Warning: The id \"my_id1\" is not referring to any views in this layout [UnknownIdInLayout]\n" + + " android:layout_alignTop=\"@+id/my_id1\"\n" + + " ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" + + "0 errors, 4 warnings\n" + + "", lintFiles("wrongid/layout1.xml=>res/layout/layout1.xml")); } diff --git a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/WrongImportDetectorTest.java b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/WrongImportDetectorTest.java index 41415df..c44f204 100644 --- a/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/WrongImportDetectorTest.java +++ b/lint/libs/lint_checks/tests/src/com/android/tools/lint/checks/WrongImportDetectorTest.java @@ -27,7 +27,11 @@ public class WrongImportDetectorTest extends AbstractCheckTest { public void test() throws Exception { assertEquals( - "BadImport.java:5: Warning: Don't include android.R here; use a fully qualified name for each usage instead", + "src/test/pkg/BadImport.java:5: Warning: Don't include android.R here; use a fully qualified name for each usage instead [SuspiciousImport]\n" + + "import android.R;\n" + + "~~~~~~~~~~~~~~~~~\n" + + "0 errors, 1 warnings\n" + + "", lintProject( // Java files must be renamed in source tree |