Repository: nifi-minifi-cpp
Updated Branches:
  refs/heads/master 58c21e0bf -> e98ff6844


MINIFI-367 port tests to use boost::filesystem vs. stat.h for better portability

This closes #124.

Signed-off-by: Marc Parisi <phroc...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/repo
Commit: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/commit/e98ff684
Tree: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/tree/e98ff684
Diff: http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/diff/e98ff684

Branch: refs/heads/master
Commit: e98ff6844b059763d587b0151c016c466a330461
Parents: 58c21e0
Author: Andrew I. Christianson <achristian...@hortonworks.com>
Authored: Tue Aug 8 13:16:19 2017 -0400
Committer: Marc Parisi <phroc...@apache.org>
Committed: Wed Aug 9 10:11:41 2017 -0400

----------------------------------------------------------------------
 libminifi/CMakeLists.txt             |  3 ++-
 libminifi/test/unit/PutFileTests.cpp | 22 ++++++----------------
 2 files changed, 8 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/e98ff684/libminifi/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/libminifi/CMakeLists.txt b/libminifi/CMakeLists.txt
index a78fd8f..5e63a30 100644
--- a/libminifi/CMakeLists.txt
+++ b/libminifi/CMakeLists.txt
@@ -80,9 +80,10 @@ target_link_libraries (minifi ${ZLIB_LIBRARIES})
 
 if (NOT IOS)
 # Include Boost System
-find_package(Boost COMPONENTS system REQUIRED)
+find_package(Boost COMPONENTS system filesystem REQUIRED)
 find_package(CURL)
 target_link_libraries(minifi ${Boost_SYSTEM_LIBRARY})
+target_link_libraries(minifi ${Boost_FILESYSTEM_LIBRARY})
 
 if (CURL_FOUND)
         include_directories(${CURL_INCLUDE_DIRS})

http://git-wip-us.apache.org/repos/asf/nifi-minifi-cpp/blob/e98ff684/libminifi/test/unit/PutFileTests.cpp
----------------------------------------------------------------------
diff --git a/libminifi/test/unit/PutFileTests.cpp 
b/libminifi/test/unit/PutFileTests.cpp
index c18c72c..024b6fa 100644
--- a/libminifi/test/unit/PutFileTests.cpp
+++ b/libminifi/test/unit/PutFileTests.cpp
@@ -25,6 +25,8 @@
 #include <set>
 #include <fstream>
 
+#include <boost/filesystem.hpp>
+
 #include "../TestBase.h"
 #include "processors/ListenHTTP.h"
 #include "processors/LogAttribute.h"
@@ -45,18 +47,6 @@ TEST_CASE("Test Creation of PutFile", "[getfileCreate]") {
   REQUIRE(processor->getName() == "processorname");
 }
 
-uint64_t getModificationTime(std::string filename) {
-  struct stat result;
-  if (stat(filename.c_str(), &result) == 0) {
-#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
-    return result.st_mtimespec.tv_sec;
-#else
-    return result.st_mtime;
-#endif
-  }
-  return 0;
-}
-
 TEST_CASE("PutFileTest", "[getfileputpfile]") {
   TestController testController;
 
@@ -231,7 +221,7 @@ TEST_CASE("PutFileTestFileExistsIgnore", 
"[getfileputpfile]") {
   file.open(movedFile.str(), std::ios::out);
   file << "tempFile";
   file.close();
-  uint64_t filemodtime = getModificationTime(movedFile.str());
+  auto filemodtime = boost::filesystem::last_write_time(movedFile.str());
 
   std::this_thread::sleep_for(std::chrono::milliseconds(1000));
   plan->reset();
@@ -252,7 +242,7 @@ TEST_CASE("PutFileTestFileExistsIgnore", 
"[getfileputpfile]") {
   // verify that the fle was moved
   REQUIRE(false == std::ifstream(ss.str()).good());
   REQUIRE(true == std::ifstream(movedFile.str()).good());
-  REQUIRE(filemodtime == getModificationTime(movedFile.str()));
+  REQUIRE(filemodtime == boost::filesystem::last_write_time(movedFile.str()));
   LogTestController::getInstance().reset();
 }
 
@@ -299,7 +289,7 @@ TEST_CASE("PutFileTestFileExistsReplace", 
"[getfileputpfile]") {
   file.open(movedFile.str(), std::ios::out);
   file << "tempFile";
   file.close();
-  uint64_t filemodtime = getModificationTime(movedFile.str());
+  auto filemodtime = boost::filesystem::last_write_time(movedFile.str());
 
   std::this_thread::sleep_for(std::chrono::milliseconds(1000));
   plan->reset();
@@ -320,7 +310,7 @@ TEST_CASE("PutFileTestFileExistsReplace", 
"[getfileputpfile]") {
   // verify that the fle was moved
   REQUIRE(false == std::ifstream(ss.str()).good());
   REQUIRE(true == std::ifstream(movedFile.str()).good());
-  REQUIRE(filemodtime != getModificationTime(movedFile.str()));
+  REQUIRE(filemodtime != boost::filesystem::last_write_time(movedFile.str()));
   LogTestController::getInstance().reset();
 }
 

Reply via email to