Cleanup to_string() usage and use toString() instead

Bug: 35703683
Test: hidl_test_java passes

Change-Id: Ib62828e5fb1c18825974f247c64c1e4dc686b23a
diff --git a/test/java_test/hidl_test_java_native.cpp b/test/java_test/hidl_test_java_native.cpp
index adb928b..ca96d03 100644
--- a/test/java_test/hidl_test_java_native.cpp
+++ b/test/java_test/hidl_test_java_native.cpp
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 //#define LOG_NDEBUG 0
 #define LOG_TAG "hidl_test_java_native"
 
@@ -45,155 +61,6 @@
 
 using std::to_string;
 
-// TODO(b/35703683) : Modify all tests to use autogenerated toString() instead to the below methods
-
-static std::string to_string(const IBaz::Foo::Bar &bar);
-static std::string to_string(const IBaz::Foo &foo);
-static std::string to_string(const hidl_string &s);
-static std::string to_string(bool x);
-static std::string to_string(const IBase::StringMatrix5x3 &M);
-static std::string to_string(const IBase::StringMatrix3x5 &M);
-
-template<typename T, size_t SIZE>
-static std::string to_string(const hidl_array<T, SIZE> &array);
-
-template<size_t SIZE>
-static std::string to_string(const hidl_array<uint8_t, SIZE> &array);
-
-template<typename T>
-static std::string to_string(const hidl_vec<T> &vec) {
-    std::string out;
-    out = "[";
-    for (size_t i = 0; i < vec.size(); ++i) {
-        if (i > 0) {
-            out += ", ";
-        }
-        out += to_string(vec[i]);
-    }
-    out += "]";
-
-    return out;
-}
-
-template<typename T, size_t SIZE>
-static std::string to_string(const hidl_array<T, SIZE> &array) {
-    std::string out;
-    out = "[";
-    for (size_t i = 0; i < SIZE; ++i) {
-        if (i > 0) {
-            out += ", ";
-        }
-        out += to_string(array[i]);
-    }
-    out += "]";
-
-    return out;
-}
-
-template<size_t SIZE>
-static std::string to_string(const hidl_array<uint8_t, SIZE> &array) {
-    std::string out;
-    for (size_t i = 0; i < SIZE; ++i) {
-        if (i > 0) {
-            out += ":";
-        }
-
-        char tmp[3];
-        sprintf(tmp, "%02x", array[i]);
-
-        out += tmp;
-    }
-
-    return out;
-}
-
-template<typename T, size_t SIZE1, size_t SIZE2>
-static std::string to_string(const hidl_array<T, SIZE1, SIZE2> &array) {
-    std::string out;
-    out = "[";
-    for (size_t i = 0; i < SIZE1; ++i) {
-        if (i > 0) {
-            out += ", ";
-        }
-
-        out += "[";
-        for (size_t j = 0; j < SIZE2; ++j) {
-            if (j > 0) {
-                out += ", ";
-            }
-
-            out += to_string(array[i][j]);
-        }
-        out += "]";
-    }
-    out += "]";
-
-    return out;
-}
-
-static std::string to_string(bool x) {
-    return x ? "true" : "false";
-}
-
-static std::string to_string(const hidl_string &s) {
-    return std::string("'") + s.c_str() + "'";
-}
-
-static std::string to_string(const IBaz::Foo::Bar &bar) {
-    std::string out;
-    out = "Bar(";
-    out += "z = " + to_string(bar.z) + ", ";
-    out += "s = '" + std::string(bar.s.c_str()) + "'";
-    out += ")";
-
-    return out;
-}
-
-static std::string to_string(const IBaz::Foo &foo) {
-    std::string out;
-    out = "Foo(";
-    out += "x = " + to_string(foo.x) + ", ";
-    out += "y = " + to_string(foo.y) + ", ";
-    out += "aaa = " + to_string(foo.aaa);
-    out += ")";
-
-    return out;
-}
-
-static std::string to_string(const IBase::StringMatrix5x3 &M) {
-    return to_string(M.s);
-}
-
-static std::string to_string(const IBase::StringMatrix3x5 &M) {
-    return to_string(M.s);
-}
-
-static std::string VectorOfArray_to_string(const IBase::VectorOfArray &in) {
-    std::string out;
-    out += "VectorOfArray(";
-
-    for (size_t i = 0; i < in.addresses.size(); ++i) {
-        if (i > 0) {
-            out += ", ";
-        }
-
-        for (size_t j = 0; j < 6; ++j) {
-            if (j > 0) {
-                out += ":";
-            }
-
-            char tmp[3];
-            sprintf(tmp, "%02x", in.addresses[i][j]);
-
-            out += tmp;
-        }
-    }
-
-    out += ")";
-
-    return out;
-}
-
 static void usage(const char *me) {
     fprintf(stderr, "%s [-c]lient | [-s]erver\n", me);
 }
@@ -255,17 +122,8 @@
                     // Strings should have the same size as they did before
                     // marshaling. b/35038064
                     EXPECT_EQ(result.y.s.size(), foo.y.s.size());
-
-                    EXPECT_EQ(
-                        to_string(result),
-                        "Foo(x = 1, "
-                            "y = Bar(z = 2.500000, s = 'Hello, world'), "
-                            "aaa = [Bar(z = 1.000000, s = 'Hello, world 0'), "
-                                   "Bar(z = 1.010000, s = 'Hello, world 1'), "
-                                   "Bar(z = 1.020000, s = 'Hello, world 2'), "
-                                   "Bar(z = 1.030000, s = 'Hello, world 3'), "
-                                   "Bar(z = 1.040000, s = 'Hello, world 4')])");
-                }));
+                    EXPECT_EQ(foo, result);
+               }));
 }
 
 TEST_F(HidlTest, BazSomeMethodWithFooArraysTest) {
@@ -291,25 +149,16 @@
         foo[1].aaa[i].s = ("Alea iacta est: " + std::to_string(i)).c_str();
     }
 
+    hidl_array<IBaz::Foo, 2> fooExpectedOutput;
+    fooExpectedOutput[0] = foo[1];
+    fooExpectedOutput[1] = foo[0];
+
     EXPECT_OK(
             baz->someMethodWithFooArrays(
                 foo,
                 [&](const auto &result) {
-                    EXPECT_EQ(
-                        to_string(result),
-                        "[Foo(x = 2, "
-                             "y = Bar(z = -2.500000, s = 'Morituri te salutant'), "
-                             "aaa = [Bar(z = 2.000000, s = 'Alea iacta est: 0'), "
-                                    "Bar(z = 1.990000, s = 'Alea iacta est: 1'), "
-                                    "Bar(z = 1.980000, s = 'Alea iacta est: 2')]), "
-                        "Foo(x = 1, "
-                            "y = Bar(z = 2.500000, s = 'Hello, world'), "
-                            "aaa = [Bar(z = 1.000000, s = 'Hello, world 0'), "
-                                   "Bar(z = 1.010000, s = 'Hello, world 1'), "
-                                   "Bar(z = 1.020000, s = 'Hello, world 2'), "
-                                   "Bar(z = 1.030000, s = 'Hello, world 3'), "
-                                   "Bar(z = 1.040000, s = 'Hello, world 4')])]");
-                }));
+                    EXPECT_EQ(result, fooExpectedOutput);
+               }));
 }
 
 TEST_F(HidlTest, BazSomeMethodWithFooVectorsTest) {
@@ -336,35 +185,31 @@
         foo[1].aaa[i].s = ("Alea iacta est: " + std::to_string(i)).c_str();
     }
 
+    hidl_vec<IBaz::Foo> fooExpectedOutput;
+    fooExpectedOutput.resize(2);
+    fooExpectedOutput[0] = foo[1];
+    fooExpectedOutput[1] = foo[0];
+
     EXPECT_OK(
             baz->someMethodWithFooVectors(
                 foo,
                 [&](const auto &result) {
-                    EXPECT_EQ(
-                        to_string(result),
-                        "[Foo(x = 2, "
-                             "y = Bar(z = -2.500000, s = 'Morituri te salutant'), "
-                             "aaa = [Bar(z = 2.000000, s = 'Alea iacta est: 0'), "
-                                    "Bar(z = 1.990000, s = 'Alea iacta est: 1'), "
-                                    "Bar(z = 1.980000, s = 'Alea iacta est: 2')]), "
-                        "Foo(x = 1, "
-                            "y = Bar(z = 2.500000, s = 'Hello, world'), "
-                            "aaa = [Bar(z = 1.000000, s = 'Hello, world 0'), "
-                                   "Bar(z = 1.010000, s = 'Hello, world 1'), "
-                                   "Bar(z = 1.020000, s = 'Hello, world 2'), "
-                                   "Bar(z = 1.030000, s = 'Hello, world 3'), "
-                                   "Bar(z = 1.040000, s = 'Hello, world 4')])]");
+                    EXPECT_EQ(result, fooExpectedOutput);
                 }));
 }
 
 TEST_F(HidlTest, BazSomeMethodWithVectorOfArray) {
-    IBase::VectorOfArray in;
+    IBase::VectorOfArray in, expectedOut;
     in.addresses.resize(3);
+    expectedOut.addresses.resize(3);
 
     size_t k = 0;
-    for (size_t i = 0; i < in.addresses.size(); ++i) {
+    const size_t n = in.addresses.size();
+
+    for (size_t i = 0; i < n; ++i) {
         for (size_t j = 0; j < 6; ++j, ++k) {
             in.addresses[i][j] = k;
+            expectedOut.addresses[n - 1 - i][j] = k;
         }
     }
 
@@ -372,23 +217,21 @@
             baz->someMethodWithVectorOfArray(
                 in,
                 [&](const auto &out) {
-                    EXPECT_EQ(
-                        VectorOfArray_to_string(out),
-                        "VectorOfArray("
-                          "0c:0d:0e:0f:10:11, "
-                          "06:07:08:09:0a:0b, "
-                          "00:01:02:03:04:05)");
+                    EXPECT_EQ(expectedOut, out);
                 }));
 }
 
 TEST_F(HidlTest, BazSomeMethodTakingAVectorOfArray) {
-    hidl_vec<hidl_array<uint8_t, 6> > in;
+    hidl_vec<hidl_array<uint8_t, 6> > in, expectedOut;
     in.resize(3);
+    expectedOut.resize(3);
 
     size_t k = 0;
-    for (size_t i = 0; i < in.size(); ++i) {
+    const size_t n = in.size();
+    for (size_t i = 0; i < n; ++i) {
         for (size_t j = 0; j < 6; ++j, ++k) {
             in[i][j] = k;
+            expectedOut[n - 1 - i][j] = k;
         }
     }
 
@@ -396,9 +239,7 @@
             baz->someMethodTakingAVectorOfArray(
                 in,
                 [&](const auto &out) {
-                    EXPECT_EQ(
-                        to_string(out),
-                        "[0c:0d:0e:0f:10:11, 06:07:08:09:0a:0b, 00:01:02:03:04:05]");
+                    EXPECT_EQ(expectedOut, out);
                 }));
 }
 
