From d6ee473d72bebd2585573de74eb4bd6d957194f0 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Thu, 25 Jul 2024 22:36:46 +0200 Subject: [PATCH] Fixed issue #1799 (Can't set cell properties by script) --- src/db/db/dbPropertiesRepository.cc | 10 ++++++- .../oasis/unit_tests/dbOASISReaderTests.cc | 25 ++++++++++++++++++ testdata/oasis/issue_1799.oas | Bin 0 -> 546 bytes 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 testdata/oasis/issue_1799.oas diff --git a/src/db/db/dbPropertiesRepository.cc b/src/db/db/dbPropertiesRepository.cc index 3f3d10049c..3d6628fe70 100644 --- a/src/db/db/dbPropertiesRepository.cc +++ b/src/db/db/dbPropertiesRepository.cc @@ -89,6 +89,11 @@ PropertiesRepository::prop_name_id (const tl::Variant &name) void PropertiesRepository::change_properties (property_names_id_type id, const properties_set &new_props) { + // NOTE: change_properties MAY put the property map into a state where there is + // more than one property ID per set. For example, 1 and 5 may be valid property + // ids for the same set. "properties(1)" and "properties(5)" returns the same + // property set "S", while "properties_id(S)" only returns 1. + const properties_set &old_props = properties (id); std::map ::const_iterator pi = m_properties_ids_by_set.find (old_props); @@ -149,7 +154,10 @@ PropertiesRepository::properties_id (const properties_set &props) std::map ::const_iterator pi = m_properties_ids_by_set.find (props); if (pi == m_properties_ids_by_set.end ()) { - properties_id_type id = m_properties_ids_by_set.size (); + properties_id_type id = 0; + if (! m_properties_by_id.empty ()) { + id = (--m_properties_by_id.end ())->first + 1; + } m_properties_ids_by_set.insert (std::make_pair (props, id)); m_properties_by_id.insert (std::make_pair (id, props)); for (properties_set::const_iterator nv = props.begin (); nv != props.end (); ++nv) { diff --git a/src/plugins/streamers/oasis/unit_tests/dbOASISReaderTests.cc b/src/plugins/streamers/oasis/unit_tests/dbOASISReaderTests.cc index ae287e6f07..a519ff1a7f 100644 --- a/src/plugins/streamers/oasis/unit_tests/dbOASISReaderTests.cc +++ b/src/plugins/streamers/oasis/unit_tests/dbOASISReaderTests.cc @@ -639,6 +639,31 @@ TEST(Bug_1474) } } +TEST(Bug_1799) +{ + db::Manager m (false); + db::Layout layout (&m); + + { + tl::InputStream file (tl::testdata () + "/oasis/issue_1799.oas"); + db::OASISReader reader (file); + reader.read (layout); + } + + db::properties_id_type pn = layout.properties_repository ().prop_name_id (tl::Variant (1)); + db::PropertiesRepository::properties_set ps; + ps.insert (std::make_pair (pn, tl::Variant ("hello, world!"))); + + auto pid = layout.properties_repository ().properties_id (ps); + + auto ps2 = layout.properties_repository ().properties (pid); + EXPECT_EQ (ps2.size (), size_t (1)); + EXPECT_EQ (ps2.find (pn) != ps2.end (), true); + if (ps2.find (pn) != ps2.end ()) { + EXPECT_EQ (ps2.find (pn)->second.to_string (), "hello, world!"); + } +} + TEST(DuplicateCellname) { db::Manager m (false); diff --git a/testdata/oasis/issue_1799.oas b/testdata/oasis/issue_1799.oas new file mode 100644 index 0000000000000000000000000000000000000000..32ae303d8b61d4023b3a574226109ad2c95cd0de GIT binary patch literal 546 zcmY!lcJ=kt^>+;R4CduxWH!_@V0gjKC?n3q!6L)YEF;ds&md#Q%FoEp#Luk6P!^th z#*nMQfXD5jp~8yY6*H5Pb+0Wm5iI@nzMk7P{Q3KjD?)wd2&K%M+H2+dp(|)^7)nZCu28Bt5wdroTtPvpE2dJh>qqdecw}_ zy64XO_Ue1;c<4Sd`BchVcqQPxpSO?RN&Qt@wET26PoDAC-*)Pp=bAJ6x}Eyox?1PX zoDaUfCDi!oTB>foRmIRwcfW@DMwTV}c;-im6!V__s&j>rmqApSgMo#$ z=@(-|?ZYd~Z~2b#JO)wBf+a=yrAaxd#re6Z@g<1`sYNp43>+UAnHW2n7#SFK7~2_v L6hp(v0t^fQ4J_y0 literal 0 HcmV?d00001