brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.3 KiB · a882fb6 Raw
171 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// REQUIRES: locale.en_US.UTF-810// REQUIRES: locale.fr_FR.UTF-811 12// <ios>13 14// template <class charT, class traits> class basic_ios15 16// void move(basic_ios&& rhs);17 18#include <ios>19#include <streambuf>20#include <cassert>21 22#include "test_macros.h"23#include "platform_support.h" // locale name macros24 25struct testbuf26    : public std::streambuf27{28};29 30struct testios31    : public std::ios32{33    testios(std::streambuf* p) : std::ios(p) {}34    void swap(std::ios& x) {std::ios::swap(x);}35};36 37bool f1_called = false;38bool f2_called = false;39 40bool g1_called = false;41bool g2_called = false;42bool g3_called = false;43 44void f1(std::ios_base::event, std::ios_base&, int index)45{46    assert(index == 4);47    f1_called = true;48}49 50void f2(std::ios_base::event, std::ios_base&, int index)51{52    assert(index == 5);53    f2_called = true;54}55 56void g1(std::ios_base::event, std::ios_base&, int index)57{58    assert(index == 7);59    g1_called = true;60}61 62void g2(std::ios_base::event, std::ios_base&, int index)63{64    assert(index == 8);65    g2_called = true;66}67 68void g3(std::ios_base::event, std::ios_base&, int index)69{70    assert(index == 9);71    g3_called = true;72}73 74int main(int, char**)75{76    testbuf sb1;77    testios ios1(&sb1);78    ios1.flags(std::ios::boolalpha | std::ios::dec | std::ios::fixed);79    ios1.precision(1);80    ios1.width(11);81    ios1.imbue(std::locale(LOCALE_en_US_UTF_8));82    ios1.exceptions(std::ios::failbit);83    ios1.setstate(std::ios::eofbit);84    ios1.register_callback(f1, 4);85    ios1.register_callback(f2, 5);86    ios1.iword(0) = 1;87    ios1.iword(1) = 2;88    ios1.iword(2) = 3;89    char c1, c2, c3;90    ios1.pword(0) = &c1;91    ios1.pword(1) = &c2;92    ios1.pword(2) = &c3;93    ios1.tie((std::ostream*)1);94    ios1.fill('1');95 96    testbuf sb2;97    testios ios2(&sb2);98    ios2.flags(std::ios::showpoint | std::ios::uppercase);99    ios2.precision(2);100    ios2.width(12);101    ios2.imbue(std::locale(LOCALE_fr_FR_UTF_8));102    ios2.exceptions(std::ios::eofbit);103    ios2.setstate(std::ios::goodbit);104    ios2.register_callback(g1, 7);105    ios2.register_callback(g2, 8);106    ios2.register_callback(g3, 9);107    ios2.iword(0) = 4;108    ios2.iword(1) = 5;109    ios2.iword(2) = 6;110    ios2.iword(3) = 7;111    ios2.iword(4) = 8;112    ios2.iword(5) = 9;113    char d1, d2;114    ios2.pword(0) = &d1;115    ios2.pword(1) = &d2;116    ios2.tie((std::ostream*)2);117    ios2.fill('2');118 119    ios1.swap(ios2);120 121    assert(ios1.rdstate() == std::ios::goodbit);122    assert(ios1.rdbuf() == &sb1);123    assert(ios1.flags() == (std::ios::showpoint | std::ios::uppercase));124    assert(ios1.precision() == 2);125    assert(ios1.width() == 12);126    assert(ios1.getloc().name() == LOCALE_fr_FR_UTF_8);127    assert(ios1.exceptions() == std::ios::eofbit);128    assert(!f1_called);129    assert(!f2_called);130    assert(!g1_called);131    assert(!g2_called);132    assert(!g3_called);133    assert(ios1.iword(0) == 4);134    assert(ios1.iword(1) == 5);135    assert(ios1.iword(2) == 6);136    assert(ios1.iword(3) == 7);137    assert(ios1.iword(4) == 8);138    assert(ios1.iword(5) == 9);139    assert(ios1.pword(0) == &d1);140    assert(ios1.pword(1) == &d2);141    assert(ios1.tie() == (std::ostream*)2);142    assert(ios1.fill() == '2');143    ios1.imbue(std::locale("C"));144    assert(!f1_called);145    assert(!f2_called);146    assert(g1_called);147    assert(g2_called);148    assert(g3_called);149 150    assert(ios2.rdstate() == std::ios::eofbit);151    assert(ios2.rdbuf() == &sb2);152    assert(ios2.flags() == (std::ios::boolalpha | std::ios::dec | std::ios::fixed));153    assert(ios2.precision() == 1);154    assert(ios2.width() == 11);155    assert(ios2.getloc().name() == LOCALE_en_US_UTF_8);156    assert(ios2.exceptions() == std::ios::failbit);157    assert(ios2.iword(0) == 1);158    assert(ios2.iword(1) == 2);159    assert(ios2.iword(2) == 3);160    assert(ios2.pword(0) == &c1);161    assert(ios2.pword(1) == &c2);162    assert(ios2.pword(2) == &c3);163    assert(ios2.tie() == (std::ostream*)1);164    assert(ios2.fill() == '1');165    ios2.imbue(std::locale("C"));166    assert(f1_called);167    assert(f2_called);168 169  return 0;170}171