Skip to content
Snippets Groups Projects
Commit 6bedf4c2 authored by Jaswant Panchumarti (Kitware)'s avatar Jaswant Panchumarti (Kitware)
Browse files

Validate ClassName and SuperClassName only when required in deserializer

parent e07917ad
No related branches found
No related tags found
No related merge requests found
......@@ -81,32 +81,33 @@ bool vtkDeserializer::DeserializeJSON(
}
std::string className;
std::vector<std::string> superClassNames;
if (objectBase == nullptr)
{
const auto iter = state.find("ClassName");
if (iter == state.end())
{
vtkErrorMacro(<< "Failed to find 'ClassName' in state at id=" << identifier);
return false;
}
else
{
className = iter->get<std::string>();
}
}
{
const auto iter = state.find("SuperClassNames");
if (iter == state.end())
// Only look for ClassName and SuperClassNames if we are going to construct the object.
{
vtkErrorMacro(<< "Failed to find 'SuperClassNames' in state at id=" << identifier);
return false;
const auto iter = state.find("ClassName");
if (iter == state.end())
{
vtkErrorMacro(<< "Failed to find 'ClassName' in state at id=" << identifier);
return false;
}
else
{
className = iter->get<std::string>();
}
}
else
{
superClassNames = iter->get<std::vector<std::string>>();
const auto iter = state.find("SuperClassNames");
if (iter == state.end())
{
vtkErrorMacro(<< "Failed to find 'SuperClassNames' in state at id=" << identifier);
return false;
}
else
{
superClassNames = iter->get<std::vector<std::string>>();
}
}
}
if (objectBase == nullptr)
{
if (auto ptr = this->ConstructObject(className, superClassNames))
{
objectBase = vtk::TakeSmartPointer(ptr);
......
......@@ -56,5 +56,30 @@ class TestUpdateObjectFromState(vtkTesting.vtkTest):
self.assertTupleEqual(camera.GetPosition(), (0, 0.2, 1.3))
self.assertEqual(camera.GetViewAngle(), 60)
def test3(self):
from vtkmodules.vtkSerializationManager import vtkObjectManager
from vtkmodules.vtkRenderingCore import vtkCamera
import json
# Scenario 3:
# An object is registered and serialized. Later, a new state is created with modified properties.
# Unlike Scenario 2, this new state does not have keys that were originally part of the state like
# "ClassName", "SuperClassNames" and "vtk-object-manager-kept-alive"
# Call UpdateObjectFromState() with modified state. Verify the real object's properties match
# with the state's properties.
manager = vtkObjectManager()
manager.Initialize()
camera = vtkCamera()
cid = manager.RegisterObject(camera)
manager.UpdateStatesFromObjects()
manager.UpdateObjectFromState(json.dumps({"Id": cid, "Position": (0, 0.2, 1.3)}))
self.assertTupleEqual(camera.GetPosition(), (0, 0.2, 1.3))
manager.UpdateObjectFromState(json.dumps({"Id": cid, "ViewAngle": 60}))
self.assertEqual(camera.GetViewAngle(), 60)
if __name__ == "__main__":
vtkTesting.main([(TestUpdateObjectFromState, 'test')])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment