brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · 26e48ff Raw
57 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// UNSUPPORTED: c++03, c++11, c++14, c++1710// UNSUPPORTED: no-localization11// UNSUPPORTED: libcpp-has-no-experimental-syncstream12 13// <syncstream>14 15// template <class charT, class traits, class Allocator>16// class basic_syncbuf;17 18// protected:19// [syncstream.syncbuf.virtuals], overridden virtual functions20// int sync() override;21 22#include <syncstream>23#include <sstream>24#include <ostream>25#include <cassert>26 27#include "test_macros.h"28 29template <class CharT>30void test_sync(bool emit_on_sync) {31  std::basic_stringbuf<CharT> base;32  std::basic_syncbuf<CharT> buff(&base);33  std::basic_ostream<CharT> out(&buff);34 35  buff.set_emit_on_sync(emit_on_sync);36 37  out << 'a';38  out.flush(); // This is an indirect call to sync.39 40  if (emit_on_sync) {41    assert(base.str().size() == 1);42    assert(base.str()[0] == CharT('a'));43  } else44    assert(base.str().empty());45}46 47int main(int, char**) {48  test_sync<char>(true);49  test_sync<char>(false);50#ifndef TEST_HAS_NO_WIDE_CHARACTERS51  test_sync<wchar_t>(true);52  test_sync<wchar_t>(false);53#endif54 55  return 0;56}57