4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 // Stefan Bund <stefan.bund@fokus.fraunhofer.de>
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 //#include "FileHandle.test.hh"
26 //#include "FileHandle.test.ih"
32 #include "FileHandle.hh"
34 #include <boost/test/auto_unit_test.hpp>
35 #include <boost/test/test_tools.hpp>
38 ///////////////////////////////cc.p////////////////////////////////////////
41 class FHandle : public senf::FileHandle
46 : senf::FileHandle(std::auto_ptr<senf::FileBody>(
47 new senf::FileBody(fd))) {}
48 FHandle(std::string const & name)
49 : senf::FileHandle(std::auto_ptr<senf::FileBody>(
50 new senf::FileBody()))
52 int rv = ::open(name.c_str(),O_RDWR|O_NONBLOCK) ;
54 throw senf::SystemException(errno);
60 BOOST_AUTO_UNIT_TEST(fileHandle)
64 FHandle fh("/dev/null");
65 BOOST_CHECK(fh.fd() != -1);
66 BOOST_CHECK(fh.valid());
71 BOOST_CHECK( ! fh2.valid() );
73 BOOST_CHECK_EQUAL(fh.fd(), fh2.fd());
75 BOOST_CHECK(fh.writeable());
76 BOOST_CHECK_NO_THROW(fh.close());
77 BOOST_CHECK_THROW(fh.close(),senf::SystemException);
78 BOOST_CHECK_NO_THROW(fh.terminate());
82 FHandle fh("/dev/zero");
83 BOOST_CHECK(fh.readable());
88 BOOST_REQUIRE(pipe(fds) == 0);
91 BOOST_CHECK(!fh.readable());
93 // Set non-blocking IO and fill the pipe buffer
94 int flags = fcntl(fds[1],F_GETFL,0);
96 BOOST_FAIL(strerror(errno));
97 if (fcntl(fds[1],F_SETFL,flags|O_NONBLOCK) == -1)
98 BOOST_FAIL(strerror(errno));
100 while (write(fds[1],buffer,1024) == 1024) ;
103 BOOST_CHECK(!fh.writeable());
106 catch (std::exception const & ex) {
107 BOOST_FAIL(ex.what());
111 ///////////////////////////////cc.e////////////////////////////////////////
118 // c-file-style: "senf"
119 // indent-tabs-mode: nil
120 // ispell-local-dictionary: "american"
121 // compile-command: "scons -u test"
122 // comment-column: 40