Files
libcxx/test/std/input.output/file.streams/fstreams/filebuf.virtuals/seekoff.pass.cpp
Billy Robert O'Neal III c3ae85dbcf [libcxx] [test] Remove non-portable assertions from filebuf tests
seekoff.pass.cpp:
libc++'s tests are asserting things about the buffer passed to pubsetbuf. [filebuf.virtuals]/12 says that what the filebuf does with the buffer you give it is completely implementation defined. The MSVC++ implementation takes that buffer and hands it off to the CRT (by calling ::setvbuf) and the CRT doesn't necessarily follow the pattern this test wants.
This change simply makes asserts against the buffer's contents use LIBCPP_ASSERT instead of assert.

pbackfail.pass.cpp:
libc++'s tests are asserting about what characters will and will not be available in the putback area. [filebuf.virtuals]/9 says "The function can alter the number of putback positions available as a result of any call." This change LIBCPP_ASSERTS libc++'s behavior, but checks invariants of the putback area independently.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@330999 91177308-0d34-0410-b5e6-96231b3b80d8
2018-04-26 22:18:33 +00:00

67 lines
2.3 KiB
C++

//===----------------------------------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is dual licensed under the MIT and the University of Illinois Open
// Source Licenses. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
// <fstream>
// pos_type seekoff(off_type off, ios_base::seekdir way,
// ios_base::openmode which = ios_base::in | ios_base::out);
// pos_type seekpos(pos_type sp,
// ios_base::openmode which = ios_base::in | ios_base::out);
#include <fstream>
#include <cassert>
#include "test_macros.h"
int main()
{
{
char buf[10];
typedef std::filebuf::pos_type pos_type;
std::filebuf f;
f.pubsetbuf(buf, sizeof(buf));
assert(f.open("seekoff.dat", std::ios_base::in | std::ios_base::out
| std::ios_base::trunc) != 0);
assert(f.is_open());
f.sputn("abcdefghijklmnopqrstuvwxyz", 26);
LIBCPP_ASSERT(buf[0] == 'v');
pos_type p = f.pubseekoff(-15, std::ios_base::cur);
assert(p == 11);
assert(f.sgetc() == 'l');
f.pubseekoff(0, std::ios_base::beg);
assert(f.sgetc() == 'a');
f.pubseekoff(-1, std::ios_base::end);
assert(f.sgetc() == 'z');
assert(f.pubseekpos(p) == p);
assert(f.sgetc() == 'l');
}
std::remove("seekoff.dat");
{
wchar_t buf[10];
typedef std::filebuf::pos_type pos_type;
std::wfilebuf f;
f.pubsetbuf(buf, sizeof(buf)/sizeof(buf[0]));
assert(f.open("seekoff.dat", std::ios_base::in | std::ios_base::out
| std::ios_base::trunc) != 0);
assert(f.is_open());
f.sputn(L"abcdefghijklmnopqrstuvwxyz", 26);
LIBCPP_ASSERT(buf[0] == L'v');
pos_type p = f.pubseekoff(-15, std::ios_base::cur);
assert(p == 11);
assert(f.sgetc() == L'l');
f.pubseekoff(0, std::ios_base::beg);
assert(f.sgetc() == L'a');
f.pubseekoff(-1, std::ios_base::end);
assert(f.sgetc() == L'z');
assert(f.pubseekpos(p) == p);
assert(f.sgetc() == L'l');
}
std::remove("seekoff.dat");
}