[education/labplot] tests/cartesianplot: Added a unit test for the single instance of Legen in CartesianPlot.

Alexander Semke <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit e8e7a414eb0bc7fbd876cbe981af27cd3f30ab6d by Alexander Semke.
Committed on 10/08/2026 at 20:13.
Pushed by asemke into branch 'master'.

Added a unit test for the single instance of Legen in CartesianPlot.

M  +20   -0    tests/cartesianplot/CartesianPlotTest.cpp
M  +3    -0    tests/cartesianplot/CartesianPlotTest.h

https://invent.kde.org/education/labplot/-/commit/e8e7a414eb0bc7fbd876cbe981af27cd3f30ab6d

diff --git a/tests/cartesianplot/CartesianPlotTest.cpp b/tests/cartesianplot/CartesianPlotTest.cpp
index 8540d0af11..6284651db3 100644
--- a/tests/cartesianplot/CartesianPlotTest.cpp
+++ b/tests/cartesianplot/CartesianPlotTest.cpp
@@ -21,6 +21,7 @@
 #include "backend/worksheet/InfoElement.h"
 #include "backend/worksheet/plots/cartesian/CartesianCoordinateSystem.h"
 #include "backend/worksheet/plots/cartesian/CartesianPlot.h"
+#include "backend/worksheet/plots/cartesian/CartesianPlotLegend.h"
 #include "backend/worksheet/plots/cartesian/CartesianPlotPrivate.h"
 #include "backend/worksheet/plots/cartesian/plots.h"
 #include "frontend/dockwidgets/XYFitCurveDock.h"
@@ -1796,4 +1797,23 @@ void CartesianPlotTest::zValueAfterAddMoveRemove() {
 	QVERIFY(zValueCurve1 < zValueHistogram);
 }
 
+void CartesianPlotTest::legendSingleInstance() {
+	auto* project = new Project();
+	auto* worksheet = new Worksheet(QStringLiteral("ws"));
+	project->addChild(worksheet);
+
+	auto* plot = new CartesianPlot(QStringLiteral("plot"));
+	worksheet->addChild(plot);
+
+	// first call creates the legend
+	plot->addLegend();
+	QCOMPARE(plot->childCount<CartesianPlotLegend>(), 1);
+
+	// second call must be a no-op — only one legend is allowed
+	plot->addLegend();
+	QCOMPARE(plot->childCount<CartesianPlotLegend>(), 1);
+
+	delete project;
+}
+
 QTEST_MAIN(CartesianPlotTest)
diff --git a/tests/cartesianplot/CartesianPlotTest.h b/tests/cartesianplot/CartesianPlotTest.h
index 3d35ab6f2d..6a60c9baeb 100644
--- a/tests/cartesianplot/CartesianPlotTest.h
+++ b/tests/cartesianplot/CartesianPlotTest.h
@@ -71,5 +71,8 @@ private Q_SLOTS:
 
 	// handling of z-values on changes in the child hierarchy
 	void zValueAfterAddMoveRemove();
+
+	// legend
+	void legendSingleInstance();
 };
 #endif
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.