MCPcopy Create free account
hub / github.com/Kitware/VTK / TestGenericDataArrayAPI

Function TestGenericDataArrayAPI

Common/Core/Testing/Cxx/TestStridedArray.cxx:108–183  ·  view source on GitHub ↗

* vtkGenericDataArray requires some methods to be defined in subclass. * Test their implementations in vtkStridedArray */

Source from the content-addressed store, hash-verified

106 * Test their implementations in vtkStridedArray
107 */
108bool TestGenericDataArrayAPI()
109{
110 std::vector<float> localBuffer = buffer::arrayBuffer();
111 const std::vector<float> initialValues = localBuffer;
112
113 vtkNew<vtkStridedArray<float>> stridedArray;
114 stridedArray->SetNumberOfComponents(strided::nbOfComponents);
115 stridedArray->SetNumberOfTuples(strided::nbOfTuples);
116 stridedArray->ConstructBackend(
117 localBuffer.data(), strided::stride, strided::nbOfComponents, strided::offset);
118
119 // Test SetValue
120 // buffer should not be modified accordingly
121 const float setVal = -0.1;
122 stridedArray->SetValue(strided::checkedValueIdx, setVal);
123
124 if (setVal == localBuffer[buffer::checkedBufferIdx])
125 {
126 std::cerr << "SetValue should not write in read-only array. Has " << setVal << " instead of "
127 << initialValues[buffer::checkedBufferIdx] << "\n";
128 buffer::printArray(localBuffer);
129 return false;
130 }
131
132 // Test GetValue
133 const float getVal = stridedArray->GetValue(strided::checkedValueIdx);
134 if (getVal != initialValues[buffer::checkedBufferIdx])
135 {
136 std::cerr << "Wrong GetValue result " << getVal << " "
137 << initialValues[buffer::checkedBufferIdx] << "\n";
138 return false;
139 }
140
141 // Test GetTypedTuple
142 float typedTuple[strided::nbOfComponents];
143 stridedArray->GetTypedTuple(strided::checkedTupleIdx, typedTuple);
144 if (typedTuple[strided::checkedCompIdx] != localBuffer[buffer::checkedBufferIdx])
145 {
146 std::cerr << "Wrong GetTypedTyple result\n";
147 buffer::printArray(localBuffer);
148 return false;
149 }
150
151 // Test SetTypedTuple
152 typedTuple[strided::checkedCompIdx] = -0.2;
153 stridedArray->SetTypedTuple(strided::checkedTupleIdx, typedTuple);
154 if (typedTuple[strided::checkedCompIdx] == localBuffer[buffer::checkedBufferIdx])
155 {
156 std::cerr << "Wrong SetTypedTyple result\n";
157 buffer::printArray(localBuffer);
158 return false;
159 }
160
161 // GetTypedComponent
162 const float getTypedComp =
163 stridedArray->GetTypedComponent(strided::checkedTupleIdx, strided::checkedCompIdx);
164 if (getTypedComp != localBuffer[buffer::checkedBufferIdx])
165 {

Callers 1

TestStridedArrayFunction · 0.70

Calls 11

arrayBufferFunction · 0.85
printArrayFunction · 0.70
SetNumberOfComponentsMethod · 0.45
SetNumberOfTuplesMethod · 0.45
dataMethod · 0.45
SetValueMethod · 0.45
GetValueMethod · 0.45
GetTypedTupleMethod · 0.45
SetTypedTupleMethod · 0.45
GetTypedComponentMethod · 0.45
SetTypedComponentMethod · 0.45

Tested by

no test coverage detected