brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · da28695 Raw
59 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// class ios_base14 15// void register_callback(event_callback fn, int index);16 17#include <ios>18#include <string>19#include <locale>20#include <cassert>21 22#include "test_macros.h"23#include "platform_support.h" // locale name macros24 25class test26    : public std::ios27{28public:29    test()30    {31        init(0);32    }33};34 35int f1_called = 0;36 37void f1(std::ios_base::event ev, std::ios_base& stream, int index)38{39    if (ev == std::ios_base::imbue_event)40    {41        assert(stream.getloc().name() == LOCALE_en_US_UTF_8);42        assert(index == 4);43        ++f1_called;44    }45}46 47int main(int, char**)48{49    test t;50    std::ios_base& b = t;51    b.register_callback(f1, 4);52    b.register_callback(f1, 4);53    b.register_callback(f1, 4);54    std::locale l = b.imbue(std::locale(LOCALE_en_US_UTF_8));55    assert(f1_called == 3);56 57  return 0;58}59