Add test for field minification using obfuscation dictionary

Bug: 131382276
Change-Id: Icb79bcafdd4b012fccd7fdb66ed7c151b2a0906b
diff --git a/src/test/java/com/android/tools/r8/TestRunResult.java b/src/test/java/com/android/tools/r8/TestRunResult.java
index bc9a98e..edd1492 100644
--- a/src/test/java/com/android/tools/r8/TestRunResult.java
+++ b/src/test/java/com/android/tools/r8/TestRunResult.java
@@ -10,6 +10,7 @@
 
 import com.android.tools.r8.ToolHelper.ProcessResult;
 import com.android.tools.r8.utils.AndroidApp;
+import com.android.tools.r8.utils.StringUtils;
 import com.android.tools.r8.utils.codeinspector.CodeInspector;
 import java.io.IOException;
 import java.io.PrintStream;
@@ -83,6 +84,10 @@
     return self();
   }
 
+  public RR assertSuccessWithOutputLines(String... expected) {
+    return assertSuccessWithOutput(StringUtils.lines(expected));
+  }
+
   public RR assertSuccessWithOutputThatMatches(Matcher<String> matcher) {
     assertSuccess();
     assertThat(errorMessage("Run stdout incorrect.", matcher.toString()), result.stdout, matcher);
diff --git a/src/test/java/com/android/tools/r8/naming/FieldNamingObfuscationDictionaryTest.java b/src/test/java/com/android/tools/r8/naming/FieldNamingObfuscationDictionaryTest.java
new file mode 100644
index 0000000..4cfb22e
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/naming/FieldNamingObfuscationDictionaryTest.java
@@ -0,0 +1,114 @@
+// Copyright (c) 2019, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package com.android.tools.r8.naming;
+
+import static junit.framework.TestCase.assertEquals;
+
+import com.android.tools.r8.CompilationFailedException;
+import com.android.tools.r8.NeverInline;
+import com.android.tools.r8.TestBase;
+import com.android.tools.r8.TestParameters;
+import com.android.tools.r8.TestParametersCollection;
+import com.android.tools.r8.utils.FileUtils;
+import java.io.IOException;
+import java.nio.file.Path;
+import java.util.concurrent.ExecutionException;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+@RunWith(Parameterized.class)
+public class FieldNamingObfuscationDictionaryTest extends TestBase {
+
+  public static class A {
+
+    public String f1;
+
+    public A(String a) {
+      this.f1 = a;
+    }
+  }
+
+  public static class B extends A {
+
+    public int f0;
+    public String f2;
+
+    public B(int f0, String a, String b) {
+      super(a);
+      this.f0 = f0;
+      this.f2 = b;
+    }
+
+    @NeverInline
+    public void print() {
+      System.out.println(f0 + f1 + " " + f2);
+    }
+  }
+
+  public static class C extends A {
+
+    public int f0;
+    public String f3;
+
+    public C(int f0, String a, String c) {
+      super(a);
+      this.f0 = f0;
+      this.f3 = c;
+    }
+
+    @NeverInline
+    public void print() {
+      System.out.println(f0 + f1 + " " + f3);
+    }
+  }
+
+  public static class Runner {
+
+    public static void main(String[] args) {
+      new B(args.length, args[0], args[1]).print();
+      new C(args.length, args[0], args[1]).print();
+    }
+  }
+
+  private TestParameters parameters;
+
+  @Parameterized.Parameters(name = "{0}")
+  public static TestParametersCollection data() {
+    return getTestParameters().withAllRuntimes().build();
+  }
+
+  public FieldNamingObfuscationDictionaryTest(TestParameters parameters) {
+    this.parameters = parameters;
+  }
+
+  @Test
+  @Ignore("b/131382276")
+  public void testInheritedNamingState()
+      throws IOException, CompilationFailedException, ExecutionException {
+    Path dictionary = temp.getRoot().toPath().resolve("dictionary.txt");
+    FileUtils.writeTextFile(dictionary, "a", "b", "c");
+
+    testForR8(parameters.getBackend())
+        .addInnerClasses(FieldNamingObfuscationDictionaryTest.class)
+        .enableInliningAnnotations()
+        .addKeepRules("-overloadaggressively", "-obfuscationdictionary " + dictionary.toString())
+        .addKeepRules()
+        .addKeepMainRule(Runner.class)
+        .setMinApi(parameters.getRuntime())
+        .compile()
+        .run(parameters.getRuntime(), Runner.class, "HELLO", "WORLD")
+        .assertSuccessWithOutputLines("2HELLO WORLD", "2HELLO WORLD")
+        .inspect(
+            inspector -> {
+              assertEquals("a", inspector.clazz(A.class).uniqueFieldWithName("f1").getFinalName());
+              assertEquals("a", inspector.clazz(B.class).uniqueFieldWithName("f0").getFinalName());
+              assertEquals("b", inspector.clazz(B.class).uniqueFieldWithName("f2").getFinalName());
+              assertEquals("a", inspector.clazz(C.class).uniqueFieldWithName("f0").getFinalName());
+              assertEquals("b", inspector.clazz(C.class).uniqueFieldWithName("f3").getFinalName());
+            });
+  }
+}