83 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// UNSUPPORTED: c++03, c++11, c++1410 11// These tests require locale for non-char paths12// UNSUPPORTED: no-localization13 14// <filesystem>15 16// class path17 18// std::string generic_string() const;19// std::wstring generic_wstring() const;20// std::u8string generic_u8string() const;21// std::u16string generic_u16string() const;22// std::u32string generic_u32string() const;23 24#include <filesystem>25#include <cassert>26#include <string>27#include <type_traits>28 29#include "count_new.h"30#include "make_string.h"31#include "min_allocator.h"32#include "test_iterators.h"33#include "test_macros.h"34namespace fs = std::filesystem;35 36MultiStringType input = MKSTR("c:\\foo\\bar");37#ifdef _WIN3238// On windows, the generic_* accessors return a path with forward slashes39MultiStringType ref = MKSTR("c:/foo/bar");40#else41// On posix, the input string is returned as-is42MultiStringType ref = MKSTR("c:\\foo\\bar");43#endif44 45int main(int, char**)46{47 using namespace fs;48 auto const& MS = ref;49 const char* value = input;50 const path p(value);51 {52 std::string s = p.generic_string();53 assert(s == (const char*)MS);54 }55 {56#if TEST_STD_VER > 17 && defined(__cpp_char8_t)57 ASSERT_SAME_TYPE(decltype(p.generic_u8string()), std::u8string);58 std::u8string s = p.generic_u8string();59 assert(s == (const char8_t*)MS);60#else61 ASSERT_SAME_TYPE(decltype(p.generic_u8string()), std::string);62 std::string s = p.generic_u8string();63 assert(s == (const char*)MS);64#endif65 }66#ifndef TEST_HAS_NO_WIDE_CHARACTERS67 {68 std::wstring s = p.generic_wstring();69 assert(s == (const wchar_t*)MS);70 }71#endif72 {73 std::u16string s = p.generic_u16string();74 assert(s == (const char16_t*)MS);75 }76 {77 std::u32string s = p.generic_u32string();78 assert(s == (const char32_t*)MS);79 }80 81 return 0;82}83