[glom/glom-1-30] Document:remove_field(): Remove from the vector, not a copy.



commit d07e354f0f26f8ec5d7f3deb3cdce1b05b59e9bd
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Jun 20 20:46:47 2017 +0200

    Document:remove_field(): Remove from the vector, not a copy.
    
    And test this.
    This regression was probably introduced by the conversion to use
    auto with C++11.

 glom/libglom/document/document.cc      |    2 +-
 tests/test_document_load_and_change.cc |   13 +++++++++++--
 2 files changed, 12 insertions(+), 3 deletions(-)
---
diff --git a/glom/libglom/document/document.cc b/glom/libglom/document/document.cc
index 92823bb..7ab1679 100644
--- a/glom/libglom/document/document.cc
+++ b/glom/libglom/document/document.cc
@@ -724,7 +724,7 @@ void Document::remove_field(const Glib::ustring& table_name, const Glib::ustring
   const auto table_info = get_table_info(table_name);
   if(table_info)
   {
-    auto vecFields = table_info->m_fields;
+    auto& vecFields = table_info->m_fields;
     auto iterFind = find_if_same_name(vecFields, field_name);
     if(iterFind != vecFields.end()) //If it was found:
     {
diff --git a/tests/test_document_load_and_change.cc b/tests/test_document_load_and_change.cc
index bbc8c49..f76daea 100644
--- a/tests/test_document_load_and_change.cc
+++ b/tests/test_document_load_and_change.cc
@@ -169,12 +169,21 @@ int main()
 
   //Remove a field from the whole document:
   document.remove_field("publisher", "publisher_id");
+
+  //Check that the old field name is not used.
+  auto field =
+    document.get_field("publisher", "publisher_id");
+  if (field) {
+    std::cerr << G_STRFUNC << ": Failure: The removed field name still exists.\n";
+    return EXIT_FAILURE;
+  }
+
   if(field_is_on_a_layout(document, "publisher", "publisher_id"))
   {
     std::cerr << G_STRFUNC << ": Failure: The removed field name is still used on a layout." << std::endl;
     return EXIT_FAILURE;
   }
-  
+
   //Remove a relationship:
   document.remove_relationship(relationship);
   relationship = document.get_relationship("invoice_lines", "products");
@@ -183,7 +192,7 @@ int main()
     std::cerr << G_STRFUNC << ": Failure: The removed relationship still exists." << std::endl;
     return EXIT_FAILURE;
   }
-  
+
   //Change a table name:
   const Glib::ustring table_renamed = "invoiceslinesrenamed";
   document.change_table_name("invoice_lines", table_renamed);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]