test file for non-portable IO extension(s)

brent verner brent@rcfile.org
Thu Jun 15 00:15:00 GMT 2000


Hi,

    To demonstrate a bug in (non-)std::filebuf, I present this little
test  case. I've got a fair idea of where to solve the problem, but
time has outpaced me tonight :) In any event, if we are gonna ship
non-portable extensions, we should make sure we are shipping
_good_/_safe_ ones.

  Brent

--
Sometimes it's quite satisfying to be the MillionthMonkey.

=======================================================================
// Copyright (C) 1997-1999, 2000 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library.  This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 2, or (at your option)
// any later version.

// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.

// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING.  If not, write to the Free
// Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
// USA.

// testsuite/27_io/NP_extensions.cc
//      various tests for the non-portable functionality in the 
//      libstdc++-v3 IO library

#include <fstream>
#include <cassert>

extern "C" {
#include <unistd.h>
#include <fcntl.h>
}

// ------------------------------------------------------------ test_01
//
// verify that std::filebuf doesn't close files that it didn't open
// when using the following std::filebuf ctor:
//
//      std::filebuf(int __fd,
//                   const char* __unused,
//                   ios_base::openmode __mode);
//
// thanks to "George T. Talbot" <george@moberg.com> for uncovering
// this bug/situation. 

int
test_01()
{
  // I hope this file is in testsuite/ by the time this
  // file is compiled/run
  const char* known_file = "testsuite/filebuf-1.txt";
  int fd = open(known_file, O_RDONLY);

#ifdef DEBUG_ASSERT
  assert( fd >= 0 );
#endif
  
  {
    std::filebuf fb(fd);
  }
  
#ifdef DEBUG_ASSERT
  assert( close(fd) == 0 );
#endif
  
  return 0;
}

//---------------------------------------------------------------------

int
main()
{
  test_01();
  return 0;
}



More information about the Libstdc++ mailing list