Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tools/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ target_include_directories(tool-test PRIVATE
${PROJECT_SOURCE_DIR}/tools-c++/src
)

target_compile_definitions(tool-test PRIVATE
"-DORC_EXAMPLE_DIR=${PROJECT_SOURCE_DIR}/examples"
"-DORC_BUILD_DIR=${PROJECT_BINARY_DIR}"
)

add_dependencies(tool-test tool-set)

if (TEST_VALGRIND_MEMCHECK)
Expand Down
28 changes: 7 additions & 21 deletions tools/test/ToolTest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,9 @@
#include <string>
#include <vector>

namespace {
const char* exampleDirectory = 0;
const char* buildDirectory = 0;
} // namespace

GTEST_API_ int main(int argc, char** argv) {
GOOGLE_PROTOBUF_VERIFY_VERSION;
std::cout << "ORC version: " << ORC_VERSION << "\n";
if (argc >= 2) {
exampleDirectory = argv[1];
} else {
exampleDirectory = "../examples";
}
if (argc >= 3) {
buildDirectory = argv[2];
} else {
buildDirectory = ".";
}
std::cout << "example dir = " << exampleDirectory << "\n";
if (buildDirectory) {
std::cout << "build dir = " << buildDirectory << "\n";
}
testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS();
google::protobuf::ShutdownProtobufLibrary();
Expand All @@ -77,12 +58,16 @@ int runProgram(const std::vector<std::string>& args, std::string& out, std::stri
return WEXITSTATUS(status);
}

#define ORC_TOOL_TEST_STRINGIFY(path) ORC_TOOL_TEST_STR(path)
#define ORC_TOOL_TEST_STR(path) #path

/**
* Get the name of the given example file.
* @param name the simple name of the example file
*/
std::string findExample(const std::string& name) {
std::string result = exampleDirectory;
#define ORC_EXAMPLE_DIR_STR ORC_TOOL_TEST_STRINGIFY(ORC_EXAMPLE_DIR)
std::string result = ORC_EXAMPLE_DIR_STR;
result += "/";
result += name;
return result;
Expand All @@ -93,7 +78,8 @@ std::string findExample(const std::string& name) {
* @param name the simple name of the executable
*/
std::string findProgram(const std::string& name) {
std::string result = buildDirectory;
#define ORC_BUILD_DIR_STR ORC_TOOL_TEST_STRINGIFY(ORC_BUILD_DIR)
std::string result = ORC_BUILD_DIR_STR;
result += "/";
result += name;
return result;
Expand Down
4 changes: 4 additions & 0 deletions tools/test/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@ exc = executable(
gtest_dep,
gmock_dep,
],
cpp_args: [
'-DORC_EXAMPLE_DIR=@0@'.format(meson.project_source_root() / 'examples'),
'-DORC_BUILD_DIR=@0@'.format(meson.project_build_root()),
],
)
test('tool-test', exc)
Loading