Allow test data path to be set by preprocessor symbol
Change-Id: I19c482c7cba34db574b3f33178ba20aede49779e
This commit is contained in:
@@ -18,16 +18,35 @@
|
|||||||
|
|
||||||
namespace libvpx_test {
|
namespace libvpx_test {
|
||||||
|
|
||||||
static FILE *OpenTestDataFile(const std::string& file_name) {
|
// Helper macros to ensure LIBVPX_TEST_DATA_PATH is a quoted string.
|
||||||
std::string path_to_source = file_name;
|
// These are undefined right below GetDataPath
|
||||||
const char *kDataPath = getenv("LIBVPX_TEST_DATA_PATH");
|
// NOTE: LIBVPX_TEST_DATA_PATH MUST NOT be a quoted string before
|
||||||
|
// Stringification or the GetDataPath will fail at runtime
|
||||||
|
#define TO_STRING(S) #S
|
||||||
|
#define STRINGIFY(S) TO_STRING(S)
|
||||||
|
|
||||||
if (kDataPath) {
|
// A simple function to encapsulate cross platform retrieval of test data path
|
||||||
path_to_source = kDataPath;
|
static std::string GetDataPath() {
|
||||||
path_to_source += "/";
|
const char *const data_path = getenv("LIBVPX_TEST_DATA_PATH");
|
||||||
path_to_source += file_name;
|
if (data_path == NULL) {
|
||||||
|
#ifdef LIBVPX_TEST_DATA_PATH
|
||||||
|
// In some environments, we cannot set environment variables
|
||||||
|
// Instead, we set the data path by using a preprocessor symbol
|
||||||
|
// which can be set from make files
|
||||||
|
return STRINGIFY(LIBVPX_TEST_DATA_PATH);
|
||||||
|
#else
|
||||||
|
return ".";
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
return data_path;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Undefining stringification macros because they are not used elsewhere
|
||||||
|
#undef TO_STRING
|
||||||
|
#undef STRINGIFY
|
||||||
|
|
||||||
|
static FILE *OpenTestDataFile(const std::string& file_name) {
|
||||||
|
const std::string path_to_source = GetDataPath() + "/" + file_name;
|
||||||
return fopen(path_to_source.c_str(), "rb");
|
return fopen(path_to_source.c_str(), "rb");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user