| 10 | #include <stdexcept> |
| 11 | |
| 12 | int TestAbstractArraySize(int vtkNotUsed(argc), char* vtkNotUsed(argv)[]) |
| 13 | { |
| 14 | int status = 0; |
| 15 | vtkNew<vtkStringArray> stringArray; |
| 16 | stringArray->SetNumberOfComponents(2); |
| 17 | stringArray->SetNumberOfTuples(1); |
| 18 | std::cout << "Size is now " << stringArray->GetSize() << "\n"; |
| 19 | if (stringArray->GetMaxId() < 1) |
| 20 | { |
| 21 | std::cerr << "Allocation failed: number of tuples requested not provided.\n"; |
| 22 | status = 1; |
| 23 | } |
| 24 | // Test for regression |
| 25 | stringArray->SetValue(0, "This value is OK."); |
| 26 | stringArray->SetValue(1, "This used to crash, even though GetMaxId reported a proper size."); |
| 27 | |
| 28 | // Test for desired behavior |
| 29 | stringArray->SetNumberOfValues(3); |
| 30 | std::cout << "Size is now " << stringArray->GetSize() << "\n"; |
| 31 | if (stringArray->GetSize() < 4) |
| 32 | { |
| 33 | std::cerr |
| 34 | << "Allocation failed: SetNumberOfValues should always allocate to a tuple boundary.\n"; |
| 35 | status = 1; |
| 36 | } |
| 37 | // Same as above, but test a vtkDataArray subclass. |
| 38 | vtkNew<vtkDoubleArray> doubleArray; |
| 39 | doubleArray->SetNumberOfComponents(3); |
| 40 | doubleArray->SetNumberOfValues(7); |
| 41 | if (doubleArray->GetSize() != 9) |
| 42 | { |
| 43 | std::cerr |
| 44 | << "Allocation failed: SetNumberOfValues should always allocate to a tuple boundary.\n"; |
| 45 | status = 1; |
| 46 | } |
| 47 | |
| 48 | return status; |
| 49 | } |
nothing calls this directly
no test coverage detected