Move test into test/std subdirectory.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@224658 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2014-12-20 01:40:03 +00:00
parent 669a8a5a19
commit a90c6dd460
4817 changed files with 13 additions and 0 deletions

View File

@@ -0,0 +1,100 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// int_type get();
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" ");
std::istream is(&sb);
char c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == ' ');
assert(is.gcount() == 1);
}
{
testbuf<char> sb(" abc");
std::istream is(&sb);
char c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == ' ');
assert(is.gcount() == 1);
c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == 'a');
assert(is.gcount() == 1);
c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == 'b');
assert(is.gcount() == 1);
c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == 'c');
assert(is.gcount() == 1);
}
{
testbuf<wchar_t> sb(L" abc");
std::wistream is(&sb);
wchar_t c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == L' ');
assert(is.gcount() == 1);
c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == L'a');
assert(is.gcount() == 1);
c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == L'b');
assert(is.gcount() == 1);
c = is.get();
assert(!is.eof());
assert(!is.fail());
assert(c == L'c');
assert(is.gcount() == 1);
}
}

View File

@@ -0,0 +1,103 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& get(char_type& c);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" ");
std::istream is(&sb);
char c;
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == ' ');
assert(is.gcount() == 1);
}
{
testbuf<char> sb(" abc");
std::istream is(&sb);
char c;
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == ' ');
assert(is.gcount() == 1);
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == 'a');
assert(is.gcount() == 1);
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == 'b');
assert(is.gcount() == 1);
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == 'c');
assert(is.gcount() == 1);
}
{
testbuf<wchar_t> sb(L" abc");
std::wistream is(&sb);
wchar_t c;
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == L' ');
assert(is.gcount() == 1);
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == L'a');
assert(is.gcount() == 1);
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == L'b');
assert(is.gcount() == 1);
is.get(c);
assert(!is.eof());
assert(!is.fail());
assert(c == L'c');
assert(is.gcount() == 1);
}
}

View File

@@ -0,0 +1,99 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& get(char_type* s, streamsize n);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" \n \n ");
std::istream is(&sb);
char s[5];
is.get(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 2);
is.get(s, 5);
assert(!is.eof());
assert( is.fail());
assert(std::string(s) == "");
assert(is.gcount() == 0);
is.clear();
assert(is.get() == '\n');
is.get(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 4);
assert(is.get() == '\n');
is.get(s, 5);
assert( is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 1);
}
{
testbuf<wchar_t> sb(L" \n \n ");
std::wistream is(&sb);
wchar_t s[5];
is.get(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 2);
is.get(s, 5);
assert(!is.eof());
assert( is.fail());
assert(std::wstring(s) == L"");
assert(is.gcount() == 0);
is.clear();
assert(is.get() == L'\n');
is.get(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 4);
assert(is.get() == L'\n');
is.get(s, 5);
assert( is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 1);
}
}

View File

@@ -0,0 +1,99 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& get(char_type* s, streamsize n, char_type delim);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" * * ");
std::istream is(&sb);
char s[5];
is.get(s, 5, '*');
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 2);
is.get(s, 5, '*');
assert(!is.eof());
assert( is.fail());
assert(std::string(s) == "");
assert(is.gcount() == 0);
is.clear();
assert(is.get() == '*');
is.get(s, 5, '*');
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 4);
assert(is.get() == '*');
is.get(s, 5, '*');
assert( is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 1);
}
{
testbuf<wchar_t> sb(L" * * ");
std::wistream is(&sb);
wchar_t s[5];
is.get(s, 5, L'*');
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 2);
is.get(s, 5, L'*');
assert(!is.eof());
assert( is.fail());
assert(std::wstring(s) == L"");
assert(is.gcount() == 0);
is.clear();
assert(is.get() == L'*');
is.get(s, 5, L'*');
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 4);
assert(is.get() == L'*');
is.get(s, 5, L'*');
assert( is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 1);
}
}

View File

