a89cd7a152
version, fix OBS reject due to source mismatch. - Fix spurious failures of ReaderTest, add * Add-property-read-write-test.patch * Fix-test-failure-temporary-file-race.patch OBS-URL: https://build.opensuse.org/package/show/science/FreeCAD?expand=0&rev=184
52 lines
1.5 KiB
Diff
52 lines
1.5 KiB
Diff
From 6f23f01e509348a6755ad3c465a3d7ffd758ee03 Mon Sep 17 00:00:00 2001
|
|
From: wmayer <wmayer@freecad.org>
|
|
Date: Sat, 28 Sep 2024 00:29:40 +0200
|
|
Subject: [PATCH] Tests: Add unit test for PR #16763
|
|
|
|
---
|
|
tests/src/App/Property.cpp | 27 +++++++++++++++++++++++++++
|
|
1 file changed, 27 insertions(+)
|
|
|
|
diff --git a/tests/src/App/Property.cpp b/tests/src/App/Property.cpp
|
|
index 9ab8aeffa6c1..528ca56f2fa1 100644
|
|
--- a/tests/src/App/Property.cpp
|
|
+++ b/tests/src/App/Property.cpp
|
|
@@ -1,6 +1,9 @@
|
|
#include <gtest/gtest.h>
|
|
|
|
#include "App/PropertyLinks.h"
|
|
+#include <App/PropertyStandard.h>
|
|
+#include <Base/Writer.h>
|
|
+#include <Base/Reader.h>
|
|
|
|
TEST(PropertyLink, TestSetValues)
|
|
{
|
|
@@ -13,3 +16,27 @@ TEST(PropertyLink, TestSetValues)
|
|
EXPECT_EQ(sub[0], "Sub1");
|
|
EXPECT_EQ(sub[1], "Sub2");
|
|
}
|
|
+
|
|
+TEST(PropertyFloatTest, testWriteRead)
|
|
+{
|
|
+#if defined(FC_OS_LINUX) || defined(FC_OS_BSD)
|
|
+ setlocale(LC_ALL, "");
|
|
+ setlocale(LC_NUMERIC, "C"); // avoid rounding of floating point numbers
|
|
+#endif
|
|
+ double value = 1.2345;
|
|
+ App::PropertyFloat prop;
|
|
+ prop.setValue(value);
|
|
+ Base::StringWriter writer;
|
|
+ prop.Save(writer);
|
|
+
|
|
+ std::string str = "<?xml version='1.0' encoding='utf-8'?>\n";
|
|
+ str.append("<Property name='Length' type='App::PropertyFloat'>\n");
|
|
+ str.append(writer.getString());
|
|
+ str.append("</Property>\n");
|
|
+
|
|
+ std::stringstream data(str);
|
|
+ Base::XMLReader reader("Document.xml", data);
|
|
+ App::PropertyFloat prop2;
|
|
+ prop2.Restore(reader);
|
|
+ EXPECT_DOUBLE_EQ(prop2.getValue(), value);
|
|
+}
|