Test: Add test cases for Persistence::validateXMLString
This commit is contained in:
@@ -666,6 +666,17 @@ class DocumentBasicCases(unittest.TestCase):
|
||||
root = ET.fromstring(test.Content)
|
||||
self.assertEqual(root.tag, "Properties")
|
||||
|
||||
def testValidateXml(self):
|
||||
self.Doc.openTransaction("Add")
|
||||
obj = self.Doc.addObject("App::FeatureTest","Label")
|
||||
obj.Label = "abc\x01ef"
|
||||
TempPath = tempfile.gettempdir()
|
||||
SaveName = TempPath + os.sep + "CreateTest.FCStd"
|
||||
self.Doc.saveAs(SaveName)
|
||||
FreeCAD.closeDocument(self.Doc.Name)
|
||||
self.Doc = FreeCAD.open(SaveName)
|
||||
self.assertEqual(self.Doc.ActiveObject.Label, "abc_ef")
|
||||
|
||||
def tearDown(self):
|
||||
# closing doc
|
||||
FreeCAD.closeDocument("CreateTest")
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#endif
|
||||
|
||||
#include "Base/Exception.h"
|
||||
#include "Base/Persistence.h"
|
||||
#include "Base/Reader.h"
|
||||
#include <array>
|
||||
#include <filesystem>
|
||||
@@ -459,3 +460,13 @@ TEST_F(ReaderTest, validDefaults)
|
||||
EXPECT_THROW({ xml.Reader()->getAttribute<TimesIGoToBed>("missing"); }, Base::XMLBaseException);
|
||||
EXPECT_EQ(value20, TimesIGoToBed::Late);
|
||||
}
|
||||
|
||||
TEST_F(ReaderTest, validateXmlString)
|
||||
{
|
||||
std::string input = "abcde";
|
||||
std::string output = input;
|
||||
input.push_back(char(15));
|
||||
output.push_back('_');
|
||||
std::string result = Base::Persistence::validateXMLString(input);
|
||||
EXPECT_EQ(output, result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user