File: TestLegacyPartitionedDataSetCollectionReaderWriter.cxx

package info (click to toggle)
paraview 5.11.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 497,236 kB
  • sloc: cpp: 3,171,290; ansic: 1,315,072; python: 134,290; xml: 103,324; sql: 65,887; sh: 5,286; javascript: 4,901; yacc: 4,383; java: 3,977; perl: 2,363; lex: 1,909; f90: 1,255; objc: 143; makefile: 119; tcl: 59; pascal: 50; fortran: 29
file content (86 lines) | stat: -rw-r--r-- 4,324 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

#include <vtkGenericDataObjectReader.h>
#include <vtkGenericDataObjectWriter.h>
#include <vtkInformation.h>
#include <vtkLogger.h>
#include <vtkMappedUnstructuredGridGenerator.h>
#include <vtkPartitionedDataSetCollection.h>
#include <vtkUnstructuredGrid.h>

int TestLegacyPartitionedDataSetCollectionReaderWriter(int, char*[])
{
  vtkUnstructuredGrid *unstructuredGrid1(nullptr), *unstructuredGrid2(nullptr);
  vtkMappedUnstructuredGridGenerator::GenerateUnstructuredGrid(&unstructuredGrid1);
  vtkMappedUnstructuredGridGenerator::GenerateUnstructuredGrid(&unstructuredGrid2);

  vtkNew<vtkPartitionedDataSetCollection> partitionedCollection;
  partitionedCollection->SetNumberOfPartitionedDataSets(2);
  partitionedCollection->SetNumberOfPartitions(0u, 2);
  partitionedCollection->SetNumberOfPartitions(1u, 2);

  partitionedCollection->SetPartition(0u, 0, unstructuredGrid1);
  partitionedCollection->SetPartition(1u, 1, unstructuredGrid2);

  partitionedCollection->GetMetaData(0u)->Set(vtkCompositeDataSet::NAME(), "GRID_1");
  partitionedCollection->GetMetaData(1u)->Set(vtkCompositeDataSet::NAME(), "GRID_2");

  int numberOfDataSets = partitionedCollection->GetNumberOfPartitionedDataSets();
  vtkLogIf(ERROR, 2 != numberOfDataSets,
    "Expected 2 partitioned input data sets, got " << numberOfDataSets);
  vtkLogIf(ERROR, nullptr == partitionedCollection->GetPartition(0u, 0),
    "Expected input data-set 0 to have data on partition-index 0");
  vtkLogIf(ERROR, nullptr != partitionedCollection->GetPartition(0u, 1),
    "Expected input data-set 0 to have no data on partition-index 1");
  vtkLogIf(ERROR, nullptr != partitionedCollection->GetPartition(1u, 0),
    "Expected input data-set 1 to have no data on partition-index 0");
  vtkLogIf(ERROR, nullptr == partitionedCollection->GetPartition(1u, 1),
    "Expected input data-set 1 to have data on partition-index 1");
  vtkLogIf(ERROR, !partitionedCollection->HasMetaData(0u), "Expected metadata on partition 0");
  vtkLogIf(ERROR, !partitionedCollection->HasMetaData(1u), "Expected metadata on partition 1");
  vtkLogIf(ERROR, 1 != partitionedCollection->GetMetaData(0u)->GetNumberOfKeys(),
    "Expected 1 key on the partition 0 metadata");
  vtkLogIf(ERROR, 1 != partitionedCollection->GetMetaData(1u)->GetNumberOfKeys(),
    "Expected 1 key on the partition 1 metadata");

  vtkNew<vtkGenericDataObjectWriter> writer;
  writer->WriteToOutputStringOn();
  writer->SetInputData(partitionedCollection);
  writer->Write();

  auto written = writer->GetOutputString();
  vtkLogIf(ERROR, nullptr == written, "Expected a written string.");

  vtkNew<vtkGenericDataObjectReader> reader;
  reader->ReadFromInputStringOn();
  reader->SetInputString(written);
  reader->Update();
  vtkDataObject* result = reader->GetOutput();
  vtkLogIf(ERROR, nullptr == result, "Expected a non-null result.");

  vtkPartitionedDataSetCollection* readCollection =
    vtkPartitionedDataSetCollection::SafeDownCast(result);
  vtkLogIf(ERROR, !readCollection, "Expected non-null dataset collection");

  numberOfDataSets = readCollection->GetNumberOfPartitionedDataSets();
  vtkLogIf(ERROR, 2 != numberOfDataSets,
    "Expected 2 partitioned result data sets, got " << numberOfDataSets);
  vtkLogIf(ERROR, nullptr == readCollection->GetPartition(0u, 0),
    "Expected result data-set 0 to have data on partition-index 0");
  vtkLogIf(ERROR, nullptr != readCollection->GetPartition(0u, 1),
    "Expected result data-set 0 to have no data on partition-index 1");
  vtkLogIf(ERROR, nullptr != readCollection->GetPartition(1u, 0),
    "Expected result data-set 1 to have no data on partition-index 0");
  vtkLogIf(ERROR, nullptr == readCollection->GetPartition(1u, 1),
    "Expected result data-set 1 to have data on partition-index 1");
  vtkLogIf(ERROR, !readCollection->HasMetaData(0u), "Expected metadata on result partition 0");
  vtkLogIf(ERROR, !readCollection->HasMetaData(1u), "Expected metadata on result partition 1");
  vtkLogIf(ERROR, 1 != readCollection->GetMetaData(0u)->GetNumberOfKeys(),
    "Expected 1 key on the result partition 0 metadata");
  vtkLogIf(ERROR, 1 != readCollection->GetMetaData(1u)->GetNumberOfKeys(),
    "Expected 1 key on the result partition 1 metadata");

  unstructuredGrid1->Delete();
  unstructuredGrid2->Delete();

  return EXIT_SUCCESS;
}