AAPT2: Allow undefined resources (placeholders)

A resource defined like so:

<item type="drawable" name="foo" />

should be assigned the value @null.

The only exception is for <string> resources, which are given the
empty string value (since <string></string> is ambiguous). The decision
to use "" is based off the fact that old AAPT used to assign "" to all
undefined resources, even non-string ones.

Bug: 38425050
Test: make aapt2_tests
Change-Id: Ib3e0f6f83d16ddd8b279c9fd44a07a37867b85e9
diff --git a/tools/aapt2/ResourceUtils_test.cpp b/tools/aapt2/ResourceUtils_test.cpp
index 048c692..cdc34f1 100644
--- a/tools/aapt2/ResourceUtils_test.cpp
+++ b/tools/aapt2/ResourceUtils_test.cpp
@@ -19,6 +19,9 @@
 #include "Resource.h"
 #include "test/Test.h"
 
+using ::aapt::test::ValueEq;
+using ::testing::Pointee;
+
 namespace aapt {
 
 TEST(ResourceUtilsTest, ParseBool) {
@@ -200,4 +203,22 @@
   EXPECT_EQ(0u, result->value.data);
 }
 
+TEST(ResourceUtilsTest, NullIsEmptyReference) {
+  auto null_value = ResourceUtils::MakeNull();
+  ASSERT_THAT(null_value, Pointee(ValueEq(Reference())));
+
+  auto value = ResourceUtils::TryParseNullOrEmpty("@null");
+  ASSERT_THAT(value, Pointee(ValueEq(Reference())));
+}
+
+TEST(ResourceUtilsTest, EmptyIsBinaryPrimitive) {
+  auto empty_value = ResourceUtils::MakeEmpty();
+  ASSERT_THAT(empty_value, Pointee(ValueEq(BinaryPrimitive(android::Res_value::TYPE_NULL,
+                                                           android::Res_value::DATA_NULL_EMPTY))));
+
+  auto value = ResourceUtils::TryParseNullOrEmpty("@empty");
+  ASSERT_THAT(value, Pointee(ValueEq(BinaryPrimitive(android::Res_value::TYPE_NULL,
+                                                     android::Res_value::DATA_NULL_EMPTY))));
+}
+
 }  // namespace aapt