@@ -450,48 +291,42 @@
 
 TEST_F(HidlTest, BazTransposeTest) {
     IBase::StringMatrix5x3 in;
+    IBase::StringMatrix3x5 expectedOut;
 
     for (int i = 0; i < 5; ++i) {
         for (int j = 0; j < 3; ++j) {
-            in.s[i][j] = numberToEnglish(3 * i + j + 1).c_str();
+            in.s[i][j] = expectedOut.s[j][i] = numberToEnglish(3 * i + j + 1).c_str();
         }
     }
 
     EXPECT_OK(baz->transpose(
                 in,
                 [&](const auto &out) {
-                    EXPECT_EQ(
-                        to_string(out),
-                        "[['one', 'four', 'seven', 'ten', 'thirteen'], "
-                         "['two', 'five', 'eight', 'eleven', 'fourteen'], "
-                         "['three', 'six', 'nine', 'twelve', 'fifteen']]");
+                    EXPECT_EQ(expectedOut, out);
                 }));
 }
 
 TEST_F(HidlTest, BazTranspose2Test) {
     hidl_array<hidl_string, 5, 3> in;
+    hidl_array<hidl_string, 3, 5> expectedOut;
 
     for (int i = 0; i < 5; ++i) {
         for (int j = 0; j < 3; ++j) {
-            in[i][j] = numberToEnglish(3 * i + j + 1).c_str();
+            in[i][j] = expectedOut[j][i] = numberToEnglish(3 * i + j + 1).c_str();
         }
     }
 
     EXPECT_OK(baz->transpose2(
                 in,
                 [&](const auto &out) {
-                    EXPECT_EQ(
-                        to_string(out),
-                        "[['one', 'four', 'seven', 'ten', 'thirteen'], "
-                         "['two', 'five', 'eight', 'eleven', 'fourteen'], "
-                         "['three', 'six', 'nine', 'twelve', 'fifteen']]");
+                    EXPECT_EQ(expectedOut, out);
                 }));
 }
 
 TEST_F(HidlTest, BazSomeBoolMethodTest) {
     auto result = baz->someBoolMethod(true);
     EXPECT_OK(result);
-    EXPECT_EQ(to_string(result), "false");
+    EXPECT_EQ(result, false);
 }
 
 TEST_F(HidlTest, BazSomeBoolArrayMethodTest) {
@@ -500,29 +335,35 @@
     someBoolArray[1] = false;
     someBoolArray[2] = true;
 
+    hidl_array<bool, 4> expectedOut;
+    expectedOut[0] = false;
+    expectedOut[1] = true;
+    expectedOut[2] = false;
+    expectedOut[3] = true;
+
     EXPECT_OK(
             baz->someBoolArrayMethod(
                 someBoolArray,
                 [&](const auto &result) {
-                    EXPECT_EQ(
-                        to_string(result),
-                        "[false, true, false, true]");
+                    EXPECT_EQ(expectedOut, result);
                 }));
 }
 
 TEST_F(HidlTest, BazSomeBoolVectorMethodTest) {
-    hidl_vec<bool> someBoolVector;
+    hidl_vec<bool> someBoolVector, expected;
     someBoolVector.resize(4);
+    expected.resize(4);
+
     for (size_t i = 0; i < someBoolVector.size(); ++i) {
         someBoolVector[i] = ((i & 1) == 0);
+        expected[i] = !someBoolVector[i];
     }
 
     EXPECT_OK(
             baz->someBoolVectorMethod(
                 someBoolVector,
                 [&](const auto &result) {
-                    EXPECT_EQ(
-                        to_string(result), "[false, true, false, true]");
+                    EXPECT_EQ(expected, result);
                 }));
 }
 
@@ -533,57 +374,60 @@
 TEST_F(HidlTest, BazDoThatAndReturnSomethingMethodTest) {
     auto result = baz->doThatAndReturnSomething(1);
     EXPECT_OK(result);
-    EXPECT_EQ(to_string(result), "666");
+    EXPECT_EQ(result, 666);
 }
 
 TEST_F(HidlTest, BazDoQuiteABitMethodTest) {
     auto result = baz->doQuiteABit(1, 2ll, 3.0f, 4.0);
 
     EXPECT_OK(result);
-    EXPECT_EQ(to_string(result), "666.500000");
+    EXPECT_EQ(result, 666.5);
 }
 
 TEST_F(HidlTest, BazDoSomethingElseMethodTest) {
     hidl_array<int32_t, 15> param;
+    hidl_array<int32_t, 32> expected;
+
     for (size_t i = 0; i < 15; ++i) {
-        param[i] = i;
+        param[i] = expected[15 + i] = i;
+        expected[i] = 2 * i;
     }
 
+    expected[30] = 1;
+    expected[31] = 2;
+
     EXPECT_OK(
             baz->doSomethingElse(
                 param,
                 [&](const auto &result) {
-                    EXPECT_EQ(
-                        to_string(result),
-                        "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, "
-                        "28, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, "
-                        "1, 2]");
+                    EXPECT_EQ(expected, result);
                 }));
 }
 
 TEST_F(HidlTest, BazDoStuffAndReturnAStringMethodTest) {
+    std::string expected = "Hello, world!";
     EXPECT_OK(
             baz->doStuffAndReturnAString(
                 [&](const auto &result) {
-                    EXPECT_EQ(to_string(result), "'Hello, world!'");
+                    EXPECT_EQ(expected, result);
                 }));
 }
 
 TEST_F(HidlTest, BazMapThisVectorMethodTest) {
-    hidl_vec<int32_t> vec_param;
+    hidl_vec<int32_t> vec_param, expected;
     vec_param.resize(15);
+    expected.resize(15);
+
     for (size_t i = 0; i < 15; ++i) {
         vec_param[i] = i;
+        expected[i] = 2 * i;
     }
 
     EXPECT_OK(
             baz->mapThisVector(
                 vec_param,
                 [&](const auto &result) {
-                    EXPECT_EQ(
-                        to_string(result),
-                        "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, "
-                        "28]");
+                    EXPECT_EQ(expected, result);
                 }));
 }
 
@@ -609,37 +453,40 @@
     string_params[1] = "two";
     string_params[2] = "three";
 
+    hidl_array<hidl_string, 2> expected;
+    expected[0] = "Hello";
+    expected[1] = "World";
+
     EXPECT_OK(
             baz->haveSomeStrings(
                 string_params,
                 [&](const auto &result) {
-                    EXPECT_EQ(to_string(result), "['Hello', 'World']");
+                    EXPECT_EQ(expected, result);
                 }));
 }
 
 TEST_F(HidlTest, BazHaveAStringVecMethodTest) {
-    hidl_vec<hidl_string> string_vec;
-    string_vec.resize(4);
-    string_vec[0] = "Uno";
-    string_vec[1] = "Dos";
-    string_vec[2] = "Tres";
-    string_vec[3] = "Cuatro";
+    hidl_vec<hidl_string> string_vec{ "Uno", "Dos", "Tres", "Cuatro" };
+    hidl_vec<hidl_string> expected{"Hello", "World"};
 
     EXPECT_OK(
             baz->haveAStringVec(
                 string_vec,
                 [&](const auto &result) {
-                    EXPECT_EQ(to_string(result), "['Hello', 'World']");
+                    EXPECT_EQ(expected, result);
                 }));
 }
 
 TEST_F(HidlTest, BazReturnABunchOfStringsMethodTest) {
+    std::string expectedA = "Eins";
+    std::string expectedB = "Zwei";
+    std::string expectedC = "Drei";
     EXPECT_OK(
             baz->returnABunchOfStrings(
                 [&](const auto &a, const auto &b, const auto &c) {
-                    EXPECT_EQ(
-                        to_string(a) + ", " + to_string(b) + ", " + to_string(c),
-                        "'Eins', 'Zwei', 'Drei'");
+                    EXPECT_EQ(a, expectedA);
+                    EXPECT_EQ(b, expectedB);
+                    EXPECT_EQ(c, expectedC);
                 }));
 }
 
diff --git a/test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java b/test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java
index dbdbb04..c7b5951 100644
--- a/test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java
+++ b/test/java_test/src/com/android/commands/hidl_test_java/HidlTestJava.java
@@ -53,273 +53,6 @@
         return 0;
     }
 