@@ -0,0 +1,88 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb);
#include <istream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
testbuf(const std::basic_string<CharT>& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
testbuf<char> sb("testing\n...");
std::istream is(&sb);
testbuf<char> sb2;
is.get(sb2);
assert(sb2.str() == "testing");
assert(is.good());
assert(is.gcount() == 7);
assert(is.get() == '\n');
is.get(sb2);
assert(sb2.str() == "testing...");
assert(is.eof());
assert(!is.fail());
assert(is.gcount() == 3);
}
{
testbuf<wchar_t> sb(L"testing\n...");
std::wistream is(&sb);
testbuf<wchar_t> sb2;
is.get(sb2);
assert(sb2.str() == L"testing");
assert(is.good());
assert(is.gcount() == 7);
assert(is.get() == L'\n');
is.get(sb2);
assert(sb2.str() == L"testing...");
assert(is.eof());
assert(!is.fail());
assert(is.gcount() == 3);
}
}

View File

@@ -0,0 +1,89 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& get(basic_streambuf<char_type,traits>& sb,
// char_type delim);
#include <istream>
#include <cassert>
template <class CharT>
class testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_streambuf<CharT> base;
std::basic_string<CharT> str_;
public:
testbuf()
{
}
testbuf(const std::basic_string<CharT>& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
}
std::basic_string<CharT> str() const
{return std::basic_string<CharT>(base::pbase(), base::pptr());}
protected:
virtual typename base::int_type
overflow(typename base::int_type __c = base::traits_type::eof())
{
if (__c != base::traits_type::eof())
{
int n = str_.size();
str_.push_back(__c);
str_.resize(str_.capacity());
base::setp(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data() + str_.size()));
base::pbump(n+1);
}
return __c;
}
};
int main()
{
{
testbuf<char> sb("testing*...");
std::istream is(&sb);
testbuf<char> sb2;
is.get(sb2, '*');
assert(sb2.str() == "testing");
assert(is.good());
assert(is.gcount() == 7);
assert(is.get() == '*');
is.get(sb2, '*');
assert(sb2.str() == "testing...");
assert(is.eof());
assert(!is.fail());
assert(is.gcount() == 3);
}
{
testbuf<wchar_t> sb(L"testing*...");
std::wistream is(&sb);
testbuf<wchar_t> sb2;
is.get(sb2, L'*');
assert(sb2.str() == L"testing");
assert(is.good());
assert(is.gcount() == 7);
assert(is.get() == L'*');
is.get(sb2, L'*');
assert(sb2.str() == L"testing...");
assert(is.eof());
assert(!is.fail());
assert(is.gcount() == 3);
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& getline(char_type* s, streamsize n);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" \n \n ");
std::istream is(&sb);
char s[5];
is.getline(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 3);
is.getline(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 5);
is.getline(s, 5);
assert( is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 1);
}
{
testbuf<wchar_t> sb(L" \n \n ");
std::wistream is(&sb);
wchar_t s[5];
is.getline(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 3);
is.getline(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 5);
is.getline(s, 5);
assert( is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 1);
}
}

View File

@@ -0,0 +1,83 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& getline(char_type* s, streamsize n, char_type delim);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" * * ");
std::istream is(&sb);
char s[5];
is.getline(s, 5, '*');
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 3);
is.getline(s, 5, '*');
assert(!is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 5);
is.getline(s, 5, '*');
assert( is.eof());
assert(!is.fail());
assert(std::string(s) == " ");
assert(is.gcount() == 1);
}
{
testbuf<wchar_t> sb(L" * * ");
std::wistream is(&sb);
wchar_t s[5];
is.getline(s, 5, L'*');
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 3);
is.getline(s, 5, L'*');
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 5);
is.getline(s, 5, L'*');
assert( is.eof());
assert(!is.fail());
assert(std::wstring(s) == L" ");
assert(is.gcount() == 1);
}
}

View File

@@ -0,0 +1,76 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>&
// ignore(streamsize n = 1, int_type delim = traits::eof());
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" 1\n2345\n6");
std::istream is(&sb);
is.ignore();
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 1);
is.ignore(5, '\n');
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 2);
is.ignore(15);
assert( is.eof());
assert(!is.fail());
assert(is.gcount() == 6);
}
{
testbuf<wchar_t> sb(L" 1\n2345\n6");
std::wistream is(&sb);
is.ignore();
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 1);
is.ignore(5, '\n');
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 2);
is.ignore(15);
assert( is.eof());
assert(!is.fail());
assert(is.gcount() == 6);
}
}

