I have a unit test which needs external data which is in a file unit_test_data
. I would like unit_test_data
to travel together with the source code (also in the version control system). But I do not know how to make the unit test aware of the location of unit_test_data
in the file system. The qmake
system knows the location, but how can it pass this knowledge to the code?
#include <ifstream>
void test()
{
std::string path = path_to_file + "/unit_test_data";
// How can I pass this ^ from qmake?
std::ifstream(path.c_str());
...
}
You can define a new macro, in the .pro
file:
DEFINES += FILENAME=\\\"/unit_test_data\\\"
As you see the issue is that is has to be quoted twice.
And then, in the C++ code, use the macro expansion:
std::string path = path_to_file + FILENAME;