AAPT2: Ensure strings are sorted by configuration
Keep strings sorted by configuration so that strings likely
to be selected (all match the same locale, for instance) are
close together.
Bug: 67958501
Test: make aapt2_tests
Change-Id: Id17d93bf2e03ce408a6f619d3ea6dc313e393b76
diff --git a/tools/aapt2/ResourceValues_test.cpp b/tools/aapt2/ResourceValues_test.cpp
index 10f9b55..a80a9dc 100644
--- a/tools/aapt2/ResourceValues_test.cpp
+++ b/tools/aapt2/ResourceValues_test.cpp
@@ -18,6 +18,10 @@
#include "test/Test.h"
+using ::testing::Eq;
+using ::testing::SizeIs;
+using ::testing::StrEq;
+
namespace aapt {
TEST(ResourceValuesTest, PluralEquals) {
@@ -148,6 +152,22 @@
EXPECT_TRUE(a->Equals(b.get()));
}
+TEST(ResourcesValuesTest, StringClones) {
+ StringPool pool_a;
+ StringPool pool_b;
+
+ String str_a(pool_a.MakeRef("hello", StringPool::Context(test::ParseConfigOrDie("en"))));
+
+ ASSERT_THAT(pool_a, SizeIs(1u));
+ EXPECT_THAT(pool_a.strings()[0]->context.config, Eq(test::ParseConfigOrDie("en")));
+ EXPECT_THAT(pool_a.strings()[0]->value, StrEq("hello"));
+
+ std::unique_ptr<String> str_b(str_a.Clone(&pool_b));
+ ASSERT_THAT(pool_b, SizeIs(1u));
+ EXPECT_THAT(pool_b.strings()[0]->context.config, Eq(test::ParseConfigOrDie("en")));
+ EXPECT_THAT(pool_b.strings()[0]->value, StrEq("hello"));
+}
+
TEST(ResourceValuesTest, StyleMerges) {
StringPool pool_a;
StringPool pool_b;