View File

@@ -0,0 +1,34 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>&
// ignore(streamsize n = 1, int_type delim = traits::eof());
// http://llvm.org/bugs/show_bug.cgi?id=16427
#include <sstream>
#include <cassert>
int main()
{
int bad=-1;
std::ostringstream os;
os << "aaaabbbb" << static_cast<char>(bad)
<< "ccccdddd" << std::endl;
std::string s=os.str();
std::istringstream is(s);
const unsigned int ignoreLen=10;
size_t a=is.tellg();
is.ignore(ignoreLen);
size_t b=is.tellg();
assert((b-a)==ignoreLen);
}

View File

@@ -0,0 +1,69 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// int_type peek();
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" 1\n2345\n6");
std::istream is(&sb);
assert(is.peek() == ' ');
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 0);
is.get();
assert(is.peek() == '1');
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 0);
}
{
testbuf<wchar_t> sb(L" 1\n2345\n6");
std::wistream is(&sb);
assert(is.peek() == L' ');
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 0);
is.get();
assert(is.peek() == L'1');
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 0);
}
}

View File

@@ -0,0 +1,89 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& putback(char_type c);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" 123456789");
std::istream is(&sb);
is.get();
is.get();
is.get();
is.putback('a');
assert(is.bad());
assert(is.gcount() == 0);
is.clear();
is.putback('2');
assert(is.good());
assert(is.gcount() == 0);
is.putback('1');
assert(is.good());
assert(is.gcount() == 0);
is.putback(' ');
assert(is.good());
assert(is.gcount() == 0);
is.putback(' ');
assert(is.bad());
assert(is.gcount() == 0);
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
is.get();
is.get();
is.get();
is.putback(L'a');
assert(is.bad());
assert(is.gcount() == 0);
is.clear();
is.putback(L'2');
assert(is.good());
assert(is.gcount() == 0);
is.putback(L'1');
assert(is.good());
assert(is.gcount() == 0);
is.putback(L' ');
assert(is.good());
assert(is.gcount() == 0);
is.putback(L' ');
assert(is.bad());
assert(is.gcount() == 0);
}
}

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& read(char_type* s, streamsize n);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" 123456789");
std::istream is(&sb);
char s[5];
is.read(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s, 5) == " 1234");
assert(is.gcount() == 5);
is.read(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s, 5) == "56789");
assert(is.gcount() == 5);
is.read(s, 5);
assert( is.eof());
assert( is.fail());
assert(is.gcount() == 0);
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
wchar_t s[5];
is.read(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s, 5) == L" 1234");
assert(is.gcount() == 5);
is.read(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s, 5) == L"56789");
assert(is.gcount() == 5);
is.read(s, 5);
assert( is.eof());
assert( is.fail());
assert(is.gcount() == 0);
}
}

View File

@@ -0,0 +1,85 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// streamsize readsome(char_type* s, streamsize n);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" 1234567890");
std::istream is(&sb);
char s[5];
assert(is.readsome(s, 5) == 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s, 5) == " 1234");
assert(is.gcount() == 5);
is.readsome(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::string(s, 5) == "56789");
assert(is.gcount() == 5);
is.readsome(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 1);
assert(std::string(s, 1) == "0");
assert(is.readsome(s, 5) == 0);
}
{
testbuf<wchar_t> sb(L" 1234567890");
std::wistream is(&sb);
wchar_t s[5];
assert(is.readsome(s, 5) == 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s, 5) == L" 1234");
assert(is.gcount() == 5);
is.readsome(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(std::wstring(s, 5) == L"56789");
assert(is.gcount() == 5);
is.readsome(s, 5);
assert(!is.eof());
assert(!is.fail());
assert(is.gcount() == 1);
assert(std::wstring(s, 1) == L"0");
assert(is.readsome(s, 5) == 0);
}
}

