class ReferenceTableTest : public CommonRuntimeTest { protected:
ReferenceTableTest() {
use_boot_image_ = true; // Make the Runtime creation cheaper.
}
// Check removal of all nulls in a empty table is a no-op.
rt.Remove(nullptr);
EXPECT_EQ(0U, rt.Size());
// Check removal of all o1 in a empty table is a no-op.
rt.Remove(o1.Get());
EXPECT_EQ(0U, rt.Size());
// Add o1 and check we have 1 element and can dump.
{
rt.Add(o1.Get());
EXPECT_EQ(1U, rt.Size());
std::ostringstream oss;
rt.Dump(oss);
EXPECT_NE(oss.str().find("1 of java.lang.String"), std::string::npos) << oss.str();
EXPECT_EQ(oss.str().find("short[]"), std::string::npos) << oss.str();
}
// Add a second object 10 times so we can then check dumping works as expected.
Handle<mirror::ShortArray> o2 = hs.NewHandle(mirror::ShortArray::Alloc(soa.Self(), 0)); for (size_t i = 0; i < 10; ++i) {
rt.Add(o2.Get());
EXPECT_EQ(i + 2, rt.Size());
std::ostringstream oss;
rt.Dump(oss);
EXPECT_NE(oss.str().find(StringPrintf("Last %zd entries (of %zd):",
i + 2 > 10 ? 10 : i + 2,
i + 2)),
std::string::npos) << oss.str();
EXPECT_NE(oss.str().find("1 of java.lang.String"), std::string::npos) << oss.str(); if (i == 0) {
EXPECT_NE(oss.str().find("1 of short[]"), std::string::npos) << oss.str();
} else {
EXPECT_NE(oss.str().find(StringPrintf("%zd of short[] (1 unique instances)", i + 1)),
std::string::npos) << oss.str();
}
}
// Remove o2 ten times. for (size_t i = 0; i < 10; ++i) {
rt.Remove(o2.Get());
EXPECT_EQ(9 - i, rt.Size());
std::ostringstream oss;
rt.Dump(oss); if (i == 9) {
EXPECT_EQ(oss.str().find("short[]"), std::string::npos) << oss.str();
} elseif (i == 8) {
EXPECT_NE(oss.str().find("1 of short[]"), std::string::npos) << oss.str();
} else {
EXPECT_NE(oss.str().find(StringPrintf("%zd of short[] (1 unique instances)", 10 - i - 1)),
std::string::npos) << oss.str();
}
}
// Add a reference and check that the type of the referent is dumped.
{
ObjPtr<mirror::Object> empty_reference = CreateWeakReference(nullptr);
ASSERT_TRUE(empty_reference->IsReferenceInstance());
rt.Add(empty_reference);
std::ostringstream oss;
rt.Dump(oss);
EXPECT_NE(oss.str().find("java.lang.ref.WeakReference (referent is null)"), std::string::npos)
<< oss.str();
rt.Remove(empty_reference);
}
// Add two objects. Enable allocation tracking for the latter.
{
Handle<mirror::String> h_without_trace(hs.NewHandle(
mirror::String::AllocFromModifiedUtf8(soa.Self(), "Without")));
// Now dump, and ensure order.
std::ostringstream oss;
rt.Dump(oss);
// Only do this on the part after Summary.
std::string base = oss.str();
size_t summary_pos = base.find("Summary:");
ASSERT_NE(summary_pos, std::string::npos);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.