With resourcesΒΆ
If we need some resource file while testing it can be uploaded by adding
$<GAUZE_RESOURCE_FILE:...>
directive:
add_executable(gauze_resource main.cpp)
set(data_dir "${CMAKE_CURRENT_LIST_DIR}/data")
gauze_add_test(
NAME gauze_resource
COMMAND
gauze_resource
arg1
arg2
arg3
$<GAUZE_RESOURCE_FILE:${data_dir}/input.txt>
${data_dir}/just_a_string.txt
--input=$<GAUZE_RESOURCE_FILE:${data_dir}/input.txt>
)
Files specified with GAUZE_RESOURCE_FILE
will be uploaded to device
and path will be substituted with real path on device.
Note that similar string without GAUZE_RESOURCE_FILE
will be used as is:
add_executable(gauze_resource main.cpp)
set(data_dir "${CMAKE_CURRENT_LIST_DIR}/data")
gauze_add_test(
NAME gauze_resource
COMMAND
gauze_resource
arg1
arg2
arg3
$<GAUZE_RESOURCE_FILE:${data_dir}/input.txt>
${data_dir}/just_a_string.txt
--input=$<GAUZE_RESOURCE_FILE:${data_dir}/input.txt>
)
Read resource file:
#include <cstdlib> // EXIT_SUCCESS
#include <fstream> // std::ifstream
#include <iostream> // std::cout
#include <string> // std::getline
int gauze_main(int argc, char** argv) {
std::cout << "argc = " << argc << std::endl;
for (int i=0; i<argc; ++i) {
std::cout << "argv[" << i << "] = " << argv[i] << std::endl;
}
if(argc < 7) {
std::cerr << "Unexpected number of arguments: " << argc << std::endl;
return EXIT_FAILURE;
}
const char* filename = argv[4];
std::ifstream file(filename);
std::string content;
std::getline(file, content);
std::cout << "Content: '" << content << "'" << std::endl;
return EXIT_SUCCESS;
}
Running this test on Android device:
> ctest -VV -R gauze_resource
3: Command output (with exit code):
3: *** BEGIN ***
3: argc = 6
3: argv[0] = /data/local/tmp/gauze/android-ndk-r10e-api-19-armeabi-v7a-neon/bin/gauze_resource
3: argv[1] = arg1
3: argv[2] = arg2
3: argv[3] = arg3
3: argv[4] = /data/local/tmp/gauze/android-ndk-r10e-api-19-armeabi-v7a-neon/data/input.txt
3: argv[5] = /.../gauze/test/gauze/resource/data/just_a_string.txt
3: Content: 'Gauze resource file'
3: 0
3: *** END ***
3: Done
1/1 Test #3: gauze_resource ................... Passed 1.15 sec