1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 public class Main { 18 assertEquals(Object expected, Object actual)19 public static void assertEquals(Object expected, Object actual) { 20 if (expected != actual) { 21 throw new Error("Expected " + expected + ", got " + actual); 22 } 23 } 24 main(String[] args)25 public static void main(String[] args) { 26 // Tescase 1: a class with: 27 // - a package-private pkg1 'foo' 28 // - a public pkg2 'foo'. 29 { 30 pkg2.PublicFoo obj = new pkg2.PublicFoo(); 31 assertEquals(pkg1.Pkg1Foo.class, pkg1.Pkg1Foo.callFoo(obj)); 32 assertEquals(pkg2.PublicFoo.class, pkg2.Pkg2Foo.callFoo(obj)); 33 assertEquals(pkg2.PublicFoo.class, pkg3.Pkg3Foo.callFoo(obj)); 34 assertEquals(pkg2.PublicFoo.class, obj.foo()); 35 } 36 // Tescase 2: a class with: 37 // - a package-private pkg1 'foo' 38 // - a public pkg2 'foo' 39 // - a public pkg1 'foo. 40 { 41 pkg1.PublicFoo obj = new pkg1.PublicFoo(); 42 assertEquals(pkg1.PublicFoo.class, pkg1.Pkg1Foo.callFoo(obj)); 43 assertEquals(pkg1.PublicFoo.class, pkg2.Pkg2Foo.callFoo(obj)); 44 assertEquals(pkg1.PublicFoo.class, pkg3.Pkg3Foo.callFoo(obj)); 45 assertEquals(pkg1.PublicFoo.class, obj.foo()); 46 } 47 48 // Tescase 3: a class with: 49 // - a package-private pkg1 'foo' 50 // - a package-private pkg2 'foo' 51 // - a public pkg3 'foo. 52 { 53 pkg3.PublicFoo obj = new pkg3.PublicFoo(); 54 assertEquals(pkg1.Pkg1Foo.class, pkg1.Pkg1Foo.callFoo(obj)); 55 assertEquals(pkg2.Pkg2Foo.class, pkg2.Pkg2Foo.callFoo(obj)); 56 assertEquals(pkg3.PublicFoo.class, pkg3.Pkg3Foo.callFoo(obj)); 57 assertEquals(pkg3.PublicFoo.class, obj.foo()); 58 } 59 60 // Tescase 4: a class with: 61 // - a package-private pkg1 'foo' 62 // - a package-private pkg2 'foo' 63 // - a public pkg3 'foo. 64 // - a public pkg2 'foo' 65 { 66 pkg2.PublicFooInheritsPkg3 obj = new pkg2.PublicFooInheritsPkg3(); 67 assertEquals(pkg1.Pkg1Foo.class, pkg1.Pkg1Foo.callFoo(obj)); 68 assertEquals(pkg2.PublicFooInheritsPkg3.class, pkg2.Pkg2Foo.callFoo(obj)); 69 assertEquals(pkg2.PublicFooInheritsPkg3.class, pkg3.Pkg3Foo.callFoo(obj)); 70 assertEquals(pkg2.PublicFooInheritsPkg3.class, obj.foo()); 71 } 72 73 // Tescase 5: a class with: 74 // - a package-private pkg1 'foo' 75 // - a package-private pkg2 'foo' 76 // - a public pkg3 'foo. 77 // - a public pkg2 'foo' 78 // - a public pkg1 'foo' 79 { 80 pkg1.PublicFooInheritsPkg2 obj = new pkg1.PublicFooInheritsPkg2(); 81 assertEquals(pkg1.PublicFooInheritsPkg2.class, pkg1.Pkg1Foo.callFoo(obj)); 82 assertEquals(pkg1.PublicFooInheritsPkg2.class, pkg2.Pkg2Foo.callFoo(obj)); 83 assertEquals(pkg1.PublicFooInheritsPkg2.class, pkg3.Pkg3Foo.callFoo(obj)); 84 assertEquals(pkg1.PublicFooInheritsPkg2.class, obj.foo()); 85 } 86 87 // Tescase 6: a class with: 88 // - a package-private pkg1 'foo' 89 // - a package-private pkg2 'foo' 90 // - a public pkg1 'foo. 91 { 92 pkg1.LowerIndexImplementsFoo obj = new pkg1.LowerIndexImplementsFoo(); 93 assertEquals(pkg1.LowerIndexPublicFoo.class, pkg1.Pkg1Foo.callFoo(obj)); 94 assertEquals(pkg2.Pkg2Foo.class, pkg2.Pkg2Foo.callFoo(obj)); 95 assertEquals(pkg2.Pkg2Foo.class, pkg3.Pkg3Foo.callFoo(obj)); 96 assertEquals(pkg1.LowerIndexPublicFoo.class, obj.foo()); 97 } 98 } 99 } 100