View File

@@ -0,0 +1,66 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& seekg(pos_type pos);
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
protected:
typename base::pos_type seekpos(typename base::pos_type sp,
std::ios_base::openmode which)
{
assert(which == std::ios_base::in);
return sp;
}
};
int main()
{
{
testbuf<char> sb(" 123456789");
std::istream is(&sb);
is.seekg(5);
assert(is.good());
is.seekg(-1);
assert(is.fail());
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
is.seekg(5);
assert(is.good());
is.seekg(-1);
assert(is.fail());
}
}

View File

@@ -0,0 +1,74 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& seekg(off_type off, ios_base::seekdir dir);
#include <istream>
#include <cassert>
int seekoff_called = 0;
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
protected:
typename base::pos_type seekoff(typename base::off_type off,
std::ios_base::seekdir way,
std::ios_base::openmode which)
{
assert(which == std::ios_base::in);
++seekoff_called;
return off;
}
};
int main()
{
{
testbuf<char> sb(" 123456789");
std::istream is(&sb);
is.seekg(5, std::ios_base::cur);
assert(is.good());
assert(seekoff_called == 1);
is.seekg(-1, std::ios_base::beg);
assert(is.fail());
assert(seekoff_called == 2);
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
is.seekg(5, std::ios_base::cur);
assert(is.good());
assert(seekoff_called == 3);
is.seekg(-1, std::ios_base::beg);
assert(is.fail());
assert(seekoff_called == 4);
}
}

View File

@@ -0,0 +1,64 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// int sync();
#include <istream>
#include <cassert>
int sync_called = 0;
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
protected:
int sync()
{
++sync_called;
return 5;
}
};
int main()
{
{
testbuf<char> sb(" 123456789");
std::istream is(&sb);
assert(is.sync() == 0);
assert(sync_called == 1);
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
assert(is.sync() == 0);
assert(sync_called == 2);
}
}

View File

@@ -0,0 +1,63 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// pos_type tellg();
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
protected:
typename base::pos_type seekoff(typename base::off_type off,
std::ios_base::seekdir way,
std::ios_base::openmode which)
{
assert(off == 0);
assert(way == std::ios_base::cur);
assert(which == std::ios_base::in);
return 5;
}
};
int main()
{
{
testbuf<char> sb(" 123456789");
std::istream is(&sb);
assert(is.tellg() == 5);
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
assert(is.tellg() == 5);
}
}

View File

@@ -0,0 +1,81 @@
//===----------------------------------------------------------------------===//
//
// 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.
//
//===----------------------------------------------------------------------===//
// <istream>
// basic_istream<charT,traits>& unget();
#include <istream>
#include <cassert>
template <class CharT>
struct testbuf
: public std::basic_streambuf<CharT>
{
typedef std::basic_string<CharT> string_type;
typedef std::basic_streambuf<CharT> base;
private:
string_type str_;
public:
testbuf() {}
testbuf(const string_type& str)
: str_(str)
{
base::setg(const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()),
const_cast<CharT*>(str_.data()) + str_.size());
}
CharT* eback() const {return base::eback();}
CharT* gptr() const {return base::gptr();}
CharT* egptr() const {return base::egptr();}
};
int main()
{
{
testbuf<char> sb(" 123456789");
std::istream is(&sb);
is.get();
is.get();
is.get();
is.unget();
assert(is.good());
assert(is.gcount() == 0);
is.unget();
assert(is.good());
assert(is.gcount() == 0);
is.unget();
assert(is.good());
assert(is.gcount() == 0);
is.unget();
assert(is.bad());
assert(is.gcount() == 0);
}
{
testbuf<wchar_t> sb(L" 123456789");
std::wistream is(&sb);
is.get();
is.get();
is.get();
is.unget();
assert(is.good());
assert(is.gcount() == 0);
is.unget();
assert(is.good());
assert(is.gcount() == 0);
is.unget();
assert(is.good());
assert(is.gcount() == 0);
is.unget();
assert(is.bad());
assert(is.gcount() == 0);
}
}