(self)
| 4 | class TestBlobs(vtkTesting.vtkTest): |
| 5 | |
| 6 | def test(self): |
| 7 | from vtkmodules.vtkSerializationManager import vtkObjectManager |
| 8 | from vtkmodules.vtkCommonCore import vtkTypeFloat32Array, vtkUnsignedIntArray |
| 9 | |
| 10 | arrayF32Id = "" |
| 11 | arrayUI32Id = "" |
| 12 | |
| 13 | def serialize(): |
| 14 | global arrayF32Id, arrayUI32Id |
| 15 | |
| 16 | manager = vtkObjectManager() |
| 17 | if not manager.Initialize(): |
| 18 | return |
| 19 | |
| 20 | |
| 21 | arrayF32 = vtkTypeFloat32Array() |
| 22 | arrayUI32 = vtkUnsignedIntArray() |
| 23 | for i in range(10): |
| 24 | arrayF32.InsertNextValue(10 - i) |
| 25 | arrayUI32.InsertNextValue(20 + i) |
| 26 | |
| 27 | arrayF32Id = manager.RegisterObject(arrayF32) |
| 28 | self.assertEqual(arrayF32Id, 1) |
| 29 | |
| 30 | arrayUI32Id = manager.RegisterObject(arrayUI32) |
| 31 | self.assertEqual(arrayUI32Id, 2) |
| 32 | |
| 33 | manager.UpdateStatesFromObjects() |
| 34 | active_ids = manager.GetAllDependencies(0) |
| 35 | |
| 36 | # these are not guaranteed to appear in the exact same order |
| 37 | # due to the unordered_map in use within vtkObjectManager. |
| 38 | self.assertEqual(len(active_ids), 2) |
| 39 | self.assertEqual(arrayF32Id in active_ids, True) |
| 40 | self.assertEqual(arrayUI32Id in active_ids, True) |
| 41 | |
| 42 | states = [ manager.GetState(object_id) for object_id in active_ids ] |
| 43 | hash_to_blob_map = { blob_hash: manager.GetBlob(blob_hash, True) for blob_hash in manager.GetBlobHashes(active_ids) } |
| 44 | |
| 45 | manager.UnRegisterObject(arrayF32Id) |
| 46 | manager.UnRegisterObject(arrayUI32Id) |
| 47 | |
| 48 | return states, hash_to_blob_map |
| 49 | |
| 50 | def deserialize(states, hash_to_blob_map): |
| 51 | global arrayF32Id, arrayUI32Id |
| 52 | |
| 53 | if not len(states): |
| 54 | return |
| 55 | |
| 56 | manager = vtkObjectManager() |
| 57 | if not manager.Initialize(): |
| 58 | return |
| 59 | |
| 60 | for state in states: |
| 61 | manager.RegisterState(state) |
| 62 | for hash_text, blob in hash_to_blob_map.items(): |
| 63 | manager.RegisterBlob(hash_text, blob) |
nothing calls this directly
no test coverage detected