-    public static String toString(IBase.Foo.Bar bar) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("Bar(");
-        builder.append("z = ");
-        builder.append(bar.z);
-        builder.append(", ");
-        builder.append("s = ");
-        builder.append(toString(bar.s));
-        builder.append(")");
-
-        return builder.toString();
-    }
-
-    public static String toString(IBase.Foo foo) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("Foo(");
-        builder.append("x = ");
-        builder.append(foo.x);
-        builder.append(", ");
-        builder.append("y = ");
-        builder.append(toString(foo.y));
-        builder.append(", ");
-        builder.append("aaa = ");
-        builder.append(toString(foo.aaa));
-        builder.append(")");
-
-        return builder.toString();
-    }
-
-    public static String toString(ArrayList<IBase.Foo.Bar> vec) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("[");
-        for (int i = 0; i < vec.size(); ++i) {
-            if (i > 0) {
-                builder.append(", ");
-            }
-            builder.append(toString(vec.get(i)));
-        }
-        builder.append("]");
-
-        return builder.toString();
-    }
-
-    public static String fooVecToString(ArrayList<IBase.Foo> vec) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("[");
-        for (int i = 0; i < vec.size(); ++i) {
-            if (i > 0) {
-                builder.append(", ");
-            }
-            builder.append(toString(vec.get(i)));
-        }
-        builder.append("]");
-
-        return builder.toString();
-    }
-
-    public static String macAddressVecToString(ArrayList<byte[]> vec) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("[");
-        for (int i = 0; i < vec.size(); ++i) {
-            if (i > 0) {
-                builder.append(", ");
-            }
-            builder.append(toString(vec.get(i)));
-        }
-        builder.append("]");
-
-        return builder.toString();
-    }
-
-    public static String booleanVecToString(ArrayList<Boolean> vec) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("[");
-        for (int i = 0; i < vec.size(); ++i) {
-            if (i > 0) {
-                builder.append(", ");
-            }
-            builder.append(toString(vec.get(i)));
-        }
-        builder.append("]");
-
-        return builder.toString();
-    }
-
-    public static String integerVecToString(ArrayList<Integer> vec) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("[");
-        for (int i = 0; i < vec.size(); ++i) {
-            if (i > 0) {
-                builder.append(", ");
-            }
-            builder.append(toString(vec.get(i)));
-        }
-        builder.append("]");
-
-        return builder.toString();
-    }
-
-    public static String stringVecToString(ArrayList<String> vec) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("[");
-        for (int i = 0; i < vec.size(); ++i) {
-            if (i > 0) {
-                builder.append(", ");
-            }
-            builder.append(toString(vec.get(i)));
-        }
-        builder.append("]");
-
-        return builder.toString();
-    }
-
-    public static String toString(IBase.Foo[] array) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("[");
-        for (int i = 0; i < array.length; ++i) {
-            if (i > 0) {
-                builder.append(", ");
-            }
-            builder.append(toString(array[i]));
-        }
-        builder.append("]");
-
-        return builder.toString();
-    }
-
-    public static String toString(IBase.Foo.Bar[] array) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("[");
-        for (int i = 0; i < array.length; ++i) {
-            if (i > 0) {
-                builder.append(", ");
-            }
-            builder.append(toString(array[i]));
-        }
-        builder.append("]");
-
-        return builder.toString();
-    }
-
-    public static String toString(int[] val) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("[");
-        for (int i = 0; i < val.length; ++i) {
-            if (i > 0) {
-                builder.append(", ");
-            }
-            builder.append(val[i]);
-        }
-        builder.append("]");
-
-        return builder.toString();
-    }
-
-    public static String toString(boolean[] val) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("[");
-        for (int i = 0; i < val.length; ++i) {
-            if (i > 0) {
-                builder.append(", ");
-            }
-            builder.append(val[i] ? "true" : "false");
-        }
-        builder.append("]");
-
-        return builder.toString();
-    }
-
-    public static String toString(String[] val) {
-        StringBuilder builder = new StringBuilder();
-        builder.append("[");
-        for (int i = 0; i < val.length; ++i) {
-            if (i > 0) {
-                builder.append(", ");
-            }
-            builder.append(toString(val[i]));
-        }
-        builder.append("]");
-
-        return builder.toString();
-    }
-
-    public static String toString(byte[] val) {
-        StringBuilder builder = new StringBuilder();
-        for (int i = 0; i < val.length; ++i) {
-            if (i > 0) {
-                builder.append(":");
-            }
-
-            byte b = val[i];
-            if (b < 16) {
-                builder.append("0");
-            }
-            builder.append(Integer.toHexString(b));
-        }
-
-        return builder.toString();
-    }
-
-    public static String toString(boolean x) {
-        return x ? "true" : "false";
-    }
-
-    public static String toString(int x) {
-        return Integer.toString(x);
-    }
-
-    public static String toString(double x) {
-        return Double.toString(x);
-    }
-
-    public static String toString(String s) {
-        return "'" + s + "'";
-    }
-
-    public static String toString(String[][] M) {
-        StringBuilder builder = new StringBuilder();
-
-        builder.append("[");
-        for (int i = 0; i < M.length; ++i) {
-            if (i > 0) {
-                builder.append(", ");
-            }
-            builder.append(toString(M[i]));
-        }
-        builder.append("]");
-
-        return builder.toString();
-    }
-
-    public static String toString(IBase.StringMatrix5x3 M) {
-        return toString(M.s);
-    }
-
-    public static String toString(IBase.StringMatrix3x5 M) {
-        return toString(M.s);
-    }
-
-    public static String toString(IBase.VectorOfArray vec) {
-        StringBuilder out = new StringBuilder();
-
-        out.append("VectorOfArray(");
-        for (int i = 0; i < vec.addresses.size(); ++i) {
-            if (i > 0) {
-                out.append(", ");
-            }
-
-            byte[] address = vec.addresses.get(i);
-
-            for (int j = 0; j < 6; ++j) {
-                if (j > 0) {
-                    out.append(":");
-                }
-
-                byte b = address[j];
-                if (b < 16) {
-                    out.append("0");
-                }
-                out.append(Integer.toHexString(b));
-            }
-        }
-
-        out.append(")");
-        return out.toString();
-    }
-
     final class HidlDeathRecipient implements HwBinder.DeathRecipient {
         final Object mLock = new Object();
         boolean mCalled = false;
@@ -470,15 +203,7 @@
             foo.y.s = "Lorem ipsum...";
 
             IBase.Foo result = proxy.someOtherBaseMethod(foo);
-
-            Expect(toString(result),
-                   "Foo(x = 1, " +
-                       "y = Bar(z = 3.14, s = 'Lorem ipsum...'), " +
-                       "aaa = [Bar(z = 1.0, s = 'Hello, world 0'), " +
-                              "Bar(z = 1.01, s = 'Hello, world 1'), " +
-                              "Bar(z = 1.02, s = 'Hello, world 2'), " +
-                              "Bar(z = 1.03, s = 'Hello, world 3'), " +
-                              "Bar(z = 1.04, s = 'Hello, world 4')])");
+            ExpectTrue(result.equals(foo));
         }
 
         {
@@ -514,21 +239,13 @@
 
             inputArray[1] = foo;
 
+            IBase.Foo[] expectedOutputArray = new IBase.Foo[2];
+            expectedOutputArray[0] = inputArray[1];
+            expectedOutputArray[1] = inputArray[0];
+
             IBase.Foo[] outputArray = proxy.someMethodWithFooArrays(inputArray);
 
-            Expect(toString(outputArray),
-                   "[Foo(x = 2, " +
-                        "y = Bar(z = 1.1414, s = 'Et tu brute?'), " +
-                        "aaa = [Bar(z = 2.0, s = 'Lorem ipsum 0'), " +
-                               "Bar(z = 1.99, s = 'Lorem ipsum 1'), " +
-                               "Bar(z = 1.98, s = 'Lorem ipsum 2')]), " +
-                     "Foo(x = 1, " +
-                         "y = Bar(z = 3.14, s = 'Lorem ipsum...'), " +
-                         "aaa = [Bar(z = 1.0, s = 'Hello, world 0'), " +
-                                "Bar(z = 1.01, s = 'Hello, world 1'), " +
-                                "Bar(z = 1.02, s = 'Hello, world 2'), " +
-                                "Bar(z = 1.03, s = 'Hello, world 3'), " +
-                                "Bar(z = 1.04, s = 'Hello, world 4')])]");
+            ExpectTrue(java.util.Objects.deepEquals(outputArray, expectedOutputArray));
         }
 
         {
@@ -564,22 +281,14 @@
 
             inputVec.add(foo);
 
+            ArrayList<IBase.Foo> expectedOutputVec = new ArrayList<IBase.Foo>();
+            expectedOutputVec.add(inputVec.get(1));
+            expectedOutputVec.add(inputVec.get(0));
+
             ArrayList<IBase.Foo> outputVec =
                 proxy.someMethodWithFooVectors(inputVec);
 
-            Expect(fooVecToString(outputVec),
-                   "[Foo(x = 2, " +
-                        "y = Bar(z = 1.1414, s = 'Et tu brute?'), " +
-                        "aaa = [Bar(z = 2.0, s = 'Lorem ipsum 0'), " +
-                               "Bar(z = 1.99, s = 'Lorem ipsum 1'), " +
-                               "Bar(z = 1.98, s = 'Lorem ipsum 2')]), " +
-                     "Foo(x = 1, " +
-                         "y = Bar(z = 3.14, s = 'Lorem ipsum...'), " +
-                         "aaa = [Bar(z = 1.0, s = 'Hello, world 0'), " +
-                                "Bar(z = 1.01, s = 'Hello, world 1'), " +
-                                "Bar(z = 1.02, s = 'Hello, world 2'), " +
-                                "Bar(z = 1.03, s = 'Hello, world 3'), " +
-                                "Bar(z = 1.04, s = 'Hello, world 4')])]");
+            ExpectTrue(java.util.Objects.deepEquals(outputVec, expectedOutputVec));
         }
 
         {
@@ -595,13 +304,21 @@
                 in.addresses.add(mac);
             }
 
