Make our new NullPointerException detail messages more readable to Java programmers.
Two to-dos to-done.
Change-Id: I0276dd8b9c062e8e9523cb51defed2c3eda77e2b
diff --git a/src/utils_test.cc b/src/utils_test.cc
index 31fccc5..3228bb6 100644
--- a/src/utils_test.cc
+++ b/src/utils_test.cc
@@ -20,54 +20,67 @@
namespace art {
+std::string PrettyArguments(const char* signature);
+std::string PrettyReturnType(const char* signature);
+
class UtilsTest : public CommonTest {
};
-#define EXPECT_DESCRIPTOR(pretty_descriptor, descriptor) \
- do { \
- SirtRef<String> s(String::AllocFromModifiedUtf8(descriptor)); \
- std::string result(PrettyDescriptor(s.get())); \
- EXPECT_EQ(pretty_descriptor, result); \
- } while (false)
-
TEST_F(UtilsTest, PrettyDescriptor_ArrayReferences) {
- EXPECT_DESCRIPTOR("java.lang.Class[]", "[Ljava/lang/Class;");
- EXPECT_DESCRIPTOR("java.lang.Class[][]", "[[Ljava/lang/Class;");
+ EXPECT_EQ("java.lang.Class[]", PrettyDescriptor("[Ljava/lang/Class;"));
+ EXPECT_EQ("java.lang.Class[][]", PrettyDescriptor("[[Ljava/lang/Class;"));
}
TEST_F(UtilsTest, PrettyDescriptor_ScalarReferences) {
- EXPECT_DESCRIPTOR("java.lang.String", "Ljava.lang.String;");
- EXPECT_DESCRIPTOR("java.lang.String", "Ljava/lang/String;");
+ EXPECT_EQ("java.lang.String", PrettyDescriptor("Ljava.lang.String;"));
+ EXPECT_EQ("java.lang.String", PrettyDescriptor("Ljava/lang/String;"));
}
TEST_F(UtilsTest, PrettyDescriptor_PrimitiveArrays) {
- EXPECT_DESCRIPTOR("boolean[]", "[Z");
- EXPECT_DESCRIPTOR("boolean[][]", "[[Z");
- EXPECT_DESCRIPTOR("byte[]", "[B");
- EXPECT_DESCRIPTOR("byte[][]", "[[B");
- EXPECT_DESCRIPTOR("char[]", "[C");
- EXPECT_DESCRIPTOR("char[][]", "[[C");
- EXPECT_DESCRIPTOR("double[]", "[D");
- EXPECT_DESCRIPTOR("double[][]", "[[D");
- EXPECT_DESCRIPTOR("float[]", "[F");
- EXPECT_DESCRIPTOR("float[][]", "[[F");
- EXPECT_DESCRIPTOR("int[]", "[I");
- EXPECT_DESCRIPTOR("int[][]", "[[I");
- EXPECT_DESCRIPTOR("long[]", "[J");
- EXPECT_DESCRIPTOR("long[][]", "[[J");
- EXPECT_DESCRIPTOR("short[]", "[S");
- EXPECT_DESCRIPTOR("short[][]", "[[S");
+ EXPECT_EQ("boolean[]", PrettyDescriptor("[Z"));
+ EXPECT_EQ("boolean[][]", PrettyDescriptor("[[Z"));
+ EXPECT_EQ("byte[]", PrettyDescriptor("[B"));
+ EXPECT_EQ("byte[][]", PrettyDescriptor("[[B"));
+ EXPECT_EQ("char[]", PrettyDescriptor("[C"));
+ EXPECT_EQ("char[][]", PrettyDescriptor("[[C"));
+ EXPECT_EQ("double[]", PrettyDescriptor("[D"));
+ EXPECT_EQ("double[][]", PrettyDescriptor("[[D"));
+ EXPECT_EQ("float[]", PrettyDescriptor("[F"));
+ EXPECT_EQ("float[][]", PrettyDescriptor("[[F"));
+ EXPECT_EQ("int[]", PrettyDescriptor("[I"));
+ EXPECT_EQ("int[][]", PrettyDescriptor("[[I"));
+ EXPECT_EQ("long[]", PrettyDescriptor("[J"));
+ EXPECT_EQ("long[][]", PrettyDescriptor("[[J"));
+ EXPECT_EQ("short[]", PrettyDescriptor("[S"));
+ EXPECT_EQ("short[][]", PrettyDescriptor("[[S"));
}
TEST_F(UtilsTest, PrettyDescriptor_PrimitiveScalars) {
- EXPECT_DESCRIPTOR("boolean", "Z");
- EXPECT_DESCRIPTOR("byte", "B");
- EXPECT_DESCRIPTOR("char", "C");
- EXPECT_DESCRIPTOR("double", "D");
- EXPECT_DESCRIPTOR("float", "F");
- EXPECT_DESCRIPTOR("int", "I");
- EXPECT_DESCRIPTOR("long", "J");
- EXPECT_DESCRIPTOR("short", "S");
+ EXPECT_EQ("boolean", PrettyDescriptor("Z"));
+ EXPECT_EQ("byte", PrettyDescriptor("B"));
+ EXPECT_EQ("char", PrettyDescriptor("C"));
+ EXPECT_EQ("double", PrettyDescriptor("D"));
+ EXPECT_EQ("float", PrettyDescriptor("F"));
+ EXPECT_EQ("int", PrettyDescriptor("I"));
+ EXPECT_EQ("long", PrettyDescriptor("J"));
+ EXPECT_EQ("short", PrettyDescriptor("S"));
+}
+
+TEST_F(UtilsTest, PrettyArguments) {
+ EXPECT_EQ("()", PrettyArguments("()V"));
+ EXPECT_EQ("(int)", PrettyArguments("(I)V"));
+ EXPECT_EQ("(int, int)", PrettyArguments("(II)V"));
+ EXPECT_EQ("(int, int, int[][])", PrettyArguments("(II[[I)V"));
+ EXPECT_EQ("(int, int, int[][], java.lang.Poop)", PrettyArguments("(II[[ILjava/lang/Poop;)V"));
+ EXPECT_EQ("(int, int, int[][], java.lang.Poop, java.lang.Poop[][])", PrettyArguments("(II[[ILjava/lang/Poop;[[Ljava/lang/Poop;)V"));
+}
+
+TEST_F(UtilsTest, PrettyReturnType) {
+ EXPECT_EQ("void", PrettyReturnType("()V"));
+ EXPECT_EQ("int", PrettyReturnType("()I"));
+ EXPECT_EQ("int[][]", PrettyReturnType("()[[I"));
+ EXPECT_EQ("java.lang.Poop", PrettyReturnType("()Ljava/lang/Poop;"));
+ EXPECT_EQ("java.lang.Poop[][]", PrettyReturnType("()[[Ljava/lang/Poop;"));
}
TEST_F(UtilsTest, PrettyTypeOf) {