[vtk-developers] New testing utility: vtkPermuteOptions

Allie Vacanti allison.vacanti at kitware.com
Fri Jan 19 06:59:49 EST 2018


Hi folks,

Firstly, I'm so happy that we've enabled C++11 in VTK :-)

I have a merge request for a new testing utility that you may find useful.
While adding support for bit arrays to the XML writers, I needed to make
sure that the new functionality worked no matter which combination of
writer settings were used (byte order, data mode, compression, etc).

To make this easier, I added a class template that will do exactly that --
you specify options and possible values, and vtkPermuteOptions will
simplify testing all possible combinations of these, e.g.

// vtkPermuteOptions is templated on the class that gets configured:
vtkPermuteOptions<vtkXMLWriter> config;

// Add option ByteOrder with values BigEndian and LittleEndian
// in separate AddOptionValue calls:
this->AddOptionValue("ByteOrder", &vtkXMLWriter::SetByteOrder,
                     "BigEndian", vtkXMLWriter::BigEndian);
this->AddOptionValue("ByteOrder", &vtkXMLWriter::SetByteOrder,
                     "LittleEndian", vtkXMLWriter::LittleEndian);

// Add option CompressorType with values NONE, ZLIB, and LZ4
// in a single AddOptionValues call:
this->AddOptionValues("CompressorType", &vtkXMLWriter::SetCompressorType,
                       "NONE", vtkXMLWriter::NONE,
                       "ZLIB", vtkXMLWriter::ZLIB,
                       "LZ4", vtkXMLWriter::LZ4);

// Generate the permutation list:
config.InitPermutations();

// Loop through all combinations of options
while (!config.IsDoneWithPermutations())
{
  // Apply the current option permutation to a vtkXMLWriter object:
  vtkXMLWriter *writer = ...;
  config.ApplyCurrentPermutation(writer);

  // Testing code:
  std::cout << "Testing " << config.GetCurrentPermutationName() << "\n";
  runTest(writer);

  config.GoToNextPermutation();
}

In this example, runTest will be called 6 times, while varying the
specified options:

Test Iteration    ByteOrder         CompressorType
--------------    ---------         --------------
1                 BigEndian         NONE
2                 BigEndian         ZLIB
3                 BigEndian         LZ4
4                 LittleEndian      NONE
5                 LittleEndian      ZLIB
6                 LittleEndian      LZ4

I figured I'd mention this here, since I've found myself wanting this
capability several times over the years and thought it may be of general
interest. The merge request is up here:

https://gitlab.kitware.com/vtk/vtk/merge_requests/3808

Also, I'm open to a name change if anyone wants to flex their knowledge of
mathematics ;) I'm not 100% sure that "permutation" is the best name for
this sort of operation.

Cheers,
Allie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtk-developers/attachments/20180119/b300e008/attachment.html>


More information about the vtk-developers mailing list