2.2. Generating The Mock Object Files

In the second step the XML file is processed and the C++ files are created. Each invocation of xml2mockpp creates a set consisting of two or more files depending on the given options and the XML file. The filenames are composed of the according C++ class name and the extension "_mock" plus some file specific suffix.

There are several options that influence the file creation process:

--gen-visitable-method

Generate files that use the visitable mock method approach.

--gen-chainable-method

Generate files that use chainableable mock methods.

--gen-user-ctor

By default the implementation of the constructors is placed in the implementation file for the mock methods. In case you have to adjust the constructor for special cases you can enable a third file for user defined constructors. If this file already exists, then the new content is written to a fourth file with the extension _user_mock.cpp.new. You can then move the new parts from there to the user defined implementation file.

--gen-class=classname

Without additional options each of the classes in the XML file result in a set of header and source files. If you want to create files for only a selected set of classes you have to pass the class name using this option. When you need more than one class you have to pass this option multiple times.

--file-name=filename.xml

The name of the XML file with the class data.

--dest-dir=dest-path

Without further options the resulting files are written to the current directory. If you want a different destination you provide the desired path with this parameter.

The following line creates the C++ files MockppIdlTest_mock.h and MockppIdlTest_mock.cpp from the XML file header-data.xml with a class MockppIdlTestMock. These files are based on visitable mock methods and they are written to the subdirectory tests. For better readability the long command line is broken into two lines.


  xml2mockpp  --gen-visitable-method --file-name=header-data.xml \
              --dest-dir=tests  --gen-class=MockppIdlTest