| 137 | //------------------------------------------------------------------------------ |
| 138 | template <typename FreeType> |
| 139 | int ExerciseDelete(FreeType f) |
| 140 | { |
| 141 | int errors = 0; |
| 142 | |
| 143 | std::cout << "Starting tests for free type: " << f.value << std::endl; |
| 144 | |
| 145 | std::vector<vtkAbstractArray*> arrays; |
| 146 | arrays.push_back(vtkStringArray::New()); |
| 147 | arrays.push_back(vtkBitArray::New()); |
| 148 | arrays.push_back(vtkFloatArray::New()); |
| 149 | arrays.push_back(vtkAOSDataArrayTemplate<double>::New()); |
| 150 | arrays.push_back(vtkSOADataArrayTemplate<double>::New()); |
| 151 | arrays.push_back(vtkScaledSOADataArrayTemplate<double>::New()); |
| 152 | constexpr std::size_t size = 5000; |
| 153 | for (auto it = arrays.begin(); it != arrays.end(); ++it) |
| 154 | { |
| 155 | |
| 156 | vtkAbstractArray* array = *it; |
| 157 | |
| 158 | // test setting the array's memory and having it not free the memory |
| 159 | void* ptr = make_allocation(f, size, array->GetDataType()); |
| 160 | errors += assign_void_array(f, array, ptr, size, false); |
| 161 | |
| 162 | // ask array to free memory, ptr should still be valid |
| 163 | array->Initialize(); |
| 164 | |
| 165 | // This time ask the array to free the memory |
| 166 | errors += assign_void_array(f, array, ptr, size, true); |
| 167 | |
| 168 | // if we are a lambda we need to set the real free function |
| 169 | assign_user_free(f, array); |
| 170 | |
| 171 | // free the memory for real this time |
| 172 | array->Initialize(); |
| 173 | } |
| 174 | |
| 175 | for (auto it = arrays.begin(); it != arrays.end(); ++it) |
| 176 | { |
| 177 | vtkAbstractArray* array = *it; |
| 178 | array->Delete(); |
| 179 | } |
| 180 | |
| 181 | return errors; |
| 182 | } |
| 183 | |
| 184 | } // end anon namespace |
| 185 |
no test coverage detected