summaryrefslogtreecommitdiff
path: root/errorprone/tests
diff options
context:
space:
mode:
authorSudheer Shanka <sudheersai@google.com>2020-08-01 01:44:00 +0000
committerSudheer Shanka <sudheersai@google.com>2020-08-05 04:30:04 +0000
commit945e3341f6e17bbafb3ae2c27d8071621955433b (patch)
tree97a8a241a1a4132dd8178387f1b247558bc6b425 /errorprone/tests
parent6a83916416cd7b9fcdda69f44abcad66c2e846d1 (diff)
Expand UidChecker to check new class initializations.
Bug: 162543841 Test: atest ./errorprone/tests/java/com/google/errorprone/bugpatterns/android/UidCheckerTest.java Change-Id: Id013a6416f687411567fa3d363c917106ab3608e
Diffstat (limited to 'errorprone/tests')
-rw-r--r--errorprone/tests/java/com/google/errorprone/bugpatterns/android/UidCheckerTest.java71
1 files changed, 69 insertions, 2 deletions
diff --git a/errorprone/tests/java/com/google/errorprone/bugpatterns/android/UidCheckerTest.java b/errorprone/tests/java/com/google/errorprone/bugpatterns/android/UidCheckerTest.java
index 74da94731092..75341fd1f317 100644
--- a/errorprone/tests/java/com/google/errorprone/bugpatterns/android/UidCheckerTest.java
+++ b/errorprone/tests/java/com/google/errorprone/bugpatterns/android/UidCheckerTest.java
@@ -34,7 +34,7 @@ public class UidCheckerTest {
}
@Test
- public void testTypical() {
+ public void testTypical_methodInvocation() {
compilationHelper
.addSourceLines("Example.java",
"public abstract class Example {",
@@ -57,7 +57,30 @@ public class UidCheckerTest {
}
@Test
- public void testCallingUid() {
+ public void testTypical_newClass() {
+ compilationHelper
+ .addSourceLines("Example.java",
+ "public abstract class Example {",
+ " class Bar { Bar(int pid, int uid, int userId) {} }",
+ " abstract int getUserId();",
+ " void foo(int pid, int uid, int userId, int unrelated) {",
+ " new Bar(0, 0, 0);",
+ " new Bar(pid, uid, userId);",
+ " new Bar(pid, uid, getUserId());",
+ " new Bar(unrelated, unrelated, unrelated);",
+ " // BUG: Diagnostic contains:",
+ " new Bar(uid, pid, userId);",
+ " // BUG: Diagnostic contains:",
+ " new Bar(pid, userId, uid);",
+ " // BUG: Diagnostic contains:",
+ " new Bar(getUserId(), 0, 0);",
+ " }",
+ "}")
+ .doTest();
+ }
+
+ @Test
+ public void testCallingUid_methodInvocation() {
compilationHelper
.addSourceFile("/android/os/Binder.java")
.addSourceFile("/android/os/UserHandle.java")
@@ -98,4 +121,48 @@ public class UidCheckerTest {
"}")
.doTest();
}
+
+
+ @Test
+ public void testCallingUid_newClass() {
+ compilationHelper
+ .addSourceFile("/android/os/Binder.java")
+ .addSourceFile("/android/os/UserHandle.java")
+ .addSourceLines("Example.java",
+ "import android.os.Binder;",
+ "import android.os.UserHandle;",
+ "public abstract class Example {",
+ " int callingUserId;",
+ " int callingUid;",
+ " class Foo { Foo(int callingUserId) {} }",
+ " class Bar { Bar(int callingUid) {} }",
+ " void doUserId(int callingUserId) {",
+ " new Foo(UserHandle.getUserId(Binder.getCallingUid()));",
+ " new Foo(this.callingUserId);",
+ " new Foo(callingUserId);",
+ " // BUG: Diagnostic contains:",
+ " new Foo(Binder.getCallingUid());",
+ " // BUG: Diagnostic contains:",
+ " new Foo(this.callingUid);",
+ " // BUG: Diagnostic contains:",
+ " new Foo(callingUid);",
+ " }",
+ " void doUid(int callingUserId) {",
+ " new Bar(Binder.getCallingUid());",
+ " new Bar(this.callingUid);",
+ " new Bar(callingUid);",
+ " // BUG: Diagnostic contains:",
+ " new Bar(UserHandle.getUserId(Binder.getCallingUid()));",
+ " // BUG: Diagnostic contains:",
+ " new Bar(this.callingUserId);",
+ " // BUG: Diagnostic contains:",
+ " new Bar(callingUserId);",
+ " }",
+ " void doInner() {",
+ " // BUG: Diagnostic contains:",
+ " new Foo(UserHandle.getUserId(callingUserId));",
+ " }",
+ "}")
+ .doTest();
+ }
}