Home | History | Annotate | Download | only in streambuf.assign
      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // REQUIRES: locale.en_US.UTF-8
     11 
     12 // <streambuf>
     13 
     14 // template <class charT, class traits = char_traits<charT> >
     15 // class basic_streambuf;
     16 
     17 // basic_streambuf& operator=(const basic_streambuf& rhs);
     18 
     19 #include <streambuf>
     20 #include <cassert>
     21 
     22 #include "platform_support.h" // locale name macros
     23 
     24 template <class CharT>
     25 struct test
     26     : public std::basic_streambuf<CharT>
     27 {
     28     typedef std::basic_streambuf<CharT> base;
     29     test() {}
     30 
     31     test& operator=(const test& t)
     32     {
     33         base::operator=(t);
     34         assert(this->eback() == t.eback());
     35         assert(this->gptr()  == t.gptr());
     36         assert(this->egptr() == t.egptr());
     37         assert(this->pbase() == t.pbase());
     38         assert(this->pptr()  == t.pptr());
     39         assert(this->epptr() == t.epptr());
     40         assert(this->getloc() == t.getloc());
     41         return *this;
     42     }
     43 
     44     void setg(CharT* gbeg, CharT* gnext, CharT* gend)
     45     {
     46         base::setg(gbeg, gnext, gend);
     47     }
     48     void setp(CharT* pbeg, CharT* pend)
     49     {
     50         base::setp(pbeg, pend);
     51     }
     52 };
     53 
     54 int main()
     55 {
     56     {
     57         test<char> t;
     58         test<char> t2;
     59         t2 = t;
     60     }
     61     {
     62         test<wchar_t> t;
     63         test<wchar_t> t2;
     64         t2 = t;
     65     }
     66     {
     67         char g1, g2, g3, p1, p3;
     68         test<char> t;
     69         t.setg(&g1, &g2, &g3);
     70         t.setp(&p1, &p3);
     71         test<char> t2;
     72         t2 = t;
     73     }
     74     {
     75         wchar_t g1, g2, g3, p1, p3;
     76         test<wchar_t> t;
     77         t.setg(&g1, &g2, &g3);
     78         t.setp(&p1, &p3);
     79         test<wchar_t> t2;
     80         t2 = t;
     81     }
     82     std::locale::global(std::locale(LOCALE_en_US_UTF_8));
     83     {
     84         test<char> t;
     85         test<char> t2;
     86         t2 = t;
     87     }
     88     {
     89         test<wchar_t> t;
     90         test<wchar_t> t2;
     91         t2 = t;
     92     }
     93 }
     94