[libc++] Get rid of _LIBCPP_HAS_OPEN_WITH_WCHAR in the test suite

Differential Revision: https://reviews.llvm.org/D135163
This commit is contained in:
Louis Dionne 2022-10-04 11:28:45 -04:00
parent 9aa004a04c
commit bc8f007fe0
9 changed files with 68 additions and 48 deletions

View File

@ -13,14 +13,16 @@
// explicit basic_fstream(const wchar_t* s, ios_base::openmode mode = ios_base::in | ios_base::out);
// This extension is only provided on Windows.
// REQUIRES: windows
// UNSUPPORTED: no-wide-characters
#include <fstream>
#include <cassert>
#include "test_macros.h"
#include "platform_support.h"
#include "wide_temp_file.h"
int main(int, char**)
{
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
int main(int, char**) {
std::wstring temp = get_wide_temp_file_name();
{
std::fstream fs(temp.c_str(), std::ios_base::in | std::ios_base::out
@ -42,7 +44,6 @@ int main(int, char**)
assert(x == 3.25);
}
_wremove(temp.c_str());
#endif
return 0;
return 0;
}

View File

@ -13,14 +13,16 @@
// void open(const wchar_t* s, ios_base::openmode mode = ios_base::in|ios_base::out);
// This extension is only provided on Windows.
// REQUIRES: windows
// UNSUPPORTED: no-wide-characters
#include <fstream>
#include <cassert>
#include "test_macros.h"
#include "platform_support.h"
#include "wide_temp_file.h"
int main(int, char**)
{
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
int main(int, char**) {
std::wstring temp = get_wide_temp_file_name();
{
std::fstream fs;
@ -48,7 +50,6 @@ int main(int, char**)
assert(x == 3.25);
}
_wremove(temp.c_str());
#endif
return 0;
return 0;
}

View File

@ -13,6 +13,10 @@
// explicit basic_ifstream(const wchar_t* s, ios_base::openmode mode = ios_base::in);
// This extension is only provided on Windows.
// REQUIRES: windows
// UNSUPPORTED: no-wide-characters
// FILE_DEPENDENCIES: test.dat
#include <fstream>
@ -20,9 +24,7 @@
#include "test_macros.h"
int main(int, char**)
{
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
int main(int, char**) {
{
std::ifstream fs(L"test.dat");
double x = 0;
@ -41,7 +43,6 @@ int main(int, char**)
// std::wifstream(const wchar_t*, std::ios_base::openmode) is tested in
// test/libcxx/input.output/file.streams/fstreams/ofstream.cons/wchar_pointer.pass.cpp
// which creates writable files.
#endif
return 0;
return 0;
}

View File

@ -13,6 +13,10 @@
// void open(const wchar_t* s, ios_base::openmode mode = ios_base::in);
// This extension is only provided on Windows.
// REQUIRES: windows
// UNSUPPORTED: no-wide-characters
// FILE_DEPENDENCIES: test.dat
#include <fstream>
@ -20,9 +24,7 @@
#include "test_macros.h"
int main(int, char**)
{
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
int main(int, char**) {
{
std::ifstream fs;
assert(!fs.is_open());
@ -47,7 +49,6 @@ int main(int, char**)
fs >> c;
assert(c == L'r');
}
#endif
return 0;
return 0;
}

View File

@ -13,14 +13,16 @@
// explicit basic_ofstream(const wchar_t* s, ios_base::openmode mode = ios_base::out);
// This extension is only provided on Windows.
// REQUIRES: windows
// UNSUPPORTED: no-wide-characters
#include <fstream>
#include <cassert>
#include "test_macros.h"
#include "platform_support.h"
#include "wide_temp_file.h"
int main(int, char**)
{
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
int main(int, char**) {
std::wstring temp = get_wide_temp_file_name();
{
std::ofstream fs(temp.c_str());
@ -56,7 +58,6 @@ int main(int, char**)
assert(x == 3.25);
}
_wremove(temp.c_str());
#endif
return 0;
return 0;
}

View File

@ -13,14 +13,16 @@
// void open(const wchar_t* s, ios_base::openmode mode = ios_base::out);
// This extension is only provided on Windows.
// REQUIRES: windows
// UNSUPPORTED: no-wide-characters
#include <fstream>
#include <cassert>
#include "test_macros.h"
#include "platform_support.h"
#include "wide_temp_file.h"
int main(int, char**)
{
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
int main(int, char**) {
std::wstring temp = get_wide_temp_file_name();
{
std::ofstream fs;
@ -56,7 +58,6 @@ int main(int, char**)
assert(c == L'a');
}
_wremove(temp.c_str());
#endif
return 0;
return 0;
}

View File

@ -35,8 +35,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <codecvt>
#include <locale>
#include <string>
#if defined(_WIN32)
# include <io.h> // _mktemp_s
@ -85,17 +83,6 @@ std::string get_temp_file_name()
#endif
}
_LIBCPP_SUPPRESS_DEPRECATED_PUSH
#ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
inline
std::wstring get_wide_temp_file_name()
{
return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> >().from_bytes(
get_temp_file_name());
}
#endif // _LIBCPP_HAS_OPEN_WITH_WCHAR
_LIBCPP_SUPPRESS_DEPRECATED_POP
#if defined(_CS_GNU_LIBC_VERSION)
inline bool glibc_version_less_than(char const* version) {
std::string test_version = std::string("glibc ") + version;

View File

@ -0,0 +1,27 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef TEST_SUPPORT_WIDE_TEMP_FILE_H
#define TEST_SUPPORT_WIDE_TEMP_FILE_H
#include <codecvt>
#include <locale>
#include <string>
#include "platform_support.h"
#include "test_macros.h"
TEST_DIAGNOSTIC_PUSH
TEST_CLANG_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
TEST_GCC_DIAGNOSTIC_IGNORED("-Wdeprecated-declarations")
inline std::wstring get_wide_temp_file_name() {
return std::wstring_convert<std::codecvt_utf8_utf16<wchar_t> >().from_bytes(get_temp_file_name());
}
TEST_DIAGNOSTIC_POP
#endif // TEST_SUPPORT_WIDE_TEMP_FILE_H

View File

@ -236,7 +236,7 @@ for locale, alts in locales.items():
when=lambda cfg, alts=alts: hasAnyLocale(cfg, alts)))
# Add features representing the platform name: darwin, linux, windows, etc...
# Add features representing the target platform name: darwin, linux, windows, etc...
DEFAULT_FEATURES += [
Feature(name='darwin', when=lambda cfg: '__APPLE__' in compilerMacros(cfg)),
Feature(name='windows', when=lambda cfg: '_WIN32' in compilerMacros(cfg)),