-            IBase.VectorOfArray out = proxy.someMethodWithVectorOfArray(in);
+            IBase.VectorOfArray expectedOut = new IBase.VectorOfArray();
+            int n = in.addresses.size();
 
-            Expect(toString(out),
-                   "VectorOfArray("
-                     + "0c:0d:0e:0f:10:11, "
-                     + "06:07:08:09:0a:0b, "
-                     + "00:01:02:03:04:05)");
+            for (int i = 0; i < n; ++i) {
+                expectedOut.addresses.add(in.addresses.get(n - 1 - i));
+            }
+
+            IBase.VectorOfArray out = proxy.someMethodWithVectorOfArray(in);
+            /*
+             * TODO(b/36454147) Switch to .equals once the bug is fixed.
+             */
+            ExpectTrue(expectedOut.addresses.size() == out.addresses.size());
+            for  (int i = 0; i < n; ++i) {
+                ExpectTrue(java.util.Objects.deepEquals(out.addresses.get(i), expectedOut.addresses.get(i)));
+            }
         }
 
         {
@@ -617,17 +334,29 @@
                 in.add(mac);
             }
 
+            ArrayList<byte[]> expectedOut = new ArrayList<byte[]>();
+
+            int n = in.size();
+            for (int i = 0; i < n; ++i) {
+                expectedOut.add(in.get(n - 1 - i));
+            }
+
             ArrayList<byte[]> out = proxy.someMethodTakingAVectorOfArray(in);
 
