YACA: Use local test-vectors when available 11/82611/3
authorLukasz Pawelczyk <l.pawelczyk@samsung.com>
Thu, 4 Aug 2016 11:15:50 +0000 (13:15 +0200)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Fri, 5 Aug 2016 10:03:18 +0000 (12:03 +0200)
Copy test-vectors to the local build dir and use them instead if
available. This makes possible to run the tests without "make install"
directly in the cmake build directory.

Change-Id: I4041cf669960e4b199aa14adfb8c17a9c991be2c

src/yaca/CMakeLists.txt
src/yaca/yaca-test-vector.cpp

index 38d6651763106a9b99786946be13a6778d29da73..303e75f7410a17127c9c68c18d8dd9ec0e18d50f 100644 (file)
@@ -29,6 +29,10 @@ FILE(GLOB  yaca_test_SRCS *.cpp)
 SET(YACA_TEST "yaca-test")
 ADD_EXECUTABLE(${YACA_TEST} ${yaca_test_SRCS})
 
+ADD_CUSTOM_TARGET(copy-test-vectors ALL
+                  COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/test-vectors ${CMAKE_CURRENT_BINARY_DIR}/test-vectors
+                  DEPENDS ${YACA_TEST})
+
 IF(NOT DEFINED YACA_TEST_DIR)
        SET(YACA_TEST_DIR "${SHARE_INSTALL_PREFIX}/${YACA_TEST}")
 ENDIF(NOT DEFINED YACA_TEST_DIR)
@@ -49,4 +53,4 @@ TARGET_LINK_LIBRARIES(${YACA_TEST}
 ## Install #####################################################################
 INSTALL(TARGETS ${YACA_TEST} DESTINATION bin)
 
-INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test-vectors DESTINATION ${YACA_TEST_DIR})
\ No newline at end of file
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/test-vectors DESTINATION ${YACA_TEST_DIR})
index b0c2087df1342323d4cec7c4136f18300f09f2e6..5b2011d9ed8790264a9d8fc32ec56d1d9bbf45d0 100644 (file)
@@ -183,13 +183,16 @@ std::string TestVector::value(const std::string &key) const
 
 TestVectorVector loadTestVector(const std::string &filename)
 {
-    std::string path = std::string(YACA_TEST_DIR"/test-vectors/") + filename;
+    std::string path_local = std::string("./test-vectors/") + filename;
+    std::string path_shared = std::string(YACA_TEST_DIR"/test-vectors/") + filename;
 
     TestVectorVector tvv;
 
-    std::ifstream ifs(path, std::ifstream::in);
+    std::ifstream ifs(path_local, std::ifstream::in);
+    if (!ifs)
+        ifs.open(path_shared, std::ifstream::in);
 
-    RUNNER_ASSERT_MSG(ifs, "Failed to open " << path);
+    RUNNER_ASSERT_MSG(ifs, "Failed to open " << filename);
     std::string line;
     TestVector tv;
     while (std::getline(ifs, line))
@@ -215,7 +218,7 @@ TestVectorVector loadTestVector(const std::string &filename)
         if (ifs.eof())
             break;
     }
-    RUNNER_ASSERT_MSG(ifs.eof(), "Failed to read " << path);
+    RUNNER_ASSERT_MSG(ifs.eof(), "Failed to read " << filename);
     if (!tv.empty())
         tvv.push_back(tv);
     return tvv;