brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 579e04a Raw
106 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 11// <ios>12 13// template <class charT, class traits> class basic_ios14 15// locale imbue(const locale& loc);16 17#include <ios>18#include <streambuf>19#include <cassert>20 21#include "test_macros.h"22#include "platform_support.h" // locale name macros23 24struct testbuf25    : public std::streambuf26{27};28 29bool f1_called = false;30bool f2_called = false;31bool f3_called = false;32 33void f1(std::ios_base::event ev, std::ios_base& stream, int index)34{35    if (ev == std::ios_base::imbue_event)36    {37        assert(!f1_called);38        assert( f2_called);39        assert( f3_called);40        assert(stream.getloc().name() == LOCALE_en_US_UTF_8);41        assert(index == 4);42        f1_called = true;43    }44}45 46void f2(std::ios_base::event ev, std::ios_base& stream, int index)47{48    if (ev == std::ios_base::imbue_event)49    {50        assert(!f1_called);51        assert(!f2_called);52        assert( f3_called);53        assert(stream.getloc().name() == LOCALE_en_US_UTF_8);54        assert(index == 5);55        f2_called = true;56    }57}58 59void f3(std::ios_base::event ev, std::ios_base& stream, int index)60{61    if (ev == std::ios_base::imbue_event)62    {63        assert(!f1_called);64        assert(!f2_called);65        assert(!f3_called);66        assert(stream.getloc().name() == LOCALE_en_US_UTF_8);67        assert(index == 6);68        f3_called = true;69    }70}71 72int main(int, char**)73{74    {75        std::ios ios(0);76        ios.register_callback(f1, 4);77        ios.register_callback(f2, 5);78        ios.register_callback(f3, 6);79        std::locale l = ios.imbue(std::locale(LOCALE_en_US_UTF_8));80        assert(l.name() == std::string("C"));81        assert(ios.getloc().name() == std::string(LOCALE_en_US_UTF_8));82        assert(f1_called);83        assert(f2_called);84        assert(f3_called);85    }86    f1_called = false;87    f2_called = false;88    f3_called = false;89    {90        testbuf sb;91        std::ios ios(&sb);92        ios.register_callback(f1, 4);93        ios.register_callback(f2, 5);94        ios.register_callback(f3, 6);95        std::locale l = ios.imbue(std::locale(LOCALE_en_US_UTF_8));96        assert(l.name() == std::string("C"));97        assert(ios.getloc().name() == std::string(LOCALE_en_US_UTF_8));98        assert(sb.getloc().name() == std::string(LOCALE_en_US_UTF_8));99        assert(f1_called);100        assert(f2_called);101        assert(f3_called);102    }103 104  return 0;105}106