TEST(StringPoolTest, PruneStringsWithNoReferences) {
    StringPool pool;

    {
        StringPool::Ref ref = pool.makeRef(u"wut");
        EXPECT_EQ(*ref, u"wut");
        EXPECT_EQ(1u, pool.size());
    }

    EXPECT_EQ(1u, pool.size());
    pool.prune();
    EXPECT_EQ(0u, pool.size());
}
TEST(StringPoolTest, DoNotInsertNewDuplicateString) {
    StringPool pool;

    StringPool::Ref ref = pool.makeRef(u"wut");
    StringPool::Ref ref2 = pool.makeRef(u"wut");

    EXPECT_EQ(*ref, u"wut");
    EXPECT_EQ(*ref2, u"wut");
    EXPECT_EQ(1u, pool.size());
}
示例#3
0
status_t XMLNode::flatten(const sp<AaptFile>& dest,
        bool stripComments, bool stripRawValues) const
{
    StringPool strings;
    Vector<uint32_t> resids;
    
    // First collect just the strings for attribute names that have a
    // resource ID assigned to them.  This ensures that the resource ID
    // array is compact, and makes it easier to deal with attribute names
    // in different namespaces (and thus with different resource IDs).
    collect_resid_strings(&strings, &resids);

    // Next collect all remainibng strings.
    collect_strings(&strings, &resids, stripComments, stripRawValues);

#if 0  // No longer compiles
    NOISY(printf("Found strings:\n");
        const size_t N = strings.size();
        for (size_t i=0; i<N; i++) {
            printf("%s\n", String8(strings.entryAt(i).string).string());
        }
    );