add get_free_diskspace()
[libi2ncommon] / test / test_filefunc.cpp
index 88515d1..fd1efb0 100644 (file)
@@ -41,6 +41,8 @@ on this file might be covered by the GNU General Public License.
 
 #include <filefunc.hxx>
 #include <daemonfunc.hpp>
+#include <pipestream.hxx>
+#include <stringfunc.hxx>
 
 #ifdef NOISEDEBUG
 #define DOUT(msg) std::cout << msg << std::endl
@@ -512,4 +514,22 @@ BOOST_AUTO_TEST_CASE(FileContentDiffersEqualSize)
     BOOST_CHECK_EQUAL( true, res );
 }
 
+BOOST_AUTO_TEST_CASE(FreeDiskSpace1)
+{
+    inpipestream cmd_df("df -B 1 --output=avail /tmp | tail -n 1");
+    string dfstr;
+    if (cmd_df)
+        getline(cmd_df, dfstr);
+
+    long long dfout=-1;
+    string_to<long long>(dfstr,dfout);
+
+    BOOST_CHECK_EQUAL( dfout, get_free_diskspace("/tmp") );
+}
+
+BOOST_AUTO_TEST_CASE(FreeDiskSpace2)
+{
+    BOOST_CHECK_EQUAL( -1, get_free_diskspace("/this/path/is/really/bogus") );
+}
+
 BOOST_AUTO_TEST_SUITE_END()