-            Expect(macAddressVecToString(out),
-                   "[0c:0d:0e:0f:10:11, 06:07:08:09:0a:0b, 00:01:02:03:04:05]");
+            ExpectTrue(out.size() == expectedOut.size());
+            for  (int i = 0; i < n; ++i) {
+                ExpectTrue(java.util.Objects.deepEquals(out.get(i), expectedOut.get(i)));
+            }
         }
 
         {
             IBase.StringMatrix5x3 in = new IBase.StringMatrix5x3();
+            IBase.StringMatrix3x5 expectedOut = new IBase.StringMatrix3x5();
+
             for (int i = 0; i < 5; ++i) {
                 for (int j = 0; j < 3; ++j) {
                     in.s[i][j] = numberToEnglish(3 * i + j + 1);
+                    expectedOut.s[j][i] = in.s[i][j];
                 }
             }
 
@@ -635,17 +364,16 @@
 
             // [[1 2 3] [4 5 6] [7 8 9] [10 11 12] [13 14 15]]^T
             // = [[1 4 7 10 13] [2 5 8 11 14] [3 6 9 12 15]]
-            Expect(toString(out),
-                   "[['one', 'four', 'seven', 'ten', 'thirteen'], "
-                   +"['two', 'five', 'eight', 'eleven', 'fourteen'], "
-                   +"['three', 'six', 'nine', 'twelve', 'fifteen']]");
+            ExpectTrue(out.equals(expectedOut));
         }
 
         {
             String[][] in = new String[5][3];
+            String[][] expectedOut = new String[3][5];
             for (int i = 0; i < 5; ++i) {
                 for (int j = 0; j < 3; ++j) {
                     in[i][j] = numberToEnglish(3 * i + j + 1);
+                    expectedOut[j][i] = in[i][j];
                 }
             }
 
@@ -653,13 +381,10 @@
 
             // [[1 2 3] [4 5 6] [7 8 9] [10 11 12] [13 14 15]]^T
             // = [[1 4 7 10 13] [2 5 8 11 14] [3 6 9 12 15]]
-            Expect(toString(out),
-                   "[['one', 'four', 'seven', 'ten', 'thirteen'], "
-                   +"['two', 'five', 'eight', 'eleven', 'fourteen'], "
-                   +"['three', 'six', 'nine', 'twelve', 'fifteen']]");
+            ExpectTrue(java.util.Arrays.deepEquals(out, expectedOut));
         }
 
-        Expect(toString(proxy.someBoolMethod(true)), "false");
+        ExpectTrue(proxy.someBoolMethod(true) == false);
 
         {
             boolean[] someBoolArray = new boolean[3];
@@ -667,47 +392,63 @@
             someBoolArray[1] = false;
             someBoolArray[2] = true;
 
-            Expect(toString(proxy.someBoolArrayMethod(someBoolArray)),
-                   "[false, true, false, true]");
+            boolean[] resultArray = proxy.someBoolArrayMethod(someBoolArray);
+            ExpectTrue(resultArray[0] == false);
+            ExpectTrue(resultArray[1] == true);
+            ExpectTrue(resultArray[2] == false);
 
             ArrayList<Boolean> someBoolVec = new ArrayList<Boolean>();
             someBoolVec.add(true);
             someBoolVec.add(false);
             someBoolVec.add(true);
 
-            Expect(booleanVecToString(proxy.someBoolVectorMethod(someBoolVec)),
-                   "[false, true, false]");
+            ArrayList<Boolean> resultVec = proxy.someBoolVectorMethod(someBoolVec);
+            ExpectTrue(resultVec.get(0) == false);
+            ExpectTrue(resultVec.get(1) == true);
+            ExpectTrue(resultVec.get(2) == false);
         }
 
         proxy.doThis(1.0f);
 
-        Expect(toString(proxy.doThatAndReturnSomething(1)), "666");
-        Expect(toString(proxy.doQuiteABit(1, 2L, 3.0f, 4.0)), "666.5");
+        ExpectTrue(proxy.doThatAndReturnSomething(1) == 666);
+        ExpectTrue(proxy.doQuiteABit(1, 2L, 3.0f, 4.0) == 666.5);
 
         {
             int[] paramArray = new int[15];
+            int[] expectedOutArray = new int[32];
             ArrayList<Integer> paramVec = new ArrayList<Integer>();
+            ArrayList<Integer> expectedOutVec = new ArrayList<Integer>();
+
             for (int i = 0; i < paramArray.length; ++i) {
                 paramArray[i] = i;
                 paramVec.add(i);
+
+                expectedOutArray[i] = 2 * i;
+                expectedOutArray[15 + i] = i;
+
+                expectedOutVec.add(2 * i);
             }
 
-            Expect(toString(proxy.doSomethingElse(paramArray)),
-                   "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, " +
-                   "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1, 2]");
+            expectedOutArray[30] = 1;
+            expectedOutArray[31] = 2;
 
-            Expect(integerVecToString(proxy.mapThisVector(paramVec)),
-                   "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]");
+
+            int[] outArray = proxy.doSomethingElse(paramArray);
+            ExpectTrue(java.util.Objects.deepEquals(outArray, expectedOutArray));
+
+            ArrayList<Integer> outVec = proxy.mapThisVector(paramVec);
+            java.util.Objects.equals(outVec, expectedOutVec);
+
         }
 
-        Expect(toString(proxy.doStuffAndReturnAString()), "'Hello, world!'");
+        Expect(proxy.doStuffAndReturnAString(), "Hello, world!");
 
         BazCallback cb = new BazCallback();
         ExpectTrue(!cb.wasCalled());
         proxy.callMe(cb);
         ExpectTrue(cb.wasCalled());
 
