From bd54b3caa36ec6a8b359ae0efbc69411a99c21c1 Mon Sep 17 00:00:00 2001
From: "d.kilic" <d.kilic@fz-juelich.de>
Date: Mon, 10 Jan 2022 11:13:44 +0100
Subject: [PATCH] Resolve "ONLY_PEOPLE_NR_LIST saved wrong in .pet file"

Fix saving only people list in .pet and add unit test for the bug
---
 src/control.cpp                 |  2 +-
 tests/unit_test/tst_control.cpp | 39 +++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/src/control.cpp b/src/control.cpp
index 9673ee2c4..3215dd284 100644
--- a/src/control.cpp
+++ b/src/control.cpp
@@ -3263,7 +3263,7 @@ void Control::setXml(QDomElement &elem)
     subSubElem.setAttribute("ONLY_PEOPLE", trackShowOnly->isChecked());
     subSubElem.setAttribute("ONLY_PEOPLE_LIST", trackShowOnlyList->isChecked());
     subSubElem.setAttribute("ONLY_PEOPLE_NR", trackShowOnlyNr->value());
-    subSubElem.setAttribute("ONLY_PEOPLE_NR_LIST", trackShowOnlyNr->text());
+    subSubElem.setAttribute("ONLY_PEOPLE_NR_LIST", trackShowOnlyNrList->text());
 
     subSubElem.setAttribute("SHOW_CURRENT_POINT", trackShowCurrentPoint->isChecked());
     subSubElem.setAttribute("SHOW_POINTS", trackShowPoints->isChecked());
diff --git a/tests/unit_test/tst_control.cpp b/tests/unit_test/tst_control.cpp
index 70c80caa2..c0f5e354b 100644
--- a/tests/unit_test/tst_control.cpp
+++ b/tests/unit_test/tst_control.cpp
@@ -258,3 +258,42 @@ SCENARIO("Open PeTrack check defaults", "[ui][config]")
     Petrack pet{};
     REQUIRE(pet.getRecognizer().getRecoMethod() == reco::RecognitionMethod::MultiColor);
 }
+
+/**
+ * @brief Transforms node to QString for debugging/logging
+ */
+QString nodeToString(QDomNode &node)
+{
+    QString     str;
+    QTextStream stream(&str);
+    node.save(stream, 4 /*indent*/);
+    return str;
+}
+
+TEST_CASE("Loading from and saving to XML node", "[config]")
+{
+    Petrack      pet{};
+    Control     *control = pet.getControlWidget();
+    QDomDocument doc;
+    QDomElement  save = doc.createElement("CONTROL");
+    control->setXml(save);
+
+    SECTION("PATH")
+    {
+        QDomElement pathNode = save.elementsByTagName("PATH").at(0).toElement();
+        REQUIRE(!pathNode.isNull());
+        SECTION("ONLY_PEOPLE_NR_LIST")
+        {
+            REQUIRE(pathNode.hasAttribute("ONLY_PEOPLE_NR_LIST"));
+
+            // IMPORTANT: reading ONLY_PEOPLE_NR is done in petrack.cpp, as the trajectories need to be loaded
+            // before! Therefore using save from petrack, not Control
+            QDomDocument doc;
+            pet.saveXml(doc);
+            const QString testValue{"101-987"};
+            doc.elementsByTagName("PATH").at(0).toElement().setAttribute("ONLY_PEOPLE_NR_LIST", testValue);
+            pet.openXml(doc, false);
+            REQUIRE(control->trackShowOnlyNrList->text() == testValue);
+        }
+    }
+}
-- 
GitLab