Skip to content

Commit

Permalink
GetSeedDataDirs: allow TEST_DATA_DIRS to be -D defined (#2162)
Browse files Browse the repository at this point in the history
This allows build/test environments to set the path if they are unable
influence the environment. This is based on the implementations in
libvpx and libaom.

Bug: https://crbug.com/329464135
  • Loading branch information
jzern authored May 21, 2024
1 parent 99c288a commit d369ffb
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/gtest/avif_fuzztest_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,22 @@ ::testing::Environment* SetEnv(const char* name, const char* value) {

//------------------------------------------------------------------------------

#ifdef TEST_DATA_DIRS
// Helper macros to ensure TEST_DATA_DIRS is a quoted string.
// NOTE: TEST_DATA_DIRS must NOT be a quoted string before stringification
// otherwise it will be quoted twice, resulting in the use of an incorrect path.
#define AVIF_TO_STRING(S) #S
#define AVIF_STRINGIFY(S) AVIF_TO_STRING(S)
#endif

std::vector<std::string> GetSeedDataDirs() {
const char* var = std::getenv("TEST_DATA_DIRS");
std::vector<std::string> res;
#ifdef TEST_DATA_DIRS
if (var == nullptr) {
var = AVIF_STRINGIFY(TEST_DATA_DIRS);
}
#endif
if (var == nullptr || *var == 0) return res;
const char* var_start = var;
while (true) {
Expand All @@ -203,6 +216,9 @@ std::vector<std::string> GetSeedDataDirs() {
return res;
}

#undef AVIF_STRINGIFY
#undef AVIF_TO_STRING

std::vector<std::string> GetTestImagesContents(
size_t max_file_size, const std::vector<avifAppFileFormat>& image_formats) {
// Use an environment variable to get the test data directory because
Expand Down

0 comments on commit d369ffb

Please sign in to comment.