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 // <locale> 11 12 // wbuffer_convert<Codecvt, Elem, Tr> 13 14 // pos_type seekoff(off_type off, ios_base::seekdir way, 15 // ios_base::openmode which = ios_base::in | ios_base::out); 16 // pos_type seekpos(pos_type sp, 17 // ios_base::openmode which = ios_base::in | ios_base::out); 18 19 // This test is not entirely portable 20 21 #include <locale> 22 #include <codecvt> 23 #include <fstream> 24 #include <cassert> 25 26 class test_codecvt 27 : public std::codecvt<wchar_t, char, std::mbstate_t> 28 { 29 typedef std::codecvt<wchar_t, char, std::mbstate_t> base; 30 public: 31 explicit test_codecvt(std::size_t refs = 0) : base(refs) {} 32 ~test_codecvt() {} 33 }; 34 35 int main() 36 { 37 { 38 wchar_t buf[10]; 39 typedef std::wbuffer_convert<test_codecvt> test_buf; 40 typedef test_buf::pos_type pos_type; 41 std::fstream bs("seekoff.dat", std::ios::trunc | std::ios::in 42 | std::ios::out); 43 test_buf f(bs.rdbuf()); 44 f.pubsetbuf(buf, sizeof(buf)/sizeof(buf[0])); 45 f.sputn(L"abcdefghijklmnopqrstuvwxyz", 26); 46 assert(buf[0] == L'v'); 47 pos_type p = f.pubseekoff(-15, std::ios_base::cur); 48 assert(p == 11); 49 assert(f.sgetc() == L'l'); 50 f.pubseekoff(0, std::ios_base::beg); 51 assert(f.sgetc() == L'a'); 52 f.pubseekoff(-1, std::ios_base::end); 53 assert(f.sgetc() == L'z'); 54 assert(f.pubseekpos(p) == p); 55 assert(f.sgetc() == L'l'); 56 } 57 std::remove("seekoff.dat"); 58 } 59