83 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <sstream>10 11// template <class charT, class traits = char_traits<charT>, class Allocator = allocator<charT> >12// class basic_stringbuf13 14// pos_type seekpos(pos_type sp,15// ios_base::openmode which = ios_base::in | ios_base::out);16 17#include <sstream>18#include <cassert>19 20#include "test_macros.h"21 22int main(int, char**)23{24 {25 std::stringbuf sb("0123456789", std::ios_base::in);26 assert(sb.pubseekpos(3, std::ios_base::out) == -1);27 assert(sb.pubseekpos(3, std::ios_base::in | std::ios_base::out) == -1);28 assert(sb.pubseekpos(3, std::ios_base::in) == 3);29 assert(sb.sgetc() == '3');30 }31 {32 std::stringbuf sb("0123456789", std::ios_base::out);33 assert(sb.pubseekpos(3, std::ios_base::in) == -1);34 assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == -1);35 assert(sb.pubseekpos(3, std::ios_base::out) == 3);36 assert(sb.sputc('a') == 'a');37 assert(sb.str() == "012a456789");38 }39 {40 std::stringbuf sb("0123456789");41 assert(sb.pubseekpos(3, std::ios_base::in) == 3);42 assert(sb.sgetc() == '3');43 assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == 3);44 assert(sb.sgetc() == '3');45 assert(sb.sputc('a') == 'a');46 assert(sb.str() == "012a456789");47 assert(sb.pubseekpos(3, std::ios_base::out) == 3);48 assert(sb.sputc('3') == '3');49 assert(sb.str() == "0123456789");50 }51#ifndef TEST_HAS_NO_WIDE_CHARACTERS52 {53 std::wstringbuf sb(L"0123456789", std::ios_base::in);54 assert(sb.pubseekpos(3, std::ios_base::out) == -1);55 assert(sb.pubseekpos(3, std::ios_base::in | std::ios_base::out) == -1);56 assert(sb.pubseekpos(3, std::ios_base::in) == 3);57 assert(sb.sgetc() == L'3');58 }59 {60 std::wstringbuf sb(L"0123456789", std::ios_base::out);61 assert(sb.pubseekpos(3, std::ios_base::in) == -1);62 assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == -1);63 assert(sb.pubseekpos(3, std::ios_base::out) == 3);64 assert(sb.sputc(L'a') == L'a');65 assert(sb.str() == L"012a456789");66 }67 {68 std::wstringbuf sb(L"0123456789");69 assert(sb.pubseekpos(3, std::ios_base::in) == 3);70 assert(sb.sgetc() == L'3');71 assert(sb.pubseekpos(3, std::ios_base::out | std::ios_base::in) == 3);72 assert(sb.sgetc() == L'3');73 assert(sb.sputc(L'a') == L'a');74 assert(sb.str() == L"012a456789");75 assert(sb.pubseekpos(3, std::ios_base::out) == 3);76 assert(sb.sputc(L'3') == L'3');77 assert(sb.str() == L"0123456789");78 }79#endif80 81 return 0;82}83