summaryrefslogtreecommitdiffstats
path: root/runtime/base/variant_map_test.cc
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2015-02-06 17:59:39 -0800
committerIgor Murashkin <iam@google.com>2015-02-17 10:57:35 -0800
commit2798da180524dde1f923b4ee964877546bd6bb44 (patch)
tree9636c049c56402a7cc0196ff3657a8c8ec1322a0 /runtime/base/variant_map_test.cc
parent6e27f82193a8f54cd8ecdc8fb2c4c1adadafbaf4 (diff)
downloadart-2798da180524dde1f923b4ee964877546bd6bb44.zip
art-2798da180524dde1f923b4ee964877546bd6bb44.tar.gz
art-2798da180524dde1f923b4ee964877546bd6bb44.tar.bz2
art: Fix bug in VariantMap::Set
Bug: 19295410 Change-Id: I7827583846d710698c0e7bc0ec1a2c3bf901bd50
Diffstat (limited to 'runtime/base/variant_map_test.cc')
-rw-r--r--runtime/base/variant_map_test.cc21
1 files changed, 21 insertions, 0 deletions
diff --git a/runtime/base/variant_map_test.cc b/runtime/base/variant_map_test.cc
index 827de46..f306a48 100644
--- a/runtime/base/variant_map_test.cc
+++ b/runtime/base/variant_map_test.cc
@@ -38,10 +38,12 @@ namespace {
static const Key<int> Apple;
static const Key<double> Orange;
+ static const Key<std::string> Label;
};
const FruitMap::Key<int> FruitMap::Apple;
const FruitMap::Key<double> FruitMap::Orange;
+ const FruitMap::Key<std::string> FruitMap::Label;
} // namespace
TEST(VariantMaps, BasicReadWrite) {
@@ -67,6 +69,7 @@ TEST(VariantMaps, BasicReadWrite) {
EXPECT_DOUBLE_EQ(555.0, *fm.Get(FruitMap::Orange));
EXPECT_EQ(size_t(2), fm.Size());
+ // Simple remove
fm.Remove(FruitMap::Apple);
EXPECT_FALSE(fm.Exists(FruitMap::Apple));
@@ -75,6 +78,24 @@ TEST(VariantMaps, BasicReadWrite) {
EXPECT_FALSE(fm.Exists(FruitMap::Orange));
}
+TEST(VariantMaps, SetPreviousValue) {
+ FruitMap fm;
+
+ // Indirect remove by setting yourself again
+ fm.Set(FruitMap::Label, std::string("hello_world"));
+ auto* ptr = fm.Get(FruitMap::Label);
+ ASSERT_TRUE(ptr != nullptr);
+ *ptr = "foobar";
+
+ // Set the value to the same exact pointer which we got out of the map.
+ // This should cleanly 'just work' and not try to delete the value too early.
+ fm.Set(FruitMap::Label, *ptr);
+
+ auto* new_ptr = fm.Get(FruitMap::Label);
+ ASSERT_TRUE(ptr != nullptr);
+ EXPECT_EQ(std::string("foobar"), *new_ptr);
+}
+
TEST(VariantMaps, RuleOfFive) {
// Test empty constructor
FruitMap fmEmpty;