From: Christoph Egger Date: Wed, 4 Mar 2015 15:10:43 +0000 (+0100) Subject: Allow tests to properly run from out-of-tree build directories X-Git-Tag: v0.1~74 X-Git-Url: https://git.siccegge.de//index.cgi?a=commitdiff_plain;h=48970b341025a501ca17b991e9a5d0ee7995ec30;p=frida%2Ffrida.git Allow tests to properly run from out-of-tree build directories Fixup gtest so it still finds the testcases if testing is started in a out-of-tree build. --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 7b86634..ae7acd7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,5 +101,5 @@ qt5_use_modules(fridatest Widgets) #ADD_SUBDIRECTORY(/usr/src/gtest gtest) ADD_SUBDIRECTORY(/usr/src/gmock gmock) enable_testing() -target_link_libraries(fridatest gmock gtest gmock_main ${QT_LIBRARIES} ${LLVM_LDFLAGS} -lLLVM-3.5 ${LLVM_SYSTEM_LIBS} ${LOG4CXX_LDFLAGS} ${GUILE_LDFLAGS} ${QUAZIP_LIBRARIES}) -add_test(NAME fridatest COMMAND fridatest WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}) +target_link_libraries(fridatest gmock gtest ${QT_LIBRARIES} ${LLVM_LDFLAGS} -lLLVM-3.5 ${LLVM_SYSTEM_LIBS} ${LOG4CXX_LDFLAGS} ${GUILE_LDFLAGS} ${QUAZIP_LIBRARIES}) +add_test(NAME fridatest COMMAND fridatest ${CMAKE_SOURCE_DIR}) diff --git a/src/core/tests/BasicBlockTest.cxx b/src/core/tests/BasicBlockTest.cxx index 0980af5..27072c8 100644 --- a/src/core/tests/BasicBlockTest.cxx +++ b/src/core/tests/BasicBlockTest.cxx @@ -5,8 +5,10 @@ #include "core/InformationManager.hxx" #include "core/BasicBlock.hxx" +extern char * TEST_DATA_DIRECTORY; + TEST(BasicBlockTest, deserializeValidInstance) { - QFile file("testdata/core/BasicBlock/valid.xml"); + QFile file(QString(TEST_DATA_DIRECTORY) + "/testdata/core/BasicBlock/valid.xml"); InformationManager manager; file.open(QFile::ReadOnly | QFile::Text); QXmlStreamReader reader(&file); @@ -22,7 +24,7 @@ TEST(BasicBlockTest, deserializeValidInstance) { } TEST(BasicBlockTest, deserializeInvalidInstance) { - QFile file("testdata/core/BasicBlock/invalid.xml"); + QFile file(QString(TEST_DATA_DIRECTORY) + "/testdata/core/BasicBlock/invalid.xml"); InformationManager manager; file.open(QFile::ReadOnly | QFile::Text); QXmlStreamReader reader(&file); @@ -34,7 +36,7 @@ TEST(BasicBlockTest, deserializeInvalidInstance) { } TEST(BasicBlockTest, deserializeThenSerializeIsIdentity) { - QFile infile("testdata/core/BasicBlock/valid.xml"); + QFile infile(QString(TEST_DATA_DIRECTORY) + "/testdata/core/BasicBlock/valid.xml"); QTemporaryFile outfile; InformationManager manager; diff --git a/src/core/tests/FunctionTest.cxx b/src/core/tests/FunctionTest.cxx index 5357bb9..0d3e56d 100644 --- a/src/core/tests/FunctionTest.cxx +++ b/src/core/tests/FunctionTest.cxx @@ -5,8 +5,10 @@ #include "core/BasicBlock.hxx" #include "core/Function.hxx" +extern char * TEST_DATA_DIRECTORY; + TEST(FunctionTest, deserializeValidInstance) { - QFile file("testdata/core/Function/valid.xml"); + QFile file(QString(TEST_DATA_DIRECTORY) + "/testdata/core/Function/valid.xml"); InformationManager manager; file.open(QFile::ReadOnly | QFile::Text); QXmlStreamReader reader(&file); diff --git a/src/test.cxx b/src/test.cxx index 100ee32..596fe3d 100644 --- a/src/test.cxx +++ b/src/test.cxx @@ -1,2 +1,14 @@ #include +char* TEST_DATA_DIRECTORY; + +int main(int argc, char **argv) { + testing::InitGoogleTest(&argc, argv); + + if (argc > 1) + TEST_DATA_DIRECTORY = argv[1]; + else + TEST_DATA_DIRECTORY = "./"; + + return RUN_ALL_TESTS(); +}