Skip to content

Commit

Permalink
Use more robust pattern to access test files
Browse files Browse the repository at this point in the history
Summary: This pattern appears to be more robust. Let's update all our tests to use it consistently.

Reviewed By: finik

Differential Revision: D58042789

fbshipit-source-id: 11a17374ee2b0b1920e242c0d0c8bc5c788d8205
  • Loading branch information
Georges Berenger authored and facebook-github-bot committed Jun 3, 2024
1 parent b4008a0 commit 9f2871f
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 33 deletions.
34 changes: 17 additions & 17 deletions tools/vrs/test/VrsAppTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct VrsAppTest : testing::Test {};

TEST_F(VrsAppTest, ANDROID_DISABLED(VrsAppTest)) {
VrsProcess vrs;
const string kChunkedFile = getTestDataDir() + "/VRS_Files/chunks.vrs";
const string kChunkedFile = os::pathJoin(getTestDataDir(), "VRS_Files/chunks.vrs");
const string outputFile = os::getTempFolder() + "VrsAppTest.vrs";

// test copying the chunked file into a single file
Expand All @@ -126,7 +126,7 @@ TEST_F(VrsAppTest, ANDROID_DISABLED(VrsAppTest)) {

TEST_F(VrsAppTest, ANDROID_DISABLED(limitedVrsAppTest)) {
VrsProcess vrs;
const string kChunkedFile = getTestDataDir() + "/VRS_Files/simulated.vrs";
const string kChunkedFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated.vrs");
const string outputFile = os::getTempFolder() + "limitedVrsAppTest.vrs";

vector<string> args = {
Expand Down Expand Up @@ -174,7 +174,7 @@ static void checkTag(const map<string, string>& tags, const string& name, const

TEST_F(VrsAppTest, ANDROID_DISABLED(copyWithTags)) {
VrsProcess vrs;
const string inputFile = getTestDataDir() + "/VRS_Files/simulated.vrs";
const string inputFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated.vrs");
const string outputFile = os::getTempFolder() + "copyWithTags.vrs";

// test copying a piece of file (to be faster), and add tags.
Expand All @@ -201,8 +201,8 @@ TEST_F(VrsAppTest, ANDROID_DISABLED(copyWithTags)) {

TEST_F(VrsAppTest, ANDROID_DISABLED(merge2FilesTest)) {
VrsProcess vrs;
const string kFirstFile = getTestDataDir() + "/VRS_Files/simulated.vrs";
const string kSecondFile = getTestDataDir() + "/VRS_Files/simulated2.vrs";
const string kFirstFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated.vrs");
const string kSecondFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated2.vrs");
const string outputFile = os::getTempFolder() + "merge2FilesTest.vrs";

// test merging two files into a single file, keeping streams separate
Expand Down Expand Up @@ -231,8 +231,8 @@ TEST_F(VrsAppTest, ANDROID_DISABLED(merge2FilesTest)) {

TEST_F(VrsAppTest, ANDROID_DISABLED(fuseTest)) {
VrsProcess vrs;
const string kFirstFile = getTestDataDir() + "/VRS_Files/simulated.vrs";
const string kSecondFile = getTestDataDir() + "/VRS_Files/simulated2.vrs";
const string kFirstFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated.vrs");
const string kSecondFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated2.vrs");
const string outputFile = os::getTempFolder() + "fuseTest.vrs";

// test merging two files into a single file, merging streams with the same RecordableTypeId
Expand All @@ -259,8 +259,8 @@ TEST_F(VrsAppTest, ANDROID_DISABLED(fuseTest)) {

TEST_F(VrsAppTest, ANDROID_DISABLED(mergeRecordablesFilterTest)) {
VrsProcess vrs;
const string kFirstFile = getTestDataDir() + "/VRS_Files/simulated.vrs";
const string kSecondFile = getTestDataDir() + "/VRS_Files/simulated2.vrs";
const string kFirstFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated.vrs");
const string kSecondFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated2.vrs");
const string outputFile = os::getTempFolder() + "mergeRecordablesFilterTest.vrs";

// test merging two files into a single file, filtering specific recordables
Expand All @@ -280,8 +280,8 @@ TEST_F(VrsAppTest, ANDROID_DISABLED(mergeRecordablesFilterTest)) {

TEST_F(VrsAppTest, ANDROID_DISABLED(mergeTimeFilterTest)) {
VrsProcess vrs;
const string kFirstFile = getTestDataDir() + "/VRS_Files/simulated.vrs";
const string kSecondFile = getTestDataDir() + "/VRS_Files/simulated2.vrs";
const string kFirstFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated.vrs");
const string kSecondFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated2.vrs");
const string outputFile = os::getTempFolder() + "mergeTimeFilterTest.vrs";

// test merging two files into a single file, filtering specific recordables
Expand All @@ -306,7 +306,7 @@ TEST_F(VrsAppTest, ANDROID_DISABLED(mergeTimeFilterTest)) {

TEST_F(VrsAppTest, ANDROID_DISABLED(chunkAndMergeTest)) {
VrsProcess vrs;
const string kOriginal = getTestDataDir() + "/VRS_Files/simulated.vrs";
const string kOriginal = os::pathJoin(getTestDataDir(), "VRS_Files/simulated.vrs");
const string kPart1 = os::getTempFolder() + "chunk1.vrs";
const string kPart2 = os::getTempFolder() + "chunk2.vrs";
const string kMerged = os::getTempFolder() + "chunkAndMergeTest.vrs";
Expand All @@ -324,7 +324,7 @@ TEST_F(VrsAppTest, ANDROID_DISABLED(chunkAndMergeTest)) {

TEST_F(VrsAppTest, ANDROID_DISABLED(decimateTest)) {
VrsProcess vrs;
const string inputFile = getTestDataDir() + "/VRS_Files/simulated.vrs";
const string inputFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated.vrs");
const string outputFile = os::getTempFolder() + "decimateTest.vrs";

EXPECT_TRUE(vrs.start(
Expand Down Expand Up @@ -353,7 +353,7 @@ TEST_F(VrsAppTest, ANDROID_DISABLED(decimateTest)) {

TEST_F(VrsAppTest, ANDROID_DISABLED(relativeRangeTest)) {
VrsProcess vrs;
const string inputFile = getTestDataDir() + "/VRS_Files/simulated.vrs";
const string inputFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated.vrs");
const string outputFile = os::getTempFolder() + "relativeRangeTest.vrs";

// Copy a sub-range of data records, while keeping the config & state records,
Expand Down Expand Up @@ -388,21 +388,21 @@ TEST_F(VrsAppTest, ANDROID_DISABLED(relativeRangeTest)) {

TEST_F(VrsAppTest, ANDROID_DISABLED(syntaxErrorTest)) {
VrsProcess vrs;
const string kFirstFile = getTestDataDir() + "/VRS_Files/simulated.vrs";
const string kFirstFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated.vrs");
EXPECT_TRUE(vrs.start(kFirstFile + " -not-a-command"));
ASSERT_NE(vrs.runProcess(), 0);
}

TEST_F(VrsAppTest, ANDROID_DISABLED(noErrorTest)) {
VrsProcess vrs;
const string kFirstFile = getTestDataDir() + "/VRS_Files/not-a-file.vrs";
const string kFirstFile = os::pathJoin(getTestDataDir(), "VRS_Files/not-a-file.vrs");
EXPECT_TRUE(vrs.start(kFirstFile));
ASSERT_NE(vrs.runProcess(), 0);
}

TEST_F(VrsAppTest, ANDROID_DISABLED(badFileErrorTest)) {
VrsProcess vrs;
const string kFirstFile = getTestDataDir() + "/VRS_Files/simulated.vrs";
const string kFirstFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated.vrs");
const string outputFile = os::getTempFolder() + "bad-file-!*:/";
EXPECT_TRUE(vrs.start(kFirstFile + " -c " + outputFile));
ASSERT_NE(vrs.runProcess(), 0);
Expand Down
11 changes: 6 additions & 5 deletions tools/vrs/test/VrsCommandTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <vrs/VrsCommand.h>

using namespace std;
using namespace vrs;
using namespace vrs::utils;
using namespace vrscli;

Expand Down Expand Up @@ -59,9 +60,9 @@ bool parse(VrsCommand& command, vector<string>& args, int& argn, int& outStatusC
TEST_F(VrsCommandTest, miscCommands) {
int argn = 1;
int statusCode = EXIT_SUCCESS;
const string inputFile = getTestDataDir() + "/VRS_Files/simulated.vrs";
const string inputFile2 = getTestDataDir() + "/VRS_Files/sample_file.vrs";
const string outputFile = getTestDataDir() + "/VRS_Files/some_output.vrs";
const string inputFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated.vrs");
const string inputFile2 = os::pathJoin(getTestDataDir(), "VRS_Files/sample_file.vrs");
const string outputFile = os::pathJoin(getTestDataDir(), "VRS_Files/some_output.vrs");

{
vector<string> args = {"vrs", "check", inputFile};
Expand Down Expand Up @@ -196,7 +197,7 @@ TEST_F(VrsCommandTest, miscCommands) {
}

TEST_F(VrsCommandTest, ArgTestsGood) {
const string inputFile = getTestDataDir() + "/VRS_Files/simulated.vrs";
const string inputFile = os::pathJoin(getTestDataDir(), "VRS_Files/simulated.vrs");

int argn = 1;
int statusCode = EXIT_SUCCESS;
Expand Down Expand Up @@ -249,7 +250,7 @@ TEST_F(VrsCommandTest, ArgTestsGood) {
}

TEST_F(VrsCommandTest, ArgTestsBad) {
const string inputFile = getTestDataDir() + "/VRS_Files/sample_file.vrs";
const string inputFile = os::pathJoin(getTestDataDir(), "VRS_Files/sample_file.vrs");

int argn = 1;
int statusCode = EXIT_SUCCESS;
Expand Down
4 changes: 2 additions & 2 deletions vrs/test/GetRecordTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ using namespace vrs;

namespace {
struct GetRecordTester : testing::Test {
string kTestFile = string(coretech::getTestDataDir()) + "/VRS_Files/sample_file.vrs";
string kTestFile2 = string(coretech::getTestDataDir()) + "/VRS_Files/simulated.vrs";
string kTestFile = os::pathJoin(coretech::getTestDataDir(), "VRS_Files/sample_file.vrs");
string kTestFile2 = os::pathJoin(coretech::getTestDataDir(), "VRS_Files/simulated.vrs");
};
} // namespace

Expand Down
8 changes: 4 additions & 4 deletions vrs/test/file_tests/ChunkedFileTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ int addPies(DiskFile& file, const string& path) {
} // namespace

struct ChunkedFileTester : testing::Test {
string kChunkedFile = getTestDataDir() + "/VRS_Files/chunks.vrs";
string kChunkedFile2 = getTestDataDir() + "/VRS_Files/chunks.vrs_1";
string kChunkedFile3 = getTestDataDir() + "/VRS_Files/chunks.vrs_2";
string kMissingFile = getTestDataDir() + "/VRS_Files/does_not_exist.vrs";
string kChunkedFile = os::pathJoin(getTestDataDir(), "VRS_Files/chunks.vrs");
string kChunkedFile2 = os::pathJoin(getTestDataDir(), "VRS_Files/chunks.vrs_1");
string kChunkedFile3 = os::pathJoin(getTestDataDir(), "VRS_Files/chunks.vrs_2");
string kMissingFile = os::pathJoin(getTestDataDir(), "VRS_Files/does_not_exist.vrs");
};

static const char* kChunkedFileStreamSignature =
Expand Down
4 changes: 2 additions & 2 deletions vrs/test/file_tests/FileCacheTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ void createRecordsThreadTask(ThreadParam* param) {
}

TEST_F(FileCacheTest, detailsTest) {
string kTestFile = string(coretech::getTestDataDir()) + "/VRS_Files/sample_file.vrs";
string kTestFile = os::pathJoin(coretech::getTestDataDir(), "VRS_Files/sample_file.vrs");
const string cacheFile = os::getTempFolder() + "detailsTest.vrsi";
RecordFileReader reader;
ASSERT_EQ(reader.openFile(kTestFile), 0);
Expand All @@ -163,7 +163,7 @@ TEST_F(FileCacheTest, detailsTest) {
}

TEST_F(FileCacheTest, memoryVrsFileTest) {
string kTestFile = string(coretech::getTestDataDir()) + "/VRS_Files/sample_file.vrs";
string kTestFile = os::pathJoin(coretech::getTestDataDir(), "VRS_Files/sample_file.vrs");

vector<uint8_t> vrsfile;
DiskFile file;
Expand Down
6 changes: 3 additions & 3 deletions vrs/test/file_tests/SimpleFileHandlerTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,9 @@ TEST_F(SimpleFileHandlerTest, openFileWithJsonPath) {

TEST_F(SimpleFileHandlerTest, openFileWithJsonPathForExistingFiles) {
vrs::RecordFileReader file;
string kChunkedFile = coretech::getTestDataDir() + "/VRS_Files/chunks.vrs";
string kChunkedFile2 = coretech::getTestDataDir() + "/VRS_Files/chunks.vrs_1";
string kChunkedFile3 = coretech::getTestDataDir() + "/VRS_Files/chunks.vrs_2";
string kChunkedFile = os::pathJoin(coretech::getTestDataDir(), "VRS_Files/chunks.vrs");
string kChunkedFile2 = os::pathJoin(coretech::getTestDataDir(), "VRS_Files/chunks.vrs_1");
string kChunkedFile3 = os::pathJoin(coretech::getTestDataDir(), "VRS_Files/chunks.vrs_2");
const string jsonPath = FileSpec({kChunkedFile, kChunkedFile2, kChunkedFile3}).toJson();
ASSERT_EQ(file.openFile(jsonPath), 0);
EXPECT_EQ(file.getRecordCount(), 306); // number of records if all chunks are found
Expand Down

0 comments on commit 9f2871f

Please sign in to comment.