-        Expect(toString(proxy.useAnEnum(IBaz.SomeEnum.goober)), "-64");
+        ExpectTrue(proxy.useAnEnum(IBaz.SomeEnum.goober) == -64);
 
         {
             String[] stringArray = new String[3];
@@ -715,16 +456,23 @@
             stringArray[1] = "two";
             stringArray[2] = "three";
 
-            Expect(toString(proxy.haveSomeStrings(stringArray)),
-                   "['Hello', 'World']");
+            String[] expectedOutArray = new String[2];
+            expectedOutArray[0] = "Hello";
+            expectedOutArray[1] = "World";
+
+            String[] outArray = proxy.haveSomeStrings(stringArray);
+            ExpectTrue(java.util.Arrays.deepEquals(outArray, expectedOutArray));
 
             ArrayList<String> stringVec = new ArrayList<String>();
             stringVec.add("one");
             stringVec.add("two");
             stringVec.add("three");
 
-            Expect(stringVecToString(proxy.haveAStringVec(stringVec)),
-                   "['Hello', 'World']");
+            ArrayList<String> expectedOutVec = new ArrayList<String>();
+            expectedOutVec.add("Hello");
+            expectedOutVec.add("World");
+
+            ExpectTrue(expectedOutVec.equals(proxy.haveAStringVec(stringVec)));
         }
 
         proxy.returnABunchOfStrings(
@@ -839,12 +587,12 @@
         }
 
         public IBase.Foo someOtherBaseMethod(IBase.Foo foo) {
-            Log.d(TAG, "Baz someOtherBaseMethod " + HidlTestJava.toString(foo));
+            Log.d(TAG, "Baz someOtherBaseMethod " + foo.toString());
             return foo;
         }
 
         public IBase.Foo[] someMethodWithFooArrays(IBase.Foo[] fooInput) {
-            Log.d(TAG, "Baz someMethodWithFooArrays " + HidlTestJava.toString(fooInput));
+            Log.d(TAG, "Baz someMethodWithFooArrays " + fooInput.toString());
 
             IBase.Foo[] fooOutput = new IBase.Foo[2];
             fooOutput[0] = fooInput[1];
@@ -855,7 +603,7 @@
 
         public ArrayList<IBase.Foo> someMethodWithFooVectors(
                 ArrayList<IBase.Foo> fooInput) {
-            Log.d(TAG, "Baz someMethodWithFooVectors " + HidlTestJava.fooVecToString(fooInput));
+            Log.d(TAG, "Baz someMethodWithFooVectors " + fooInput.toString());
 
             ArrayList<IBase.Foo> fooOutput = new ArrayList<IBase.Foo>();
             fooOutput.add(fooInput.get(1));
@@ -866,7 +614,7 @@
 
         public IBase.VectorOfArray someMethodWithVectorOfArray(
                 IBase.VectorOfArray in) {
-            Log.d(TAG, "Baz someMethodWithVectorOfArray " + HidlTestJava.toString(in));
+            Log.d(TAG, "Baz someMethodWithVectorOfArray " + in.toString());
 
             IBase.VectorOfArray out = new IBase.VectorOfArray();
             int n = in.addresses.size();
@@ -891,7 +639,7 @@
         }
 
         public IBase.StringMatrix3x5 transpose(IBase.StringMatrix5x3 in) {
-            Log.d(TAG, "Baz transpose " + HidlTestJava.toString(in));
+            Log.d(TAG, "Baz transpose " + in.toString());
 
             IBase.StringMatrix3x5 out = new IBase.StringMatrix3x5();
             for (int i = 0; i < 3; ++i) {
@@ -904,7 +652,7 @@
         }
 
         public String[][] transpose2(String[][] in) {
-            Log.d(TAG, "Baz transpose2 " + HidlTestJava.toString(in));
+            Log.d(TAG, "Baz transpose2 " + in.toString());
 
             String[][] out = new String[3][5];
             for (int i = 0; i < 3; ++i) {
@@ -924,7 +672,7 @@
 
         public boolean[] someBoolArrayMethod(boolean[] x) {
             Log.d(TAG, "Baz someBoolArrayMethod("
-                    + HidlTestJava.toString(x) + ")");
+                    + x.toString() + ")");
 
             boolean[] out = new boolean[4];
             out[0] = !x[0];
@@ -936,7 +684,7 @@
         }
 
         public ArrayList<Boolean> someBoolVectorMethod(ArrayList<Boolean> x) {
-            Log.d(TAG, "Baz someBoolVectorMethod(" + HidlTestJava.booleanVecToString(x) + ")");
+            Log.d(TAG, "Baz someBoolVectorMethod(" + x.toString() + ")");
 
             ArrayList<Boolean> out = new ArrayList<Boolean>();
             for (int i = 0; i < x.size(); ++i) {
@@ -961,7 +709,7 @@
         }
 
         public int[] doSomethingElse(int[] param) {
-            Log.d(TAG, "Baz doSomethingElse " + HidlTestJava.toString(param));
+            Log.d(TAG, "Baz doSomethingElse " + param.toString());
 
             int[] something = new int[32];
             for (int i = 0; i < 15; ++i) {
@@ -980,7 +728,7 @@
         }
 
         public ArrayList<Integer> mapThisVector(ArrayList<Integer> param) {
-            Log.d(TAG, "mapThisVector " + HidlTestJava.integerVecToString(param));
+            Log.d(TAG, "mapThisVector " + param.toString());
 
             ArrayList<Integer> out = new ArrayList<Integer>();