signed_char_pointer.pass.cpp revision 256813f4e7915d64776a4edd5f4765d893b9f062
1ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com//===----------------------------------------------------------------------===// 2ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com// 3ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com// The LLVM Compiler Infrastructure 4ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com// 5ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com// This file is distributed under the University of Illinois Open Source 6ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com// License. See LICENSE.TXT for details. 7ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com// 8ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com//===----------------------------------------------------------------------===// 9ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com 10ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com// <istream> 11ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com 12ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com// template<class traits> 13e8fe4bc3efa8f18f5651c5d005fba1935a741be0robertphillips@google.com// basic_istream<char,traits>& operator>>(basic_istream<char,traits>&& in, signed char* s); 14e8fe4bc3efa8f18f5651c5d005fba1935a741be0robertphillips@google.com 15ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com#include <istream> 16ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com#include <cassert> 17607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com 18ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.comtemplate <class CharT> 19ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.comstruct testbuf 20ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com : public std::basic_streambuf<CharT> 21ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com{ 22ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com typedef std::basic_string<CharT> string_type; 23ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com typedef std::basic_streambuf<CharT> base; 24ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.comprivate: 25ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com string_type str_; 26a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.compublic: 27ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com 28ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com testbuf() {} 29607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com testbuf(const string_type& str) 30ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com : str_(str) 31ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com { 32ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com base::setg(const_cast<CharT*>(str_.data()), 33607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com const_cast<CharT*>(str_.data()), 34ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com const_cast<CharT*>(str_.data()) + str_.size()); 35ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com } 36ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com 37a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com CharT* eback() const {return base::eback();} 38a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com CharT* gptr() const {return base::gptr();} 39a9e937c7b712b024de108fa963f92d0e70e4a296chudy@google.com CharT* egptr() const {return base::egptr();} 40ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com}; 41ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com 42ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.comint main() 43ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com{ 44ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com { 45ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com testbuf<char> sb(" abcdefghijk "); 46ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com std::istream is(&sb); 47ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com signed char s[20]; 48ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com is >> s; 49ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com assert(!is.eof()); 50ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com assert(!is.fail()); 51607357fde8a9c4c70549d4223e0bd1181b012e0echudy@google.com assert(std::string((char*)s) == "abcdefghijk"); 5216e3ddea6a80972aced04b21b1d66377fa95e7c7bsalomon@google.com } 53ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com { 54ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com testbuf<char> sb(" abcdefghijk "); 55e8fe4bc3efa8f18f5651c5d005fba1935a741be0robertphillips@google.com std::istream is(&sb); 56e8fe4bc3efa8f18f5651c5d005fba1935a741be0robertphillips@google.com is.width(4); 57ea5488b9655fc7d71345c3a823de85f8b74e3279chudy@google.com signed char s[20]; 58 is >> s; 59 assert(!is.eof()); 60 assert(!is.fail()); 61 assert(std::string((char*)s) == "abc"); 62 assert(is.width() == 0); 63 } 64 { 65 testbuf<char> sb(" abcdefghijk"); 66 std::istream is(&sb); 67 signed char s[20]; 68 is >> s; 69 assert( is.eof()); 70 assert(!is.fail()); 71 assert(std::string((char*)s) == "abcdefghijk"); 72 assert(is.width() == 0); 73 } 74 { 75 testbuf<char> sb(" abcdefghijk"); 76 std::istream is(&sb); 77 signed char s[20]; 78 is.width(1); 79 is >> s; 80 assert(!is.eof()); 81 assert( is.fail()); 82 assert(std::string((char*)s) == ""); 83 assert(is.width() == 0); 84 } 85} 86