49 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// This test hangs on Android devices that lack shell_v2, which was added in10// Android N (API 24).11// UNSUPPORTED: LIBCXX-ANDROID-FIXME && android-device-api={{2[1-3]}}12 13// <iostream>14 15// wistream wcin;16 17// UNSUPPORTED: no-wide-characters18 19// RUN: %{build}20// RUN: echo -n 1234 > %t.input21// RUN: %{exec} %t.exe < %t.input22 23#include <iostream>24#include <cassert>25 26struct custom_codecvt : std::codecvt<wchar_t, char, std::mbstate_t> {27 using base = std::codecvt<wchar_t, char, std::mbstate_t>;28protected:29 result do_in(std::mbstate_t&, const char *from, const char *from_end,30 const char *&from_next, wchar_t *to, wchar_t *to_end, wchar_t *&to_next) const {31 while (from != from_end && to != to_end) {32 ++from;33 *to++ = L'z';34 }35 from_next = from;36 to_next = to;37 return ok;38 }39};40 41int main(int, char**) {42 std::locale loc(std::locale::classic(), new custom_codecvt);43 std::wcin.imbue(loc);44 std::wstring str;45 std::wcin >> str;46 assert(str == L"zzzz");47 return 0;48}49