]> git.llucax.com Git - software/posixx.git/commitdiff
Use open() instead of close() for testing posixx::error
authorLeandro Lucarella <llucarella@integratech.com.ar>
Thu, 18 Sep 2008 22:43:15 +0000 (19:43 -0300)
committerLeandro Lucarella <llucarella@integratech.com.ar>
Fri, 19 Sep 2008 20:08:41 +0000 (17:08 -0300)
Closing an invalid file descriptor triggers a valgrind error and makes
'make memtest' fail.

test/error.cpp

index 03996b5270e7ceb00a210c971324910d9db584ba..7726da27d1105ae803c0eb35ad31beb4992d2b5c 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <boost/test/unit_test.hpp>
 #include <string>
-#include <unistd.h>
+#include <fcntl.h>
 
 BOOST_AUTO_TEST_SUITE( error_suite )
 
@@ -11,18 +11,18 @@ BOOST_AUTO_TEST_CASE( constructor_test )
 {
 
        // default constructor
-       close(-123);
+       open("/non/existent", 0);
        posixx::error e1;
-       BOOST_CHECK_EQUAL(e1.no, EBADF);
+       BOOST_CHECK_EQUAL(e1.no, ENOENT);
 
        // "where" string constructor
-       close(-123);
-       posixx::error e2("fopen");
-       BOOST_CHECK_EQUAL(e2.no, EBADF);
-       BOOST_CHECK_EQUAL(std::string(e2.what()).find("fopen: "), 0);
+       open("/non/existent", 0);
+       posixx::error e2("open");
+       BOOST_CHECK_EQUAL(e2.no, ENOENT);
+       BOOST_CHECK_EQUAL(std::string(e2.what()).find("open: "), 0);
 
        // e1 and e2 should be the same appart from the "where" string
-       BOOST_CHECK_EQUAL(std::string(e2.what()).substr(7), e1.what());
+       BOOST_CHECK_EQUAL(std::string(e2.what()).substr(6), e1.what());
 
 }