Add a helper class to generate temp paths for tests

This commit is contained in:
Thomas Goyne 2016-01-26 10:33:53 -08:00
parent b7b2822082
commit 773e7db14d
3 changed files with 55 additions and 3 deletions

View File

@ -1,11 +1,17 @@
include_directories(../external/catch/single_include)
include_directories(../external/catch/single_include .)
set(HEADERS
util/test_file.hpp
)
set(SOURCES
index_set.cpp
main.cpp
parser.cpp)
parser.cpp
util/test_file.cpp
)
add_executable(tests ${SOURCES})
add_executable(tests ${SOURCES} ${HEADERS})
target_link_libraries(tests realm-object-store)
add_custom_target(run-tests USES_TERMINAL DEPENDS tests COMMAND ./tests)

31
tests/util/test_file.cpp Normal file
View File

@ -0,0 +1,31 @@
#include "util/test_file.hpp"
#include <realm/disable_sync_to_disk.hpp>
#include <cstdlib>
#include <unistd.h>
TestFile::TestFile()
{
static std::string tmpdir = [] {
realm::disable_sync_to_disk();
const char* dir = getenv("TMPDIR");
if (dir && *dir)
return dir;
return "/tmp";
}();
path = tmpdir + "/realm.XXXXXX";
mktemp(&path[0]);
unlink(path.c_str());
}
TestFile::~TestFile()
{
unlink(path.c_str());
}
InMemoryTestFile::InMemoryTestFile()
{
in_memory = true;
}

15
tests/util/test_file.hpp Normal file
View File

@ -0,0 +1,15 @@
#ifndef REALM_TEST_UTIL_TEST_FILE_HPP
#define REALM_TEST_UTIL_TEST_FILE_HPP
#include "shared_realm.hpp"
struct TestFile : realm::Realm::Config {
TestFile();
~TestFile();
};
struct InMemoryTestFile : TestFile {
InMemoryTestFile();
};
#endif